1 /***********************************************************************************************************************************
2 * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3 * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.Stack;
15 import net.sourceforge.phpdt.core.compiler.CharOperation;
16 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
17 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
18 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
21 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
23 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
24 import net.sourceforge.phpdt.internal.compiler.util.Util;
25 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
26 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
54 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
56 import org.eclipse.core.resources.IFile;
57 import org.eclipse.core.resources.IProject;
58 import org.eclipse.core.resources.IResource;
59 import org.eclipse.core.runtime.IPath;
61 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
62 protected final static int StackIncrement = 255;
64 protected int stateStackTop;
66 // protected int[] stack = new int[StackIncrement];
68 public int firstToken; // handle for multiple parsing goals
70 public int lastAct; //handle for multiple parsing goals
72 // protected RecoveredElement currentElement;
74 public static boolean VERBOSE_RECOVERY = false;
76 protected boolean diet = false; //tells the scanner to jump over some
78 // parts of the code/expressions like
81 public Scanner scanner;
83 // private ArrayList phpList;
85 // private int currentPHPString;
87 // private boolean phpEnd;
89 // private static HashMap keywordMap = null;
97 // row counter for syntax errors:
99 // column counter for syntax errors:
103 // // current identifier
104 // String identifier;
107 // Double doubleNumber;
109 // private String stringValue;
111 /** Contains the current expression. */
112 // private StringBuffer expression;
113 //private boolean phpMode;
114 protected int modifiers;
116 protected int modifiersSourceStart;
118 protected Parser(ProblemReporter problemReporter) {
119 this.problemReporter = problemReporter;
120 this.options = problemReporter.options;
121 // this.currentPHPString = 0;
122 // PHPParserSuperclass.fileToParse = fileToParse;
123 // this.phpList = null;
124 // this.indexManager = null;
126 this.token = TokenNameEOF;
128 // this.rowCount = 1;
129 // this.columnCount = 0;
130 // this.phpEnd = false;
132 this.initializeScanner();
135 public void setFileToParse(IFile fileToParse) {
136 // this.currentPHPString = 0;
137 // PHPParserSuperclass.fileToParse = fileToParse;
138 // this.phpList = null;
139 // this.indexManager = null;
141 this.token = TokenNameEOF;
142 // this.phpEnd = false;
143 this.initializeScanner();
147 * ClassDeclaration Constructor.
151 * Description of Parameter
154 public Parser(IFile fileToParse) {
155 // if (keywordMap == null) {
156 // keywordMap = new HashMap();
157 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
158 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
161 // this.currentPHPString = 0;
162 // PHPParserSuperclass.fileToParse = fileToParse;
163 // this.phpList = null;
164 this.includesList = null;
166 this.token = TokenNameEOF;
168 // this.rowCount = 1;
169 // this.columnCount = 0;
170 // this.phpEnd = false;
172 this.initializeScanner();
175 public void initializeScanner() {
176 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
177 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
178 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
182 * Create marker for the parse error
184 // private void setMarker(String message, int charStart, int charEnd, int
186 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
189 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
193 * @throws SyntaxError
196 private void throwSyntaxError(String error) {
197 int problemStartPosition = scanner.getCurrentTokenStartPosition();
198 int problemEndPosition = scanner.getCurrentTokenEndPosition();
199 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
203 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
207 * @throws SyntaxError
210 // private void throwSyntaxError(String error, int startRow) {
211 // throw new SyntaxError(startRow, 0, " ", error);
213 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
214 if (referenceContext != null) {
215 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
216 compilationUnit.compilationResult);
218 throw new SyntaxError(1, 0, " ", error);
221 private void reportSyntaxError(String error) {
222 int problemStartPosition = scanner.getCurrentTokenStartPosition();
223 int problemEndPosition = scanner.getCurrentTokenEndPosition();
224 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
227 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
228 if (referenceContext != null) {
229 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
230 compilationUnit.compilationResult);
234 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
235 if (referenceContext != null) {
236 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
237 compilationUnit.compilationResult);
242 * gets the next token from input
244 private void getNextToken() {
246 token = scanner.getNextToken();
248 int currentEndPosition = scanner.getCurrentTokenEndPosition();
249 int currentStartPosition = scanner.getCurrentTokenStartPosition();
250 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
251 System.out.println(scanner.toStringAction(token));
253 } catch (InvalidInputException e) {
254 token = TokenNameERROR;
255 String detailedMessage = e.getMessage();
257 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
258 throwSyntaxError("Unterminated string.");
259 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
260 throwSyntaxError("Unterminated commment.");
266 public void init(String s) {
268 this.token = TokenNameEOF;
269 this.includesList = new ArrayList();
271 // this.rowCount = 1;
272 // this.columnCount = 0;
273 // this.phpEnd = false;
274 // this.phpMode = false;
275 /* scanner initialization */
276 scanner.setSource(s.toCharArray());
277 scanner.setPHPMode(false);
281 protected void initialize(boolean phpMode) {
282 initialize(phpMode, null);
285 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
286 compilationUnit = null;
287 referenceContext = null;
288 this.includesList = new ArrayList();
289 // this.indexManager = indexManager;
291 this.token = TokenNameEOF;
293 // this.rowCount = 1;
294 // this.columnCount = 0;
295 // this.phpEnd = false;
296 // this.phpMode = phpMode;
297 scanner.setPHPMode(phpMode);
302 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
304 public void parse(String s) {
309 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
311 public void parse(String s, HashMap variables) {
312 fMethodVariables = variables;
313 fStackUnassigned = new Stack();
319 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
321 protected void parse() {
322 if (scanner.compilationUnit != null) {
323 IResource resource = scanner.compilationUnit.getResource();
324 if (resource != null && resource instanceof IFile) {
325 // set the package name
326 consumePackageDeclarationName((IFile) resource);
332 if (token != TokenNameEOF && token != TokenNameERROR) {
335 if (token != TokenNameEOF) {
336 if (token == TokenNameERROR) {
337 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
339 if (token == TokenNameRPAREN) {
340 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
342 if (token == TokenNameRBRACE) {
343 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
345 if (token == TokenNameRBRACKET) {
346 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
348 if (token == TokenNameLPAREN) {
349 throwSyntaxError("Read character '('; end-of-file not reached.");
351 if (token == TokenNameLBRACE) {
352 throwSyntaxError("Read character '{'; end-of-file not reached.");
354 if (token == TokenNameLBRACKET) {
355 throwSyntaxError("Read character '['; end-of-file not reached.");
357 throwSyntaxError("End-of-file not reached.");
360 } catch (SyntaxError sytaxErr1) {
362 // // if an error occured,
363 // // try to find keywords 'abstract' 'final' 'class' or 'function'
364 // // to parse the rest of the string
365 // boolean tokenize = scanner.tokenizeStrings;
367 // scanner.tokenizeStrings = true;
370 // while (token != TokenNameEOF) {
371 // if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
376 // if (token == TokenNameEOF) {
379 // } catch (SyntaxError sytaxErr2) {
382 // scanner.tokenizeStrings = tokenize;
391 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
393 public void parseFunction(String s, HashMap variables) {
395 scanner.phpMode = true;
396 parseFunction(variables);
400 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
402 protected void parseFunction(HashMap variables) {
404 boolean hasModifiers = member_modifiers();
405 if (token == TokenNamefunction) {
407 checkAndSetModifiers(AccPublic);
409 this.fMethodVariables = variables;
411 MethodDeclaration methodDecl = new MethodDeclaration(null);
412 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
413 methodDecl.modifiers = this.modifiers;
414 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
417 functionDefinition(methodDecl);
418 } catch (SyntaxError sytaxErr1) {
421 int sourceEnd = scanner.getCurrentTokenStartPosition();
422 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
423 sourceEnd = methodDecl.declarationSourceStart + 1;
425 methodDecl.declarationSourceEnd = sourceEnd;
430 protected CompilationUnitDeclaration endParse(int act) {
434 // if (currentElement != null) {
435 // currentElement.topElement().updateParseTree();
436 // if (VERBOSE_RECOVERY) {
437 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
438 // System.out.println("--------------------------"); //$NON-NLS-1$
439 // System.out.println(compilationUnit);
440 // System.out.println("----------------------------------"); //$NON-NLS-1$
443 if (diet & VERBOSE_RECOVERY) {
444 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
445 System.out.println("--------------------------"); //$NON-NLS-1$
446 System.out.println(compilationUnit);
447 System.out.println("----------------------------------"); //$NON-NLS-1$
450 if (scanner.recordLineSeparator) {
451 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
453 if (scanner.taskTags != null) {
454 for (int i = 0; i < scanner.foundTaskCount; i++) {
455 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
456 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
457 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
460 compilationUnit.imports = new ImportReference[includesList.size()];
461 for (int i = 0; i < includesList.size(); i++) {
462 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
464 return compilationUnit;
467 private Block statementList() {
468 boolean branchStatement = false;
470 int blockStart = scanner.getCurrentTokenStartPosition();
471 ArrayList blockStatements = new ArrayList();
474 statement = statement();
475 blockStatements.add(statement);
476 if (branchStatement && statement != null) {
477 // reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
478 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()),statement.sourceStart, statement.sourceEnd,
479 referenceContext, compilationUnit.compilationResult);
481 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
482 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
483 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
484 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
485 return createBlock(blockStart, blockStatements);
487 branchStatement = checkUnreachableStatements(statement);
488 } catch (SyntaxError sytaxErr1) {
489 // if an error occured,
490 // try to find keywords
491 // to parse the rest of the string
492 boolean tokenize = scanner.tokenizeStrings;
494 scanner.tokenizeStrings = true;
497 while (token != TokenNameEOF) {
498 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
499 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
500 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
501 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
502 return createBlock(blockStart, blockStatements);
504 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
505 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
506 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
507 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
508 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
509 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
512 // System.out.println(scanner.toStringAction(token));
514 // System.out.println(scanner.toStringAction(token));
516 if (token == TokenNameEOF) {
520 scanner.tokenizeStrings = tokenize;
530 private boolean checkUnreachableStatements(Statement statement) {
531 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
533 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
541 * @param blockStatements
544 private Block createBlock(int blockStart, ArrayList blockStatements) {
545 int blockEnd = scanner.getCurrentTokenEndPosition();
546 Block b = Block.EmptyWith(blockStart, blockEnd);
547 b.statements = new Statement[blockStatements.size()];
548 blockStatements.toArray(b.statements);
552 private void functionBody(MethodDeclaration methodDecl) {
553 // '{' [statement-list] '}'
554 if (token == TokenNameLBRACE) {
557 throwSyntaxError("'{' expected in compound-statement.");
559 if (token != TokenNameRBRACE) {
562 if (token == TokenNameRBRACE) {
563 // methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
566 throwSyntaxError("'}' expected in compound-statement.");
570 private Statement statement() {
571 Statement statement = null;
572 Expression expression;
573 int sourceStart = scanner.getCurrentTokenStartPosition();
575 if (token == TokenNameif) {
576 // T_IF '(' expr ')' statement elseif_list else_single
577 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
579 if (token == TokenNameLPAREN) {
582 throwSyntaxError("'(' expected after 'if' keyword.");
585 if (token == TokenNameRPAREN) {
588 throwSyntaxError("')' expected after 'if' condition.");
590 // create basic IfStatement
591 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
592 if (token == TokenNameCOLON) {
594 ifStatementColon(ifStatement);
596 ifStatement(ifStatement);
599 } else if (token == TokenNameswitch) {
601 if (token == TokenNameLPAREN) {
604 throwSyntaxError("'(' expected after 'switch' keyword.");
607 if (token == TokenNameRPAREN) {
610 throwSyntaxError("')' expected after 'switch' condition.");
614 } else if (token == TokenNamefor) {
616 if (token == TokenNameLPAREN) {
619 throwSyntaxError("'(' expected after 'for' keyword.");
621 if (token == TokenNameSEMICOLON) {
625 if (token == TokenNameSEMICOLON) {
628 throwSyntaxError("';' expected after 'for'.");
631 if (token == TokenNameSEMICOLON) {
635 if (token == TokenNameSEMICOLON) {
638 throwSyntaxError("';' expected after 'for'.");
641 if (token == TokenNameRPAREN) {
645 if (token == TokenNameRPAREN) {
648 throwSyntaxError("')' expected after 'for'.");
653 } else if (token == TokenNamewhile) {
655 if (token == TokenNameLPAREN) {
658 throwSyntaxError("'(' expected after 'while' keyword.");
661 if (token == TokenNameRPAREN) {
664 throwSyntaxError("')' expected after 'while' condition.");
668 } else if (token == TokenNamedo) {
670 if (token == TokenNameLBRACE) {
672 if (token != TokenNameRBRACE) {
675 if (token == TokenNameRBRACE) {
678 throwSyntaxError("'}' expected after 'do' keyword.");
683 if (token == TokenNamewhile) {
685 if (token == TokenNameLPAREN) {
688 throwSyntaxError("'(' expected after 'while' keyword.");
691 if (token == TokenNameRPAREN) {
694 throwSyntaxError("')' expected after 'while' condition.");
697 throwSyntaxError("'while' expected after 'do' keyword.");
699 if (token == TokenNameSEMICOLON) {
702 if (token != TokenNameINLINE_HTML) {
703 throwSyntaxError("';' expected after do-while statement.");
708 } else if (token == TokenNameforeach) {
710 if (token == TokenNameLPAREN) {
713 throwSyntaxError("'(' expected after 'foreach' keyword.");
716 if (token == TokenNameas) {
719 throwSyntaxError("'as' expected after 'foreach' exxpression.");
723 foreach_optional_arg();
724 if (token == TokenNameEQUAL_GREATER) {
728 if (token == TokenNameRPAREN) {
731 throwSyntaxError("')' expected after 'foreach' expression.");
735 } else if (token == TokenNamebreak) {
738 if (token != TokenNameSEMICOLON) {
741 if (token == TokenNameSEMICOLON) {
742 sourceEnd = scanner.getCurrentTokenEndPosition();
745 if (token != TokenNameINLINE_HTML) {
746 throwSyntaxError("';' expected after 'break'.");
748 sourceEnd = scanner.getCurrentTokenEndPosition();
751 return new BreakStatement(null, sourceStart, sourceEnd);
752 } else if (token == TokenNamecontinue) {
755 if (token != TokenNameSEMICOLON) {
758 if (token == TokenNameSEMICOLON) {
759 sourceEnd = scanner.getCurrentTokenEndPosition();
762 if (token != TokenNameINLINE_HTML) {
763 throwSyntaxError("';' expected after 'continue'.");
765 sourceEnd = scanner.getCurrentTokenEndPosition();
768 return new ContinueStatement(null, sourceStart, sourceEnd);
769 } else if (token == TokenNamereturn) {
772 if (token != TokenNameSEMICOLON) {
775 if (token == TokenNameSEMICOLON) {
776 sourceEnd = scanner.getCurrentTokenEndPosition();
779 if (token != TokenNameINLINE_HTML) {
780 throwSyntaxError("';' expected after 'return'.");
782 sourceEnd = scanner.getCurrentTokenEndPosition();
785 return new ReturnStatement(expression, sourceStart, sourceEnd);
786 } else if (token == TokenNameecho) {
789 if (token == TokenNameSEMICOLON) {
792 if (token != TokenNameINLINE_HTML) {
793 throwSyntaxError("';' expected after 'echo' statement.");
798 } else if (token == TokenNameINLINE_HTML) {
801 // } else if (token == TokenNameprint) {
804 // if (token == TokenNameSEMICOLON) {
807 // if (token != TokenNameStopPHP) {
808 // throwSyntaxError("';' expected after 'print' statement.");
813 } else if (token == TokenNameglobal) {
816 if (token == TokenNameSEMICOLON) {
819 if (token != TokenNameINLINE_HTML) {
820 throwSyntaxError("';' expected after 'global' statement.");
825 } else if (token == TokenNamestatic) {
828 if (token == TokenNameSEMICOLON) {
831 if (token != TokenNameINLINE_HTML) {
832 throwSyntaxError("';' expected after 'static' statement.");
837 } else if (token == TokenNameunset) {
839 if (token == TokenNameLPAREN) {
842 throwSyntaxError("'(' expected after 'unset' statement.");
845 if (token == TokenNameRPAREN) {
848 throwSyntaxError("')' expected after 'unset' statement.");
850 if (token == TokenNameSEMICOLON) {
853 if (token != TokenNameINLINE_HTML) {
854 throwSyntaxError("';' expected after 'unset' statement.");
859 } else if (token == TokenNamefunction) {
860 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
861 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
862 methodDecl.modifiers = AccDefault;
863 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
866 functionDefinition(methodDecl);
868 sourceEnd = scanner.getCurrentTokenStartPosition();
869 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
870 sourceEnd = methodDecl.declarationSourceStart + 1;
872 methodDecl.declarationSourceEnd = sourceEnd;
875 } else if (token == TokenNamedeclare) {
876 //T_DECLARE '(' declare_list ')' declare_statement
878 if (token != TokenNameLPAREN) {
879 throwSyntaxError("'(' expected in 'declare' statement.");
883 if (token != TokenNameRPAREN) {
884 throwSyntaxError("')' expected in 'declare' statement.");
889 } else if (token == TokenNametry) {
891 if (token != TokenNameLBRACE) {
892 throwSyntaxError("'{' expected in 'try' statement.");
896 if (token != TokenNameRBRACE) {
897 throwSyntaxError("'}' expected in 'try' statement.");
901 } else if (token == TokenNamecatch) {
903 if (token != TokenNameLPAREN) {
904 throwSyntaxError("'(' expected in 'catch' statement.");
907 fully_qualified_class_name();
908 if (token != TokenNameVariable) {
909 throwSyntaxError("Variable expected in 'catch' statement.");
912 if (token != TokenNameRPAREN) {
913 throwSyntaxError("')' expected in 'catch' statement.");
916 if (token != TokenNameLBRACE) {
917 throwSyntaxError("'{' expected in 'catch' statement.");
920 if (token != TokenNameRBRACE) {
922 if (token != TokenNameRBRACE) {
923 throwSyntaxError("'}' expected in 'catch' statement.");
927 additional_catches();
929 } else if (token == TokenNamethrow) {
932 if (token == TokenNameSEMICOLON) {
935 throwSyntaxError("';' expected after 'throw' exxpression.");
938 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
940 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
941 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
942 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
943 typeDecl.name = new char[] { ' ' };
944 // default super class
945 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
946 compilationUnit.types.add(typeDecl);
947 pushOnAstStack(typeDecl);
948 unticked_class_declaration_statement(typeDecl);
956 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
957 } else if (token == TokenNameLBRACE) {
959 if (token != TokenNameRBRACE) {
960 statement = statementList();
962 if (token == TokenNameRBRACE) {
966 throwSyntaxError("'}' expected.");
969 if (token != TokenNameSEMICOLON) {
972 if (token == TokenNameSEMICOLON) {
976 if (token == TokenNameRBRACE) {
977 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
979 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
980 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
990 private void declare_statement() {
992 //| ':' inner_statement_list T_ENDDECLARE ';'
994 if (token == TokenNameCOLON) {
996 // TODO: implement inner_statement_list();
998 if (token != TokenNameenddeclare) {
999 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1002 if (token != TokenNameSEMICOLON) {
1003 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1011 private void declare_list() {
1012 // T_STRING '=' static_scalar
1013 //| declare_list ',' T_STRING '=' static_scalar
1015 if (token != TokenNameIdentifier) {
1016 throwSyntaxError("Identifier expected in 'declare' list.");
1019 if (token != TokenNameEQUAL) {
1020 throwSyntaxError("'=' expected in 'declare' list.");
1024 if (token != TokenNameCOMMA) {
1031 private void additional_catches() {
1032 while (token == TokenNamecatch) {
1034 if (token != TokenNameLPAREN) {
1035 throwSyntaxError("'(' expected in 'catch' statement.");
1038 fully_qualified_class_name();
1039 if (token != TokenNameVariable) {
1040 throwSyntaxError("Variable expected in 'catch' statement.");
1043 if (token != TokenNameRPAREN) {
1044 throwSyntaxError("')' expected in 'catch' statement.");
1047 if (token != TokenNameLBRACE) {
1048 throwSyntaxError("'{' expected in 'catch' statement.");
1051 if (token != TokenNameRBRACE) {
1054 if (token != TokenNameRBRACE) {
1055 throwSyntaxError("'}' expected in 'catch' statement.");
1061 private void foreach_variable() {
1064 if (token == TokenNameAND) {
1070 private void foreach_optional_arg() {
1072 //| T_DOUBLE_ARROW foreach_variable
1073 if (token == TokenNameEQUAL_GREATER) {
1079 private void global_var_list() {
1081 // global_var_list ',' global_var
1083 HashSet set = peekVariableSet();
1086 if (token != TokenNameCOMMA) {
1093 private void global_var(HashSet set) {
1097 //| '$' '{' expr '}'
1098 if (token == TokenNameVariable) {
1099 if (fMethodVariables != null) {
1100 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1101 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1103 addVariableSet(set);
1105 } else if (token == TokenNameDOLLAR) {
1107 if (token == TokenNameLBRACE) {
1110 if (token != TokenNameRBRACE) {
1111 throwSyntaxError("'}' expected in global variable.");
1120 private void static_var_list() {
1122 // static_var_list ',' T_VARIABLE
1123 //| static_var_list ',' T_VARIABLE '=' static_scalar
1125 //| T_VARIABLE '=' static_scalar,
1126 HashSet set = peekVariableSet();
1128 if (token == TokenNameVariable) {
1129 if (fMethodVariables != null) {
1130 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1131 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1133 addVariableSet(set);
1135 if (token == TokenNameEQUAL) {
1139 if (token != TokenNameCOMMA) {
1149 private void unset_variables() {
1152 // | unset_variables ',' unset_variable
1157 if (token != TokenNameCOMMA) {
1164 private final void initializeModifiers() {
1166 this.modifiersSourceStart = -1;
1169 private final void checkAndSetModifiers(int flag) {
1170 this.modifiers |= flag;
1171 if (this.modifiersSourceStart < 0)
1172 this.modifiersSourceStart = this.scanner.startPosition;
1175 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1176 initializeModifiers();
1177 if (token == TokenNameinterface) {
1178 // interface_entry T_STRING
1179 // interface_extends_list
1180 // '{' class_statement_list '}'
1181 checkAndSetModifiers(AccInterface);
1183 typeDecl.modifiers = this.modifiers;
1184 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1185 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1186 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1187 typeDecl.name = scanner.getCurrentIdentifierSource();
1188 if (token > TokenNameKEYWORD) {
1189 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1190 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1191 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1192 // typeDecl.sourceStart, typeDecl.sourceEnd);
1195 interface_extends_list(typeDecl);
1197 typeDecl.name = new char[] { ' ' };
1198 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1202 // class_entry_type T_STRING extends_from
1204 // '{' class_statement_list'}'
1206 typeDecl.modifiers = this.modifiers;
1207 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1208 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1210 //identifier 'extends' identifier
1211 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1212 typeDecl.name = scanner.getCurrentIdentifierSource();
1213 if (token > TokenNameKEYWORD) {
1214 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1215 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1216 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1217 // typeDecl.sourceStart, typeDecl.sourceEnd);
1222 // | T_EXTENDS fully_qualified_class_name
1223 if (token == TokenNameextends) {
1224 interface_extends_list(typeDecl);
1226 // if (token != TokenNameIdentifier) {
1227 // throwSyntaxError("Class name expected after keyword
1229 // scanner.getCurrentTokenStartPosition(), scanner
1230 // .getCurrentTokenEndPosition());
1233 implements_list(typeDecl);
1235 typeDecl.name = new char[] { ' ' };
1236 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1240 // '{' class_statement_list '}'
1241 if (token == TokenNameLBRACE) {
1243 if (token != TokenNameRBRACE) {
1244 ArrayList list = new ArrayList();
1245 class_statement_list(list);
1246 typeDecl.fields = new FieldDeclaration[list.size()];
1247 for (int i = 0; i < list.size(); i++) {
1248 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1251 if (token == TokenNameRBRACE) {
1252 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1255 throwSyntaxError("'}' expected at end of class body.");
1258 throwSyntaxError("'{' expected at start of class body.");
1262 private void class_entry_type() {
1264 // | T_ABSTRACT T_CLASS
1265 // | T_FINAL T_CLASS
1266 if (token == TokenNameclass) {
1268 } else if (token == TokenNameabstract) {
1269 checkAndSetModifiers(AccAbstract);
1271 if (token != TokenNameclass) {
1272 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1275 } else if (token == TokenNamefinal) {
1276 checkAndSetModifiers(AccFinal);
1278 if (token != TokenNameclass) {
1279 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1283 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1287 private void class_extends(TypeDeclaration typeDecl) {
1289 // | T_EXTENDS interface_list
1290 if (token == TokenNameextends) {
1293 if (token == TokenNameIdentifier) {
1296 throwSyntaxError("Class name expected after keyword 'extends'.");
1301 private void interface_extends_list(TypeDeclaration typeDecl) {
1303 // | T_EXTENDS interface_list
1304 if (token == TokenNameextends) {
1310 private void implements_list(TypeDeclaration typeDecl) {
1312 // | T_IMPLEMENTS interface_list
1313 if (token == TokenNameimplements) {
1319 private void interface_list() {
1321 // fully_qualified_class_name
1322 //| interface_list ',' fully_qualified_class_name
1324 if (token == TokenNameIdentifier) {
1327 throwSyntaxError("Interface name expected after keyword 'implements'.");
1329 if (token != TokenNameCOMMA) {
1336 // private void classBody(TypeDeclaration typeDecl) {
1337 // //'{' [class-element-list] '}'
1338 // if (token == TokenNameLBRACE) {
1340 // if (token != TokenNameRBRACE) {
1341 // class_statement_list();
1343 // if (token == TokenNameRBRACE) {
1344 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1347 // throwSyntaxError("'}' expected at end of class body.");
1350 // throwSyntaxError("'{' expected at start of class body.");
1353 private void class_statement_list(ArrayList list) {
1356 class_statement(list);
1357 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1358 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1359 || token == TokenNameconst) {
1362 if (token == TokenNameRBRACE) {
1365 throwSyntaxError("'}' at end of class statement.");
1366 } catch (SyntaxError sytaxErr1) {
1367 boolean tokenize = scanner.tokenizeStrings;
1369 scanner.tokenizeStrings = true;
1372 // if an error occured,
1373 // try to find keywords
1374 // to parse the rest of the string
1375 while (token != TokenNameEOF) {
1376 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1377 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1378 || token == TokenNameconst) {
1381 // System.out.println(scanner.toStringAction(token));
1384 if (token == TokenNameEOF) {
1388 scanner.tokenizeStrings = tokenize;
1394 private void class_statement(ArrayList list) {
1396 // variable_modifiers class_variable_declaration ';'
1397 // | class_constant_declaration ';'
1398 // | method_modifiers T_FUNCTION is_reference T_STRING
1399 // '(' parameter_list ')' method_body
1400 initializeModifiers();
1401 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1403 if (token == TokenNamevar) {
1404 checkAndSetModifiers(AccPublic);
1405 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1406 referenceContext, compilationUnit.compilationResult);
1408 class_variable_declaration(declarationSourceStart, list);
1409 } else if (token == TokenNameconst) {
1410 checkAndSetModifiers(AccFinal | AccPublic);
1411 class_constant_declaration(declarationSourceStart, list);
1412 if (token != TokenNameSEMICOLON) {
1413 throwSyntaxError("';' expected after class const declaration.");
1417 boolean hasModifiers = member_modifiers();
1418 if (token == TokenNamefunction) {
1419 if (!hasModifiers) {
1420 checkAndSetModifiers(AccPublic);
1422 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1423 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1424 methodDecl.modifiers = this.modifiers;
1425 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1428 functionDefinition(methodDecl);
1430 int sourceEnd = scanner.getCurrentTokenStartPosition();
1431 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1432 sourceEnd = methodDecl.declarationSourceStart + 1;
1434 methodDecl.declarationSourceEnd = sourceEnd;
1437 if (!hasModifiers) {
1438 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1440 class_variable_declaration(declarationSourceStart, list);
1445 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1446 // class_constant_declaration ',' T_STRING '=' static_scalar
1447 // | T_CONST T_STRING '=' static_scalar
1448 if (token != TokenNameconst) {
1449 throwSyntaxError("'const' keyword expected in class declaration.");
1454 if (token != TokenNameIdentifier) {
1455 throwSyntaxError("Identifier expected in class const declaration.");
1457 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1458 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1459 fieldDeclaration.modifiers = this.modifiers;
1460 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1461 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1462 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1463 // fieldDeclaration.type
1464 list.add(fieldDeclaration);
1466 if (token != TokenNameEQUAL) {
1467 throwSyntaxError("'=' expected in class const declaration.");
1471 if (token != TokenNameCOMMA) {
1472 break; // while(true)-loop
1478 // private void variable_modifiers() {
1479 // // variable_modifiers:
1480 // // non_empty_member_modifiers
1482 // initializeModifiers();
1483 // if (token == TokenNamevar) {
1484 // checkAndSetModifiers(AccPublic);
1485 // reportSyntaxError(
1486 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1488 // modifier for field declarations.",
1489 // scanner.getCurrentTokenStartPosition(), scanner
1490 // .getCurrentTokenEndPosition());
1493 // if (!member_modifiers()) {
1494 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1495 // field declarations.");
1499 // private void method_modifiers() {
1500 // //method_modifiers:
1502 // //| non_empty_member_modifiers
1503 // initializeModifiers();
1504 // if (!member_modifiers()) {
1505 // checkAndSetModifiers(AccPublic);
1508 private boolean member_modifiers() {
1515 boolean foundToken = false;
1517 if (token == TokenNamepublic) {
1518 checkAndSetModifiers(AccPublic);
1521 } else if (token == TokenNameprotected) {
1522 checkAndSetModifiers(AccProtected);
1525 } else if (token == TokenNameprivate) {
1526 checkAndSetModifiers(AccPrivate);
1529 } else if (token == TokenNamestatic) {
1530 checkAndSetModifiers(AccStatic);
1533 } else if (token == TokenNameabstract) {
1534 checkAndSetModifiers(AccAbstract);
1537 } else if (token == TokenNamefinal) {
1538 checkAndSetModifiers(AccFinal);
1548 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1549 // class_variable_declaration:
1550 // class_variable_declaration ',' T_VARIABLE
1551 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1553 // | T_VARIABLE '=' static_scalar
1554 char[] classVariable;
1556 if (token == TokenNameVariable) {
1557 classVariable = scanner.getCurrentIdentifierSource();
1558 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1559 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1560 .getCurrentTokenEndPosition());
1561 fieldDeclaration.modifiers = this.modifiers;
1562 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1563 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1564 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1565 list.add(fieldDeclaration);
1566 if (fTypeVariables != null) {
1567 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1568 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1571 if (token == TokenNameEQUAL) {
1576 // if (token == TokenNamethis) {
1577 // throwSyntaxError("'$this' not allowed after keyword 'public'
1578 // 'protected' 'private' 'var'.");
1580 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1582 if (token != TokenNameCOMMA) {
1587 if (token != TokenNameSEMICOLON) {
1588 throwSyntaxError("';' expected after field declaration.");
1593 private void functionDefinition(MethodDeclaration methodDecl) {
1594 boolean isAbstract = false;
1596 if (compilationUnit != null) {
1597 compilationUnit.types.add(methodDecl);
1600 ASTNode node = astStack[astPtr];
1601 if (node instanceof TypeDeclaration) {
1602 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1603 if (typeDecl.methods == null) {
1604 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1606 AbstractMethodDeclaration[] newMethods;
1607 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1608 typeDecl.methods.length);
1609 newMethods[typeDecl.methods.length] = methodDecl;
1610 typeDecl.methods = newMethods;
1612 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1614 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1621 functionDeclarator(methodDecl);
1622 if (token == TokenNameSEMICOLON) {
1624 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1629 functionBody(methodDecl);
1631 fStackUnassigned.pop();
1635 private void functionDeclarator(MethodDeclaration methodDecl) {
1636 //identifier '(' [parameter-list] ')'
1637 if (token == TokenNameAND) {
1640 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1641 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1642 if (Scanner.isIdentifierOrKeyword(token)) {
1643 methodDecl.selector = scanner.getCurrentIdentifierSource();
1644 if (token > TokenNameKEYWORD) {
1645 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1646 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1649 if (token == TokenNameLPAREN) {
1652 throwSyntaxError("'(' expected in function declaration.");
1654 if (token != TokenNameRPAREN) {
1655 parameter_list(methodDecl);
1657 if (token != TokenNameRPAREN) {
1658 throwSyntaxError("')' expected in function declaration.");
1660 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1664 methodDecl.selector = "<undefined>".toCharArray();
1665 throwSyntaxError("Function name expected after keyword 'function'.");
1670 private void parameter_list(MethodDeclaration methodDecl) {
1671 // non_empty_parameter_list
1673 non_empty_parameter_list(methodDecl, true);
1676 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1677 // optional_class_type T_VARIABLE
1678 // | optional_class_type '&' T_VARIABLE
1679 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1680 // | optional_class_type T_VARIABLE '=' static_scalar
1681 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1682 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1683 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1685 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1687 char[] typeIdentifier = null;
1688 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1689 HashSet set = peekVariableSet();
1691 if (token == TokenNameIdentifier) {
1692 typeIdentifier = scanner.getCurrentIdentifierSource();
1695 if (token == TokenNameAND) {
1698 if (token == TokenNameVariable) {
1699 if (fMethodVariables != null) {
1701 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1702 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1704 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1706 info.typeIdentifier = typeIdentifier;
1707 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1709 addVariableSet(set);
1711 if (token == TokenNameEQUAL) {
1716 throwSyntaxError("Variable expected in parameter list.");
1718 if (token != TokenNameCOMMA) {
1725 if (!empty_allowed) {
1726 throwSyntaxError("Identifier expected in parameter list.");
1730 private void optional_class_type() {
1735 // private void parameterDeclaration() {
1737 // //variable-reference
1738 // if (token == TokenNameAND) {
1740 // if (isVariable()) {
1743 // throwSyntaxError("Variable expected after reference operator '&'.");
1746 // //variable '=' constant
1747 // if (token == TokenNameVariable) {
1749 // if (token == TokenNameEQUAL) {
1755 // // if (token == TokenNamethis) {
1756 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1757 // // declaration.");
1761 private void labeledStatementList() {
1762 if (token != TokenNamecase && token != TokenNamedefault) {
1763 throwSyntaxError("'case' or 'default' expected.");
1766 if (token == TokenNamecase) {
1768 expr(); //constant();
1769 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1771 if (token == TokenNamecase || token == TokenNamedefault) {
1772 // empty case statement ?
1777 // else if (token == TokenNameSEMICOLON) {
1779 // "':' expected after 'case' keyword (Found token: " +
1780 // scanner.toStringAction(token) + ")",
1781 // scanner.getCurrentTokenStartPosition(),
1782 // scanner.getCurrentTokenEndPosition(),
1785 // if (token == TokenNamecase) { // empty case statement ?
1791 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1793 } else { // TokenNamedefault
1795 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1797 if (token == TokenNameRBRACE) {
1798 // empty default case
1801 if (token != TokenNamecase) {
1805 throwSyntaxError("':' character expected after 'default'.");
1808 } while (token == TokenNamecase || token == TokenNamedefault);
1811 private void ifStatementColon(IfStatement iState) {
1812 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
1813 Block b = inner_statement_list();
1814 iState.thenStatement = b;
1815 checkUnreachable(iState, b);
1816 if (token == TokenNameelseif) {
1817 new_elseif_list(iState);
1819 new_else_single(iState);
1820 if (token != TokenNameendif) {
1821 throwSyntaxError("'endif' expected.");
1824 if (token != TokenNameSEMICOLON) {
1825 reportSyntaxError("';' expected after if-statement.");
1826 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1828 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1833 private void ifStatement(IfStatement iState) {
1834 // T_IF '(' expr ')' statement elseif_list else_single
1835 Statement s = statement();
1836 iState.thenStatement = s;
1837 checkUnreachable(iState, s);
1838 if (token == TokenNameelseif) {
1839 elseif_list(iState);
1841 else_single(iState);
1844 private void elseif_list(IfStatement iState) {
1846 //| elseif_list T_ELSEIF '(' expr ')' statement
1847 ArrayList conditionList = new ArrayList();
1848 ArrayList statementList = new ArrayList();
1851 while (token == TokenNameelseif) {
1853 if (token == TokenNameLPAREN) {
1856 throwSyntaxError("'(' expected after 'elseif' keyword.");
1859 conditionList.add(e);
1860 if (token == TokenNameRPAREN) {
1863 throwSyntaxError("')' expected after 'elseif' condition.");
1866 statementList.add(s);
1867 checkUnreachable(iState, s);
1869 iState.elseifConditions = new Expression[conditionList.size()];
1870 iState.elseifStatements = new Statement[statementList.size()];
1871 conditionList.toArray(iState.elseifConditions);
1872 statementList.toArray(iState.elseifStatements);
1875 private void new_elseif_list(IfStatement iState) {
1877 //| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1878 ArrayList conditionList = new ArrayList();
1879 ArrayList statementList = new ArrayList();
1882 while (token == TokenNameelseif) {
1884 if (token == TokenNameLPAREN) {
1887 throwSyntaxError("'(' expected after 'elseif' keyword.");
1890 conditionList.add(e);
1891 if (token == TokenNameRPAREN) {
1894 throwSyntaxError("')' expected after 'elseif' condition.");
1896 if (token == TokenNameCOLON) {
1899 throwSyntaxError("':' expected after 'elseif' keyword.");
1901 b = inner_statement_list();
1902 statementList.add(b);
1903 checkUnreachable(iState, b);
1905 iState.elseifConditions = new Expression[conditionList.size()];
1906 iState.elseifStatements = new Statement[statementList.size()];
1907 conditionList.toArray(iState.elseifConditions);
1908 statementList.toArray(iState.elseifStatements);
1911 private void else_single(IfStatement iState) {
1914 if (token == TokenNameelse) {
1916 Statement s = statement();
1917 iState.elseStatement = s;
1918 checkUnreachable(iState, s);
1920 iState.checkUnreachable = false;
1922 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1925 private void new_else_single(IfStatement iState) {
1927 //| T_ELSE ':' inner_statement_list
1928 if (token == TokenNameelse) {
1930 if (token == TokenNameCOLON) {
1933 throwSyntaxError("':' expected after 'else' keyword.");
1935 Block b = inner_statement_list();
1936 iState.elseStatement = b;
1937 checkUnreachable(iState, b);
1939 iState.checkUnreachable = false;
1943 private Block inner_statement_list() {
1944 // inner_statement_list inner_statement
1946 return statementList();
1953 private void checkUnreachable(IfStatement iState, Statement s) {
1954 if (s instanceof Block) {
1955 Block b = (Block) s;
1956 if (b.statements == null || b.statements.length == 0) {
1957 iState.checkUnreachable = false;
1959 int off = b.statements.length - 1;
1960 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
1961 && !(b.statements[off] instanceof BreakStatement)) {
1962 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
1963 iState.checkUnreachable = false;
1968 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
1969 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
1970 iState.checkUnreachable = false;
1976 // private void elseifStatementList() {
1978 // elseifStatement();
1980 // case TokenNameelse:
1982 // if (token == TokenNameCOLON) {
1984 // if (token != TokenNameendif) {
1989 // if (token == TokenNameif) { //'else if'
1992 // throwSyntaxError("':' expected after 'else'.");
1996 // case TokenNameelseif:
2005 // private void elseifStatement() {
2006 // if (token == TokenNameLPAREN) {
2009 // if (token != TokenNameRPAREN) {
2010 // throwSyntaxError("')' expected in else-if-statement.");
2013 // if (token != TokenNameCOLON) {
2014 // throwSyntaxError("':' expected in else-if-statement.");
2017 // if (token != TokenNameendif) {
2023 private void switchStatement() {
2024 if (token == TokenNameCOLON) {
2025 // ':' [labeled-statement-list] 'endswitch' ';'
2027 labeledStatementList();
2028 if (token != TokenNameendswitch) {
2029 throwSyntaxError("'endswitch' expected.");
2032 if (token != TokenNameSEMICOLON) {
2033 throwSyntaxError("';' expected after switch-statement.");
2037 // '{' [labeled-statement-list] '}'
2038 if (token != TokenNameLBRACE) {
2039 throwSyntaxError("'{' expected in switch statement.");
2042 if (token != TokenNameRBRACE) {
2043 labeledStatementList();
2045 if (token != TokenNameRBRACE) {
2046 throwSyntaxError("'}' expected in switch statement.");
2052 private void forStatement() {
2053 if (token == TokenNameCOLON) {
2056 if (token != TokenNameendfor) {
2057 throwSyntaxError("'endfor' expected.");
2060 if (token != TokenNameSEMICOLON) {
2061 throwSyntaxError("';' expected after for-statement.");
2069 private void whileStatement() {
2070 // ':' statement-list 'endwhile' ';'
2071 if (token == TokenNameCOLON) {
2074 if (token != TokenNameendwhile) {
2075 throwSyntaxError("'endwhile' expected.");
2078 if (token != TokenNameSEMICOLON) {
2079 throwSyntaxError("';' expected after while-statement.");
2087 private void foreachStatement() {
2088 if (token == TokenNameCOLON) {
2091 if (token != TokenNameendforeach) {
2092 throwSyntaxError("'endforeach' expected.");
2095 if (token != TokenNameSEMICOLON) {
2096 throwSyntaxError("';' expected after foreach-statement.");
2104 // private void exitStatus() {
2105 // if (token == TokenNameLPAREN) {
2108 // throwSyntaxError("'(' expected in 'exit-status'.");
2110 // if (token != TokenNameRPAREN) {
2113 // if (token == TokenNameRPAREN) {
2116 // throwSyntaxError("')' expected after 'exit-status'.");
2119 private void expressionList() {
2122 if (token == TokenNameCOMMA) {
2130 private Expression expr() {
2132 // | expr_without_variable
2133 // if (token!=TokenNameEOF) {
2134 if (Scanner.TRACE) {
2135 System.out.println("TRACE: expr()");
2137 return expr_without_variable(true);
2141 private Expression expr_without_variable(boolean only_variable) {
2142 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2143 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2144 Expression expression = new Expression();
2145 expression.sourceStart = exprSourceStart;
2146 // default, may be overwritten
2147 expression.sourceEnd = exprSourceEnd;
2149 // internal_functions_in_yacc
2158 // | T_INC rw_variable
2159 // | T_DEC rw_variable
2160 // | T_INT_CAST expr
2161 // | T_DOUBLE_CAST expr
2162 // | T_STRING_CAST expr
2163 // | T_ARRAY_CAST expr
2164 // | T_OBJECT_CAST expr
2165 // | T_BOOL_CAST expr
2166 // | T_UNSET_CAST expr
2167 // | T_EXIT exit_expr
2169 // | T_ARRAY '(' array_pair_list ')'
2170 // | '`' encaps_list '`'
2171 // | T_LIST '(' assignment_list ')' '=' expr
2172 // | T_NEW class_name_reference ctor_arguments
2173 // | variable '=' expr
2174 // | variable '=' '&' variable
2175 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2176 // | variable T_PLUS_EQUAL expr
2177 // | variable T_MINUS_EQUAL expr
2178 // | variable T_MUL_EQUAL expr
2179 // | variable T_DIV_EQUAL expr
2180 // | variable T_CONCAT_EQUAL expr
2181 // | variable T_MOD_EQUAL expr
2182 // | variable T_AND_EQUAL expr
2183 // | variable T_OR_EQUAL expr
2184 // | variable T_XOR_EQUAL expr
2185 // | variable T_SL_EQUAL expr
2186 // | variable T_SR_EQUAL expr
2187 // | rw_variable T_INC
2188 // | rw_variable T_DEC
2189 // | expr T_BOOLEAN_OR expr
2190 // | expr T_BOOLEAN_AND expr
2191 // | expr T_LOGICAL_OR expr
2192 // | expr T_LOGICAL_AND expr
2193 // | expr T_LOGICAL_XOR expr
2205 // | expr T_IS_IDENTICAL expr
2206 // | expr T_IS_NOT_IDENTICAL expr
2207 // | expr T_IS_EQUAL expr
2208 // | expr T_IS_NOT_EQUAL expr
2210 // | expr T_IS_SMALLER_OR_EQUAL expr
2212 // | expr T_IS_GREATER_OR_EQUAL expr
2213 // | expr T_INSTANCEOF class_name_reference
2214 // | expr '?' expr ':' expr
2215 if (Scanner.TRACE) {
2216 System.out.println("TRACE: expr_without_variable() PART 1");
2219 case TokenNameisset:
2220 case TokenNameempty:
2222 case TokenNameinclude:
2223 case TokenNameinclude_once:
2224 case TokenNamerequire:
2225 case TokenNamerequire_once:
2226 internal_functions_in_yacc();
2229 case TokenNameLPAREN:
2232 if (token == TokenNameRPAREN) {
2235 throwSyntaxError("')' expected in expression.");
2245 // | T_INT_CAST expr
2246 // | T_DOUBLE_CAST expr
2247 // | T_STRING_CAST expr
2248 // | T_ARRAY_CAST expr
2249 // | T_OBJECT_CAST expr
2250 // | T_BOOL_CAST expr
2251 // | T_UNSET_CAST expr
2252 case TokenNameclone:
2253 case TokenNameprint:
2256 case TokenNameMINUS:
2258 case TokenNameTWIDDLE:
2259 case TokenNameintCAST:
2260 case TokenNamedoubleCAST:
2261 case TokenNamestringCAST:
2262 case TokenNamearrayCAST:
2263 case TokenNameobjectCAST:
2264 case TokenNameboolCAST:
2265 case TokenNameunsetCAST:
2275 //| T_STRING_VARNAME
2277 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2278 // | '`' encaps_list '`'
2280 // | '`' encaps_list '`'
2281 case TokenNameEncapsedString0:
2282 scanner.encapsedStringStack.push(new Character('`'));
2285 if (token == TokenNameEncapsedString0) {
2288 if (token != TokenNameEncapsedString0) {
2289 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2293 scanner.encapsedStringStack.pop();
2297 // | '\'' encaps_list '\''
2298 case TokenNameEncapsedString1:
2299 scanner.encapsedStringStack.push(new Character('\''));
2302 exprSourceStart = scanner.getCurrentTokenStartPosition();
2303 if (token == TokenNameEncapsedString1) {
2304 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2305 .getCurrentTokenEndPosition());
2308 if (token != TokenNameEncapsedString1) {
2309 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2311 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2312 .getCurrentTokenEndPosition());
2316 scanner.encapsedStringStack.pop();
2320 //| '"' encaps_list '"'
2321 case TokenNameEncapsedString2:
2322 scanner.encapsedStringStack.push(new Character('"'));
2325 exprSourceStart = scanner.getCurrentTokenStartPosition();
2326 if (token == TokenNameEncapsedString2) {
2327 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2328 .getCurrentTokenEndPosition());
2331 if (token != TokenNameEncapsedString2) {
2332 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2334 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2335 .getCurrentTokenEndPosition());
2339 scanner.encapsedStringStack.pop();
2343 case TokenNameStringDoubleQuote:
2344 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2345 .getCurrentTokenEndPosition());
2348 case TokenNameStringSingleQuote:
2349 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2350 .getCurrentTokenEndPosition());
2353 case TokenNameIntegerLiteral:
2354 case TokenNameDoubleLiteral:
2355 case TokenNameStringInterpolated:
2358 case TokenNameCLASS_C:
2359 case TokenNameMETHOD_C:
2360 case TokenNameFUNC_C:
2363 case TokenNameHEREDOC:
2366 case TokenNamearray:
2367 // T_ARRAY '(' array_pair_list ')'
2369 if (token == TokenNameLPAREN) {
2371 if (token == TokenNameRPAREN) {
2376 if (token != TokenNameRPAREN) {
2377 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2381 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2385 // | T_LIST '(' assignment_list ')' '=' expr
2387 if (token == TokenNameLPAREN) {
2390 if (token != TokenNameRPAREN) {
2391 throwSyntaxError("')' expected after 'list' keyword.");
2394 if (token != TokenNameEQUAL) {
2395 throwSyntaxError("'=' expected after 'list' keyword.");
2400 throwSyntaxError("'(' expected after 'list' keyword.");
2404 // | T_NEW class_name_reference ctor_arguments
2406 Expression typeRef = class_name_reference();
2408 if (typeRef != null) {
2409 expression = typeRef;
2412 // | T_INC rw_variable
2413 // | T_DEC rw_variable
2414 case TokenNamePLUS_PLUS:
2415 case TokenNameMINUS_MINUS:
2419 // | variable '=' expr
2420 // | variable '=' '&' variable
2421 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2422 // | variable T_PLUS_EQUAL expr
2423 // | variable T_MINUS_EQUAL expr
2424 // | variable T_MUL_EQUAL expr
2425 // | variable T_DIV_EQUAL expr
2426 // | variable T_CONCAT_EQUAL expr
2427 // | variable T_MOD_EQUAL expr
2428 // | variable T_AND_EQUAL expr
2429 // | variable T_OR_EQUAL expr
2430 // | variable T_XOR_EQUAL expr
2431 // | variable T_SL_EQUAL expr
2432 // | variable T_SR_EQUAL expr
2433 // | rw_variable T_INC
2434 // | rw_variable T_DEC
2435 case TokenNameIdentifier:
2436 case TokenNameVariable:
2437 case TokenNameDOLLAR:
2438 boolean rememberedVar = false;
2439 // char[] lhsVar = null;
2440 // if (token==TokenNameVariable) {
2441 // lhsVar = scanner.getCurrentTokenSource();
2443 Expression lhs = variable(true);
2446 case TokenNameEQUAL:
2447 // if (lhsVar != null) {
2448 // addVariableSet(lhsVar);
2451 if (token == TokenNameAND) {
2453 if (token == TokenNamenew) {
2454 // | variable '=' '&' T_NEW class_name_reference
2457 SingleTypeReference classRef = class_name_reference();
2459 if (classRef != null) {
2460 if (lhs != null && lhs instanceof FieldReference) {
2462 // $var = & new Object();
2463 if (fMethodVariables != null) {
2464 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2465 lhsInfo.reference = classRef;
2466 lhsInfo.typeIdentifier = classRef.token;
2467 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2468 rememberedVar = true;
2473 Expression rhs = variable(false);
2474 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2477 if (fMethodVariables != null) {
2478 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2479 if (rhsInfo != null && rhsInfo.reference != null) {
2480 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2481 lhsInfo.reference = rhsInfo.reference;
2482 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2483 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2484 rememberedVar = true;
2490 Expression rhs = expr();
2491 if (lhs != null && lhs instanceof FieldReference) {
2492 if (rhs != null && rhs instanceof FieldReference) {
2495 if (fMethodVariables != null) {
2496 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2497 if (rhsInfo != null && rhsInfo.reference != null) {
2498 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2499 lhsInfo.reference = rhsInfo.reference;
2500 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2501 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2502 rememberedVar = true;
2505 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2507 // $var = new Object();
2508 if (fMethodVariables != null) {
2509 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2510 lhsInfo.reference = (SingleTypeReference) rhs;
2511 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2512 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2513 rememberedVar = true;
2518 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2519 if (fMethodVariables != null) {
2520 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2521 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2525 case TokenNamePLUS_EQUAL:
2526 case TokenNameMINUS_EQUAL:
2527 case TokenNameMULTIPLY_EQUAL:
2528 case TokenNameDIVIDE_EQUAL:
2529 case TokenNameDOT_EQUAL:
2530 case TokenNameREMAINDER_EQUAL:
2531 case TokenNameAND_EQUAL:
2532 case TokenNameOR_EQUAL:
2533 case TokenNameXOR_EQUAL:
2534 case TokenNameRIGHT_SHIFT_EQUAL:
2535 case TokenNameLEFT_SHIFT_EQUAL:
2539 case TokenNamePLUS_PLUS:
2540 case TokenNameMINUS_MINUS:
2544 if (!only_variable) {
2545 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2553 if (token != TokenNameINLINE_HTML) {
2554 if (token > TokenNameKEYWORD) {
2558 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2563 if (Scanner.TRACE) {
2564 System.out.println("TRACE: expr_without_variable() PART 2");
2566 // | expr T_BOOLEAN_OR expr
2567 // | expr T_BOOLEAN_AND expr
2568 // | expr T_LOGICAL_OR expr
2569 // | expr T_LOGICAL_AND expr
2570 // | expr T_LOGICAL_XOR expr
2582 // | expr T_IS_IDENTICAL expr
2583 // | expr T_IS_NOT_IDENTICAL expr
2584 // | expr T_IS_EQUAL expr
2585 // | expr T_IS_NOT_EQUAL expr
2587 // | expr T_IS_SMALLER_OR_EQUAL expr
2589 // | expr T_IS_GREATER_OR_EQUAL expr
2592 case TokenNameOR_OR:
2594 expression = new OR_OR_Expression(expression, expr(), token);
2596 case TokenNameAND_AND:
2598 expression = new AND_AND_Expression(expression, expr(), token);
2600 case TokenNameEQUAL_EQUAL:
2602 expression = new EqualExpression(expression, expr(), token);
2612 case TokenNameMINUS:
2613 case TokenNameMULTIPLY:
2614 case TokenNameDIVIDE:
2615 case TokenNameREMAINDER:
2616 case TokenNameLEFT_SHIFT:
2617 case TokenNameRIGHT_SHIFT:
2618 case TokenNameEQUAL_EQUAL_EQUAL:
2619 case TokenNameNOT_EQUAL_EQUAL:
2620 case TokenNameNOT_EQUAL:
2622 case TokenNameLESS_EQUAL:
2623 case TokenNameGREATER:
2624 case TokenNameGREATER_EQUAL:
2626 expression = new BinaryExpression(expression, expr(), token);
2628 // | expr T_INSTANCEOF class_name_reference
2629 // | expr '?' expr ':' expr
2630 case TokenNameinstanceof:
2632 TypeReference classRef = class_name_reference();
2633 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2634 expression.sourceStart = exprSourceStart;
2635 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2637 case TokenNameQUESTION:
2639 Expression valueIfTrue = expr();
2640 if (token != TokenNameCOLON) {
2641 throwSyntaxError("':' expected in conditional expression.");
2644 Expression valueIfFalse = expr();
2646 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2652 } catch (SyntaxError e) {
2653 // try to find next token after expression with errors:
2654 if (token == TokenNameSEMICOLON) {
2658 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2666 private SingleTypeReference class_name_reference() {
2667 // class_name_reference:
2669 //| dynamic_class_name_reference
2670 SingleTypeReference ref = null;
2671 if (Scanner.TRACE) {
2672 System.out.println("TRACE: class_name_reference()");
2674 if (token == TokenNameIdentifier) {
2675 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2679 dynamic_class_name_reference();
2684 private void dynamic_class_name_reference() {
2685 //dynamic_class_name_reference:
2686 // base_variable T_OBJECT_OPERATOR object_property
2687 // dynamic_class_name_variable_properties
2689 if (Scanner.TRACE) {
2690 System.out.println("TRACE: dynamic_class_name_reference()");
2693 if (token == TokenNameMINUS_GREATER) {
2696 dynamic_class_name_variable_properties();
2700 private void dynamic_class_name_variable_properties() {
2701 // dynamic_class_name_variable_properties:
2702 // dynamic_class_name_variable_properties
2703 // dynamic_class_name_variable_property
2705 if (Scanner.TRACE) {
2706 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2708 while (token == TokenNameMINUS_GREATER) {
2709 dynamic_class_name_variable_property();
2713 private void dynamic_class_name_variable_property() {
2714 // dynamic_class_name_variable_property:
2715 // T_OBJECT_OPERATOR object_property
2716 if (Scanner.TRACE) {
2717 System.out.println("TRACE: dynamic_class_name_variable_property()");
2719 if (token == TokenNameMINUS_GREATER) {
2725 private void ctor_arguments() {
2728 //| '(' function_call_parameter_list ')'
2729 if (token == TokenNameLPAREN) {
2731 if (token == TokenNameRPAREN) {
2735 non_empty_function_call_parameter_list();
2736 if (token != TokenNameRPAREN) {
2737 throwSyntaxError("')' expected in ctor_arguments.");
2743 private void assignment_list() {
2745 // assignment_list ',' assignment_list_element
2746 //| assignment_list_element
2748 assignment_list_element();
2749 if (token != TokenNameCOMMA) {
2756 private void assignment_list_element() {
2757 //assignment_list_element:
2759 //| T_LIST '(' assignment_list ')'
2761 if (token == TokenNameVariable) {
2763 } else if (token == TokenNameDOLLAR) {
2766 if (token == TokenNamelist) {
2768 if (token == TokenNameLPAREN) {
2771 if (token != TokenNameRPAREN) {
2772 throwSyntaxError("')' expected after 'list' keyword.");
2776 throwSyntaxError("'(' expected after 'list' keyword.");
2782 private void array_pair_list() {
2785 //| non_empty_array_pair_list possible_comma
2786 non_empty_array_pair_list();
2787 if (token == TokenNameCOMMA) {
2792 private void non_empty_array_pair_list() {
2793 //non_empty_array_pair_list:
2794 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2795 //| non_empty_array_pair_list ',' expr
2796 //| expr T_DOUBLE_ARROW expr
2798 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2799 //| non_empty_array_pair_list ',' '&' w_variable
2800 //| expr T_DOUBLE_ARROW '&' w_variable
2803 if (token == TokenNameAND) {
2808 if (token == TokenNameAND) {
2811 } else if (token == TokenNameEQUAL_GREATER) {
2813 if (token == TokenNameAND) {
2821 if (token != TokenNameCOMMA) {
2825 if (token == TokenNameRPAREN) {
2831 // private void variableList() {
2834 // if (token == TokenNameCOMMA) {
2841 private Expression variable_without_objects(boolean lefthandside) {
2842 // variable_without_objects:
2843 // reference_variable
2844 // | simple_indirect_reference reference_variable
2845 if (Scanner.TRACE) {
2846 System.out.println("TRACE: variable_without_objects()");
2848 while (token == TokenNameDOLLAR) {
2851 return reference_variable(lefthandside);
2854 private Expression function_call(boolean lefthandside) {
2856 // T_STRING '(' function_call_parameter_list ')'
2857 //| class_constant '(' function_call_parameter_list ')'
2858 //| static_member '(' function_call_parameter_list ')'
2859 //| variable_without_objects '(' function_call_parameter_list ')'
2860 char[] defineName = null;
2861 char[] ident = null;
2864 Expression ref = null;
2865 if (Scanner.TRACE) {
2866 System.out.println("TRACE: function_call()");
2868 if (token == TokenNameIdentifier) {
2869 ident = scanner.getCurrentIdentifierSource();
2871 startPos = scanner.getCurrentTokenStartPosition();
2872 endPos = scanner.getCurrentTokenEndPosition();
2875 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2879 if (token == TokenNameIdentifier) {
2884 variable_without_objects(false);
2889 ref = variable_without_objects(lefthandside);
2891 if (token != TokenNameLPAREN) {
2892 if (defineName != null) {
2893 // does this identifier contain only uppercase characters?
2894 if (defineName.length == 3) {
2895 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2898 } else if (defineName.length == 4) {
2899 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2901 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2904 } else if (defineName.length == 5) {
2905 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2909 if (defineName != null) {
2910 for (int i = 0; i < defineName.length; i++) {
2911 if (Character.isLowerCase(defineName[i])) {
2912 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2918 // TODO is this ok ?
2920 // throwSyntaxError("'(' expected in function call.");
2923 if (token == TokenNameRPAREN) {
2927 non_empty_function_call_parameter_list();
2928 if (token != TokenNameRPAREN) {
2929 String functionName;
2930 if (ident == null) {
2931 functionName = new String(" ");
2933 functionName = new String(ident);
2935 throwSyntaxError("')' expected in function call (" + functionName + ").");
2941 // private void function_call_parameter_list() {
2942 // function_call_parameter_list:
2943 // non_empty_function_call_parameter_list { $$ = $1; }
2946 private void non_empty_function_call_parameter_list() {
2947 //non_empty_function_call_parameter_list:
2948 // expr_without_variable
2951 // | non_empty_function_call_parameter_list ',' expr_without_variable
2952 // | non_empty_function_call_parameter_list ',' variable
2953 // | non_empty_function_call_parameter_list ',' '&' w_variable
2954 if (Scanner.TRACE) {
2955 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2958 if (token == TokenNameAND) {
2962 // if (token == TokenNameIdentifier || token ==
2963 // TokenNameVariable
2964 // || token == TokenNameDOLLAR) {
2967 expr_without_variable(true);
2970 if (token != TokenNameCOMMA) {
2977 private void fully_qualified_class_name() {
2978 if (token == TokenNameIdentifier) {
2981 throwSyntaxError("Class name expected.");
2985 private void static_member() {
2987 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2988 // variable_without_objects
2989 if (Scanner.TRACE) {
2990 System.out.println("TRACE: static_member()");
2992 fully_qualified_class_name();
2993 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2994 throwSyntaxError("'::' expected after class name (static_member).");
2997 variable_without_objects(false);
3000 private Expression base_variable_with_function_calls(boolean lefthandside) {
3001 // base_variable_with_function_calls:
3004 boolean functionCall = false;
3005 if (Scanner.TRACE) {
3006 System.out.println("TRACE: base_variable_with_function_calls()");
3008 // if (token == TokenNameIdentifier) {
3009 // functionCall = true;
3010 // } else if (token == TokenNameVariable) {
3011 // int tempToken = token;
3012 // int tempPosition = scanner.currentPosition;
3014 // if (token == TokenNameLPAREN) {
3015 // functionCall = true;
3017 // token = tempToken;
3018 // scanner.currentPosition = tempPosition;
3019 // scanner.phpMode = true;
3021 // if (functionCall) {
3022 return function_call(lefthandside);
3028 private Expression base_variable() {
3030 // reference_variable
3031 // | simple_indirect_reference reference_variable
3033 Expression ref = null;
3034 if (Scanner.TRACE) {
3035 System.out.println("TRACE: base_variable()");
3037 if (token == TokenNameIdentifier) {
3040 while (token == TokenNameDOLLAR) {
3043 reference_variable(false);
3048 // private void simple_indirect_reference() {
3049 // // simple_indirect_reference:
3051 // //| simple_indirect_reference '$'
3053 private Expression reference_variable(boolean lefthandside) {
3054 // reference_variable:
3055 // reference_variable '[' dim_offset ']'
3056 // | reference_variable '{' expr '}'
3057 // | compound_variable
3058 Expression ref = null;
3059 if (Scanner.TRACE) {
3060 System.out.println("TRACE: reference_variable()");
3062 ref = compound_variable(lefthandside);
3064 if (token == TokenNameLBRACE) {
3068 if (token != TokenNameRBRACE) {
3069 throwSyntaxError("'}' expected in reference variable.");
3072 } else if (token == TokenNameLBRACKET) {
3075 if (token != TokenNameRBRACKET) {
3078 if (token != TokenNameRBRACKET) {
3079 throwSyntaxError("']' expected in reference variable.");
3090 private Expression compound_variable(boolean lefthandside) {
3091 // compound_variable:
3093 // | '$' '{' expr '}'
3094 if (Scanner.TRACE) {
3095 System.out.println("TRACE: compound_variable()");
3097 if (token == TokenNameVariable) {
3098 if (!lefthandside) {
3099 if (!containsVariableSet()) {
3100 // reportSyntaxError("The local variable " + new String(scanner.getCurrentIdentifierSource())
3101 // + " may not have been initialized");
3102 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()),scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
3103 referenceContext, compilationUnit.compilationResult);
3108 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3112 // because of simple_indirect_reference
3113 while (token == TokenNameDOLLAR) {
3116 if (token != TokenNameLBRACE) {
3117 reportSyntaxError("'{' expected after compound variable token '$'.");
3122 if (token != TokenNameRBRACE) {
3123 throwSyntaxError("'}' expected after compound variable token '$'.");
3130 // private void dim_offset() {
3136 private void object_property() {
3139 //| variable_without_objects
3140 if (Scanner.TRACE) {
3141 System.out.println("TRACE: object_property()");
3143 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3144 variable_without_objects(false);
3150 private void object_dim_list() {
3152 // object_dim_list '[' dim_offset ']'
3153 //| object_dim_list '{' expr '}'
3155 if (Scanner.TRACE) {
3156 System.out.println("TRACE: object_dim_list()");
3160 if (token == TokenNameLBRACE) {
3163 if (token != TokenNameRBRACE) {
3164 throwSyntaxError("'}' expected in object_dim_list.");
3167 } else if (token == TokenNameLBRACKET) {
3169 if (token == TokenNameRBRACKET) {
3174 if (token != TokenNameRBRACKET) {
3175 throwSyntaxError("']' expected in object_dim_list.");
3184 private void variable_name() {
3188 if (Scanner.TRACE) {
3189 System.out.println("TRACE: variable_name()");
3191 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3192 if (token > TokenNameKEYWORD) {
3193 // TODO show a warning "Keyword used as variable" ?
3197 if (token != TokenNameLBRACE) {
3198 throwSyntaxError("'{' expected in variable name.");
3202 if (token != TokenNameRBRACE) {
3203 throwSyntaxError("'}' expected in variable name.");
3209 private void r_variable() {
3213 private void w_variable(boolean lefthandside) {
3214 variable(lefthandside);
3217 private void rw_variable() {
3221 private Expression variable(boolean lefthandside) {
3223 // base_variable_with_function_calls T_OBJECT_OPERATOR
3224 // object_property method_or_not variable_properties
3225 // | base_variable_with_function_calls
3226 Expression ref = base_variable_with_function_calls(lefthandside);
3227 if (token == TokenNameMINUS_GREATER) {
3232 variable_properties();
3237 private void variable_properties() {
3238 // variable_properties:
3239 // variable_properties variable_property
3241 while (token == TokenNameMINUS_GREATER) {
3242 variable_property();
3246 private void variable_property() {
3247 // variable_property:
3248 // T_OBJECT_OPERATOR object_property method_or_not
3249 if (Scanner.TRACE) {
3250 System.out.println("TRACE: variable_property()");
3252 if (token == TokenNameMINUS_GREATER) {
3257 throwSyntaxError("'->' expected in variable_property.");
3261 private void method_or_not() {
3263 // '(' function_call_parameter_list ')'
3265 if (Scanner.TRACE) {
3266 System.out.println("TRACE: method_or_not()");
3268 if (token == TokenNameLPAREN) {
3270 if (token == TokenNameRPAREN) {
3274 non_empty_function_call_parameter_list();
3275 if (token != TokenNameRPAREN) {
3276 throwSyntaxError("')' expected in method_or_not.");
3282 private void exit_expr() {
3286 if (token != TokenNameLPAREN) {
3290 if (token == TokenNameRPAREN) {
3295 if (token != TokenNameRPAREN) {
3296 throwSyntaxError("')' expected after keyword 'exit'");
3301 private void encaps_list() {
3302 // encaps_list encaps_var
3303 // | encaps_list T_STRING
3304 // | encaps_list T_NUM_STRING
3305 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3306 // | encaps_list T_CHARACTER
3307 // | encaps_list T_BAD_CHARACTER
3308 // | encaps_list '['
3309 // | encaps_list ']'
3310 // | encaps_list '{'
3311 // | encaps_list '}'
3312 // | encaps_list T_OBJECT_OPERATOR
3316 case TokenNameSTRING:
3319 case TokenNameLBRACE:
3320 // scanner.encapsedStringStack.pop();
3323 case TokenNameRBRACE:
3324 // scanner.encapsedStringStack.pop();
3327 case TokenNameLBRACKET:
3328 // scanner.encapsedStringStack.pop();
3331 case TokenNameRBRACKET:
3332 // scanner.encapsedStringStack.pop();
3335 case TokenNameMINUS_GREATER:
3336 // scanner.encapsedStringStack.pop();
3339 case TokenNameVariable:
3340 case TokenNameDOLLAR_LBRACE:
3341 case TokenNameLBRACE_DOLLAR:
3345 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3346 if (encapsedChar == '$') {
3347 scanner.encapsedStringStack.pop();
3348 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3349 switch (encapsedChar) {
3351 if (token == TokenNameEncapsedString0) {
3354 token = TokenNameSTRING;
3357 if (token == TokenNameEncapsedString1) {
3360 token = TokenNameSTRING;
3363 if (token == TokenNameEncapsedString2) {
3366 token = TokenNameSTRING;
3375 private void encaps_var() {
3377 // | T_VARIABLE '[' encaps_var_offset ']'
3378 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3379 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3380 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3381 // | T_CURLY_OPEN variable '}'
3383 case TokenNameVariable:
3385 if (token == TokenNameLBRACKET) {
3387 expr(); //encaps_var_offset();
3388 if (token != TokenNameRBRACKET) {
3389 throwSyntaxError("']' expected after variable.");
3391 // scanner.encapsedStringStack.pop();
3394 } else if (token == TokenNameMINUS_GREATER) {
3396 if (token != TokenNameIdentifier) {
3397 throwSyntaxError("Identifier expected after '->'.");
3399 // scanner.encapsedStringStack.pop();
3403 // // scanner.encapsedStringStack.pop();
3404 // int tempToken = TokenNameSTRING;
3405 // if (!scanner.encapsedStringStack.isEmpty()
3406 // && (token == TokenNameEncapsedString0
3407 // || token == TokenNameEncapsedString1
3408 // || token == TokenNameEncapsedString2 || token ==
3409 // TokenNameERROR)) {
3410 // char encapsedChar = ((Character)
3411 // scanner.encapsedStringStack.peek())
3414 // case TokenNameEncapsedString0 :
3415 // if (encapsedChar == '`') {
3416 // tempToken = TokenNameEncapsedString0;
3419 // case TokenNameEncapsedString1 :
3420 // if (encapsedChar == '\'') {
3421 // tempToken = TokenNameEncapsedString1;
3424 // case TokenNameEncapsedString2 :
3425 // if (encapsedChar == '"') {
3426 // tempToken = TokenNameEncapsedString2;
3429 // case TokenNameERROR :
3430 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3431 // scanner.currentPosition--;
3437 // token = tempToken;
3440 case TokenNameDOLLAR_LBRACE:
3442 if (token == TokenNameDOLLAR_LBRACE) {
3444 } else if (token == TokenNameIdentifier) {
3446 if (token == TokenNameLBRACKET) {
3448 // if (token == TokenNameRBRACKET) {
3452 if (token != TokenNameRBRACKET) {
3453 throwSyntaxError("']' expected after '${'.");
3461 if (token != TokenNameRBRACE) {
3462 throwSyntaxError("'}' expected.");
3466 case TokenNameLBRACE_DOLLAR:
3468 if (token == TokenNameLBRACE_DOLLAR) {
3470 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3472 if (token == TokenNameLBRACKET) {
3474 // if (token == TokenNameRBRACKET) {
3478 if (token != TokenNameRBRACKET) {
3479 throwSyntaxError("']' expected.");
3483 } else if (token == TokenNameMINUS_GREATER) {
3485 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3486 throwSyntaxError("String or Variable token expected.");
3489 if (token == TokenNameLBRACKET) {
3491 // if (token == TokenNameRBRACKET) {
3495 if (token != TokenNameRBRACKET) {
3496 throwSyntaxError("']' expected after '${'.");
3502 // if (token != TokenNameRBRACE) {
3503 // throwSyntaxError("'}' expected after '{$'.");
3505 // // scanner.encapsedStringStack.pop();
3509 if (token != TokenNameRBRACE) {
3510 throwSyntaxError("'}' expected.");
3512 // scanner.encapsedStringStack.pop();
3519 private void encaps_var_offset() {
3524 case TokenNameSTRING:
3527 case TokenNameIntegerLiteral:
3530 case TokenNameVariable:
3533 case TokenNameIdentifier:
3537 throwSyntaxError("Variable or String token expected.");
3542 private void internal_functions_in_yacc() {
3545 case TokenNameisset:
3546 // T_ISSET '(' isset_variables ')'
3548 if (token != TokenNameLPAREN) {
3549 throwSyntaxError("'(' expected after keyword 'isset'");
3553 if (token != TokenNameRPAREN) {
3554 throwSyntaxError("')' expected after keyword 'isset'");
3558 case TokenNameempty:
3559 // T_EMPTY '(' variable ')'
3561 if (token != TokenNameLPAREN) {
3562 throwSyntaxError("'(' expected after keyword 'empty'");
3566 if (token != TokenNameRPAREN) {
3567 throwSyntaxError("')' expected after keyword 'empty'");
3571 case TokenNameinclude:
3573 checkFileName(token);
3575 case TokenNameinclude_once:
3576 // T_INCLUDE_ONCE expr
3577 checkFileName(token);
3580 // T_EVAL '(' expr ')'
3582 if (token != TokenNameLPAREN) {
3583 throwSyntaxError("'(' expected after keyword 'eval'");
3587 if (token != TokenNameRPAREN) {
3588 throwSyntaxError("')' expected after keyword 'eval'");
3592 case TokenNamerequire:
3594 checkFileName(token);
3596 case TokenNamerequire_once:
3597 // T_REQUIRE_ONCE expr
3598 checkFileName(token);
3603 private void checkFileName(int includeToken) {
3604 //<include-token> expr
3605 int start = scanner.getCurrentTokenStartPosition();
3606 boolean hasLPAREN = false;
3608 if (token == TokenNameLPAREN) {
3612 Expression expression = expr();
3614 if (token == TokenNameRPAREN) {
3617 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3620 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3622 if (scanner.compilationUnit != null) {
3623 IResource resource = scanner.compilationUnit.getResource();
3624 if (resource != null && resource instanceof IFile) {
3625 file = (IFile) resource;
3629 tokens = new char[1][];
3630 tokens[0] = currTokenSource;
3632 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3633 impt.declarationSourceEnd = impt.sourceEnd;
3634 impt.declarationEnd = impt.declarationSourceEnd;
3635 //endPosition is just before the ;
3636 impt.declarationSourceStart = start;
3637 includesList.add(impt);
3639 if (expression instanceof StringLiteral) {
3640 StringLiteral literal = (StringLiteral) expression;
3641 char[] includeName = literal.source();
3642 if (includeName.length == 0) {
3643 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3644 literal.sourceStart + 1);
3646 String includeNameString = new String(includeName);
3647 if (literal instanceof StringLiteralDQ) {
3648 if (includeNameString.indexOf('$') >= 0) {
3649 // assuming that the filename contains a variable => no filename check
3653 if (includeNameString.startsWith("http://")) {
3654 // assuming external include location
3658 // check the filename:
3659 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3660 IProject project = file.getProject();
3661 if (project != null) {
3662 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3665 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3666 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3667 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3668 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3669 compilationUnit.compilationResult);
3672 // String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
3673 // String filePath = file.getRawLocation().toString();
3674 String filePath = path.toString();
3675 String ext = file.getRawLocation().getFileExtension();
3676 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3679 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3680 impt.setFile(PHPFileUtil.createFile(path, project));
3681 } catch (Exception e) {
3682 // the file is outside of the workspace
3690 private void isset_variables() {
3692 // | isset_variables ','
3693 if (token == TokenNameRPAREN) {
3694 throwSyntaxError("Variable expected after keyword 'isset'");
3698 if (token == TokenNameCOMMA) {
3706 private boolean common_scalar() {
3710 // | T_CONSTANT_ENCAPSED_STRING
3717 case TokenNameIntegerLiteral:
3720 case TokenNameDoubleLiteral:
3723 case TokenNameStringDoubleQuote:
3726 case TokenNameStringSingleQuote:
3729 case TokenNameStringInterpolated:
3738 case TokenNameCLASS_C:
3741 case TokenNameMETHOD_C:
3744 case TokenNameFUNC_C:
3751 private void scalar() {
3754 //| T_STRING_VARNAME
3757 //| '"' encaps_list '"'
3758 //| '\'' encaps_list '\''
3759 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3760 throwSyntaxError("Not yet implemented (scalar).");
3763 private void static_scalar() {
3764 // static_scalar: /* compile-time evaluated scalars */
3767 // | '+' static_scalar
3768 // | '-' static_scalar
3769 // | T_ARRAY '(' static_array_pair_list ')'
3770 // | static_class_constant
3771 if (common_scalar()) {
3775 case TokenNameIdentifier:
3777 // static_class_constant:
3778 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3779 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3781 if (token == TokenNameIdentifier) {
3784 throwSyntaxError("Identifier expected after '::' operator.");
3788 case TokenNameEncapsedString0:
3790 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3791 while (scanner.currentCharacter != '`') {
3792 if (scanner.currentCharacter == '\\') {
3793 scanner.currentPosition++;
3795 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3798 } catch (IndexOutOfBoundsException e) {
3799 throwSyntaxError("'`' expected at end of static string.");
3802 case TokenNameEncapsedString1:
3804 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3805 while (scanner.currentCharacter != '\'') {
3806 if (scanner.currentCharacter == '\\') {
3807 scanner.currentPosition++;
3809 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3812 } catch (IndexOutOfBoundsException e) {
3813 throwSyntaxError("'\'' expected at end of static string.");
3816 case TokenNameEncapsedString2:
3818 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3819 while (scanner.currentCharacter != '"') {
3820 if (scanner.currentCharacter == '\\') {
3821 scanner.currentPosition++;
3823 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3826 } catch (IndexOutOfBoundsException e) {
3827 throwSyntaxError("'\"' expected at end of static string.");
3834 case TokenNameMINUS:
3838 case TokenNamearray:
3840 if (token != TokenNameLPAREN) {
3841 throwSyntaxError("'(' expected after keyword 'array'");
3844 if (token == TokenNameRPAREN) {
3848 non_empty_static_array_pair_list();
3849 if (token != TokenNameRPAREN) {
3850 throwSyntaxError("')' or ',' expected after keyword 'array'");
3854 // case TokenNamenull :
3857 // case TokenNamefalse :
3860 // case TokenNametrue :
3864 throwSyntaxError("Static scalar/constant expected.");
3868 private void non_empty_static_array_pair_list() {
3869 // non_empty_static_array_pair_list:
3870 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3872 //| non_empty_static_array_pair_list ',' static_scalar
3873 //| static_scalar T_DOUBLE_ARROW static_scalar
3877 if (token == TokenNameEQUAL_GREATER) {
3881 if (token != TokenNameCOMMA) {
3885 if (token == TokenNameRPAREN) {
3891 public void reportSyntaxError() { //int act, int currentKind, int
3893 /* remember current scanner position */
3894 int startPos = scanner.startPosition;
3895 int currentPos = scanner.currentPosition;
3896 // String[] expectings;
3897 // String tokenName = name[symbol_index[currentKind]];
3898 //fetch all "accurate" possible terminals that could recover the error
3899 // int start, end = start = asi(stack[stateStackTop]);
3900 // while (asr[end] != 0)
3902 // int length = end - start;
3903 // expectings = new String[length];
3904 // if (length != 0) {
3905 // char[] indexes = new char[length];
3906 // System.arraycopy(asr, start, indexes, 0, length);
3907 // for (int i = 0; i < length; i++) {
3908 // expectings[i] = name[symbol_index[indexes[i]]];
3911 //if the pb is an EOF, try to tell the user that they are some
3912 // if (tokenName.equals(UNEXPECTED_EOF)) {
3913 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3914 // char[] tokenSource;
3916 // tokenSource = this.scanner.getCurrentTokenSource();
3917 // } catch (Exception e) {
3918 // tokenSource = new char[] {};
3920 // problemReporter().parseError(
3921 // this.scanner.startPosition,
3922 // this.scanner.currentPosition - 1,
3927 // } else { //the next test is HEAVILY grammar DEPENDENT.
3928 // if ((length == 14)
3929 // && (expectings[0] == "=") //$NON-NLS-1$
3930 // && (expectings[1] == "*=") //$NON-NLS-1$
3931 // && (expressionPtr > -1)) {
3932 // switch(currentKind) {
3933 // case TokenNameSEMICOLON:
3934 // case TokenNamePLUS:
3935 // case TokenNameMINUS:
3936 // case TokenNameDIVIDE:
3937 // case TokenNameREMAINDER:
3938 // case TokenNameMULTIPLY:
3939 // case TokenNameLEFT_SHIFT:
3940 // case TokenNameRIGHT_SHIFT:
3941 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3942 // case TokenNameLESS:
3943 // case TokenNameGREATER:
3944 // case TokenNameLESS_EQUAL:
3945 // case TokenNameGREATER_EQUAL:
3946 // case TokenNameEQUAL_EQUAL:
3947 // case TokenNameNOT_EQUAL:
3948 // case TokenNameXOR:
3949 // case TokenNameAND:
3950 // case TokenNameOR:
3951 // case TokenNameOR_OR:
3952 // case TokenNameAND_AND:
3953 // // the ; is not the expected token ==> it ends a statement when an
3954 // expression is not ended
3955 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3957 // case TokenNameRBRACE :
3958 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3961 // char[] tokenSource;
3963 // tokenSource = this.scanner.getCurrentTokenSource();
3964 // } catch (Exception e) {
3965 // tokenSource = new char[] {};
3967 // problemReporter().parseError(
3968 // this.scanner.startPosition,
3969 // this.scanner.currentPosition - 1,
3973 // this.checkAndReportBracketAnomalies(problemReporter());
3978 tokenSource = this.scanner.getCurrentTokenSource();
3979 } catch (Exception e) {
3980 tokenSource = new char[] {};
3982 // problemReporter().parseError(
3983 // this.scanner.startPosition,
3984 // this.scanner.currentPosition - 1,
3988 this.checkAndReportBracketAnomalies(problemReporter());
3991 /* reset scanner where it was */
3992 scanner.startPosition = startPos;
3993 scanner.currentPosition = currentPos;
3996 public static final int RoundBracket = 0;
3998 public static final int SquareBracket = 1;
4000 public static final int CurlyBracket = 2;
4002 public static final int BracketKinds = 3;
4004 protected int[] nestedMethod; //the ptr is nestedType
4006 protected int nestedType, dimensions;
4008 //variable set stack
4009 final static int VariableStackIncrement = 10;
4011 HashMap fTypeVariables = null;
4013 HashMap fMethodVariables = null;
4015 Stack fStackUnassigned = new Stack();
4018 final static int AstStackIncrement = 100;
4020 protected int astPtr;
4022 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4024 protected int astLengthPtr;
4026 protected int[] astLengthStack;
4028 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4030 public CompilationUnitDeclaration compilationUnit; /*
4031 * the result from parse()
4034 protected ReferenceContext referenceContext;
4036 protected ProblemReporter problemReporter;
4038 protected CompilerOptions options;
4040 private ArrayList includesList;
4042 // protected CompilationResult compilationResult;
4044 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
4045 * reported, so initializes the compilation result's line positions.
4047 public ProblemReporter problemReporter() {
4048 if (scanner.recordLineSeparator) {
4049 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4051 problemReporter.referenceContext = referenceContext;
4052 return problemReporter;
4056 * Reconsider the entire source looking for inconsistencies in {} () []
4058 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
4059 scanner.wasAcr = false;
4060 boolean anomaliesDetected = false;
4062 char[] source = scanner.source;
4063 int[] leftCount = { 0, 0, 0 };
4064 int[] rightCount = { 0, 0, 0 };
4065 int[] depths = { 0, 0, 0 };
4066 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
4067 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4068 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
4069 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
4070 scanner.currentPosition = scanner.initialPosition; //starting
4072 // (first-zero-based
4074 while (scanner.currentPosition < scanner.eofPosition) { //loop for
4079 // ---------Consume white space and handles
4080 // startPosition---------
4081 boolean isWhiteSpace;
4083 scanner.startPosition = scanner.currentPosition;
4084 // if (((scanner.currentCharacter =
4085 // source[scanner.currentPosition++]) == '\\') &&
4086 // (source[scanner.currentPosition] == 'u')) {
4087 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4089 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4090 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4091 // only record line positions we have not
4093 scanner.pushLineSeparator();
4096 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4098 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4099 // -------consume token until } is found---------
4100 switch (scanner.currentCharacter) {
4102 int index = leftCount[CurlyBracket]++;
4103 if (index == leftPositions[CurlyBracket].length) {
4104 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4105 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
4107 leftPositions[CurlyBracket][index] = scanner.startPosition;
4108 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4112 int index = rightCount[CurlyBracket]++;
4113 if (index == rightPositions[CurlyBracket].length) {
4114 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4115 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
4117 rightPositions[CurlyBracket][index] = scanner.startPosition;
4118 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4122 int index = leftCount[RoundBracket]++;
4123 if (index == leftPositions[RoundBracket].length) {
4124 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4125 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
4127 leftPositions[RoundBracket][index] = scanner.startPosition;
4128 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4132 int index = rightCount[RoundBracket]++;
4133 if (index == rightPositions[RoundBracket].length) {
4134 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4135 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
4137 rightPositions[RoundBracket][index] = scanner.startPosition;
4138 rightDepths[RoundBracket][index] = --depths[RoundBracket];
4142 int index = leftCount[SquareBracket]++;
4143 if (index == leftPositions[SquareBracket].length) {
4144 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4145 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
4147 leftPositions[SquareBracket][index] = scanner.startPosition;
4148 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4152 int index = rightCount[SquareBracket]++;
4153 if (index == rightPositions[SquareBracket].length) {
4154 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4155 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
4157 rightPositions[SquareBracket][index] = scanner.startPosition;
4158 rightDepths[SquareBracket][index] = --depths[SquareBracket];
4162 if (scanner.getNextChar('\\')) {
4163 scanner.scanEscapeCharacter();
4164 } else { // consume next character
4165 scanner.unicodeAsBackSlash = false;
4166 // if (((scanner.currentCharacter =
4167 // source[scanner.currentPosition++]) ==
4169 // (source[scanner.currentPosition] ==
4171 // scanner.getNextUnicodeChar();
4173 if (scanner.withoutUnicodePtr != 0) {
4174 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4178 scanner.getNextChar('\'');
4182 // consume next character
4183 scanner.unicodeAsBackSlash = false;
4184 // if (((scanner.currentCharacter =
4185 // source[scanner.currentPosition++]) == '\\') &&
4186 // (source[scanner.currentPosition] == 'u')) {
4187 // scanner.getNextUnicodeChar();
4189 if (scanner.withoutUnicodePtr != 0) {
4190 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4193 while (scanner.currentCharacter != '"') {
4194 if (scanner.currentCharacter == '\r') {
4195 if (source[scanner.currentPosition] == '\n')
4196 scanner.currentPosition++;
4197 break; // the string cannot go further that
4200 if (scanner.currentCharacter == '\n') {
4201 break; // the string cannot go further that
4204 if (scanner.currentCharacter == '\\') {
4205 scanner.scanEscapeCharacter();
4207 // consume next character
4208 scanner.unicodeAsBackSlash = false;
4209 // if (((scanner.currentCharacter =
4210 // source[scanner.currentPosition++]) == '\\')
4211 // && (source[scanner.currentPosition] == 'u'))
4213 // scanner.getNextUnicodeChar();
4215 if (scanner.withoutUnicodePtr != 0) {
4216 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4223 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4226 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4227 && (source[scanner.currentPosition] == 'u')) {
4228 //-------------unicode traitement
4230 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4231 scanner.currentPosition++;
4232 while (source[scanner.currentPosition] == 'u') {
4233 scanner.currentPosition++;
4235 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4236 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4237 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4238 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4242 scanner.currentCharacter = 'A';
4243 } //something different from \n and \r
4245 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4248 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
4250 scanner.startPosition = scanner.currentPosition;
4251 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4252 && (source[scanner.currentPosition] == 'u')) {
4253 //-------------unicode traitement
4255 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4256 scanner.currentPosition++;
4257 while (source[scanner.currentPosition] == 'u') {
4258 scanner.currentPosition++;
4260 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4261 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4262 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4263 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4267 scanner.currentCharacter = 'A';
4268 } //something different from \n
4271 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4275 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4276 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4277 // only record line positions we
4278 // have not recorded yet
4279 scanner.pushLineSeparator();
4280 if (this.scanner.taskTags != null) {
4281 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4282 .getCurrentTokenEndPosition());
4288 if (test > 0) { //traditional and annotation
4290 boolean star = false;
4291 // consume next character
4292 scanner.unicodeAsBackSlash = false;
4293 // if (((scanner.currentCharacter =
4294 // source[scanner.currentPosition++]) ==
4296 // (source[scanner.currentPosition] ==
4298 // scanner.getNextUnicodeChar();
4300 if (scanner.withoutUnicodePtr != 0) {
4301 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4304 if (scanner.currentCharacter == '*') {
4308 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4309 && (source[scanner.currentPosition] == 'u')) {
4310 //-------------unicode traitement
4312 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4313 scanner.currentPosition++;
4314 while (source[scanner.currentPosition] == 'u') {
4315 scanner.currentPosition++;
4317 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4318 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4319 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4320 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4324 scanner.currentCharacter = 'A';
4325 } //something different from * and /
4327 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4330 //loop until end of comment */
4331 while ((scanner.currentCharacter != '/') || (!star)) {
4332 star = scanner.currentCharacter == '*';
4334 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4335 && (source[scanner.currentPosition] == 'u')) {
4336 //-------------unicode traitement
4338 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4339 scanner.currentPosition++;
4340 while (source[scanner.currentPosition] == 'u') {
4341 scanner.currentPosition++;
4343 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4344 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4345 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4346 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4350 scanner.currentCharacter = 'A';
4351 } //something different from * and
4354 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4358 if (this.scanner.taskTags != null) {
4359 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4366 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4367 scanner.scanIdentifierOrKeyword(false);
4370 if (Character.isDigit(scanner.currentCharacter)) {
4371 scanner.scanNumber(false);
4375 //-----------------end switch while
4376 // try--------------------
4377 } catch (IndexOutOfBoundsException e) {
4378 break; // read until EOF
4379 } catch (InvalidInputException e) {
4380 return false; // no clue
4383 if (scanner.recordLineSeparator) {
4384 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4386 // check placement anomalies against other kinds of brackets
4387 for (int kind = 0; kind < BracketKinds; kind++) {
4388 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4389 int start = leftPositions[kind][leftIndex]; // deepest
4391 // find matching closing bracket
4392 int depth = leftDepths[kind][leftIndex];
4394 for (int i = 0; i < rightCount[kind]; i++) {
4395 int pos = rightPositions[kind][i];
4396 // want matching bracket further in source with same
4398 if ((pos > start) && (depth == rightDepths[kind][i])) {
4403 if (end < 0) { // did not find a good closing match
4404 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4407 // check if even number of opening/closing other brackets
4408 // in between this pair of brackets
4410 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4411 for (int i = 0; i < leftCount[otherKind]; i++) {
4412 int pos = leftPositions[otherKind][i];
4413 if ((pos > start) && (pos < end))
4416 for (int i = 0; i < rightCount[otherKind]; i++) {
4417 int pos = rightPositions[otherKind][i];
4418 if ((pos > start) && (pos < end))
4422 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4428 // too many opening brackets ?
4429 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4430 anomaliesDetected = true;
4431 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4432 compilationUnit.compilationResult);
4434 // too many closing brackets ?
4435 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4436 anomaliesDetected = true;
4437 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4439 if (anomaliesDetected)
4442 return anomaliesDetected;
4443 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4444 return anomaliesDetected;
4445 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4446 return anomaliesDetected;
4450 protected void pushOnAstLengthStack(int pos) {
4452 astLengthStack[++astLengthPtr] = pos;
4453 } catch (IndexOutOfBoundsException e) {
4454 int oldStackLength = astLengthStack.length;
4455 int[] oldPos = astLengthStack;
4456 astLengthStack = new int[oldStackLength + StackIncrement];
4457 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4458 astLengthStack[astLengthPtr] = pos;
4462 protected void pushOnAstStack(ASTNode node) {
4464 * add a new obj on top of the ast stack
4467 astStack[++astPtr] = node;
4468 } catch (IndexOutOfBoundsException e) {
4469 int oldStackLength = astStack.length;
4470 ASTNode[] oldStack = astStack;
4471 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4472 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4473 astPtr = oldStackLength;
4474 astStack[astPtr] = node;
4477 astLengthStack[++astLengthPtr] = 1;
4478 } catch (IndexOutOfBoundsException e) {
4479 int oldStackLength = astLengthStack.length;
4480 int[] oldPos = astLengthStack;
4481 astLengthStack = new int[oldStackLength + AstStackIncrement];
4482 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4483 astLengthStack[astLengthPtr] = 1;
4487 protected void resetModifiers() {
4488 this.modifiers = AccDefault;
4489 this.modifiersSourceStart = -1; // <-- see comment into
4490 // modifiersFlag(int)
4491 this.scanner.commentPtr = -1;
4494 protected void consumePackageDeclarationName(IFile file) {
4495 // create a package name similar to java package names
4496 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4497 String filePath = file.getRawLocation().toString();
4498 String ext = file.getRawLocation().getFileExtension();
4499 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4500 ImportReference impt;
4503 if (filePath.startsWith(projectPath)) {
4504 tokens = CharOperation
4505 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4507 String name = file.getName();
4508 tokens = new char[1][];
4509 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4512 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4514 impt.declarationSourceStart = 0;
4515 impt.declarationSourceEnd = 0;
4516 impt.declarationEnd = 0;
4517 //endPosition is just before the ;
4521 public final static String[] GLOBALS = {
4536 private void pushVariableSet() {
4537 HashSet set =new HashSet();
4538 for (int i = 0; i < GLOBALS.length; i++) {
4539 set.add(GLOBALS[i]);
4541 fStackUnassigned.push(set);
4545 * Returns the <i>set of assigned variables </i> returns null if no Set is defined at the current scanner position
4547 private HashSet peekVariableSet() {
4548 if (!fStackUnassigned.isEmpty()) {
4549 return (HashSet) fStackUnassigned.peek();
4555 * add the current identifier source to the <i>set of assigned variables </i>
4559 private void addVariableSet(HashSet set) {
4561 set.add(new String(scanner.getCurrentTokenSource()));
4566 * add the current identifier source to the <i>set of assigned variables </i>
4569 private void addVariableSet() {
4570 HashSet set = peekVariableSet();
4572 set.add(new String(scanner.getCurrentTokenSource()));
4577 * add the current identifier source to the <i>set of assigned variables </i>
4580 private void addVariableSet(char[] token) {
4581 HashSet set = peekVariableSet();
4583 set.add(new String(token));
4588 * check if the current identifier source is in the <i>set of assigned variables </i> Returns true, if no set is defined for the
4589 * current scanner position
4592 private boolean containsVariableSet() {
4593 HashSet set = peekVariableSet();
4595 return set.contains(new String(scanner.getCurrentTokenSource()));