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;
13 import net.sourceforge.phpdt.core.compiler.CharOperation;
14 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
15 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
16 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
17 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
18 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
19 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
21 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
22 import net.sourceforge.phpdt.internal.compiler.util.Util;
23 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
24 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
52 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
54 import org.eclipse.core.resources.IFile;
55 import org.eclipse.core.resources.IProject;
56 import org.eclipse.core.resources.IResource;
57 import org.eclipse.core.runtime.IPath;
59 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
60 protected final static int StackIncrement = 255;
62 protected int stateStackTop;
64 // protected int[] stack = new int[StackIncrement];
66 public int firstToken; // handle for multiple parsing goals
68 public int lastAct; //handle for multiple parsing goals
70 // protected RecoveredElement currentElement;
72 public static boolean VERBOSE_RECOVERY = false;
74 protected boolean diet = false; //tells the scanner to jump over some
76 // parts of the code/expressions like
79 public Scanner scanner;
81 // private ArrayList phpList;
83 // private int currentPHPString;
85 // private boolean phpEnd;
87 // private static HashMap keywordMap = null;
95 // row counter for syntax errors:
97 // column counter for syntax errors:
101 // // current identifier
102 // String identifier;
105 // Double doubleNumber;
107 // private String stringValue;
109 /** Contains the current expression. */
110 // private StringBuffer expression;
111 //private boolean phpMode;
112 protected int modifiers;
114 protected int modifiersSourceStart;
116 protected Parser(ProblemReporter problemReporter) {
117 this.problemReporter = problemReporter;
118 this.options = problemReporter.options;
119 // this.currentPHPString = 0;
120 // PHPParserSuperclass.fileToParse = fileToParse;
121 // this.phpList = null;
122 // this.indexManager = null;
124 this.token = TokenNameEOF;
126 // this.rowCount = 1;
127 // this.columnCount = 0;
128 // this.phpEnd = false;
130 this.initializeScanner();
133 public void setFileToParse(IFile fileToParse) {
134 // this.currentPHPString = 0;
135 // PHPParserSuperclass.fileToParse = fileToParse;
136 // this.phpList = null;
137 // this.indexManager = null;
139 this.token = TokenNameEOF;
140 // this.phpEnd = false;
141 this.initializeScanner();
145 * ClassDeclaration Constructor.
149 * Description of Parameter
152 public Parser(IFile fileToParse) {
153 // if (keywordMap == null) {
154 // keywordMap = new HashMap();
155 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
156 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
159 // this.currentPHPString = 0;
160 // PHPParserSuperclass.fileToParse = fileToParse;
161 // this.phpList = null;
162 this.includesList = null;
164 this.token = TokenNameEOF;
166 // this.rowCount = 1;
167 // this.columnCount = 0;
168 // this.phpEnd = false;
170 this.initializeScanner();
173 public void initializeScanner() {
174 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
175 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
176 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
180 * Create marker for the parse error
182 // private void setMarker(String message, int charStart, int charEnd, int
184 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
187 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
191 * @throws SyntaxError
194 private void throwSyntaxError(String error) {
195 int problemStartPosition = scanner.getCurrentTokenStartPosition();
196 int problemEndPosition = scanner.getCurrentTokenEndPosition();
197 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
201 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
205 * @throws SyntaxError
208 // private void throwSyntaxError(String error, int startRow) {
209 // throw new SyntaxError(startRow, 0, " ", error);
211 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
212 if (referenceContext != null) {
213 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
214 compilationUnit.compilationResult);
216 throw new SyntaxError(1, 0, " ", error);
219 private void reportSyntaxError(String error) {
220 int problemStartPosition = scanner.getCurrentTokenStartPosition();
221 int problemEndPosition = scanner.getCurrentTokenEndPosition();
222 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
225 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
226 if (referenceContext != null) {
227 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
228 compilationUnit.compilationResult);
232 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
233 if (referenceContext != null) {
234 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
235 compilationUnit.compilationResult);
240 * gets the next token from input
242 private void getNextToken() {
244 token = scanner.getNextToken();
246 int currentEndPosition = scanner.getCurrentTokenEndPosition();
247 int currentStartPosition = scanner.getCurrentTokenStartPosition();
248 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
249 System.out.println(scanner.toStringAction(token));
251 } catch (InvalidInputException e) {
252 token = TokenNameERROR;
253 String detailedMessage = e.getMessage();
255 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
256 throwSyntaxError("Unterminated string.");
257 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
258 throwSyntaxError("Unterminated commment.");
264 public void init(String s) {
266 this.token = TokenNameEOF;
267 this.includesList = new ArrayList();
269 // this.rowCount = 1;
270 // this.columnCount = 0;
271 // this.phpEnd = false;
272 // this.phpMode = false;
273 /* scanner initialization */
274 scanner.setSource(s.toCharArray());
275 scanner.setPHPMode(false);
279 protected void initialize(boolean phpMode) {
280 initialize(phpMode, null);
283 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
284 compilationUnit = null;
285 referenceContext = null;
286 this.includesList = new ArrayList();
287 // this.indexManager = indexManager;
289 this.token = TokenNameEOF;
291 // this.rowCount = 1;
292 // this.columnCount = 0;
293 // this.phpEnd = false;
294 // this.phpMode = phpMode;
295 scanner.setPHPMode(phpMode);
300 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
302 public void parse(String s) {
307 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
309 public void parse(String s, HashMap variables) {
310 fMethodVariables = variables;
316 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
318 protected void parse() {
319 if (scanner.compilationUnit != null) {
320 IResource resource = scanner.compilationUnit.getResource();
321 if (resource != null && resource instanceof IFile) {
322 // set the package name
323 consumePackageDeclarationName((IFile) resource);
329 if (token != TokenNameEOF && token != TokenNameERROR) {
332 if (token != TokenNameEOF) {
333 if (token == TokenNameERROR) {
334 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
336 if (token == TokenNameRPAREN) {
337 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
339 if (token == TokenNameRBRACE) {
340 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
342 if (token == TokenNameRBRACKET) {
343 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
345 if (token == TokenNameLPAREN) {
346 throwSyntaxError("Read character '('; end-of-file not reached.");
348 if (token == TokenNameLBRACE) {
349 throwSyntaxError("Read character '{'; end-of-file not reached.");
351 if (token == TokenNameLBRACKET) {
352 throwSyntaxError("Read character '['; end-of-file not reached.");
354 throwSyntaxError("End-of-file not reached.");
357 } catch (SyntaxError sytaxErr1) {
359 // // if an error occured,
360 // // try to find keywords 'abstract' 'final' 'class' or 'function'
361 // // to parse the rest of the string
362 // boolean tokenize = scanner.tokenizeStrings;
364 // scanner.tokenizeStrings = true;
367 // while (token != TokenNameEOF) {
368 // if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
373 // if (token == TokenNameEOF) {
376 // } catch (SyntaxError sytaxErr2) {
379 // scanner.tokenizeStrings = tokenize;
388 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
390 public void parseFunction(String s, HashMap variables) {
392 scanner.phpMode = true;
393 parseFunction(variables);
397 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
399 protected void parseFunction(HashMap variables) {
401 boolean hasModifiers = member_modifiers();
402 if (token == TokenNamefunction) {
404 checkAndSetModifiers(AccPublic);
406 this.fMethodVariables = variables;
408 MethodDeclaration methodDecl = new MethodDeclaration(null);
409 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
410 methodDecl.modifiers = this.modifiers;
411 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
414 functionDefinition(methodDecl);
415 } catch (SyntaxError sytaxErr1) {
418 int sourceEnd = scanner.getCurrentTokenStartPosition();
419 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
420 sourceEnd = methodDecl.declarationSourceStart + 1;
422 methodDecl.declarationSourceEnd = sourceEnd;
427 protected CompilationUnitDeclaration endParse(int act) {
431 // if (currentElement != null) {
432 // currentElement.topElement().updateParseTree();
433 // if (VERBOSE_RECOVERY) {
434 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
435 // System.out.println("--------------------------"); //$NON-NLS-1$
436 // System.out.println(compilationUnit);
437 // System.out.println("----------------------------------"); //$NON-NLS-1$
440 if (diet & VERBOSE_RECOVERY) {
441 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
442 System.out.println("--------------------------"); //$NON-NLS-1$
443 System.out.println(compilationUnit);
444 System.out.println("----------------------------------"); //$NON-NLS-1$
447 if (scanner.recordLineSeparator) {
448 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
450 if (scanner.taskTags != null) {
451 for (int i = 0; i < scanner.foundTaskCount; i++) {
452 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
453 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
454 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
457 compilationUnit.imports = new ImportReference[includesList.size()];
458 for (int i = 0; i < includesList.size(); i++) {
459 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
461 return compilationUnit;
464 private Block statementList() {
465 boolean branchStatement = false;
467 int blockStart = scanner.getCurrentTokenStartPosition();
468 ArrayList blockStatements = new ArrayList();
471 statement = statement();
472 blockStatements.add(statement);
473 if (branchStatement && statement!=null) {
474 reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
476 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
477 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
478 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
479 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
480 return createBlock(blockStart, blockStatements);
482 branchStatement = checkUnreachableStatements(statement);
483 } catch (SyntaxError sytaxErr1) {
484 // if an error occured,
485 // try to find keywords
486 // to parse the rest of the string
487 boolean tokenize = scanner.tokenizeStrings;
489 scanner.tokenizeStrings = true;
492 while (token != TokenNameEOF) {
493 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
494 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
495 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
496 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
497 return createBlock(blockStart, blockStatements);
499 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
500 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
501 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
502 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
503 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
504 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
507 // System.out.println(scanner.toStringAction(token));
509 // System.out.println(scanner.toStringAction(token));
511 if (token == TokenNameEOF) {
515 scanner.tokenizeStrings = tokenize;
525 private boolean checkUnreachableStatements(Statement statement) {
526 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
528 } else if (statement instanceof IfStatement && ((IfStatement)statement).checkUnreachable) {
536 * @param blockStatements
539 private Block createBlock(int blockStart, ArrayList blockStatements) {
540 int blockEnd = scanner.getCurrentTokenEndPosition();
541 Block b = Block.EmptyWith(blockStart, blockEnd);
542 b.statements = new Statement[blockStatements.size()];
543 blockStatements.toArray(b.statements);
547 private void functionBody(MethodDeclaration methodDecl) {
548 // '{' [statement-list] '}'
549 if (token == TokenNameLBRACE) {
552 throwSyntaxError("'{' expected in compound-statement.");
554 if (token != TokenNameRBRACE) {
557 if (token == TokenNameRBRACE) {
558 // methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
561 throwSyntaxError("'}' expected in compound-statement.");
565 private Statement statement() {
566 Statement statement = null;
567 Expression expression;
568 int sourceStart = scanner.getCurrentTokenStartPosition();
570 if (token == TokenNameif) {
571 // T_IF '(' expr ')' statement elseif_list else_single
572 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
574 if (token == TokenNameLPAREN) {
577 throwSyntaxError("'(' expected after 'if' keyword.");
580 if (token == TokenNameRPAREN) {
583 throwSyntaxError("')' expected after 'if' condition.");
585 // create basic IfStatement
586 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
587 if (token == TokenNameCOLON) {
589 ifStatementColon(ifStatement);
591 ifStatement(ifStatement);
594 } else if (token == TokenNameswitch) {
596 if (token == TokenNameLPAREN) {
599 throwSyntaxError("'(' expected after 'switch' keyword.");
602 if (token == TokenNameRPAREN) {
605 throwSyntaxError("')' expected after 'switch' condition.");
609 } else if (token == TokenNamefor) {
611 if (token == TokenNameLPAREN) {
614 throwSyntaxError("'(' expected after 'for' keyword.");
616 if (token == TokenNameSEMICOLON) {
620 if (token == TokenNameSEMICOLON) {
623 throwSyntaxError("';' expected after 'for'.");
626 if (token == TokenNameSEMICOLON) {
630 if (token == TokenNameSEMICOLON) {
633 throwSyntaxError("';' expected after 'for'.");
636 if (token == TokenNameRPAREN) {
640 if (token == TokenNameRPAREN) {
643 throwSyntaxError("')' expected after 'for'.");
648 } else if (token == TokenNamewhile) {
650 if (token == TokenNameLPAREN) {
653 throwSyntaxError("'(' expected after 'while' keyword.");
656 if (token == TokenNameRPAREN) {
659 throwSyntaxError("')' expected after 'while' condition.");
663 } else if (token == TokenNamedo) {
665 if (token == TokenNameLBRACE) {
667 if (token != TokenNameRBRACE) {
670 if (token == TokenNameRBRACE) {
673 throwSyntaxError("'}' expected after 'do' keyword.");
678 if (token == TokenNamewhile) {
680 if (token == TokenNameLPAREN) {
683 throwSyntaxError("'(' expected after 'while' keyword.");
686 if (token == TokenNameRPAREN) {
689 throwSyntaxError("')' expected after 'while' condition.");
692 throwSyntaxError("'while' expected after 'do' keyword.");
694 if (token == TokenNameSEMICOLON) {
697 if (token != TokenNameINLINE_HTML) {
698 throwSyntaxError("';' expected after do-while statement.");
703 } else if (token == TokenNameforeach) {
705 if (token == TokenNameLPAREN) {
708 throwSyntaxError("'(' expected after 'foreach' keyword.");
711 if (token == TokenNameas) {
714 throwSyntaxError("'as' expected after 'foreach' exxpression.");
718 foreach_optional_arg();
719 if (token == TokenNameEQUAL_GREATER) {
723 if (token == TokenNameRPAREN) {
726 throwSyntaxError("')' expected after 'foreach' expression.");
730 } else if (token == TokenNamebreak) {
733 if (token != TokenNameSEMICOLON) {
736 if (token == TokenNameSEMICOLON) {
737 sourceEnd = scanner.getCurrentTokenEndPosition();
740 if (token != TokenNameINLINE_HTML) {
741 throwSyntaxError("';' expected after 'break'.");
743 sourceEnd = scanner.getCurrentTokenEndPosition();
746 return new BreakStatement(null, sourceStart, sourceEnd);
747 } else if (token == TokenNamecontinue) {
750 if (token != TokenNameSEMICOLON) {
753 if (token == TokenNameSEMICOLON) {
754 sourceEnd = scanner.getCurrentTokenEndPosition();
757 if (token != TokenNameINLINE_HTML) {
758 throwSyntaxError("';' expected after 'continue'.");
760 sourceEnd = scanner.getCurrentTokenEndPosition();
763 return new ContinueStatement(null, sourceStart, sourceEnd);
764 } else if (token == TokenNamereturn) {
767 if (token != TokenNameSEMICOLON) {
770 if (token == TokenNameSEMICOLON) {
771 sourceEnd = scanner.getCurrentTokenEndPosition();
774 if (token != TokenNameINLINE_HTML) {
775 throwSyntaxError("';' expected after 'return'.");
777 sourceEnd = scanner.getCurrentTokenEndPosition();
780 return new ReturnStatement(expression, sourceStart, sourceEnd);
781 } else if (token == TokenNameecho) {
784 if (token == TokenNameSEMICOLON) {
787 if (token != TokenNameINLINE_HTML) {
788 throwSyntaxError("';' expected after 'echo' statement.");
793 } else if (token == TokenNameINLINE_HTML) {
796 // } else if (token == TokenNameprint) {
799 // if (token == TokenNameSEMICOLON) {
802 // if (token != TokenNameStopPHP) {
803 // throwSyntaxError("';' expected after 'print' statement.");
808 } else if (token == TokenNameglobal) {
811 if (token == TokenNameSEMICOLON) {
814 if (token != TokenNameINLINE_HTML) {
815 throwSyntaxError("';' expected after 'global' statement.");
820 } else if (token == TokenNamestatic) {
823 if (token == TokenNameSEMICOLON) {
826 if (token != TokenNameINLINE_HTML) {
827 throwSyntaxError("';' expected after 'static' statement.");
832 } else if (token == TokenNameunset) {
834 if (token == TokenNameLPAREN) {
837 throwSyntaxError("'(' expected after 'unset' statement.");
840 if (token == TokenNameRPAREN) {
843 throwSyntaxError("')' expected after 'unset' statement.");
845 if (token == TokenNameSEMICOLON) {
848 if (token != TokenNameINLINE_HTML) {
849 throwSyntaxError("';' expected after 'unset' statement.");
854 } else if (token == TokenNamefunction) {
855 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
856 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
857 methodDecl.modifiers = AccDefault;
858 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
861 functionDefinition(methodDecl);
863 sourceEnd = scanner.getCurrentTokenStartPosition();
864 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
865 sourceEnd = methodDecl.declarationSourceStart + 1;
867 methodDecl.declarationSourceEnd = sourceEnd;
870 } else if (token == TokenNamedeclare) {
871 //T_DECLARE '(' declare_list ')' declare_statement
873 if (token != TokenNameLPAREN) {
874 throwSyntaxError("'(' expected in 'declare' statement.");
878 if (token != TokenNameRPAREN) {
879 throwSyntaxError("')' expected in 'declare' statement.");
884 } else if (token == TokenNametry) {
886 if (token != TokenNameLBRACE) {
887 throwSyntaxError("'{' expected in 'try' statement.");
891 if (token != TokenNameRBRACE) {
892 throwSyntaxError("'}' expected in 'try' statement.");
896 } else if (token == TokenNamecatch) {
898 if (token != TokenNameLPAREN) {
899 throwSyntaxError("'(' expected in 'catch' statement.");
902 fully_qualified_class_name();
903 if (token != TokenNameVariable) {
904 throwSyntaxError("Variable expected in 'catch' statement.");
907 if (token != TokenNameRPAREN) {
908 throwSyntaxError("')' expected in 'catch' statement.");
911 if (token != TokenNameLBRACE) {
912 throwSyntaxError("'{' expected in 'catch' statement.");
915 if (token != TokenNameRBRACE) {
917 if (token != TokenNameRBRACE) {
918 throwSyntaxError("'}' expected in 'catch' statement.");
922 additional_catches();
924 } else if (token == TokenNamethrow) {
927 if (token == TokenNameSEMICOLON) {
930 throwSyntaxError("';' expected after 'throw' exxpression.");
933 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
935 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
936 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
937 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
938 typeDecl.name = new char[] { ' ' };
939 // default super class
940 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
941 compilationUnit.types.add(typeDecl);
942 pushOnAstStack(typeDecl);
943 unticked_class_declaration_statement(typeDecl);
951 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
952 } else if (token == TokenNameLBRACE) {
954 if (token != TokenNameRBRACE) {
955 statement = statementList();
957 if (token == TokenNameRBRACE) {
961 throwSyntaxError("'}' expected.");
964 if (token != TokenNameSEMICOLON) {
967 if (token == TokenNameSEMICOLON) {
971 if (token == TokenNameRBRACE) {
972 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
974 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
975 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
985 private void declare_statement() {
987 //| ':' inner_statement_list T_ENDDECLARE ';'
989 if (token == TokenNameCOLON) {
991 // TODO: implement inner_statement_list();
993 if (token != TokenNameenddeclare) {
994 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
997 if (token != TokenNameSEMICOLON) {
998 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1006 private void declare_list() {
1007 // T_STRING '=' static_scalar
1008 //| declare_list ',' T_STRING '=' static_scalar
1010 if (token != TokenNameIdentifier) {
1011 throwSyntaxError("Identifier expected in 'declare' list.");
1014 if (token != TokenNameEQUAL) {
1015 throwSyntaxError("'=' expected in 'declare' list.");
1019 if (token != TokenNameCOMMA) {
1026 private void additional_catches() {
1027 while (token == TokenNamecatch) {
1029 if (token != TokenNameLPAREN) {
1030 throwSyntaxError("'(' expected in 'catch' statement.");
1033 fully_qualified_class_name();
1034 if (token != TokenNameVariable) {
1035 throwSyntaxError("Variable expected in 'catch' statement.");
1038 if (token != TokenNameRPAREN) {
1039 throwSyntaxError("')' expected in 'catch' statement.");
1042 if (token != TokenNameLBRACE) {
1043 throwSyntaxError("'{' expected in 'catch' statement.");
1046 if (token != TokenNameRBRACE) {
1049 if (token != TokenNameRBRACE) {
1050 throwSyntaxError("'}' expected in 'catch' statement.");
1056 private void foreach_variable() {
1059 if (token == TokenNameAND) {
1065 private void foreach_optional_arg() {
1067 //| T_DOUBLE_ARROW foreach_variable
1068 if (token == TokenNameEQUAL_GREATER) {
1074 private void global_var_list() {
1076 // global_var_list ',' global_var
1080 if (token != TokenNameCOMMA) {
1087 private void global_var() {
1091 //| '$' '{' expr '}'
1092 if (token == TokenNameVariable) {
1093 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1094 if (fMethodVariables != null) {
1095 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1098 } else if (token == TokenNameDOLLAR) {
1100 if (token == TokenNameLBRACE) {
1103 if (token != TokenNameRBRACE) {
1104 throwSyntaxError("'}' expected in global variable.");
1113 private void static_var_list() {
1115 // static_var_list ',' T_VARIABLE
1116 //| static_var_list ',' T_VARIABLE '=' static_scalar
1118 //| T_VARIABLE '=' static_scalar
1120 if (token == TokenNameVariable) {
1121 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1122 if (fMethodVariables != null) {
1123 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1126 if (token == TokenNameEQUAL) {
1130 if (token != TokenNameCOMMA) {
1140 private void unset_variables() {
1143 // | unset_variables ',' unset_variable
1148 if (token != TokenNameCOMMA) {
1155 private final void initializeModifiers() {
1157 this.modifiersSourceStart = -1;
1160 private final void checkAndSetModifiers(int flag) {
1161 this.modifiers |= flag;
1162 if (this.modifiersSourceStart < 0)
1163 this.modifiersSourceStart = this.scanner.startPosition;
1166 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1167 initializeModifiers();
1168 if (token == TokenNameinterface) {
1169 // interface_entry T_STRING
1170 // interface_extends_list
1171 // '{' class_statement_list '}'
1172 checkAndSetModifiers(AccInterface);
1174 typeDecl.modifiers = this.modifiers;
1175 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1176 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1177 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1178 typeDecl.name = scanner.getCurrentIdentifierSource();
1179 if (token > TokenNameKEYWORD) {
1180 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1181 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1182 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1183 // typeDecl.sourceStart, typeDecl.sourceEnd);
1186 interface_extends_list(typeDecl);
1188 typeDecl.name = new char[] { ' ' };
1189 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1193 // class_entry_type T_STRING extends_from
1195 // '{' class_statement_list'}'
1197 typeDecl.modifiers = this.modifiers;
1198 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1199 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1201 //identifier 'extends' identifier
1202 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1203 typeDecl.name = scanner.getCurrentIdentifierSource();
1204 if (token > TokenNameKEYWORD) {
1205 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1206 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1207 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1208 // typeDecl.sourceStart, typeDecl.sourceEnd);
1213 // | T_EXTENDS fully_qualified_class_name
1214 if (token == TokenNameextends) {
1215 interface_extends_list(typeDecl);
1217 // if (token != TokenNameIdentifier) {
1218 // throwSyntaxError("Class name expected after keyword
1220 // scanner.getCurrentTokenStartPosition(), scanner
1221 // .getCurrentTokenEndPosition());
1224 implements_list(typeDecl);
1226 typeDecl.name = new char[] { ' ' };
1227 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1231 // '{' class_statement_list '}'
1232 if (token == TokenNameLBRACE) {
1234 if (token != TokenNameRBRACE) {
1235 ArrayList list = new ArrayList();
1236 class_statement_list(list);
1237 typeDecl.fields = new FieldDeclaration[list.size()];
1238 for (int i = 0; i < list.size(); i++) {
1239 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1242 if (token == TokenNameRBRACE) {
1243 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1246 throwSyntaxError("'}' expected at end of class body.");
1249 throwSyntaxError("'{' expected at start of class body.");
1253 private void class_entry_type() {
1255 // | T_ABSTRACT T_CLASS
1256 // | T_FINAL T_CLASS
1257 if (token == TokenNameclass) {
1259 } else if (token == TokenNameabstract) {
1260 checkAndSetModifiers(AccAbstract);
1262 if (token != TokenNameclass) {
1263 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1266 } else if (token == TokenNamefinal) {
1267 checkAndSetModifiers(AccFinal);
1269 if (token != TokenNameclass) {
1270 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1274 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1278 private void class_extends(TypeDeclaration typeDecl) {
1280 // | T_EXTENDS interface_list
1281 if (token == TokenNameextends) {
1284 if (token == TokenNameIdentifier) {
1287 throwSyntaxError("Class name expected after keyword 'extends'.");
1292 private void interface_extends_list(TypeDeclaration typeDecl) {
1294 // | T_EXTENDS interface_list
1295 if (token == TokenNameextends) {
1301 private void implements_list(TypeDeclaration typeDecl) {
1303 // | T_IMPLEMENTS interface_list
1304 if (token == TokenNameimplements) {
1310 private void interface_list() {
1312 // fully_qualified_class_name
1313 //| interface_list ',' fully_qualified_class_name
1315 if (token == TokenNameIdentifier) {
1318 throwSyntaxError("Interface name expected after keyword 'implements'.");
1320 if (token != TokenNameCOMMA) {
1327 // private void classBody(TypeDeclaration typeDecl) {
1328 // //'{' [class-element-list] '}'
1329 // if (token == TokenNameLBRACE) {
1331 // if (token != TokenNameRBRACE) {
1332 // class_statement_list();
1334 // if (token == TokenNameRBRACE) {
1335 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1338 // throwSyntaxError("'}' expected at end of class body.");
1341 // throwSyntaxError("'{' expected at start of class body.");
1344 private void class_statement_list(ArrayList list) {
1347 class_statement(list);
1348 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1349 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1350 || token == TokenNameconst) {
1353 if (token == TokenNameRBRACE) {
1356 throwSyntaxError("'}' at end of class statement.");
1357 } catch (SyntaxError sytaxErr1) {
1358 boolean tokenize = scanner.tokenizeStrings;
1360 scanner.tokenizeStrings = true;
1363 // if an error occured,
1364 // try to find keywords
1365 // to parse the rest of the string
1366 while (token != TokenNameEOF) {
1367 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1368 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1369 || token == TokenNameconst) {
1372 // System.out.println(scanner.toStringAction(token));
1375 if (token == TokenNameEOF) {
1379 scanner.tokenizeStrings = tokenize;
1385 private void class_statement(ArrayList list) {
1387 // variable_modifiers class_variable_declaration ';'
1388 // | class_constant_declaration ';'
1389 // | method_modifiers T_FUNCTION is_reference T_STRING
1390 // '(' parameter_list ')' method_body
1391 initializeModifiers();
1392 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1394 if (token == TokenNamevar) {
1395 checkAndSetModifiers(AccPublic);
1396 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1397 referenceContext, compilationUnit.compilationResult);
1399 class_variable_declaration(declarationSourceStart, list);
1400 } else if (token == TokenNameconst) {
1401 checkAndSetModifiers(AccFinal | AccPublic);
1402 class_constant_declaration(declarationSourceStart, list);
1403 if (token != TokenNameSEMICOLON) {
1404 throwSyntaxError("';' expected after class const declaration.");
1408 boolean hasModifiers = member_modifiers();
1409 if (token == TokenNamefunction) {
1410 if (!hasModifiers) {
1411 checkAndSetModifiers(AccPublic);
1413 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1414 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1415 methodDecl.modifiers = this.modifiers;
1416 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1419 functionDefinition(methodDecl);
1421 int sourceEnd = scanner.getCurrentTokenStartPosition();
1422 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1423 sourceEnd = methodDecl.declarationSourceStart + 1;
1425 methodDecl.declarationSourceEnd = sourceEnd;
1428 if (!hasModifiers) {
1429 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1431 class_variable_declaration(declarationSourceStart, list);
1436 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1437 // class_constant_declaration ',' T_STRING '=' static_scalar
1438 // | T_CONST T_STRING '=' static_scalar
1439 if (token != TokenNameconst) {
1440 throwSyntaxError("'const' keyword expected in class declaration.");
1445 if (token != TokenNameIdentifier) {
1446 throwSyntaxError("Identifier expected in class const declaration.");
1448 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1449 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1450 fieldDeclaration.modifiers = this.modifiers;
1451 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1452 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1453 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1454 // fieldDeclaration.type
1455 list.add(fieldDeclaration);
1457 if (token != TokenNameEQUAL) {
1458 throwSyntaxError("'=' expected in class const declaration.");
1462 if (token != TokenNameCOMMA) {
1463 break; // while(true)-loop
1469 // private void variable_modifiers() {
1470 // // variable_modifiers:
1471 // // non_empty_member_modifiers
1473 // initializeModifiers();
1474 // if (token == TokenNamevar) {
1475 // checkAndSetModifiers(AccPublic);
1476 // reportSyntaxError(
1477 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1479 // modifier for field declarations.",
1480 // scanner.getCurrentTokenStartPosition(), scanner
1481 // .getCurrentTokenEndPosition());
1484 // if (!member_modifiers()) {
1485 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1486 // field declarations.");
1490 // private void method_modifiers() {
1491 // //method_modifiers:
1493 // //| non_empty_member_modifiers
1494 // initializeModifiers();
1495 // if (!member_modifiers()) {
1496 // checkAndSetModifiers(AccPublic);
1499 private boolean member_modifiers() {
1506 boolean foundToken = false;
1508 if (token == TokenNamepublic) {
1509 checkAndSetModifiers(AccPublic);
1512 } else if (token == TokenNameprotected) {
1513 checkAndSetModifiers(AccProtected);
1516 } else if (token == TokenNameprivate) {
1517 checkAndSetModifiers(AccPrivate);
1520 } else if (token == TokenNamestatic) {
1521 checkAndSetModifiers(AccStatic);
1524 } else if (token == TokenNameabstract) {
1525 checkAndSetModifiers(AccAbstract);
1528 } else if (token == TokenNamefinal) {
1529 checkAndSetModifiers(AccFinal);
1539 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1540 // class_variable_declaration:
1541 // class_variable_declaration ',' T_VARIABLE
1542 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1544 // | T_VARIABLE '=' static_scalar
1545 char[] classVariable;
1547 if (token == TokenNameVariable) {
1548 classVariable = scanner.getCurrentIdentifierSource();
1549 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1550 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1551 .getCurrentTokenEndPosition());
1552 fieldDeclaration.modifiers = this.modifiers;
1553 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1554 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1555 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1556 list.add(fieldDeclaration);
1557 if (fTypeVariables != null) {
1558 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1559 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1562 if (token == TokenNameEQUAL) {
1567 // if (token == TokenNamethis) {
1568 // throwSyntaxError("'$this' not allowed after keyword 'public'
1569 // 'protected' 'private' 'var'.");
1571 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1573 if (token != TokenNameCOMMA) {
1578 if (token != TokenNameSEMICOLON) {
1579 throwSyntaxError("';' expected after field declaration.");
1584 private void functionDefinition(MethodDeclaration methodDecl) {
1585 boolean isAbstract = false;
1587 if (compilationUnit != null) {
1588 compilationUnit.types.add(methodDecl);
1591 ASTNode node = astStack[astPtr];
1592 if (node instanceof TypeDeclaration) {
1593 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1594 if (typeDecl.methods == null) {
1595 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1597 AbstractMethodDeclaration[] newMethods;
1598 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1599 typeDecl.methods.length);
1600 newMethods[typeDecl.methods.length] = methodDecl;
1601 typeDecl.methods = newMethods;
1603 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1605 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1610 functionDeclarator(methodDecl);
1611 if (token == TokenNameSEMICOLON) {
1613 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1618 functionBody(methodDecl);
1621 private void functionDeclarator(MethodDeclaration methodDecl) {
1622 //identifier '(' [parameter-list] ')'
1623 if (token == TokenNameAND) {
1626 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1627 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1628 if (Scanner.isIdentifierOrKeyword(token)) {
1629 methodDecl.selector = scanner.getCurrentIdentifierSource();
1630 if (token > TokenNameKEYWORD) {
1631 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1632 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1635 if (token == TokenNameLPAREN) {
1638 throwSyntaxError("'(' expected in function declaration.");
1640 if (token != TokenNameRPAREN) {
1641 parameter_list(methodDecl);
1643 if (token != TokenNameRPAREN) {
1644 throwSyntaxError("')' expected in function declaration.");
1646 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1650 methodDecl.selector = "<undefined>".toCharArray();
1651 throwSyntaxError("Function name expected after keyword 'function'.");
1656 private void parameter_list(MethodDeclaration methodDecl) {
1657 // non_empty_parameter_list
1659 non_empty_parameter_list(methodDecl, true);
1662 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1663 // optional_class_type T_VARIABLE
1664 // | optional_class_type '&' T_VARIABLE
1665 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1666 // | optional_class_type T_VARIABLE '=' static_scalar
1667 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1668 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1669 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1671 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1673 char[] typeIdentifier = null;
1674 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1676 if (token == TokenNameIdentifier) {
1677 typeIdentifier = scanner.getCurrentIdentifierSource();
1680 if (token == TokenNameAND) {
1683 if (token == TokenNameVariable) {
1684 if (fMethodVariables != null) {
1686 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1687 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1689 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1691 info.typeIdentifier = typeIdentifier;
1692 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1695 if (token == TokenNameEQUAL) {
1700 throwSyntaxError("Variable expected in parameter list.");
1702 if (token != TokenNameCOMMA) {
1709 if (!empty_allowed) {
1710 throwSyntaxError("Identifier expected in parameter list.");
1714 private void optional_class_type() {
1719 // private void parameterDeclaration() {
1721 // //variable-reference
1722 // if (token == TokenNameAND) {
1724 // if (isVariable()) {
1727 // throwSyntaxError("Variable expected after reference operator '&'.");
1730 // //variable '=' constant
1731 // if (token == TokenNameVariable) {
1733 // if (token == TokenNameEQUAL) {
1739 // // if (token == TokenNamethis) {
1740 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1741 // // declaration.");
1745 private void labeledStatementList() {
1746 if (token != TokenNamecase && token != TokenNamedefault) {
1747 throwSyntaxError("'case' or 'default' expected.");
1750 if (token == TokenNamecase) {
1752 expr(); //constant();
1753 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1755 if (token == TokenNamecase || token == TokenNamedefault) {
1756 // empty case statement ?
1761 // else if (token == TokenNameSEMICOLON) {
1763 // "':' expected after 'case' keyword (Found token: " +
1764 // scanner.toStringAction(token) + ")",
1765 // scanner.getCurrentTokenStartPosition(),
1766 // scanner.getCurrentTokenEndPosition(),
1769 // if (token == TokenNamecase) { // empty case statement ?
1775 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1777 } else { // TokenNamedefault
1779 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1781 if (token == TokenNameRBRACE) {
1782 // empty default case
1785 if (token != TokenNamecase) {
1789 throwSyntaxError("':' character expected after 'default'.");
1792 } while (token == TokenNamecase || token == TokenNamedefault);
1795 private void ifStatementColon(IfStatement iState) {
1796 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
1797 Block b = inner_statement_list();
1798 iState.thenStatement = b;
1799 checkUnreachable(iState, b);
1800 if (token == TokenNameelseif) {
1801 new_elseif_list(iState);
1803 new_else_single(iState);
1804 if (token != TokenNameendif) {
1805 throwSyntaxError("'endif' expected.");
1808 if (token != TokenNameSEMICOLON) {
1809 reportSyntaxError("';' expected after if-statement.");
1810 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1812 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1817 private void ifStatement(IfStatement iState) {
1818 // T_IF '(' expr ')' statement elseif_list else_single
1819 Statement s = statement();
1820 iState.thenStatement = s;
1821 checkUnreachable(iState, s);
1822 if (token == TokenNameelseif) {
1823 elseif_list(iState);
1825 else_single(iState);
1828 private void elseif_list(IfStatement iState) {
1830 //| elseif_list T_ELSEIF '(' expr ')' statement
1831 ArrayList conditionList = new ArrayList();
1832 ArrayList statementList = new ArrayList();
1835 while (token == TokenNameelseif) {
1837 if (token == TokenNameLPAREN) {
1840 throwSyntaxError("'(' expected after 'elseif' keyword.");
1843 conditionList.add(e);
1844 if (token == TokenNameRPAREN) {
1847 throwSyntaxError("')' expected after 'elseif' condition.");
1850 statementList.add(s);
1851 checkUnreachable(iState, s);
1853 iState.elseifConditions = new Expression[conditionList.size()];
1854 iState.elseifStatements = new Statement[statementList.size()];
1855 conditionList.toArray(iState.elseifConditions);
1856 statementList.toArray(iState.elseifStatements);
1859 private void new_elseif_list(IfStatement iState) {
1861 //| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1862 ArrayList conditionList = new ArrayList();
1863 ArrayList statementList = new ArrayList();
1866 while (token == TokenNameelseif) {
1868 if (token == TokenNameLPAREN) {
1871 throwSyntaxError("'(' expected after 'elseif' keyword.");
1874 conditionList.add(e);
1875 if (token == TokenNameRPAREN) {
1878 throwSyntaxError("')' expected after 'elseif' condition.");
1880 if (token == TokenNameCOLON) {
1883 throwSyntaxError("':' expected after 'elseif' keyword.");
1885 b = inner_statement_list();
1886 statementList.add(b);
1887 checkUnreachable(iState, b);
1889 iState.elseifConditions = new Expression[conditionList.size()];
1890 iState.elseifStatements = new Statement[statementList.size()];
1891 conditionList.toArray(iState.elseifConditions);
1892 statementList.toArray(iState.elseifStatements);
1895 private void else_single(IfStatement iState) {
1898 if (token == TokenNameelse) {
1900 Statement s = statement();
1901 iState.elseStatement = s;
1902 checkUnreachable(iState, s);
1904 iState.checkUnreachable = false;
1906 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1909 private void new_else_single(IfStatement iState) {
1911 //| T_ELSE ':' inner_statement_list
1912 if (token == TokenNameelse) {
1914 if (token == TokenNameCOLON) {
1917 throwSyntaxError("':' expected after 'else' keyword.");
1919 Block b = inner_statement_list();
1920 iState.elseStatement = b;
1921 checkUnreachable(iState, b);
1923 iState.checkUnreachable = false;
1927 private Block inner_statement_list() {
1928 // inner_statement_list inner_statement
1930 return statementList();
1937 private void checkUnreachable(IfStatement iState, Statement s) {
1938 if (s instanceof Block) {
1939 Block b = (Block) s;
1940 if (b.statements == null || b.statements.length == 0) {
1941 iState.checkUnreachable = false;
1943 int off = b.statements.length - 1;
1944 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
1945 && !(b.statements[off] instanceof BreakStatement)) {
1946 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement)b.statements[off]).checkUnreachable) {
1947 iState.checkUnreachable = false;
1952 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
1953 if (!(s instanceof IfStatement) || !((IfStatement)s).checkUnreachable) {
1954 iState.checkUnreachable = false;
1960 // private void elseifStatementList() {
1962 // elseifStatement();
1964 // case TokenNameelse:
1966 // if (token == TokenNameCOLON) {
1968 // if (token != TokenNameendif) {
1973 // if (token == TokenNameif) { //'else if'
1976 // throwSyntaxError("':' expected after 'else'.");
1980 // case TokenNameelseif:
1989 // private void elseifStatement() {
1990 // if (token == TokenNameLPAREN) {
1993 // if (token != TokenNameRPAREN) {
1994 // throwSyntaxError("')' expected in else-if-statement.");
1997 // if (token != TokenNameCOLON) {
1998 // throwSyntaxError("':' expected in else-if-statement.");
2001 // if (token != TokenNameendif) {
2007 private void switchStatement() {
2008 if (token == TokenNameCOLON) {
2009 // ':' [labeled-statement-list] 'endswitch' ';'
2011 labeledStatementList();
2012 if (token != TokenNameendswitch) {
2013 throwSyntaxError("'endswitch' expected.");
2016 if (token != TokenNameSEMICOLON) {
2017 throwSyntaxError("';' expected after switch-statement.");
2021 // '{' [labeled-statement-list] '}'
2022 if (token != TokenNameLBRACE) {
2023 throwSyntaxError("'{' expected in switch statement.");
2026 if (token != TokenNameRBRACE) {
2027 labeledStatementList();
2029 if (token != TokenNameRBRACE) {
2030 throwSyntaxError("'}' expected in switch statement.");
2036 private void forStatement() {
2037 if (token == TokenNameCOLON) {
2040 if (token != TokenNameendfor) {
2041 throwSyntaxError("'endfor' expected.");
2044 if (token != TokenNameSEMICOLON) {
2045 throwSyntaxError("';' expected after for-statement.");
2053 private void whileStatement() {
2054 // ':' statement-list 'endwhile' ';'
2055 if (token == TokenNameCOLON) {
2058 if (token != TokenNameendwhile) {
2059 throwSyntaxError("'endwhile' expected.");
2062 if (token != TokenNameSEMICOLON) {
2063 throwSyntaxError("';' expected after while-statement.");
2071 private void foreachStatement() {
2072 if (token == TokenNameCOLON) {
2075 if (token != TokenNameendforeach) {
2076 throwSyntaxError("'endforeach' expected.");
2079 if (token != TokenNameSEMICOLON) {
2080 throwSyntaxError("';' expected after foreach-statement.");
2088 // private void exitStatus() {
2089 // if (token == TokenNameLPAREN) {
2092 // throwSyntaxError("'(' expected in 'exit-status'.");
2094 // if (token != TokenNameRPAREN) {
2097 // if (token == TokenNameRPAREN) {
2100 // throwSyntaxError("')' expected after 'exit-status'.");
2103 private void expressionList() {
2106 if (token == TokenNameCOMMA) {
2114 private Expression expr() {
2116 // | expr_without_variable
2117 // if (token!=TokenNameEOF) {
2118 if (Scanner.TRACE) {
2119 System.out.println("TRACE: expr()");
2121 return expr_without_variable(true);
2125 private Expression expr_without_variable(boolean only_variable) {
2126 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2127 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2128 Expression expression = new Expression();
2129 expression.sourceStart = exprSourceStart;
2130 // default, may be overwritten
2131 expression.sourceEnd = exprSourceEnd;
2133 // internal_functions_in_yacc
2142 // | T_INC rw_variable
2143 // | T_DEC rw_variable
2144 // | T_INT_CAST expr
2145 // | T_DOUBLE_CAST expr
2146 // | T_STRING_CAST expr
2147 // | T_ARRAY_CAST expr
2148 // | T_OBJECT_CAST expr
2149 // | T_BOOL_CAST expr
2150 // | T_UNSET_CAST expr
2151 // | T_EXIT exit_expr
2153 // | T_ARRAY '(' array_pair_list ')'
2154 // | '`' encaps_list '`'
2155 // | T_LIST '(' assignment_list ')' '=' expr
2156 // | T_NEW class_name_reference ctor_arguments
2157 // | variable '=' expr
2158 // | variable '=' '&' variable
2159 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2160 // | variable T_PLUS_EQUAL expr
2161 // | variable T_MINUS_EQUAL expr
2162 // | variable T_MUL_EQUAL expr
2163 // | variable T_DIV_EQUAL expr
2164 // | variable T_CONCAT_EQUAL expr
2165 // | variable T_MOD_EQUAL expr
2166 // | variable T_AND_EQUAL expr
2167 // | variable T_OR_EQUAL expr
2168 // | variable T_XOR_EQUAL expr
2169 // | variable T_SL_EQUAL expr
2170 // | variable T_SR_EQUAL expr
2171 // | rw_variable T_INC
2172 // | rw_variable T_DEC
2173 // | expr T_BOOLEAN_OR expr
2174 // | expr T_BOOLEAN_AND expr
2175 // | expr T_LOGICAL_OR expr
2176 // | expr T_LOGICAL_AND expr
2177 // | expr T_LOGICAL_XOR expr
2189 // | expr T_IS_IDENTICAL expr
2190 // | expr T_IS_NOT_IDENTICAL expr
2191 // | expr T_IS_EQUAL expr
2192 // | expr T_IS_NOT_EQUAL expr
2194 // | expr T_IS_SMALLER_OR_EQUAL expr
2196 // | expr T_IS_GREATER_OR_EQUAL expr
2197 // | expr T_INSTANCEOF class_name_reference
2198 // | expr '?' expr ':' expr
2199 if (Scanner.TRACE) {
2200 System.out.println("TRACE: expr_without_variable() PART 1");
2203 case TokenNameisset:
2204 case TokenNameempty:
2206 case TokenNameinclude:
2207 case TokenNameinclude_once:
2208 case TokenNamerequire:
2209 case TokenNamerequire_once:
2210 internal_functions_in_yacc();
2213 case TokenNameLPAREN:
2216 if (token == TokenNameRPAREN) {
2219 throwSyntaxError("')' expected in expression.");
2229 // | T_INT_CAST expr
2230 // | T_DOUBLE_CAST expr
2231 // | T_STRING_CAST expr
2232 // | T_ARRAY_CAST expr
2233 // | T_OBJECT_CAST expr
2234 // | T_BOOL_CAST expr
2235 // | T_UNSET_CAST expr
2236 case TokenNameclone:
2237 case TokenNameprint:
2240 case TokenNameMINUS:
2242 case TokenNameTWIDDLE:
2243 case TokenNameintCAST:
2244 case TokenNamedoubleCAST:
2245 case TokenNamestringCAST:
2246 case TokenNamearrayCAST:
2247 case TokenNameobjectCAST:
2248 case TokenNameboolCAST:
2249 case TokenNameunsetCAST:
2259 //| T_STRING_VARNAME
2261 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2262 // | '`' encaps_list '`'
2264 // | '`' encaps_list '`'
2265 case TokenNameEncapsedString0:
2266 scanner.encapsedStringStack.push(new Character('`'));
2269 if (token == TokenNameEncapsedString0) {
2272 if (token != TokenNameEncapsedString0) {
2273 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2277 scanner.encapsedStringStack.pop();
2281 // | '\'' encaps_list '\''
2282 case TokenNameEncapsedString1:
2283 scanner.encapsedStringStack.push(new Character('\''));
2286 exprSourceStart = scanner.getCurrentTokenStartPosition();
2287 if (token == TokenNameEncapsedString1) {
2288 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2289 .getCurrentTokenEndPosition());
2292 if (token != TokenNameEncapsedString1) {
2293 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2295 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2296 .getCurrentTokenEndPosition());
2300 scanner.encapsedStringStack.pop();
2304 //| '"' encaps_list '"'
2305 case TokenNameEncapsedString2:
2306 scanner.encapsedStringStack.push(new Character('"'));
2309 exprSourceStart = scanner.getCurrentTokenStartPosition();
2310 if (token == TokenNameEncapsedString2) {
2311 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2312 .getCurrentTokenEndPosition());
2315 if (token != TokenNameEncapsedString2) {
2316 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2318 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2319 .getCurrentTokenEndPosition());
2323 scanner.encapsedStringStack.pop();
2327 case TokenNameStringDoubleQuote:
2328 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2329 .getCurrentTokenEndPosition());
2332 case TokenNameStringSingleQuote:
2333 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2334 .getCurrentTokenEndPosition());
2337 case TokenNameIntegerLiteral:
2338 case TokenNameDoubleLiteral:
2339 case TokenNameStringInterpolated:
2342 case TokenNameCLASS_C:
2343 case TokenNameMETHOD_C:
2344 case TokenNameFUNC_C:
2347 case TokenNameHEREDOC:
2350 case TokenNamearray:
2351 // T_ARRAY '(' array_pair_list ')'
2353 if (token == TokenNameLPAREN) {
2355 if (token == TokenNameRPAREN) {
2360 if (token != TokenNameRPAREN) {
2361 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2365 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2369 // | T_LIST '(' assignment_list ')' '=' expr
2371 if (token == TokenNameLPAREN) {
2374 if (token != TokenNameRPAREN) {
2375 throwSyntaxError("')' expected after 'list' keyword.");
2378 if (token != TokenNameEQUAL) {
2379 throwSyntaxError("'=' expected after 'list' keyword.");
2384 throwSyntaxError("'(' expected after 'list' keyword.");
2388 // | T_NEW class_name_reference ctor_arguments
2390 Expression typeRef = class_name_reference();
2392 if (typeRef != null) {
2393 expression = typeRef;
2396 // | T_INC rw_variable
2397 // | T_DEC rw_variable
2398 case TokenNamePLUS_PLUS:
2399 case TokenNameMINUS_MINUS:
2403 // | variable '=' expr
2404 // | variable '=' '&' variable
2405 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2406 // | variable T_PLUS_EQUAL expr
2407 // | variable T_MINUS_EQUAL expr
2408 // | variable T_MUL_EQUAL expr
2409 // | variable T_DIV_EQUAL expr
2410 // | variable T_CONCAT_EQUAL expr
2411 // | variable T_MOD_EQUAL expr
2412 // | variable T_AND_EQUAL expr
2413 // | variable T_OR_EQUAL expr
2414 // | variable T_XOR_EQUAL expr
2415 // | variable T_SL_EQUAL expr
2416 // | variable T_SR_EQUAL expr
2417 // | rw_variable T_INC
2418 // | rw_variable T_DEC
2419 case TokenNameIdentifier:
2420 case TokenNameVariable:
2421 case TokenNameDOLLAR:
2422 boolean rememberedVar = false;
2423 Expression lhs = variable();
2425 case TokenNameEQUAL:
2427 if (token == TokenNameAND) {
2429 if (token == TokenNamenew) {
2430 // | variable '=' '&' T_NEW class_name_reference
2433 SingleTypeReference classRef = class_name_reference();
2435 if (classRef != null) {
2436 if (lhs != null && lhs instanceof FieldReference) {
2438 // $var = & new Object();
2439 if (fMethodVariables != null) {
2440 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2441 lhsInfo.reference = classRef;
2442 lhsInfo.typeIdentifier = classRef.token;
2443 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2444 rememberedVar = true;
2449 Expression rhs = variable();
2450 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2453 if (fMethodVariables != null) {
2454 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2455 if (rhsInfo != null && rhsInfo.reference != null) {
2456 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2457 lhsInfo.reference = rhsInfo.reference;
2458 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2459 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2460 rememberedVar = true;
2466 Expression rhs = expr();
2467 if (lhs != null && lhs instanceof FieldReference) {
2468 if (rhs != null && rhs instanceof FieldReference) {
2471 if (fMethodVariables != null) {
2472 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2473 if (rhsInfo != null && rhsInfo.reference != null) {
2474 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2475 lhsInfo.reference = rhsInfo.reference;
2476 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2477 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2478 rememberedVar = true;
2481 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2483 // $var = new Object();
2484 if (fMethodVariables != null) {
2485 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2486 lhsInfo.reference = (SingleTypeReference) rhs;
2487 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2488 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2489 rememberedVar = true;
2494 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2495 if (fMethodVariables != null) {
2496 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2497 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2501 case TokenNamePLUS_EQUAL:
2502 case TokenNameMINUS_EQUAL:
2503 case TokenNameMULTIPLY_EQUAL:
2504 case TokenNameDIVIDE_EQUAL:
2505 case TokenNameDOT_EQUAL:
2506 case TokenNameREMAINDER_EQUAL:
2507 case TokenNameAND_EQUAL:
2508 case TokenNameOR_EQUAL:
2509 case TokenNameXOR_EQUAL:
2510 case TokenNameRIGHT_SHIFT_EQUAL:
2511 case TokenNameLEFT_SHIFT_EQUAL:
2515 case TokenNamePLUS_PLUS:
2516 case TokenNameMINUS_MINUS:
2520 if (!only_variable) {
2521 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2529 if (token != TokenNameINLINE_HTML) {
2530 if (token > TokenNameKEYWORD) {
2534 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2539 if (Scanner.TRACE) {
2540 System.out.println("TRACE: expr_without_variable() PART 2");
2542 // | expr T_BOOLEAN_OR expr
2543 // | expr T_BOOLEAN_AND expr
2544 // | expr T_LOGICAL_OR expr
2545 // | expr T_LOGICAL_AND expr
2546 // | expr T_LOGICAL_XOR expr
2558 // | expr T_IS_IDENTICAL expr
2559 // | expr T_IS_NOT_IDENTICAL expr
2560 // | expr T_IS_EQUAL expr
2561 // | expr T_IS_NOT_EQUAL expr
2563 // | expr T_IS_SMALLER_OR_EQUAL expr
2565 // | expr T_IS_GREATER_OR_EQUAL expr
2568 case TokenNameOR_OR:
2570 expression = new OR_OR_Expression(expression, expr(), token);
2572 case TokenNameAND_AND:
2574 expression = new AND_AND_Expression(expression, expr(), token);
2576 case TokenNameEQUAL_EQUAL:
2578 expression = new EqualExpression(expression, expr(), token);
2588 case TokenNameMINUS:
2589 case TokenNameMULTIPLY:
2590 case TokenNameDIVIDE:
2591 case TokenNameREMAINDER:
2592 case TokenNameLEFT_SHIFT:
2593 case TokenNameRIGHT_SHIFT:
2594 case TokenNameEQUAL_EQUAL_EQUAL:
2595 case TokenNameNOT_EQUAL_EQUAL:
2596 case TokenNameNOT_EQUAL:
2598 case TokenNameLESS_EQUAL:
2599 case TokenNameGREATER:
2600 case TokenNameGREATER_EQUAL:
2602 expression = new BinaryExpression(expression, expr(), token);
2604 // | expr T_INSTANCEOF class_name_reference
2605 // | expr '?' expr ':' expr
2606 case TokenNameinstanceof:
2608 TypeReference classRef = class_name_reference();
2609 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2610 expression.sourceStart = exprSourceStart;
2611 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2613 case TokenNameQUESTION:
2615 Expression valueIfTrue = expr();
2616 if (token != TokenNameCOLON) {
2617 throwSyntaxError("':' expected in conditional expression.");
2620 Expression valueIfFalse = expr();
2622 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2628 } catch (SyntaxError e) {
2629 // try to find next token after expression with errors:
2630 if (token == TokenNameSEMICOLON) {
2634 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2642 private SingleTypeReference class_name_reference() {
2643 // class_name_reference:
2645 //| dynamic_class_name_reference
2646 SingleTypeReference ref = null;
2647 if (Scanner.TRACE) {
2648 System.out.println("TRACE: class_name_reference()");
2650 if (token == TokenNameIdentifier) {
2651 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2655 dynamic_class_name_reference();
2660 private void dynamic_class_name_reference() {
2661 //dynamic_class_name_reference:
2662 // base_variable T_OBJECT_OPERATOR object_property
2663 // dynamic_class_name_variable_properties
2665 if (Scanner.TRACE) {
2666 System.out.println("TRACE: dynamic_class_name_reference()");
2669 if (token == TokenNameMINUS_GREATER) {
2672 dynamic_class_name_variable_properties();
2676 private void dynamic_class_name_variable_properties() {
2677 // dynamic_class_name_variable_properties:
2678 // dynamic_class_name_variable_properties
2679 // dynamic_class_name_variable_property
2681 if (Scanner.TRACE) {
2682 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2684 while (token == TokenNameMINUS_GREATER) {
2685 dynamic_class_name_variable_property();
2689 private void dynamic_class_name_variable_property() {
2690 // dynamic_class_name_variable_property:
2691 // T_OBJECT_OPERATOR object_property
2692 if (Scanner.TRACE) {
2693 System.out.println("TRACE: dynamic_class_name_variable_property()");
2695 if (token == TokenNameMINUS_GREATER) {
2701 private void ctor_arguments() {
2704 //| '(' function_call_parameter_list ')'
2705 if (token == TokenNameLPAREN) {
2707 if (token == TokenNameRPAREN) {
2711 non_empty_function_call_parameter_list();
2712 if (token != TokenNameRPAREN) {
2713 throwSyntaxError("')' expected in ctor_arguments.");
2719 private void assignment_list() {
2721 // assignment_list ',' assignment_list_element
2722 //| assignment_list_element
2724 assignment_list_element();
2725 if (token != TokenNameCOMMA) {
2732 private void assignment_list_element() {
2733 //assignment_list_element:
2735 //| T_LIST '(' assignment_list ')'
2737 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2740 if (token == TokenNamelist) {
2742 if (token == TokenNameLPAREN) {
2745 if (token != TokenNameRPAREN) {
2746 throwSyntaxError("')' expected after 'list' keyword.");
2750 throwSyntaxError("'(' expected after 'list' keyword.");
2756 private void array_pair_list() {
2759 //| non_empty_array_pair_list possible_comma
2760 non_empty_array_pair_list();
2761 if (token == TokenNameCOMMA) {
2766 private void non_empty_array_pair_list() {
2767 //non_empty_array_pair_list:
2768 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2769 //| non_empty_array_pair_list ',' expr
2770 //| expr T_DOUBLE_ARROW expr
2772 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2773 //| non_empty_array_pair_list ',' '&' w_variable
2774 //| expr T_DOUBLE_ARROW '&' w_variable
2777 if (token == TokenNameAND) {
2782 if (token == TokenNameAND) {
2785 } else if (token == TokenNameEQUAL_GREATER) {
2787 if (token == TokenNameAND) {
2795 if (token != TokenNameCOMMA) {
2799 if (token == TokenNameRPAREN) {
2805 // private void variableList() {
2808 // if (token == TokenNameCOMMA) {
2815 private Expression variable_without_objects() {
2816 // variable_without_objects:
2817 // reference_variable
2818 // | simple_indirect_reference reference_variable
2819 if (Scanner.TRACE) {
2820 System.out.println("TRACE: variable_without_objects()");
2822 while (token == TokenNameDOLLAR) {
2825 return reference_variable();
2828 private Expression function_call() {
2830 // T_STRING '(' function_call_parameter_list ')'
2831 //| class_constant '(' function_call_parameter_list ')'
2832 //| static_member '(' function_call_parameter_list ')'
2833 //| variable_without_objects '(' function_call_parameter_list ')'
2834 char[] defineName = null;
2835 char[] ident = null;
2838 Expression ref = null;
2839 if (Scanner.TRACE) {
2840 System.out.println("TRACE: function_call()");
2842 if (token == TokenNameIdentifier) {
2843 ident = scanner.getCurrentIdentifierSource();
2845 startPos = scanner.getCurrentTokenStartPosition();
2846 endPos = scanner.getCurrentTokenEndPosition();
2849 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2853 if (token == TokenNameIdentifier) {
2858 variable_without_objects();
2863 ref = variable_without_objects();
2865 if (token != TokenNameLPAREN) {
2866 if (defineName != null) {
2867 // does this identifier contain only uppercase characters?
2868 if (defineName.length == 3) {
2869 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2872 } else if (defineName.length == 4) {
2873 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2875 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2878 } else if (defineName.length == 5) {
2879 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2883 if (defineName != null) {
2884 for (int i = 0; i < defineName.length; i++) {
2885 if (Character.isLowerCase(defineName[i])) {
2886 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2892 // TODO is this ok ?
2894 // throwSyntaxError("'(' expected in function call.");
2897 if (token == TokenNameRPAREN) {
2901 non_empty_function_call_parameter_list();
2902 if (token != TokenNameRPAREN) {
2903 String functionName;
2904 if (ident == null) {
2905 functionName = new String(" ");
2907 functionName = new String(ident);
2909 throwSyntaxError("')' expected in function call (" + functionName + ").");
2915 // private void function_call_parameter_list() {
2916 // function_call_parameter_list:
2917 // non_empty_function_call_parameter_list { $$ = $1; }
2920 private void non_empty_function_call_parameter_list() {
2921 //non_empty_function_call_parameter_list:
2922 // expr_without_variable
2925 // | non_empty_function_call_parameter_list ',' expr_without_variable
2926 // | non_empty_function_call_parameter_list ',' variable
2927 // | non_empty_function_call_parameter_list ',' '&' w_variable
2928 if (Scanner.TRACE) {
2929 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2932 if (token == TokenNameAND) {
2936 // if (token == TokenNameIdentifier || token ==
2937 // TokenNameVariable
2938 // || token == TokenNameDOLLAR) {
2941 expr_without_variable(true);
2944 if (token != TokenNameCOMMA) {
2951 private void fully_qualified_class_name() {
2952 if (token == TokenNameIdentifier) {
2955 throwSyntaxError("Class name expected.");
2959 private void static_member() {
2961 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2962 // variable_without_objects
2963 if (Scanner.TRACE) {
2964 System.out.println("TRACE: static_member()");
2966 fully_qualified_class_name();
2967 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2968 throwSyntaxError("'::' expected after class name (static_member).");
2971 variable_without_objects();
2974 private Expression base_variable_with_function_calls() {
2975 // base_variable_with_function_calls:
2978 boolean functionCall = false;
2979 if (Scanner.TRACE) {
2980 System.out.println("TRACE: base_variable_with_function_calls()");
2982 // if (token == TokenNameIdentifier) {
2983 // functionCall = true;
2984 // } else if (token == TokenNameVariable) {
2985 // int tempToken = token;
2986 // int tempPosition = scanner.currentPosition;
2988 // if (token == TokenNameLPAREN) {
2989 // functionCall = true;
2991 // token = tempToken;
2992 // scanner.currentPosition = tempPosition;
2993 // scanner.phpMode = true;
2995 // if (functionCall) {
2996 return function_call();
3002 private Expression base_variable() {
3004 // reference_variable
3005 // | simple_indirect_reference reference_variable
3007 Expression ref = null;
3008 if (Scanner.TRACE) {
3009 System.out.println("TRACE: base_variable()");
3011 if (token == TokenNameIdentifier) {
3014 while (token == TokenNameDOLLAR) {
3017 reference_variable();
3022 // private void simple_indirect_reference() {
3023 // // simple_indirect_reference:
3025 // //| simple_indirect_reference '$'
3027 private Expression reference_variable() {
3028 // reference_variable:
3029 // reference_variable '[' dim_offset ']'
3030 // | reference_variable '{' expr '}'
3031 // | compound_variable
3032 Expression ref = null;
3033 if (Scanner.TRACE) {
3034 System.out.println("TRACE: reference_variable()");
3036 ref = compound_variable();
3038 if (token == TokenNameLBRACE) {
3042 if (token != TokenNameRBRACE) {
3043 throwSyntaxError("'}' expected in reference variable.");
3046 } else if (token == TokenNameLBRACKET) {
3049 if (token != TokenNameRBRACKET) {
3052 if (token != TokenNameRBRACKET) {
3053 throwSyntaxError("']' expected in reference variable.");
3064 private Expression compound_variable() {
3065 // compound_variable:
3067 // | '$' '{' expr '}'
3068 if (Scanner.TRACE) {
3069 System.out.println("TRACE: compound_variable()");
3071 if (token == TokenNameVariable) {
3072 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3076 // because of simple_indirect_reference
3077 while (token == TokenNameDOLLAR) {
3080 if (token != TokenNameLBRACE) {
3081 reportSyntaxError("'{' expected after compound variable token '$'.");
3086 if (token != TokenNameRBRACE) {
3087 throwSyntaxError("'}' expected after compound variable token '$'.");
3094 // private void dim_offset() {
3100 private void object_property() {
3103 //| variable_without_objects
3104 if (Scanner.TRACE) {
3105 System.out.println("TRACE: object_property()");
3107 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3108 variable_without_objects();
3114 private void object_dim_list() {
3116 // object_dim_list '[' dim_offset ']'
3117 //| object_dim_list '{' expr '}'
3119 if (Scanner.TRACE) {
3120 System.out.println("TRACE: object_dim_list()");
3124 if (token == TokenNameLBRACE) {
3127 if (token != TokenNameRBRACE) {
3128 throwSyntaxError("'}' expected in object_dim_list.");
3131 } else if (token == TokenNameLBRACKET) {
3133 if (token == TokenNameRBRACKET) {
3138 if (token != TokenNameRBRACKET) {
3139 throwSyntaxError("']' expected in object_dim_list.");
3148 private void variable_name() {
3152 if (Scanner.TRACE) {
3153 System.out.println("TRACE: variable_name()");
3155 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3156 if (token > TokenNameKEYWORD) {
3157 // TODO show a warning "Keyword used as variable" ?
3161 if (token != TokenNameLBRACE) {
3162 throwSyntaxError("'{' expected in variable name.");
3166 if (token != TokenNameRBRACE) {
3167 throwSyntaxError("'}' expected in variable name.");
3173 private void r_variable() {
3177 private void w_variable() {
3181 private void rw_variable() {
3185 private Expression variable() {
3187 // base_variable_with_function_calls T_OBJECT_OPERATOR
3188 // object_property method_or_not variable_properties
3189 // | base_variable_with_function_calls
3190 Expression ref = base_variable_with_function_calls();
3191 if (token == TokenNameMINUS_GREATER) {
3196 variable_properties();
3201 private void variable_properties() {
3202 // variable_properties:
3203 // variable_properties variable_property
3205 while (token == TokenNameMINUS_GREATER) {
3206 variable_property();
3210 private void variable_property() {
3211 // variable_property:
3212 // T_OBJECT_OPERATOR object_property method_or_not
3213 if (Scanner.TRACE) {
3214 System.out.println("TRACE: variable_property()");
3216 if (token == TokenNameMINUS_GREATER) {
3221 throwSyntaxError("'->' expected in variable_property.");
3225 private void method_or_not() {
3227 // '(' function_call_parameter_list ')'
3229 if (Scanner.TRACE) {
3230 System.out.println("TRACE: method_or_not()");
3232 if (token == TokenNameLPAREN) {
3234 if (token == TokenNameRPAREN) {
3238 non_empty_function_call_parameter_list();
3239 if (token != TokenNameRPAREN) {
3240 throwSyntaxError("')' expected in method_or_not.");
3246 private void exit_expr() {
3250 if (token != TokenNameLPAREN) {
3254 if (token == TokenNameRPAREN) {
3259 if (token != TokenNameRPAREN) {
3260 throwSyntaxError("')' expected after keyword 'exit'");
3265 private void encaps_list() {
3266 // encaps_list encaps_var
3267 // | encaps_list T_STRING
3268 // | encaps_list T_NUM_STRING
3269 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3270 // | encaps_list T_CHARACTER
3271 // | encaps_list T_BAD_CHARACTER
3272 // | encaps_list '['
3273 // | encaps_list ']'
3274 // | encaps_list '{'
3275 // | encaps_list '}'
3276 // | encaps_list T_OBJECT_OPERATOR
3280 case TokenNameSTRING:
3283 case TokenNameLBRACE:
3284 // scanner.encapsedStringStack.pop();
3287 case TokenNameRBRACE:
3288 // scanner.encapsedStringStack.pop();
3291 case TokenNameLBRACKET:
3292 // scanner.encapsedStringStack.pop();
3295 case TokenNameRBRACKET:
3296 // scanner.encapsedStringStack.pop();
3299 case TokenNameMINUS_GREATER:
3300 // scanner.encapsedStringStack.pop();
3303 case TokenNameVariable:
3304 case TokenNameDOLLAR_LBRACE:
3305 case TokenNameLBRACE_DOLLAR:
3309 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3310 if (encapsedChar == '$') {
3311 scanner.encapsedStringStack.pop();
3312 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3313 switch (encapsedChar) {
3315 if (token == TokenNameEncapsedString0) {
3318 token = TokenNameSTRING;
3321 if (token == TokenNameEncapsedString1) {
3324 token = TokenNameSTRING;
3327 if (token == TokenNameEncapsedString2) {
3330 token = TokenNameSTRING;
3339 private void encaps_var() {
3341 // | T_VARIABLE '[' encaps_var_offset ']'
3342 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3343 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3344 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3345 // | T_CURLY_OPEN variable '}'
3347 case TokenNameVariable:
3349 if (token == TokenNameLBRACKET) {
3351 expr(); //encaps_var_offset();
3352 if (token != TokenNameRBRACKET) {
3353 throwSyntaxError("']' expected after variable.");
3355 // scanner.encapsedStringStack.pop();
3358 } else if (token == TokenNameMINUS_GREATER) {
3360 if (token != TokenNameIdentifier) {
3361 throwSyntaxError("Identifier expected after '->'.");
3363 // scanner.encapsedStringStack.pop();
3367 // // scanner.encapsedStringStack.pop();
3368 // int tempToken = TokenNameSTRING;
3369 // if (!scanner.encapsedStringStack.isEmpty()
3370 // && (token == TokenNameEncapsedString0
3371 // || token == TokenNameEncapsedString1
3372 // || token == TokenNameEncapsedString2 || token ==
3373 // TokenNameERROR)) {
3374 // char encapsedChar = ((Character)
3375 // scanner.encapsedStringStack.peek())
3378 // case TokenNameEncapsedString0 :
3379 // if (encapsedChar == '`') {
3380 // tempToken = TokenNameEncapsedString0;
3383 // case TokenNameEncapsedString1 :
3384 // if (encapsedChar == '\'') {
3385 // tempToken = TokenNameEncapsedString1;
3388 // case TokenNameEncapsedString2 :
3389 // if (encapsedChar == '"') {
3390 // tempToken = TokenNameEncapsedString2;
3393 // case TokenNameERROR :
3394 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3395 // scanner.currentPosition--;
3401 // token = tempToken;
3404 case TokenNameDOLLAR_LBRACE:
3406 if (token == TokenNameDOLLAR_LBRACE) {
3408 } else if (token == TokenNameIdentifier) {
3410 if (token == TokenNameLBRACKET) {
3412 // if (token == TokenNameRBRACKET) {
3416 if (token != TokenNameRBRACKET) {
3417 throwSyntaxError("']' expected after '${'.");
3425 if (token != TokenNameRBRACE) {
3426 throwSyntaxError("'}' expected.");
3430 case TokenNameLBRACE_DOLLAR:
3432 if (token == TokenNameLBRACE_DOLLAR) {
3434 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3436 if (token == TokenNameLBRACKET) {
3438 // if (token == TokenNameRBRACKET) {
3442 if (token != TokenNameRBRACKET) {
3443 throwSyntaxError("']' expected.");
3447 } else if (token == TokenNameMINUS_GREATER) {
3449 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3450 throwSyntaxError("String or Variable token expected.");
3453 if (token == TokenNameLBRACKET) {
3455 // if (token == TokenNameRBRACKET) {
3459 if (token != TokenNameRBRACKET) {
3460 throwSyntaxError("']' expected after '${'.");
3466 // if (token != TokenNameRBRACE) {
3467 // throwSyntaxError("'}' expected after '{$'.");
3469 // // scanner.encapsedStringStack.pop();
3473 if (token != TokenNameRBRACE) {
3474 throwSyntaxError("'}' expected.");
3476 // scanner.encapsedStringStack.pop();
3483 private void encaps_var_offset() {
3488 case TokenNameSTRING:
3491 case TokenNameIntegerLiteral:
3494 case TokenNameVariable:
3497 case TokenNameIdentifier:
3501 throwSyntaxError("Variable or String token expected.");
3506 private void internal_functions_in_yacc() {
3509 case TokenNameisset:
3510 // T_ISSET '(' isset_variables ')'
3512 if (token != TokenNameLPAREN) {
3513 throwSyntaxError("'(' expected after keyword 'isset'");
3517 if (token != TokenNameRPAREN) {
3518 throwSyntaxError("')' expected after keyword 'isset'");
3522 case TokenNameempty:
3523 // T_EMPTY '(' variable ')'
3525 if (token != TokenNameLPAREN) {
3526 throwSyntaxError("'(' expected after keyword 'empty'");
3530 if (token != TokenNameRPAREN) {
3531 throwSyntaxError("')' expected after keyword 'empty'");
3535 case TokenNameinclude:
3537 checkFileName(token);
3539 case TokenNameinclude_once:
3540 // T_INCLUDE_ONCE expr
3541 checkFileName(token);
3544 // T_EVAL '(' expr ')'
3546 if (token != TokenNameLPAREN) {
3547 throwSyntaxError("'(' expected after keyword 'eval'");
3551 if (token != TokenNameRPAREN) {
3552 throwSyntaxError("')' expected after keyword 'eval'");
3556 case TokenNamerequire:
3558 checkFileName(token);
3560 case TokenNamerequire_once:
3561 // T_REQUIRE_ONCE expr
3562 checkFileName(token);
3567 private void checkFileName(int includeToken) {
3568 //<include-token> expr
3569 int start = scanner.getCurrentTokenStartPosition();
3570 boolean hasLPAREN = false;
3572 if (token == TokenNameLPAREN) {
3576 Expression expression = expr();
3578 if (token == TokenNameRPAREN) {
3581 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3584 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3586 if (scanner.compilationUnit != null) {
3587 IResource resource = scanner.compilationUnit.getResource();
3588 if (resource != null && resource instanceof IFile) {
3589 file = (IFile) resource;
3593 tokens = new char[1][];
3594 tokens[0] = currTokenSource;
3596 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3597 impt.declarationSourceEnd = impt.sourceEnd;
3598 impt.declarationEnd = impt.declarationSourceEnd;
3599 //endPosition is just before the ;
3600 impt.declarationSourceStart = start;
3601 includesList.add(impt);
3603 if (expression instanceof StringLiteral) {
3604 StringLiteral literal = (StringLiteral) expression;
3605 char[] includeName = literal.source();
3606 if (includeName.length == 0) {
3607 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3608 literal.sourceStart + 1);
3610 String includeNameString = new String(includeName);
3611 if (literal instanceof StringLiteralDQ) {
3612 if (includeNameString.indexOf('$') >= 0) {
3613 // assuming that the filename contains a variable => no filename check
3617 if (includeNameString.startsWith("http://")) {
3618 // assuming external include location
3622 // check the filename:
3623 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3624 IProject project = file.getProject();
3625 if (project != null) {
3626 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3629 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3630 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3631 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3632 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3633 compilationUnit.compilationResult);
3636 // String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
3637 // String filePath = file.getRawLocation().toString();
3638 String filePath = path.toString();
3639 String ext = file.getRawLocation().getFileExtension();
3640 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3643 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3644 impt.setFile(PHPFileUtil.createFile(path, project));
3645 } catch (Exception e) {
3646 // the file is outside of the workspace
3654 private void isset_variables() {
3656 // | isset_variables ','
3657 if (token == TokenNameRPAREN) {
3658 throwSyntaxError("Variable expected after keyword 'isset'");
3662 if (token == TokenNameCOMMA) {
3670 private boolean common_scalar() {
3674 // | T_CONSTANT_ENCAPSED_STRING
3681 case TokenNameIntegerLiteral:
3684 case TokenNameDoubleLiteral:
3687 case TokenNameStringDoubleQuote:
3690 case TokenNameStringSingleQuote:
3693 case TokenNameStringInterpolated:
3702 case TokenNameCLASS_C:
3705 case TokenNameMETHOD_C:
3708 case TokenNameFUNC_C:
3715 private void scalar() {
3718 //| T_STRING_VARNAME
3721 //| '"' encaps_list '"'
3722 //| '\'' encaps_list '\''
3723 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3724 throwSyntaxError("Not yet implemented (scalar).");
3727 private void static_scalar() {
3728 // static_scalar: /* compile-time evaluated scalars */
3731 // | '+' static_scalar
3732 // | '-' static_scalar
3733 // | T_ARRAY '(' static_array_pair_list ')'
3734 // | static_class_constant
3735 if (common_scalar()) {
3739 case TokenNameIdentifier:
3741 // static_class_constant:
3742 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3743 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3745 if (token == TokenNameIdentifier) {
3748 throwSyntaxError("Identifier expected after '::' operator.");
3752 case TokenNameEncapsedString0:
3754 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3755 while (scanner.currentCharacter != '`') {
3756 if (scanner.currentCharacter == '\\') {
3757 scanner.currentPosition++;
3759 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3762 } catch (IndexOutOfBoundsException e) {
3763 throwSyntaxError("'`' expected at end of static string.");
3766 case TokenNameEncapsedString1:
3768 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3769 while (scanner.currentCharacter != '\'') {
3770 if (scanner.currentCharacter == '\\') {
3771 scanner.currentPosition++;
3773 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3776 } catch (IndexOutOfBoundsException e) {
3777 throwSyntaxError("'\'' expected at end of static string.");
3780 case TokenNameEncapsedString2:
3782 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3783 while (scanner.currentCharacter != '"') {
3784 if (scanner.currentCharacter == '\\') {
3785 scanner.currentPosition++;
3787 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3790 } catch (IndexOutOfBoundsException e) {
3791 throwSyntaxError("'\"' expected at end of static string.");
3798 case TokenNameMINUS:
3802 case TokenNamearray:
3804 if (token != TokenNameLPAREN) {
3805 throwSyntaxError("'(' expected after keyword 'array'");
3808 if (token == TokenNameRPAREN) {
3812 non_empty_static_array_pair_list();
3813 if (token != TokenNameRPAREN) {
3814 throwSyntaxError("')' or ',' expected after keyword 'array'");
3818 // case TokenNamenull :
3821 // case TokenNamefalse :
3824 // case TokenNametrue :
3828 throwSyntaxError("Static scalar/constant expected.");
3832 private void non_empty_static_array_pair_list() {
3833 // non_empty_static_array_pair_list:
3834 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3836 //| non_empty_static_array_pair_list ',' static_scalar
3837 //| static_scalar T_DOUBLE_ARROW static_scalar
3841 if (token == TokenNameEQUAL_GREATER) {
3845 if (token != TokenNameCOMMA) {
3849 if (token == TokenNameRPAREN) {
3855 public void reportSyntaxError() { //int act, int currentKind, int
3857 /* remember current scanner position */
3858 int startPos = scanner.startPosition;
3859 int currentPos = scanner.currentPosition;
3860 // String[] expectings;
3861 // String tokenName = name[symbol_index[currentKind]];
3862 //fetch all "accurate" possible terminals that could recover the error
3863 // int start, end = start = asi(stack[stateStackTop]);
3864 // while (asr[end] != 0)
3866 // int length = end - start;
3867 // expectings = new String[length];
3868 // if (length != 0) {
3869 // char[] indexes = new char[length];
3870 // System.arraycopy(asr, start, indexes, 0, length);
3871 // for (int i = 0; i < length; i++) {
3872 // expectings[i] = name[symbol_index[indexes[i]]];
3875 //if the pb is an EOF, try to tell the user that they are some
3876 // if (tokenName.equals(UNEXPECTED_EOF)) {
3877 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3878 // char[] tokenSource;
3880 // tokenSource = this.scanner.getCurrentTokenSource();
3881 // } catch (Exception e) {
3882 // tokenSource = new char[] {};
3884 // problemReporter().parseError(
3885 // this.scanner.startPosition,
3886 // this.scanner.currentPosition - 1,
3891 // } else { //the next test is HEAVILY grammar DEPENDENT.
3892 // if ((length == 14)
3893 // && (expectings[0] == "=") //$NON-NLS-1$
3894 // && (expectings[1] == "*=") //$NON-NLS-1$
3895 // && (expressionPtr > -1)) {
3896 // switch(currentKind) {
3897 // case TokenNameSEMICOLON:
3898 // case TokenNamePLUS:
3899 // case TokenNameMINUS:
3900 // case TokenNameDIVIDE:
3901 // case TokenNameREMAINDER:
3902 // case TokenNameMULTIPLY:
3903 // case TokenNameLEFT_SHIFT:
3904 // case TokenNameRIGHT_SHIFT:
3905 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3906 // case TokenNameLESS:
3907 // case TokenNameGREATER:
3908 // case TokenNameLESS_EQUAL:
3909 // case TokenNameGREATER_EQUAL:
3910 // case TokenNameEQUAL_EQUAL:
3911 // case TokenNameNOT_EQUAL:
3912 // case TokenNameXOR:
3913 // case TokenNameAND:
3914 // case TokenNameOR:
3915 // case TokenNameOR_OR:
3916 // case TokenNameAND_AND:
3917 // // the ; is not the expected token ==> it ends a statement when an
3918 // expression is not ended
3919 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3921 // case TokenNameRBRACE :
3922 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3925 // char[] tokenSource;
3927 // tokenSource = this.scanner.getCurrentTokenSource();
3928 // } catch (Exception e) {
3929 // tokenSource = new char[] {};
3931 // problemReporter().parseError(
3932 // this.scanner.startPosition,
3933 // this.scanner.currentPosition - 1,
3937 // this.checkAndReportBracketAnomalies(problemReporter());
3942 tokenSource = this.scanner.getCurrentTokenSource();
3943 } catch (Exception e) {
3944 tokenSource = new char[] {};
3946 // problemReporter().parseError(
3947 // this.scanner.startPosition,
3948 // this.scanner.currentPosition - 1,
3952 this.checkAndReportBracketAnomalies(problemReporter());
3955 /* reset scanner where it was */
3956 scanner.startPosition = startPos;
3957 scanner.currentPosition = currentPos;
3960 public static final int RoundBracket = 0;
3962 public static final int SquareBracket = 1;
3964 public static final int CurlyBracket = 2;
3966 public static final int BracketKinds = 3;
3968 protected int[] nestedMethod; //the ptr is nestedType
3970 protected int nestedType, dimensions;
3972 //variable set stack
3973 final static int VariableStackIncrement = 10;
3975 HashMap fTypeVariables = null;
3977 HashMap fMethodVariables = null;
3980 final static int AstStackIncrement = 100;
3982 protected int astPtr;
3984 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
3986 protected int astLengthPtr;
3988 protected int[] astLengthStack;
3990 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
3992 public CompilationUnitDeclaration compilationUnit; /*
3993 * the result from parse()
3996 protected ReferenceContext referenceContext;
3998 protected ProblemReporter problemReporter;
4000 protected CompilerOptions options;
4002 private ArrayList includesList;
4004 // protected CompilationResult compilationResult;
4006 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
4007 * reported, so initializes the compilation result's line positions.
4009 public ProblemReporter problemReporter() {
4010 if (scanner.recordLineSeparator) {
4011 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4013 problemReporter.referenceContext = referenceContext;
4014 return problemReporter;
4018 * Reconsider the entire source looking for inconsistencies in {} () []
4020 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
4021 scanner.wasAcr = false;
4022 boolean anomaliesDetected = false;
4024 char[] source = scanner.source;
4025 int[] leftCount = { 0, 0, 0 };
4026 int[] rightCount = { 0, 0, 0 };
4027 int[] depths = { 0, 0, 0 };
4028 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
4029 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4030 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
4031 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
4032 scanner.currentPosition = scanner.initialPosition; //starting
4034 // (first-zero-based
4036 while (scanner.currentPosition < scanner.eofPosition) { //loop for
4041 // ---------Consume white space and handles
4042 // startPosition---------
4043 boolean isWhiteSpace;
4045 scanner.startPosition = scanner.currentPosition;
4046 // if (((scanner.currentCharacter =
4047 // source[scanner.currentPosition++]) == '\\') &&
4048 // (source[scanner.currentPosition] == 'u')) {
4049 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4051 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4052 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4053 // only record line positions we have not
4055 scanner.pushLineSeparator();
4058 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4060 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4061 // -------consume token until } is found---------
4062 switch (scanner.currentCharacter) {
4064 int index = leftCount[CurlyBracket]++;
4065 if (index == leftPositions[CurlyBracket].length) {
4066 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4067 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
4069 leftPositions[CurlyBracket][index] = scanner.startPosition;
4070 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4074 int index = rightCount[CurlyBracket]++;
4075 if (index == rightPositions[CurlyBracket].length) {
4076 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4077 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
4079 rightPositions[CurlyBracket][index] = scanner.startPosition;
4080 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4084 int index = leftCount[RoundBracket]++;
4085 if (index == leftPositions[RoundBracket].length) {
4086 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4087 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
4089 leftPositions[RoundBracket][index] = scanner.startPosition;
4090 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4094 int index = rightCount[RoundBracket]++;
4095 if (index == rightPositions[RoundBracket].length) {
4096 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4097 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
4099 rightPositions[RoundBracket][index] = scanner.startPosition;
4100 rightDepths[RoundBracket][index] = --depths[RoundBracket];
4104 int index = leftCount[SquareBracket]++;
4105 if (index == leftPositions[SquareBracket].length) {
4106 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4107 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
4109 leftPositions[SquareBracket][index] = scanner.startPosition;
4110 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4114 int index = rightCount[SquareBracket]++;
4115 if (index == rightPositions[SquareBracket].length) {
4116 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4117 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
4119 rightPositions[SquareBracket][index] = scanner.startPosition;
4120 rightDepths[SquareBracket][index] = --depths[SquareBracket];
4124 if (scanner.getNextChar('\\')) {
4125 scanner.scanEscapeCharacter();
4126 } else { // consume next character
4127 scanner.unicodeAsBackSlash = false;
4128 // if (((scanner.currentCharacter =
4129 // source[scanner.currentPosition++]) ==
4131 // (source[scanner.currentPosition] ==
4133 // scanner.getNextUnicodeChar();
4135 if (scanner.withoutUnicodePtr != 0) {
4136 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4140 scanner.getNextChar('\'');
4144 // consume next character
4145 scanner.unicodeAsBackSlash = false;
4146 // if (((scanner.currentCharacter =
4147 // source[scanner.currentPosition++]) == '\\') &&
4148 // (source[scanner.currentPosition] == 'u')) {
4149 // scanner.getNextUnicodeChar();
4151 if (scanner.withoutUnicodePtr != 0) {
4152 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4155 while (scanner.currentCharacter != '"') {
4156 if (scanner.currentCharacter == '\r') {
4157 if (source[scanner.currentPosition] == '\n')
4158 scanner.currentPosition++;
4159 break; // the string cannot go further that
4162 if (scanner.currentCharacter == '\n') {
4163 break; // the string cannot go further that
4166 if (scanner.currentCharacter == '\\') {
4167 scanner.scanEscapeCharacter();
4169 // consume next character
4170 scanner.unicodeAsBackSlash = false;
4171 // if (((scanner.currentCharacter =
4172 // source[scanner.currentPosition++]) == '\\')
4173 // && (source[scanner.currentPosition] == 'u'))
4175 // scanner.getNextUnicodeChar();
4177 if (scanner.withoutUnicodePtr != 0) {
4178 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4185 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4188 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4189 && (source[scanner.currentPosition] == 'u')) {
4190 //-------------unicode traitement
4192 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4193 scanner.currentPosition++;
4194 while (source[scanner.currentPosition] == 'u') {
4195 scanner.currentPosition++;
4197 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4198 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4199 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4200 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4204 scanner.currentCharacter = 'A';
4205 } //something different from \n and \r
4207 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4210 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
4212 scanner.startPosition = scanner.currentPosition;
4213 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4214 && (source[scanner.currentPosition] == 'u')) {
4215 //-------------unicode traitement
4217 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4218 scanner.currentPosition++;
4219 while (source[scanner.currentPosition] == 'u') {
4220 scanner.currentPosition++;
4222 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4223 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4224 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4225 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4229 scanner.currentCharacter = 'A';
4230 } //something different from \n
4233 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4237 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4238 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4239 // only record line positions we
4240 // have not recorded yet
4241 scanner.pushLineSeparator();
4242 if (this.scanner.taskTags != null) {
4243 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4244 .getCurrentTokenEndPosition());
4250 if (test > 0) { //traditional and annotation
4252 boolean star = false;
4253 // consume next character
4254 scanner.unicodeAsBackSlash = false;
4255 // if (((scanner.currentCharacter =
4256 // source[scanner.currentPosition++]) ==
4258 // (source[scanner.currentPosition] ==
4260 // scanner.getNextUnicodeChar();
4262 if (scanner.withoutUnicodePtr != 0) {
4263 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4266 if (scanner.currentCharacter == '*') {
4270 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4271 && (source[scanner.currentPosition] == 'u')) {
4272 //-------------unicode traitement
4274 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4275 scanner.currentPosition++;
4276 while (source[scanner.currentPosition] == 'u') {
4277 scanner.currentPosition++;
4279 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4280 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4281 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4282 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4286 scanner.currentCharacter = 'A';
4287 } //something different from * and /
4289 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4292 //loop until end of comment */
4293 while ((scanner.currentCharacter != '/') || (!star)) {
4294 star = scanner.currentCharacter == '*';
4296 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4297 && (source[scanner.currentPosition] == 'u')) {
4298 //-------------unicode traitement
4300 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4301 scanner.currentPosition++;
4302 while (source[scanner.currentPosition] == 'u') {
4303 scanner.currentPosition++;
4305 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4306 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4307 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4308 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4312 scanner.currentCharacter = 'A';
4313 } //something different from * and
4316 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4320 if (this.scanner.taskTags != null) {
4321 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4328 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4329 scanner.scanIdentifierOrKeyword(false);
4332 if (Character.isDigit(scanner.currentCharacter)) {
4333 scanner.scanNumber(false);
4337 //-----------------end switch while
4338 // try--------------------
4339 } catch (IndexOutOfBoundsException e) {
4340 break; // read until EOF
4341 } catch (InvalidInputException e) {
4342 return false; // no clue
4345 if (scanner.recordLineSeparator) {
4346 // compilationUnit.compilationResult.lineSeparatorPositions =
4347 // scanner.getLineEnds();
4349 // check placement anomalies against other kinds of brackets
4350 for (int kind = 0; kind < BracketKinds; kind++) {
4351 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4352 int start = leftPositions[kind][leftIndex]; // deepest
4354 // find matching closing bracket
4355 int depth = leftDepths[kind][leftIndex];
4357 for (int i = 0; i < rightCount[kind]; i++) {
4358 int pos = rightPositions[kind][i];
4359 // want matching bracket further in source with same
4361 if ((pos > start) && (depth == rightDepths[kind][i])) {
4366 if (end < 0) { // did not find a good closing match
4367 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4370 // check if even number of opening/closing other brackets
4371 // in between this pair of brackets
4373 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4374 for (int i = 0; i < leftCount[otherKind]; i++) {
4375 int pos = leftPositions[otherKind][i];
4376 if ((pos > start) && (pos < end))
4379 for (int i = 0; i < rightCount[otherKind]; i++) {
4380 int pos = rightPositions[otherKind][i];
4381 if ((pos > start) && (pos < end))
4385 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4391 // too many opening brackets ?
4392 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4393 anomaliesDetected = true;
4394 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4395 compilationUnit.compilationResult);
4397 // too many closing brackets ?
4398 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4399 anomaliesDetected = true;
4400 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4402 if (anomaliesDetected)
4405 return anomaliesDetected;
4406 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4407 return anomaliesDetected;
4408 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4409 return anomaliesDetected;
4413 protected void pushOnAstLengthStack(int pos) {
4415 astLengthStack[++astLengthPtr] = pos;
4416 } catch (IndexOutOfBoundsException e) {
4417 int oldStackLength = astLengthStack.length;
4418 int[] oldPos = astLengthStack;
4419 astLengthStack = new int[oldStackLength + StackIncrement];
4420 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4421 astLengthStack[astLengthPtr] = pos;
4425 protected void pushOnAstStack(ASTNode node) {
4427 * add a new obj on top of the ast stack
4430 astStack[++astPtr] = node;
4431 } catch (IndexOutOfBoundsException e) {
4432 int oldStackLength = astStack.length;
4433 ASTNode[] oldStack = astStack;
4434 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4435 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4436 astPtr = oldStackLength;
4437 astStack[astPtr] = node;
4440 astLengthStack[++astLengthPtr] = 1;
4441 } catch (IndexOutOfBoundsException e) {
4442 int oldStackLength = astLengthStack.length;
4443 int[] oldPos = astLengthStack;
4444 astLengthStack = new int[oldStackLength + AstStackIncrement];
4445 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4446 astLengthStack[astLengthPtr] = 1;
4450 protected void resetModifiers() {
4451 this.modifiers = AccDefault;
4452 this.modifiersSourceStart = -1; // <-- see comment into
4453 // modifiersFlag(int)
4454 this.scanner.commentPtr = -1;
4457 protected void consumePackageDeclarationName(IFile file) {
4458 // create a package name similar to java package names
4459 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4460 String filePath = file.getRawLocation().toString();
4461 String ext = file.getRawLocation().getFileExtension();
4462 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4463 ImportReference impt;
4466 if (filePath.startsWith(projectPath)) {
4467 tokens = CharOperation
4468 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4470 String name = file.getName();
4471 tokens = new char[1][];
4472 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4475 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4477 impt.declarationSourceStart = 0;
4478 impt.declarationSourceEnd = 0;
4479 impt.declarationEnd = 0;
4480 //endPosition is just before the ;