1 /***********************************************************************************************************************************
2 * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3 * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols.TokenName;
18 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
19 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
20 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
21 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
22 import net.sourceforge.phpdt.internal.compiler.ast.Block;
23 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
24 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
25 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
26 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
27 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
28 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
29 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
30 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
31 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
32 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
33 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
34 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
35 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
36 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
37 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
38 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
39 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
40 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
41 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
42 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
43 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
44 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
45 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
46 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
47 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
48 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
49 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
50 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
51 import net.sourceforge.phpdt.internal.compiler.util.Util;
52 import net.sourceforge.phpdt.internal.core.util.PHPFileUtil;
53 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
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,
62 ParserBasicInformation {
63 protected final static int StackIncrement = 255;
65 protected int stateStackTop;
67 // protected int[] stack = new int[StackIncrement];
69 public TokenName firstToken; // handle for multiple parsing goals
71 public int lastAct; // handle for multiple parsing goals
73 // protected RecoveredElement currentElement;
75 public static boolean VERBOSE_RECOVERY = false;
77 protected boolean diet = false; // tells the scanner to jump over some
80 * the PHP token scanner
82 public Scanner scanner;
86 protected int modifiers;
88 protected int modifiersSourceStart;
90 protected Parser(ProblemReporter problemReporter) {
91 this.problemReporter = problemReporter;
92 this.options = problemReporter.options;
93 this.token = TokenName.EOF;
94 this.initializeScanner();
97 // public void setFileToParse(IFile fileToParse) {
98 // this.token = TokenName.EOF;
99 // this.initializeScanner();
103 * ClassDeclaration Constructor.
107 * Description of Parameter
110 // public Parser(IFile fileToParse) {
111 // // if (keywordMap == null) {
112 // // keywordMap = new HashMap();
113 // // for (int i = 0; i < PHP_KEYWORS.length; i++) {
114 // // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
117 // // this.currentPHPString = 0;
118 // // PHPParserSuperclass.fileToParse = fileToParse;
119 // // this.phpList = null;
120 // this.includesList = null;
122 // this.token = TokenName.EOF;
123 // // this.chIndx = 0;
124 // // this.rowCount = 1;
125 // // this.columnCount = 0;
126 // // this.phpEnd = false;
127 // // getNextToken();
128 // this.initializeScanner();
131 public void initializeScanner() {
132 this.scanner = new Scanner(
134 false /* whitespace */,
135 this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */,
136 false, false, this.options.taskTags/* taskTags */,
137 this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
141 * Create marker for the parse error
143 // private void setMarker(String message, int charStart, int charEnd, int
145 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
148 * This method will throw the SyntaxError. It will add the good lines and
149 * columns to the Error
153 * @throws SyntaxError
156 private void throwSyntaxError(String error) {
157 int problemStartPosition = scanner.getCurrentTokenStartPosition();
158 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
159 if (scanner.source.length <= problemEndPosition
160 && problemEndPosition > 0) {
161 problemEndPosition = scanner.source.length - 1;
162 if (problemStartPosition > 0
163 && problemStartPosition >= problemEndPosition
164 && problemEndPosition > 0) {
165 problemStartPosition = problemEndPosition - 1;
168 throwSyntaxError(error, problemStartPosition, problemEndPosition);
172 * This method will throw the SyntaxError. It will add the good lines and
173 * columns to the Error
177 * @throws SyntaxError
180 // private void throwSyntaxError(String error, int startRow) {
181 // throw new SyntaxError(startRow, 0, " ", error);
183 private void throwSyntaxError(String error, int problemStartPosition,
184 int problemEndPosition) {
185 if (referenceContext != null) {
186 problemReporter.phpParsingError(new String[] { error },
187 problemStartPosition, problemEndPosition, referenceContext,
188 compilationUnit.compilationResult);
190 throw new SyntaxError(1, 0, " ", error);
193 private void reportSyntaxError(String error) {
194 int problemStartPosition = scanner.getCurrentTokenStartPosition();
195 int problemEndPosition = scanner.getCurrentTokenEndPosition();
196 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
199 private void reportSyntaxError(String error, int problemStartPosition,
200 int problemEndPosition) {
201 if (referenceContext != null) {
202 problemReporter.phpParsingError(new String[] { error },
203 problemStartPosition, problemEndPosition, referenceContext,
204 compilationUnit.compilationResult);
208 // private void reportSyntaxWarning(String error, int problemStartPosition,
209 // int problemEndPosition) {
210 // if (referenceContext != null) {
211 // problemReporter.phpParsingWarning(new String[] { error },
212 // problemStartPosition, problemEndPosition, referenceContext,
213 // compilationUnit.compilationResult);
218 * Read the next token from input
220 private void getNextToken() {
222 token = scanner.getNextToken();
224 int currentEndPosition = scanner.getCurrentTokenEndPosition();
225 int currentStartPosition = scanner.getCurrentTokenStartPosition();
227 System.out.print ("getNextToken: from " + currentStartPosition + " to " + currentEndPosition + ": ");
228 System.out.println(scanner.toStringAction(token));
230 } catch (InvalidInputException e) {
231 token = TokenName.ERROR;
232 String detailedMessage = e.getMessage();
234 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
235 throwSyntaxError("Unterminated string.");
236 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
237 throwSyntaxError("Unterminated commment.");
243 public void init(String s) {
245 this.token = TokenName.EOF;
246 this.includesList = new ArrayList();
248 // this.rowCount = 1;
249 // this.columnCount = 0;
250 // this.phpEnd = false;
251 // this.phpMode = false;
252 /* scanner initialization */
253 scanner.setSource(s.toCharArray());
254 scanner.setPHPMode(false);
258 protected void initialize(boolean phpMode) {
259 initialize(phpMode, null);
262 protected void initialize(boolean phpMode,
263 IdentifierIndexManager indexManager) {
264 compilationUnit = null;
265 referenceContext = null;
266 this.includesList = new ArrayList();
267 // this.indexManager = indexManager;
269 this.token = TokenName.EOF;
271 // this.rowCount = 1;
272 // this.columnCount = 0;
273 // this.phpEnd = false;
274 // this.phpMode = phpMode;
275 scanner.setPHPMode(phpMode);
280 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
283 public void parse(String s) {
288 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
291 public void parse(String s, HashMap variables) {
292 fMethodVariables = variables;
293 fStackUnassigned = new ArrayList();
299 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
302 * The main entry point when parsing a file
304 protected void parse() {
305 if (scanner.compilationUnit != null) {
306 IResource resource = scanner.compilationUnit.getResource();
307 if (resource != null && resource instanceof IFile) {
308 // set the package name
309 consumePackageDeclarationName((IFile) resource);
317 if (token != TokenName.EOF && // If we are not at the end of file
318 token != TokenName.ERROR) { // and have no error
319 statementList(); // build the statement list for the entire file
322 if (token != TokenName.EOF) {
325 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
329 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
333 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
337 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
341 throwSyntaxError("Read character '('; end-of-file not reached.");
345 throwSyntaxError("Read character '{'; end-of-file not reached.");
349 throwSyntaxError("Read character '['; end-of-file not reached.");
353 throwSyntaxError("End-of-file not reached.");
358 } catch (SyntaxError syntaxError) {
359 // syntaxError.printStackTrace();
368 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
371 public void parseFunction(String s, HashMap variables) {
373 scanner.phpMode = true;
374 parseFunction(variables);
378 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
381 protected void parseFunction(HashMap variables) {
383 boolean hasModifiers = member_modifiers();
384 if (token == TokenName.FUNCTION) {
386 checkAndSetModifiers(AccPublic);
388 this.fMethodVariables = variables;
390 MethodDeclaration methodDecl = new MethodDeclaration(null);
391 methodDecl.declarationSourceStart = scanner
392 .getCurrentTokenStartPosition();
393 methodDecl.modifiers = this.modifiers;
394 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
397 functionDefinition(methodDecl);
398 } catch (SyntaxError sytaxErr1) {
401 int sourceEnd = methodDecl.sourceEnd;
403 || methodDecl.declarationSourceStart > sourceEnd) {
404 sourceEnd = methodDecl.declarationSourceStart + 1;
406 methodDecl.sourceEnd = sourceEnd;
407 methodDecl.declarationSourceEnd = sourceEnd;
412 protected CompilationUnitDeclaration endParse(int act) {
416 // if (currentElement != null) {
417 // currentElement.topElement().updateParseTree();
418 // if (VERBOSE_RECOVERY) {
419 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
420 // System.out.println("--------------------------"); //$NON-NLS-1$
421 // System.out.println(compilationUnit);
422 // System.out.println("----------------------------------");
426 if (diet & VERBOSE_RECOVERY) {
427 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
428 System.out.println("--------------------------"); //$NON-NLS-1$
429 System.out.println(compilationUnit);
430 System.out.println("----------------------------------"); //$NON-NLS-1$
433 if (scanner.recordLineSeparator) {
434 compilationUnit.compilationResult.lineSeparatorPositions = scanner
437 if (scanner.taskTags != null) {
438 for (int i = 0; i < scanner.foundTaskCount; i++) {
439 problemReporter().task(
440 new String(scanner.foundTaskTags[i]),
441 new String(scanner.foundTaskMessages[i]),
442 scanner.foundTaskPriorities[i] == null ? null
443 : new String(scanner.foundTaskPriorities[i]),
444 scanner.foundTaskPositions[i][0],
445 scanner.foundTaskPositions[i][1]);
448 compilationUnit.imports = new ImportReference[includesList.size()];
449 for (int i = 0; i < includesList.size(); i++) {
450 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
452 return compilationUnit;
457 * @return A block object which contains all statements from within the current block
459 private Block statementList() {
460 boolean branchStatement = false;
461 int blockStart = scanner.getCurrentTokenStartPosition();
462 ArrayList blockStatements = new ArrayList();
467 statement = statement();
469 if (statement != null) {
470 blockStatements.add(statement);
473 if (token == TokenName.EOF) {
477 if (branchStatement && statement != null) {
478 // reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
479 if (!(statement instanceof BreakStatement)) {
481 * Don't give an error for break statement following return statement.
482 * Technically it's unreachable code, but in switch-case it's recommended to avoid
483 * accidental fall-through later when editing the code
485 problemReporter.unreachableCode (new String (scanner.getCurrentIdentifierSource ()),
486 statement.sourceStart,
489 compilationUnit.compilationResult);
507 return createBlock (blockStart, blockStatements); // Create and return a block object (contains all the statements from the current read block)
510 branchStatement = checkUnreachableStatements(statement);
512 catch (SyntaxError sytaxErr1) {
513 // If an error occurred, try to find keywords
514 // to parse the rest of the string
515 boolean tokenize = scanner.tokenizeStrings;
518 scanner.tokenizeStrings = true;
522 boolean bBreakLoop = false;
524 while (token != TokenName.EOF) { // As long as we are not at the end of file
525 switch (token) { // If a block close?
539 return createBlock (blockStart, blockStatements); // Create and return a block object (contains all the statements from the current read block)
576 // System.out.println(scanner.toStringAction(token));
578 // System.out.println(scanner.toStringAction(token));
581 if (token == TokenName.EOF) {
585 scanner.tokenizeStrings = tokenize;
595 private boolean checkUnreachableStatements(Statement statement) {
596 if (statement instanceof ReturnStatement ||
597 statement instanceof ContinueStatement ||
598 statement instanceof BreakStatement) {
600 } else if (statement instanceof IfStatement
601 && ((IfStatement) statement).checkUnreachable) {
609 * @param blockStatements
612 private Block createBlock (int blockStart, ArrayList blockStatements) {
613 int blockEnd = scanner.getCurrentTokenEndPosition ();
614 Block b = Block.EmptyWith (blockStart, blockEnd);
616 b.statements = new Statement[blockStatements.size()];
617 blockStatements.toArray (b.statements);
622 private void functionBody(MethodDeclaration methodDecl) {
623 // '{' [statement-list] '}'
624 if (token == TokenName.LBRACE) {
627 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
628 throwSyntaxError("'{' expected in compound-statement.");
631 if (token != TokenName.RBRACE) {
635 if (token == TokenName.RBRACE) {
636 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
639 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
640 throwSyntaxError("'}' expected in compound-statement.");
645 * Try to create an statement reading from the current token position
647 * @return Returns a found statement or empty statement
649 private Statement statement() {
650 Statement statement = null;
651 Expression expression;
652 int sourceStart = scanner.getCurrentTokenStartPosition();
657 // T_IF '(' expr ')' statement elseif_list else_single
658 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
659 // new_else_single T_ENDIF ';'
661 if (token == TokenName.LPAREN) {
664 throwSyntaxError("'(' expected after 'if' keyword.");
669 if (token == TokenName.RPAREN) {
672 throwSyntaxError("')' expected after 'if' condition.");
674 // create basic IfStatement
675 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
677 if (token == TokenName.COLON) {
679 ifStatementColon(ifStatement);
681 ifStatement(ifStatement);
687 if (token == TokenName.LPAREN) {
690 throwSyntaxError("'(' expected after 'switch' keyword.");
693 if (token == TokenName.RPAREN) {
696 throwSyntaxError("')' expected after 'switch' condition.");
703 if (token == TokenName.LPAREN) {
706 throwSyntaxError("'(' expected after 'for' keyword.");
708 if (token == TokenName.SEMICOLON) {
712 if (token == TokenName.SEMICOLON) {
715 throwSyntaxError("';' expected after 'for'.");
718 if (token == TokenName.SEMICOLON) {
722 if (token == TokenName.SEMICOLON) {
725 throwSyntaxError("';' expected after 'for'.");
728 if (token == TokenName.RPAREN) {
732 if (token == TokenName.RPAREN) {
735 throwSyntaxError("')' expected after 'for'.");
743 if (token == TokenName.LPAREN) {
746 throwSyntaxError("'(' expected after 'while' keyword.");
749 if (token == TokenName.RPAREN) {
752 throwSyntaxError("')' expected after 'while' condition.");
759 if (token == TokenName.LBRACE) {
761 if (token != TokenName.RBRACE) {
764 if (token == TokenName.RBRACE) {
767 throwSyntaxError("'}' expected after 'do' keyword.");
772 if (token == TokenName.WHILE) {
774 if (token == TokenName.LPAREN) {
777 throwSyntaxError("'(' expected after 'while' keyword.");
780 if (token == TokenName.RPAREN) {
783 throwSyntaxError("')' expected after 'while' condition.");
786 throwSyntaxError("'while' expected after 'do' keyword.");
788 if (token == TokenName.SEMICOLON) {
791 if (token != TokenName.INLINE_HTML) {
792 throwSyntaxError("';' expected after do-while statement.");
800 if (token == TokenName.LPAREN) {
803 throwSyntaxError("'(' expected after 'foreach' keyword.");
806 if (token == TokenName.AS) {
809 throwSyntaxError("'as' expected after 'foreach' exxpression.");
813 foreach_optional_arg();
814 if (token == TokenName.EQUAL_GREATER) {
816 variable(false, false);
818 if (token == TokenName.RPAREN) {
821 throwSyntaxError("')' expected after 'foreach' expression.");
829 if (token != TokenName.SEMICOLON) {
832 if (token == TokenName.SEMICOLON) {
833 sourceEnd = scanner.getCurrentTokenEndPosition();
836 if (token != TokenName.INLINE_HTML) {
837 throwSyntaxError("';' expected after 'break'.");
839 sourceEnd = scanner.getCurrentTokenEndPosition();
842 return new BreakStatement(null, sourceStart, sourceEnd);
847 if (token != TokenName.SEMICOLON) {
850 if (token == TokenName.SEMICOLON) {
851 sourceEnd = scanner.getCurrentTokenEndPosition();
854 if (token != TokenName.INLINE_HTML) {
855 throwSyntaxError("';' expected after 'continue'.");
857 sourceEnd = scanner.getCurrentTokenEndPosition();
860 return new ContinueStatement(null, sourceStart, sourceEnd);
866 if (token == TokenName.VARIABLE) {
869 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
872 if (token != TokenName.IDENTIFIER) {
873 throwSyntaxError("identifier expected after '::'.");
881 if (token != TokenName.SEMICOLON) {
885 if (token == TokenName.SEMICOLON) {
886 sourceEnd = scanner.getCurrentTokenEndPosition();
890 if (token != TokenName.INLINE_HTML) {
891 throwSyntaxError("';' expected after 'return'.");
894 sourceEnd = scanner.getCurrentTokenEndPosition();
897 return new ReturnStatement(expression, sourceStart, sourceEnd);
900 getNextToken(); // Read the token after 'echo'
901 expressionList(); // Read everything after 'echo'
902 if (token == TokenName.SEMICOLON) {
905 if (token != TokenName.INLINE_HTML) {
906 throwSyntaxError("';' expected after 'echo' statement.");
910 return statement; // return null statement
913 // 0-length token directly after PHP short tag <?=
916 if (token == TokenName.SEMICOLON) {
918 // if (token != TokenName.INLINE_HTML) {
919 // // TODO should this become a configurable warning?
920 // reportSyntaxError("Probably '?>' expected after PHP short tag
921 // expression (only the first expression will be echoed).");
924 if (token != TokenName.INLINE_HTML) {
925 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
938 if (token == TokenName.SEMICOLON) {
941 if (token != TokenName.INLINE_HTML) {
942 throwSyntaxError("';' expected after 'global' statement.");
951 if (token == TokenName.SEMICOLON) {
954 if (token != TokenName.INLINE_HTML) {
955 throwSyntaxError("';' expected after 'static' statement.");
963 if (token == TokenName.LPAREN) {
966 throwSyntaxError("'(' expected after 'unset' statement.");
969 if (token == TokenName.RPAREN) {
972 throwSyntaxError("')' expected after 'unset' statement.");
974 if (token == TokenName.SEMICOLON) {
977 if (token != TokenName.INLINE_HTML) {
978 throwSyntaxError("';' expected after 'unset' statement.");
988 if (token == TokenName.SEMICOLON) { // After the namespace identifier there is a ';'
991 else if (token == TokenName.LBRACE) { // or a '{'
992 getNextToken(); // set to next token
994 if (token != TokenName.RBRACE) { // if next token is not a '}'
995 statementList(); // read the entire block
998 if (token == TokenName.RBRACE) { // If the end is a '}'
999 getNextToken(); // go for the next token
1001 else { // Not a '}' as expected
1002 throwSyntaxError("'}' expected after 'do' keyword.");
1006 if (token != TokenName.INLINE_HTML) {
1007 throwSyntaxError("';' expected after 'namespace' statement.");
1014 getNextToken (); // This should get the label
1016 if (token == TokenName.IDENTIFIER) {
1020 throwSyntaxError("expected a label after goto");
1023 if (token == TokenName.SEMICOLON) { // After the 'goto' label name there is a ';'
1027 throwSyntaxError("expected a ';' after goto label");
1032 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
1033 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1034 methodDecl.modifiers = AccDefault;
1035 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
1038 functionDefinition(methodDecl);
1040 sourceEnd = methodDecl.sourceEnd;
1041 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1042 sourceEnd = methodDecl.declarationSourceStart + 1;
1044 methodDecl.declarationSourceEnd = sourceEnd;
1045 methodDecl.sourceEnd = sourceEnd;
1050 // T_DECLARE '(' declare_list ')' declare_statement
1052 if (token != TokenName.LPAREN) {
1053 throwSyntaxError("'(' expected in 'declare' statement.");
1057 if (token != TokenName.RPAREN) {
1058 throwSyntaxError("')' expected in 'declare' statement.");
1061 declare_statement();
1066 if (token != TokenName.LBRACE) {
1067 throwSyntaxError("'{' expected in 'try' statement.");
1072 if (token != TokenName.RBRACE) { // Process the statement only if there is (possibly) a statement
1075 if (token != TokenName.RBRACE) {
1076 throwSyntaxError("'}' expected in 'try' statement.");
1085 if (token != TokenName.LPAREN) {
1086 throwSyntaxError("'(' expected in 'catch' statement.");
1089 fully_qualified_class_name();
1090 if (token != TokenName.VARIABLE) {
1091 throwSyntaxError("Variable expected in 'catch' statement.");
1095 if (token != TokenName.RPAREN) {
1096 throwSyntaxError("')' expected in 'catch' statement.");
1099 if (token != TokenName.LBRACE) {
1100 throwSyntaxError("'{' expected in 'catch' statement.");
1103 if (token != TokenName.RBRACE) {
1105 if (token != TokenName.RBRACE) {
1106 throwSyntaxError("'}' expected in 'catch' statement.");
1110 additional_catches();
1116 if (token == TokenName.SEMICOLON) {
1119 throwSyntaxError("';' expected after 'throw' exxpression.");
1128 TypeDeclaration typeDecl = new TypeDeclaration (this.compilationUnit.compilationResult);
1129 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1130 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1131 typeDecl.name = new char[] { ' ' };
1132 // default super class
1133 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
1134 compilationUnit.types.add(typeDecl);
1135 pushOnAstStack(typeDecl);
1136 unticked_class_declaration_statement(typeDecl);
1146 if (token != TokenName.RBRACE) {
1147 statement = statementList();
1149 if (token == TokenName.RBRACE) {
1153 throwSyntaxError("'}' expected.");
1158 if (token != TokenName.SEMICOLON) {
1162 if (token == TokenName.SEMICOLON) {
1166 else if (token == TokenName.COLON) { // Colon after Label identifier
1171 if (token == TokenName.RBRACE) {
1172 reportSyntaxError ("';' expected after expression (Found token: "
1173 + scanner.toStringAction(token) + ")");
1176 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
1179 if (token != TokenName.IDENTIFIER) {
1180 throwSyntaxError("identifier expected after '::'.");
1186 else if (token != TokenName.INLINE_HTML && token != TokenName.EOF) {
1187 throwSyntaxError ("';' expected after expression (Found token: "
1188 + scanner.toStringAction(token) + ")");
1199 private void declare_statement() {
1201 // | ':' inner_statement_list T_ENDDECLARE ';'
1203 if (token == TokenName.COLON) {
1205 // TODO: implement inner_statement_list();
1207 if (token != TokenName.ENDDECLARE) {
1208 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1211 if (token != TokenName.SEMICOLON) {
1212 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1220 private void declare_list() {
1221 // T_STRING '=' static_scalar
1222 // | declare_list ',' T_STRING '=' static_scalar
1224 if (token != TokenName.IDENTIFIER) {
1225 throwSyntaxError("Identifier expected in 'declare' list.");
1228 if (token != TokenName.EQUAL) {
1229 throwSyntaxError("'=' expected in 'declare' list.");
1233 if (token != TokenName.COMMA) {
1240 private void additional_catches() {
1241 while (token == TokenName.CATCH) {
1243 if (token != TokenName.LPAREN) {
1244 throwSyntaxError("'(' expected in 'catch' statement.");
1247 fully_qualified_class_name();
1248 if (token != TokenName.VARIABLE) {
1249 throwSyntaxError("Variable expected in 'catch' statement.");
1253 if (token != TokenName.RPAREN) {
1254 throwSyntaxError("')' expected in 'catch' statement.");
1257 if (token != TokenName.LBRACE) {
1258 throwSyntaxError("'{' expected in 'catch' statement.");
1261 if (token != TokenName.RBRACE) {
1264 if (token != TokenName.RBRACE) {
1265 throwSyntaxError("'}' expected in 'catch' statement.");
1271 private void foreach_variable() {
1274 if (token == TokenName.OP_AND) {
1280 private void foreach_optional_arg() {
1282 // | T_DOUBLE_ARROW foreach_variable
1283 if (token == TokenName.EQUAL_GREATER) {
1289 private void global_var_list() {
1291 // global_var_list ',' global_var
1293 HashSet set = peekVariableSet();
1296 if (token != TokenName.COMMA) {
1303 private void global_var(HashSet set) {
1307 // | '$' '{' expr '}'
1308 if (token == TokenName.VARIABLE) {
1309 if (fMethodVariables != null) {
1310 VariableInfo info = new VariableInfo(scanner
1311 .getCurrentTokenStartPosition(),
1312 VariableInfo.LEVEL_GLOBAL_VAR);
1313 fMethodVariables.put(new String(scanner
1314 .getCurrentIdentifierSource()), info);
1316 addVariableSet(set);
1318 } else if (token == TokenName.DOLLAR) {
1320 if (token == TokenName.LBRACE) {
1323 if (token != TokenName.RBRACE) {
1324 throwSyntaxError("'}' expected in global variable.");
1333 private void static_var_list() {
1335 // static_var_list ',' T_VARIABLE
1336 // | static_var_list ',' T_VARIABLE '=' static_scalar
1338 // | T_VARIABLE '=' static_scalar,
1339 HashSet set = peekVariableSet();
1341 if (token == TokenName.VARIABLE) {
1342 if (fMethodVariables != null) {
1343 VariableInfo info = new VariableInfo(scanner
1344 .getCurrentTokenStartPosition(),
1345 VariableInfo.LEVEL_STATIC_VAR);
1346 fMethodVariables.put(new String(scanner
1347 .getCurrentIdentifierSource()), info);
1349 addVariableSet(set);
1351 if (token == TokenName.EQUAL) {
1355 if (token != TokenName.COMMA) {
1365 private void unset_variables() {
1368 // | unset_variables ',' unset_variable
1372 variable(false, false);
1373 if (token != TokenName.COMMA) {
1380 private final void initializeModifiers() {
1382 this.modifiersSourceStart = -1;
1385 private final void checkAndSetModifiers(int flag) {
1386 this.modifiers |= flag;
1387 if (this.modifiersSourceStart < 0)
1388 this.modifiersSourceStart = this.scanner.startPosition;
1391 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1392 initializeModifiers();
1393 if (token == TokenName.INTERFACE) {
1394 // interface_entry T_STRING
1395 // interface_extends_list
1396 // '{' class_statement_list '}'
1397 checkAndSetModifiers(AccInterface);
1399 typeDecl.modifiers = this.modifiers;
1400 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1401 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1402 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1403 typeDecl.name = scanner.getCurrentIdentifierSource();
1404 if (token.compareTo (TokenName.KEYWORD) > 0) {
1405 problemReporter.phpKeywordWarning(new String[] { scanner
1406 .toStringAction(token) }, scanner
1407 .getCurrentTokenStartPosition(), scanner
1408 .getCurrentTokenEndPosition(), referenceContext,
1409 compilationUnit.compilationResult);
1410 // throwSyntaxError("Don't use a keyword for interface
1412 // + scanner.toStringAction(token) + "].",
1413 // typeDecl.sourceStart, typeDecl.sourceEnd);
1416 interface_extends_list(typeDecl);
1418 typeDecl.name = new char[] { ' ' };
1420 "Interface name expected after keyword 'interface'.",
1421 typeDecl.sourceStart, typeDecl.sourceEnd);
1425 // class_entry_type T_STRING extends_from
1427 // '{' class_statement_list'}'
1429 typeDecl.modifiers = this.modifiers;
1430 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1431 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1433 // identifier 'extends' identifier
1434 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1435 typeDecl.name = scanner.getCurrentIdentifierSource();
1436 if (token.compareTo (TokenName.KEYWORD) > 0) {
1437 problemReporter.phpKeywordWarning(new String[] { scanner
1438 .toStringAction(token) }, scanner
1439 .getCurrentTokenStartPosition(), scanner
1440 .getCurrentTokenEndPosition(), referenceContext,
1441 compilationUnit.compilationResult);
1442 // throwSyntaxError("Don't use a keyword for class
1444 // scanner.toStringAction(token) + "].",
1445 // typeDecl.sourceStart, typeDecl.sourceEnd);
1450 // | T_EXTENDS fully_qualified_class_name
1451 if (token == TokenName.EXTENDS) {
1452 class_extends_list(typeDecl);
1454 // if (token != TokenName.IDENTIFIER) {
1455 // throwSyntaxError("Class name expected after keyword
1457 // scanner.getCurrentTokenStartPosition(), scanner
1458 // .getCurrentTokenEndPosition());
1461 implements_list(typeDecl);
1463 typeDecl.name = new char[] { ' ' };
1464 throwSyntaxError("Class name expected after keyword 'class'.",
1465 typeDecl.sourceStart, typeDecl.sourceEnd);
1469 // '{' class_statement_list '}'
1470 if (token == TokenName.LBRACE) {
1472 if (token != TokenName.RBRACE) {
1473 ArrayList list = new ArrayList();
1474 class_statement_list(list);
1475 typeDecl.fields = new FieldDeclaration[list.size()];
1476 for (int i = 0; i < list.size(); i++) {
1477 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1480 if (token == TokenName.RBRACE) {
1481 typeDecl.declarationSourceEnd = scanner
1482 .getCurrentTokenEndPosition();
1485 throwSyntaxError("'}' expected at end of class body.");
1488 throwSyntaxError("'{' expected at start of class body.");
1492 private void class_entry_type() {
1494 // | T_ABSTRACT T_CLASS
1495 // | T_FINAL T_CLASS
1496 if (token == TokenName.CLASS) {
1498 } else if (token == TokenName.ABSTRACT) {
1499 checkAndSetModifiers(AccAbstract);
1501 if (token != TokenName.CLASS) {
1502 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1505 } else if (token == TokenName.FINAL) {
1506 checkAndSetModifiers(AccFinal);
1508 if (token != TokenName.CLASS) {
1509 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1513 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1517 // private void class_extends(TypeDeclaration typeDecl) {
1519 // // | T_EXTENDS interface_list
1520 // if (token == TokenName.EXTENDS) {
1523 // if (token == TokenName.IDENTIFIER) {
1526 // throwSyntaxError("Class name expected after keyword 'extends'.");
1531 private void interface_extends_list(TypeDeclaration typeDecl) {
1533 // | T_EXTENDS interface_list
1534 if (token == TokenName.EXTENDS) {
1536 interface_list(typeDecl);
1540 private void class_extends_list(TypeDeclaration typeDecl) {
1542 // | T_EXTENDS interface_list
1543 if (token == TokenName.EXTENDS) {
1545 class_list(typeDecl);
1549 private void implements_list(TypeDeclaration typeDecl) {
1551 // | T_IMPLEMENTS interface_list
1552 if (token == TokenName.IMPLEMENTS) {
1554 interface_list(typeDecl);
1558 private void class_list(TypeDeclaration typeDecl) {
1560 // fully_qualified_class_name
1562 if (token == TokenName.IDENTIFIER) {
1563 //char[] ident = scanner.getCurrentIdentifierSource();
1564 // TODO make this code working better:
1565 // SingleTypeReference ref =
1566 // ParserUtil.getTypeReference(scanner,
1567 // includesList, ident);
1568 // if (ref != null) {
1569 // typeDecl.superclass = ref;
1573 throwSyntaxError("Classname expected after keyword 'extends'.");
1575 if (token == TokenName.COMMA) {
1576 reportSyntaxError("No multiple inheritance allowed. Expected token 'implements' or '{'.");
1585 private void interface_list(TypeDeclaration typeDecl) {
1587 // fully_qualified_class_name
1588 // | interface_list ',' fully_qualified_class_name
1590 if (token == TokenName.IDENTIFIER) {
1593 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1595 if (token != TokenName.COMMA) {
1602 // private void classBody(TypeDeclaration typeDecl) {
1603 // //'{' [class-element-list] '}'
1604 // if (token == TokenName.LBRACE) {
1606 // if (token != TokenName.RBRACE) {
1607 // class_statement_list();
1609 // if (token == TokenName.RBRACE) {
1610 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1613 // throwSyntaxError("'}' expected at end of class body.");
1616 // throwSyntaxError("'{' expected at start of class body.");
1619 private void class_statement_list(ArrayList list) {
1622 class_statement(list);
1623 if (token == TokenName.PUBLIC ||
1624 token == TokenName.PROTECTED ||
1625 token == TokenName.PRIVATE ||
1626 token == TokenName.STATIC ||
1627 token == TokenName.ABSTRACT ||
1628 token == TokenName.FINAL ||
1629 token == TokenName.FUNCTION ||
1630 token == TokenName.VAR ||
1631 token == TokenName.CONST) {
1635 if (token == TokenName.RBRACE) {
1639 throwSyntaxError("'}' at end of class statement.");
1641 catch (SyntaxError sytaxErr1) {
1642 boolean tokenize = scanner.tokenizeStrings;
1645 scanner.tokenizeStrings = true;
1648 // if an error occured,
1649 // try to find keywords
1650 // to parse the rest of the string
1651 while (token != TokenName.EOF) {
1652 if (token == TokenName.PUBLIC ||
1653 token == TokenName.PROTECTED ||
1654 token == TokenName.PRIVATE ||
1655 token == TokenName.STATIC ||
1656 token == TokenName.ABSTRACT ||
1657 token == TokenName.FINAL ||
1658 token == TokenName.FUNCTION ||
1659 token == TokenName.VAR ||
1660 token == TokenName.CONST) {
1663 // System.out.println(scanner.toStringAction(token));
1666 if (token == TokenName.EOF) {
1670 scanner.tokenizeStrings = tokenize;
1679 private void class_statement(ArrayList list) {
1681 // variable_modifiers class_variable_declaration ';'
1682 // | class_constant_declaration ';'
1683 // | method_modifiers T_FUNCTION is_reference T_STRING
1684 // '(' parameter_list ')' method_body
1685 initializeModifiers();
1686 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1688 if (token == TokenName.VAR) {
1689 checkAndSetModifiers(AccPublic);
1690 problemReporter.phpVarDeprecatedWarning(scanner
1691 .getCurrentTokenStartPosition(), scanner
1692 .getCurrentTokenEndPosition(), referenceContext,
1693 compilationUnit.compilationResult);
1695 class_variable_declaration(declarationSourceStart, list);
1696 } else if (token == TokenName.CONST) {
1697 checkAndSetModifiers(AccFinal | AccPublic);
1698 class_constant_declaration(declarationSourceStart, list);
1699 if (token != TokenName.SEMICOLON) {
1700 throwSyntaxError("';' expected after class const declaration.");
1704 boolean hasModifiers = member_modifiers();
1705 if (token == TokenName.FUNCTION) {
1706 if (!hasModifiers) {
1707 checkAndSetModifiers(AccPublic);
1709 MethodDeclaration methodDecl = new MethodDeclaration(
1710 this.compilationUnit.compilationResult);
1711 methodDecl.declarationSourceStart = scanner
1712 .getCurrentTokenStartPosition();
1713 methodDecl.modifiers = this.modifiers;
1714 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1717 functionDefinition(methodDecl);
1719 int sourceEnd = methodDecl.sourceEnd;
1721 || methodDecl.declarationSourceStart > sourceEnd) {
1722 sourceEnd = methodDecl.declarationSourceStart + 1;
1724 methodDecl.declarationSourceEnd = sourceEnd;
1725 methodDecl.sourceEnd = sourceEnd;
1728 if (!hasModifiers) {
1729 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1731 class_variable_declaration(declarationSourceStart, list);
1736 private void class_constant_declaration(int declarationSourceStart,
1738 // class_constant_declaration ',' T_STRING '=' static_scalar
1739 // | T_CONST T_STRING '=' static_scalar
1740 if (token != TokenName.CONST) {
1741 throwSyntaxError("'const' keyword expected in class declaration.");
1746 if (token != TokenName.IDENTIFIER) {
1747 throwSyntaxError("Identifier expected in class const declaration.");
1749 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner
1750 .getCurrentIdentifierSource(), scanner
1751 .getCurrentTokenStartPosition(), scanner
1752 .getCurrentTokenEndPosition());
1753 fieldDeclaration.modifiers = this.modifiers;
1754 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1755 fieldDeclaration.declarationSourceEnd = scanner
1756 .getCurrentTokenEndPosition();
1757 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1758 // fieldDeclaration.type
1759 list.add(fieldDeclaration);
1761 if (token != TokenName.EQUAL) {
1762 throwSyntaxError("'=' expected in class const declaration.");
1766 if (token != TokenName.COMMA) {
1767 break; // while(true)-loop
1773 // private void variable_modifiers() {
1774 // // variable_modifiers:
1775 // // non_empty_member_modifiers
1777 // initializeModifiers();
1778 // if (token == TokenName.var) {
1779 // checkAndSetModifiers(AccPublic);
1780 // reportSyntaxError(
1781 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1783 // modifier for field declarations.",
1784 // scanner.getCurrentTokenStartPosition(), scanner
1785 // .getCurrentTokenEndPosition());
1788 // if (!member_modifiers()) {
1789 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1790 // field declarations.");
1794 // private void method_modifiers() {
1795 // //method_modifiers:
1797 // //| non_empty_member_modifiers
1798 // initializeModifiers();
1799 // if (!member_modifiers()) {
1800 // checkAndSetModifiers(AccPublic);
1803 private boolean member_modifiers() {
1810 boolean foundToken = false;
1812 if (token == TokenName.PUBLIC) {
1813 checkAndSetModifiers(AccPublic);
1816 } else if (token == TokenName.PROTECTED) {
1817 checkAndSetModifiers(AccProtected);
1820 } else if (token == TokenName.PRIVATE) {
1821 checkAndSetModifiers(AccPrivate);
1824 } else if (token == TokenName.STATIC) {
1825 checkAndSetModifiers(AccStatic);
1828 } else if (token == TokenName.ABSTRACT) {
1829 checkAndSetModifiers(AccAbstract);
1832 } else if (token == TokenName.FINAL) {
1833 checkAndSetModifiers(AccFinal);
1843 private void class_variable_declaration(int declarationSourceStart,
1845 // class_variable_declaration:
1846 // class_variable_declaration ',' T_VARIABLE
1847 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1849 // | T_VARIABLE '=' static_scalar
1850 char[] classVariable;
1852 if (token == TokenName.VARIABLE) {
1853 classVariable = scanner.getCurrentIdentifierSource();
1854 // indexManager.addIdentifierInformation('v', classVariable,
1857 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1858 classVariable, scanner.getCurrentTokenStartPosition(),
1859 scanner.getCurrentTokenEndPosition());
1860 fieldDeclaration.modifiers = this.modifiers;
1861 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1862 fieldDeclaration.declarationSourceEnd = scanner
1863 .getCurrentTokenEndPosition();
1864 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1865 list.add(fieldDeclaration);
1866 if (fTypeVariables != null) {
1867 VariableInfo info = new VariableInfo(scanner
1868 .getCurrentTokenStartPosition(),
1869 VariableInfo.LEVEL_CLASS_UNIT);
1870 fTypeVariables.put(new String(scanner
1871 .getCurrentIdentifierSource()), info);
1874 if (token == TokenName.EQUAL) {
1879 // if (token == TokenName.THIS) {
1880 // throwSyntaxError("'$this' not allowed after keyword 'public'
1881 // 'protected' 'private' 'var'.");
1883 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1885 if (token != TokenName.COMMA) {
1890 if (token != TokenName.SEMICOLON) {
1891 throwSyntaxError("';' expected after field declaration.");
1896 private void functionDefinition(MethodDeclaration methodDecl) {
1897 boolean isAbstract = false;
1899 if (compilationUnit != null) {
1900 compilationUnit.types.add(methodDecl);
1903 ASTNode node = astStack[astPtr];
1904 if (node instanceof TypeDeclaration) {
1905 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1906 if (typeDecl.methods == null) {
1907 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1909 AbstractMethodDeclaration[] newMethods;
1914 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1915 0, typeDecl.methods.length);
1916 newMethods[typeDecl.methods.length] = methodDecl;
1917 typeDecl.methods = newMethods;
1919 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1921 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1927 pushFunctionVariableSet();
1928 functionDeclarator(methodDecl);
1929 if (token == TokenName.SEMICOLON) {
1931 methodDecl.sourceEnd = scanner
1932 .getCurrentTokenStartPosition() - 1;
1933 throwSyntaxError("Body declaration expected for method: "
1934 + new String(methodDecl.selector));
1939 functionBody(methodDecl);
1941 if (!fStackUnassigned.isEmpty()) {
1942 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1947 private void functionDeclarator(MethodDeclaration methodDecl) {
1948 // identifier '(' [parameter-list] ')'
1949 if (token == TokenName.OP_AND) {
1953 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1954 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1956 if (Scanner.isIdentifierOrKeyword (token) ||
1957 token == TokenName.LPAREN) {
1959 if (token == TokenName.LPAREN) {
1960 methodDecl.selector = scanner.getCurrentIdentifierSource();
1962 if (token.compareTo (TokenName.KEYWORD) > 0) {
1963 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1964 scanner.getCurrentTokenStartPosition(),
1965 scanner.getCurrentTokenEndPosition(),
1967 compilationUnit.compilationResult);
1971 methodDecl.selector = scanner.getCurrentIdentifierSource();
1973 if (token.compareTo (TokenName.KEYWORD) > 0) {
1974 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1975 scanner.getCurrentTokenStartPosition(),
1976 scanner.getCurrentTokenEndPosition(),
1978 compilationUnit.compilationResult);
1984 if (token == TokenName.LPAREN) {
1988 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1989 throwSyntaxError("'(' expected in function declaration.");
1992 if (token != TokenName.RPAREN) {
1993 parameter_list(methodDecl);
1996 if (token != TokenName.RPAREN) {
1997 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1998 throwSyntaxError("')' expected in function declaration.");
2001 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
2006 methodDecl.selector = "<undefined>".toCharArray();
2007 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
2008 throwSyntaxError("Function name expected after keyword 'function'.");
2013 private void parameter_list(MethodDeclaration methodDecl) {
2014 // non_empty_parameter_list
2016 non_empty_parameter_list(methodDecl, true);
2019 private void non_empty_parameter_list(MethodDeclaration methodDecl,
2020 boolean empty_allowed) {
2021 // optional_class_type T_VARIABLE
2022 // | optional_class_type '&' T_VARIABLE
2023 // | optional_class_type '&' T_VARIABLE '=' static_scalar
2024 // | optional_class_type T_VARIABLE '=' static_scalar
2025 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
2026 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
2027 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
2029 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
2031 char[] typeIdentifier = null;
2032 if (token == TokenName.IDENTIFIER ||
2033 token == TokenName.ARRAY ||
2034 token == TokenName.VARIABLE ||
2035 token == TokenName.OP_AND) {
2036 HashSet set = peekVariableSet();
2039 if (token == TokenName.IDENTIFIER || token == TokenName.ARRAY) {// feature req. #1254275
2040 typeIdentifier = scanner.getCurrentIdentifierSource();
2043 if (token == TokenName.OP_AND) {
2046 if (token == TokenName.VARIABLE) {
2047 if (fMethodVariables != null) {
2049 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
2050 info = new VariableInfo(scanner
2051 .getCurrentTokenStartPosition(),
2052 VariableInfo.LEVEL_FUNCTION_DEFINITION);
2054 info = new VariableInfo(scanner
2055 .getCurrentTokenStartPosition(),
2056 VariableInfo.LEVEL_METHOD_DEFINITION);
2058 info.typeIdentifier = typeIdentifier;
2059 fMethodVariables.put(new String(scanner
2060 .getCurrentIdentifierSource()), info);
2062 addVariableSet(set);
2064 if (token == TokenName.EQUAL) {
2069 throwSyntaxError("Variable expected in parameter list.");
2071 if (token != TokenName.COMMA) {
2078 if (!empty_allowed) {
2079 throwSyntaxError("Identifier expected in parameter list.");
2083 // private void optional_class_type() {
2088 // private void parameterDeclaration() {
2090 // //variable-reference
2091 // if (token == TokenName.AND) {
2093 // if (isVariable()) {
2096 // throwSyntaxError("Variable expected after reference operator '&'.");
2099 // //variable '=' constant
2100 // if (token == TokenName.VARIABLE) {
2102 // if (token == TokenName.EQUAL) {
2108 // // if (token == TokenName.THIS) {
2109 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
2110 // // declaration.");
2114 private void labeledStatementList() {
2115 if (token != TokenName.CASE && token != TokenName.DEFAULT) {
2116 throwSyntaxError("'case' or 'default' expected.");
2119 if (token == TokenName.CASE) {
2121 expr_without_variable (true, null, true); // constant();
2122 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2124 if (token == TokenName.RBRACE) {
2125 // empty case; assumes that the '}' token belongs to the wrapping
2126 // switch statement - #1371992
2129 if (token == TokenName.CASE || token == TokenName.DEFAULT) {
2130 // empty case statement ?
2135 // else if (token == TokenName.SEMICOLON) {
2137 // "':' expected after 'case' keyword (Found token: " +
2138 // scanner.toStringAction(token) + ")",
2139 // scanner.getCurrentTokenStartPosition(),
2140 // scanner.getCurrentTokenEndPosition(),
2143 // if (token == TokenName.CASE) { // empty case statement ?
2149 throwSyntaxError("':' character expected after 'case' constant (Found token: "
2150 + scanner.toStringAction(token) + ")");
2152 } else { // TokenName.DEFAULT
2154 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2156 if (token == TokenName.RBRACE) {
2157 // empty default case; ; assumes that the '}' token belongs to the
2158 // wrapping switch statement - #1371992
2161 if (token != TokenName.CASE) {
2165 throwSyntaxError("':' character expected after 'default'.");
2168 } while (token == TokenName.CASE || token == TokenName.DEFAULT);
2171 private void ifStatementColon(IfStatement iState) {
2172 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
2173 // new_else_single T_ENDIF ';'
2174 HashSet assignedVariableSet = null;
2176 Block b = inner_statement_list();
2177 iState.thenStatement = b;
2178 checkUnreachable(iState, b);
2180 assignedVariableSet = removeIfVariableSet();
2182 if (token == TokenName.ELSEIF) {
2184 pushIfVariableSet();
2185 new_elseif_list(iState);
2187 HashSet set = removeIfVariableSet();
2188 if (assignedVariableSet != null && set != null) {
2189 assignedVariableSet.addAll(set);
2194 pushIfVariableSet();
2195 new_else_single(iState);
2197 HashSet set = removeIfVariableSet();
2198 if (assignedVariableSet != null) {
2199 HashSet topSet = peekVariableSet();
2200 if (topSet != null) {
2204 topSet.addAll(assignedVariableSet);
2208 if (token != TokenName.ENDIF) {
2209 throwSyntaxError("'endif' expected.");
2212 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2213 reportSyntaxError("';' expected after if-statement.");
2214 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2216 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
2221 private void ifStatement(IfStatement iState) {
2222 // T_IF '(' expr ')' statement elseif_list else_single
2223 HashSet assignedVariableSet = null;
2225 pushIfVariableSet();
2226 Statement s = statement();
2227 iState.thenStatement = s;
2228 checkUnreachable(iState, s);
2230 assignedVariableSet = removeIfVariableSet();
2233 if (token == TokenName.ELSEIF) {
2235 pushIfVariableSet();
2236 elseif_list(iState);
2238 HashSet set = removeIfVariableSet();
2239 if (assignedVariableSet != null && set != null) {
2240 assignedVariableSet.addAll(set);
2245 pushIfVariableSet();
2246 else_single(iState);
2248 HashSet set = removeIfVariableSet();
2249 if (assignedVariableSet != null) {
2250 HashSet topSet = peekVariableSet();
2251 if (topSet != null) {
2255 topSet.addAll(assignedVariableSet);
2261 private void elseif_list(IfStatement iState) {
2263 // | elseif_list T_ELSEIF '(' expr ')' statement
2264 ArrayList conditionList = new ArrayList();
2265 ArrayList statementList = new ArrayList();
2268 while (token == TokenName.ELSEIF) {
2270 if (token == TokenName.LPAREN) {
2273 throwSyntaxError("'(' expected after 'elseif' keyword.");
2276 conditionList.add(e);
2277 if (token == TokenName.RPAREN) {
2280 throwSyntaxError("')' expected after 'elseif' condition.");
2283 statementList.add(s);
2284 checkUnreachable(iState, s);
2286 iState.elseifConditions = new Expression[conditionList.size()];
2287 iState.elseifStatements = new Statement[statementList.size()];
2288 conditionList.toArray(iState.elseifConditions);
2289 statementList.toArray(iState.elseifStatements);
2292 private void new_elseif_list(IfStatement iState) {
2294 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
2295 ArrayList conditionList = new ArrayList();
2296 ArrayList statementList = new ArrayList();
2299 while (token == TokenName.ELSEIF) {
2301 if (token == TokenName.LPAREN) {
2304 throwSyntaxError("'(' expected after 'elseif' keyword.");
2307 conditionList.add(e);
2308 if (token == TokenName.RPAREN) {
2311 throwSyntaxError("')' expected after 'elseif' condition.");
2313 if (token == TokenName.COLON) {
2316 throwSyntaxError("':' expected after 'elseif' keyword.");
2318 b = inner_statement_list();
2319 statementList.add(b);
2320 checkUnreachable(iState, b);
2322 iState.elseifConditions = new Expression[conditionList.size()];
2323 iState.elseifStatements = new Statement[statementList.size()];
2324 conditionList.toArray(iState.elseifConditions);
2325 statementList.toArray(iState.elseifStatements);
2328 private void else_single(IfStatement iState) {
2331 if (token == TokenName.ELSE) {
2333 Statement s = statement();
2334 iState.elseStatement = s;
2335 checkUnreachable(iState, s);
2337 iState.checkUnreachable = false;
2339 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2342 private void new_else_single(IfStatement iState) {
2344 // | T_ELSE ':' inner_statement_list
2345 if (token == TokenName.ELSE) {
2347 if (token == TokenName.COLON) {
2350 throwSyntaxError("':' expected after 'else' keyword.");
2352 Block b = inner_statement_list();
2353 iState.elseStatement = b;
2354 checkUnreachable(iState, b);
2356 iState.checkUnreachable = false;
2360 private Block inner_statement_list() {
2361 // inner_statement_list inner_statement
2363 return statementList();
2370 private void checkUnreachable(IfStatement iState, Statement s) {
2371 if (s instanceof Block) {
2372 Block b = (Block) s;
2373 if (b.statements == null || b.statements.length == 0) {
2374 iState.checkUnreachable = false;
2376 int off = b.statements.length - 1;
2377 if (!(b.statements[off] instanceof ReturnStatement)
2378 && !(b.statements[off] instanceof ContinueStatement)
2379 && !(b.statements[off] instanceof BreakStatement)) {
2380 if (!(b.statements[off] instanceof IfStatement)
2381 || !((IfStatement) b.statements[off]).checkUnreachable) {
2382 iState.checkUnreachable = false;
2387 if (!(s instanceof ReturnStatement)
2388 && !(s instanceof ContinueStatement)
2389 && !(s instanceof BreakStatement)) {
2390 if (!(s instanceof IfStatement)
2391 || !((IfStatement) s).checkUnreachable) {
2392 iState.checkUnreachable = false;
2398 // private void elseifStatementList() {
2400 // elseifStatement();
2402 // case TokenName.else:
2404 // if (token == TokenName.COLON) {
2406 // if (token != TokenName.endif) {
2411 // if (token == TokenName.if) { //'else if'
2414 // throwSyntaxError("':' expected after 'else'.");
2418 // case TokenName.elseif:
2427 // private void elseifStatement() {
2428 // if (token == TokenName.LPAREN) {
2431 // if (token != TokenName.RPAREN) {
2432 // throwSyntaxError("')' expected in else-if-statement.");
2435 // if (token != TokenName.COLON) {
2436 // throwSyntaxError("':' expected in else-if-statement.");
2439 // if (token != TokenName.endif) {
2445 private void switchStatement() {
2446 if (token == TokenName.COLON) {
2447 // ':' [labeled-statement-list] 'endswitch' ';'
2449 labeledStatementList();
2450 if (token != TokenName.ENDSWITCH) {
2451 throwSyntaxError("'endswitch' expected.");
2454 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2455 throwSyntaxError("';' expected after switch-statement.");
2459 // '{' [labeled-statement-list] '}'
2460 if (token != TokenName.LBRACE) {
2461 throwSyntaxError("'{' expected in switch statement.");
2464 if (token != TokenName.RBRACE) {
2465 labeledStatementList();
2467 if (token != TokenName.RBRACE) {
2468 throwSyntaxError("'}' expected in switch statement.");
2474 private void forStatement() {
2475 if (token == TokenName.COLON) {
2478 if (token != TokenName.ENDFOR) {
2479 throwSyntaxError("'endfor' expected.");
2482 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2483 throwSyntaxError("';' expected after for-statement.");
2491 private void whileStatement() {
2492 // ':' statement-list 'endwhile' ';'
2493 if (token == TokenName.COLON) {
2496 if (token != TokenName.ENDWHILE) {
2497 throwSyntaxError("'endwhile' expected.");
2500 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2501 throwSyntaxError("';' expected after while-statement.");
2509 private void foreachStatement() {
2510 if (token == TokenName.COLON) {
2513 if (token != TokenName.ENDFOREACH) {
2514 throwSyntaxError("'endforeach' expected.");
2517 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2518 throwSyntaxError("';' expected after foreach-statement.");
2526 // private void exitStatus() {
2527 // if (token == TokenName.LPAREN) {
2530 // throwSyntaxError("'(' expected in 'exit-status'.");
2532 // if (token != TokenName.RPAREN) {
2535 // if (token == TokenName.RPAREN) {
2538 // throwSyntaxError("')' expected after 'exit-status'.");
2544 private void namespacePath () {
2546 expr_without_variable (true, null, false);
2548 if (token == TokenName.BACKSLASH) {
2559 private void expressionList() {
2561 expr_without_variable (true, null, false);
2563 if (token == TokenName.COMMA) { // If it's a list of (comma separated) expressions
2564 getNextToken(); // read all in, untill no more found
2571 private Expression expr() {
2572 return expr_without_variable(true, null, false);
2577 * @param only_variable
2578 * @param initHandler
2580 private Expression expr_without_variable (boolean only_variable,
2581 UninitializedVariableHandler initHandler,
2582 boolean bColonAllowed) {
2583 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2584 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2585 Expression expression = new Expression();
2587 expression.sourceStart = exprSourceStart;
2588 expression.sourceEnd = exprSourceEnd; // default, may be overwritten
2591 // internal_functions_in_yacc
2600 // | T_INC rw_variable
2601 // | T_DEC rw_variable
2602 // | T_INT_CAST expr
2603 // | T_DOUBLE_CAST expr
2604 // | T_STRING_CAST expr
2605 // | T_ARRAY_CAST expr
2606 // | T_OBJECT_CAST expr
2607 // | T_BOOL_CAST expr
2608 // | T_UNSET_CAST expr
2609 // | T_EXIT exit_expr
2611 // | T_ARRAY '(' array_pair_list ')'
2612 // | '`' encaps_list '`'
2613 // | T_LIST '(' assignment_list ')' '=' expr
2614 // | T_NEW class_name_reference ctor_arguments
2615 // | variable '=' expr
2616 // | variable '=' '&' variable
2617 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2618 // | variable T_PLUS_EQUAL expr
2619 // | variable T_MINUS_EQUAL expr
2620 // | variable T_MUL_EQUAL expr
2621 // | variable T_DIV_EQUAL expr
2622 // | variable T_CONCAT_EQUAL expr
2623 // | variable T_MOD_EQUAL expr
2624 // | variable T_AND_EQUAL expr
2625 // | variable T_OR_EQUAL expr
2626 // | variable T_XOR_EQUAL expr
2627 // | variable T_SL_EQUAL expr
2628 // | variable T_SR_EQUAL expr
2629 // | rw_variable T_INC
2630 // | rw_variable T_DEC
2631 // | expr T_BOOLEAN_OR expr
2632 // | expr T_BOOLEAN_AND expr
2633 // | expr T_LOGICAL_OR expr
2634 // | expr T_LOGICAL_AND expr
2635 // | expr T_LOGICAL_XOR expr
2647 // | expr T_IS_IDENTICAL expr
2648 // | expr T_IS_NOT_IDENTICAL expr
2649 // | expr T_IS_EQUAL expr
2650 // | expr T_IS_NOT_EQUAL expr
2652 // | expr T_IS_SMALLER_OR_EQUAL expr
2654 // | expr T_IS_GREATER_OR_EQUAL expr
2655 // | expr T_INSTANCEOF class_name_reference
2656 // | expr '?' expr ':' expr
2657 if (Scanner.TRACE) {
2658 System.out.println("TRACE: expr_without_variable() PART 1");
2663 // T_ISSET '(' isset_variables ')'
2665 if (token != TokenName.LPAREN) {
2666 throwSyntaxError("'(' expected after keyword 'isset'");
2670 if (token != TokenName.RPAREN) {
2671 throwSyntaxError("')' expected after keyword 'isset'");
2677 if (token != TokenName.LPAREN) {
2678 throwSyntaxError("'(' expected after keyword 'empty'");
2681 variable(true, false);
2682 if (token != TokenName.RPAREN) {
2683 throwSyntaxError("')' expected after keyword 'empty'");
2692 internal_functions_in_yacc();
2699 if (token == TokenName.RPAREN) {
2702 throwSyntaxError("')' expected in expression.");
2712 // | T_INT_CAST expr
2713 // | T_DOUBLE_CAST expr
2714 // | T_STRING_CAST expr
2715 // | T_ARRAY_CAST expr
2716 // | T_OBJECT_CAST expr
2717 // | T_BOOL_CAST expr
2718 // | T_UNSET_CAST expr
2734 expr_without_variable (only_variable, initHandler, bColonAllowed);
2742 // | T_STRING_VARNAME
2744 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2745 // | '`' encaps_list '`'
2747 // | '`' encaps_list '`'
2748 // case TokenName.EncapsedString0:
2749 // scanner.encapsedStringStack.push(new Character('`'));
2752 // if (token == TokenName.EncapsedString0) {
2755 // if (token != TokenName.EncapsedString0) {
2756 // throwSyntaxError("\'`\' expected at end of string" + "(Found
2758 // scanner.toStringAction(token) + " )");
2762 // scanner.encapsedStringStack.pop();
2766 // // | '\'' encaps_list '\''
2767 // case TokenName.EncapsedString1:
2768 // scanner.encapsedStringStack.push(new Character('\''));
2771 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2772 // if (token == TokenName.EncapsedString1) {
2774 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2775 // exprSourceStart, scanner
2776 // .getCurrentTokenEndPosition());
2779 // if (token != TokenName.EncapsedString1) {
2780 // throwSyntaxError("\'\'\' expected at end of string" + "(Found
2782 // + scanner.toStringAction(token) + " )");
2785 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2786 // exprSourceStart, scanner
2787 // .getCurrentTokenEndPosition());
2791 // scanner.encapsedStringStack.pop();
2795 // //| '"' encaps_list '"'
2796 // case TokenName.EncapsedString2:
2797 // scanner.encapsedStringStack.push(new Character('"'));
2800 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2801 // if (token == TokenName.EncapsedString2) {
2803 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2804 // exprSourceStart, scanner
2805 // .getCurrentTokenEndPosition());
2808 // if (token != TokenName.EncapsedString2) {
2809 // throwSyntaxError("'\"' expected at end of string" + "(Found
2811 // scanner.toStringAction(token) + " )");
2814 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2815 // exprSourceStart, scanner
2816 // .getCurrentTokenEndPosition());
2820 // scanner.encapsedStringStack.pop();
2824 case STRINGDOUBLEQUOTE:
2825 expression = new StringLiteralDQ (scanner.getCurrentStringLiteralSource(),
2826 scanner.getCurrentTokenStartPosition(),
2827 scanner.getCurrentTokenEndPosition());
2830 case STRINGSINGLEQUOTE:
2831 expression = new StringLiteralSQ (scanner.getCurrentStringLiteralSource(),
2832 scanner.getCurrentTokenStartPosition(),
2833 scanner.getCurrentTokenEndPosition());
2836 case INTEGERLITERAL:
2838 case STRINGINTERPOLATED:
2850 // T_ARRAY '(' array_pair_list ')'
2852 if (token == TokenName.LPAREN) {
2854 if (token == TokenName.RPAREN) {
2859 if (token != TokenName.RPAREN) {
2860 throwSyntaxError("')' or ',' expected after keyword 'array'"
2862 + scanner.toStringAction(token) + ")");
2866 throwSyntaxError("'(' expected after keyword 'array'"
2867 + "(Found token: " + scanner.toStringAction(token)
2872 // | T_LIST '(' assignment_list ')' '=' expr
2874 if (token == TokenName.LPAREN) {
2877 if (token != TokenName.RPAREN) {
2878 throwSyntaxError("')' expected after 'list' keyword.");
2881 if (token != TokenName.EQUAL) {
2882 throwSyntaxError("'=' expected after 'list' keyword.");
2887 throwSyntaxError("'(' expected after 'list' keyword.");
2891 // | T_NEW class_name_reference ctor_arguments
2893 Expression typeRef = class_name_reference();
2895 if (typeRef != null) {
2896 expression = typeRef;
2899 // | T_INC rw_variable
2900 // | T_DEC rw_variable
2906 // | variable '=' expr
2907 // | variable '=' '&' variable
2908 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2909 // | variable T_PLUS_EQUAL expr
2910 // | variable T_MINUS_EQUAL expr
2911 // | variable T_MUL_EQUAL expr
2912 // | variable T_DIV_EQUAL expr
2913 // | variable T_CONCAT_EQUAL expr
2914 // | variable T_MOD_EQUAL expr
2915 // | variable T_AND_EQUAL expr
2916 // | variable T_OR_EQUAL expr
2917 // | variable T_XOR_EQUAL expr
2918 // | variable T_SL_EQUAL expr
2919 // | variable T_SR_EQUAL expr
2920 // | rw_variable T_INC
2921 // | rw_variable T_DEC
2925 Expression lhs = null;
2926 boolean rememberedVar = false;
2928 if (token == TokenName.IDENTIFIER) {
2929 lhs = identifier(true, true, bColonAllowed);
2936 lhs = variable (true, true);
2943 lhs instanceof FieldReference &&
2944 token != TokenName.EQUAL &&
2945 token != TokenName.PLUS_EQUAL &&
2946 token != TokenName.MINUS_EQUAL &&
2947 token != TokenName.MULTIPLY_EQUAL &&
2948 token != TokenName.DIVIDE_EQUAL &&
2949 token != TokenName.DOT_EQUAL &&
2950 token != TokenName.REMAINDER_EQUAL &&
2951 token != TokenName.AND_EQUAL &&
2952 token != TokenName.OR_EQUAL &&
2953 token != TokenName.XOR_EQUAL &&
2954 token != TokenName.RIGHT_SHIFT_EQUAL &&
2955 token != TokenName.LEFT_SHIFT_EQUAL) {
2957 FieldReference ref = (FieldReference) lhs;
2959 if (!containsVariableSet(ref.token)) {
2960 if (null == initHandler || initHandler.reportError()) {
2961 problemReporter.uninitializedLocalVariable(
2962 new String(ref.token), ref.sourceStart,
2963 ref.sourceEnd, referenceContext,
2964 compilationUnit.compilationResult);
2966 addVariableSet(ref.token);
2973 if (lhs != null && lhs instanceof FieldReference) {
2974 addVariableSet(((FieldReference) lhs).token);
2977 if (token == TokenName.OP_AND) {
2979 if (token == TokenName.NEW) {
2980 // | variable '=' '&' T_NEW class_name_reference
2983 SingleTypeReference classRef = class_name_reference();
2985 if (classRef != null) {
2987 && lhs instanceof FieldReference) {
2989 // $var = & new Object();
2990 if (fMethodVariables != null) {
2991 VariableInfo lhsInfo = new VariableInfo(
2992 ((FieldReference) lhs).sourceStart);
2993 lhsInfo.reference = classRef;
2994 lhsInfo.typeIdentifier = classRef.token;
2995 fMethodVariables.put(new String(
2996 ((FieldReference) lhs).token),
2998 rememberedVar = true;
3003 Expression rhs = variable(false, false);
3004 if (rhs != null && rhs instanceof FieldReference
3006 && lhs instanceof FieldReference) {
3009 if (fMethodVariables != null) {
3010 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
3011 .get(((FieldReference) rhs).token);
3013 && rhsInfo.reference != null) {
3014 VariableInfo lhsInfo = new VariableInfo(
3015 ((FieldReference) lhs).sourceStart);
3016 lhsInfo.reference = rhsInfo.reference;
3017 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
3018 fMethodVariables.put(new String(
3019 ((FieldReference) lhs).token),
3021 rememberedVar = true;
3027 Expression rhs = expr_without_variable (only_variable, initHandler, bColonAllowed);
3029 if (lhs != null && lhs instanceof FieldReference) {
3030 if (rhs != null && rhs instanceof FieldReference) {
3033 if (fMethodVariables != null) {
3034 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
3035 .get(((FieldReference) rhs).token);
3037 && rhsInfo.reference != null) {
3038 VariableInfo lhsInfo = new VariableInfo(
3039 ((FieldReference) lhs).sourceStart);
3040 lhsInfo.reference = rhsInfo.reference;
3041 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
3042 fMethodVariables.put(new String(
3043 ((FieldReference) lhs).token),
3045 rememberedVar = true;
3048 } else if (rhs != null
3049 && rhs instanceof SingleTypeReference) {
3051 // $var = new Object();
3052 if (fMethodVariables != null) {
3053 VariableInfo lhsInfo = new VariableInfo(
3054 ((FieldReference) lhs).sourceStart);
3055 lhsInfo.reference = (SingleTypeReference) rhs;
3056 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
3057 fMethodVariables.put(new String(
3058 ((FieldReference) lhs).token),
3060 rememberedVar = true;
3065 if (rememberedVar == false && lhs != null
3066 && lhs instanceof FieldReference) {
3067 if (fMethodVariables != null) {
3068 VariableInfo lhsInfo = new VariableInfo (((FieldReference) lhs).sourceStart);
3069 fMethodVariables.put (new String (((FieldReference) lhs).token), lhsInfo);
3077 case MULTIPLY_EQUAL:
3080 case REMAINDER_EQUAL:
3084 case RIGHT_SHIFT_EQUAL:
3085 case LEFT_SHIFT_EQUAL:
3086 if (lhs != null && lhs instanceof FieldReference) {
3087 addVariableSet(((FieldReference) lhs).token);
3090 expr_without_variable (only_variable, initHandler, bColonAllowed);
3097 if (!only_variable) {
3098 throwSyntaxError("Variable expression not allowed (found token '"
3099 + scanner.toStringAction(token) + "').");
3104 } // case DOLLAR, VARIABLE, IDENTIFIER: switch token
3108 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
3109 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
3110 methodDecl.modifiers = AccDefault;
3111 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
3114 functionDefinition(methodDecl);
3116 int sourceEnd = methodDecl.sourceEnd;
3117 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
3118 sourceEnd = methodDecl.declarationSourceStart + 1;
3120 methodDecl.declarationSourceEnd = sourceEnd;
3121 methodDecl.sourceEnd = sourceEnd;
3126 if (token != TokenName.INLINE_HTML) {
3127 if (token.compareTo (TokenName.KEYWORD) > 0) {
3131 // System.out.println(scanner.getCurrentTokenStartPosition());
3132 // System.out.println(scanner.getCurrentTokenEndPosition());
3134 throwSyntaxError("Error in expression (found token '"
3135 + scanner.toStringAction(token) + "').");
3141 if (Scanner.TRACE) {
3142 System.out.println("TRACE: expr_without_variable() PART 2");
3145 // | expr T_BOOLEAN_OR expr
3146 // | expr T_BOOLEAN_AND expr
3147 // | expr T_LOGICAL_OR expr
3148 // | expr T_LOGICAL_AND expr
3149 // | expr T_LOGICAL_XOR expr
3161 // | expr T_IS_IDENTICAL expr
3162 // | expr T_IS_NOT_IDENTICAL expr
3163 // | expr T_IS_EQUAL expr
3164 // | expr T_IS_NOT_EQUAL expr
3166 // | expr T_IS_SMALLER_OR_EQUAL expr
3168 // | expr T_IS_GREATER_OR_EQUAL expr
3173 expression = new OR_OR_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR_OR);
3177 expression = new AND_AND_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND_AND);
3181 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3185 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3189 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3193 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3197 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3201 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3205 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3209 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TWIDDLE);
3213 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.PLUS);
3217 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MINUS);
3221 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MULTIPLY);
3225 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.DIVIDE);
3229 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.REMAINDER);
3233 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LEFT_SHIFT);
3237 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.RIGHT_SHIFT);
3239 case EQUAL_EQUAL_EQUAL:
3241 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3243 case NOT_EQUAL_EQUAL:
3245 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3249 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3253 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS);
3257 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS_EQUAL);
3261 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER);
3265 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER_EQUAL);
3267 // | expr T_INSTANCEOF class_name_reference
3268 // | expr '?' expr ':' expr
3271 TypeReference classRef = class_name_reference();
3273 if (classRef != null) {
3274 expression = new InstanceOfExpression (expression, classRef, OperatorIds.INSTANCEOF);
3275 expression.sourceStart = exprSourceStart;
3276 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
3282 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TERNARY_SHORT);
3287 Expression valueIfTrue = expr_without_variable (true, null, true);
3288 if (token != TokenName.COLON) {
3289 throwSyntaxError("':' expected in conditional expression.");
3292 Expression valueIfFalse = expr();
3294 expression = new ConditionalExpression (expression, valueIfTrue, valueIfFalse);
3300 } catch (SyntaxError e) {
3301 // try to find next token after expression with errors:
3302 if (token == TokenName.SEMICOLON) {
3307 if (token == TokenName.RBRACE ||
3308 token == TokenName.RPAREN ||
3309 token == TokenName.RBRACKET) {
3320 private SingleTypeReference class_name_reference() {
3321 // class_name_reference:
3323 // | dynamic_class_name_reference
3324 SingleTypeReference ref = null;
3325 if (Scanner.TRACE) {
3326 System.out.println("TRACE: class_name_reference()");
3328 if (token == TokenName.IDENTIFIER) {
3329 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3330 scanner.getCurrentTokenStartPosition());
3331 int pos = scanner.currentPosition;
3333 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
3334 // Not terminated by T_STRING, reduce to dynamic_class_name_reference
3335 scanner.currentPosition = pos;
3336 token = TokenName.IDENTIFIER;
3338 dynamic_class_name_reference();
3342 dynamic_class_name_reference();
3347 private void dynamic_class_name_reference() {
3348 // dynamic_class_name_reference:
3349 // base_variable T_OBJECT_OPERATOR object_property
3350 // dynamic_class_name_variable_properties
3352 if (Scanner.TRACE) {
3353 System.out.println("TRACE: dynamic_class_name_reference()");
3355 base_variable(true);
3356 if (token == TokenName.MINUS_GREATER) {
3359 dynamic_class_name_variable_properties();
3363 private void dynamic_class_name_variable_properties() {
3364 // dynamic_class_name_variable_properties:
3365 // dynamic_class_name_variable_properties
3366 // dynamic_class_name_variable_property
3368 if (Scanner.TRACE) {
3370 .println("TRACE: dynamic_class_name_variable_properties()");
3372 while (token == TokenName.MINUS_GREATER) {
3373 dynamic_class_name_variable_property();
3377 private void dynamic_class_name_variable_property() {
3378 // dynamic_class_name_variable_property:
3379 // T_OBJECT_OPERATOR object_property
3380 if (Scanner.TRACE) {
3381 System.out.println("TRACE: dynamic_class_name_variable_property()");
3383 if (token == TokenName.MINUS_GREATER) {
3389 private void ctor_arguments() {
3392 // | '(' function_call_parameter_list ')'
3393 if (token == TokenName.LPAREN) {
3395 if (token == TokenName.RPAREN) {
3399 non_empty_function_call_parameter_list();
3400 if (token != TokenName.RPAREN) {
3401 throwSyntaxError("')' expected in ctor_arguments.");
3407 private void assignment_list() {
3409 // assignment_list ',' assignment_list_element
3410 // | assignment_list_element
3412 assignment_list_element();
3413 if (token != TokenName.COMMA) {
3420 private void assignment_list_element() {
3421 // assignment_list_element:
3423 // | T_LIST '(' assignment_list ')'
3425 if (token == TokenName.VARIABLE) {
3426 variable(true, false);
3427 } else if (token == TokenName.DOLLAR) {
3428 variable(false, false);
3429 } else if (token == TokenName.IDENTIFIER) {
3430 identifier(true, true, false);
3432 if (token == TokenName.LIST) {
3434 if (token == TokenName.LPAREN) {
3437 if (token != TokenName.RPAREN) {
3438 throwSyntaxError("')' expected after 'list' keyword.");
3442 throwSyntaxError("'(' expected after 'list' keyword.");
3448 private void array_pair_list() {
3451 // | non_empty_array_pair_list possible_comma
3452 non_empty_array_pair_list();
3453 if (token == TokenName.COMMA) {
3458 private void non_empty_array_pair_list() {
3459 // non_empty_array_pair_list:
3460 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3461 // | non_empty_array_pair_list ',' expr
3462 // | expr T_DOUBLE_ARROW expr
3464 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3465 // | non_empty_array_pair_list ',' '&' w_variable
3466 // | expr T_DOUBLE_ARROW '&' w_variable
3469 if (token == TokenName.OP_AND) {
3471 variable(true, false);
3474 if (token == TokenName.OP_AND) {
3476 variable(true, false);
3477 } else if (token == TokenName.EQUAL_GREATER) {
3479 if (token == TokenName.OP_AND) {
3481 variable(true, false);
3487 if (token != TokenName.COMMA) {
3491 if (token == TokenName.RPAREN) {
3497 // private void variableList() {
3500 // if (token == TokenName.COMMA) {
3507 private Expression variable_without_objects(boolean lefthandside,
3508 boolean ignoreVar) {
3509 // variable_without_objects:
3510 // reference_variable
3511 // | simple_indirect_reference reference_variable
3512 if (Scanner.TRACE) {
3513 System.out.println("TRACE: variable_without_objects()");
3515 while (token == TokenName.DOLLAR) {
3518 return reference_variable(lefthandside, ignoreVar);
3521 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3523 // T_STRING '(' function_call_parameter_list ')'
3524 // | class_constant '(' function_call_parameter_list ')'
3525 // | static_member '(' function_call_parameter_list ')'
3526 // | variable_without_objects '(' function_call_parameter_list ')'
3527 char[] defineName = null;
3528 char[] ident = null;
3531 Expression ref = null;
3532 if (Scanner.TRACE) {
3533 System.out.println("TRACE: function_call()");
3535 if (token == TokenName.IDENTIFIER) {
3536 ident = scanner.getCurrentIdentifierSource();
3538 startPos = scanner.getCurrentTokenStartPosition();
3539 endPos = scanner.getCurrentTokenEndPosition();
3542 case PAAMAYIM_NEKUDOTAYIM:
3546 if (token == TokenName.IDENTIFIER) {
3551 variable_without_objects(true, false);
3556 ref = variable_without_objects(lefthandside, ignoreVar);
3558 if (token != TokenName.LPAREN) {
3559 if (defineName != null) {
3560 // does this identifier contain only uppercase characters?
3561 if (defineName.length == 3) {
3562 if (defineName[0] == 'd' &&
3563 defineName[1] == 'i' &&
3564 defineName[2] == 'e') {
3567 } else if (defineName.length == 4) {
3568 if (defineName[0] == 't' &&
3569 defineName[1] == 'r' &&
3570 defineName[2] == 'u' &&
3571 defineName[3] == 'e') {
3573 } else if (defineName[0] == 'n' &&
3574 defineName[1] == 'u' &&
3575 defineName[2] == 'l' &&
3576 defineName[3] == 'l') {
3579 } else if (defineName.length == 5) {
3580 if (defineName[0] == 'f' &&
3581 defineName[1] == 'a' &&
3582 defineName[2] == 'l' &&
3583 defineName[3] == 's' &&
3584 defineName[4] == 'e') {
3588 if (defineName != null) {
3589 for (int i = 0; i < defineName.length; i++) {
3590 if (Character.isLowerCase(defineName[i])) {
3591 problemReporter.phpUppercaseIdentifierWarning(
3592 startPos, endPos, referenceContext,
3593 compilationUnit.compilationResult);
3601 if (token == TokenName.RPAREN) {
3606 non_empty_function_call_parameter_list();
3608 if (token != TokenName.RPAREN) {
3609 String functionName;
3611 if (ident == null) {
3612 functionName = new String(" ");
3614 functionName = new String(ident);
3617 throwSyntaxError("')' expected in function call (" + functionName + ").");
3624 private void non_empty_function_call_parameter_list() {
3625 this.non_empty_function_call_parameter_list(null);
3628 // private void function_call_parameter_list() {
3629 // function_call_parameter_list:
3630 // non_empty_function_call_parameter_list { $$ = $1; }
3633 private void non_empty_function_call_parameter_list(String functionName) {
3634 // non_empty_function_call_parameter_list:
3635 // expr_without_variable
3638 // | non_empty_function_call_parameter_list ',' expr_without_variable
3639 // | non_empty_function_call_parameter_list ',' variable
3640 // | non_empty_function_call_parameter_list ',' '&' w_variable
3641 if (Scanner.TRACE) {
3643 .println("TRACE: non_empty_function_call_parameter_list()");
3645 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3646 initHandler.setFunctionName(functionName);
3648 initHandler.incrementArgumentCount();
3649 if (token == TokenName.OP_AND) {
3653 // if (token == TokenName.Identifier || token ==
3654 // TokenName.Variable
3655 // || token == TokenName.DOLLAR) {
3658 expr_without_variable(true, initHandler, false);
3661 if (token != TokenName.COMMA) {
3668 private void fully_qualified_class_name() {
3669 if (token == TokenName.IDENTIFIER) {
3672 throwSyntaxError("Class name expected.");
3676 private void static_member() {
3678 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3679 // variable_without_objects
3680 if (Scanner.TRACE) {
3681 System.out.println("TRACE: static_member()");
3683 fully_qualified_class_name();
3684 if (token != TokenName.PAAMAYIM_NEKUDOTAYIM) {
3685 throwSyntaxError("'::' expected after class name (static_member).");
3688 variable_without_objects(false, false);
3692 * base_variable_with_function_calls:
3693 * base_variable | function_call
3695 * @param lefthandside
3699 private Expression base_variable_with_function_calls (boolean lefthandside, boolean ignoreVar) {
3700 if (Scanner.TRACE) {
3701 System.out.println("TRACE: base_variable_with_function_calls()");
3704 return function_call(lefthandside, ignoreVar);
3709 * reference_variable
3710 * | simple_indirect_reference reference_variable
3713 * @param lefthandside
3716 private Expression base_variable (boolean lefthandside) {
3717 Expression ref = null;
3719 if (Scanner.TRACE) {
3720 System.out.println ("TRACE: base_variable()");
3723 if (token == TokenName.IDENTIFIER) {
3727 while (token == TokenName.DOLLAR) {
3731 reference_variable (lefthandside, false);
3737 // private void simple_indirect_reference() {
3738 // // simple_indirect_reference:
3740 // //| simple_indirect_reference '$'
3742 private Expression reference_variable (boolean lefthandside, boolean ignoreVar) {
3743 // reference_variable:
3744 // reference_variable '[' dim_offset ']'
3745 // | reference_variable '{' expr '}'
3746 // | compound_variable
3747 Expression ref = null;
3748 if (Scanner.TRACE) {
3749 System.out.println("TRACE: reference_variable()");
3751 ref = compound_variable(lefthandside, ignoreVar);
3753 if (token == TokenName.LBRACE) {
3757 if (token != TokenName.RBRACE) {
3758 throwSyntaxError("'}' expected in reference variable.");
3761 } else if (token == TokenName.LBRACKET) {
3762 // To remove "ref = null;" here, is probably better than the
3764 // commented in #1368081 - axelcl
3766 if (token != TokenName.RBRACKET) {
3769 if (token != TokenName.RBRACKET) {
3770 throwSyntaxError("']' expected in reference variable.");
3781 private Expression compound_variable (boolean lefthandside, boolean ignoreVar) {
3782 // compound_variable:
3784 // | '$' '{' expr '}'
3785 if (Scanner.TRACE) {
3786 System.out.println("TRACE: compound_variable()");
3789 if (token == TokenName.VARIABLE) {
3790 if (!lefthandside) {
3791 if (!containsVariableSet()) {
3792 // reportSyntaxError("The local variable " + new
3793 // String(scanner.getCurrentIdentifierSource())
3794 // + " may not have been initialized");
3795 problemReporter.uninitializedLocalVariable (
3796 new String (scanner.getCurrentIdentifierSource()),
3797 scanner.getCurrentTokenStartPosition(),
3798 scanner.getCurrentTokenEndPosition(),
3800 compilationUnit.compilationResult);
3808 FieldReference ref = new FieldReference (scanner.getCurrentIdentifierSource(),
3809 scanner.getCurrentTokenStartPosition());
3814 // because of simple_indirect_reference
3815 while (token == TokenName.DOLLAR) {
3819 if (token != TokenName.LBRACE) {
3820 reportSyntaxError("'{' expected after compound variable token '$'.");
3827 if (token != TokenName.RBRACE) {
3828 throwSyntaxError("'}' expected after compound variable token '$'.");
3835 } // private void dim_offset() { // // dim_offset: // // /* empty */
3840 private void object_property() {
3843 // | variable_without_objects
3844 if (Scanner.TRACE) {
3845 System.out.println("TRACE: object_property()");
3848 if ((token == TokenName.VARIABLE) ||
3849 (token == TokenName.DOLLAR)) {
3850 variable_without_objects (false, false);
3857 private void object_dim_list() {
3859 // object_dim_list '[' dim_offset ']'
3860 // | object_dim_list '{' expr '}'
3862 if (Scanner.TRACE) {
3863 System.out.println("TRACE: object_dim_list()");
3869 if (token == TokenName.LBRACE) {
3873 if (token != TokenName.RBRACE) {
3874 throwSyntaxError("'}' expected in object_dim_list.");
3879 else if (token == TokenName.LBRACKET) {
3882 if (token == TokenName.RBRACKET) {
3889 if (token != TokenName.RBRACKET) {
3890 throwSyntaxError("']' expected in object_dim_list.");
3901 private void variable_name() {
3905 if (Scanner.TRACE) {
3906 System.out.println("TRACE: variable_name()");
3909 if ((token == TokenName.IDENTIFIER) ||
3910 (token.compareTo (TokenName.KEYWORD) > 0)) {
3911 if (token.compareTo (TokenName.KEYWORD) > 0) {
3912 // TODO show a warning "Keyword used as variable" ?
3917 else if ((token == TokenName.OP_AND_OLD) || // If the found token is e.g $var->and
3918 (token == TokenName.OP_OR_OLD) || // or is $var->or
3919 (token == TokenName.OP_XOR_OLD)) { // or is $var->xor
3920 getNextToken (); // get the next token. Maybe we should issue an warning?
3923 if (token != TokenName.LBRACE) {
3924 throwSyntaxError("'{' expected in variable name.");
3930 if (token != TokenName.RBRACE) {
3931 throwSyntaxError("'}' expected in variable name.");
3938 private void r_variable() {
3939 variable(false, false);
3942 private void w_variable(boolean lefthandside) {
3943 variable(lefthandside, false);
3946 private void rw_variable() {
3947 variable(false, false);
3953 * base_variable_with_function_calls T_OBJECT_OPERATOR
3954 * object_property method_or_not variable_properties
3955 * | base_variable_with_function_calls
3957 * @param lefthandside
3961 private Expression variable (boolean lefthandside, boolean ignoreVar) {
3962 Expression ref = base_variable_with_function_calls (lefthandside, ignoreVar);
3964 if ((token == TokenName.MINUS_GREATER) ||
3965 (token == TokenName.PAAMAYIM_NEKUDOTAYIM)) {
3966 /* I don't know why ref was set to null, but if it is null, the variable will neither be added to the set of variable,
3967 * nor would it be checked for beeing unitialized. So I don't set it to null!
3973 variable_properties();
3979 private void variable_properties() {
3980 // variable_properties:
3981 // variable_properties variable_property
3983 while (token == TokenName.MINUS_GREATER) {
3984 variable_property();
3988 private void variable_property() {
3989 // variable_property:
3990 // T_OBJECT_OPERATOR object_property method_or_not
3991 if (Scanner.TRACE) {
3992 System.out.println("TRACE: variable_property()");
3995 if (token == TokenName.MINUS_GREATER) {
4001 throwSyntaxError("'->' expected in variable_property.");
4008 * base_variable_with_function_calls T_OBJECT_OPERATOR
4009 * object_property method_or_not variable_properties
4010 * | base_variable_with_function_calls
4012 * Expression ref = function_call(lefthandside, ignoreVar);
4015 * T_STRING '(' function_call_parameter_list ')'
4016 * | class_constant '(' function_call_parameter_list ')'
4017 * | static_member '(' function_call_parameter_list ')'
4018 * | variable_without_objects '(' function_call_parameter_list ')'
4020 * @param lefthandside
4025 private Expression identifier (boolean lefthandside, boolean ignoreVar, boolean bColonAllowed) {
4026 char[] defineName = null;
4027 char[] ident = null;
4030 Expression ref = null;
4032 if (Scanner.TRACE) {
4033 System.out.println("TRACE: function_call()");
4036 if (token == TokenName.IDENTIFIER) {
4037 ident = scanner.getCurrentIdentifierSource();
4039 startPos = scanner.getCurrentTokenStartPosition();
4040 endPos = scanner.getCurrentTokenEndPosition();
4042 getNextToken(); // Get the token after the identifier
4048 case MULTIPLY_EQUAL:
4051 case REMAINDER_EQUAL:
4055 case RIGHT_SHIFT_EQUAL:
4056 case LEFT_SHIFT_EQUAL:
4057 String error = "Assignment operator '"
4058 + scanner.toStringAction(token)
4059 + "' not allowed after identifier '"
4061 + "' (use 'define(...)' to define constants).";
4062 reportSyntaxError(error);
4066 if (token == TokenName.COLON) { // If it's a ':', the identifier is a label
4071 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) { // '::'
4074 getNextToken (); // Read the identifier
4076 if (token == TokenName.IDENTIFIER) { // class _constant
4079 else { // static member:
4080 variable_without_objects (true, false);
4084 else if (token == TokenName.BACKSLASH) { // '\' namespace path separator
4087 if (token == TokenName.IDENTIFIER) { // If it's an identifier
4088 getNextToken (); // go for the next token
4090 else { // It's not an identifiere, something wrong
4091 throwSyntaxError ("an identifier expected after '\\' ");
4099 else { // Token is not an identifier
4100 ref = variable_without_objects(lefthandside, ignoreVar);
4103 if (token == TokenName.LPAREN) { // If token is '('
4106 if (token == TokenName.RPAREN) { // If token is ')'
4111 String functionName;
4113 if (ident == null) {
4114 functionName = new String(" ");
4116 functionName = new String(ident);
4119 non_empty_function_call_parameter_list(functionName); // Get the parameter list for the given function name
4121 if (token != TokenName.RPAREN) { // If token is not a ')', throw error
4122 throwSyntaxError ("')' expected in function call (" + functionName + ").");
4125 getNextToken(); // Get the token after ')'
4128 else { // It's not an '('
4129 if (defineName != null) { // does this identifier contain only uppercase characters?
4130 if (defineName.length == 3) { // If it's a 'die'
4131 if (defineName[0] == 'd' &&
4132 defineName[1] == 'i' &&
4133 defineName[2] == 'e') {
4137 else if (defineName.length == 4) { // If it's a 'true'
4138 if (defineName[0] == 't' &&
4139 defineName[1] == 'r' &&
4140 defineName[2] == 'u' &&
4141 defineName[3] == 'e') {
4144 else if (defineName[0] == 'n' && // If it's a 'null'
4145 defineName[1] == 'u' &&
4146 defineName[2] == 'l' &&
4147 defineName[3] == 'l') {
4151 else if (defineName.length == 5) { // If it's a 'false'
4152 if (defineName[0] == 'f' &&
4153 defineName[1] == 'a' &&
4154 defineName[2] == 'l' &&
4155 defineName[3] == 's' &&
4156 defineName[4] == 'e') {
4161 if (defineName != null) {
4162 for (int i = 0; i < defineName.length; i++) {
4163 if (Character.isLowerCase (defineName[i])) {
4164 problemReporter.phpUppercaseIdentifierWarning (startPos, endPos, referenceContext,
4165 compilationUnit.compilationResult);
4171 // TODO is this ok ?
4173 // throwSyntaxError("'(' expected in function call.");
4176 if (token == TokenName.MINUS_GREATER) {
4181 variable_properties();
4184 // A colon is only allowed here if it is an expression read after a '?'
4186 if ((token == TokenName.COLON) &&
4188 throwSyntaxError ("No ':' allowed");
4194 private void method_or_not() {
4196 // '(' function_call_parameter_list ')'
4198 if (Scanner.TRACE) {
4199 System.out.println("TRACE: method_or_not()");
4201 if (token == TokenName.LPAREN) {
4203 if (token == TokenName.RPAREN) {
4207 non_empty_function_call_parameter_list();
4208 if (token != TokenName.RPAREN) {
4209 throwSyntaxError("')' expected in method_or_not.");
4215 private void exit_expr() {
4219 if (token != TokenName.LPAREN) {
4223 if (token == TokenName.RPAREN) {
4228 if (token != TokenName.RPAREN) {
4229 throwSyntaxError("')' expected after keyword 'exit'");
4234 // private void encaps_list() {
4235 // // encaps_list encaps_var
4236 // // | encaps_list T_STRING
4237 // // | encaps_list T_NUM_STRING
4238 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
4239 // // | encaps_list T_CHARACTER
4240 // // | encaps_list T_BAD_CHARACTER
4241 // // | encaps_list '['
4242 // // | encaps_list ']'
4243 // // | encaps_list '{'
4244 // // | encaps_list '}'
4245 // // | encaps_list T_OBJECT_OPERATOR
4249 // case TokenName.STRING:
4252 // case TokenName.LBRACE:
4253 // // scanner.encapsedStringStack.pop();
4256 // case TokenName.RBRACE:
4257 // // scanner.encapsedStringStack.pop();
4260 // case TokenName.LBRACKET:
4261 // // scanner.encapsedStringStack.pop();
4264 // case TokenName.RBRACKET:
4265 // // scanner.encapsedStringStack.pop();
4268 // case TokenName.MINUS_GREATER:
4269 // // scanner.encapsedStringStack.pop();
4272 // case TokenName.Variable:
4273 // case TokenName.DOLLAR_LBRACE:
4274 // case TokenName.LBRACE_DOLLAR:
4278 // char encapsedChar = ((Character)
4279 // scanner.encapsedStringStack.peek()).charValue();
4280 // if (encapsedChar == '$') {
4281 // scanner.encapsedStringStack.pop();
4282 // encapsedChar = ((Character)
4283 // scanner.encapsedStringStack.peek()).charValue();
4284 // switch (encapsedChar) {
4286 // if (token == TokenName.EncapsedString0) {
4289 // token = TokenName.STRING;
4292 // if (token == TokenName.EncapsedString1) {
4295 // token = TokenName.STRING;
4298 // if (token == TokenName.EncapsedString2) {
4301 // token = TokenName.STRING;
4310 // private void encaps_var() {
4312 // // | T_VARIABLE '[' encaps_var_offset ']'
4313 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
4314 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
4315 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
4316 // // | T_CURLY_OPEN variable '}'
4318 // case TokenName.Variable:
4320 // if (token == TokenName.LBRACKET) {
4322 // expr(); //encaps_var_offset();
4323 // if (token != TokenName.RBRACKET) {
4324 // throwSyntaxError("']' expected after variable.");
4326 // // scanner.encapsedStringStack.pop();
4329 // } else if (token == TokenName.MINUS_GREATER) {
4331 // if (token != TokenName.Identifier) {
4332 // throwSyntaxError("Identifier expected after '->'.");
4334 // // scanner.encapsedStringStack.pop();
4338 // // // scanner.encapsedStringStack.pop();
4339 // // int tempToken = TokenName.STRING;
4340 // // if (!scanner.encapsedStringStack.isEmpty()
4341 // // && (token == TokenName.EncapsedString0
4342 // // || token == TokenName.EncapsedString1
4343 // // || token == TokenName.EncapsedString2 || token ==
4344 // // TokenName.ERROR)) {
4345 // // char encapsedChar = ((Character)
4346 // // scanner.encapsedStringStack.peek())
4348 // // switch (token) {
4349 // // case TokenName.EncapsedString0 :
4350 // // if (encapsedChar == '`') {
4351 // // tempToken = TokenName.EncapsedString0;
4354 // // case TokenName.EncapsedString1 :
4355 // // if (encapsedChar == '\'') {
4356 // // tempToken = TokenName.EncapsedString1;
4359 // // case TokenName.EncapsedString2 :
4360 // // if (encapsedChar == '"') {
4361 // // tempToken = TokenName.EncapsedString2;
4364 // // case TokenName.ERROR :
4365 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
4366 // // scanner.currentPosition--;
4367 // // getNextToken();
4372 // // token = tempToken;
4375 // case TokenName.DOLLAR_LBRACE:
4377 // if (token == TokenName.DOLLAR_LBRACE) {
4379 // } else if (token == TokenName.Identifier) {
4381 // if (token == TokenName.LBRACKET) {
4383 // // if (token == TokenName.RBRACKET) {
4384 // // getNextToken();
4387 // if (token != TokenName.RBRACKET) {
4388 // throwSyntaxError("']' expected after '${'.");
4396 // if (token != TokenName.RBRACE) {
4397 // throwSyntaxError("'}' expected.");
4401 // case TokenName.LBRACE_DOLLAR:
4403 // if (token == TokenName.LBRACE_DOLLAR) {
4405 // } else if (token == TokenName.Identifier || token > TokenName.KEYWORD) {
4407 // if (token == TokenName.LBRACKET) {
4409 // // if (token == TokenName.RBRACKET) {
4410 // // getNextToken();
4413 // if (token != TokenName.RBRACKET) {
4414 // throwSyntaxError("']' expected.");
4418 // } else if (token == TokenName.MINUS_GREATER) {
4420 // if (token != TokenName.Identifier && token != TokenName.Variable) {
4421 // throwSyntaxError("String or Variable token expected.");
4424 // if (token == TokenName.LBRACKET) {
4426 // // if (token == TokenName.RBRACKET) {
4427 // // getNextToken();
4430 // if (token != TokenName.RBRACKET) {
4431 // throwSyntaxError("']' expected after '${'.");
4437 // // if (token != TokenName.RBRACE) {
4438 // // throwSyntaxError("'}' expected after '{$'.");
4440 // // // scanner.encapsedStringStack.pop();
4441 // // getNextToken();
4444 // if (token != TokenName.RBRACE) {
4445 // throwSyntaxError("'}' expected.");
4447 // // scanner.encapsedStringStack.pop();
4454 // private void encaps_var_offset() {
4456 // // | T_NUM_STRING
4459 // case TokenName.STRING:
4462 // case TokenName.IntegerLiteral:
4465 // case TokenName.Variable:
4468 // case TokenName.Identifier:
4472 // throwSyntaxError("Variable or String token expected.");
4480 private void internal_functions_in_yacc() {
4483 // case TokenName.isset:
4484 // // T_ISSET '(' isset_variables ')'
4486 // if (token != TokenName.LPAREN) {
4487 // throwSyntaxError("'(' expected after keyword 'isset'");
4490 // isset_variables();
4491 // if (token != TokenName.RPAREN) {
4492 // throwSyntaxError("')' expected after keyword 'isset'");
4496 // case TokenName.empty:
4497 // // T_EMPTY '(' variable ')'
4499 // if (token != TokenName.LPAREN) {
4500 // throwSyntaxError("'(' expected after keyword 'empty'");
4504 // if (token != TokenName.RPAREN) {
4505 // throwSyntaxError("')' expected after keyword 'empty'");
4511 checkFileName(token);
4514 // T_INCLUDE_ONCE expr
4515 checkFileName(token);
4518 // T_EVAL '(' expr ')'
4520 if (token != TokenName.LPAREN) {
4521 throwSyntaxError("'(' expected after keyword 'eval'");
4525 if (token != TokenName.RPAREN) {
4526 throwSyntaxError("')' expected after keyword 'eval'");
4532 checkFileName(token);
4535 // T_REQUIRE_ONCE expr
4536 checkFileName(token);
4542 * Parse and check the include file name
4544 * @param includeToken
4546 private void checkFileName(TokenName includeToken) {
4547 // <include-token> expr
4548 int start = scanner.getCurrentTokenStartPosition();
4549 boolean hasLPAREN = false;
4551 if (token == TokenName.LPAREN) {
4555 Expression expression = expr();
4557 if (token == TokenName.RPAREN) {
4560 throwSyntaxError("')' expected for keyword '"
4561 + scanner.toStringAction(includeToken) + "'");
4564 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4566 if (scanner.compilationUnit != null) {
4567 IResource resource = scanner.compilationUnit.getResource();
4568 if (resource != null && resource instanceof IFile) {
4569 file = (IFile) resource;
4573 tokens = new char[1][];
4574 tokens[0] = currTokenSource;
4576 ImportReference impt = new ImportReference(tokens, currTokenSource,
4577 start, scanner.getCurrentTokenEndPosition(), false);
4578 impt.declarationSourceEnd = impt.sourceEnd;
4579 impt.declarationEnd = impt.declarationSourceEnd;
4580 // endPosition is just before the ;
4581 impt.declarationSourceStart = start;
4582 includesList.add(impt);
4584 if (expression instanceof StringLiteral) {
4585 StringLiteral literal = (StringLiteral) expression;
4586 char[] includeName = literal.source();
4587 if (includeName.length == 0) {
4588 reportSyntaxError("Empty filename after keyword '"
4589 + scanner.toStringAction(includeToken) + "'",
4590 literal.sourceStart, literal.sourceStart + 1);
4592 String includeNameString = new String(includeName);
4593 if (literal instanceof StringLiteralDQ) {
4594 if (includeNameString.indexOf('$') >= 0) {
4595 // assuming that the filename contains a variable => no
4600 if (includeNameString.startsWith("http://")) {
4601 // assuming external include location
4605 // check the filename:
4606 // System.out.println(new
4607 // String(compilationUnit.getFileName())+" - "+
4608 // expression.toStringExpression());
4609 IProject project = file.getProject();
4610 if (project != null) {
4611 IPath path = PHPFileUtil.determineFilePath(
4612 includeNameString, file, project);
4615 // SyntaxError: "File: << >> doesn't exist in project."
4616 String[] args = { expression.toStringExpression(),
4617 project.getFullPath().toString() };
4618 problemReporter.phpIncludeNotExistWarning(args,
4619 literal.sourceStart, literal.sourceEnd,
4621 compilationUnit.compilationResult);
4624 String filePath = path.toString();
4625 String ext = file.getRawLocation()
4626 .getFileExtension();
4627 int fileExtensionLength = ext == null ? 0 : ext
4630 IFile f = PHPFileUtil.createFile(path, project);
4632 impt.tokens = CharOperation.splitOn('/', filePath
4633 .toCharArray(), 0, filePath.length()
4634 - fileExtensionLength);
4636 } catch (Exception e) {
4637 // the file is outside of the workspace
4645 private void isset_variables() {
4647 // | isset_variables ','
4648 if (token == TokenName.RPAREN) {
4649 throwSyntaxError("Variable expected after keyword 'isset'");
4652 variable(true, false);
4653 if (token == TokenName.COMMA) {
4661 private boolean common_scalar() {
4665 // | T_CONSTANT_ENCAPSED_STRING
4672 case INTEGERLITERAL:
4678 case STRINGDOUBLEQUOTE:
4681 case STRINGSINGLEQUOTE:
4684 case STRINGINTERPOLATED:
4706 // private void scalar() {
4709 // // | T_STRING_VARNAME
4710 // // | class_constant
4711 // // | common_scalar
4712 // // | '"' encaps_list '"'
4713 // // | '\'' encaps_list '\''
4714 // // | T_START_HEREDOC encaps_list T_END_HEREDOC
4715 // throwSyntaxError("Not yet implemented (scalar).");
4718 private void static_scalar() {
4719 // static_scalar: /* compile-time evaluated scalars */
4722 // | '+' static_scalar
4723 // | '-' static_scalar
4724 // | T_ARRAY '(' static_array_pair_list ')'
4725 // | static_class_constant
4726 if (common_scalar()) {
4732 // static_class_constant:
4733 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4734 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
4736 if (token == TokenName.IDENTIFIER) {
4739 throwSyntaxError("Identifier expected after '::' operator.");
4743 case ENCAPSEDSTRING0:
4745 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4746 while (scanner.currentCharacter != '`') {
4747 if (scanner.currentCharacter == '\\') {
4748 scanner.currentPosition++;
4750 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4753 } catch (IndexOutOfBoundsException e) {
4754 throwSyntaxError("'`' expected at end of static string.");
4757 // case TokenName.EncapsedString1:
4759 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4760 // while (scanner.currentCharacter != '\'') {
4761 // if (scanner.currentCharacter == '\\') {
4762 // scanner.currentPosition++;
4764 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4767 // } catch (IndexOutOfBoundsException e) {
4768 // throwSyntaxError("'\'' expected at end of static string.");
4771 // case TokenName.EncapsedString2:
4773 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4774 // while (scanner.currentCharacter != '"') {
4775 // if (scanner.currentCharacter == '\\') {
4776 // scanner.currentPosition++;
4778 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4781 // } catch (IndexOutOfBoundsException e) {
4782 // throwSyntaxError("'\"' expected at end of static string.");
4785 case STRINGSINGLEQUOTE:
4788 case STRINGDOUBLEQUOTE:
4801 if (token != TokenName.LPAREN) {
4802 throwSyntaxError("'(' expected after keyword 'array'");
4805 if (token == TokenName.RPAREN) {
4809 non_empty_static_array_pair_list();
4810 if (token != TokenName.RPAREN) {
4811 throwSyntaxError("')' or ',' expected after keyword 'array'");
4815 // case TokenName.null :
4818 // case TokenName.false :
4821 // case TokenName.true :
4825 throwSyntaxError("Static scalar/constant expected.");
4829 private void non_empty_static_array_pair_list() {
4830 // non_empty_static_array_pair_list:
4831 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4833 // | non_empty_static_array_pair_list ',' static_scalar
4834 // | static_scalar T_DOUBLE_ARROW static_scalar
4838 if (token == TokenName.EQUAL_GREATER) {
4842 if (token != TokenName.COMMA) {
4846 if (token == TokenName.RPAREN) {
4852 // public void reportSyntaxError() { //int act, int currentKind, int
4853 // // stateStackTop) {
4854 // /* remember current scanner position */
4855 // int startPos = scanner.startPosition;
4856 // int currentPos = scanner.currentPosition;
4858 // this.checkAndReportBracketAnomalies(problemReporter());
4859 // /* reset scanner where it was */
4860 // scanner.startPosition = startPos;
4861 // scanner.currentPosition = currentPos;
4864 public static final int RoundBracket = 0;
4866 public static final int SquareBracket = 1;
4868 public static final int CurlyBracket = 2;
4870 public static final int BracketKinds = 3;
4872 protected int[] nestedMethod; // the ptr is nestedType
4874 protected int nestedType, dimensions;
4876 // variable set stack
4877 final static int VariableStackIncrement = 10;
4879 HashMap fTypeVariables = null;
4881 HashMap fMethodVariables = null;
4883 ArrayList fStackUnassigned = new ArrayList();
4886 final static int AstStackIncrement = 100;
4888 protected int astPtr;
4890 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4892 protected int astLengthPtr;
4894 protected int[] astLengthStack;
4896 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4898 public CompilationUnitDeclaration compilationUnit; /*
4903 protected ReferenceContext referenceContext;
4905 protected ProblemReporter problemReporter;
4907 protected CompilerOptions options;
4909 private ArrayList includesList;
4911 // protected CompilationResult compilationResult;
4913 * Returns this parser's problem reporter initialized with its reference
4914 * context. Also it is assumed that a problem is going to be reported, so
4915 * initializes the compilation result's line positions.
4917 public ProblemReporter problemReporter() {
4918 if (scanner.recordLineSeparator) {
4919 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4922 problemReporter.referenceContext = referenceContext;
4923 return problemReporter;
4927 * Reconsider the entire source looking for inconsistencies in {} () []
4929 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4930 // problemReporter) {
4931 // scanner.wasAcr = false;
4932 // boolean anomaliesDetected = false;
4934 // char[] source = scanner.source;
4935 // int[] leftCount = { 0, 0, 0 };
4936 // int[] rightCount = { 0, 0, 0 };
4937 // int[] depths = { 0, 0, 0 };
4938 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4941 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4943 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4945 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4947 // scanner.currentPosition = scanner.initialPosition; //starting
4949 // // (first-zero-based
4951 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4956 // // ---------Consume white space and handles
4957 // // startPosition---------
4958 // boolean isWhiteSpace;
4960 // scanner.startPosition = scanner.currentPosition;
4961 // // if (((scanner.currentCharacter =
4962 // // source[scanner.currentPosition++]) == '\\') &&
4963 // // (source[scanner.currentPosition] == 'u')) {
4964 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4966 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4967 // (scanner.currentCharacter == '\n'))) {
4968 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4969 // // only record line positions we have not
4971 // scanner.pushLineSeparator();
4974 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4976 // } while (isWhiteSpace && (scanner.currentPosition <
4977 // scanner.eofPosition));
4978 // // -------consume token until } is found---------
4979 // switch (scanner.currentCharacter) {
4981 // int index = leftCount[CurlyBracket]++;
4982 // if (index == leftPositions[CurlyBracket].length) {
4983 // System.arraycopy(leftPositions[CurlyBracket], 0,
4984 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4985 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4986 // new int[index * 2]), 0, index);
4988 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4989 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4993 // int index = rightCount[CurlyBracket]++;
4994 // if (index == rightPositions[CurlyBracket].length) {
4995 // System.arraycopy(rightPositions[CurlyBracket], 0,
4996 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4997 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
4999 // new int[index * 2]), 0, index);
5001 // rightPositions[CurlyBracket][index] = scanner.startPosition;
5002 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
5006 // int index = leftCount[RoundBracket]++;
5007 // if (index == leftPositions[RoundBracket].length) {
5008 // System.arraycopy(leftPositions[RoundBracket], 0,
5009 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
5010 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
5011 // new int[index * 2]), 0, index);
5013 // leftPositions[RoundBracket][index] = scanner.startPosition;
5014 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
5018 // int index = rightCount[RoundBracket]++;
5019 // if (index == rightPositions[RoundBracket].length) {
5020 // System.arraycopy(rightPositions[RoundBracket], 0,
5021 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
5022 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
5024 // new int[index * 2]), 0, index);
5026 // rightPositions[RoundBracket][index] = scanner.startPosition;
5027 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
5031 // int index = leftCount[SquareBracket]++;
5032 // if (index == leftPositions[SquareBracket].length) {
5033 // System.arraycopy(leftPositions[SquareBracket], 0,
5034 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
5035 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
5037 // new int[index * 2]), 0, index);
5039 // leftPositions[SquareBracket][index] = scanner.startPosition;
5040 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
5044 // int index = rightCount[SquareBracket]++;
5045 // if (index == rightPositions[SquareBracket].length) {
5046 // System.arraycopy(rightPositions[SquareBracket], 0,
5047 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
5048 // System.arraycopy(rightDepths[SquareBracket], 0,
5049 // (rightDepths[SquareBracket]
5050 // = new int[index * 2]), 0, index);
5052 // rightPositions[SquareBracket][index] = scanner.startPosition;
5053 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
5057 // if (scanner.getNextChar('\\')) {
5058 // scanner.scanEscapeCharacter();
5059 // } else { // consume next character
5060 // scanner.unicodeAsBackSlash = false;
5061 // // if (((scanner.currentCharacter =
5062 // // source[scanner.currentPosition++]) ==
5064 // // (source[scanner.currentPosition] ==
5066 // // scanner.getNextUnicodeChar();
5068 // if (scanner.withoutUnicodePtr != 0) {
5069 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5070 // scanner.currentCharacter;
5074 // scanner.getNextChar('\'');
5078 // // consume next character
5079 // scanner.unicodeAsBackSlash = false;
5080 // // if (((scanner.currentCharacter =
5081 // // source[scanner.currentPosition++]) == '\\') &&
5082 // // (source[scanner.currentPosition] == 'u')) {
5083 // // scanner.getNextUnicodeChar();
5085 // if (scanner.withoutUnicodePtr != 0) {
5086 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5087 // scanner.currentCharacter;
5090 // while (scanner.currentCharacter != '"') {
5091 // if (scanner.currentCharacter == '\r') {
5092 // if (source[scanner.currentPosition] == '\n')
5093 // scanner.currentPosition++;
5094 // break; // the string cannot go further that
5097 // if (scanner.currentCharacter == '\n') {
5098 // break; // the string cannot go further that
5101 // if (scanner.currentCharacter == '\\') {
5102 // scanner.scanEscapeCharacter();
5104 // // consume next character
5105 // scanner.unicodeAsBackSlash = false;
5106 // // if (((scanner.currentCharacter =
5107 // // source[scanner.currentPosition++]) == '\\')
5108 // // && (source[scanner.currentPosition] == 'u'))
5110 // // scanner.getNextUnicodeChar();
5112 // if (scanner.withoutUnicodePtr != 0) {
5113 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5114 // scanner.currentCharacter;
5121 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
5123 // //get the next char
5124 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5126 // && (source[scanner.currentPosition] == 'u')) {
5127 // //-------------unicode traitement
5129 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5130 // scanner.currentPosition++;
5131 // while (source[scanner.currentPosition] == 'u') {
5132 // scanner.currentPosition++;
5134 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5136 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5139 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5142 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5144 // || c4 < 0) { //error
5148 // scanner.currentCharacter = 'A';
5149 // } //something different from \n and \r
5151 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5154 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
5156 // //get the next char
5157 // scanner.startPosition = scanner.currentPosition;
5158 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5160 // && (source[scanner.currentPosition] == 'u')) {
5161 // //-------------unicode traitement
5163 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5164 // scanner.currentPosition++;
5165 // while (source[scanner.currentPosition] == 'u') {
5166 // scanner.currentPosition++;
5168 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5170 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5173 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5176 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5178 // || c4 < 0) { //error
5182 // scanner.currentCharacter = 'A';
5183 // } //something different from \n
5186 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5190 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
5191 // (scanner.currentCharacter == '\n'))) {
5192 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
5193 // // only record line positions we
5194 // // have not recorded yet
5195 // scanner.pushLineSeparator();
5196 // if (this.scanner.taskTags != null) {
5197 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5199 // .getCurrentTokenEndPosition());
5205 // if (test > 0) { //traditional and annotation
5207 // boolean star = false;
5208 // // consume next character
5209 // scanner.unicodeAsBackSlash = false;
5210 // // if (((scanner.currentCharacter =
5211 // // source[scanner.currentPosition++]) ==
5213 // // (source[scanner.currentPosition] ==
5215 // // scanner.getNextUnicodeChar();
5217 // if (scanner.withoutUnicodePtr != 0) {
5218 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5219 // scanner.currentCharacter;
5222 // if (scanner.currentCharacter == '*') {
5225 // //get the next char
5226 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5228 // && (source[scanner.currentPosition] == 'u')) {
5229 // //-------------unicode traitement
5231 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5232 // scanner.currentPosition++;
5233 // while (source[scanner.currentPosition] == 'u') {
5234 // scanner.currentPosition++;
5236 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5238 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5241 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5244 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5246 // || c4 < 0) { //error
5250 // scanner.currentCharacter = 'A';
5251 // } //something different from * and /
5253 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5256 // //loop until end of comment */
5257 // while ((scanner.currentCharacter != '/') || (!star)) {
5258 // star = scanner.currentCharacter == '*';
5260 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5262 // && (source[scanner.currentPosition] == 'u')) {
5263 // //-------------unicode traitement
5265 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5266 // scanner.currentPosition++;
5267 // while (source[scanner.currentPosition] == 'u') {
5268 // scanner.currentPosition++;
5270 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5272 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5275 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5278 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5280 // || c4 < 0) { //error
5284 // scanner.currentCharacter = 'A';
5285 // } //something different from * and
5288 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5292 // if (this.scanner.taskTags != null) {
5293 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5294 // this.scanner.getCurrentTokenEndPosition());
5301 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
5302 // scanner.scanIdentifierOrKeyword(false);
5305 // if (Character.isDigit(scanner.currentCharacter)) {
5306 // scanner.scanNumber(false);
5310 // //-----------------end switch while
5311 // // try--------------------
5312 // } catch (IndexOutOfBoundsException e) {
5313 // break; // read until EOF
5314 // } catch (InvalidInputException e) {
5315 // return false; // no clue
5318 // if (scanner.recordLineSeparator) {
5319 // compilationUnit.compilationResult.lineSeparatorPositions =
5320 // scanner.getLineEnds();
5322 // // check placement anomalies against other kinds of brackets
5323 // for (int kind = 0; kind < BracketKinds; kind++) {
5324 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
5325 // int start = leftPositions[kind][leftIndex]; // deepest
5327 // // find matching closing bracket
5328 // int depth = leftDepths[kind][leftIndex];
5330 // for (int i = 0; i < rightCount[kind]; i++) {
5331 // int pos = rightPositions[kind][i];
5332 // // want matching bracket further in source with same
5334 // if ((pos > start) && (depth == rightDepths[kind][i])) {
5339 // if (end < 0) { // did not find a good closing match
5340 // problemReporter.unmatchedBracket(start, referenceContext,
5341 // compilationUnit.compilationResult);
5344 // // check if even number of opening/closing other brackets
5345 // // in between this pair of brackets
5347 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
5349 // for (int i = 0; i < leftCount[otherKind]; i++) {
5350 // int pos = leftPositions[otherKind][i];
5351 // if ((pos > start) && (pos < end))
5354 // for (int i = 0; i < rightCount[otherKind]; i++) {
5355 // int pos = rightPositions[otherKind][i];
5356 // if ((pos > start) && (pos < end))
5359 // if (balance != 0) {
5360 // problemReporter.unmatchedBracket(start, referenceContext,
5361 // compilationUnit.compilationResult); //bracket
5367 // // too many opening brackets ?
5368 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
5369 // anomaliesDetected = true;
5370 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
5372 // 1], referenceContext,
5373 // compilationUnit.compilationResult);
5375 // // too many closing brackets ?
5376 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
5377 // anomaliesDetected = true;
5378 // problemReporter.unmatchedBracket(rightPositions[kind][i],
5379 // referenceContext,
5380 // compilationUnit.compilationResult);
5382 // if (anomaliesDetected)
5385 // return anomaliesDetected;
5386 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
5387 // return anomaliesDetected;
5388 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
5389 // return anomaliesDetected;
5392 // protected void pushOnAstLengthStack(int pos) {
5394 // astLengthStack[++astLengthPtr] = pos;
5395 // } catch (IndexOutOfBoundsException e) {
5396 // int oldStackLength = astLengthStack.length;
5397 // int[] oldPos = astLengthStack;
5398 // astLengthStack = new int[oldStackLength + StackIncrement];
5399 // System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5400 // astLengthStack[astLengthPtr] = pos;
5404 protected void pushOnAstStack(ASTNode node) {
5406 * add a new obj on top of the ast stack
5409 astStack[++astPtr] = node;
5410 } catch (IndexOutOfBoundsException e) {
5411 int oldStackLength = astStack.length;
5412 ASTNode[] oldStack = astStack;
5413 astStack = new ASTNode[oldStackLength + AstStackIncrement];
5414 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
5415 astPtr = oldStackLength;
5416 astStack[astPtr] = node;
5419 astLengthStack[++astLengthPtr] = 1;
5420 } catch (IndexOutOfBoundsException e) {
5421 int oldStackLength = astLengthStack.length;
5422 int[] oldPos = astLengthStack;
5423 astLengthStack = new int[oldStackLength + AstStackIncrement];
5424 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5425 astLengthStack[astLengthPtr] = 1;
5429 protected void resetModifiers() {
5430 this.modifiers = AccDefault;
5431 this.modifiersSourceStart = -1; // <-- see comment into
5432 // modifiersFlag(int)
5433 this.scanner.commentPtr = -1;
5436 protected void consumePackageDeclarationName(IFile file) {
5437 // create a package name similar to java package names
5439 //String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
5441 //String filePath = file.getFullPath().toString();
5443 String ext = file.getFileExtension();
5444 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
5445 ImportReference impt;
5448 /*if (filePath.startsWith(projectPath)) {
5449 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
5450 projectPath.length() + 1, filePath.length()
5451 - fileExtensionLength);
5453 String name = file.getName();
5454 tokens = new char[1][];
5455 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5459 this.compilationUnit.currentPackage = impt = new ImportReference(
5460 tokens, new char[0], 0, 0, true);
5462 impt.declarationSourceStart = 0;
5463 impt.declarationSourceEnd = 0;
5464 impt.declarationEnd = 0;
5465 // endPosition is just before the ;
5469 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5470 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5476 private void pushFunctionVariableSet() {
5477 HashSet set = new HashSet();
5478 if (fStackUnassigned.isEmpty()) {
5479 for (int i = 0; i < GLOBALS.length; i++) {
5480 set.add(GLOBALS[i]);
5483 fStackUnassigned.add(set);
5486 private void pushIfVariableSet() {
5487 if (!fStackUnassigned.isEmpty()) {
5488 HashSet set = new HashSet();
5489 fStackUnassigned.add(set);
5493 private HashSet removeIfVariableSet() {
5494 if (!fStackUnassigned.isEmpty()) {
5495 return (HashSet) fStackUnassigned
5496 .remove(fStackUnassigned.size() - 1);
5502 * Returns the <i>set of assigned variables </i> returns null if no Set is
5503 * defined at the current scanner position
5505 private HashSet peekVariableSet() {
5506 if (!fStackUnassigned.isEmpty()) {
5507 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5513 * add the current identifier source to the <i>set of assigned variables
5518 private void addVariableSet(HashSet set) {
5520 set.add(new String(scanner.getCurrentTokenSource()));
5525 * add the current identifier source to the <i>set of assigned variables
5529 private void addVariableSet() {
5530 HashSet set = peekVariableSet();
5532 set.add(new String(scanner.getCurrentTokenSource()));
5537 * add the current identifier source to the <i>set of assigned variables
5541 private void addVariableSet(char[] token) {
5542 HashSet set = peekVariableSet();
5544 set.add(new String(token));
5549 * check if the current identifier source is in the <i>set of assigned
5550 * variables </i> Returns true, if no set is defined for the current scanner
5554 private boolean containsVariableSet() {
5555 return containsVariableSet(scanner.getCurrentTokenSource());
5558 private boolean containsVariableSet(char[] token) {
5560 if (!fStackUnassigned.isEmpty()) {
5562 String str = new String(token);
5563 for (int i = 0; i < fStackUnassigned.size(); i++) {
5564 set = (HashSet) fStackUnassigned.get(i);
5565 if (set.contains(str)) {