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;
13 import java.util.Stack;
15 import net.sourceforge.phpdt.core.compiler.CharOperation;
16 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
17 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
18 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
21 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
23 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
24 import net.sourceforge.phpdt.internal.compiler.util.Util;
25 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
26 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
54 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
56 import org.eclipse.core.resources.IFile;
57 import org.eclipse.core.resources.IProject;
58 import org.eclipse.core.resources.IResource;
59 import org.eclipse.core.runtime.IPath;
61 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
62 protected final static int StackIncrement = 255;
64 protected int stateStackTop;
66 // protected int[] stack = new int[StackIncrement];
68 public int firstToken; // handle for multiple parsing goals
70 public int lastAct; //handle for multiple parsing goals
72 // protected RecoveredElement currentElement;
74 public static boolean VERBOSE_RECOVERY = false;
76 protected boolean diet = false; //tells the scanner to jump over some
78 // parts of the code/expressions like
81 public Scanner scanner;
83 // private ArrayList phpList;
85 // private int currentPHPString;
87 // private boolean phpEnd;
89 // private static HashMap keywordMap = null;
97 // row counter for syntax errors:
99 // column counter for syntax errors:
103 // // current identifier
104 // String identifier;
107 // Double doubleNumber;
109 // private String stringValue;
111 /** Contains the current expression. */
112 // private StringBuffer expression;
113 //private boolean phpMode;
114 protected int modifiers;
116 protected int modifiersSourceStart;
118 protected Parser(ProblemReporter problemReporter) {
119 this.problemReporter = problemReporter;
120 this.options = problemReporter.options;
121 // this.currentPHPString = 0;
122 // PHPParserSuperclass.fileToParse = fileToParse;
123 // this.phpList = null;
124 // this.indexManager = null;
126 this.token = TokenNameEOF;
128 // this.rowCount = 1;
129 // this.columnCount = 0;
130 // this.phpEnd = false;
132 this.initializeScanner();
135 public void setFileToParse(IFile fileToParse) {
136 // this.currentPHPString = 0;
137 // PHPParserSuperclass.fileToParse = fileToParse;
138 // this.phpList = null;
139 // this.indexManager = null;
141 this.token = TokenNameEOF;
142 // this.phpEnd = false;
143 this.initializeScanner();
147 * ClassDeclaration Constructor.
151 * Description of Parameter
154 public Parser(IFile fileToParse) {
155 // if (keywordMap == null) {
156 // keywordMap = new HashMap();
157 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
158 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
161 // this.currentPHPString = 0;
162 // PHPParserSuperclass.fileToParse = fileToParse;
163 // this.phpList = null;
164 this.includesList = null;
166 this.token = TokenNameEOF;
168 // this.rowCount = 1;
169 // this.columnCount = 0;
170 // this.phpEnd = false;
172 this.initializeScanner();
175 public void initializeScanner() {
176 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
177 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
178 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
182 * Create marker for the parse error
184 // private void setMarker(String message, int charStart, int charEnd, int
186 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
189 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
193 * @throws SyntaxError
196 private void throwSyntaxError(String error) {
197 int problemStartPosition = scanner.getCurrentTokenStartPosition();
198 int problemEndPosition = scanner.getCurrentTokenEndPosition();
199 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
203 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
207 * @throws SyntaxError
210 // private void throwSyntaxError(String error, int startRow) {
211 // throw new SyntaxError(startRow, 0, " ", error);
213 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
214 if (referenceContext != null) {
215 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
216 compilationUnit.compilationResult);
218 throw new SyntaxError(1, 0, " ", error);
221 private void reportSyntaxError(String error) {
222 int problemStartPosition = scanner.getCurrentTokenStartPosition();
223 int problemEndPosition = scanner.getCurrentTokenEndPosition();
224 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
227 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
228 if (referenceContext != null) {
229 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
230 compilationUnit.compilationResult);
234 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
235 if (referenceContext != null) {
236 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
237 compilationUnit.compilationResult);
242 * gets the next token from input
244 private void getNextToken() {
246 token = scanner.getNextToken();
248 int currentEndPosition = scanner.getCurrentTokenEndPosition();
249 int currentStartPosition = scanner.getCurrentTokenStartPosition();
250 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
251 System.out.println(scanner.toStringAction(token));
253 } catch (InvalidInputException e) {
254 token = TokenNameERROR;
255 String detailedMessage = e.getMessage();
257 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
258 throwSyntaxError("Unterminated string.");
259 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
260 throwSyntaxError("Unterminated commment.");
266 public void init(String s) {
268 this.token = TokenNameEOF;
269 this.includesList = new ArrayList();
271 // this.rowCount = 1;
272 // this.columnCount = 0;
273 // this.phpEnd = false;
274 // this.phpMode = false;
275 /* scanner initialization */
276 scanner.setSource(s.toCharArray());
277 scanner.setPHPMode(false);
281 protected void initialize(boolean phpMode) {
282 initialize(phpMode, null);
285 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
286 compilationUnit = null;
287 referenceContext = null;
288 this.includesList = new ArrayList();
289 // this.indexManager = indexManager;
291 this.token = TokenNameEOF;
293 // this.rowCount = 1;
294 // this.columnCount = 0;
295 // this.phpEnd = false;
296 // this.phpMode = phpMode;
297 scanner.setPHPMode(phpMode);
302 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
304 public void parse(String s) {
309 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
311 public void parse(String s, HashMap variables) {
312 fMethodVariables = variables;
313 fStackUnassigned = new ArrayList();
319 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
321 protected void parse() {
322 if (scanner.compilationUnit != null) {
323 IResource resource = scanner.compilationUnit.getResource();
324 if (resource != null && resource instanceof IFile) {
325 // set the package name
326 consumePackageDeclarationName((IFile) resource);
332 if (token != TokenNameEOF && token != TokenNameERROR) {
335 if (token != TokenNameEOF) {
336 if (token == TokenNameERROR) {
337 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
339 if (token == TokenNameRPAREN) {
340 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
342 if (token == TokenNameRBRACE) {
343 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
345 if (token == TokenNameRBRACKET) {
346 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
348 if (token == TokenNameLPAREN) {
349 throwSyntaxError("Read character '('; end-of-file not reached.");
351 if (token == TokenNameLBRACE) {
352 throwSyntaxError("Read character '{'; end-of-file not reached.");
354 if (token == TokenNameLBRACKET) {
355 throwSyntaxError("Read character '['; end-of-file not reached.");
357 throwSyntaxError("End-of-file not reached.");
360 } catch (SyntaxError sytaxErr1) {
362 // // if an error occured,
363 // // try to find keywords 'abstract' 'final' 'class' or 'function'
364 // // to parse the rest of the string
365 // boolean tokenize = scanner.tokenizeStrings;
367 // scanner.tokenizeStrings = true;
370 // while (token != TokenNameEOF) {
371 // if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
376 // if (token == TokenNameEOF) {
379 // } catch (SyntaxError sytaxErr2) {
382 // scanner.tokenizeStrings = tokenize;
391 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
393 public void parseFunction(String s, HashMap variables) {
395 scanner.phpMode = true;
396 parseFunction(variables);
400 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
402 protected void parseFunction(HashMap variables) {
404 boolean hasModifiers = member_modifiers();
405 if (token == TokenNamefunction) {
407 checkAndSetModifiers(AccPublic);
409 this.fMethodVariables = variables;
411 MethodDeclaration methodDecl = new MethodDeclaration(null);
412 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
413 methodDecl.modifiers = this.modifiers;
414 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
417 functionDefinition(methodDecl);
418 } catch (SyntaxError sytaxErr1) {
421 int sourceEnd = methodDecl.sourceEnd;
422 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
423 sourceEnd = methodDecl.declarationSourceStart + 1;
425 methodDecl.sourceEnd = sourceEnd;
426 methodDecl.declarationSourceEnd = sourceEnd;
431 protected CompilationUnitDeclaration endParse(int act) {
435 // if (currentElement != null) {
436 // currentElement.topElement().updateParseTree();
437 // if (VERBOSE_RECOVERY) {
438 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
439 // System.out.println("--------------------------"); //$NON-NLS-1$
440 // System.out.println(compilationUnit);
441 // System.out.println("----------------------------------"); //$NON-NLS-1$
444 if (diet & VERBOSE_RECOVERY) {
445 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
446 System.out.println("--------------------------"); //$NON-NLS-1$
447 System.out.println(compilationUnit);
448 System.out.println("----------------------------------"); //$NON-NLS-1$
451 if (scanner.recordLineSeparator) {
452 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
454 if (scanner.taskTags != null) {
455 for (int i = 0; i < scanner.foundTaskCount; i++) {
456 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
457 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
458 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
461 compilationUnit.imports = new ImportReference[includesList.size()];
462 for (int i = 0; i < includesList.size(); i++) {
463 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
465 return compilationUnit;
468 private Block statementList() {
469 boolean branchStatement = false;
471 int blockStart = scanner.getCurrentTokenStartPosition();
472 ArrayList blockStatements = new ArrayList();
475 statement = statement();
476 blockStatements.add(statement);
477 if (branchStatement && statement != null) {
478 // reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
479 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
480 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
482 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
483 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
484 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
485 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
486 return createBlock(blockStart, blockStatements);
488 branchStatement = checkUnreachableStatements(statement);
489 } catch (SyntaxError sytaxErr1) {
490 // if an error occured,
491 // try to find keywords
492 // to parse the rest of the string
493 boolean tokenize = scanner.tokenizeStrings;
495 scanner.tokenizeStrings = true;
498 while (token != TokenNameEOF) {
499 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
500 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
501 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
502 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
503 return createBlock(blockStart, blockStatements);
505 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
506 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
507 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
508 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
509 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
510 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
513 // System.out.println(scanner.toStringAction(token));
515 // System.out.println(scanner.toStringAction(token));
517 if (token == TokenNameEOF) {
521 scanner.tokenizeStrings = tokenize;
531 private boolean checkUnreachableStatements(Statement statement) {
532 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
534 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
542 * @param blockStatements
545 private Block createBlock(int blockStart, ArrayList blockStatements) {
546 int blockEnd = scanner.getCurrentTokenEndPosition();
547 Block b = Block.EmptyWith(blockStart, blockEnd);
548 b.statements = new Statement[blockStatements.size()];
549 blockStatements.toArray(b.statements);
553 private void functionBody(MethodDeclaration methodDecl) {
554 // '{' [statement-list] '}'
555 if (token == TokenNameLBRACE) {
558 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
559 throwSyntaxError("'{' expected in compound-statement.");
561 if (token != TokenNameRBRACE) {
564 if (token == TokenNameRBRACE) {
565 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
568 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
569 throwSyntaxError("'}' expected in compound-statement.");
573 private Statement statement() {
574 Statement statement = null;
575 Expression expression;
576 int sourceStart = scanner.getCurrentTokenStartPosition();
578 if (token == TokenNameif) {
579 // T_IF '(' expr ')' statement elseif_list else_single
580 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
582 if (token == TokenNameLPAREN) {
585 throwSyntaxError("'(' expected after 'if' keyword.");
588 if (token == TokenNameRPAREN) {
591 throwSyntaxError("')' expected after 'if' condition.");
593 // create basic IfStatement
594 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
595 if (token == TokenNameCOLON) {
597 ifStatementColon(ifStatement);
599 ifStatement(ifStatement);
602 } else if (token == TokenNameswitch) {
604 if (token == TokenNameLPAREN) {
607 throwSyntaxError("'(' expected after 'switch' keyword.");
610 if (token == TokenNameRPAREN) {
613 throwSyntaxError("')' expected after 'switch' condition.");
617 } else if (token == TokenNamefor) {
619 if (token == TokenNameLPAREN) {
622 throwSyntaxError("'(' expected after 'for' keyword.");
624 if (token == TokenNameSEMICOLON) {
628 if (token == TokenNameSEMICOLON) {
631 throwSyntaxError("';' expected after 'for'.");
634 if (token == TokenNameSEMICOLON) {
638 if (token == TokenNameSEMICOLON) {
641 throwSyntaxError("';' expected after 'for'.");
644 if (token == TokenNameRPAREN) {
648 if (token == TokenNameRPAREN) {
651 throwSyntaxError("')' expected after 'for'.");
656 } else if (token == TokenNamewhile) {
658 if (token == TokenNameLPAREN) {
661 throwSyntaxError("'(' expected after 'while' keyword.");
664 if (token == TokenNameRPAREN) {
667 throwSyntaxError("')' expected after 'while' condition.");
671 } else if (token == TokenNamedo) {
673 if (token == TokenNameLBRACE) {
675 if (token != TokenNameRBRACE) {
678 if (token == TokenNameRBRACE) {
681 throwSyntaxError("'}' expected after 'do' keyword.");
686 if (token == TokenNamewhile) {
688 if (token == TokenNameLPAREN) {
691 throwSyntaxError("'(' expected after 'while' keyword.");
694 if (token == TokenNameRPAREN) {
697 throwSyntaxError("')' expected after 'while' condition.");
700 throwSyntaxError("'while' expected after 'do' keyword.");
702 if (token == TokenNameSEMICOLON) {
705 if (token != TokenNameINLINE_HTML) {
706 throwSyntaxError("';' expected after do-while statement.");
711 } else if (token == TokenNameforeach) {
713 if (token == TokenNameLPAREN) {
716 throwSyntaxError("'(' expected after 'foreach' keyword.");
719 if (token == TokenNameas) {
722 throwSyntaxError("'as' expected after 'foreach' exxpression.");
726 foreach_optional_arg();
727 if (token == TokenNameEQUAL_GREATER) {
729 variable(false, false);
731 if (token == TokenNameRPAREN) {
734 throwSyntaxError("')' expected after 'foreach' expression.");
738 } else if (token == TokenNamebreak) {
741 if (token != TokenNameSEMICOLON) {
744 if (token == TokenNameSEMICOLON) {
745 sourceEnd = scanner.getCurrentTokenEndPosition();
748 if (token != TokenNameINLINE_HTML) {
749 throwSyntaxError("';' expected after 'break'.");
751 sourceEnd = scanner.getCurrentTokenEndPosition();
754 return new BreakStatement(null, sourceStart, sourceEnd);
755 } else if (token == TokenNamecontinue) {
758 if (token != TokenNameSEMICOLON) {
761 if (token == TokenNameSEMICOLON) {
762 sourceEnd = scanner.getCurrentTokenEndPosition();
765 if (token != TokenNameINLINE_HTML) {
766 throwSyntaxError("';' expected after 'continue'.");
768 sourceEnd = scanner.getCurrentTokenEndPosition();
771 return new ContinueStatement(null, sourceStart, sourceEnd);
772 } else if (token == TokenNamereturn) {
775 if (token != TokenNameSEMICOLON) {
778 if (token == TokenNameSEMICOLON) {
779 sourceEnd = scanner.getCurrentTokenEndPosition();
782 if (token != TokenNameINLINE_HTML) {
783 throwSyntaxError("';' expected after 'return'.");
785 sourceEnd = scanner.getCurrentTokenEndPosition();
788 return new ReturnStatement(expression, sourceStart, sourceEnd);
789 } else if (token == TokenNameecho) {
792 if (token == TokenNameSEMICOLON) {
795 if (token != TokenNameINLINE_HTML) {
796 throwSyntaxError("';' expected after 'echo' statement.");
801 } else if (token == TokenNameINLINE_HTML) {
804 // } else if (token == TokenNameprint) {
807 // if (token == TokenNameSEMICOLON) {
810 // if (token != TokenNameStopPHP) {
811 // throwSyntaxError("';' expected after 'print' statement.");
816 } else if (token == TokenNameglobal) {
819 if (token == TokenNameSEMICOLON) {
822 if (token != TokenNameINLINE_HTML) {
823 throwSyntaxError("';' expected after 'global' statement.");
828 } else if (token == TokenNamestatic) {
831 if (token == TokenNameSEMICOLON) {
834 if (token != TokenNameINLINE_HTML) {
835 throwSyntaxError("';' expected after 'static' statement.");
840 } else if (token == TokenNameunset) {
842 if (token == TokenNameLPAREN) {
845 throwSyntaxError("'(' expected after 'unset' statement.");
848 if (token == TokenNameRPAREN) {
851 throwSyntaxError("')' expected after 'unset' statement.");
853 if (token == TokenNameSEMICOLON) {
856 if (token != TokenNameINLINE_HTML) {
857 throwSyntaxError("';' expected after 'unset' statement.");
862 } else if (token == TokenNamefunction) {
863 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
864 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
865 methodDecl.modifiers = AccDefault;
866 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
869 functionDefinition(methodDecl);
871 sourceEnd = methodDecl.sourceEnd;
872 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
873 sourceEnd = methodDecl.declarationSourceStart + 1;
875 methodDecl.declarationSourceEnd = sourceEnd;
876 methodDecl.sourceEnd = sourceEnd;
879 } else if (token == TokenNamedeclare) {
880 //T_DECLARE '(' declare_list ')' declare_statement
882 if (token != TokenNameLPAREN) {
883 throwSyntaxError("'(' expected in 'declare' statement.");
887 if (token != TokenNameRPAREN) {
888 throwSyntaxError("')' expected in 'declare' statement.");
893 } else if (token == TokenNametry) {
895 if (token != TokenNameLBRACE) {
896 throwSyntaxError("'{' expected in 'try' statement.");
900 if (token != TokenNameRBRACE) {
901 throwSyntaxError("'}' expected in 'try' statement.");
905 } else if (token == TokenNamecatch) {
907 if (token != TokenNameLPAREN) {
908 throwSyntaxError("'(' expected in 'catch' statement.");
911 fully_qualified_class_name();
912 if (token != TokenNameVariable) {
913 throwSyntaxError("Variable expected in 'catch' statement.");
916 if (token != TokenNameRPAREN) {
917 throwSyntaxError("')' expected in 'catch' statement.");
920 if (token != TokenNameLBRACE) {
921 throwSyntaxError("'{' expected in 'catch' statement.");
924 if (token != TokenNameRBRACE) {
926 if (token != TokenNameRBRACE) {
927 throwSyntaxError("'}' expected in 'catch' statement.");
931 additional_catches();
933 } else if (token == TokenNamethrow) {
936 if (token == TokenNameSEMICOLON) {
939 throwSyntaxError("';' expected after 'throw' exxpression.");
942 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
944 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
945 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
946 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
947 typeDecl.name = new char[] { ' ' };
948 // default super class
949 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
950 compilationUnit.types.add(typeDecl);
951 pushOnAstStack(typeDecl);
952 unticked_class_declaration_statement(typeDecl);
960 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
961 } else if (token == TokenNameLBRACE) {
963 if (token != TokenNameRBRACE) {
964 statement = statementList();
966 if (token == TokenNameRBRACE) {
970 throwSyntaxError("'}' expected.");
973 if (token != TokenNameSEMICOLON) {
976 if (token == TokenNameSEMICOLON) {
980 if (token == TokenNameRBRACE) {
981 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
983 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
984 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
994 private void declare_statement() {
996 //| ':' inner_statement_list T_ENDDECLARE ';'
998 if (token == TokenNameCOLON) {
1000 // TODO: implement inner_statement_list();
1002 if (token != TokenNameenddeclare) {
1003 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1006 if (token != TokenNameSEMICOLON) {
1007 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1015 private void declare_list() {
1016 // T_STRING '=' static_scalar
1017 //| declare_list ',' T_STRING '=' static_scalar
1019 if (token != TokenNameIdentifier) {
1020 throwSyntaxError("Identifier expected in 'declare' list.");
1023 if (token != TokenNameEQUAL) {
1024 throwSyntaxError("'=' expected in 'declare' list.");
1028 if (token != TokenNameCOMMA) {
1035 private void additional_catches() {
1036 while (token == TokenNamecatch) {
1038 if (token != TokenNameLPAREN) {
1039 throwSyntaxError("'(' expected in 'catch' statement.");
1042 fully_qualified_class_name();
1043 if (token != TokenNameVariable) {
1044 throwSyntaxError("Variable expected in 'catch' statement.");
1047 if (token != TokenNameRPAREN) {
1048 throwSyntaxError("')' expected in 'catch' statement.");
1051 if (token != TokenNameLBRACE) {
1052 throwSyntaxError("'{' expected in 'catch' statement.");
1055 if (token != TokenNameRBRACE) {
1058 if (token != TokenNameRBRACE) {
1059 throwSyntaxError("'}' expected in 'catch' statement.");
1065 private void foreach_variable() {
1068 if (token == TokenNameAND) {
1074 private void foreach_optional_arg() {
1076 //| T_DOUBLE_ARROW foreach_variable
1077 if (token == TokenNameEQUAL_GREATER) {
1083 private void global_var_list() {
1085 // global_var_list ',' global_var
1087 HashSet set = peekVariableSet();
1090 if (token != TokenNameCOMMA) {
1097 private void global_var(HashSet set) {
1101 //| '$' '{' expr '}'
1102 if (token == TokenNameVariable) {
1103 if (fMethodVariables != null) {
1104 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1105 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1107 addVariableSet(set);
1109 } else if (token == TokenNameDOLLAR) {
1111 if (token == TokenNameLBRACE) {
1114 if (token != TokenNameRBRACE) {
1115 throwSyntaxError("'}' expected in global variable.");
1124 private void static_var_list() {
1126 // static_var_list ',' T_VARIABLE
1127 //| static_var_list ',' T_VARIABLE '=' static_scalar
1129 //| T_VARIABLE '=' static_scalar,
1130 HashSet set = peekVariableSet();
1132 if (token == TokenNameVariable) {
1133 if (fMethodVariables != null) {
1134 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1135 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1137 addVariableSet(set);
1139 if (token == TokenNameEQUAL) {
1143 if (token != TokenNameCOMMA) {
1153 private void unset_variables() {
1156 // | unset_variables ',' unset_variable
1160 variable(false, false);
1161 if (token != TokenNameCOMMA) {
1168 private final void initializeModifiers() {
1170 this.modifiersSourceStart = -1;
1173 private final void checkAndSetModifiers(int flag) {
1174 this.modifiers |= flag;
1175 if (this.modifiersSourceStart < 0)
1176 this.modifiersSourceStart = this.scanner.startPosition;
1179 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1180 initializeModifiers();
1181 if (token == TokenNameinterface) {
1182 // interface_entry T_STRING
1183 // interface_extends_list
1184 // '{' class_statement_list '}'
1185 checkAndSetModifiers(AccInterface);
1187 typeDecl.modifiers = this.modifiers;
1188 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1189 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1190 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1191 typeDecl.name = scanner.getCurrentIdentifierSource();
1192 if (token > TokenNameKEYWORD) {
1193 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1194 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1195 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1196 // typeDecl.sourceStart, typeDecl.sourceEnd);
1199 interface_extends_list(typeDecl);
1201 typeDecl.name = new char[] { ' ' };
1202 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1206 // class_entry_type T_STRING extends_from
1208 // '{' class_statement_list'}'
1210 typeDecl.modifiers = this.modifiers;
1211 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1212 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1214 //identifier 'extends' identifier
1215 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1216 typeDecl.name = scanner.getCurrentIdentifierSource();
1217 if (token > TokenNameKEYWORD) {
1218 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1219 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1220 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1221 // typeDecl.sourceStart, typeDecl.sourceEnd);
1226 // | T_EXTENDS fully_qualified_class_name
1227 if (token == TokenNameextends) {
1228 interface_extends_list(typeDecl);
1230 // if (token != TokenNameIdentifier) {
1231 // throwSyntaxError("Class name expected after keyword
1233 // scanner.getCurrentTokenStartPosition(), scanner
1234 // .getCurrentTokenEndPosition());
1237 implements_list(typeDecl);
1239 typeDecl.name = new char[] { ' ' };
1240 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1244 // '{' class_statement_list '}'
1245 if (token == TokenNameLBRACE) {
1247 if (token != TokenNameRBRACE) {
1248 ArrayList list = new ArrayList();
1249 class_statement_list(list);
1250 typeDecl.fields = new FieldDeclaration[list.size()];
1251 for (int i = 0; i < list.size(); i++) {
1252 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1255 if (token == TokenNameRBRACE) {
1256 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1259 throwSyntaxError("'}' expected at end of class body.");
1262 throwSyntaxError("'{' expected at start of class body.");
1266 private void class_entry_type() {
1268 // | T_ABSTRACT T_CLASS
1269 // | T_FINAL T_CLASS
1270 if (token == TokenNameclass) {
1272 } else if (token == TokenNameabstract) {
1273 checkAndSetModifiers(AccAbstract);
1275 if (token != TokenNameclass) {
1276 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1279 } else if (token == TokenNamefinal) {
1280 checkAndSetModifiers(AccFinal);
1282 if (token != TokenNameclass) {
1283 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1287 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1291 private void class_extends(TypeDeclaration typeDecl) {
1293 // | T_EXTENDS interface_list
1294 if (token == TokenNameextends) {
1297 if (token == TokenNameIdentifier) {
1300 throwSyntaxError("Class name expected after keyword 'extends'.");
1305 private void interface_extends_list(TypeDeclaration typeDecl) {
1307 // | T_EXTENDS interface_list
1308 if (token == TokenNameextends) {
1314 private void implements_list(TypeDeclaration typeDecl) {
1316 // | T_IMPLEMENTS interface_list
1317 if (token == TokenNameimplements) {
1323 private void interface_list() {
1325 // fully_qualified_class_name
1326 //| interface_list ',' fully_qualified_class_name
1328 if (token == TokenNameIdentifier) {
1331 throwSyntaxError("Interface name expected after keyword 'implements'.");
1333 if (token != TokenNameCOMMA) {
1340 // private void classBody(TypeDeclaration typeDecl) {
1341 // //'{' [class-element-list] '}'
1342 // if (token == TokenNameLBRACE) {
1344 // if (token != TokenNameRBRACE) {
1345 // class_statement_list();
1347 // if (token == TokenNameRBRACE) {
1348 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1351 // throwSyntaxError("'}' expected at end of class body.");
1354 // throwSyntaxError("'{' expected at start of class body.");
1357 private void class_statement_list(ArrayList list) {
1360 class_statement(list);
1361 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1362 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1363 || token == TokenNameconst) {
1366 if (token == TokenNameRBRACE) {
1369 throwSyntaxError("'}' at end of class statement.");
1370 } catch (SyntaxError sytaxErr1) {
1371 boolean tokenize = scanner.tokenizeStrings;
1373 scanner.tokenizeStrings = true;
1376 // if an error occured,
1377 // try to find keywords
1378 // to parse the rest of the string
1379 while (token != TokenNameEOF) {
1380 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1381 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1382 || token == TokenNameconst) {
1385 // System.out.println(scanner.toStringAction(token));
1388 if (token == TokenNameEOF) {
1392 scanner.tokenizeStrings = tokenize;
1398 private void class_statement(ArrayList list) {
1400 // variable_modifiers class_variable_declaration ';'
1401 // | class_constant_declaration ';'
1402 // | method_modifiers T_FUNCTION is_reference T_STRING
1403 // '(' parameter_list ')' method_body
1404 initializeModifiers();
1405 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1407 if (token == TokenNamevar) {
1408 checkAndSetModifiers(AccPublic);
1409 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1410 referenceContext, compilationUnit.compilationResult);
1412 class_variable_declaration(declarationSourceStart, list);
1413 } else if (token == TokenNameconst) {
1414 checkAndSetModifiers(AccFinal | AccPublic);
1415 class_constant_declaration(declarationSourceStart, list);
1416 if (token != TokenNameSEMICOLON) {
1417 throwSyntaxError("';' expected after class const declaration.");
1421 boolean hasModifiers = member_modifiers();
1422 if (token == TokenNamefunction) {
1423 if (!hasModifiers) {
1424 checkAndSetModifiers(AccPublic);
1426 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1427 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1428 methodDecl.modifiers = this.modifiers;
1429 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1432 functionDefinition(methodDecl);
1434 int sourceEnd = methodDecl.sourceEnd;
1435 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1436 sourceEnd = methodDecl.declarationSourceStart + 1;
1438 methodDecl.declarationSourceEnd = sourceEnd;
1439 methodDecl.sourceEnd = sourceEnd;
1442 if (!hasModifiers) {
1443 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1445 class_variable_declaration(declarationSourceStart, list);
1450 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1451 // class_constant_declaration ',' T_STRING '=' static_scalar
1452 // | T_CONST T_STRING '=' static_scalar
1453 if (token != TokenNameconst) {
1454 throwSyntaxError("'const' keyword expected in class declaration.");
1459 if (token != TokenNameIdentifier) {
1460 throwSyntaxError("Identifier expected in class const declaration.");
1462 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1463 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1464 fieldDeclaration.modifiers = this.modifiers;
1465 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1466 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1467 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1468 // fieldDeclaration.type
1469 list.add(fieldDeclaration);
1471 if (token != TokenNameEQUAL) {
1472 throwSyntaxError("'=' expected in class const declaration.");
1476 if (token != TokenNameCOMMA) {
1477 break; // while(true)-loop
1483 // private void variable_modifiers() {
1484 // // variable_modifiers:
1485 // // non_empty_member_modifiers
1487 // initializeModifiers();
1488 // if (token == TokenNamevar) {
1489 // checkAndSetModifiers(AccPublic);
1490 // reportSyntaxError(
1491 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1493 // modifier for field declarations.",
1494 // scanner.getCurrentTokenStartPosition(), scanner
1495 // .getCurrentTokenEndPosition());
1498 // if (!member_modifiers()) {
1499 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1500 // field declarations.");
1504 // private void method_modifiers() {
1505 // //method_modifiers:
1507 // //| non_empty_member_modifiers
1508 // initializeModifiers();
1509 // if (!member_modifiers()) {
1510 // checkAndSetModifiers(AccPublic);
1513 private boolean member_modifiers() {
1520 boolean foundToken = false;
1522 if (token == TokenNamepublic) {
1523 checkAndSetModifiers(AccPublic);
1526 } else if (token == TokenNameprotected) {
1527 checkAndSetModifiers(AccProtected);
1530 } else if (token == TokenNameprivate) {
1531 checkAndSetModifiers(AccPrivate);
1534 } else if (token == TokenNamestatic) {
1535 checkAndSetModifiers(AccStatic);
1538 } else if (token == TokenNameabstract) {
1539 checkAndSetModifiers(AccAbstract);
1542 } else if (token == TokenNamefinal) {
1543 checkAndSetModifiers(AccFinal);
1553 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1554 // class_variable_declaration:
1555 // class_variable_declaration ',' T_VARIABLE
1556 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1558 // | T_VARIABLE '=' static_scalar
1559 char[] classVariable;
1561 if (token == TokenNameVariable) {
1562 classVariable = scanner.getCurrentIdentifierSource();
1563 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1564 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1565 .getCurrentTokenEndPosition());
1566 fieldDeclaration.modifiers = this.modifiers;
1567 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1568 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1569 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1570 list.add(fieldDeclaration);
1571 if (fTypeVariables != null) {
1572 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1573 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1576 if (token == TokenNameEQUAL) {
1581 // if (token == TokenNamethis) {
1582 // throwSyntaxError("'$this' not allowed after keyword 'public'
1583 // 'protected' 'private' 'var'.");
1585 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1587 if (token != TokenNameCOMMA) {
1592 if (token != TokenNameSEMICOLON) {
1593 throwSyntaxError("';' expected after field declaration.");
1598 private void functionDefinition(MethodDeclaration methodDecl) {
1599 boolean isAbstract = false;
1601 if (compilationUnit != null) {
1602 compilationUnit.types.add(methodDecl);
1605 ASTNode node = astStack[astPtr];
1606 if (node instanceof TypeDeclaration) {
1607 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1608 if (typeDecl.methods == null) {
1609 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1611 AbstractMethodDeclaration[] newMethods;
1612 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1613 typeDecl.methods.length);
1614 newMethods[typeDecl.methods.length] = methodDecl;
1615 typeDecl.methods = newMethods;
1617 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1619 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1625 pushFunctionVariableSet();
1626 functionDeclarator(methodDecl);
1627 if (token == TokenNameSEMICOLON) {
1629 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1630 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1635 functionBody(methodDecl);
1637 if (!fStackUnassigned.isEmpty()) {
1638 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1643 private void functionDeclarator(MethodDeclaration methodDecl) {
1644 //identifier '(' [parameter-list] ')'
1645 if (token == TokenNameAND) {
1648 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1649 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1650 if (Scanner.isIdentifierOrKeyword(token)) {
1651 methodDecl.selector = scanner.getCurrentIdentifierSource();
1652 if (token > TokenNameKEYWORD) {
1653 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1654 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1657 if (token == TokenNameLPAREN) {
1660 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1661 throwSyntaxError("'(' expected in function declaration.");
1663 if (token != TokenNameRPAREN) {
1664 parameter_list(methodDecl);
1666 if (token != TokenNameRPAREN) {
1667 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1668 throwSyntaxError("')' expected in function declaration.");
1670 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1674 methodDecl.selector = "<undefined>".toCharArray();
1675 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1676 throwSyntaxError("Function name expected after keyword 'function'.");
1681 private void parameter_list(MethodDeclaration methodDecl) {
1682 // non_empty_parameter_list
1684 non_empty_parameter_list(methodDecl, true);
1687 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1688 // optional_class_type T_VARIABLE
1689 // | optional_class_type '&' T_VARIABLE
1690 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1691 // | optional_class_type T_VARIABLE '=' static_scalar
1692 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1693 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1694 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1696 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1698 char[] typeIdentifier = null;
1699 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1700 HashSet set = peekVariableSet();
1702 if (token == TokenNameIdentifier) {
1703 typeIdentifier = scanner.getCurrentIdentifierSource();
1706 if (token == TokenNameAND) {
1709 if (token == TokenNameVariable) {
1710 if (fMethodVariables != null) {
1712 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1713 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1715 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1717 info.typeIdentifier = typeIdentifier;
1718 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1720 addVariableSet(set);
1722 if (token == TokenNameEQUAL) {
1727 throwSyntaxError("Variable expected in parameter list.");
1729 if (token != TokenNameCOMMA) {
1736 if (!empty_allowed) {
1737 throwSyntaxError("Identifier expected in parameter list.");
1741 private void optional_class_type() {
1746 // private void parameterDeclaration() {
1748 // //variable-reference
1749 // if (token == TokenNameAND) {
1751 // if (isVariable()) {
1754 // throwSyntaxError("Variable expected after reference operator '&'.");
1757 // //variable '=' constant
1758 // if (token == TokenNameVariable) {
1760 // if (token == TokenNameEQUAL) {
1766 // // if (token == TokenNamethis) {
1767 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1768 // // declaration.");
1772 private void labeledStatementList() {
1773 if (token != TokenNamecase && token != TokenNamedefault) {
1774 throwSyntaxError("'case' or 'default' expected.");
1777 if (token == TokenNamecase) {
1779 expr(); //constant();
1780 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1782 if (token == TokenNamecase || token == TokenNamedefault) {
1783 // empty case statement ?
1788 // else if (token == TokenNameSEMICOLON) {
1790 // "':' expected after 'case' keyword (Found token: " +
1791 // scanner.toStringAction(token) + ")",
1792 // scanner.getCurrentTokenStartPosition(),
1793 // scanner.getCurrentTokenEndPosition(),
1796 // if (token == TokenNamecase) { // empty case statement ?
1802 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1804 } else { // TokenNamedefault
1806 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1808 if (token == TokenNameRBRACE) {
1809 // empty default case
1812 if (token != TokenNamecase) {
1816 throwSyntaxError("':' character expected after 'default'.");
1819 } while (token == TokenNamecase || token == TokenNamedefault);
1822 private void ifStatementColon(IfStatement iState) {
1823 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
1824 HashSet assignedVariableSet = null;
1826 Block b = inner_statement_list();
1827 iState.thenStatement = b;
1828 checkUnreachable(iState, b);
1830 assignedVariableSet = removeIfVariableSet();
1832 if (token == TokenNameelseif) {
1834 pushIfVariableSet();
1835 new_elseif_list(iState);
1837 HashSet set = removeIfVariableSet();
1838 if (assignedVariableSet != null) {
1839 assignedVariableSet.addAll(set);
1844 pushIfVariableSet();
1845 new_else_single(iState);
1847 HashSet set = removeIfVariableSet();
1848 if (assignedVariableSet != null) {
1849 HashSet topSet = peekVariableSet();
1850 if (topSet != null) {
1852 topSet.addAll(assignedVariableSet);
1856 if (token != TokenNameendif) {
1857 throwSyntaxError("'endif' expected.");
1860 if (token != TokenNameSEMICOLON) {
1861 reportSyntaxError("';' expected after if-statement.");
1862 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1864 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1869 private void ifStatement(IfStatement iState) {
1870 // T_IF '(' expr ')' statement elseif_list else_single
1871 HashSet assignedVariableSet = null;
1873 pushIfVariableSet();
1874 Statement s = statement();
1875 iState.thenStatement = s;
1876 checkUnreachable(iState, s);
1878 assignedVariableSet = removeIfVariableSet();
1881 if (token == TokenNameelseif) {
1883 pushIfVariableSet();
1884 elseif_list(iState);
1886 HashSet set = removeIfVariableSet();
1887 if (assignedVariableSet != null) {
1888 assignedVariableSet.addAll(set);
1893 pushIfVariableSet();
1894 else_single(iState);
1896 HashSet set = removeIfVariableSet();
1897 if (assignedVariableSet != null) {
1898 HashSet topSet = peekVariableSet();
1899 if (topSet != null) {
1901 topSet.addAll(assignedVariableSet);
1907 private void elseif_list(IfStatement iState) {
1909 //| elseif_list T_ELSEIF '(' expr ')' statement
1910 ArrayList conditionList = new ArrayList();
1911 ArrayList statementList = new ArrayList();
1914 while (token == TokenNameelseif) {
1916 if (token == TokenNameLPAREN) {
1919 throwSyntaxError("'(' expected after 'elseif' keyword.");
1922 conditionList.add(e);
1923 if (token == TokenNameRPAREN) {
1926 throwSyntaxError("')' expected after 'elseif' condition.");
1929 statementList.add(s);
1930 checkUnreachable(iState, s);
1932 iState.elseifConditions = new Expression[conditionList.size()];
1933 iState.elseifStatements = new Statement[statementList.size()];
1934 conditionList.toArray(iState.elseifConditions);
1935 statementList.toArray(iState.elseifStatements);
1938 private void new_elseif_list(IfStatement iState) {
1940 //| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1941 ArrayList conditionList = new ArrayList();
1942 ArrayList statementList = new ArrayList();
1945 while (token == TokenNameelseif) {
1947 if (token == TokenNameLPAREN) {
1950 throwSyntaxError("'(' expected after 'elseif' keyword.");
1953 conditionList.add(e);
1954 if (token == TokenNameRPAREN) {
1957 throwSyntaxError("')' expected after 'elseif' condition.");
1959 if (token == TokenNameCOLON) {
1962 throwSyntaxError("':' expected after 'elseif' keyword.");
1964 b = inner_statement_list();
1965 statementList.add(b);
1966 checkUnreachable(iState, b);
1968 iState.elseifConditions = new Expression[conditionList.size()];
1969 iState.elseifStatements = new Statement[statementList.size()];
1970 conditionList.toArray(iState.elseifConditions);
1971 statementList.toArray(iState.elseifStatements);
1974 private void else_single(IfStatement iState) {
1977 if (token == TokenNameelse) {
1979 Statement s = statement();
1980 iState.elseStatement = s;
1981 checkUnreachable(iState, s);
1983 iState.checkUnreachable = false;
1985 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1988 private void new_else_single(IfStatement iState) {
1990 //| T_ELSE ':' inner_statement_list
1991 if (token == TokenNameelse) {
1993 if (token == TokenNameCOLON) {
1996 throwSyntaxError("':' expected after 'else' keyword.");
1998 Block b = inner_statement_list();
1999 iState.elseStatement = b;
2000 checkUnreachable(iState, b);
2002 iState.checkUnreachable = false;
2006 private Block inner_statement_list() {
2007 // inner_statement_list inner_statement
2009 return statementList();
2016 private void checkUnreachable(IfStatement iState, Statement s) {
2017 if (s instanceof Block) {
2018 Block b = (Block) s;
2019 if (b.statements == null || b.statements.length == 0) {
2020 iState.checkUnreachable = false;
2022 int off = b.statements.length - 1;
2023 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2024 && !(b.statements[off] instanceof BreakStatement)) {
2025 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2026 iState.checkUnreachable = false;
2031 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2032 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2033 iState.checkUnreachable = false;
2039 // private void elseifStatementList() {
2041 // elseifStatement();
2043 // case TokenNameelse:
2045 // if (token == TokenNameCOLON) {
2047 // if (token != TokenNameendif) {
2052 // if (token == TokenNameif) { //'else if'
2055 // throwSyntaxError("':' expected after 'else'.");
2059 // case TokenNameelseif:
2068 // private void elseifStatement() {
2069 // if (token == TokenNameLPAREN) {
2072 // if (token != TokenNameRPAREN) {
2073 // throwSyntaxError("')' expected in else-if-statement.");
2076 // if (token != TokenNameCOLON) {
2077 // throwSyntaxError("':' expected in else-if-statement.");
2080 // if (token != TokenNameendif) {
2086 private void switchStatement() {
2087 if (token == TokenNameCOLON) {
2088 // ':' [labeled-statement-list] 'endswitch' ';'
2090 labeledStatementList();
2091 if (token != TokenNameendswitch) {
2092 throwSyntaxError("'endswitch' expected.");
2095 if (token != TokenNameSEMICOLON) {
2096 throwSyntaxError("';' expected after switch-statement.");
2100 // '{' [labeled-statement-list] '}'
2101 if (token != TokenNameLBRACE) {
2102 throwSyntaxError("'{' expected in switch statement.");
2105 if (token != TokenNameRBRACE) {
2106 labeledStatementList();
2108 if (token != TokenNameRBRACE) {
2109 throwSyntaxError("'}' expected in switch statement.");
2115 private void forStatement() {
2116 if (token == TokenNameCOLON) {
2119 if (token != TokenNameendfor) {
2120 throwSyntaxError("'endfor' expected.");
2123 if (token != TokenNameSEMICOLON) {
2124 throwSyntaxError("';' expected after for-statement.");
2132 private void whileStatement() {
2133 // ':' statement-list 'endwhile' ';'
2134 if (token == TokenNameCOLON) {
2137 if (token != TokenNameendwhile) {
2138 throwSyntaxError("'endwhile' expected.");
2141 if (token != TokenNameSEMICOLON) {
2142 throwSyntaxError("';' expected after while-statement.");
2150 private void foreachStatement() {
2151 if (token == TokenNameCOLON) {
2154 if (token != TokenNameendforeach) {
2155 throwSyntaxError("'endforeach' expected.");
2158 if (token != TokenNameSEMICOLON) {
2159 throwSyntaxError("';' expected after foreach-statement.");
2167 // private void exitStatus() {
2168 // if (token == TokenNameLPAREN) {
2171 // throwSyntaxError("'(' expected in 'exit-status'.");
2173 // if (token != TokenNameRPAREN) {
2176 // if (token == TokenNameRPAREN) {
2179 // throwSyntaxError("')' expected after 'exit-status'.");
2182 private void expressionList() {
2185 if (token == TokenNameCOMMA) {
2193 private Expression expr() {
2195 // | expr_without_variable
2196 // if (token!=TokenNameEOF) {
2197 if (Scanner.TRACE) {
2198 System.out.println("TRACE: expr()");
2200 return expr_without_variable(true);
2204 private Expression expr_without_variable(boolean only_variable) {
2205 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2206 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2207 Expression expression = new Expression();
2208 expression.sourceStart = exprSourceStart;
2209 // default, may be overwritten
2210 expression.sourceEnd = exprSourceEnd;
2212 // internal_functions_in_yacc
2221 // | T_INC rw_variable
2222 // | T_DEC rw_variable
2223 // | T_INT_CAST expr
2224 // | T_DOUBLE_CAST expr
2225 // | T_STRING_CAST expr
2226 // | T_ARRAY_CAST expr
2227 // | T_OBJECT_CAST expr
2228 // | T_BOOL_CAST expr
2229 // | T_UNSET_CAST expr
2230 // | T_EXIT exit_expr
2232 // | T_ARRAY '(' array_pair_list ')'
2233 // | '`' encaps_list '`'
2234 // | T_LIST '(' assignment_list ')' '=' expr
2235 // | T_NEW class_name_reference ctor_arguments
2236 // | variable '=' expr
2237 // | variable '=' '&' variable
2238 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2239 // | variable T_PLUS_EQUAL expr
2240 // | variable T_MINUS_EQUAL expr
2241 // | variable T_MUL_EQUAL expr
2242 // | variable T_DIV_EQUAL expr
2243 // | variable T_CONCAT_EQUAL expr
2244 // | variable T_MOD_EQUAL expr
2245 // | variable T_AND_EQUAL expr
2246 // | variable T_OR_EQUAL expr
2247 // | variable T_XOR_EQUAL expr
2248 // | variable T_SL_EQUAL expr
2249 // | variable T_SR_EQUAL expr
2250 // | rw_variable T_INC
2251 // | rw_variable T_DEC
2252 // | expr T_BOOLEAN_OR expr
2253 // | expr T_BOOLEAN_AND expr
2254 // | expr T_LOGICAL_OR expr
2255 // | expr T_LOGICAL_AND expr
2256 // | expr T_LOGICAL_XOR expr
2268 // | expr T_IS_IDENTICAL expr
2269 // | expr T_IS_NOT_IDENTICAL expr
2270 // | expr T_IS_EQUAL expr
2271 // | expr T_IS_NOT_EQUAL expr
2273 // | expr T_IS_SMALLER_OR_EQUAL expr
2275 // | expr T_IS_GREATER_OR_EQUAL expr
2276 // | expr T_INSTANCEOF class_name_reference
2277 // | expr '?' expr ':' expr
2278 if (Scanner.TRACE) {
2279 System.out.println("TRACE: expr_without_variable() PART 1");
2282 case TokenNameisset:
2283 // T_ISSET '(' isset_variables ')'
2285 if (token != TokenNameLPAREN) {
2286 throwSyntaxError("'(' expected after keyword 'isset'");
2290 if (token != TokenNameRPAREN) {
2291 throwSyntaxError("')' expected after keyword 'isset'");
2295 case TokenNameempty:
2297 if (token != TokenNameLPAREN) {
2298 throwSyntaxError("'(' expected after keyword 'empty'");
2301 variable(true, false);
2302 if (token != TokenNameRPAREN) {
2303 throwSyntaxError("')' expected after keyword 'empty'");
2308 case TokenNameinclude:
2309 case TokenNameinclude_once:
2310 case TokenNamerequire:
2311 case TokenNamerequire_once:
2312 internal_functions_in_yacc();
2315 case TokenNameLPAREN:
2318 if (token == TokenNameRPAREN) {
2321 throwSyntaxError("')' expected in expression.");
2331 // | T_INT_CAST expr
2332 // | T_DOUBLE_CAST expr
2333 // | T_STRING_CAST expr
2334 // | T_ARRAY_CAST expr
2335 // | T_OBJECT_CAST expr
2336 // | T_BOOL_CAST expr
2337 // | T_UNSET_CAST expr
2338 case TokenNameclone:
2339 case TokenNameprint:
2342 case TokenNameMINUS:
2344 case TokenNameTWIDDLE:
2345 case TokenNameintCAST:
2346 case TokenNamedoubleCAST:
2347 case TokenNamestringCAST:
2348 case TokenNamearrayCAST:
2349 case TokenNameobjectCAST:
2350 case TokenNameboolCAST:
2351 case TokenNameunsetCAST:
2361 //| T_STRING_VARNAME
2363 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2364 // | '`' encaps_list '`'
2366 // | '`' encaps_list '`'
2367 case TokenNameEncapsedString0:
2368 scanner.encapsedStringStack.push(new Character('`'));
2371 if (token == TokenNameEncapsedString0) {
2374 if (token != TokenNameEncapsedString0) {
2375 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2379 scanner.encapsedStringStack.pop();
2383 // | '\'' encaps_list '\''
2384 case TokenNameEncapsedString1:
2385 scanner.encapsedStringStack.push(new Character('\''));
2388 exprSourceStart = scanner.getCurrentTokenStartPosition();
2389 if (token == TokenNameEncapsedString1) {
2390 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2391 .getCurrentTokenEndPosition());
2394 if (token != TokenNameEncapsedString1) {
2395 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2397 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2398 .getCurrentTokenEndPosition());
2402 scanner.encapsedStringStack.pop();
2406 //| '"' encaps_list '"'
2407 case TokenNameEncapsedString2:
2408 scanner.encapsedStringStack.push(new Character('"'));
2411 exprSourceStart = scanner.getCurrentTokenStartPosition();
2412 if (token == TokenNameEncapsedString2) {
2413 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2414 .getCurrentTokenEndPosition());
2417 if (token != TokenNameEncapsedString2) {
2418 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2420 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2421 .getCurrentTokenEndPosition());
2425 scanner.encapsedStringStack.pop();
2429 case TokenNameStringDoubleQuote:
2430 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2431 .getCurrentTokenEndPosition());
2434 case TokenNameStringSingleQuote:
2435 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2436 .getCurrentTokenEndPosition());
2439 case TokenNameIntegerLiteral:
2440 case TokenNameDoubleLiteral:
2441 case TokenNameStringInterpolated:
2444 case TokenNameCLASS_C:
2445 case TokenNameMETHOD_C:
2446 case TokenNameFUNC_C:
2449 case TokenNameHEREDOC:
2452 case TokenNamearray:
2453 // T_ARRAY '(' array_pair_list ')'
2455 if (token == TokenNameLPAREN) {
2457 if (token == TokenNameRPAREN) {
2462 if (token != TokenNameRPAREN) {
2463 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2467 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2471 // | T_LIST '(' assignment_list ')' '=' expr
2473 if (token == TokenNameLPAREN) {
2476 if (token != TokenNameRPAREN) {
2477 throwSyntaxError("')' expected after 'list' keyword.");
2480 if (token != TokenNameEQUAL) {
2481 throwSyntaxError("'=' expected after 'list' keyword.");
2486 throwSyntaxError("'(' expected after 'list' keyword.");
2490 // | T_NEW class_name_reference ctor_arguments
2492 Expression typeRef = class_name_reference();
2494 if (typeRef != null) {
2495 expression = typeRef;
2498 // | T_INC rw_variable
2499 // | T_DEC rw_variable
2500 case TokenNamePLUS_PLUS:
2501 case TokenNameMINUS_MINUS:
2505 // | variable '=' expr
2506 // | variable '=' '&' variable
2507 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2508 // | variable T_PLUS_EQUAL expr
2509 // | variable T_MINUS_EQUAL expr
2510 // | variable T_MUL_EQUAL expr
2511 // | variable T_DIV_EQUAL expr
2512 // | variable T_CONCAT_EQUAL expr
2513 // | variable T_MOD_EQUAL expr
2514 // | variable T_AND_EQUAL expr
2515 // | variable T_OR_EQUAL expr
2516 // | variable T_XOR_EQUAL expr
2517 // | variable T_SL_EQUAL expr
2518 // | variable T_SR_EQUAL expr
2519 // | rw_variable T_INC
2520 // | rw_variable T_DEC
2521 case TokenNameIdentifier:
2522 case TokenNameVariable:
2523 case TokenNameDOLLAR:
2524 boolean rememberedVar = false;
2525 Expression lhs = variable(true, true);
2526 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2527 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2528 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2529 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2530 && token != TokenNameLEFT_SHIFT_EQUAL) {
2531 FieldReference ref = (FieldReference) lhs;
2532 if (!containsVariableSet(ref.token)) {
2533 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(), referenceContext,
2534 compilationUnit.compilationResult);
2535 addVariableSet(ref.token);
2540 case TokenNameEQUAL:
2541 if (lhs != null && lhs instanceof FieldReference) {
2542 addVariableSet(((FieldReference) lhs).token);
2544 // if (lhsVar != null) {
2545 // addVariableSet(lhsVar);
2548 if (token == TokenNameAND) {
2550 if (token == TokenNamenew) {
2551 // | variable '=' '&' T_NEW class_name_reference
2554 SingleTypeReference classRef = class_name_reference();
2556 if (classRef != null) {
2557 if (lhs != null && lhs instanceof FieldReference) {
2559 // $var = & new Object();
2560 if (fMethodVariables != null) {
2561 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2562 lhsInfo.reference = classRef;
2563 lhsInfo.typeIdentifier = classRef.token;
2564 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2565 rememberedVar = true;
2570 Expression rhs = variable(false, false);
2571 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2574 if (fMethodVariables != null) {
2575 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2576 if (rhsInfo != null && rhsInfo.reference != null) {
2577 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2578 lhsInfo.reference = rhsInfo.reference;
2579 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2580 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2581 rememberedVar = true;
2587 Expression rhs = expr();
2588 if (lhs != null && lhs instanceof FieldReference) {
2589 if (rhs != null && rhs instanceof FieldReference) {
2592 if (fMethodVariables != null) {
2593 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2594 if (rhsInfo != null && rhsInfo.reference != null) {
2595 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2596 lhsInfo.reference = rhsInfo.reference;
2597 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2598 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2599 rememberedVar = true;
2602 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2604 // $var = new Object();
2605 if (fMethodVariables != null) {
2606 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2607 lhsInfo.reference = (SingleTypeReference) rhs;
2608 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2609 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2610 rememberedVar = true;
2615 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2616 if (fMethodVariables != null) {
2617 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2618 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2622 case TokenNamePLUS_EQUAL:
2623 case TokenNameMINUS_EQUAL:
2624 case TokenNameMULTIPLY_EQUAL:
2625 case TokenNameDIVIDE_EQUAL:
2626 case TokenNameDOT_EQUAL:
2627 case TokenNameREMAINDER_EQUAL:
2628 case TokenNameAND_EQUAL:
2629 case TokenNameOR_EQUAL:
2630 case TokenNameXOR_EQUAL:
2631 case TokenNameRIGHT_SHIFT_EQUAL:
2632 case TokenNameLEFT_SHIFT_EQUAL:
2633 if (lhs != null && lhs instanceof FieldReference) {
2634 addVariableSet(((FieldReference) lhs).token);
2639 case TokenNamePLUS_PLUS:
2640 case TokenNameMINUS_MINUS:
2644 if (!only_variable) {
2645 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2653 if (token != TokenNameINLINE_HTML) {
2654 if (token > TokenNameKEYWORD) {
2658 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2663 if (Scanner.TRACE) {
2664 System.out.println("TRACE: expr_without_variable() PART 2");
2666 // | expr T_BOOLEAN_OR expr
2667 // | expr T_BOOLEAN_AND expr
2668 // | expr T_LOGICAL_OR expr
2669 // | expr T_LOGICAL_AND expr
2670 // | expr T_LOGICAL_XOR expr
2682 // | expr T_IS_IDENTICAL expr
2683 // | expr T_IS_NOT_IDENTICAL expr
2684 // | expr T_IS_EQUAL expr
2685 // | expr T_IS_NOT_EQUAL expr
2687 // | expr T_IS_SMALLER_OR_EQUAL expr
2689 // | expr T_IS_GREATER_OR_EQUAL expr
2692 case TokenNameOR_OR:
2694 expression = new OR_OR_Expression(expression, expr(), token);
2696 case TokenNameAND_AND:
2698 expression = new AND_AND_Expression(expression, expr(), token);
2700 case TokenNameEQUAL_EQUAL:
2702 expression = new EqualExpression(expression, expr(), token);
2712 case TokenNameMINUS:
2713 case TokenNameMULTIPLY:
2714 case TokenNameDIVIDE:
2715 case TokenNameREMAINDER:
2716 case TokenNameLEFT_SHIFT:
2717 case TokenNameRIGHT_SHIFT:
2718 case TokenNameEQUAL_EQUAL_EQUAL:
2719 case TokenNameNOT_EQUAL_EQUAL:
2720 case TokenNameNOT_EQUAL:
2722 case TokenNameLESS_EQUAL:
2723 case TokenNameGREATER:
2724 case TokenNameGREATER_EQUAL:
2726 expression = new BinaryExpression(expression, expr(), token);
2728 // | expr T_INSTANCEOF class_name_reference
2729 // | expr '?' expr ':' expr
2730 case TokenNameinstanceof:
2732 TypeReference classRef = class_name_reference();
2733 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2734 expression.sourceStart = exprSourceStart;
2735 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2737 case TokenNameQUESTION:
2739 Expression valueIfTrue = expr();
2740 if (token != TokenNameCOLON) {
2741 throwSyntaxError("':' expected in conditional expression.");
2744 Expression valueIfFalse = expr();
2746 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2752 } catch (SyntaxError e) {
2753 // try to find next token after expression with errors:
2754 if (token == TokenNameSEMICOLON) {
2758 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2766 private SingleTypeReference class_name_reference() {
2767 // class_name_reference:
2769 //| dynamic_class_name_reference
2770 SingleTypeReference ref = null;
2771 if (Scanner.TRACE) {
2772 System.out.println("TRACE: class_name_reference()");
2774 if (token == TokenNameIdentifier) {
2775 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2779 dynamic_class_name_reference();
2784 private void dynamic_class_name_reference() {
2785 //dynamic_class_name_reference:
2786 // base_variable T_OBJECT_OPERATOR object_property
2787 // dynamic_class_name_variable_properties
2789 if (Scanner.TRACE) {
2790 System.out.println("TRACE: dynamic_class_name_reference()");
2793 if (token == TokenNameMINUS_GREATER) {
2796 dynamic_class_name_variable_properties();
2800 private void dynamic_class_name_variable_properties() {
2801 // dynamic_class_name_variable_properties:
2802 // dynamic_class_name_variable_properties
2803 // dynamic_class_name_variable_property
2805 if (Scanner.TRACE) {
2806 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2808 while (token == TokenNameMINUS_GREATER) {
2809 dynamic_class_name_variable_property();
2813 private void dynamic_class_name_variable_property() {
2814 // dynamic_class_name_variable_property:
2815 // T_OBJECT_OPERATOR object_property
2816 if (Scanner.TRACE) {
2817 System.out.println("TRACE: dynamic_class_name_variable_property()");
2819 if (token == TokenNameMINUS_GREATER) {
2825 private void ctor_arguments() {
2828 //| '(' function_call_parameter_list ')'
2829 if (token == TokenNameLPAREN) {
2831 if (token == TokenNameRPAREN) {
2835 non_empty_function_call_parameter_list();
2836 if (token != TokenNameRPAREN) {
2837 throwSyntaxError("')' expected in ctor_arguments.");
2843 private void assignment_list() {
2845 // assignment_list ',' assignment_list_element
2846 //| assignment_list_element
2848 assignment_list_element();
2849 if (token != TokenNameCOMMA) {
2856 private void assignment_list_element() {
2857 //assignment_list_element:
2859 //| T_LIST '(' assignment_list ')'
2861 if (token == TokenNameVariable) {
2862 variable(true, false);
2863 } else if (token == TokenNameDOLLAR) {
2864 variable(false, false);
2866 if (token == TokenNamelist) {
2868 if (token == TokenNameLPAREN) {
2871 if (token != TokenNameRPAREN) {
2872 throwSyntaxError("')' expected after 'list' keyword.");
2876 throwSyntaxError("'(' expected after 'list' keyword.");
2882 private void array_pair_list() {
2885 //| non_empty_array_pair_list possible_comma
2886 non_empty_array_pair_list();
2887 if (token == TokenNameCOMMA) {
2892 private void non_empty_array_pair_list() {
2893 //non_empty_array_pair_list:
2894 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2895 //| non_empty_array_pair_list ',' expr
2896 //| expr T_DOUBLE_ARROW expr
2898 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2899 //| non_empty_array_pair_list ',' '&' w_variable
2900 //| expr T_DOUBLE_ARROW '&' w_variable
2903 if (token == TokenNameAND) {
2905 variable(true, false);
2908 if (token == TokenNameAND) {
2910 variable(true, false);
2911 } else if (token == TokenNameEQUAL_GREATER) {
2913 if (token == TokenNameAND) {
2915 variable(true, false);
2921 if (token != TokenNameCOMMA) {
2925 if (token == TokenNameRPAREN) {
2931 // private void variableList() {
2934 // if (token == TokenNameCOMMA) {
2941 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2942 // variable_without_objects:
2943 // reference_variable
2944 // | simple_indirect_reference reference_variable
2945 if (Scanner.TRACE) {
2946 System.out.println("TRACE: variable_without_objects()");
2948 while (token == TokenNameDOLLAR) {
2951 return reference_variable(lefthandside, ignoreVar);
2954 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2956 // T_STRING '(' function_call_parameter_list ')'
2957 //| class_constant '(' function_call_parameter_list ')'
2958 //| static_member '(' function_call_parameter_list ')'
2959 //| variable_without_objects '(' function_call_parameter_list ')'
2960 char[] defineName = null;
2961 char[] ident = null;
2964 Expression ref = null;
2965 if (Scanner.TRACE) {
2966 System.out.println("TRACE: function_call()");
2968 if (token == TokenNameIdentifier) {
2969 ident = scanner.getCurrentIdentifierSource();
2971 startPos = scanner.getCurrentTokenStartPosition();
2972 endPos = scanner.getCurrentTokenEndPosition();
2975 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2979 if (token == TokenNameIdentifier) {
2984 variable_without_objects(true, false);
2989 ref = variable_without_objects(lefthandside, ignoreVar);
2991 if (token != TokenNameLPAREN) {
2992 if (defineName != null) {
2993 // does this identifier contain only uppercase characters?
2994 if (defineName.length == 3) {
2995 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2998 } else if (defineName.length == 4) {
2999 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3001 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3004 } else if (defineName.length == 5) {
3005 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3009 if (defineName != null) {
3010 for (int i = 0; i < defineName.length; i++) {
3011 if (Character.isLowerCase(defineName[i])) {
3012 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3018 // TODO is this ok ?
3020 // throwSyntaxError("'(' expected in function call.");
3023 if (token == TokenNameRPAREN) {
3027 non_empty_function_call_parameter_list();
3028 if (token != TokenNameRPAREN) {
3029 String functionName;
3030 if (ident == null) {
3031 functionName = new String(" ");
3033 functionName = new String(ident);
3035 throwSyntaxError("')' expected in function call (" + functionName + ").");
3041 // private void function_call_parameter_list() {
3042 // function_call_parameter_list:
3043 // non_empty_function_call_parameter_list { $$ = $1; }
3046 private void non_empty_function_call_parameter_list() {
3047 //non_empty_function_call_parameter_list:
3048 // expr_without_variable
3051 // | non_empty_function_call_parameter_list ',' expr_without_variable
3052 // | non_empty_function_call_parameter_list ',' variable
3053 // | non_empty_function_call_parameter_list ',' '&' w_variable
3054 if (Scanner.TRACE) {
3055 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3058 if (token == TokenNameAND) {
3062 // if (token == TokenNameIdentifier || token ==
3063 // TokenNameVariable
3064 // || token == TokenNameDOLLAR) {
3067 expr_without_variable(true);
3070 if (token != TokenNameCOMMA) {
3077 private void fully_qualified_class_name() {
3078 if (token == TokenNameIdentifier) {
3081 throwSyntaxError("Class name expected.");
3085 private void static_member() {
3087 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3088 // variable_without_objects
3089 if (Scanner.TRACE) {
3090 System.out.println("TRACE: static_member()");
3092 fully_qualified_class_name();
3093 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3094 throwSyntaxError("'::' expected after class name (static_member).");
3097 variable_without_objects(false, false);
3100 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3101 // base_variable_with_function_calls:
3104 boolean functionCall = false;
3105 if (Scanner.TRACE) {
3106 System.out.println("TRACE: base_variable_with_function_calls()");
3108 // if (token == TokenNameIdentifier) {
3109 // functionCall = true;
3110 // } else if (token == TokenNameVariable) {
3111 // int tempToken = token;
3112 // int tempPosition = scanner.currentPosition;
3114 // if (token == TokenNameLPAREN) {
3115 // functionCall = true;
3117 // token = tempToken;
3118 // scanner.currentPosition = tempPosition;
3119 // scanner.phpMode = true;
3121 // if (functionCall) {
3122 return function_call(lefthandside, ignoreVar);
3128 private Expression base_variable() {
3130 // reference_variable
3131 // | simple_indirect_reference reference_variable
3133 Expression ref = null;
3134 if (Scanner.TRACE) {
3135 System.out.println("TRACE: base_variable()");
3137 if (token == TokenNameIdentifier) {
3140 while (token == TokenNameDOLLAR) {
3143 reference_variable(false, false);
3148 // private void simple_indirect_reference() {
3149 // // simple_indirect_reference:
3151 // //| simple_indirect_reference '$'
3153 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3154 // reference_variable:
3155 // reference_variable '[' dim_offset ']'
3156 // | reference_variable '{' expr '}'
3157 // | compound_variable
3158 Expression ref = null;
3159 if (Scanner.TRACE) {
3160 System.out.println("TRACE: reference_variable()");
3162 ref = compound_variable(lefthandside, ignoreVar);
3164 if (token == TokenNameLBRACE) {
3168 if (token != TokenNameRBRACE) {
3169 throwSyntaxError("'}' expected in reference variable.");
3172 } else if (token == TokenNameLBRACKET) {
3173 if (ref != null && ref instanceof FieldReference) {
3174 FieldReference fref = (FieldReference) ref;
3175 addVariableSet(fref.token);
3179 if (token != TokenNameRBRACKET) {
3182 if (token != TokenNameRBRACKET) {
3183 throwSyntaxError("']' expected in reference variable.");
3194 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3195 // compound_variable:
3197 // | '$' '{' expr '}'
3198 if (Scanner.TRACE) {
3199 System.out.println("TRACE: compound_variable()");
3201 if (token == TokenNameVariable) {
3202 if (!lefthandside) {
3203 if (!containsVariableSet()) {
3204 // reportSyntaxError("The local variable " + new String(scanner.getCurrentIdentifierSource())
3205 // + " may not have been initialized");
3206 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3207 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3208 compilationUnit.compilationResult);
3215 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3219 // because of simple_indirect_reference
3220 while (token == TokenNameDOLLAR) {
3223 if (token != TokenNameLBRACE) {
3224 reportSyntaxError("'{' expected after compound variable token '$'.");
3229 if (token != TokenNameRBRACE) {
3230 throwSyntaxError("'}' expected after compound variable token '$'.");
3235 } // private void dim_offset() { // // dim_offset: // // /* empty */
3240 private void object_property() {
3243 //| variable_without_objects
3244 if (Scanner.TRACE) {
3245 System.out.println("TRACE: object_property()");
3247 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3248 variable_without_objects(false, false);
3254 private void object_dim_list() {
3256 // object_dim_list '[' dim_offset ']'
3257 //| object_dim_list '{' expr '}'
3259 if (Scanner.TRACE) {
3260 System.out.println("TRACE: object_dim_list()");
3264 if (token == TokenNameLBRACE) {
3267 if (token != TokenNameRBRACE) {
3268 throwSyntaxError("'}' expected in object_dim_list.");
3271 } else if (token == TokenNameLBRACKET) {
3273 if (token == TokenNameRBRACKET) {
3278 if (token != TokenNameRBRACKET) {
3279 throwSyntaxError("']' expected in object_dim_list.");
3288 private void variable_name() {
3292 if (Scanner.TRACE) {
3293 System.out.println("TRACE: variable_name()");
3295 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3296 if (token > TokenNameKEYWORD) {
3297 // TODO show a warning "Keyword used as variable" ?
3301 if (token != TokenNameLBRACE) {
3302 throwSyntaxError("'{' expected in variable name.");
3306 if (token != TokenNameRBRACE) {
3307 throwSyntaxError("'}' expected in variable name.");
3313 private void r_variable() {
3314 variable(false, false);
3317 private void w_variable(boolean lefthandside) {
3318 variable(lefthandside, false);
3321 private void rw_variable() {
3322 variable(false, false);
3325 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3327 // base_variable_with_function_calls T_OBJECT_OPERATOR
3328 // object_property method_or_not variable_properties
3329 // | base_variable_with_function_calls
3330 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3331 if (token == TokenNameMINUS_GREATER) {
3336 variable_properties();
3341 private void variable_properties() {
3342 // variable_properties:
3343 // variable_properties variable_property
3345 while (token == TokenNameMINUS_GREATER) {
3346 variable_property();
3350 private void variable_property() {
3351 // variable_property:
3352 // T_OBJECT_OPERATOR object_property method_or_not
3353 if (Scanner.TRACE) {
3354 System.out.println("TRACE: variable_property()");
3356 if (token == TokenNameMINUS_GREATER) {
3361 throwSyntaxError("'->' expected in variable_property.");
3365 private void method_or_not() {
3367 // '(' function_call_parameter_list ')'
3369 if (Scanner.TRACE) {
3370 System.out.println("TRACE: method_or_not()");
3372 if (token == TokenNameLPAREN) {
3374 if (token == TokenNameRPAREN) {
3378 non_empty_function_call_parameter_list();
3379 if (token != TokenNameRPAREN) {
3380 throwSyntaxError("')' expected in method_or_not.");
3386 private void exit_expr() {
3390 if (token != TokenNameLPAREN) {
3394 if (token == TokenNameRPAREN) {
3399 if (token != TokenNameRPAREN) {
3400 throwSyntaxError("')' expected after keyword 'exit'");
3405 private void encaps_list() {
3406 // encaps_list encaps_var
3407 // | encaps_list T_STRING
3408 // | encaps_list T_NUM_STRING
3409 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3410 // | encaps_list T_CHARACTER
3411 // | encaps_list T_BAD_CHARACTER
3412 // | encaps_list '['
3413 // | encaps_list ']'
3414 // | encaps_list '{'
3415 // | encaps_list '}'
3416 // | encaps_list T_OBJECT_OPERATOR
3420 case TokenNameSTRING:
3423 case TokenNameLBRACE:
3424 // scanner.encapsedStringStack.pop();
3427 case TokenNameRBRACE:
3428 // scanner.encapsedStringStack.pop();
3431 case TokenNameLBRACKET:
3432 // scanner.encapsedStringStack.pop();
3435 case TokenNameRBRACKET:
3436 // scanner.encapsedStringStack.pop();
3439 case TokenNameMINUS_GREATER:
3440 // scanner.encapsedStringStack.pop();
3443 case TokenNameVariable:
3444 case TokenNameDOLLAR_LBRACE:
3445 case TokenNameLBRACE_DOLLAR:
3449 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3450 if (encapsedChar == '$') {
3451 scanner.encapsedStringStack.pop();
3452 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3453 switch (encapsedChar) {
3455 if (token == TokenNameEncapsedString0) {
3458 token = TokenNameSTRING;
3461 if (token == TokenNameEncapsedString1) {
3464 token = TokenNameSTRING;
3467 if (token == TokenNameEncapsedString2) {
3470 token = TokenNameSTRING;
3479 private void encaps_var() {
3481 // | T_VARIABLE '[' encaps_var_offset ']'
3482 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3483 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3484 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3485 // | T_CURLY_OPEN variable '}'
3487 case TokenNameVariable:
3489 if (token == TokenNameLBRACKET) {
3491 expr(); //encaps_var_offset();
3492 if (token != TokenNameRBRACKET) {
3493 throwSyntaxError("']' expected after variable.");
3495 // scanner.encapsedStringStack.pop();
3498 } else if (token == TokenNameMINUS_GREATER) {
3500 if (token != TokenNameIdentifier) {
3501 throwSyntaxError("Identifier expected after '->'.");
3503 // scanner.encapsedStringStack.pop();
3507 // // scanner.encapsedStringStack.pop();
3508 // int tempToken = TokenNameSTRING;
3509 // if (!scanner.encapsedStringStack.isEmpty()
3510 // && (token == TokenNameEncapsedString0
3511 // || token == TokenNameEncapsedString1
3512 // || token == TokenNameEncapsedString2 || token ==
3513 // TokenNameERROR)) {
3514 // char encapsedChar = ((Character)
3515 // scanner.encapsedStringStack.peek())
3518 // case TokenNameEncapsedString0 :
3519 // if (encapsedChar == '`') {
3520 // tempToken = TokenNameEncapsedString0;
3523 // case TokenNameEncapsedString1 :
3524 // if (encapsedChar == '\'') {
3525 // tempToken = TokenNameEncapsedString1;
3528 // case TokenNameEncapsedString2 :
3529 // if (encapsedChar == '"') {
3530 // tempToken = TokenNameEncapsedString2;
3533 // case TokenNameERROR :
3534 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3535 // scanner.currentPosition--;
3541 // token = tempToken;
3544 case TokenNameDOLLAR_LBRACE:
3546 if (token == TokenNameDOLLAR_LBRACE) {
3548 } else if (token == TokenNameIdentifier) {
3550 if (token == TokenNameLBRACKET) {
3552 // if (token == TokenNameRBRACKET) {
3556 if (token != TokenNameRBRACKET) {
3557 throwSyntaxError("']' expected after '${'.");
3565 if (token != TokenNameRBRACE) {
3566 throwSyntaxError("'}' expected.");
3570 case TokenNameLBRACE_DOLLAR:
3572 if (token == TokenNameLBRACE_DOLLAR) {
3574 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3576 if (token == TokenNameLBRACKET) {
3578 // if (token == TokenNameRBRACKET) {
3582 if (token != TokenNameRBRACKET) {
3583 throwSyntaxError("']' expected.");
3587 } else if (token == TokenNameMINUS_GREATER) {
3589 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3590 throwSyntaxError("String or Variable token expected.");
3593 if (token == TokenNameLBRACKET) {
3595 // if (token == TokenNameRBRACKET) {
3599 if (token != TokenNameRBRACKET) {
3600 throwSyntaxError("']' expected after '${'.");
3606 // if (token != TokenNameRBRACE) {
3607 // throwSyntaxError("'}' expected after '{$'.");
3609 // // scanner.encapsedStringStack.pop();
3613 if (token != TokenNameRBRACE) {
3614 throwSyntaxError("'}' expected.");
3616 // scanner.encapsedStringStack.pop();
3623 private void encaps_var_offset() {
3628 case TokenNameSTRING:
3631 case TokenNameIntegerLiteral:
3634 case TokenNameVariable:
3637 case TokenNameIdentifier:
3641 throwSyntaxError("Variable or String token expected.");
3646 private void internal_functions_in_yacc() {
3649 // case TokenNameisset:
3650 // // T_ISSET '(' isset_variables ')'
3652 // if (token != TokenNameLPAREN) {
3653 // throwSyntaxError("'(' expected after keyword 'isset'");
3656 // isset_variables();
3657 // if (token != TokenNameRPAREN) {
3658 // throwSyntaxError("')' expected after keyword 'isset'");
3662 // case TokenNameempty:
3663 // // T_EMPTY '(' variable ')'
3665 // if (token != TokenNameLPAREN) {
3666 // throwSyntaxError("'(' expected after keyword 'empty'");
3670 // if (token != TokenNameRPAREN) {
3671 // throwSyntaxError("')' expected after keyword 'empty'");
3675 case TokenNameinclude:
3677 checkFileName(token);
3679 case TokenNameinclude_once:
3680 // T_INCLUDE_ONCE expr
3681 checkFileName(token);
3684 // T_EVAL '(' expr ')'
3686 if (token != TokenNameLPAREN) {
3687 throwSyntaxError("'(' expected after keyword 'eval'");
3691 if (token != TokenNameRPAREN) {
3692 throwSyntaxError("')' expected after keyword 'eval'");
3696 case TokenNamerequire:
3698 checkFileName(token);
3700 case TokenNamerequire_once:
3701 // T_REQUIRE_ONCE expr
3702 checkFileName(token);
3707 private void checkFileName(int includeToken) {
3708 //<include-token> expr
3709 int start = scanner.getCurrentTokenStartPosition();
3710 boolean hasLPAREN = false;
3712 if (token == TokenNameLPAREN) {
3716 Expression expression = expr();
3718 if (token == TokenNameRPAREN) {
3721 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3724 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3726 if (scanner.compilationUnit != null) {
3727 IResource resource = scanner.compilationUnit.getResource();
3728 if (resource != null && resource instanceof IFile) {
3729 file = (IFile) resource;
3733 tokens = new char[1][];
3734 tokens[0] = currTokenSource;
3736 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3737 impt.declarationSourceEnd = impt.sourceEnd;
3738 impt.declarationEnd = impt.declarationSourceEnd;
3739 //endPosition is just before the ;
3740 impt.declarationSourceStart = start;
3741 includesList.add(impt);
3743 if (expression instanceof StringLiteral) {
3744 StringLiteral literal = (StringLiteral) expression;
3745 char[] includeName = literal.source();
3746 if (includeName.length == 0) {
3747 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3748 literal.sourceStart + 1);
3750 String includeNameString = new String(includeName);
3751 if (literal instanceof StringLiteralDQ) {
3752 if (includeNameString.indexOf('$') >= 0) {
3753 // assuming that the filename contains a variable => no filename check
3757 if (includeNameString.startsWith("http://")) {
3758 // assuming external include location
3762 // check the filename:
3763 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3764 IProject project = file.getProject();
3765 if (project != null) {
3766 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3769 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3770 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3771 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3772 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3773 compilationUnit.compilationResult);
3776 // String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
3777 // String filePath = file.getRawLocation().toString();
3778 String filePath = path.toString();
3779 String ext = file.getRawLocation().getFileExtension();
3780 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3783 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3784 impt.setFile(PHPFileUtil.createFile(path, project));
3785 } catch (Exception e) {
3786 // the file is outside of the workspace
3794 private void isset_variables() {
3796 // | isset_variables ','
3797 if (token == TokenNameRPAREN) {
3798 throwSyntaxError("Variable expected after keyword 'isset'");
3801 variable(true, false);
3802 if (token == TokenNameCOMMA) {
3810 private boolean common_scalar() {
3814 // | T_CONSTANT_ENCAPSED_STRING
3821 case TokenNameIntegerLiteral:
3824 case TokenNameDoubleLiteral:
3827 case TokenNameStringDoubleQuote:
3830 case TokenNameStringSingleQuote:
3833 case TokenNameStringInterpolated:
3842 case TokenNameCLASS_C:
3845 case TokenNameMETHOD_C:
3848 case TokenNameFUNC_C:
3855 private void scalar() {
3858 //| T_STRING_VARNAME
3861 //| '"' encaps_list '"'
3862 //| '\'' encaps_list '\''
3863 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3864 throwSyntaxError("Not yet implemented (scalar).");
3867 private void static_scalar() {
3868 // static_scalar: /* compile-time evaluated scalars */
3871 // | '+' static_scalar
3872 // | '-' static_scalar
3873 // | T_ARRAY '(' static_array_pair_list ')'
3874 // | static_class_constant
3875 if (common_scalar()) {
3879 case TokenNameIdentifier:
3881 // static_class_constant:
3882 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3883 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3885 if (token == TokenNameIdentifier) {
3888 throwSyntaxError("Identifier expected after '::' operator.");
3892 case TokenNameEncapsedString0:
3894 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3895 while (scanner.currentCharacter != '`') {
3896 if (scanner.currentCharacter == '\\') {
3897 scanner.currentPosition++;
3899 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3902 } catch (IndexOutOfBoundsException e) {
3903 throwSyntaxError("'`' expected at end of static string.");
3906 case TokenNameEncapsedString1:
3908 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3909 while (scanner.currentCharacter != '\'') {
3910 if (scanner.currentCharacter == '\\') {
3911 scanner.currentPosition++;
3913 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3916 } catch (IndexOutOfBoundsException e) {
3917 throwSyntaxError("'\'' expected at end of static string.");
3920 case TokenNameEncapsedString2:
3922 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3923 while (scanner.currentCharacter != '"') {
3924 if (scanner.currentCharacter == '\\') {
3925 scanner.currentPosition++;
3927 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3930 } catch (IndexOutOfBoundsException e) {
3931 throwSyntaxError("'\"' expected at end of static string.");
3938 case TokenNameMINUS:
3942 case TokenNamearray:
3944 if (token != TokenNameLPAREN) {
3945 throwSyntaxError("'(' expected after keyword 'array'");
3948 if (token == TokenNameRPAREN) {
3952 non_empty_static_array_pair_list();
3953 if (token != TokenNameRPAREN) {
3954 throwSyntaxError("')' or ',' expected after keyword 'array'");
3958 // case TokenNamenull :
3961 // case TokenNamefalse :
3964 // case TokenNametrue :
3968 throwSyntaxError("Static scalar/constant expected.");
3972 private void non_empty_static_array_pair_list() {
3973 // non_empty_static_array_pair_list:
3974 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3976 //| non_empty_static_array_pair_list ',' static_scalar
3977 //| static_scalar T_DOUBLE_ARROW static_scalar
3981 if (token == TokenNameEQUAL_GREATER) {
3985 if (token != TokenNameCOMMA) {
3989 if (token == TokenNameRPAREN) {
3995 public void reportSyntaxError() { //int act, int currentKind, int
3997 /* remember current scanner position */
3998 int startPos = scanner.startPosition;
3999 int currentPos = scanner.currentPosition;
4000 // String[] expectings;
4001 // String tokenName = name[symbol_index[currentKind]];
4002 //fetch all "accurate" possible terminals that could recover the error
4003 // int start, end = start = asi(stack[stateStackTop]);
4004 // while (asr[end] != 0)
4006 // int length = end - start;
4007 // expectings = new String[length];
4008 // if (length != 0) {
4009 // char[] indexes = new char[length];
4010 // System.arraycopy(asr, start, indexes, 0, length);
4011 // for (int i = 0; i < length; i++) {
4012 // expectings[i] = name[symbol_index[indexes[i]]];
4015 //if the pb is an EOF, try to tell the user that they are some
4016 // if (tokenName.equals(UNEXPECTED_EOF)) {
4017 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
4018 // char[] tokenSource;
4020 // tokenSource = this.scanner.getCurrentTokenSource();
4021 // } catch (Exception e) {
4022 // tokenSource = new char[] {};
4024 // problemReporter().parseError(
4025 // this.scanner.startPosition,
4026 // this.scanner.currentPosition - 1,
4031 // } else { //the next test is HEAVILY grammar DEPENDENT.
4032 // if ((length == 14)
4033 // && (expectings[0] == "=") //$NON-NLS-1$
4034 // && (expectings[1] == "*=") //$NON-NLS-1$
4035 // && (expressionPtr > -1)) {
4036 // switch(currentKind) {
4037 // case TokenNameSEMICOLON:
4038 // case TokenNamePLUS:
4039 // case TokenNameMINUS:
4040 // case TokenNameDIVIDE:
4041 // case TokenNameREMAINDER:
4042 // case TokenNameMULTIPLY:
4043 // case TokenNameLEFT_SHIFT:
4044 // case TokenNameRIGHT_SHIFT:
4045 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
4046 // case TokenNameLESS:
4047 // case TokenNameGREATER:
4048 // case TokenNameLESS_EQUAL:
4049 // case TokenNameGREATER_EQUAL:
4050 // case TokenNameEQUAL_EQUAL:
4051 // case TokenNameNOT_EQUAL:
4052 // case TokenNameXOR:
4053 // case TokenNameAND:
4054 // case TokenNameOR:
4055 // case TokenNameOR_OR:
4056 // case TokenNameAND_AND:
4057 // // the ; is not the expected token ==> it ends a statement when an
4058 // expression is not ended
4059 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
4061 // case TokenNameRBRACE :
4062 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
4065 // char[] tokenSource;
4067 // tokenSource = this.scanner.getCurrentTokenSource();
4068 // } catch (Exception e) {
4069 // tokenSource = new char[] {};
4071 // problemReporter().parseError(
4072 // this.scanner.startPosition,
4073 // this.scanner.currentPosition - 1,
4077 // this.checkAndReportBracketAnomalies(problemReporter());
4082 tokenSource = this.scanner.getCurrentTokenSource();
4083 } catch (Exception e) {
4084 tokenSource = new char[] {};
4086 // problemReporter().parseError(
4087 // this.scanner.startPosition,
4088 // this.scanner.currentPosition - 1,
4092 this.checkAndReportBracketAnomalies(problemReporter());
4095 /* reset scanner where it was */
4096 scanner.startPosition = startPos;
4097 scanner.currentPosition = currentPos;
4100 public static final int RoundBracket = 0;
4102 public static final int SquareBracket = 1;
4104 public static final int CurlyBracket = 2;
4106 public static final int BracketKinds = 3;
4108 protected int[] nestedMethod; //the ptr is nestedType
4110 protected int nestedType, dimensions;
4112 //variable set stack
4113 final static int VariableStackIncrement = 10;
4115 HashMap fTypeVariables = null;
4117 HashMap fMethodVariables = null;
4119 ArrayList fStackUnassigned = new ArrayList();
4122 final static int AstStackIncrement = 100;
4124 protected int astPtr;
4126 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4128 protected int astLengthPtr;
4130 protected int[] astLengthStack;
4132 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4134 public CompilationUnitDeclaration compilationUnit; /*
4135 * the result from parse()
4138 protected ReferenceContext referenceContext;
4140 protected ProblemReporter problemReporter;
4142 protected CompilerOptions options;
4144 private ArrayList includesList;
4146 // protected CompilationResult compilationResult;
4148 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
4149 * reported, so initializes the compilation result's line positions.
4151 public ProblemReporter problemReporter() {
4152 if (scanner.recordLineSeparator) {
4153 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4155 problemReporter.referenceContext = referenceContext;
4156 return problemReporter;
4160 * Reconsider the entire source looking for inconsistencies in {} () []
4162 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
4163 scanner.wasAcr = false;
4164 boolean anomaliesDetected = false;
4166 char[] source = scanner.source;
4167 int[] leftCount = { 0, 0, 0 };
4168 int[] rightCount = { 0, 0, 0 };
4169 int[] depths = { 0, 0, 0 };
4170 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
4171 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4172 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
4173 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
4174 scanner.currentPosition = scanner.initialPosition; //starting
4176 // (first-zero-based
4178 while (scanner.currentPosition < scanner.eofPosition) { //loop for
4183 // ---------Consume white space and handles
4184 // startPosition---------
4185 boolean isWhiteSpace;
4187 scanner.startPosition = scanner.currentPosition;
4188 // if (((scanner.currentCharacter =
4189 // source[scanner.currentPosition++]) == '\\') &&
4190 // (source[scanner.currentPosition] == 'u')) {
4191 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4193 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4194 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4195 // only record line positions we have not
4197 scanner.pushLineSeparator();
4200 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4202 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4203 // -------consume token until } is found---------
4204 switch (scanner.currentCharacter) {
4206 int index = leftCount[CurlyBracket]++;
4207 if (index == leftPositions[CurlyBracket].length) {
4208 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4209 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
4211 leftPositions[CurlyBracket][index] = scanner.startPosition;
4212 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4216 int index = rightCount[CurlyBracket]++;
4217 if (index == rightPositions[CurlyBracket].length) {
4218 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4219 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
4221 rightPositions[CurlyBracket][index] = scanner.startPosition;
4222 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4226 int index = leftCount[RoundBracket]++;
4227 if (index == leftPositions[RoundBracket].length) {
4228 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4229 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
4231 leftPositions[RoundBracket][index] = scanner.startPosition;
4232 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4236 int index = rightCount[RoundBracket]++;
4237 if (index == rightPositions[RoundBracket].length) {
4238 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4239 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
4241 rightPositions[RoundBracket][index] = scanner.startPosition;
4242 rightDepths[RoundBracket][index] = --depths[RoundBracket];
4246 int index = leftCount[SquareBracket]++;
4247 if (index == leftPositions[SquareBracket].length) {
4248 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4249 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
4251 leftPositions[SquareBracket][index] = scanner.startPosition;
4252 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4256 int index = rightCount[SquareBracket]++;
4257 if (index == rightPositions[SquareBracket].length) {
4258 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4259 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
4261 rightPositions[SquareBracket][index] = scanner.startPosition;
4262 rightDepths[SquareBracket][index] = --depths[SquareBracket];
4266 if (scanner.getNextChar('\\')) {
4267 scanner.scanEscapeCharacter();
4268 } else { // consume next character
4269 scanner.unicodeAsBackSlash = false;
4270 // if (((scanner.currentCharacter =
4271 // source[scanner.currentPosition++]) ==
4273 // (source[scanner.currentPosition] ==
4275 // scanner.getNextUnicodeChar();
4277 if (scanner.withoutUnicodePtr != 0) {
4278 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4282 scanner.getNextChar('\'');
4286 // consume next character
4287 scanner.unicodeAsBackSlash = false;
4288 // if (((scanner.currentCharacter =
4289 // source[scanner.currentPosition++]) == '\\') &&
4290 // (source[scanner.currentPosition] == 'u')) {
4291 // scanner.getNextUnicodeChar();
4293 if (scanner.withoutUnicodePtr != 0) {
4294 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4297 while (scanner.currentCharacter != '"') {
4298 if (scanner.currentCharacter == '\r') {
4299 if (source[scanner.currentPosition] == '\n')
4300 scanner.currentPosition++;
4301 break; // the string cannot go further that
4304 if (scanner.currentCharacter == '\n') {
4305 break; // the string cannot go further that
4308 if (scanner.currentCharacter == '\\') {
4309 scanner.scanEscapeCharacter();
4311 // consume next character
4312 scanner.unicodeAsBackSlash = false;
4313 // if (((scanner.currentCharacter =
4314 // source[scanner.currentPosition++]) == '\\')
4315 // && (source[scanner.currentPosition] == 'u'))
4317 // scanner.getNextUnicodeChar();
4319 if (scanner.withoutUnicodePtr != 0) {
4320 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4327 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4330 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4331 && (source[scanner.currentPosition] == 'u')) {
4332 //-------------unicode traitement
4334 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4335 scanner.currentPosition++;
4336 while (source[scanner.currentPosition] == 'u') {
4337 scanner.currentPosition++;
4339 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4340 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4341 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4342 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4346 scanner.currentCharacter = 'A';
4347 } //something different from \n and \r
4349 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4352 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
4354 scanner.startPosition = scanner.currentPosition;
4355 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4356 && (source[scanner.currentPosition] == 'u')) {
4357 //-------------unicode traitement
4359 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4360 scanner.currentPosition++;
4361 while (source[scanner.currentPosition] == 'u') {
4362 scanner.currentPosition++;
4364 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4365 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4366 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4367 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4371 scanner.currentCharacter = 'A';
4372 } //something different from \n
4375 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4379 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4380 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4381 // only record line positions we
4382 // have not recorded yet
4383 scanner.pushLineSeparator();
4384 if (this.scanner.taskTags != null) {
4385 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4386 .getCurrentTokenEndPosition());
4392 if (test > 0) { //traditional and annotation
4394 boolean star = false;
4395 // consume next character
4396 scanner.unicodeAsBackSlash = false;
4397 // if (((scanner.currentCharacter =
4398 // source[scanner.currentPosition++]) ==
4400 // (source[scanner.currentPosition] ==
4402 // scanner.getNextUnicodeChar();
4404 if (scanner.withoutUnicodePtr != 0) {
4405 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4408 if (scanner.currentCharacter == '*') {
4412 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4413 && (source[scanner.currentPosition] == 'u')) {
4414 //-------------unicode traitement
4416 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4417 scanner.currentPosition++;
4418 while (source[scanner.currentPosition] == 'u') {
4419 scanner.currentPosition++;
4421 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4422 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4423 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4424 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4428 scanner.currentCharacter = 'A';
4429 } //something different from * and /
4431 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4434 //loop until end of comment */
4435 while ((scanner.currentCharacter != '/') || (!star)) {
4436 star = scanner.currentCharacter == '*';
4438 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4439 && (source[scanner.currentPosition] == 'u')) {
4440 //-------------unicode traitement
4442 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4443 scanner.currentPosition++;
4444 while (source[scanner.currentPosition] == 'u') {
4445 scanner.currentPosition++;
4447 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4448 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4449 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4450 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4454 scanner.currentCharacter = 'A';
4455 } //something different from * and
4458 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4462 if (this.scanner.taskTags != null) {
4463 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4470 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4471 scanner.scanIdentifierOrKeyword(false);
4474 if (Character.isDigit(scanner.currentCharacter)) {
4475 scanner.scanNumber(false);
4479 //-----------------end switch while
4480 // try--------------------
4481 } catch (IndexOutOfBoundsException e) {
4482 break; // read until EOF
4483 } catch (InvalidInputException e) {
4484 return false; // no clue
4487 if (scanner.recordLineSeparator) {
4488 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4490 // check placement anomalies against other kinds of brackets
4491 for (int kind = 0; kind < BracketKinds; kind++) {
4492 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4493 int start = leftPositions[kind][leftIndex]; // deepest
4495 // find matching closing bracket
4496 int depth = leftDepths[kind][leftIndex];
4498 for (int i = 0; i < rightCount[kind]; i++) {
4499 int pos = rightPositions[kind][i];
4500 // want matching bracket further in source with same
4502 if ((pos > start) && (depth == rightDepths[kind][i])) {
4507 if (end < 0) { // did not find a good closing match
4508 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4511 // check if even number of opening/closing other brackets
4512 // in between this pair of brackets
4514 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4515 for (int i = 0; i < leftCount[otherKind]; i++) {
4516 int pos = leftPositions[otherKind][i];
4517 if ((pos > start) && (pos < end))
4520 for (int i = 0; i < rightCount[otherKind]; i++) {
4521 int pos = rightPositions[otherKind][i];
4522 if ((pos > start) && (pos < end))
4526 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4532 // too many opening brackets ?
4533 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4534 anomaliesDetected = true;
4535 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4536 compilationUnit.compilationResult);
4538 // too many closing brackets ?
4539 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4540 anomaliesDetected = true;
4541 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4543 if (anomaliesDetected)
4546 return anomaliesDetected;
4547 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4548 return anomaliesDetected;
4549 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4550 return anomaliesDetected;
4554 protected void pushOnAstLengthStack(int pos) {
4556 astLengthStack[++astLengthPtr] = pos;
4557 } catch (IndexOutOfBoundsException e) {
4558 int oldStackLength = astLengthStack.length;
4559 int[] oldPos = astLengthStack;
4560 astLengthStack = new int[oldStackLength + StackIncrement];
4561 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4562 astLengthStack[astLengthPtr] = pos;
4566 protected void pushOnAstStack(ASTNode node) {
4568 * add a new obj on top of the ast stack
4571 astStack[++astPtr] = node;
4572 } catch (IndexOutOfBoundsException e) {
4573 int oldStackLength = astStack.length;
4574 ASTNode[] oldStack = astStack;
4575 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4576 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4577 astPtr = oldStackLength;
4578 astStack[astPtr] = node;
4581 astLengthStack[++astLengthPtr] = 1;
4582 } catch (IndexOutOfBoundsException e) {
4583 int oldStackLength = astLengthStack.length;
4584 int[] oldPos = astLengthStack;
4585 astLengthStack = new int[oldStackLength + AstStackIncrement];
4586 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4587 astLengthStack[astLengthPtr] = 1;
4591 protected void resetModifiers() {
4592 this.modifiers = AccDefault;
4593 this.modifiersSourceStart = -1; // <-- see comment into
4594 // modifiersFlag(int)
4595 this.scanner.commentPtr = -1;
4598 protected void consumePackageDeclarationName(IFile file) {
4599 // create a package name similar to java package names
4600 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4601 String filePath = file.getRawLocation().toString();
4602 String ext = file.getRawLocation().getFileExtension();
4603 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4604 ImportReference impt;
4607 if (filePath.startsWith(projectPath)) {
4608 tokens = CharOperation
4609 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4611 String name = file.getName();
4612 tokens = new char[1][];
4613 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4616 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4618 impt.declarationSourceStart = 0;
4619 impt.declarationSourceEnd = 0;
4620 impt.declarationEnd = 0;
4621 //endPosition is just before the ;
4625 public final static String[] GLOBALS = {
4640 private void pushFunctionVariableSet() {
4641 HashSet set = new HashSet();
4642 if (fStackUnassigned.isEmpty()) {
4643 for (int i = 0; i < GLOBALS.length; i++) {
4644 set.add(GLOBALS[i]);
4647 fStackUnassigned.add(set);
4650 private void pushIfVariableSet() {
4651 if (!fStackUnassigned.isEmpty()) {
4652 HashSet set = new HashSet();
4653 fStackUnassigned.add(set);
4657 private HashSet removeIfVariableSet() {
4658 if (!fStackUnassigned.isEmpty()) {
4659 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4665 * Returns the <i>set of assigned variables </i> returns null if no Set is defined at the current scanner position
4667 private HashSet peekVariableSet() {
4668 if (!fStackUnassigned.isEmpty()) {
4669 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4675 * add the current identifier source to the <i>set of assigned variables </i>
4679 private void addVariableSet(HashSet set) {
4681 set.add(new String(scanner.getCurrentTokenSource()));
4686 * add the current identifier source to the <i>set of assigned variables </i>
4689 private void addVariableSet() {
4690 HashSet set = peekVariableSet();
4692 set.add(new String(scanner.getCurrentTokenSource()));
4697 * add the current identifier source to the <i>set of assigned variables </i>
4700 private void addVariableSet(char[] token) {
4701 HashSet set = peekVariableSet();
4703 set.add(new String(token));
4708 * check if the current identifier source is in the <i>set of assigned variables </i> Returns true, if no set is defined for the
4709 * current scanner position
4712 private boolean containsVariableSet() {
4713 return containsVariableSet(scanner.getCurrentTokenSource());
4714 // if (!fStackUnassigned.isEmpty()) {
4716 // String str = new String(scanner.getCurrentTokenSource());
4717 // for (int i = 0; i < fStackUnassigned.size(); i++) {
4718 // set = (HashSet) fStackUnassigned.get(i);
4719 // if (set.contains(str)) {
4728 private boolean containsVariableSet(char[] token) {
4730 if (!fStackUnassigned.isEmpty()) {
4732 String str = new String(token);
4733 for (int i = 0; i < fStackUnassigned.size(); i++) {
4734 set = (HashSet) fStackUnassigned.get(i);
4735 if (set.contains(str)) {