1 /***********************************************************************************************************************************
2 * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3 * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
19 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
20 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
21 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
23 import net.sourceforge.phpdt.internal.compiler.util.Util;
24 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
25 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
53 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
55 import org.eclipse.core.resources.IFile;
56 import org.eclipse.core.resources.IProject;
57 import org.eclipse.core.resources.IResource;
58 import org.eclipse.core.runtime.IPath;
60 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
61 protected final static int StackIncrement = 255;
63 protected int stateStackTop;
65 // protected int[] stack = new int[StackIncrement];
67 public int firstToken; // handle for multiple parsing goals
69 public int lastAct; //handle for multiple parsing goals
71 // protected RecoveredElement currentElement;
73 public static boolean VERBOSE_RECOVERY = false;
75 protected boolean diet = false; //tells the scanner to jump over some
77 // parts of the code/expressions like
80 public Scanner scanner;
82 // private ArrayList phpList;
84 // private int currentPHPString;
86 // private boolean phpEnd;
88 // private static HashMap keywordMap = null;
96 // row counter for syntax errors:
98 // column counter for syntax errors:
102 // // current identifier
103 // String identifier;
106 // Double doubleNumber;
108 // private String stringValue;
110 /** Contains the current expression. */
111 // private StringBuffer expression;
112 //private boolean phpMode;
113 protected int modifiers;
115 protected int modifiersSourceStart;
117 protected Parser(ProblemReporter problemReporter) {
118 this.problemReporter = problemReporter;
119 this.options = problemReporter.options;
120 // this.currentPHPString = 0;
121 // PHPParserSuperclass.fileToParse = fileToParse;
122 // this.phpList = null;
123 // this.indexManager = null;
125 this.token = TokenNameEOF;
127 // this.rowCount = 1;
128 // this.columnCount = 0;
129 // this.phpEnd = false;
131 this.initializeScanner();
134 public void setFileToParse(IFile fileToParse) {
135 // this.currentPHPString = 0;
136 // PHPParserSuperclass.fileToParse = fileToParse;
137 // this.phpList = null;
138 // this.indexManager = null;
140 this.token = TokenNameEOF;
141 // this.phpEnd = false;
142 this.initializeScanner();
146 * ClassDeclaration Constructor.
150 * Description of Parameter
153 public Parser(IFile fileToParse) {
154 // if (keywordMap == null) {
155 // keywordMap = new HashMap();
156 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
157 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
160 // this.currentPHPString = 0;
161 // PHPParserSuperclass.fileToParse = fileToParse;
162 // this.phpList = null;
163 this.includesList = null;
165 this.token = TokenNameEOF;
167 // this.rowCount = 1;
168 // this.columnCount = 0;
169 // this.phpEnd = false;
171 this.initializeScanner();
174 public void initializeScanner() {
175 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
176 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
177 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
181 * Create marker for the parse error
183 // private void setMarker(String message, int charStart, int charEnd, int
185 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
188 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
192 * @throws SyntaxError
195 private void throwSyntaxError(String error) {
196 int problemStartPosition = scanner.getCurrentTokenStartPosition();
197 int problemEndPosition = scanner.getCurrentTokenEndPosition();
198 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
202 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
206 * @throws SyntaxError
209 // private void throwSyntaxError(String error, int startRow) {
210 // throw new SyntaxError(startRow, 0, " ", error);
212 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
213 if (referenceContext != null) {
214 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
215 compilationUnit.compilationResult);
217 throw new SyntaxError(1, 0, " ", error);
220 private void reportSyntaxError(String error) {
221 int problemStartPosition = scanner.getCurrentTokenStartPosition();
222 int problemEndPosition = scanner.getCurrentTokenEndPosition();
223 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
226 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
227 if (referenceContext != null) {
228 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
229 compilationUnit.compilationResult);
233 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
234 if (referenceContext != null) {
235 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
236 compilationUnit.compilationResult);
241 * gets the next token from input
243 private void getNextToken() {
245 token = scanner.getNextToken();
247 int currentEndPosition = scanner.getCurrentTokenEndPosition();
248 int currentStartPosition = scanner.getCurrentTokenStartPosition();
249 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
250 System.out.println(scanner.toStringAction(token));
252 } catch (InvalidInputException e) {
253 token = TokenNameERROR;
254 String detailedMessage = e.getMessage();
256 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
257 throwSyntaxError("Unterminated string.");
258 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
259 throwSyntaxError("Unterminated commment.");
265 public void init(String s) {
267 this.token = TokenNameEOF;
268 this.includesList = new ArrayList();
270 // this.rowCount = 1;
271 // this.columnCount = 0;
272 // this.phpEnd = false;
273 // this.phpMode = false;
274 /* scanner initialization */
275 scanner.setSource(s.toCharArray());
276 scanner.setPHPMode(false);
280 protected void initialize(boolean phpMode) {
281 initialize(phpMode, null);
284 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
285 compilationUnit = null;
286 referenceContext = null;
287 this.includesList = new ArrayList();
288 // this.indexManager = indexManager;
290 this.token = TokenNameEOF;
292 // this.rowCount = 1;
293 // this.columnCount = 0;
294 // this.phpEnd = false;
295 // this.phpMode = phpMode;
296 scanner.setPHPMode(phpMode);
301 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
303 public void parse(String s) {
308 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
310 public void parse(String s, HashMap variables) {
311 fMethodVariables = variables;
312 fStackUnassigned = new ArrayList();
318 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
320 protected void parse() {
321 if (scanner.compilationUnit != null) {
322 IResource resource = scanner.compilationUnit.getResource();
323 if (resource != null && resource instanceof IFile) {
324 // set the package name
325 consumePackageDeclarationName((IFile) resource);
331 if (token != TokenNameEOF && token != TokenNameERROR) {
334 if (token != TokenNameEOF) {
335 if (token == TokenNameERROR) {
336 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
338 if (token == TokenNameRPAREN) {
339 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
341 if (token == TokenNameRBRACE) {
342 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
344 if (token == TokenNameRBRACKET) {
345 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
347 if (token == TokenNameLPAREN) {
348 throwSyntaxError("Read character '('; end-of-file not reached.");
350 if (token == TokenNameLBRACE) {
351 throwSyntaxError("Read character '{'; end-of-file not reached.");
353 if (token == TokenNameLBRACKET) {
354 throwSyntaxError("Read character '['; end-of-file not reached.");
356 throwSyntaxError("End-of-file not reached.");
359 } catch (SyntaxError sytaxErr1) {
361 // // if an error occured,
362 // // try to find keywords 'abstract' 'final' 'class' or 'function'
363 // // to parse the rest of the string
364 // boolean tokenize = scanner.tokenizeStrings;
366 // scanner.tokenizeStrings = true;
369 // while (token != TokenNameEOF) {
370 // if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
375 // if (token == TokenNameEOF) {
378 // } catch (SyntaxError sytaxErr2) {
381 // scanner.tokenizeStrings = tokenize;
390 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
392 public void parseFunction(String s, HashMap variables) {
394 scanner.phpMode = true;
395 parseFunction(variables);
399 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
401 protected void parseFunction(HashMap variables) {
403 boolean hasModifiers = member_modifiers();
404 if (token == TokenNamefunction) {
406 checkAndSetModifiers(AccPublic);
408 this.fMethodVariables = variables;
410 MethodDeclaration methodDecl = new MethodDeclaration(null);
411 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
412 methodDecl.modifiers = this.modifiers;
413 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
416 functionDefinition(methodDecl);
417 } catch (SyntaxError sytaxErr1) {
420 int sourceEnd = methodDecl.sourceEnd;
421 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
422 sourceEnd = methodDecl.declarationSourceStart + 1;
424 methodDecl.sourceEnd = sourceEnd;
425 methodDecl.declarationSourceEnd = sourceEnd;
430 protected CompilationUnitDeclaration endParse(int act) {
434 // if (currentElement != null) {
435 // currentElement.topElement().updateParseTree();
436 // if (VERBOSE_RECOVERY) {
437 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
438 // System.out.println("--------------------------"); //$NON-NLS-1$
439 // System.out.println(compilationUnit);
440 // System.out.println("----------------------------------"); //$NON-NLS-1$
443 if (diet & VERBOSE_RECOVERY) {
444 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
445 System.out.println("--------------------------"); //$NON-NLS-1$
446 System.out.println(compilationUnit);
447 System.out.println("----------------------------------"); //$NON-NLS-1$
450 if (scanner.recordLineSeparator) {
451 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
453 if (scanner.taskTags != null) {
454 for (int i = 0; i < scanner.foundTaskCount; i++) {
455 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
456 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
457 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
460 compilationUnit.imports = new ImportReference[includesList.size()];
461 for (int i = 0; i < includesList.size(); i++) {
462 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
464 return compilationUnit;
467 private Block statementList() {
468 boolean branchStatement = false;
470 int blockStart = scanner.getCurrentTokenStartPosition();
471 ArrayList blockStatements = new ArrayList();
474 statement = statement();
475 blockStatements.add(statement);
476 if (branchStatement && statement != null) {
477 // reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
478 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
479 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
481 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
482 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
483 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
484 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
485 return createBlock(blockStart, blockStatements);
487 branchStatement = checkUnreachableStatements(statement);
488 } catch (SyntaxError sytaxErr1) {
489 // if an error occured,
490 // try to find keywords
491 // to parse the rest of the string
492 boolean tokenize = scanner.tokenizeStrings;
494 scanner.tokenizeStrings = true;
497 while (token != TokenNameEOF) {
498 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
499 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
500 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
501 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
502 return createBlock(blockStart, blockStatements);
504 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
505 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
506 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
507 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
508 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
509 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
512 // System.out.println(scanner.toStringAction(token));
514 // System.out.println(scanner.toStringAction(token));
516 if (token == TokenNameEOF) {
520 scanner.tokenizeStrings = tokenize;
530 private boolean checkUnreachableStatements(Statement statement) {
531 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
533 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
541 * @param blockStatements
544 private Block createBlock(int blockStart, ArrayList blockStatements) {
545 int blockEnd = scanner.getCurrentTokenEndPosition();
546 Block b = Block.EmptyWith(blockStart, blockEnd);
547 b.statements = new Statement[blockStatements.size()];
548 blockStatements.toArray(b.statements);
552 private void functionBody(MethodDeclaration methodDecl) {
553 // '{' [statement-list] '}'
554 if (token == TokenNameLBRACE) {
557 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
558 throwSyntaxError("'{' expected in compound-statement.");
560 if (token != TokenNameRBRACE) {
563 if (token == TokenNameRBRACE) {
564 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
567 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
568 throwSyntaxError("'}' expected in compound-statement.");
572 private Statement statement() {
573 Statement statement = null;
574 Expression expression;
575 int sourceStart = scanner.getCurrentTokenStartPosition();
577 if (token == TokenNameif) {
578 // T_IF '(' expr ')' statement elseif_list else_single
579 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
581 if (token == TokenNameLPAREN) {
584 throwSyntaxError("'(' expected after 'if' keyword.");
587 if (token == TokenNameRPAREN) {
590 throwSyntaxError("')' expected after 'if' condition.");
592 // create basic IfStatement
593 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
594 if (token == TokenNameCOLON) {
596 ifStatementColon(ifStatement);
598 ifStatement(ifStatement);
601 } else if (token == TokenNameswitch) {
603 if (token == TokenNameLPAREN) {
606 throwSyntaxError("'(' expected after 'switch' keyword.");
609 if (token == TokenNameRPAREN) {
612 throwSyntaxError("')' expected after 'switch' condition.");
616 } else if (token == TokenNamefor) {
618 if (token == TokenNameLPAREN) {
621 throwSyntaxError("'(' expected after 'for' keyword.");
623 if (token == TokenNameSEMICOLON) {
627 if (token == TokenNameSEMICOLON) {
630 throwSyntaxError("';' expected after 'for'.");
633 if (token == TokenNameSEMICOLON) {
637 if (token == TokenNameSEMICOLON) {
640 throwSyntaxError("';' expected after 'for'.");
643 if (token == TokenNameRPAREN) {
647 if (token == TokenNameRPAREN) {
650 throwSyntaxError("')' expected after 'for'.");
655 } else if (token == TokenNamewhile) {
657 if (token == TokenNameLPAREN) {
660 throwSyntaxError("'(' expected after 'while' keyword.");
663 if (token == TokenNameRPAREN) {
666 throwSyntaxError("')' expected after 'while' condition.");
670 } else if (token == TokenNamedo) {
672 if (token == TokenNameLBRACE) {
674 if (token != TokenNameRBRACE) {
677 if (token == TokenNameRBRACE) {
680 throwSyntaxError("'}' expected after 'do' keyword.");
685 if (token == TokenNamewhile) {
687 if (token == TokenNameLPAREN) {
690 throwSyntaxError("'(' expected after 'while' keyword.");
693 if (token == TokenNameRPAREN) {
696 throwSyntaxError("')' expected after 'while' condition.");
699 throwSyntaxError("'while' expected after 'do' keyword.");
701 if (token == TokenNameSEMICOLON) {
704 if (token != TokenNameINLINE_HTML) {
705 throwSyntaxError("';' expected after do-while statement.");
710 } else if (token == TokenNameforeach) {
712 if (token == TokenNameLPAREN) {
715 throwSyntaxError("'(' expected after 'foreach' keyword.");
718 if (token == TokenNameas) {
721 throwSyntaxError("'as' expected after 'foreach' exxpression.");
725 foreach_optional_arg();
726 if (token == TokenNameEQUAL_GREATER) {
728 variable(false, false);
730 if (token == TokenNameRPAREN) {
733 throwSyntaxError("')' expected after 'foreach' expression.");
737 } else if (token == TokenNamebreak) {
740 if (token != TokenNameSEMICOLON) {
743 if (token == TokenNameSEMICOLON) {
744 sourceEnd = scanner.getCurrentTokenEndPosition();
747 if (token != TokenNameINLINE_HTML) {
748 throwSyntaxError("';' expected after 'break'.");
750 sourceEnd = scanner.getCurrentTokenEndPosition();
753 return new BreakStatement(null, sourceStart, sourceEnd);
754 } else if (token == TokenNamecontinue) {
757 if (token != TokenNameSEMICOLON) {
760 if (token == TokenNameSEMICOLON) {
761 sourceEnd = scanner.getCurrentTokenEndPosition();
764 if (token != TokenNameINLINE_HTML) {
765 throwSyntaxError("';' expected after 'continue'.");
767 sourceEnd = scanner.getCurrentTokenEndPosition();
770 return new ContinueStatement(null, sourceStart, sourceEnd);
771 } else if (token == TokenNamereturn) {
774 if (token != TokenNameSEMICOLON) {
777 if (token == TokenNameSEMICOLON) {
778 sourceEnd = scanner.getCurrentTokenEndPosition();
781 if (token != TokenNameINLINE_HTML) {
782 throwSyntaxError("';' expected after 'return'.");
784 sourceEnd = scanner.getCurrentTokenEndPosition();
787 return new ReturnStatement(expression, sourceStart, sourceEnd);
788 } else if (token == TokenNameecho) {
791 if (token == TokenNameSEMICOLON) {
794 if (token != TokenNameINLINE_HTML) {
795 throwSyntaxError("';' expected after 'echo' statement.");
800 } else if (token == TokenNameINLINE_HTML) {
803 // } else if (token == TokenNameprint) {
806 // if (token == TokenNameSEMICOLON) {
809 // if (token != TokenNameStopPHP) {
810 // throwSyntaxError("';' expected after 'print' statement.");
815 } else if (token == TokenNameglobal) {
818 if (token == TokenNameSEMICOLON) {
821 if (token != TokenNameINLINE_HTML) {
822 throwSyntaxError("';' expected after 'global' statement.");
827 } else if (token == TokenNamestatic) {
830 if (token == TokenNameSEMICOLON) {
833 if (token != TokenNameINLINE_HTML) {
834 throwSyntaxError("';' expected after 'static' statement.");
839 } else if (token == TokenNameunset) {
841 if (token == TokenNameLPAREN) {
844 throwSyntaxError("'(' expected after 'unset' statement.");
847 if (token == TokenNameRPAREN) {
850 throwSyntaxError("')' expected after 'unset' statement.");
852 if (token == TokenNameSEMICOLON) {
855 if (token != TokenNameINLINE_HTML) {
856 throwSyntaxError("';' expected after 'unset' statement.");
861 } else if (token == TokenNamefunction) {
862 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
863 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
864 methodDecl.modifiers = AccDefault;
865 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
868 functionDefinition(methodDecl);
870 sourceEnd = methodDecl.sourceEnd;
871 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
872 sourceEnd = methodDecl.declarationSourceStart + 1;
874 methodDecl.declarationSourceEnd = sourceEnd;
875 methodDecl.sourceEnd = sourceEnd;
878 } else if (token == TokenNamedeclare) {
879 //T_DECLARE '(' declare_list ')' declare_statement
881 if (token != TokenNameLPAREN) {
882 throwSyntaxError("'(' expected in 'declare' statement.");
886 if (token != TokenNameRPAREN) {
887 throwSyntaxError("')' expected in 'declare' statement.");
892 } else if (token == TokenNametry) {
894 if (token != TokenNameLBRACE) {
895 throwSyntaxError("'{' expected in 'try' statement.");
899 if (token != TokenNameRBRACE) {
900 throwSyntaxError("'}' expected in 'try' statement.");
904 } else if (token == TokenNamecatch) {
906 if (token != TokenNameLPAREN) {
907 throwSyntaxError("'(' expected in 'catch' statement.");
910 fully_qualified_class_name();
911 if (token != TokenNameVariable) {
912 throwSyntaxError("Variable expected in 'catch' statement.");
915 if (token != TokenNameRPAREN) {
916 throwSyntaxError("')' expected in 'catch' statement.");
919 if (token != TokenNameLBRACE) {
920 throwSyntaxError("'{' expected in 'catch' statement.");
923 if (token != TokenNameRBRACE) {
925 if (token != TokenNameRBRACE) {
926 throwSyntaxError("'}' expected in 'catch' statement.");
930 additional_catches();
932 } else if (token == TokenNamethrow) {
935 if (token == TokenNameSEMICOLON) {
938 throwSyntaxError("';' expected after 'throw' exxpression.");
941 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
943 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
944 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
945 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
946 typeDecl.name = new char[] { ' ' };
947 // default super class
948 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
949 compilationUnit.types.add(typeDecl);
950 pushOnAstStack(typeDecl);
951 unticked_class_declaration_statement(typeDecl);
959 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
960 } else if (token == TokenNameLBRACE) {
962 if (token != TokenNameRBRACE) {
963 statement = statementList();
965 if (token == TokenNameRBRACE) {
969 throwSyntaxError("'}' expected.");
972 if (token != TokenNameSEMICOLON) {
975 if (token == TokenNameSEMICOLON) {
979 if (token == TokenNameRBRACE) {
980 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
982 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
983 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
993 private void declare_statement() {
995 //| ':' inner_statement_list T_ENDDECLARE ';'
997 if (token == TokenNameCOLON) {
999 // TODO: implement inner_statement_list();
1001 if (token != TokenNameenddeclare) {
1002 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1005 if (token != TokenNameSEMICOLON) {
1006 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1014 private void declare_list() {
1015 // T_STRING '=' static_scalar
1016 //| declare_list ',' T_STRING '=' static_scalar
1018 if (token != TokenNameIdentifier) {
1019 throwSyntaxError("Identifier expected in 'declare' list.");
1022 if (token != TokenNameEQUAL) {
1023 throwSyntaxError("'=' expected in 'declare' list.");
1027 if (token != TokenNameCOMMA) {
1034 private void additional_catches() {
1035 while (token == TokenNamecatch) {
1037 if (token != TokenNameLPAREN) {
1038 throwSyntaxError("'(' expected in 'catch' statement.");
1041 fully_qualified_class_name();
1042 if (token != TokenNameVariable) {
1043 throwSyntaxError("Variable expected in 'catch' statement.");
1046 if (token != TokenNameRPAREN) {
1047 throwSyntaxError("')' expected in 'catch' statement.");
1050 if (token != TokenNameLBRACE) {
1051 throwSyntaxError("'{' expected in 'catch' statement.");
1054 if (token != TokenNameRBRACE) {
1057 if (token != TokenNameRBRACE) {
1058 throwSyntaxError("'}' expected in 'catch' statement.");
1064 private void foreach_variable() {
1067 if (token == TokenNameAND) {
1073 private void foreach_optional_arg() {
1075 //| T_DOUBLE_ARROW foreach_variable
1076 if (token == TokenNameEQUAL_GREATER) {
1082 private void global_var_list() {
1084 // global_var_list ',' global_var
1086 HashSet set = peekVariableSet();
1089 if (token != TokenNameCOMMA) {
1096 private void global_var(HashSet set) {
1100 //| '$' '{' expr '}'
1101 if (token == TokenNameVariable) {
1102 if (fMethodVariables != null) {
1103 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1104 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1106 addVariableSet(set);
1108 } else if (token == TokenNameDOLLAR) {
1110 if (token == TokenNameLBRACE) {
1113 if (token != TokenNameRBRACE) {
1114 throwSyntaxError("'}' expected in global variable.");
1123 private void static_var_list() {
1125 // static_var_list ',' T_VARIABLE
1126 //| static_var_list ',' T_VARIABLE '=' static_scalar
1128 //| T_VARIABLE '=' static_scalar,
1129 HashSet set = peekVariableSet();
1131 if (token == TokenNameVariable) {
1132 if (fMethodVariables != null) {
1133 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1134 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1136 addVariableSet(set);
1138 if (token == TokenNameEQUAL) {
1142 if (token != TokenNameCOMMA) {
1152 private void unset_variables() {
1155 // | unset_variables ',' unset_variable
1159 variable(false, false);
1160 if (token != TokenNameCOMMA) {
1167 private final void initializeModifiers() {
1169 this.modifiersSourceStart = -1;
1172 private final void checkAndSetModifiers(int flag) {
1173 this.modifiers |= flag;
1174 if (this.modifiersSourceStart < 0)
1175 this.modifiersSourceStart = this.scanner.startPosition;
1178 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1179 initializeModifiers();
1180 if (token == TokenNameinterface) {
1181 // interface_entry T_STRING
1182 // interface_extends_list
1183 // '{' class_statement_list '}'
1184 checkAndSetModifiers(AccInterface);
1186 typeDecl.modifiers = this.modifiers;
1187 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1188 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1189 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1190 typeDecl.name = scanner.getCurrentIdentifierSource();
1191 if (token > TokenNameKEYWORD) {
1192 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1193 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1194 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1195 // typeDecl.sourceStart, typeDecl.sourceEnd);
1198 interface_extends_list(typeDecl);
1200 typeDecl.name = new char[] { ' ' };
1201 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1205 // class_entry_type T_STRING extends_from
1207 // '{' class_statement_list'}'
1209 typeDecl.modifiers = this.modifiers;
1210 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1211 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1213 //identifier 'extends' identifier
1214 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1215 typeDecl.name = scanner.getCurrentIdentifierSource();
1216 if (token > TokenNameKEYWORD) {
1217 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1218 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1219 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1220 // typeDecl.sourceStart, typeDecl.sourceEnd);
1225 // | T_EXTENDS fully_qualified_class_name
1226 if (token == TokenNameextends) {
1227 interface_extends_list(typeDecl);
1229 // if (token != TokenNameIdentifier) {
1230 // throwSyntaxError("Class name expected after keyword
1232 // scanner.getCurrentTokenStartPosition(), scanner
1233 // .getCurrentTokenEndPosition());
1236 implements_list(typeDecl);
1238 typeDecl.name = new char[] { ' ' };
1239 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1243 // '{' class_statement_list '}'
1244 if (token == TokenNameLBRACE) {
1246 if (token != TokenNameRBRACE) {
1247 ArrayList list = new ArrayList();
1248 class_statement_list(list);
1249 typeDecl.fields = new FieldDeclaration[list.size()];
1250 for (int i = 0; i < list.size(); i++) {
1251 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1254 if (token == TokenNameRBRACE) {
1255 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1258 throwSyntaxError("'}' expected at end of class body.");
1261 throwSyntaxError("'{' expected at start of class body.");
1265 private void class_entry_type() {
1267 // | T_ABSTRACT T_CLASS
1268 // | T_FINAL T_CLASS
1269 if (token == TokenNameclass) {
1271 } else if (token == TokenNameabstract) {
1272 checkAndSetModifiers(AccAbstract);
1274 if (token != TokenNameclass) {
1275 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1278 } else if (token == TokenNamefinal) {
1279 checkAndSetModifiers(AccFinal);
1281 if (token != TokenNameclass) {
1282 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1286 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1290 private void class_extends(TypeDeclaration typeDecl) {
1292 // | T_EXTENDS interface_list
1293 if (token == TokenNameextends) {
1296 if (token == TokenNameIdentifier) {
1299 throwSyntaxError("Class name expected after keyword 'extends'.");
1304 private void interface_extends_list(TypeDeclaration typeDecl) {
1306 // | T_EXTENDS interface_list
1307 if (token == TokenNameextends) {
1313 private void implements_list(TypeDeclaration typeDecl) {
1315 // | T_IMPLEMENTS interface_list
1316 if (token == TokenNameimplements) {
1322 private void interface_list() {
1324 // fully_qualified_class_name
1325 //| interface_list ',' fully_qualified_class_name
1327 if (token == TokenNameIdentifier) {
1330 throwSyntaxError("Interface name expected after keyword 'implements'.");
1332 if (token != TokenNameCOMMA) {
1339 // private void classBody(TypeDeclaration typeDecl) {
1340 // //'{' [class-element-list] '}'
1341 // if (token == TokenNameLBRACE) {
1343 // if (token != TokenNameRBRACE) {
1344 // class_statement_list();
1346 // if (token == TokenNameRBRACE) {
1347 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1350 // throwSyntaxError("'}' expected at end of class body.");
1353 // throwSyntaxError("'{' expected at start of class body.");
1356 private void class_statement_list(ArrayList list) {
1359 class_statement(list);
1360 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1361 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1362 || token == TokenNameconst) {
1365 if (token == TokenNameRBRACE) {
1368 throwSyntaxError("'}' at end of class statement.");
1369 } catch (SyntaxError sytaxErr1) {
1370 boolean tokenize = scanner.tokenizeStrings;
1372 scanner.tokenizeStrings = true;
1375 // if an error occured,
1376 // try to find keywords
1377 // to parse the rest of the string
1378 while (token != TokenNameEOF) {
1379 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1380 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1381 || token == TokenNameconst) {
1384 // System.out.println(scanner.toStringAction(token));
1387 if (token == TokenNameEOF) {
1391 scanner.tokenizeStrings = tokenize;
1397 private void class_statement(ArrayList list) {
1399 // variable_modifiers class_variable_declaration ';'
1400 // | class_constant_declaration ';'
1401 // | method_modifiers T_FUNCTION is_reference T_STRING
1402 // '(' parameter_list ')' method_body
1403 initializeModifiers();
1404 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1406 if (token == TokenNamevar) {
1407 checkAndSetModifiers(AccPublic);
1408 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1409 referenceContext, compilationUnit.compilationResult);
1411 class_variable_declaration(declarationSourceStart, list);
1412 } else if (token == TokenNameconst) {
1413 checkAndSetModifiers(AccFinal | AccPublic);
1414 class_constant_declaration(declarationSourceStart, list);
1415 if (token != TokenNameSEMICOLON) {
1416 throwSyntaxError("';' expected after class const declaration.");
1420 boolean hasModifiers = member_modifiers();
1421 if (token == TokenNamefunction) {
1422 if (!hasModifiers) {
1423 checkAndSetModifiers(AccPublic);
1425 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1426 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1427 methodDecl.modifiers = this.modifiers;
1428 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1431 functionDefinition(methodDecl);
1433 int sourceEnd = methodDecl.sourceEnd;
1434 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1435 sourceEnd = methodDecl.declarationSourceStart + 1;
1437 methodDecl.declarationSourceEnd = sourceEnd;
1438 methodDecl.sourceEnd = sourceEnd;
1441 if (!hasModifiers) {
1442 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1444 class_variable_declaration(declarationSourceStart, list);
1449 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1450 // class_constant_declaration ',' T_STRING '=' static_scalar
1451 // | T_CONST T_STRING '=' static_scalar
1452 if (token != TokenNameconst) {
1453 throwSyntaxError("'const' keyword expected in class declaration.");
1458 if (token != TokenNameIdentifier) {
1459 throwSyntaxError("Identifier expected in class const declaration.");
1461 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1462 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1463 fieldDeclaration.modifiers = this.modifiers;
1464 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1465 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1466 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1467 // fieldDeclaration.type
1468 list.add(fieldDeclaration);
1470 if (token != TokenNameEQUAL) {
1471 throwSyntaxError("'=' expected in class const declaration.");
1475 if (token != TokenNameCOMMA) {
1476 break; // while(true)-loop
1482 // private void variable_modifiers() {
1483 // // variable_modifiers:
1484 // // non_empty_member_modifiers
1486 // initializeModifiers();
1487 // if (token == TokenNamevar) {
1488 // checkAndSetModifiers(AccPublic);
1489 // reportSyntaxError(
1490 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1492 // modifier for field declarations.",
1493 // scanner.getCurrentTokenStartPosition(), scanner
1494 // .getCurrentTokenEndPosition());
1497 // if (!member_modifiers()) {
1498 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1499 // field declarations.");
1503 // private void method_modifiers() {
1504 // //method_modifiers:
1506 // //| non_empty_member_modifiers
1507 // initializeModifiers();
1508 // if (!member_modifiers()) {
1509 // checkAndSetModifiers(AccPublic);
1512 private boolean member_modifiers() {
1519 boolean foundToken = false;
1521 if (token == TokenNamepublic) {
1522 checkAndSetModifiers(AccPublic);
1525 } else if (token == TokenNameprotected) {
1526 checkAndSetModifiers(AccProtected);
1529 } else if (token == TokenNameprivate) {
1530 checkAndSetModifiers(AccPrivate);
1533 } else if (token == TokenNamestatic) {
1534 checkAndSetModifiers(AccStatic);
1537 } else if (token == TokenNameabstract) {
1538 checkAndSetModifiers(AccAbstract);
1541 } else if (token == TokenNamefinal) {
1542 checkAndSetModifiers(AccFinal);
1552 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1553 // class_variable_declaration:
1554 // class_variable_declaration ',' T_VARIABLE
1555 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1557 // | T_VARIABLE '=' static_scalar
1558 char[] classVariable;
1560 if (token == TokenNameVariable) {
1561 classVariable = scanner.getCurrentIdentifierSource();
1562 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1563 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1564 .getCurrentTokenEndPosition());
1565 fieldDeclaration.modifiers = this.modifiers;
1566 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1567 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1568 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1569 list.add(fieldDeclaration);
1570 if (fTypeVariables != null) {
1571 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1572 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1575 if (token == TokenNameEQUAL) {
1580 // if (token == TokenNamethis) {
1581 // throwSyntaxError("'$this' not allowed after keyword 'public'
1582 // 'protected' 'private' 'var'.");
1584 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1586 if (token != TokenNameCOMMA) {
1591 if (token != TokenNameSEMICOLON) {
1592 throwSyntaxError("';' expected after field declaration.");
1597 private void functionDefinition(MethodDeclaration methodDecl) {
1598 boolean isAbstract = false;
1600 if (compilationUnit != null) {
1601 compilationUnit.types.add(methodDecl);
1604 ASTNode node = astStack[astPtr];
1605 if (node instanceof TypeDeclaration) {
1606 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1607 if (typeDecl.methods == null) {
1608 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1610 AbstractMethodDeclaration[] newMethods;
1611 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1612 typeDecl.methods.length);
1613 newMethods[typeDecl.methods.length] = methodDecl;
1614 typeDecl.methods = newMethods;
1616 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1618 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1624 pushFunctionVariableSet();
1625 functionDeclarator(methodDecl);
1626 if (token == TokenNameSEMICOLON) {
1628 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1629 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1634 functionBody(methodDecl);
1636 if (!fStackUnassigned.isEmpty()) {
1637 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1642 private void functionDeclarator(MethodDeclaration methodDecl) {
1643 //identifier '(' [parameter-list] ')'
1644 if (token == TokenNameAND) {
1647 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1648 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1649 if (Scanner.isIdentifierOrKeyword(token)) {
1650 methodDecl.selector = scanner.getCurrentIdentifierSource();
1651 if (token > TokenNameKEYWORD) {
1652 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1653 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1656 if (token == TokenNameLPAREN) {
1659 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1660 throwSyntaxError("'(' expected in function declaration.");
1662 if (token != TokenNameRPAREN) {
1663 parameter_list(methodDecl);
1665 if (token != TokenNameRPAREN) {
1666 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1667 throwSyntaxError("')' expected in function declaration.");
1669 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1673 methodDecl.selector = "<undefined>".toCharArray();
1674 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1675 throwSyntaxError("Function name expected after keyword 'function'.");
1680 private void parameter_list(MethodDeclaration methodDecl) {
1681 // non_empty_parameter_list
1683 non_empty_parameter_list(methodDecl, true);
1686 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1687 // optional_class_type T_VARIABLE
1688 // | optional_class_type '&' T_VARIABLE
1689 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1690 // | optional_class_type T_VARIABLE '=' static_scalar
1691 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1692 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1693 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1695 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1697 char[] typeIdentifier = null;
1698 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1699 HashSet set = peekVariableSet();
1701 if (token == TokenNameIdentifier) {
1702 typeIdentifier = scanner.getCurrentIdentifierSource();
1705 if (token == TokenNameAND) {
1708 if (token == TokenNameVariable) {
1709 if (fMethodVariables != null) {
1711 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1712 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1714 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1716 info.typeIdentifier = typeIdentifier;
1717 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1719 addVariableSet(set);
1721 if (token == TokenNameEQUAL) {
1726 throwSyntaxError("Variable expected in parameter list.");
1728 if (token != TokenNameCOMMA) {
1735 if (!empty_allowed) {
1736 throwSyntaxError("Identifier expected in parameter list.");
1740 private void optional_class_type() {
1745 // private void parameterDeclaration() {
1747 // //variable-reference
1748 // if (token == TokenNameAND) {
1750 // if (isVariable()) {
1753 // throwSyntaxError("Variable expected after reference operator '&'.");
1756 // //variable '=' constant
1757 // if (token == TokenNameVariable) {
1759 // if (token == TokenNameEQUAL) {
1765 // // if (token == TokenNamethis) {
1766 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1767 // // declaration.");
1771 private void labeledStatementList() {
1772 if (token != TokenNamecase && token != TokenNamedefault) {
1773 throwSyntaxError("'case' or 'default' expected.");
1776 if (token == TokenNamecase) {
1778 expr(); //constant();
1779 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1781 if (token == TokenNamecase || token == TokenNamedefault) {
1782 // empty case statement ?
1787 // else if (token == TokenNameSEMICOLON) {
1789 // "':' expected after 'case' keyword (Found token: " +
1790 // scanner.toStringAction(token) + ")",
1791 // scanner.getCurrentTokenStartPosition(),
1792 // scanner.getCurrentTokenEndPosition(),
1795 // if (token == TokenNamecase) { // empty case statement ?
1801 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1803 } else { // TokenNamedefault
1805 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1807 if (token == TokenNameRBRACE) {
1808 // empty default case
1811 if (token != TokenNamecase) {
1815 throwSyntaxError("':' character expected after 'default'.");
1818 } while (token == TokenNamecase || token == TokenNamedefault);
1821 private void ifStatementColon(IfStatement iState) {
1822 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
1823 HashSet assignedVariableSet = null;
1825 Block b = inner_statement_list();
1826 iState.thenStatement = b;
1827 checkUnreachable(iState, b);
1829 assignedVariableSet = removeIfVariableSet();
1831 if (token == TokenNameelseif) {
1833 pushIfVariableSet();
1834 new_elseif_list(iState);
1836 HashSet set = removeIfVariableSet();
1837 if (assignedVariableSet != null) {
1838 assignedVariableSet.addAll(set);
1843 pushIfVariableSet();
1844 new_else_single(iState);
1846 HashSet set = removeIfVariableSet();
1847 if (assignedVariableSet != null) {
1848 HashSet topSet = peekVariableSet();
1849 if (topSet != null) {
1851 topSet.addAll(assignedVariableSet);
1855 if (token != TokenNameendif) {
1856 throwSyntaxError("'endif' expected.");
1859 if (token != TokenNameSEMICOLON) {
1860 reportSyntaxError("';' expected after if-statement.");
1861 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1863 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1868 private void ifStatement(IfStatement iState) {
1869 // T_IF '(' expr ')' statement elseif_list else_single
1870 HashSet assignedVariableSet = null;
1872 pushIfVariableSet();
1873 Statement s = statement();
1874 iState.thenStatement = s;
1875 checkUnreachable(iState, s);
1877 assignedVariableSet = removeIfVariableSet();
1880 if (token == TokenNameelseif) {
1882 pushIfVariableSet();
1883 elseif_list(iState);
1885 HashSet set = removeIfVariableSet();
1886 if (assignedVariableSet != null) {
1887 assignedVariableSet.addAll(set);
1892 pushIfVariableSet();
1893 else_single(iState);
1895 HashSet set = removeIfVariableSet();
1896 if (assignedVariableSet != null) {
1897 HashSet topSet = peekVariableSet();
1898 if (topSet != null) {
1900 topSet.addAll(assignedVariableSet);
1906 private void elseif_list(IfStatement iState) {
1908 //| elseif_list T_ELSEIF '(' expr ')' statement
1909 ArrayList conditionList = new ArrayList();
1910 ArrayList statementList = new ArrayList();
1913 while (token == TokenNameelseif) {
1915 if (token == TokenNameLPAREN) {
1918 throwSyntaxError("'(' expected after 'elseif' keyword.");
1921 conditionList.add(e);
1922 if (token == TokenNameRPAREN) {
1925 throwSyntaxError("')' expected after 'elseif' condition.");
1928 statementList.add(s);
1929 checkUnreachable(iState, s);
1931 iState.elseifConditions = new Expression[conditionList.size()];
1932 iState.elseifStatements = new Statement[statementList.size()];
1933 conditionList.toArray(iState.elseifConditions);
1934 statementList.toArray(iState.elseifStatements);
1937 private void new_elseif_list(IfStatement iState) {
1939 //| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1940 ArrayList conditionList = new ArrayList();
1941 ArrayList statementList = new ArrayList();
1944 while (token == TokenNameelseif) {
1946 if (token == TokenNameLPAREN) {
1949 throwSyntaxError("'(' expected after 'elseif' keyword.");
1952 conditionList.add(e);
1953 if (token == TokenNameRPAREN) {
1956 throwSyntaxError("')' expected after 'elseif' condition.");
1958 if (token == TokenNameCOLON) {
1961 throwSyntaxError("':' expected after 'elseif' keyword.");
1963 b = inner_statement_list();
1964 statementList.add(b);
1965 checkUnreachable(iState, b);
1967 iState.elseifConditions = new Expression[conditionList.size()];
1968 iState.elseifStatements = new Statement[statementList.size()];
1969 conditionList.toArray(iState.elseifConditions);
1970 statementList.toArray(iState.elseifStatements);
1973 private void else_single(IfStatement iState) {
1976 if (token == TokenNameelse) {
1978 Statement s = statement();
1979 iState.elseStatement = s;
1980 checkUnreachable(iState, s);
1982 iState.checkUnreachable = false;
1984 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1987 private void new_else_single(IfStatement iState) {
1989 //| T_ELSE ':' inner_statement_list
1990 if (token == TokenNameelse) {
1992 if (token == TokenNameCOLON) {
1995 throwSyntaxError("':' expected after 'else' keyword.");
1997 Block b = inner_statement_list();
1998 iState.elseStatement = b;
1999 checkUnreachable(iState, b);
2001 iState.checkUnreachable = false;
2005 private Block inner_statement_list() {
2006 // inner_statement_list inner_statement
2008 return statementList();
2015 private void checkUnreachable(IfStatement iState, Statement s) {
2016 if (s instanceof Block) {
2017 Block b = (Block) s;
2018 if (b.statements == null || b.statements.length == 0) {
2019 iState.checkUnreachable = false;
2021 int off = b.statements.length - 1;
2022 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2023 && !(b.statements[off] instanceof BreakStatement)) {
2024 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2025 iState.checkUnreachable = false;
2030 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2031 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2032 iState.checkUnreachable = false;
2038 // private void elseifStatementList() {
2040 // elseifStatement();
2042 // case TokenNameelse:
2044 // if (token == TokenNameCOLON) {
2046 // if (token != TokenNameendif) {
2051 // if (token == TokenNameif) { //'else if'
2054 // throwSyntaxError("':' expected after 'else'.");
2058 // case TokenNameelseif:
2067 // private void elseifStatement() {
2068 // if (token == TokenNameLPAREN) {
2071 // if (token != TokenNameRPAREN) {
2072 // throwSyntaxError("')' expected in else-if-statement.");
2075 // if (token != TokenNameCOLON) {
2076 // throwSyntaxError("':' expected in else-if-statement.");
2079 // if (token != TokenNameendif) {
2085 private void switchStatement() {
2086 if (token == TokenNameCOLON) {
2087 // ':' [labeled-statement-list] 'endswitch' ';'
2089 labeledStatementList();
2090 if (token != TokenNameendswitch) {
2091 throwSyntaxError("'endswitch' expected.");
2094 if (token != TokenNameSEMICOLON) {
2095 throwSyntaxError("';' expected after switch-statement.");
2099 // '{' [labeled-statement-list] '}'
2100 if (token != TokenNameLBRACE) {
2101 throwSyntaxError("'{' expected in switch statement.");
2104 if (token != TokenNameRBRACE) {
2105 labeledStatementList();
2107 if (token != TokenNameRBRACE) {
2108 throwSyntaxError("'}' expected in switch statement.");
2114 private void forStatement() {
2115 if (token == TokenNameCOLON) {
2118 if (token != TokenNameendfor) {
2119 throwSyntaxError("'endfor' expected.");
2122 if (token != TokenNameSEMICOLON) {
2123 throwSyntaxError("';' expected after for-statement.");
2131 private void whileStatement() {
2132 // ':' statement-list 'endwhile' ';'
2133 if (token == TokenNameCOLON) {
2136 if (token != TokenNameendwhile) {
2137 throwSyntaxError("'endwhile' expected.");
2140 if (token != TokenNameSEMICOLON) {
2141 throwSyntaxError("';' expected after while-statement.");
2149 private void foreachStatement() {
2150 if (token == TokenNameCOLON) {
2153 if (token != TokenNameendforeach) {
2154 throwSyntaxError("'endforeach' expected.");
2157 if (token != TokenNameSEMICOLON) {
2158 throwSyntaxError("';' expected after foreach-statement.");
2166 // private void exitStatus() {
2167 // if (token == TokenNameLPAREN) {
2170 // throwSyntaxError("'(' expected in 'exit-status'.");
2172 // if (token != TokenNameRPAREN) {
2175 // if (token == TokenNameRPAREN) {
2178 // throwSyntaxError("')' expected after 'exit-status'.");
2181 private void expressionList() {
2184 if (token == TokenNameCOMMA) {
2192 private Expression expr() {
2194 // | expr_without_variable
2195 // if (token!=TokenNameEOF) {
2196 if (Scanner.TRACE) {
2197 System.out.println("TRACE: expr()");
2199 return expr_without_variable(true);
2203 private Expression expr_without_variable(boolean only_variable) {
2204 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2205 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2206 Expression expression = new Expression();
2207 expression.sourceStart = exprSourceStart;
2208 // default, may be overwritten
2209 expression.sourceEnd = exprSourceEnd;
2211 // internal_functions_in_yacc
2220 // | T_INC rw_variable
2221 // | T_DEC rw_variable
2222 // | T_INT_CAST expr
2223 // | T_DOUBLE_CAST expr
2224 // | T_STRING_CAST expr
2225 // | T_ARRAY_CAST expr
2226 // | T_OBJECT_CAST expr
2227 // | T_BOOL_CAST expr
2228 // | T_UNSET_CAST expr
2229 // | T_EXIT exit_expr
2231 // | T_ARRAY '(' array_pair_list ')'
2232 // | '`' encaps_list '`'
2233 // | T_LIST '(' assignment_list ')' '=' expr
2234 // | T_NEW class_name_reference ctor_arguments
2235 // | variable '=' expr
2236 // | variable '=' '&' variable
2237 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2238 // | variable T_PLUS_EQUAL expr
2239 // | variable T_MINUS_EQUAL expr
2240 // | variable T_MUL_EQUAL expr
2241 // | variable T_DIV_EQUAL expr
2242 // | variable T_CONCAT_EQUAL expr
2243 // | variable T_MOD_EQUAL expr
2244 // | variable T_AND_EQUAL expr
2245 // | variable T_OR_EQUAL expr
2246 // | variable T_XOR_EQUAL expr
2247 // | variable T_SL_EQUAL expr
2248 // | variable T_SR_EQUAL expr
2249 // | rw_variable T_INC
2250 // | rw_variable T_DEC
2251 // | expr T_BOOLEAN_OR expr
2252 // | expr T_BOOLEAN_AND expr
2253 // | expr T_LOGICAL_OR expr
2254 // | expr T_LOGICAL_AND expr
2255 // | expr T_LOGICAL_XOR expr
2267 // | expr T_IS_IDENTICAL expr
2268 // | expr T_IS_NOT_IDENTICAL expr
2269 // | expr T_IS_EQUAL expr
2270 // | expr T_IS_NOT_EQUAL expr
2272 // | expr T_IS_SMALLER_OR_EQUAL expr
2274 // | expr T_IS_GREATER_OR_EQUAL expr
2275 // | expr T_INSTANCEOF class_name_reference
2276 // | expr '?' expr ':' expr
2277 if (Scanner.TRACE) {
2278 System.out.println("TRACE: expr_without_variable() PART 1");
2281 case TokenNameisset:
2282 // T_ISSET '(' isset_variables ')'
2284 if (token != TokenNameLPAREN) {
2285 throwSyntaxError("'(' expected after keyword 'isset'");
2289 if (token != TokenNameRPAREN) {
2290 throwSyntaxError("')' expected after keyword 'isset'");
2294 case TokenNameempty:
2296 if (token != TokenNameLPAREN) {
2297 throwSyntaxError("'(' expected after keyword 'empty'");
2300 variable(true, false);
2301 if (token != TokenNameRPAREN) {
2302 throwSyntaxError("')' expected after keyword 'empty'");
2307 case TokenNameinclude:
2308 case TokenNameinclude_once:
2309 case TokenNamerequire:
2310 case TokenNamerequire_once:
2311 internal_functions_in_yacc();
2314 case TokenNameLPAREN:
2317 if (token == TokenNameRPAREN) {
2320 throwSyntaxError("')' expected in expression.");
2330 // | T_INT_CAST expr
2331 // | T_DOUBLE_CAST expr
2332 // | T_STRING_CAST expr
2333 // | T_ARRAY_CAST expr
2334 // | T_OBJECT_CAST expr
2335 // | T_BOOL_CAST expr
2336 // | T_UNSET_CAST expr
2337 case TokenNameclone:
2338 case TokenNameprint:
2341 case TokenNameMINUS:
2343 case TokenNameTWIDDLE:
2344 case TokenNameintCAST:
2345 case TokenNamedoubleCAST:
2346 case TokenNamestringCAST:
2347 case TokenNamearrayCAST:
2348 case TokenNameobjectCAST:
2349 case TokenNameboolCAST:
2350 case TokenNameunsetCAST:
2360 //| T_STRING_VARNAME
2362 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2363 // | '`' encaps_list '`'
2365 // | '`' encaps_list '`'
2366 case TokenNameEncapsedString0:
2367 scanner.encapsedStringStack.push(new Character('`'));
2370 if (token == TokenNameEncapsedString0) {
2373 if (token != TokenNameEncapsedString0) {
2374 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2378 scanner.encapsedStringStack.pop();
2382 // | '\'' encaps_list '\''
2383 case TokenNameEncapsedString1:
2384 scanner.encapsedStringStack.push(new Character('\''));
2387 exprSourceStart = scanner.getCurrentTokenStartPosition();
2388 if (token == TokenNameEncapsedString1) {
2389 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2390 .getCurrentTokenEndPosition());
2393 if (token != TokenNameEncapsedString1) {
2394 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2396 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2397 .getCurrentTokenEndPosition());
2401 scanner.encapsedStringStack.pop();
2405 //| '"' encaps_list '"'
2406 case TokenNameEncapsedString2:
2407 scanner.encapsedStringStack.push(new Character('"'));
2410 exprSourceStart = scanner.getCurrentTokenStartPosition();
2411 if (token == TokenNameEncapsedString2) {
2412 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2413 .getCurrentTokenEndPosition());
2416 if (token != TokenNameEncapsedString2) {
2417 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2419 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2420 .getCurrentTokenEndPosition());
2424 scanner.encapsedStringStack.pop();
2428 case TokenNameStringDoubleQuote:
2429 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2430 .getCurrentTokenEndPosition());
2433 case TokenNameStringSingleQuote:
2434 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2435 .getCurrentTokenEndPosition());
2438 case TokenNameIntegerLiteral:
2439 case TokenNameDoubleLiteral:
2440 case TokenNameStringInterpolated:
2443 case TokenNameCLASS_C:
2444 case TokenNameMETHOD_C:
2445 case TokenNameFUNC_C:
2448 case TokenNameHEREDOC:
2451 case TokenNamearray:
2452 // T_ARRAY '(' array_pair_list ')'
2454 if (token == TokenNameLPAREN) {
2456 if (token == TokenNameRPAREN) {
2461 if (token != TokenNameRPAREN) {
2462 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2466 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2470 // | T_LIST '(' assignment_list ')' '=' expr
2472 if (token == TokenNameLPAREN) {
2475 if (token != TokenNameRPAREN) {
2476 throwSyntaxError("')' expected after 'list' keyword.");
2479 if (token != TokenNameEQUAL) {
2480 throwSyntaxError("'=' expected after 'list' keyword.");
2485 throwSyntaxError("'(' expected after 'list' keyword.");
2489 // | T_NEW class_name_reference ctor_arguments
2491 Expression typeRef = class_name_reference();
2493 if (typeRef != null) {
2494 expression = typeRef;
2497 // | T_INC rw_variable
2498 // | T_DEC rw_variable
2499 case TokenNamePLUS_PLUS:
2500 case TokenNameMINUS_MINUS:
2504 // | variable '=' expr
2505 // | variable '=' '&' variable
2506 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2507 // | variable T_PLUS_EQUAL expr
2508 // | variable T_MINUS_EQUAL expr
2509 // | variable T_MUL_EQUAL expr
2510 // | variable T_DIV_EQUAL expr
2511 // | variable T_CONCAT_EQUAL expr
2512 // | variable T_MOD_EQUAL expr
2513 // | variable T_AND_EQUAL expr
2514 // | variable T_OR_EQUAL expr
2515 // | variable T_XOR_EQUAL expr
2516 // | variable T_SL_EQUAL expr
2517 // | variable T_SR_EQUAL expr
2518 // | rw_variable T_INC
2519 // | rw_variable T_DEC
2520 case TokenNameIdentifier:
2521 case TokenNameVariable:
2522 case TokenNameDOLLAR:
2523 boolean rememberedVar = false;
2524 Expression lhs = variable(true, true);
2525 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2526 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2527 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2528 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2529 && token != TokenNameLEFT_SHIFT_EQUAL) {
2530 FieldReference ref = (FieldReference) lhs;
2531 if (!containsVariableSet(ref.token)) {
2532 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(), referenceContext,
2533 compilationUnit.compilationResult);
2534 addVariableSet(ref.token);
2539 case TokenNameEQUAL:
2540 if (lhs != null && lhs instanceof FieldReference) {
2541 addVariableSet(((FieldReference) lhs).token);
2543 // if (lhsVar != null) {
2544 // addVariableSet(lhsVar);
2547 if (token == TokenNameAND) {
2549 if (token == TokenNamenew) {
2550 // | variable '=' '&' T_NEW class_name_reference
2553 SingleTypeReference classRef = class_name_reference();
2555 if (classRef != null) {
2556 if (lhs != null && lhs instanceof FieldReference) {
2558 // $var = & new Object();
2559 if (fMethodVariables != null) {
2560 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2561 lhsInfo.reference = classRef;
2562 lhsInfo.typeIdentifier = classRef.token;
2563 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2564 rememberedVar = true;
2569 Expression rhs = variable(false, false);
2570 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2573 if (fMethodVariables != null) {
2574 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2575 if (rhsInfo != null && rhsInfo.reference != null) {
2576 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2577 lhsInfo.reference = rhsInfo.reference;
2578 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2579 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2580 rememberedVar = true;
2586 Expression rhs = expr();
2587 if (lhs != null && lhs instanceof FieldReference) {
2588 if (rhs != null && rhs instanceof FieldReference) {
2591 if (fMethodVariables != null) {
2592 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2593 if (rhsInfo != null && rhsInfo.reference != null) {
2594 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2595 lhsInfo.reference = rhsInfo.reference;
2596 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2597 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2598 rememberedVar = true;
2601 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2603 // $var = new Object();
2604 if (fMethodVariables != null) {
2605 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2606 lhsInfo.reference = (SingleTypeReference) rhs;
2607 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2608 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2609 rememberedVar = true;
2614 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2615 if (fMethodVariables != null) {
2616 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2617 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2621 case TokenNamePLUS_EQUAL:
2622 case TokenNameMINUS_EQUAL:
2623 case TokenNameMULTIPLY_EQUAL:
2624 case TokenNameDIVIDE_EQUAL:
2625 case TokenNameDOT_EQUAL:
2626 case TokenNameREMAINDER_EQUAL:
2627 case TokenNameAND_EQUAL:
2628 case TokenNameOR_EQUAL:
2629 case TokenNameXOR_EQUAL:
2630 case TokenNameRIGHT_SHIFT_EQUAL:
2631 case TokenNameLEFT_SHIFT_EQUAL:
2632 if (lhs != null && lhs instanceof FieldReference) {
2633 addVariableSet(((FieldReference) lhs).token);
2638 case TokenNamePLUS_PLUS:
2639 case TokenNameMINUS_MINUS:
2643 if (!only_variable) {
2644 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2652 if (token != TokenNameINLINE_HTML) {
2653 if (token > TokenNameKEYWORD) {
2657 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2662 if (Scanner.TRACE) {
2663 System.out.println("TRACE: expr_without_variable() PART 2");
2665 // | expr T_BOOLEAN_OR expr
2666 // | expr T_BOOLEAN_AND expr
2667 // | expr T_LOGICAL_OR expr
2668 // | expr T_LOGICAL_AND expr
2669 // | expr T_LOGICAL_XOR expr
2681 // | expr T_IS_IDENTICAL expr
2682 // | expr T_IS_NOT_IDENTICAL expr
2683 // | expr T_IS_EQUAL expr
2684 // | expr T_IS_NOT_EQUAL expr
2686 // | expr T_IS_SMALLER_OR_EQUAL expr
2688 // | expr T_IS_GREATER_OR_EQUAL expr
2691 case TokenNameOR_OR:
2693 expression = new OR_OR_Expression(expression, expr(), token);
2695 case TokenNameAND_AND:
2697 expression = new AND_AND_Expression(expression, expr(), token);
2699 case TokenNameEQUAL_EQUAL:
2701 expression = new EqualExpression(expression, expr(), token);
2711 case TokenNameMINUS:
2712 case TokenNameMULTIPLY:
2713 case TokenNameDIVIDE:
2714 case TokenNameREMAINDER:
2715 case TokenNameLEFT_SHIFT:
2716 case TokenNameRIGHT_SHIFT:
2717 case TokenNameEQUAL_EQUAL_EQUAL:
2718 case TokenNameNOT_EQUAL_EQUAL:
2719 case TokenNameNOT_EQUAL:
2721 case TokenNameLESS_EQUAL:
2722 case TokenNameGREATER:
2723 case TokenNameGREATER_EQUAL:
2725 expression = new BinaryExpression(expression, expr(), token);
2727 // | expr T_INSTANCEOF class_name_reference
2728 // | expr '?' expr ':' expr
2729 case TokenNameinstanceof:
2731 TypeReference classRef = class_name_reference();
2732 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2733 expression.sourceStart = exprSourceStart;
2734 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2736 case TokenNameQUESTION:
2738 Expression valueIfTrue = expr();
2739 if (token != TokenNameCOLON) {
2740 throwSyntaxError("':' expected in conditional expression.");
2743 Expression valueIfFalse = expr();
2745 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2751 } catch (SyntaxError e) {
2752 // try to find next token after expression with errors:
2753 if (token == TokenNameSEMICOLON) {
2757 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2765 private SingleTypeReference class_name_reference() {
2766 // class_name_reference:
2768 //| dynamic_class_name_reference
2769 SingleTypeReference ref = null;
2770 if (Scanner.TRACE) {
2771 System.out.println("TRACE: class_name_reference()");
2773 if (token == TokenNameIdentifier) {
2774 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2778 dynamic_class_name_reference();
2783 private void dynamic_class_name_reference() {
2784 //dynamic_class_name_reference:
2785 // base_variable T_OBJECT_OPERATOR object_property
2786 // dynamic_class_name_variable_properties
2788 if (Scanner.TRACE) {
2789 System.out.println("TRACE: dynamic_class_name_reference()");
2792 if (token == TokenNameMINUS_GREATER) {
2795 dynamic_class_name_variable_properties();
2799 private void dynamic_class_name_variable_properties() {
2800 // dynamic_class_name_variable_properties:
2801 // dynamic_class_name_variable_properties
2802 // dynamic_class_name_variable_property
2804 if (Scanner.TRACE) {
2805 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2807 while (token == TokenNameMINUS_GREATER) {
2808 dynamic_class_name_variable_property();
2812 private void dynamic_class_name_variable_property() {
2813 // dynamic_class_name_variable_property:
2814 // T_OBJECT_OPERATOR object_property
2815 if (Scanner.TRACE) {
2816 System.out.println("TRACE: dynamic_class_name_variable_property()");
2818 if (token == TokenNameMINUS_GREATER) {
2824 private void ctor_arguments() {
2827 //| '(' function_call_parameter_list ')'
2828 if (token == TokenNameLPAREN) {
2830 if (token == TokenNameRPAREN) {
2834 non_empty_function_call_parameter_list();
2835 if (token != TokenNameRPAREN) {
2836 throwSyntaxError("')' expected in ctor_arguments.");
2842 private void assignment_list() {
2844 // assignment_list ',' assignment_list_element
2845 //| assignment_list_element
2847 assignment_list_element();
2848 if (token != TokenNameCOMMA) {
2855 private void assignment_list_element() {
2856 //assignment_list_element:
2858 //| T_LIST '(' assignment_list ')'
2860 if (token == TokenNameVariable) {
2861 variable(true, false);
2862 } else if (token == TokenNameDOLLAR) {
2863 variable(false, false);
2865 if (token == TokenNamelist) {
2867 if (token == TokenNameLPAREN) {
2870 if (token != TokenNameRPAREN) {
2871 throwSyntaxError("')' expected after 'list' keyword.");
2875 throwSyntaxError("'(' expected after 'list' keyword.");
2881 private void array_pair_list() {
2884 //| non_empty_array_pair_list possible_comma
2885 non_empty_array_pair_list();
2886 if (token == TokenNameCOMMA) {
2891 private void non_empty_array_pair_list() {
2892 //non_empty_array_pair_list:
2893 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2894 //| non_empty_array_pair_list ',' expr
2895 //| expr T_DOUBLE_ARROW expr
2897 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2898 //| non_empty_array_pair_list ',' '&' w_variable
2899 //| expr T_DOUBLE_ARROW '&' w_variable
2902 if (token == TokenNameAND) {
2904 variable(true, false);
2907 if (token == TokenNameAND) {
2909 variable(true, false);
2910 } else if (token == TokenNameEQUAL_GREATER) {
2912 if (token == TokenNameAND) {
2914 variable(true, false);
2920 if (token != TokenNameCOMMA) {
2924 if (token == TokenNameRPAREN) {
2930 // private void variableList() {
2933 // if (token == TokenNameCOMMA) {
2940 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2941 // variable_without_objects:
2942 // reference_variable
2943 // | simple_indirect_reference reference_variable
2944 if (Scanner.TRACE) {
2945 System.out.println("TRACE: variable_without_objects()");
2947 while (token == TokenNameDOLLAR) {
2950 return reference_variable(lefthandside, ignoreVar);
2953 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2955 // T_STRING '(' function_call_parameter_list ')'
2956 //| class_constant '(' function_call_parameter_list ')'
2957 //| static_member '(' function_call_parameter_list ')'
2958 //| variable_without_objects '(' function_call_parameter_list ')'
2959 char[] defineName = null;
2960 char[] ident = null;
2963 Expression ref = null;
2964 if (Scanner.TRACE) {
2965 System.out.println("TRACE: function_call()");
2967 if (token == TokenNameIdentifier) {
2968 ident = scanner.getCurrentIdentifierSource();
2970 startPos = scanner.getCurrentTokenStartPosition();
2971 endPos = scanner.getCurrentTokenEndPosition();
2974 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2978 if (token == TokenNameIdentifier) {
2983 variable_without_objects(true, false);
2988 ref = variable_without_objects(lefthandside, ignoreVar);
2990 if (token != TokenNameLPAREN) {
2991 if (defineName != null) {
2992 // does this identifier contain only uppercase characters?
2993 if (defineName.length == 3) {
2994 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2997 } else if (defineName.length == 4) {
2998 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3000 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3003 } else if (defineName.length == 5) {
3004 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3008 if (defineName != null) {
3009 for (int i = 0; i < defineName.length; i++) {
3010 if (Character.isLowerCase(defineName[i])) {
3011 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3017 // TODO is this ok ?
3019 // throwSyntaxError("'(' expected in function call.");
3022 if (token == TokenNameRPAREN) {
3026 non_empty_function_call_parameter_list();
3027 if (token != TokenNameRPAREN) {
3028 String functionName;
3029 if (ident == null) {
3030 functionName = new String(" ");
3032 functionName = new String(ident);
3034 throwSyntaxError("')' expected in function call (" + functionName + ").");
3040 // private void function_call_parameter_list() {
3041 // function_call_parameter_list:
3042 // non_empty_function_call_parameter_list { $$ = $1; }
3045 private void non_empty_function_call_parameter_list() {
3046 //non_empty_function_call_parameter_list:
3047 // expr_without_variable
3050 // | non_empty_function_call_parameter_list ',' expr_without_variable
3051 // | non_empty_function_call_parameter_list ',' variable
3052 // | non_empty_function_call_parameter_list ',' '&' w_variable
3053 if (Scanner.TRACE) {
3054 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3057 if (token == TokenNameAND) {
3061 // if (token == TokenNameIdentifier || token ==
3062 // TokenNameVariable
3063 // || token == TokenNameDOLLAR) {
3066 expr_without_variable(true);
3069 if (token != TokenNameCOMMA) {
3076 private void fully_qualified_class_name() {
3077 if (token == TokenNameIdentifier) {
3080 throwSyntaxError("Class name expected.");
3084 private void static_member() {
3086 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3087 // variable_without_objects
3088 if (Scanner.TRACE) {
3089 System.out.println("TRACE: static_member()");
3091 fully_qualified_class_name();
3092 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3093 throwSyntaxError("'::' expected after class name (static_member).");
3096 variable_without_objects(false, false);
3099 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3100 // base_variable_with_function_calls:
3103 boolean functionCall = false;
3104 if (Scanner.TRACE) {
3105 System.out.println("TRACE: base_variable_with_function_calls()");
3107 // if (token == TokenNameIdentifier) {
3108 // functionCall = true;
3109 // } else if (token == TokenNameVariable) {
3110 // int tempToken = token;
3111 // int tempPosition = scanner.currentPosition;
3113 // if (token == TokenNameLPAREN) {
3114 // functionCall = true;
3116 // token = tempToken;
3117 // scanner.currentPosition = tempPosition;
3118 // scanner.phpMode = true;
3120 // if (functionCall) {
3121 return function_call(lefthandside, ignoreVar);
3127 private Expression base_variable() {
3129 // reference_variable
3130 // | simple_indirect_reference reference_variable
3132 Expression ref = null;
3133 if (Scanner.TRACE) {
3134 System.out.println("TRACE: base_variable()");
3136 if (token == TokenNameIdentifier) {
3139 while (token == TokenNameDOLLAR) {
3142 reference_variable(false, false);
3147 // private void simple_indirect_reference() {
3148 // // simple_indirect_reference:
3150 // //| simple_indirect_reference '$'
3152 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3153 // reference_variable:
3154 // reference_variable '[' dim_offset ']'
3155 // | reference_variable '{' expr '}'
3156 // | compound_variable
3157 Expression ref = null;
3158 if (Scanner.TRACE) {
3159 System.out.println("TRACE: reference_variable()");
3161 ref = compound_variable(lefthandside, ignoreVar);
3163 if (token == TokenNameLBRACE) {
3167 if (token != TokenNameRBRACE) {
3168 throwSyntaxError("'}' expected in reference variable.");
3171 } else if (token == TokenNameLBRACKET) {
3172 if (ref != null && ref instanceof FieldReference) {
3173 FieldReference fref = (FieldReference) ref;
3174 addVariableSet(fref.token);
3178 if (token != TokenNameRBRACKET) {
3181 if (token != TokenNameRBRACKET) {
3182 throwSyntaxError("']' expected in reference variable.");
3193 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3194 // compound_variable:
3196 // | '$' '{' expr '}'
3197 if (Scanner.TRACE) {
3198 System.out.println("TRACE: compound_variable()");
3200 if (token == TokenNameVariable) {
3201 if (!lefthandside) {
3202 if (!containsVariableSet()) {
3203 // reportSyntaxError("The local variable " + new String(scanner.getCurrentIdentifierSource())
3204 // + " may not have been initialized");
3205 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3206 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3207 compilationUnit.compilationResult);
3214 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3218 // because of simple_indirect_reference
3219 while (token == TokenNameDOLLAR) {
3222 if (token != TokenNameLBRACE) {
3223 reportSyntaxError("'{' expected after compound variable token '$'.");
3228 if (token != TokenNameRBRACE) {
3229 throwSyntaxError("'}' expected after compound variable token '$'.");
3234 } // private void dim_offset() { // // dim_offset: // // /* empty */
3239 private void object_property() {
3242 //| variable_without_objects
3243 if (Scanner.TRACE) {
3244 System.out.println("TRACE: object_property()");
3246 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3247 variable_without_objects(false, false);
3253 private void object_dim_list() {
3255 // object_dim_list '[' dim_offset ']'
3256 //| object_dim_list '{' expr '}'
3258 if (Scanner.TRACE) {
3259 System.out.println("TRACE: object_dim_list()");
3263 if (token == TokenNameLBRACE) {
3266 if (token != TokenNameRBRACE) {
3267 throwSyntaxError("'}' expected in object_dim_list.");
3270 } else if (token == TokenNameLBRACKET) {
3272 if (token == TokenNameRBRACKET) {
3277 if (token != TokenNameRBRACKET) {
3278 throwSyntaxError("']' expected in object_dim_list.");
3287 private void variable_name() {
3291 if (Scanner.TRACE) {
3292 System.out.println("TRACE: variable_name()");
3294 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3295 if (token > TokenNameKEYWORD) {
3296 // TODO show a warning "Keyword used as variable" ?
3300 if (token != TokenNameLBRACE) {
3301 throwSyntaxError("'{' expected in variable name.");
3305 if (token != TokenNameRBRACE) {
3306 throwSyntaxError("'}' expected in variable name.");
3312 private void r_variable() {
3313 variable(false, false);
3316 private void w_variable(boolean lefthandside) {
3317 variable(lefthandside, false);
3320 private void rw_variable() {
3321 variable(false, false);
3324 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3326 // base_variable_with_function_calls T_OBJECT_OPERATOR
3327 // object_property method_or_not variable_properties
3328 // | base_variable_with_function_calls
3329 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3330 if (token == TokenNameMINUS_GREATER) {
3335 variable_properties();
3340 private void variable_properties() {
3341 // variable_properties:
3342 // variable_properties variable_property
3344 while (token == TokenNameMINUS_GREATER) {
3345 variable_property();
3349 private void variable_property() {
3350 // variable_property:
3351 // T_OBJECT_OPERATOR object_property method_or_not
3352 if (Scanner.TRACE) {
3353 System.out.println("TRACE: variable_property()");
3355 if (token == TokenNameMINUS_GREATER) {
3360 throwSyntaxError("'->' expected in variable_property.");
3364 private void method_or_not() {
3366 // '(' function_call_parameter_list ')'
3368 if (Scanner.TRACE) {
3369 System.out.println("TRACE: method_or_not()");
3371 if (token == TokenNameLPAREN) {
3373 if (token == TokenNameRPAREN) {
3377 non_empty_function_call_parameter_list();
3378 if (token != TokenNameRPAREN) {
3379 throwSyntaxError("')' expected in method_or_not.");
3385 private void exit_expr() {
3389 if (token != TokenNameLPAREN) {
3393 if (token == TokenNameRPAREN) {
3398 if (token != TokenNameRPAREN) {
3399 throwSyntaxError("')' expected after keyword 'exit'");
3404 private void encaps_list() {
3405 // encaps_list encaps_var
3406 // | encaps_list T_STRING
3407 // | encaps_list T_NUM_STRING
3408 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3409 // | encaps_list T_CHARACTER
3410 // | encaps_list T_BAD_CHARACTER
3411 // | encaps_list '['
3412 // | encaps_list ']'
3413 // | encaps_list '{'
3414 // | encaps_list '}'
3415 // | encaps_list T_OBJECT_OPERATOR
3419 case TokenNameSTRING:
3422 case TokenNameLBRACE:
3423 // scanner.encapsedStringStack.pop();
3426 case TokenNameRBRACE:
3427 // scanner.encapsedStringStack.pop();
3430 case TokenNameLBRACKET:
3431 // scanner.encapsedStringStack.pop();
3434 case TokenNameRBRACKET:
3435 // scanner.encapsedStringStack.pop();
3438 case TokenNameMINUS_GREATER:
3439 // scanner.encapsedStringStack.pop();
3442 case TokenNameVariable:
3443 case TokenNameDOLLAR_LBRACE:
3444 case TokenNameLBRACE_DOLLAR:
3448 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3449 if (encapsedChar == '$') {
3450 scanner.encapsedStringStack.pop();
3451 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3452 switch (encapsedChar) {
3454 if (token == TokenNameEncapsedString0) {
3457 token = TokenNameSTRING;
3460 if (token == TokenNameEncapsedString1) {
3463 token = TokenNameSTRING;
3466 if (token == TokenNameEncapsedString2) {
3469 token = TokenNameSTRING;
3478 private void encaps_var() {
3480 // | T_VARIABLE '[' encaps_var_offset ']'
3481 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3482 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3483 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3484 // | T_CURLY_OPEN variable '}'
3486 case TokenNameVariable:
3488 if (token == TokenNameLBRACKET) {
3490 expr(); //encaps_var_offset();
3491 if (token != TokenNameRBRACKET) {
3492 throwSyntaxError("']' expected after variable.");
3494 // scanner.encapsedStringStack.pop();
3497 } else if (token == TokenNameMINUS_GREATER) {
3499 if (token != TokenNameIdentifier) {
3500 throwSyntaxError("Identifier expected after '->'.");
3502 // scanner.encapsedStringStack.pop();
3506 // // scanner.encapsedStringStack.pop();
3507 // int tempToken = TokenNameSTRING;
3508 // if (!scanner.encapsedStringStack.isEmpty()
3509 // && (token == TokenNameEncapsedString0
3510 // || token == TokenNameEncapsedString1
3511 // || token == TokenNameEncapsedString2 || token ==
3512 // TokenNameERROR)) {
3513 // char encapsedChar = ((Character)
3514 // scanner.encapsedStringStack.peek())
3517 // case TokenNameEncapsedString0 :
3518 // if (encapsedChar == '`') {
3519 // tempToken = TokenNameEncapsedString0;
3522 // case TokenNameEncapsedString1 :
3523 // if (encapsedChar == '\'') {
3524 // tempToken = TokenNameEncapsedString1;
3527 // case TokenNameEncapsedString2 :
3528 // if (encapsedChar == '"') {
3529 // tempToken = TokenNameEncapsedString2;
3532 // case TokenNameERROR :
3533 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3534 // scanner.currentPosition--;
3540 // token = tempToken;
3543 case TokenNameDOLLAR_LBRACE:
3545 if (token == TokenNameDOLLAR_LBRACE) {
3547 } else if (token == TokenNameIdentifier) {
3549 if (token == TokenNameLBRACKET) {
3551 // if (token == TokenNameRBRACKET) {
3555 if (token != TokenNameRBRACKET) {
3556 throwSyntaxError("']' expected after '${'.");
3564 if (token != TokenNameRBRACE) {
3565 throwSyntaxError("'}' expected.");
3569 case TokenNameLBRACE_DOLLAR:
3571 if (token == TokenNameLBRACE_DOLLAR) {
3573 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3575 if (token == TokenNameLBRACKET) {
3577 // if (token == TokenNameRBRACKET) {
3581 if (token != TokenNameRBRACKET) {
3582 throwSyntaxError("']' expected.");
3586 } else if (token == TokenNameMINUS_GREATER) {
3588 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3589 throwSyntaxError("String or Variable token expected.");
3592 if (token == TokenNameLBRACKET) {
3594 // if (token == TokenNameRBRACKET) {
3598 if (token != TokenNameRBRACKET) {
3599 throwSyntaxError("']' expected after '${'.");
3605 // if (token != TokenNameRBRACE) {
3606 // throwSyntaxError("'}' expected after '{$'.");
3608 // // scanner.encapsedStringStack.pop();
3612 if (token != TokenNameRBRACE) {
3613 throwSyntaxError("'}' expected.");
3615 // scanner.encapsedStringStack.pop();
3622 private void encaps_var_offset() {
3627 case TokenNameSTRING:
3630 case TokenNameIntegerLiteral:
3633 case TokenNameVariable:
3636 case TokenNameIdentifier:
3640 throwSyntaxError("Variable or String token expected.");
3645 private void internal_functions_in_yacc() {
3648 // case TokenNameisset:
3649 // // T_ISSET '(' isset_variables ')'
3651 // if (token != TokenNameLPAREN) {
3652 // throwSyntaxError("'(' expected after keyword 'isset'");
3655 // isset_variables();
3656 // if (token != TokenNameRPAREN) {
3657 // throwSyntaxError("')' expected after keyword 'isset'");
3661 // case TokenNameempty:
3662 // // T_EMPTY '(' variable ')'
3664 // if (token != TokenNameLPAREN) {
3665 // throwSyntaxError("'(' expected after keyword 'empty'");
3669 // if (token != TokenNameRPAREN) {
3670 // throwSyntaxError("')' expected after keyword 'empty'");
3674 case TokenNameinclude:
3676 checkFileName(token);
3678 case TokenNameinclude_once:
3679 // T_INCLUDE_ONCE expr
3680 checkFileName(token);
3683 // T_EVAL '(' expr ')'
3685 if (token != TokenNameLPAREN) {
3686 throwSyntaxError("'(' expected after keyword 'eval'");
3690 if (token != TokenNameRPAREN) {
3691 throwSyntaxError("')' expected after keyword 'eval'");
3695 case TokenNamerequire:
3697 checkFileName(token);
3699 case TokenNamerequire_once:
3700 // T_REQUIRE_ONCE expr
3701 checkFileName(token);
3706 private void checkFileName(int includeToken) {
3707 //<include-token> expr
3708 int start = scanner.getCurrentTokenStartPosition();
3709 boolean hasLPAREN = false;
3711 if (token == TokenNameLPAREN) {
3715 Expression expression = expr();
3717 if (token == TokenNameRPAREN) {
3720 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3723 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3725 if (scanner.compilationUnit != null) {
3726 IResource resource = scanner.compilationUnit.getResource();
3727 if (resource != null && resource instanceof IFile) {
3728 file = (IFile) resource;
3732 tokens = new char[1][];
3733 tokens[0] = currTokenSource;
3735 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3736 impt.declarationSourceEnd = impt.sourceEnd;
3737 impt.declarationEnd = impt.declarationSourceEnd;
3738 //endPosition is just before the ;
3739 impt.declarationSourceStart = start;
3740 includesList.add(impt);
3742 if (expression instanceof StringLiteral) {
3743 StringLiteral literal = (StringLiteral) expression;
3744 char[] includeName = literal.source();
3745 if (includeName.length == 0) {
3746 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3747 literal.sourceStart + 1);
3749 String includeNameString = new String(includeName);
3750 if (literal instanceof StringLiteralDQ) {
3751 if (includeNameString.indexOf('$') >= 0) {
3752 // assuming that the filename contains a variable => no filename check
3756 if (includeNameString.startsWith("http://")) {
3757 // assuming external include location
3761 // check the filename:
3762 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3763 IProject project = file.getProject();
3764 if (project != null) {
3765 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3768 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3769 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3770 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3771 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3772 compilationUnit.compilationResult);
3775 // String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
3776 // String filePath = file.getRawLocation().toString();
3777 String filePath = path.toString();
3778 String ext = file.getRawLocation().getFileExtension();
3779 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3782 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3783 impt.setFile(PHPFileUtil.createFile(path, project));
3784 } catch (Exception e) {
3785 // the file is outside of the workspace
3793 private void isset_variables() {
3795 // | isset_variables ','
3796 if (token == TokenNameRPAREN) {
3797 throwSyntaxError("Variable expected after keyword 'isset'");
3800 variable(true, false);
3801 if (token == TokenNameCOMMA) {
3809 private boolean common_scalar() {
3813 // | T_CONSTANT_ENCAPSED_STRING
3820 case TokenNameIntegerLiteral:
3823 case TokenNameDoubleLiteral:
3826 case TokenNameStringDoubleQuote:
3829 case TokenNameStringSingleQuote:
3832 case TokenNameStringInterpolated:
3841 case TokenNameCLASS_C:
3844 case TokenNameMETHOD_C:
3847 case TokenNameFUNC_C:
3854 private void scalar() {
3857 //| T_STRING_VARNAME
3860 //| '"' encaps_list '"'
3861 //| '\'' encaps_list '\''
3862 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3863 throwSyntaxError("Not yet implemented (scalar).");
3866 private void static_scalar() {
3867 // static_scalar: /* compile-time evaluated scalars */
3870 // | '+' static_scalar
3871 // | '-' static_scalar
3872 // | T_ARRAY '(' static_array_pair_list ')'
3873 // | static_class_constant
3874 if (common_scalar()) {
3878 case TokenNameIdentifier:
3880 // static_class_constant:
3881 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3882 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3884 if (token == TokenNameIdentifier) {
3887 throwSyntaxError("Identifier expected after '::' operator.");
3891 case TokenNameEncapsedString0:
3893 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3894 while (scanner.currentCharacter != '`') {
3895 if (scanner.currentCharacter == '\\') {
3896 scanner.currentPosition++;
3898 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3901 } catch (IndexOutOfBoundsException e) {
3902 throwSyntaxError("'`' expected at end of static string.");
3905 case TokenNameEncapsedString1:
3907 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3908 while (scanner.currentCharacter != '\'') {
3909 if (scanner.currentCharacter == '\\') {
3910 scanner.currentPosition++;
3912 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3915 } catch (IndexOutOfBoundsException e) {
3916 throwSyntaxError("'\'' expected at end of static string.");
3919 case TokenNameEncapsedString2:
3921 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3922 while (scanner.currentCharacter != '"') {
3923 if (scanner.currentCharacter == '\\') {
3924 scanner.currentPosition++;
3926 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3929 } catch (IndexOutOfBoundsException e) {
3930 throwSyntaxError("'\"' expected at end of static string.");
3937 case TokenNameMINUS:
3941 case TokenNamearray:
3943 if (token != TokenNameLPAREN) {
3944 throwSyntaxError("'(' expected after keyword 'array'");
3947 if (token == TokenNameRPAREN) {
3951 non_empty_static_array_pair_list();
3952 if (token != TokenNameRPAREN) {
3953 throwSyntaxError("')' or ',' expected after keyword 'array'");
3957 // case TokenNamenull :
3960 // case TokenNamefalse :
3963 // case TokenNametrue :
3967 throwSyntaxError("Static scalar/constant expected.");
3971 private void non_empty_static_array_pair_list() {
3972 // non_empty_static_array_pair_list:
3973 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3975 //| non_empty_static_array_pair_list ',' static_scalar
3976 //| static_scalar T_DOUBLE_ARROW static_scalar
3980 if (token == TokenNameEQUAL_GREATER) {
3984 if (token != TokenNameCOMMA) {
3988 if (token == TokenNameRPAREN) {
3994 public void reportSyntaxError() { //int act, int currentKind, int
3996 /* remember current scanner position */
3997 int startPos = scanner.startPosition;
3998 int currentPos = scanner.currentPosition;
3999 // String[] expectings;
4000 // String tokenName = name[symbol_index[currentKind]];
4001 //fetch all "accurate" possible terminals that could recover the error
4002 // int start, end = start = asi(stack[stateStackTop]);
4003 // while (asr[end] != 0)
4005 // int length = end - start;
4006 // expectings = new String[length];
4007 // if (length != 0) {
4008 // char[] indexes = new char[length];
4009 // System.arraycopy(asr, start, indexes, 0, length);
4010 // for (int i = 0; i < length; i++) {
4011 // expectings[i] = name[symbol_index[indexes[i]]];
4014 //if the pb is an EOF, try to tell the user that they are some
4015 // if (tokenName.equals(UNEXPECTED_EOF)) {
4016 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
4017 // char[] tokenSource;
4019 // tokenSource = this.scanner.getCurrentTokenSource();
4020 // } catch (Exception e) {
4021 // tokenSource = new char[] {};
4023 // problemReporter().parseError(
4024 // this.scanner.startPosition,
4025 // this.scanner.currentPosition - 1,
4030 // } else { //the next test is HEAVILY grammar DEPENDENT.
4031 // if ((length == 14)
4032 // && (expectings[0] == "=") //$NON-NLS-1$
4033 // && (expectings[1] == "*=") //$NON-NLS-1$
4034 // && (expressionPtr > -1)) {
4035 // switch(currentKind) {
4036 // case TokenNameSEMICOLON:
4037 // case TokenNamePLUS:
4038 // case TokenNameMINUS:
4039 // case TokenNameDIVIDE:
4040 // case TokenNameREMAINDER:
4041 // case TokenNameMULTIPLY:
4042 // case TokenNameLEFT_SHIFT:
4043 // case TokenNameRIGHT_SHIFT:
4044 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
4045 // case TokenNameLESS:
4046 // case TokenNameGREATER:
4047 // case TokenNameLESS_EQUAL:
4048 // case TokenNameGREATER_EQUAL:
4049 // case TokenNameEQUAL_EQUAL:
4050 // case TokenNameNOT_EQUAL:
4051 // case TokenNameXOR:
4052 // case TokenNameAND:
4053 // case TokenNameOR:
4054 // case TokenNameOR_OR:
4055 // case TokenNameAND_AND:
4056 // // the ; is not the expected token ==> it ends a statement when an
4057 // expression is not ended
4058 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
4060 // case TokenNameRBRACE :
4061 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
4064 // char[] tokenSource;
4066 // tokenSource = this.scanner.getCurrentTokenSource();
4067 // } catch (Exception e) {
4068 // tokenSource = new char[] {};
4070 // problemReporter().parseError(
4071 // this.scanner.startPosition,
4072 // this.scanner.currentPosition - 1,
4076 // this.checkAndReportBracketAnomalies(problemReporter());
4081 tokenSource = this.scanner.getCurrentTokenSource();
4082 } catch (Exception e) {
4083 tokenSource = new char[] {};
4085 // problemReporter().parseError(
4086 // this.scanner.startPosition,
4087 // this.scanner.currentPosition - 1,
4091 this.checkAndReportBracketAnomalies(problemReporter());
4094 /* reset scanner where it was */
4095 scanner.startPosition = startPos;
4096 scanner.currentPosition = currentPos;
4099 public static final int RoundBracket = 0;
4101 public static final int SquareBracket = 1;
4103 public static final int CurlyBracket = 2;
4105 public static final int BracketKinds = 3;
4107 protected int[] nestedMethod; //the ptr is nestedType
4109 protected int nestedType, dimensions;
4111 //variable set stack
4112 final static int VariableStackIncrement = 10;
4114 HashMap fTypeVariables = null;
4116 HashMap fMethodVariables = null;
4118 ArrayList fStackUnassigned = new ArrayList();
4121 final static int AstStackIncrement = 100;
4123 protected int astPtr;
4125 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4127 protected int astLengthPtr;
4129 protected int[] astLengthStack;
4131 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4133 public CompilationUnitDeclaration compilationUnit; /*
4134 * the result from parse()
4137 protected ReferenceContext referenceContext;
4139 protected ProblemReporter problemReporter;
4141 protected CompilerOptions options;
4143 private ArrayList includesList;
4145 // protected CompilationResult compilationResult;
4147 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
4148 * reported, so initializes the compilation result's line positions.
4150 public ProblemReporter problemReporter() {
4151 if (scanner.recordLineSeparator) {
4152 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4154 problemReporter.referenceContext = referenceContext;
4155 return problemReporter;
4159 * Reconsider the entire source looking for inconsistencies in {} () []
4161 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
4162 scanner.wasAcr = false;
4163 boolean anomaliesDetected = false;
4165 char[] source = scanner.source;
4166 int[] leftCount = { 0, 0, 0 };
4167 int[] rightCount = { 0, 0, 0 };
4168 int[] depths = { 0, 0, 0 };
4169 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
4170 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4171 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
4172 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
4173 scanner.currentPosition = scanner.initialPosition; //starting
4175 // (first-zero-based
4177 while (scanner.currentPosition < scanner.eofPosition) { //loop for
4182 // ---------Consume white space and handles
4183 // startPosition---------
4184 boolean isWhiteSpace;
4186 scanner.startPosition = scanner.currentPosition;
4187 // if (((scanner.currentCharacter =
4188 // source[scanner.currentPosition++]) == '\\') &&
4189 // (source[scanner.currentPosition] == 'u')) {
4190 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4192 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4193 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4194 // only record line positions we have not
4196 scanner.pushLineSeparator();
4199 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4201 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4202 // -------consume token until } is found---------
4203 switch (scanner.currentCharacter) {
4205 int index = leftCount[CurlyBracket]++;
4206 if (index == leftPositions[CurlyBracket].length) {
4207 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4208 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
4210 leftPositions[CurlyBracket][index] = scanner.startPosition;
4211 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4215 int index = rightCount[CurlyBracket]++;
4216 if (index == rightPositions[CurlyBracket].length) {
4217 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4218 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
4220 rightPositions[CurlyBracket][index] = scanner.startPosition;
4221 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4225 int index = leftCount[RoundBracket]++;
4226 if (index == leftPositions[RoundBracket].length) {
4227 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4228 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
4230 leftPositions[RoundBracket][index] = scanner.startPosition;
4231 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4235 int index = rightCount[RoundBracket]++;
4236 if (index == rightPositions[RoundBracket].length) {
4237 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4238 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
4240 rightPositions[RoundBracket][index] = scanner.startPosition;
4241 rightDepths[RoundBracket][index] = --depths[RoundBracket];
4245 int index = leftCount[SquareBracket]++;
4246 if (index == leftPositions[SquareBracket].length) {
4247 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4248 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
4250 leftPositions[SquareBracket][index] = scanner.startPosition;
4251 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4255 int index = rightCount[SquareBracket]++;
4256 if (index == rightPositions[SquareBracket].length) {
4257 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4258 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
4260 rightPositions[SquareBracket][index] = scanner.startPosition;
4261 rightDepths[SquareBracket][index] = --depths[SquareBracket];
4265 if (scanner.getNextChar('\\')) {
4266 scanner.scanEscapeCharacter();
4267 } else { // consume next character
4268 scanner.unicodeAsBackSlash = false;
4269 // if (((scanner.currentCharacter =
4270 // source[scanner.currentPosition++]) ==
4272 // (source[scanner.currentPosition] ==
4274 // scanner.getNextUnicodeChar();
4276 if (scanner.withoutUnicodePtr != 0) {
4277 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4281 scanner.getNextChar('\'');
4285 // consume next character
4286 scanner.unicodeAsBackSlash = false;
4287 // if (((scanner.currentCharacter =
4288 // source[scanner.currentPosition++]) == '\\') &&
4289 // (source[scanner.currentPosition] == 'u')) {
4290 // scanner.getNextUnicodeChar();
4292 if (scanner.withoutUnicodePtr != 0) {
4293 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4296 while (scanner.currentCharacter != '"') {
4297 if (scanner.currentCharacter == '\r') {
4298 if (source[scanner.currentPosition] == '\n')
4299 scanner.currentPosition++;
4300 break; // the string cannot go further that
4303 if (scanner.currentCharacter == '\n') {
4304 break; // the string cannot go further that
4307 if (scanner.currentCharacter == '\\') {
4308 scanner.scanEscapeCharacter();
4310 // consume next character
4311 scanner.unicodeAsBackSlash = false;
4312 // if (((scanner.currentCharacter =
4313 // source[scanner.currentPosition++]) == '\\')
4314 // && (source[scanner.currentPosition] == 'u'))
4316 // scanner.getNextUnicodeChar();
4318 if (scanner.withoutUnicodePtr != 0) {
4319 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4326 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4329 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4330 && (source[scanner.currentPosition] == 'u')) {
4331 //-------------unicode traitement
4333 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4334 scanner.currentPosition++;
4335 while (source[scanner.currentPosition] == 'u') {
4336 scanner.currentPosition++;
4338 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4339 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4340 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4341 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4345 scanner.currentCharacter = 'A';
4346 } //something different from \n and \r
4348 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4351 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
4353 scanner.startPosition = scanner.currentPosition;
4354 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4355 && (source[scanner.currentPosition] == 'u')) {
4356 //-------------unicode traitement
4358 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4359 scanner.currentPosition++;
4360 while (source[scanner.currentPosition] == 'u') {
4361 scanner.currentPosition++;
4363 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4364 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4365 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4366 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4370 scanner.currentCharacter = 'A';
4371 } //something different from \n
4374 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4378 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4379 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4380 // only record line positions we
4381 // have not recorded yet
4382 scanner.pushLineSeparator();
4383 if (this.scanner.taskTags != null) {
4384 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4385 .getCurrentTokenEndPosition());
4391 if (test > 0) { //traditional and annotation
4393 boolean star = false;
4394 // consume next character
4395 scanner.unicodeAsBackSlash = false;
4396 // if (((scanner.currentCharacter =
4397 // source[scanner.currentPosition++]) ==
4399 // (source[scanner.currentPosition] ==
4401 // scanner.getNextUnicodeChar();
4403 if (scanner.withoutUnicodePtr != 0) {
4404 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4407 if (scanner.currentCharacter == '*') {
4411 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4412 && (source[scanner.currentPosition] == 'u')) {
4413 //-------------unicode traitement
4415 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4416 scanner.currentPosition++;
4417 while (source[scanner.currentPosition] == 'u') {
4418 scanner.currentPosition++;
4420 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4421 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4422 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4423 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4427 scanner.currentCharacter = 'A';
4428 } //something different from * and /
4430 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4433 //loop until end of comment */
4434 while ((scanner.currentCharacter != '/') || (!star)) {
4435 star = scanner.currentCharacter == '*';
4437 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4438 && (source[scanner.currentPosition] == 'u')) {
4439 //-------------unicode traitement
4441 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4442 scanner.currentPosition++;
4443 while (source[scanner.currentPosition] == 'u') {
4444 scanner.currentPosition++;
4446 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4447 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4448 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4449 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4453 scanner.currentCharacter = 'A';
4454 } //something different from * and
4457 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4461 if (this.scanner.taskTags != null) {
4462 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4469 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4470 scanner.scanIdentifierOrKeyword(false);
4473 if (Character.isDigit(scanner.currentCharacter)) {
4474 scanner.scanNumber(false);
4478 //-----------------end switch while
4479 // try--------------------
4480 } catch (IndexOutOfBoundsException e) {
4481 break; // read until EOF
4482 } catch (InvalidInputException e) {
4483 return false; // no clue
4486 if (scanner.recordLineSeparator) {
4487 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4489 // check placement anomalies against other kinds of brackets
4490 for (int kind = 0; kind < BracketKinds; kind++) {
4491 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4492 int start = leftPositions[kind][leftIndex]; // deepest
4494 // find matching closing bracket
4495 int depth = leftDepths[kind][leftIndex];
4497 for (int i = 0; i < rightCount[kind]; i++) {
4498 int pos = rightPositions[kind][i];
4499 // want matching bracket further in source with same
4501 if ((pos > start) && (depth == rightDepths[kind][i])) {
4506 if (end < 0) { // did not find a good closing match
4507 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4510 // check if even number of opening/closing other brackets
4511 // in between this pair of brackets
4513 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4514 for (int i = 0; i < leftCount[otherKind]; i++) {
4515 int pos = leftPositions[otherKind][i];
4516 if ((pos > start) && (pos < end))
4519 for (int i = 0; i < rightCount[otherKind]; i++) {
4520 int pos = rightPositions[otherKind][i];
4521 if ((pos > start) && (pos < end))
4525 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4531 // too many opening brackets ?
4532 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4533 anomaliesDetected = true;
4534 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4535 compilationUnit.compilationResult);
4537 // too many closing brackets ?
4538 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4539 anomaliesDetected = true;
4540 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4542 if (anomaliesDetected)
4545 return anomaliesDetected;
4546 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4547 return anomaliesDetected;
4548 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4549 return anomaliesDetected;
4553 protected void pushOnAstLengthStack(int pos) {
4555 astLengthStack[++astLengthPtr] = pos;
4556 } catch (IndexOutOfBoundsException e) {
4557 int oldStackLength = astLengthStack.length;
4558 int[] oldPos = astLengthStack;
4559 astLengthStack = new int[oldStackLength + StackIncrement];
4560 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4561 astLengthStack[astLengthPtr] = pos;
4565 protected void pushOnAstStack(ASTNode node) {
4567 * add a new obj on top of the ast stack
4570 astStack[++astPtr] = node;
4571 } catch (IndexOutOfBoundsException e) {
4572 int oldStackLength = astStack.length;
4573 ASTNode[] oldStack = astStack;
4574 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4575 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4576 astPtr = oldStackLength;
4577 astStack[astPtr] = node;
4580 astLengthStack[++astLengthPtr] = 1;
4581 } catch (IndexOutOfBoundsException e) {
4582 int oldStackLength = astLengthStack.length;
4583 int[] oldPos = astLengthStack;
4584 astLengthStack = new int[oldStackLength + AstStackIncrement];
4585 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4586 astLengthStack[astLengthPtr] = 1;
4590 protected void resetModifiers() {
4591 this.modifiers = AccDefault;
4592 this.modifiersSourceStart = -1; // <-- see comment into
4593 // modifiersFlag(int)
4594 this.scanner.commentPtr = -1;
4597 protected void consumePackageDeclarationName(IFile file) {
4598 // create a package name similar to java package names
4599 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4600 String filePath = file.getRawLocation().toString();
4601 String ext = file.getRawLocation().getFileExtension();
4602 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4603 ImportReference impt;
4606 if (filePath.startsWith(projectPath)) {
4607 tokens = CharOperation
4608 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4610 String name = file.getName();
4611 tokens = new char[1][];
4612 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4615 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4617 impt.declarationSourceStart = 0;
4618 impt.declarationSourceEnd = 0;
4619 impt.declarationEnd = 0;
4620 //endPosition is just before the ;
4624 public final static String[] GLOBALS = {
4639 private void pushFunctionVariableSet() {
4640 HashSet set = new HashSet();
4641 if (fStackUnassigned.isEmpty()) {
4642 for (int i = 0; i < GLOBALS.length; i++) {
4643 set.add(GLOBALS[i]);
4646 fStackUnassigned.add(set);
4649 private void pushIfVariableSet() {
4650 if (!fStackUnassigned.isEmpty()) {
4651 HashSet set = new HashSet();
4652 fStackUnassigned.add(set);
4656 private HashSet removeIfVariableSet() {
4657 if (!fStackUnassigned.isEmpty()) {
4658 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4664 * Returns the <i>set of assigned variables </i> returns null if no Set is defined at the current scanner position
4666 private HashSet peekVariableSet() {
4667 if (!fStackUnassigned.isEmpty()) {
4668 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4674 * add the current identifier source to the <i>set of assigned variables </i>
4678 private void addVariableSet(HashSet set) {
4680 set.add(new String(scanner.getCurrentTokenSource()));
4685 * add the current identifier source to the <i>set of assigned variables </i>
4688 private void addVariableSet() {
4689 HashSet set = peekVariableSet();
4691 set.add(new String(scanner.getCurrentTokenSource()));
4696 * add the current identifier source to the <i>set of assigned variables </i>
4699 private void addVariableSet(char[] token) {
4700 HashSet set = peekVariableSet();
4702 set.add(new String(token));
4707 * check if the current identifier source is in the <i>set of assigned variables </i> Returns true, if no set is defined for the
4708 * current scanner position
4711 private boolean containsVariableSet() {
4712 return containsVariableSet(scanner.getCurrentTokenSource());
4713 // if (!fStackUnassigned.isEmpty()) {
4715 // String str = new String(scanner.getCurrentTokenSource());
4716 // for (int i = 0; i < fStackUnassigned.size(); i++) {
4717 // set = (HashSet) fStackUnassigned.get(i);
4718 // if (set.contains(str)) {
4727 private boolean containsVariableSet(char[] token) {
4729 if (!fStackUnassigned.isEmpty()) {
4731 String str = new String(token);
4732 for (int i = 0; i < fStackUnassigned.size(); i++) {
4733 set = (HashSet) fStackUnassigned.get(i);
4734 if (set.contains(str)) {