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 else if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
957 if (token != TokenName.IDENTIFIER) {
958 throwSyntaxError("identifier expected after '::'.");
962 if (token != TokenName.INLINE_HTML) {
963 throwSyntaxError("';' expected after 'static' statement.");
971 if (token == TokenName.LPAREN) {
974 throwSyntaxError("'(' expected after 'unset' statement.");
977 if (token == TokenName.RPAREN) {
980 throwSyntaxError("')' expected after 'unset' statement.");
982 if (token == TokenName.SEMICOLON) {
985 if (token != TokenName.INLINE_HTML) {
986 throwSyntaxError("';' expected after 'unset' statement.");
996 if (token == TokenName.SEMICOLON) { // After the namespace identifier there is a ';'
999 else if (token == TokenName.LBRACE) { // or a '{'
1000 getNextToken(); // set to next token
1002 if (token != TokenName.RBRACE) { // if next token is not a '}'
1003 statementList(); // read the entire block
1006 if (token == TokenName.RBRACE) { // If the end is a '}'
1007 getNextToken(); // go for the next token
1009 else { // Not a '}' as expected
1010 throwSyntaxError("'}' expected after 'do' keyword.");
1014 if (token != TokenName.INLINE_HTML) {
1015 throwSyntaxError("';' expected after 'namespace' statement.");
1022 getNextToken (); // This should get the label
1024 if (token == TokenName.IDENTIFIER) {
1028 throwSyntaxError("expected a label after goto");
1031 if (token == TokenName.SEMICOLON) { // After the 'goto' label name there is a ';'
1035 throwSyntaxError("expected a ';' after goto label");
1040 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
1041 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1042 methodDecl.modifiers = AccDefault;
1043 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
1046 functionDefinition(methodDecl);
1048 sourceEnd = methodDecl.sourceEnd;
1049 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1050 sourceEnd = methodDecl.declarationSourceStart + 1;
1052 methodDecl.declarationSourceEnd = sourceEnd;
1053 methodDecl.sourceEnd = sourceEnd;
1058 // T_DECLARE '(' declare_list ')' declare_statement
1060 if (token != TokenName.LPAREN) {
1061 throwSyntaxError("'(' expected in 'declare' statement.");
1065 if (token != TokenName.RPAREN) {
1066 throwSyntaxError("')' expected in 'declare' statement.");
1069 declare_statement();
1074 if (token != TokenName.LBRACE) {
1075 throwSyntaxError("'{' expected in 'try' statement.");
1080 if (token != TokenName.RBRACE) { // Process the statement only if there is (possibly) a statement
1083 if (token != TokenName.RBRACE) {
1084 throwSyntaxError("'}' expected in 'try' statement.");
1093 if (token != TokenName.LPAREN) {
1094 throwSyntaxError("'(' expected in 'catch' statement.");
1097 fully_qualified_class_name();
1098 if (token != TokenName.VARIABLE) {
1099 throwSyntaxError("Variable expected in 'catch' statement.");
1103 if (token != TokenName.RPAREN) {
1104 throwSyntaxError("')' expected in 'catch' statement.");
1107 if (token != TokenName.LBRACE) {
1108 throwSyntaxError("'{' expected in 'catch' statement.");
1111 if (token != TokenName.RBRACE) {
1113 if (token != TokenName.RBRACE) {
1114 throwSyntaxError("'}' expected in 'catch' statement.");
1118 additional_catches();
1124 if (token == TokenName.SEMICOLON) {
1127 throwSyntaxError("';' expected after 'throw' exxpression.");
1136 TypeDeclaration typeDecl = new TypeDeclaration (this.compilationUnit.compilationResult);
1137 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1138 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1139 typeDecl.name = new char[] { ' ' };
1140 // default super class
1141 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
1142 compilationUnit.types.add(typeDecl);
1143 pushOnAstStack(typeDecl);
1144 unticked_class_declaration_statement(typeDecl);
1154 if (token != TokenName.RBRACE) {
1155 statement = statementList();
1157 if (token == TokenName.RBRACE) {
1161 throwSyntaxError("'}' expected.");
1166 if (token != TokenName.SEMICOLON) {
1170 if (token == TokenName.SEMICOLON) {
1174 else if (token == TokenName.COLON) { // Colon after Label identifier
1179 if (token == TokenName.RBRACE) {
1180 reportSyntaxError ("';' expected after expression (Found token: "
1181 + scanner.toStringAction(token) + ")");
1184 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
1187 if (token != TokenName.IDENTIFIER) {
1188 throwSyntaxError("identifier expected after '::'.");
1194 else if (token != TokenName.INLINE_HTML && token != TokenName.EOF) {
1195 throwSyntaxError ("';' expected after expression (Found token: "
1196 + scanner.toStringAction(token) + ")");
1207 private void declare_statement() {
1209 // | ':' inner_statement_list T_ENDDECLARE ';'
1211 if (token == TokenName.COLON) {
1213 // TODO: implement inner_statement_list();
1215 if (token != TokenName.ENDDECLARE) {
1216 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1219 if (token != TokenName.SEMICOLON) {
1220 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1228 private void declare_list() {
1229 // T_STRING '=' static_scalar
1230 // | declare_list ',' T_STRING '=' static_scalar
1232 if (token != TokenName.IDENTIFIER) {
1233 throwSyntaxError("Identifier expected in 'declare' list.");
1236 if (token != TokenName.EQUAL) {
1237 throwSyntaxError("'=' expected in 'declare' list.");
1241 if (token != TokenName.COMMA) {
1248 private void additional_catches() {
1249 while (token == TokenName.CATCH) {
1251 if (token != TokenName.LPAREN) {
1252 throwSyntaxError("'(' expected in 'catch' statement.");
1255 fully_qualified_class_name();
1256 if (token != TokenName.VARIABLE) {
1257 throwSyntaxError("Variable expected in 'catch' statement.");
1261 if (token != TokenName.RPAREN) {
1262 throwSyntaxError("')' expected in 'catch' statement.");
1265 if (token != TokenName.LBRACE) {
1266 throwSyntaxError("'{' expected in 'catch' statement.");
1269 if (token != TokenName.RBRACE) {
1272 if (token != TokenName.RBRACE) {
1273 throwSyntaxError("'}' expected in 'catch' statement.");
1279 private void foreach_variable() {
1282 if (token == TokenName.OP_AND) {
1288 private void foreach_optional_arg() {
1290 // | T_DOUBLE_ARROW foreach_variable
1291 if (token == TokenName.EQUAL_GREATER) {
1297 private void global_var_list() {
1299 // global_var_list ',' global_var
1301 HashSet set = peekVariableSet();
1304 if (token != TokenName.COMMA) {
1311 private void global_var(HashSet set) {
1315 // | '$' '{' expr '}'
1316 if (token == TokenName.VARIABLE) {
1317 if (fMethodVariables != null) {
1318 VariableInfo info = new VariableInfo(scanner
1319 .getCurrentTokenStartPosition(),
1320 VariableInfo.LEVEL_GLOBAL_VAR);
1321 fMethodVariables.put(new String(scanner
1322 .getCurrentIdentifierSource()), info);
1324 addVariableSet(set);
1326 } else if (token == TokenName.DOLLAR) {
1328 if (token == TokenName.LBRACE) {
1331 if (token != TokenName.RBRACE) {
1332 throwSyntaxError("'}' expected in global variable.");
1341 private void static_var_list() {
1343 // static_var_list ',' T_VARIABLE
1344 // | static_var_list ',' T_VARIABLE '=' static_scalar
1346 // | T_VARIABLE '=' static_scalar,
1347 HashSet set = peekVariableSet();
1349 if (token == TokenName.VARIABLE) {
1350 if (fMethodVariables != null) {
1351 VariableInfo info = new VariableInfo(scanner
1352 .getCurrentTokenStartPosition(),
1353 VariableInfo.LEVEL_STATIC_VAR);
1354 fMethodVariables.put(new String(scanner
1355 .getCurrentIdentifierSource()), info);
1357 addVariableSet(set);
1359 if (token == TokenName.EQUAL) {
1363 if (token != TokenName.COMMA) {
1373 private void unset_variables() {
1376 // | unset_variables ',' unset_variable
1380 variable(false, false);
1381 if (token != TokenName.COMMA) {
1388 private final void initializeModifiers() {
1390 this.modifiersSourceStart = -1;
1393 private final void checkAndSetModifiers(int flag) {
1394 this.modifiers |= flag;
1395 if (this.modifiersSourceStart < 0)
1396 this.modifiersSourceStart = this.scanner.startPosition;
1399 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1400 initializeModifiers();
1401 if (token == TokenName.INTERFACE) {
1402 // interface_entry T_STRING
1403 // interface_extends_list
1404 // '{' class_statement_list '}'
1405 checkAndSetModifiers(AccInterface);
1407 typeDecl.modifiers = this.modifiers;
1408 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1409 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1410 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1411 typeDecl.name = scanner.getCurrentIdentifierSource();
1412 if (token.compareTo (TokenName.KEYWORD) > 0) {
1413 problemReporter.phpKeywordWarning(new String[] { scanner
1414 .toStringAction(token) }, scanner
1415 .getCurrentTokenStartPosition(), scanner
1416 .getCurrentTokenEndPosition(), referenceContext,
1417 compilationUnit.compilationResult);
1418 // throwSyntaxError("Don't use a keyword for interface
1420 // + scanner.toStringAction(token) + "].",
1421 // typeDecl.sourceStart, typeDecl.sourceEnd);
1424 interface_extends_list(typeDecl);
1426 typeDecl.name = new char[] { ' ' };
1428 "Interface name expected after keyword 'interface'.",
1429 typeDecl.sourceStart, typeDecl.sourceEnd);
1433 // class_entry_type T_STRING extends_from
1435 // '{' class_statement_list'}'
1437 typeDecl.modifiers = this.modifiers;
1438 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1439 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1441 // identifier 'extends' identifier
1442 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1443 typeDecl.name = scanner.getCurrentIdentifierSource();
1444 if (token.compareTo (TokenName.KEYWORD) > 0) {
1445 problemReporter.phpKeywordWarning(new String[] { scanner
1446 .toStringAction(token) }, scanner
1447 .getCurrentTokenStartPosition(), scanner
1448 .getCurrentTokenEndPosition(), referenceContext,
1449 compilationUnit.compilationResult);
1450 // throwSyntaxError("Don't use a keyword for class
1452 // scanner.toStringAction(token) + "].",
1453 // typeDecl.sourceStart, typeDecl.sourceEnd);
1458 // | T_EXTENDS fully_qualified_class_name
1459 if (token == TokenName.EXTENDS) {
1460 class_extends_list(typeDecl);
1462 // if (token != TokenName.IDENTIFIER) {
1463 // throwSyntaxError("Class name expected after keyword
1465 // scanner.getCurrentTokenStartPosition(), scanner
1466 // .getCurrentTokenEndPosition());
1469 implements_list(typeDecl);
1471 typeDecl.name = new char[] { ' ' };
1472 throwSyntaxError("Class name expected after keyword 'class'.",
1473 typeDecl.sourceStart, typeDecl.sourceEnd);
1477 // '{' class_statement_list '}'
1478 if (token == TokenName.LBRACE) {
1480 if (token != TokenName.RBRACE) {
1481 ArrayList list = new ArrayList();
1482 class_statement_list(list);
1483 typeDecl.fields = new FieldDeclaration[list.size()];
1484 for (int i = 0; i < list.size(); i++) {
1485 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1488 if (token == TokenName.RBRACE) {
1489 typeDecl.declarationSourceEnd = scanner
1490 .getCurrentTokenEndPosition();
1493 throwSyntaxError("'}' expected at end of class body.");
1496 throwSyntaxError("'{' expected at start of class body.");
1500 private void class_entry_type() {
1502 // | T_ABSTRACT T_CLASS
1503 // | T_FINAL T_CLASS
1504 if (token == TokenName.CLASS) {
1506 } else if (token == TokenName.ABSTRACT) {
1507 checkAndSetModifiers(AccAbstract);
1509 if (token != TokenName.CLASS) {
1510 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1513 } else if (token == TokenName.FINAL) {
1514 checkAndSetModifiers(AccFinal);
1516 if (token != TokenName.CLASS) {
1517 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1521 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1525 // private void class_extends(TypeDeclaration typeDecl) {
1527 // // | T_EXTENDS interface_list
1528 // if (token == TokenName.EXTENDS) {
1531 // if (token == TokenName.IDENTIFIER) {
1534 // throwSyntaxError("Class name expected after keyword 'extends'.");
1539 private void interface_extends_list(TypeDeclaration typeDecl) {
1541 // | T_EXTENDS interface_list
1542 if (token == TokenName.EXTENDS) {
1544 interface_list(typeDecl);
1548 private void class_extends_list(TypeDeclaration typeDecl) {
1550 // | T_EXTENDS interface_list
1551 if (token == TokenName.EXTENDS) {
1553 class_list(typeDecl);
1557 private void implements_list(TypeDeclaration typeDecl) {
1559 // | T_IMPLEMENTS interface_list
1560 if (token == TokenName.IMPLEMENTS) {
1562 interface_list(typeDecl);
1566 private void class_list(TypeDeclaration typeDecl) {
1568 // fully_qualified_class_name
1570 if (token == TokenName.IDENTIFIER) {
1571 //char[] ident = scanner.getCurrentIdentifierSource();
1572 // TODO make this code working better:
1573 // SingleTypeReference ref =
1574 // ParserUtil.getTypeReference(scanner,
1575 // includesList, ident);
1576 // if (ref != null) {
1577 // typeDecl.superclass = ref;
1581 throwSyntaxError("Classname expected after keyword 'extends'.");
1583 if (token == TokenName.COMMA) {
1584 reportSyntaxError("No multiple inheritance allowed. Expected token 'implements' or '{'.");
1593 private void interface_list(TypeDeclaration typeDecl) {
1595 // fully_qualified_class_name
1596 // | interface_list ',' fully_qualified_class_name
1598 if (token == TokenName.IDENTIFIER) {
1601 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1603 if (token != TokenName.COMMA) {
1610 // private void classBody(TypeDeclaration typeDecl) {
1611 // //'{' [class-element-list] '}'
1612 // if (token == TokenName.LBRACE) {
1614 // if (token != TokenName.RBRACE) {
1615 // class_statement_list();
1617 // if (token == TokenName.RBRACE) {
1618 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1621 // throwSyntaxError("'}' expected at end of class body.");
1624 // throwSyntaxError("'{' expected at start of class body.");
1627 private void class_statement_list(ArrayList list) {
1630 class_statement(list);
1631 if (token == TokenName.PUBLIC ||
1632 token == TokenName.PROTECTED ||
1633 token == TokenName.PRIVATE ||
1634 token == TokenName.STATIC ||
1635 token == TokenName.ABSTRACT ||
1636 token == TokenName.FINAL ||
1637 token == TokenName.FUNCTION ||
1638 token == TokenName.VAR ||
1639 token == TokenName.CONST) {
1643 if (token == TokenName.RBRACE) {
1647 throwSyntaxError("'}' at end of class statement.");
1649 catch (SyntaxError sytaxErr1) {
1650 boolean tokenize = scanner.tokenizeStrings;
1653 scanner.tokenizeStrings = true;
1656 // if an error occured,
1657 // try to find keywords
1658 // to parse the rest of the string
1659 while (token != TokenName.EOF) {
1660 if (token == TokenName.PUBLIC ||
1661 token == TokenName.PROTECTED ||
1662 token == TokenName.PRIVATE ||
1663 token == TokenName.STATIC ||
1664 token == TokenName.ABSTRACT ||
1665 token == TokenName.FINAL ||
1666 token == TokenName.FUNCTION ||
1667 token == TokenName.VAR ||
1668 token == TokenName.CONST) {
1671 // System.out.println(scanner.toStringAction(token));
1674 if (token == TokenName.EOF) {
1678 scanner.tokenizeStrings = tokenize;
1687 private void class_statement(ArrayList list) {
1689 // variable_modifiers class_variable_declaration ';'
1690 // | class_constant_declaration ';'
1691 // | method_modifiers T_FUNCTION is_reference T_STRING
1692 // '(' parameter_list ')' method_body
1693 initializeModifiers();
1694 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1696 if (token == TokenName.VAR) {
1697 checkAndSetModifiers(AccPublic);
1698 problemReporter.phpVarDeprecatedWarning(scanner
1699 .getCurrentTokenStartPosition(), scanner
1700 .getCurrentTokenEndPosition(), referenceContext,
1701 compilationUnit.compilationResult);
1703 class_variable_declaration(declarationSourceStart, list);
1704 } else if (token == TokenName.CONST) {
1705 checkAndSetModifiers(AccFinal | AccPublic);
1706 class_constant_declaration(declarationSourceStart, list);
1707 if (token != TokenName.SEMICOLON) {
1708 throwSyntaxError("';' expected after class const declaration.");
1712 boolean hasModifiers = member_modifiers();
1713 if (token == TokenName.FUNCTION) {
1714 if (!hasModifiers) {
1715 checkAndSetModifiers(AccPublic);
1717 MethodDeclaration methodDecl = new MethodDeclaration(
1718 this.compilationUnit.compilationResult);
1719 methodDecl.declarationSourceStart = scanner
1720 .getCurrentTokenStartPosition();
1721 methodDecl.modifiers = this.modifiers;
1722 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1725 functionDefinition(methodDecl);
1727 int sourceEnd = methodDecl.sourceEnd;
1729 || methodDecl.declarationSourceStart > sourceEnd) {
1730 sourceEnd = methodDecl.declarationSourceStart + 1;
1732 methodDecl.declarationSourceEnd = sourceEnd;
1733 methodDecl.sourceEnd = sourceEnd;
1736 if (!hasModifiers) {
1737 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1739 class_variable_declaration(declarationSourceStart, list);
1744 private void class_constant_declaration(int declarationSourceStart,
1746 // class_constant_declaration ',' T_STRING '=' static_scalar
1747 // | T_CONST T_STRING '=' static_scalar
1748 if (token != TokenName.CONST) {
1749 throwSyntaxError("'const' keyword expected in class declaration.");
1754 if (token != TokenName.IDENTIFIER) {
1755 throwSyntaxError("Identifier expected in class const declaration.");
1757 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner
1758 .getCurrentIdentifierSource(), scanner
1759 .getCurrentTokenStartPosition(), scanner
1760 .getCurrentTokenEndPosition());
1761 fieldDeclaration.modifiers = this.modifiers;
1762 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1763 fieldDeclaration.declarationSourceEnd = scanner
1764 .getCurrentTokenEndPosition();
1765 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1766 // fieldDeclaration.type
1767 list.add(fieldDeclaration);
1769 if (token != TokenName.EQUAL) {
1770 throwSyntaxError("'=' expected in class const declaration.");
1774 if (token != TokenName.COMMA) {
1775 break; // while(true)-loop
1781 // private void variable_modifiers() {
1782 // // variable_modifiers:
1783 // // non_empty_member_modifiers
1785 // initializeModifiers();
1786 // if (token == TokenName.var) {
1787 // checkAndSetModifiers(AccPublic);
1788 // reportSyntaxError(
1789 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1791 // modifier for field declarations.",
1792 // scanner.getCurrentTokenStartPosition(), scanner
1793 // .getCurrentTokenEndPosition());
1796 // if (!member_modifiers()) {
1797 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1798 // field declarations.");
1802 // private void method_modifiers() {
1803 // //method_modifiers:
1805 // //| non_empty_member_modifiers
1806 // initializeModifiers();
1807 // if (!member_modifiers()) {
1808 // checkAndSetModifiers(AccPublic);
1811 private boolean member_modifiers() {
1818 boolean foundToken = false;
1820 if (token == TokenName.PUBLIC) {
1821 checkAndSetModifiers(AccPublic);
1824 } else if (token == TokenName.PROTECTED) {
1825 checkAndSetModifiers(AccProtected);
1828 } else if (token == TokenName.PRIVATE) {
1829 checkAndSetModifiers(AccPrivate);
1832 } else if (token == TokenName.STATIC) {
1833 checkAndSetModifiers(AccStatic);
1836 } else if (token == TokenName.ABSTRACT) {
1837 checkAndSetModifiers(AccAbstract);
1840 } else if (token == TokenName.FINAL) {
1841 checkAndSetModifiers(AccFinal);
1851 private void class_variable_declaration(int declarationSourceStart,
1853 // class_variable_declaration:
1854 // class_variable_declaration ',' T_VARIABLE
1855 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1857 // | T_VARIABLE '=' static_scalar
1858 char[] classVariable;
1860 if (token == TokenName.VARIABLE) {
1861 classVariable = scanner.getCurrentIdentifierSource();
1862 // indexManager.addIdentifierInformation('v', classVariable,
1865 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1866 classVariable, scanner.getCurrentTokenStartPosition(),
1867 scanner.getCurrentTokenEndPosition());
1868 fieldDeclaration.modifiers = this.modifiers;
1869 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1870 fieldDeclaration.declarationSourceEnd = scanner
1871 .getCurrentTokenEndPosition();
1872 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1873 list.add(fieldDeclaration);
1874 if (fTypeVariables != null) {
1875 VariableInfo info = new VariableInfo(scanner
1876 .getCurrentTokenStartPosition(),
1877 VariableInfo.LEVEL_CLASS_UNIT);
1878 fTypeVariables.put(new String(scanner
1879 .getCurrentIdentifierSource()), info);
1882 if (token == TokenName.EQUAL) {
1887 // if (token == TokenName.THIS) {
1888 // throwSyntaxError("'$this' not allowed after keyword 'public'
1889 // 'protected' 'private' 'var'.");
1891 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1893 if (token != TokenName.COMMA) {
1898 if (token != TokenName.SEMICOLON) {
1899 throwSyntaxError("';' expected after field declaration.");
1904 private void functionDefinition(MethodDeclaration methodDecl) {
1905 boolean isAbstract = false;
1907 if (compilationUnit != null) {
1908 compilationUnit.types.add(methodDecl);
1911 ASTNode node = astStack[astPtr];
1912 if (node instanceof TypeDeclaration) {
1913 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1914 if (typeDecl.methods == null) {
1915 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1917 AbstractMethodDeclaration[] newMethods;
1922 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1923 0, typeDecl.methods.length);
1924 newMethods[typeDecl.methods.length] = methodDecl;
1925 typeDecl.methods = newMethods;
1927 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1929 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1935 pushFunctionVariableSet();
1936 functionDeclarator(methodDecl);
1937 if (token == TokenName.SEMICOLON) {
1939 methodDecl.sourceEnd = scanner
1940 .getCurrentTokenStartPosition() - 1;
1941 throwSyntaxError("Body declaration expected for method: "
1942 + new String(methodDecl.selector));
1947 functionBody(methodDecl);
1949 if (!fStackUnassigned.isEmpty()) {
1950 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1955 private void functionDeclarator(MethodDeclaration methodDecl) {
1956 // identifier '(' [parameter-list] ')'
1957 if (token == TokenName.OP_AND) {
1961 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1962 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1964 if (Scanner.isIdentifierOrKeyword (token) ||
1965 token == TokenName.LPAREN) {
1967 if (token == TokenName.LPAREN) {
1968 methodDecl.selector = scanner.getCurrentIdentifierSource();
1970 if (token.compareTo (TokenName.KEYWORD) > 0) {
1971 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1972 scanner.getCurrentTokenStartPosition(),
1973 scanner.getCurrentTokenEndPosition(),
1975 compilationUnit.compilationResult);
1979 methodDecl.selector = scanner.getCurrentIdentifierSource();
1981 if (token.compareTo (TokenName.KEYWORD) > 0) {
1982 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1983 scanner.getCurrentTokenStartPosition(),
1984 scanner.getCurrentTokenEndPosition(),
1986 compilationUnit.compilationResult);
1992 if (token == TokenName.LPAREN) {
1996 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1997 throwSyntaxError("'(' expected in function declaration.");
2000 if (token != TokenName.RPAREN) {
2001 parameter_list(methodDecl);
2004 if (token != TokenName.RPAREN) {
2005 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
2006 throwSyntaxError("')' expected in function declaration.");
2009 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
2014 methodDecl.selector = "<undefined>".toCharArray();
2015 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
2016 throwSyntaxError("Function name expected after keyword 'function'.");
2021 private void parameter_list(MethodDeclaration methodDecl) {
2022 // non_empty_parameter_list
2024 non_empty_parameter_list(methodDecl, true);
2027 private void non_empty_parameter_list(MethodDeclaration methodDecl,
2028 boolean empty_allowed) {
2029 // optional_class_type T_VARIABLE
2030 // | optional_class_type '&' T_VARIABLE
2031 // | optional_class_type '&' T_VARIABLE '=' static_scalar
2032 // | optional_class_type T_VARIABLE '=' static_scalar
2033 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
2034 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
2035 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
2037 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
2039 char[] typeIdentifier = null;
2040 if (token == TokenName.IDENTIFIER ||
2041 token == TokenName.ARRAY ||
2042 token == TokenName.VARIABLE ||
2043 token == TokenName.OP_AND) {
2044 HashSet set = peekVariableSet();
2047 if (token == TokenName.IDENTIFIER || token == TokenName.ARRAY) {// feature req. #1254275
2048 typeIdentifier = scanner.getCurrentIdentifierSource();
2051 if (token == TokenName.OP_AND) {
2054 if (token == TokenName.VARIABLE) {
2055 if (fMethodVariables != null) {
2057 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
2058 info = new VariableInfo(scanner
2059 .getCurrentTokenStartPosition(),
2060 VariableInfo.LEVEL_FUNCTION_DEFINITION);
2062 info = new VariableInfo(scanner
2063 .getCurrentTokenStartPosition(),
2064 VariableInfo.LEVEL_METHOD_DEFINITION);
2066 info.typeIdentifier = typeIdentifier;
2067 fMethodVariables.put(new String(scanner
2068 .getCurrentIdentifierSource()), info);
2070 addVariableSet(set);
2072 if (token == TokenName.EQUAL) {
2077 throwSyntaxError("Variable expected in parameter list.");
2079 if (token != TokenName.COMMA) {
2086 if (!empty_allowed) {
2087 throwSyntaxError("Identifier expected in parameter list.");
2091 // private void optional_class_type() {
2096 // private void parameterDeclaration() {
2098 // //variable-reference
2099 // if (token == TokenName.AND) {
2101 // if (isVariable()) {
2104 // throwSyntaxError("Variable expected after reference operator '&'.");
2107 // //variable '=' constant
2108 // if (token == TokenName.VARIABLE) {
2110 // if (token == TokenName.EQUAL) {
2116 // // if (token == TokenName.THIS) {
2117 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
2118 // // declaration.");
2122 private void labeledStatementList() {
2123 if (token != TokenName.CASE && token != TokenName.DEFAULT) {
2124 throwSyntaxError("'case' or 'default' expected.");
2127 if (token == TokenName.CASE) {
2129 expr_without_variable (true, null, true); // constant();
2130 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2132 if (token == TokenName.RBRACE) {
2133 // empty case; assumes that the '}' token belongs to the wrapping
2134 // switch statement - #1371992
2137 if (token == TokenName.CASE || token == TokenName.DEFAULT) {
2138 // empty case statement ?
2143 // else if (token == TokenName.SEMICOLON) {
2145 // "':' expected after 'case' keyword (Found token: " +
2146 // scanner.toStringAction(token) + ")",
2147 // scanner.getCurrentTokenStartPosition(),
2148 // scanner.getCurrentTokenEndPosition(),
2151 // if (token == TokenName.CASE) { // empty case statement ?
2157 throwSyntaxError("':' character expected after 'case' constant (Found token: "
2158 + scanner.toStringAction(token) + ")");
2160 } else { // TokenName.DEFAULT
2162 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2164 if (token == TokenName.RBRACE) {
2165 // empty default case; ; assumes that the '}' token belongs to the
2166 // wrapping switch statement - #1371992
2169 if (token != TokenName.CASE) {
2173 throwSyntaxError("':' character expected after 'default'.");
2176 } while (token == TokenName.CASE || token == TokenName.DEFAULT);
2179 private void ifStatementColon(IfStatement iState) {
2180 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
2181 // new_else_single T_ENDIF ';'
2182 HashSet assignedVariableSet = null;
2184 Block b = inner_statement_list();
2185 iState.thenStatement = b;
2186 checkUnreachable(iState, b);
2188 assignedVariableSet = removeIfVariableSet();
2190 if (token == TokenName.ELSEIF) {
2192 pushIfVariableSet();
2193 new_elseif_list(iState);
2195 HashSet set = removeIfVariableSet();
2196 if (assignedVariableSet != null && set != null) {
2197 assignedVariableSet.addAll(set);
2202 pushIfVariableSet();
2203 new_else_single(iState);
2205 HashSet set = removeIfVariableSet();
2206 if (assignedVariableSet != null) {
2207 HashSet topSet = peekVariableSet();
2208 if (topSet != null) {
2212 topSet.addAll(assignedVariableSet);
2216 if (token != TokenName.ENDIF) {
2217 throwSyntaxError("'endif' expected.");
2220 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2221 reportSyntaxError("';' expected after if-statement.");
2222 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2224 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
2229 private void ifStatement(IfStatement iState) {
2230 // T_IF '(' expr ')' statement elseif_list else_single
2231 HashSet assignedVariableSet = null;
2233 pushIfVariableSet();
2234 Statement s = statement();
2235 iState.thenStatement = s;
2236 checkUnreachable(iState, s);
2238 assignedVariableSet = removeIfVariableSet();
2241 if (token == TokenName.ELSEIF) {
2243 pushIfVariableSet();
2244 elseif_list(iState);
2246 HashSet set = removeIfVariableSet();
2247 if (assignedVariableSet != null && set != null) {
2248 assignedVariableSet.addAll(set);
2253 pushIfVariableSet();
2254 else_single(iState);
2256 HashSet set = removeIfVariableSet();
2257 if (assignedVariableSet != null) {
2258 HashSet topSet = peekVariableSet();
2259 if (topSet != null) {
2263 topSet.addAll(assignedVariableSet);
2269 private void elseif_list(IfStatement iState) {
2271 // | elseif_list T_ELSEIF '(' expr ')' statement
2272 ArrayList conditionList = new ArrayList();
2273 ArrayList statementList = new ArrayList();
2276 while (token == TokenName.ELSEIF) {
2278 if (token == TokenName.LPAREN) {
2281 throwSyntaxError("'(' expected after 'elseif' keyword.");
2284 conditionList.add(e);
2285 if (token == TokenName.RPAREN) {
2288 throwSyntaxError("')' expected after 'elseif' condition.");
2291 statementList.add(s);
2292 checkUnreachable(iState, s);
2294 iState.elseifConditions = new Expression[conditionList.size()];
2295 iState.elseifStatements = new Statement[statementList.size()];
2296 conditionList.toArray(iState.elseifConditions);
2297 statementList.toArray(iState.elseifStatements);
2300 private void new_elseif_list(IfStatement iState) {
2302 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
2303 ArrayList conditionList = new ArrayList();
2304 ArrayList statementList = new ArrayList();
2307 while (token == TokenName.ELSEIF) {
2309 if (token == TokenName.LPAREN) {
2312 throwSyntaxError("'(' expected after 'elseif' keyword.");
2315 conditionList.add(e);
2316 if (token == TokenName.RPAREN) {
2319 throwSyntaxError("')' expected after 'elseif' condition.");
2321 if (token == TokenName.COLON) {
2324 throwSyntaxError("':' expected after 'elseif' keyword.");
2326 b = inner_statement_list();
2327 statementList.add(b);
2328 checkUnreachable(iState, b);
2330 iState.elseifConditions = new Expression[conditionList.size()];
2331 iState.elseifStatements = new Statement[statementList.size()];
2332 conditionList.toArray(iState.elseifConditions);
2333 statementList.toArray(iState.elseifStatements);
2336 private void else_single(IfStatement iState) {
2339 if (token == TokenName.ELSE) {
2341 Statement s = statement();
2342 iState.elseStatement = s;
2343 checkUnreachable(iState, s);
2345 iState.checkUnreachable = false;
2347 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2350 private void new_else_single(IfStatement iState) {
2352 // | T_ELSE ':' inner_statement_list
2353 if (token == TokenName.ELSE) {
2355 if (token == TokenName.COLON) {
2358 throwSyntaxError("':' expected after 'else' keyword.");
2360 Block b = inner_statement_list();
2361 iState.elseStatement = b;
2362 checkUnreachable(iState, b);
2364 iState.checkUnreachable = false;
2368 private Block inner_statement_list() {
2369 // inner_statement_list inner_statement
2371 return statementList();
2378 private void checkUnreachable(IfStatement iState, Statement s) {
2379 if (s instanceof Block) {
2380 Block b = (Block) s;
2381 if (b.statements == null || b.statements.length == 0) {
2382 iState.checkUnreachable = false;
2384 int off = b.statements.length - 1;
2385 if (!(b.statements[off] instanceof ReturnStatement)
2386 && !(b.statements[off] instanceof ContinueStatement)
2387 && !(b.statements[off] instanceof BreakStatement)) {
2388 if (!(b.statements[off] instanceof IfStatement)
2389 || !((IfStatement) b.statements[off]).checkUnreachable) {
2390 iState.checkUnreachable = false;
2395 if (!(s instanceof ReturnStatement)
2396 && !(s instanceof ContinueStatement)
2397 && !(s instanceof BreakStatement)) {
2398 if (!(s instanceof IfStatement)
2399 || !((IfStatement) s).checkUnreachable) {
2400 iState.checkUnreachable = false;
2406 // private void elseifStatementList() {
2408 // elseifStatement();
2410 // case TokenName.else:
2412 // if (token == TokenName.COLON) {
2414 // if (token != TokenName.endif) {
2419 // if (token == TokenName.if) { //'else if'
2422 // throwSyntaxError("':' expected after 'else'.");
2426 // case TokenName.elseif:
2435 // private void elseifStatement() {
2436 // if (token == TokenName.LPAREN) {
2439 // if (token != TokenName.RPAREN) {
2440 // throwSyntaxError("')' expected in else-if-statement.");
2443 // if (token != TokenName.COLON) {
2444 // throwSyntaxError("':' expected in else-if-statement.");
2447 // if (token != TokenName.endif) {
2453 private void switchStatement() {
2454 if (token == TokenName.COLON) {
2455 // ':' [labeled-statement-list] 'endswitch' ';'
2457 labeledStatementList();
2458 if (token != TokenName.ENDSWITCH) {
2459 throwSyntaxError("'endswitch' expected.");
2462 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2463 throwSyntaxError("';' expected after switch-statement.");
2467 // '{' [labeled-statement-list] '}'
2468 if (token != TokenName.LBRACE) {
2469 throwSyntaxError("'{' expected in switch statement.");
2472 if (token != TokenName.RBRACE) {
2473 labeledStatementList();
2475 if (token != TokenName.RBRACE) {
2476 throwSyntaxError("'}' expected in switch statement.");
2482 private void forStatement() {
2483 if (token == TokenName.COLON) {
2486 if (token != TokenName.ENDFOR) {
2487 throwSyntaxError("'endfor' expected.");
2490 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2491 throwSyntaxError("';' expected after for-statement.");
2499 private void whileStatement() {
2500 // ':' statement-list 'endwhile' ';'
2501 if (token == TokenName.COLON) {
2504 if (token != TokenName.ENDWHILE) {
2505 throwSyntaxError("'endwhile' expected.");
2508 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2509 throwSyntaxError("';' expected after while-statement.");
2517 private void foreachStatement() {
2518 if (token == TokenName.COLON) {
2521 if (token != TokenName.ENDFOREACH) {
2522 throwSyntaxError("'endforeach' expected.");
2525 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2526 throwSyntaxError("';' expected after foreach-statement.");
2534 // private void exitStatus() {
2535 // if (token == TokenName.LPAREN) {
2538 // throwSyntaxError("'(' expected in 'exit-status'.");
2540 // if (token != TokenName.RPAREN) {
2543 // if (token == TokenName.RPAREN) {
2546 // throwSyntaxError("')' expected after 'exit-status'.");
2552 private void namespacePath () {
2554 expr_without_variable (true, null, false);
2556 if (token == TokenName.BACKSLASH) {
2567 private void expressionList() {
2569 expr_without_variable (true, null, false);
2571 if (token == TokenName.COMMA) { // If it's a list of (comma separated) expressions
2572 getNextToken(); // read all in, untill no more found
2579 private Expression expr() {
2580 return expr_without_variable(true, null, false);
2585 * @param only_variable
2586 * @param initHandler
2588 private Expression expr_without_variable (boolean only_variable,
2589 UninitializedVariableHandler initHandler,
2590 boolean bColonAllowed) {
2591 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2592 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2593 Expression expression = new Expression();
2595 expression.sourceStart = exprSourceStart;
2596 expression.sourceEnd = exprSourceEnd; // default, may be overwritten
2599 // internal_functions_in_yacc
2608 // | T_INC rw_variable
2609 // | T_DEC rw_variable
2610 // | T_INT_CAST expr
2611 // | T_DOUBLE_CAST expr
2612 // | T_STRING_CAST expr
2613 // | T_ARRAY_CAST expr
2614 // | T_OBJECT_CAST expr
2615 // | T_BOOL_CAST expr
2616 // | T_UNSET_CAST expr
2617 // | T_EXIT exit_expr
2619 // | T_ARRAY '(' array_pair_list ')'
2620 // | '`' encaps_list '`'
2621 // | T_LIST '(' assignment_list ')' '=' expr
2622 // | T_NEW class_name_reference ctor_arguments
2623 // | variable '=' expr
2624 // | variable '=' '&' variable
2625 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2626 // | variable T_PLUS_EQUAL expr
2627 // | variable T_MINUS_EQUAL expr
2628 // | variable T_MUL_EQUAL expr
2629 // | variable T_DIV_EQUAL expr
2630 // | variable T_CONCAT_EQUAL expr
2631 // | variable T_MOD_EQUAL expr
2632 // | variable T_AND_EQUAL expr
2633 // | variable T_OR_EQUAL expr
2634 // | variable T_XOR_EQUAL expr
2635 // | variable T_SL_EQUAL expr
2636 // | variable T_SR_EQUAL expr
2637 // | rw_variable T_INC
2638 // | rw_variable T_DEC
2639 // | expr T_BOOLEAN_OR expr
2640 // | expr T_BOOLEAN_AND expr
2641 // | expr T_LOGICAL_OR expr
2642 // | expr T_LOGICAL_AND expr
2643 // | expr T_LOGICAL_XOR expr
2655 // | expr T_IS_IDENTICAL expr
2656 // | expr T_IS_NOT_IDENTICAL expr
2657 // | expr T_IS_EQUAL expr
2658 // | expr T_IS_NOT_EQUAL expr
2660 // | expr T_IS_SMALLER_OR_EQUAL expr
2662 // | expr T_IS_GREATER_OR_EQUAL expr
2663 // | expr T_INSTANCEOF class_name_reference
2664 // | expr '?' expr ':' expr
2665 if (Scanner.TRACE) {
2666 System.out.println("TRACE: expr_without_variable() PART 1");
2671 // T_ISSET '(' isset_variables ')'
2673 if (token != TokenName.LPAREN) {
2674 throwSyntaxError("'(' expected after keyword 'isset'");
2678 if (token != TokenName.RPAREN) {
2679 throwSyntaxError("')' expected after keyword 'isset'");
2685 if (token != TokenName.LPAREN) {
2686 throwSyntaxError("'(' expected after keyword 'empty'");
2689 variable(true, false);
2690 if (token != TokenName.RPAREN) {
2691 throwSyntaxError("')' expected after keyword 'empty'");
2700 internal_functions_in_yacc();
2707 if (token == TokenName.RPAREN) {
2710 throwSyntaxError("')' expected in expression.");
2720 // | T_INT_CAST expr
2721 // | T_DOUBLE_CAST expr
2722 // | T_STRING_CAST expr
2723 // | T_ARRAY_CAST expr
2724 // | T_OBJECT_CAST expr
2725 // | T_BOOL_CAST expr
2726 // | T_UNSET_CAST expr
2742 expr_without_variable (only_variable, initHandler, bColonAllowed);
2750 // | T_STRING_VARNAME
2752 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2753 // | '`' encaps_list '`'
2755 // | '`' encaps_list '`'
2756 // case TokenName.EncapsedString0:
2757 // scanner.encapsedStringStack.push(new Character('`'));
2760 // if (token == TokenName.EncapsedString0) {
2763 // if (token != TokenName.EncapsedString0) {
2764 // throwSyntaxError("\'`\' expected at end of string" + "(Found
2766 // scanner.toStringAction(token) + " )");
2770 // scanner.encapsedStringStack.pop();
2774 // // | '\'' encaps_list '\''
2775 // case TokenName.EncapsedString1:
2776 // scanner.encapsedStringStack.push(new Character('\''));
2779 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2780 // if (token == TokenName.EncapsedString1) {
2782 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2783 // exprSourceStart, scanner
2784 // .getCurrentTokenEndPosition());
2787 // if (token != TokenName.EncapsedString1) {
2788 // throwSyntaxError("\'\'\' expected at end of string" + "(Found
2790 // + scanner.toStringAction(token) + " )");
2793 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2794 // exprSourceStart, scanner
2795 // .getCurrentTokenEndPosition());
2799 // scanner.encapsedStringStack.pop();
2803 // //| '"' encaps_list '"'
2804 // case TokenName.EncapsedString2:
2805 // scanner.encapsedStringStack.push(new Character('"'));
2808 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2809 // if (token == TokenName.EncapsedString2) {
2811 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2812 // exprSourceStart, scanner
2813 // .getCurrentTokenEndPosition());
2816 // if (token != TokenName.EncapsedString2) {
2817 // throwSyntaxError("'\"' expected at end of string" + "(Found
2819 // scanner.toStringAction(token) + " )");
2822 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2823 // exprSourceStart, scanner
2824 // .getCurrentTokenEndPosition());
2828 // scanner.encapsedStringStack.pop();
2832 case STRINGDOUBLEQUOTE:
2833 expression = new StringLiteralDQ (scanner.getCurrentStringLiteralSource(),
2834 scanner.getCurrentTokenStartPosition(),
2835 scanner.getCurrentTokenEndPosition());
2838 case STRINGSINGLEQUOTE:
2839 expression = new StringLiteralSQ (scanner.getCurrentStringLiteralSource(),
2840 scanner.getCurrentTokenStartPosition(),
2841 scanner.getCurrentTokenEndPosition());
2844 case INTEGERLITERAL:
2846 case STRINGINTERPOLATED:
2858 // T_ARRAY '(' array_pair_list ')'
2860 if (token == TokenName.LPAREN) {
2862 if (token == TokenName.RPAREN) {
2867 if (token != TokenName.RPAREN) {
2868 throwSyntaxError("')' or ',' expected after keyword 'array'"
2870 + scanner.toStringAction(token) + ")");
2874 throwSyntaxError("'(' expected after keyword 'array'"
2875 + "(Found token: " + scanner.toStringAction(token)
2880 // | T_LIST '(' assignment_list ')' '=' expr
2882 if (token == TokenName.LPAREN) {
2885 if (token != TokenName.RPAREN) {
2886 throwSyntaxError("')' expected after 'list' keyword.");
2889 if (token != TokenName.EQUAL) {
2890 throwSyntaxError("'=' expected after 'list' keyword.");
2895 throwSyntaxError("'(' expected after 'list' keyword.");
2899 // | T_NEW class_name_reference ctor_arguments
2901 Expression typeRef = class_name_reference();
2903 if (typeRef != null) {
2904 expression = typeRef;
2907 // | T_INC rw_variable
2908 // | T_DEC rw_variable
2914 // | variable '=' expr
2915 // | variable '=' '&' variable
2916 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2917 // | variable T_PLUS_EQUAL expr
2918 // | variable T_MINUS_EQUAL expr
2919 // | variable T_MUL_EQUAL expr
2920 // | variable T_DIV_EQUAL expr
2921 // | variable T_CONCAT_EQUAL expr
2922 // | variable T_MOD_EQUAL expr
2923 // | variable T_AND_EQUAL expr
2924 // | variable T_OR_EQUAL expr
2925 // | variable T_XOR_EQUAL expr
2926 // | variable T_SL_EQUAL expr
2927 // | variable T_SR_EQUAL expr
2928 // | rw_variable T_INC
2929 // | rw_variable T_DEC
2933 Expression lhs = null;
2934 boolean rememberedVar = false;
2936 if (token == TokenName.IDENTIFIER) {
2937 lhs = identifier(true, true, bColonAllowed);
2944 lhs = variable (true, true);
2951 lhs instanceof FieldReference &&
2952 token != TokenName.EQUAL &&
2953 token != TokenName.PLUS_EQUAL &&
2954 token != TokenName.MINUS_EQUAL &&
2955 token != TokenName.MULTIPLY_EQUAL &&
2956 token != TokenName.DIVIDE_EQUAL &&
2957 token != TokenName.DOT_EQUAL &&
2958 token != TokenName.REMAINDER_EQUAL &&
2959 token != TokenName.AND_EQUAL &&
2960 token != TokenName.OR_EQUAL &&
2961 token != TokenName.XOR_EQUAL &&
2962 token != TokenName.RIGHT_SHIFT_EQUAL &&
2963 token != TokenName.LEFT_SHIFT_EQUAL) {
2965 FieldReference ref = (FieldReference) lhs;
2967 if (!containsVariableSet(ref.token)) {
2968 if (null == initHandler || initHandler.reportError()) {
2969 problemReporter.uninitializedLocalVariable(
2970 new String(ref.token), ref.sourceStart,
2971 ref.sourceEnd, referenceContext,
2972 compilationUnit.compilationResult);
2974 addVariableSet(ref.token);
2981 if (lhs != null && lhs instanceof FieldReference) {
2982 addVariableSet(((FieldReference) lhs).token);
2985 if (token == TokenName.OP_AND) {
2987 if (token == TokenName.NEW) {
2988 // | variable '=' '&' T_NEW class_name_reference
2991 SingleTypeReference classRef = class_name_reference();
2993 if (classRef != null) {
2995 && lhs instanceof FieldReference) {
2997 // $var = & new Object();
2998 if (fMethodVariables != null) {
2999 VariableInfo lhsInfo = new VariableInfo(
3000 ((FieldReference) lhs).sourceStart);
3001 lhsInfo.reference = classRef;
3002 lhsInfo.typeIdentifier = classRef.token;
3003 fMethodVariables.put(new String(
3004 ((FieldReference) lhs).token),
3006 rememberedVar = true;
3011 Expression rhs = variable(false, false);
3012 if (rhs != null && rhs instanceof FieldReference
3014 && lhs instanceof FieldReference) {
3017 if (fMethodVariables != null) {
3018 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
3019 .get(((FieldReference) rhs).token);
3021 && rhsInfo.reference != null) {
3022 VariableInfo lhsInfo = new VariableInfo(
3023 ((FieldReference) lhs).sourceStart);
3024 lhsInfo.reference = rhsInfo.reference;
3025 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
3026 fMethodVariables.put(new String(
3027 ((FieldReference) lhs).token),
3029 rememberedVar = true;
3035 Expression rhs = expr_without_variable (only_variable, initHandler, bColonAllowed);
3037 if (lhs != null && lhs instanceof FieldReference) {
3038 if (rhs != null && rhs instanceof FieldReference) {
3041 if (fMethodVariables != null) {
3042 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
3043 .get(((FieldReference) rhs).token);
3045 && rhsInfo.reference != null) {
3046 VariableInfo lhsInfo = new VariableInfo(
3047 ((FieldReference) lhs).sourceStart);
3048 lhsInfo.reference = rhsInfo.reference;
3049 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
3050 fMethodVariables.put(new String(
3051 ((FieldReference) lhs).token),
3053 rememberedVar = true;
3056 } else if (rhs != null
3057 && rhs instanceof SingleTypeReference) {
3059 // $var = new Object();
3060 if (fMethodVariables != null) {
3061 VariableInfo lhsInfo = new VariableInfo(
3062 ((FieldReference) lhs).sourceStart);
3063 lhsInfo.reference = (SingleTypeReference) rhs;
3064 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
3065 fMethodVariables.put(new String(
3066 ((FieldReference) lhs).token),
3068 rememberedVar = true;
3073 if (rememberedVar == false && lhs != null
3074 && lhs instanceof FieldReference) {
3075 if (fMethodVariables != null) {
3076 VariableInfo lhsInfo = new VariableInfo (((FieldReference) lhs).sourceStart);
3077 fMethodVariables.put (new String (((FieldReference) lhs).token), lhsInfo);
3085 case MULTIPLY_EQUAL:
3088 case REMAINDER_EQUAL:
3092 case RIGHT_SHIFT_EQUAL:
3093 case LEFT_SHIFT_EQUAL:
3094 if (lhs != null && lhs instanceof FieldReference) {
3095 addVariableSet(((FieldReference) lhs).token);
3098 expr_without_variable (only_variable, initHandler, bColonAllowed);
3105 if (!only_variable) {
3106 throwSyntaxError("Variable expression not allowed (found token '"
3107 + scanner.toStringAction(token) + "').");
3112 } // case DOLLAR, VARIABLE, IDENTIFIER: switch token
3116 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
3117 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
3118 methodDecl.modifiers = AccDefault;
3119 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
3122 functionDefinition(methodDecl);
3124 int sourceEnd = methodDecl.sourceEnd;
3125 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
3126 sourceEnd = methodDecl.declarationSourceStart + 1;
3128 methodDecl.declarationSourceEnd = sourceEnd;
3129 methodDecl.sourceEnd = sourceEnd;
3135 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
3137 expr_without_variable (only_variable, initHandler, bColonAllowed);
3140 throwSyntaxError("Error in expression (Expected '::' after 'static').");
3145 if (token != TokenName.INLINE_HTML) {
3146 if (token.compareTo (TokenName.KEYWORD) > 0) {
3150 // System.out.println(scanner.getCurrentTokenStartPosition());
3151 // System.out.println(scanner.getCurrentTokenEndPosition());
3153 throwSyntaxError("Error in expression (found token '"
3154 + scanner.toStringAction(token) + "').");
3160 if (Scanner.TRACE) {
3161 System.out.println("TRACE: expr_without_variable() PART 2");
3164 // | expr T_BOOLEAN_OR expr
3165 // | expr T_BOOLEAN_AND expr
3166 // | expr T_LOGICAL_OR expr
3167 // | expr T_LOGICAL_AND expr
3168 // | expr T_LOGICAL_XOR expr
3180 // | expr T_IS_IDENTICAL expr
3181 // | expr T_IS_NOT_IDENTICAL expr
3182 // | expr T_IS_EQUAL expr
3183 // | expr T_IS_NOT_EQUAL expr
3185 // | expr T_IS_SMALLER_OR_EQUAL expr
3187 // | expr T_IS_GREATER_OR_EQUAL expr
3192 expression = new OR_OR_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR_OR);
3196 expression = new AND_AND_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND_AND);
3200 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3204 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3208 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3212 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3216 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3220 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3224 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3228 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TWIDDLE);
3232 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.PLUS);
3236 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MINUS);
3240 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MULTIPLY);
3244 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.DIVIDE);
3248 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.REMAINDER);
3252 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LEFT_SHIFT);
3256 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.RIGHT_SHIFT);
3258 case EQUAL_EQUAL_EQUAL:
3260 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3262 case NOT_EQUAL_EQUAL:
3264 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3268 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3272 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS);
3276 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS_EQUAL);
3280 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER);
3284 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER_EQUAL);
3286 // | expr T_INSTANCEOF class_name_reference
3287 // | expr '?' expr ':' expr
3290 TypeReference classRef = class_name_reference();
3292 if (classRef != null) {
3293 expression = new InstanceOfExpression (expression, classRef, OperatorIds.INSTANCEOF);
3294 expression.sourceStart = exprSourceStart;
3295 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
3301 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TERNARY_SHORT);
3306 Expression valueIfTrue = expr_without_variable (true, null, true);
3307 if (token != TokenName.COLON) {
3308 throwSyntaxError("':' expected in conditional expression.");
3311 Expression valueIfFalse = expr();
3313 expression = new ConditionalExpression (expression, valueIfTrue, valueIfFalse);
3319 } catch (SyntaxError e) {
3320 // try to find next token after expression with errors:
3321 if (token == TokenName.SEMICOLON) {
3326 if (token == TokenName.RBRACE ||
3327 token == TokenName.RPAREN ||
3328 token == TokenName.RBRACKET) {
3339 private SingleTypeReference class_name_reference() {
3340 // class_name_reference:
3342 // | dynamic_class_name_reference
3343 SingleTypeReference ref = null;
3344 if (Scanner.TRACE) {
3345 System.out.println("TRACE: class_name_reference()");
3347 if (token == TokenName.IDENTIFIER) {
3348 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3349 scanner.getCurrentTokenStartPosition());
3350 int pos = scanner.currentPosition;
3352 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
3353 // Not terminated by T_STRING, reduce to dynamic_class_name_reference
3354 scanner.currentPosition = pos;
3355 token = TokenName.IDENTIFIER;
3357 dynamic_class_name_reference();
3361 dynamic_class_name_reference();
3366 private void dynamic_class_name_reference() {
3367 // dynamic_class_name_reference:
3368 // base_variable T_OBJECT_OPERATOR object_property
3369 // dynamic_class_name_variable_properties
3371 if (Scanner.TRACE) {
3372 System.out.println("TRACE: dynamic_class_name_reference()");
3374 base_variable(true);
3375 if (token == TokenName.MINUS_GREATER) {
3378 dynamic_class_name_variable_properties();
3382 private void dynamic_class_name_variable_properties() {
3383 // dynamic_class_name_variable_properties:
3384 // dynamic_class_name_variable_properties
3385 // dynamic_class_name_variable_property
3387 if (Scanner.TRACE) {
3389 .println("TRACE: dynamic_class_name_variable_properties()");
3391 while (token == TokenName.MINUS_GREATER) {
3392 dynamic_class_name_variable_property();
3396 private void dynamic_class_name_variable_property() {
3397 // dynamic_class_name_variable_property:
3398 // T_OBJECT_OPERATOR object_property
3399 if (Scanner.TRACE) {
3400 System.out.println("TRACE: dynamic_class_name_variable_property()");
3402 if (token == TokenName.MINUS_GREATER) {
3408 private void ctor_arguments() {
3411 // | '(' function_call_parameter_list ')'
3412 if (token == TokenName.LPAREN) {
3414 if (token == TokenName.RPAREN) {
3418 non_empty_function_call_parameter_list();
3419 if (token != TokenName.RPAREN) {
3420 throwSyntaxError("')' expected in ctor_arguments.");
3426 private void assignment_list() {
3428 // assignment_list ',' assignment_list_element
3429 // | assignment_list_element
3431 assignment_list_element();
3432 if (token != TokenName.COMMA) {
3439 private void assignment_list_element() {
3440 // assignment_list_element:
3442 // | T_LIST '(' assignment_list ')'
3444 if (token == TokenName.VARIABLE) {
3445 variable(true, false);
3446 } else if (token == TokenName.DOLLAR) {
3447 variable(false, false);
3448 } else if (token == TokenName.IDENTIFIER) {
3449 identifier(true, true, false);
3451 if (token == TokenName.LIST) {
3453 if (token == TokenName.LPAREN) {
3456 if (token != TokenName.RPAREN) {
3457 throwSyntaxError("')' expected after 'list' keyword.");
3461 throwSyntaxError("'(' expected after 'list' keyword.");
3467 private void array_pair_list() {
3470 // | non_empty_array_pair_list possible_comma
3471 non_empty_array_pair_list();
3472 if (token == TokenName.COMMA) {
3477 private void non_empty_array_pair_list() {
3478 // non_empty_array_pair_list:
3479 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3480 // | non_empty_array_pair_list ',' expr
3481 // | expr T_DOUBLE_ARROW expr
3483 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3484 // | non_empty_array_pair_list ',' '&' w_variable
3485 // | expr T_DOUBLE_ARROW '&' w_variable
3488 if (token == TokenName.OP_AND) {
3490 variable(true, false);
3493 if (token == TokenName.OP_AND) {
3495 variable(true, false);
3496 } else if (token == TokenName.EQUAL_GREATER) {
3498 if (token == TokenName.OP_AND) {
3500 variable(true, false);
3506 if (token != TokenName.COMMA) {
3510 if (token == TokenName.RPAREN) {
3516 // private void variableList() {
3519 // if (token == TokenName.COMMA) {
3526 private Expression variable_without_objects(boolean lefthandside,
3527 boolean ignoreVar) {
3528 // variable_without_objects:
3529 // reference_variable
3530 // | simple_indirect_reference reference_variable
3531 if (Scanner.TRACE) {
3532 System.out.println("TRACE: variable_without_objects()");
3534 while (token == TokenName.DOLLAR) {
3537 return reference_variable(lefthandside, ignoreVar);
3540 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3542 // T_STRING '(' function_call_parameter_list ')'
3543 // | class_constant '(' function_call_parameter_list ')'
3544 // | static_member '(' function_call_parameter_list ')'
3545 // | variable_without_objects '(' function_call_parameter_list ')'
3546 char[] defineName = null;
3547 char[] ident = null;
3550 Expression ref = null;
3551 if (Scanner.TRACE) {
3552 System.out.println("TRACE: function_call()");
3554 if (token == TokenName.IDENTIFIER) {
3555 ident = scanner.getCurrentIdentifierSource();
3557 startPos = scanner.getCurrentTokenStartPosition();
3558 endPos = scanner.getCurrentTokenEndPosition();
3561 case PAAMAYIM_NEKUDOTAYIM:
3565 if (token == TokenName.IDENTIFIER) {
3570 variable_without_objects(true, false);
3575 ref = variable_without_objects(lefthandside, ignoreVar);
3577 if (token != TokenName.LPAREN) {
3578 if (defineName != null) {
3579 // does this identifier contain only uppercase characters?
3580 if (defineName.length == 3) {
3581 if (defineName[0] == 'd' &&
3582 defineName[1] == 'i' &&
3583 defineName[2] == 'e') {
3586 } else if (defineName.length == 4) {
3587 if (defineName[0] == 't' &&
3588 defineName[1] == 'r' &&
3589 defineName[2] == 'u' &&
3590 defineName[3] == 'e') {
3592 } else if (defineName[0] == 'n' &&
3593 defineName[1] == 'u' &&
3594 defineName[2] == 'l' &&
3595 defineName[3] == 'l') {
3598 } else if (defineName.length == 5) {
3599 if (defineName[0] == 'f' &&
3600 defineName[1] == 'a' &&
3601 defineName[2] == 'l' &&
3602 defineName[3] == 's' &&
3603 defineName[4] == 'e') {
3607 if (defineName != null) {
3608 for (int i = 0; i < defineName.length; i++) {
3609 if (Character.isLowerCase(defineName[i])) {
3610 problemReporter.phpUppercaseIdentifierWarning(
3611 startPos, endPos, referenceContext,
3612 compilationUnit.compilationResult);
3620 if (token == TokenName.RPAREN) {
3625 non_empty_function_call_parameter_list();
3627 if (token != TokenName.RPAREN) {
3628 String functionName;
3630 if (ident == null) {
3631 functionName = new String(" ");
3633 functionName = new String(ident);
3636 throwSyntaxError("')' expected in function call (" + functionName + ").");
3643 private void non_empty_function_call_parameter_list() {
3644 this.non_empty_function_call_parameter_list(null);
3647 // private void function_call_parameter_list() {
3648 // function_call_parameter_list:
3649 // non_empty_function_call_parameter_list { $$ = $1; }
3652 private void non_empty_function_call_parameter_list(String functionName) {
3653 // non_empty_function_call_parameter_list:
3654 // expr_without_variable
3657 // | non_empty_function_call_parameter_list ',' expr_without_variable
3658 // | non_empty_function_call_parameter_list ',' variable
3659 // | non_empty_function_call_parameter_list ',' '&' w_variable
3660 if (Scanner.TRACE) {
3662 .println("TRACE: non_empty_function_call_parameter_list()");
3664 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3665 initHandler.setFunctionName(functionName);
3667 initHandler.incrementArgumentCount();
3668 if (token == TokenName.OP_AND) {
3672 // if (token == TokenName.Identifier || token ==
3673 // TokenName.Variable
3674 // || token == TokenName.DOLLAR) {
3677 expr_without_variable(true, initHandler, false);
3680 if (token != TokenName.COMMA) {
3687 private void fully_qualified_class_name() {
3688 if (token == TokenName.IDENTIFIER) {
3691 throwSyntaxError("Class name expected.");
3695 private void static_member() {
3697 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3698 // variable_without_objects
3699 if (Scanner.TRACE) {
3700 System.out.println("TRACE: static_member()");
3702 fully_qualified_class_name();
3703 if (token != TokenName.PAAMAYIM_NEKUDOTAYIM) {
3704 throwSyntaxError("'::' expected after class name (static_member).");
3707 variable_without_objects(false, false);
3711 * base_variable_with_function_calls:
3712 * base_variable | function_call
3714 * @param lefthandside
3718 private Expression base_variable_with_function_calls (boolean lefthandside, boolean ignoreVar) {
3719 if (Scanner.TRACE) {
3720 System.out.println("TRACE: base_variable_with_function_calls()");
3723 return function_call(lefthandside, ignoreVar);
3728 * reference_variable
3729 * | simple_indirect_reference reference_variable
3732 * @param lefthandside
3735 private Expression base_variable (boolean lefthandside) {
3736 Expression ref = null;
3738 if (Scanner.TRACE) {
3739 System.out.println ("TRACE: base_variable()");
3742 if (token == TokenName.IDENTIFIER) {
3746 while (token == TokenName.DOLLAR) {
3750 reference_variable (lefthandside, false);
3756 // private void simple_indirect_reference() {
3757 // // simple_indirect_reference:
3759 // //| simple_indirect_reference '$'
3761 private Expression reference_variable (boolean lefthandside, boolean ignoreVar) {
3762 // reference_variable:
3763 // reference_variable '[' dim_offset ']'
3764 // | reference_variable '{' expr '}'
3765 // | compound_variable
3766 Expression ref = null;
3767 if (Scanner.TRACE) {
3768 System.out.println("TRACE: reference_variable()");
3770 ref = compound_variable(lefthandside, ignoreVar);
3772 if (token == TokenName.LBRACE) {
3776 if (token != TokenName.RBRACE) {
3777 throwSyntaxError("'}' expected in reference variable.");
3780 } else if (token == TokenName.LBRACKET) {
3781 // To remove "ref = null;" here, is probably better than the
3783 // commented in #1368081 - axelcl
3785 if (token != TokenName.RBRACKET) {
3788 if (token != TokenName.RBRACKET) {
3789 throwSyntaxError("']' expected in reference variable.");
3800 private Expression compound_variable (boolean lefthandside, boolean ignoreVar) {
3801 // compound_variable:
3803 // | '$' '{' expr '}'
3804 if (Scanner.TRACE) {
3805 System.out.println("TRACE: compound_variable()");
3808 if (token == TokenName.VARIABLE) {
3809 if (!lefthandside) {
3810 if (!containsVariableSet()) {
3811 // reportSyntaxError("The local variable " + new
3812 // String(scanner.getCurrentIdentifierSource())
3813 // + " may not have been initialized");
3814 problemReporter.uninitializedLocalVariable (
3815 new String (scanner.getCurrentIdentifierSource()),
3816 scanner.getCurrentTokenStartPosition(),
3817 scanner.getCurrentTokenEndPosition(),
3819 compilationUnit.compilationResult);
3827 FieldReference ref = new FieldReference (scanner.getCurrentIdentifierSource(),
3828 scanner.getCurrentTokenStartPosition());
3833 // because of simple_indirect_reference
3834 while (token == TokenName.DOLLAR) {
3838 if (token != TokenName.LBRACE) {
3839 reportSyntaxError("'{' expected after compound variable token '$'.");
3846 if (token != TokenName.RBRACE) {
3847 throwSyntaxError("'}' expected after compound variable token '$'.");
3854 } // private void dim_offset() { // // dim_offset: // // /* empty */
3859 private void object_property() {
3862 // | variable_without_objects
3863 if (Scanner.TRACE) {
3864 System.out.println("TRACE: object_property()");
3867 if ((token == TokenName.VARIABLE) ||
3868 (token == TokenName.DOLLAR)) {
3869 variable_without_objects (false, false);
3876 private void object_dim_list() {
3878 // object_dim_list '[' dim_offset ']'
3879 // | object_dim_list '{' expr '}'
3881 if (Scanner.TRACE) {
3882 System.out.println("TRACE: object_dim_list()");
3888 if (token == TokenName.LBRACE) {
3892 if (token != TokenName.RBRACE) {
3893 throwSyntaxError("'}' expected in object_dim_list.");
3898 else if (token == TokenName.LBRACKET) {
3901 if (token == TokenName.RBRACKET) {
3908 if (token != TokenName.RBRACKET) {
3909 throwSyntaxError("']' expected in object_dim_list.");
3920 private void variable_name() {
3924 if (Scanner.TRACE) {
3925 System.out.println("TRACE: variable_name()");
3928 if ((token == TokenName.IDENTIFIER) ||
3929 (token.compareTo (TokenName.KEYWORD) > 0)) {
3930 if (token.compareTo (TokenName.KEYWORD) > 0) {
3931 // TODO show a warning "Keyword used as variable" ?
3936 else if ((token == TokenName.OP_AND_OLD) || // If the found token is e.g $var->and
3937 (token == TokenName.OP_OR_OLD) || // or is $var->or
3938 (token == TokenName.OP_XOR_OLD)) { // or is $var->xor
3939 getNextToken (); // get the next token. Maybe we should issue an warning?
3942 if (token != TokenName.LBRACE) {
3943 throwSyntaxError("'{' expected in variable name.");
3949 if (token != TokenName.RBRACE) {
3950 throwSyntaxError("'}' expected in variable name.");
3957 private void r_variable() {
3958 variable(false, false);
3961 private void w_variable(boolean lefthandside) {
3962 variable(lefthandside, false);
3965 private void rw_variable() {
3966 variable(false, false);
3972 * base_variable_with_function_calls T_OBJECT_OPERATOR
3973 * object_property method_or_not variable_properties
3974 * | base_variable_with_function_calls
3976 * @param lefthandside
3980 private Expression variable (boolean lefthandside, boolean ignoreVar) {
3981 Expression ref = base_variable_with_function_calls (lefthandside, ignoreVar);
3983 if ((token == TokenName.MINUS_GREATER) ||
3984 (token == TokenName.PAAMAYIM_NEKUDOTAYIM)) {
3985 /* 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,
3986 * nor would it be checked for beeing unitialized. So I don't set it to null!
3992 variable_properties();
3998 private void variable_properties() {
3999 // variable_properties:
4000 // variable_properties variable_property
4002 while (token == TokenName.MINUS_GREATER) {
4003 variable_property();
4007 private void variable_property() {
4008 // variable_property:
4009 // T_OBJECT_OPERATOR object_property method_or_not
4010 if (Scanner.TRACE) {
4011 System.out.println("TRACE: variable_property()");
4014 if (token == TokenName.MINUS_GREATER) {
4020 throwSyntaxError("'->' expected in variable_property.");
4027 * base_variable_with_function_calls T_OBJECT_OPERATOR
4028 * object_property method_or_not variable_properties
4029 * | base_variable_with_function_calls
4031 * Expression ref = function_call(lefthandside, ignoreVar);
4034 * T_STRING '(' function_call_parameter_list ')'
4035 * | class_constant '(' function_call_parameter_list ')'
4036 * | static_member '(' function_call_parameter_list ')'
4037 * | variable_without_objects '(' function_call_parameter_list ')'
4039 * @param lefthandside
4044 private Expression identifier (boolean lefthandside, boolean ignoreVar, boolean bColonAllowed) {
4045 char[] defineName = null;
4046 char[] ident = null;
4049 Expression ref = null;
4051 if (Scanner.TRACE) {
4052 System.out.println("TRACE: function_call()");
4055 if (token == TokenName.IDENTIFIER) {
4056 ident = scanner.getCurrentIdentifierSource();
4058 startPos = scanner.getCurrentTokenStartPosition();
4059 endPos = scanner.getCurrentTokenEndPosition();
4061 getNextToken(); // Get the token after the identifier
4067 case MULTIPLY_EQUAL:
4070 case REMAINDER_EQUAL:
4074 case RIGHT_SHIFT_EQUAL:
4075 case LEFT_SHIFT_EQUAL:
4076 String error = "Assignment operator '"
4077 + scanner.toStringAction(token)
4078 + "' not allowed after identifier '"
4080 + "' (use 'define(...)' to define constants).";
4081 reportSyntaxError(error);
4085 if (token == TokenName.COLON) { // If it's a ':', the identifier is a label
4090 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) { // '::'
4093 getNextToken (); // Read the identifier
4095 if (token == TokenName.IDENTIFIER) { // class _constant
4098 else { // static member:
4099 variable_without_objects (true, false);
4103 else if (token == TokenName.BACKSLASH) { // '\' namespace path separator
4106 if (token == TokenName.IDENTIFIER) { // If it's an identifier
4107 getNextToken (); // go for the next token
4109 else { // It's not an identifiere, something wrong
4110 throwSyntaxError ("an identifier expected after '\\' ");
4118 else { // Token is not an identifier
4119 ref = variable_without_objects(lefthandside, ignoreVar);
4122 if (token == TokenName.LPAREN) { // If token is '('
4125 if (token == TokenName.RPAREN) { // If token is ')'
4130 String functionName;
4132 if (ident == null) {
4133 functionName = new String(" ");
4135 functionName = new String(ident);
4138 non_empty_function_call_parameter_list(functionName); // Get the parameter list for the given function name
4140 if (token != TokenName.RPAREN) { // If token is not a ')', throw error
4141 throwSyntaxError ("')' expected in function call (" + functionName + ").");
4144 getNextToken(); // Get the token after ')'
4147 else { // It's not an '('
4148 if (defineName != null) { // does this identifier contain only uppercase characters?
4149 if (defineName.length == 3) { // If it's a 'die'
4150 if (defineName[0] == 'd' &&
4151 defineName[1] == 'i' &&
4152 defineName[2] == 'e') {
4156 else if (defineName.length == 4) { // If it's a 'true'
4157 if (defineName[0] == 't' &&
4158 defineName[1] == 'r' &&
4159 defineName[2] == 'u' &&
4160 defineName[3] == 'e') {
4163 else if (defineName[0] == 'n' && // If it's a 'null'
4164 defineName[1] == 'u' &&
4165 defineName[2] == 'l' &&
4166 defineName[3] == 'l') {
4170 else if (defineName.length == 5) { // If it's a 'false'
4171 if (defineName[0] == 'f' &&
4172 defineName[1] == 'a' &&
4173 defineName[2] == 'l' &&
4174 defineName[3] == 's' &&
4175 defineName[4] == 'e') {
4180 if (defineName != null) {
4181 for (int i = 0; i < defineName.length; i++) {
4182 if (Character.isLowerCase (defineName[i])) {
4183 problemReporter.phpUppercaseIdentifierWarning (startPos, endPos, referenceContext,
4184 compilationUnit.compilationResult);
4190 // TODO is this ok ?
4192 // throwSyntaxError("'(' expected in function call.");
4195 if (token == TokenName.MINUS_GREATER) {
4200 variable_properties();
4203 // A colon is only allowed here if it is an expression read after a '?'
4205 if ((token == TokenName.COLON) &&
4207 throwSyntaxError ("No ':' allowed");
4213 private void method_or_not() {
4215 // '(' function_call_parameter_list ')'
4217 if (Scanner.TRACE) {
4218 System.out.println("TRACE: method_or_not()");
4220 if (token == TokenName.LPAREN) {
4222 if (token == TokenName.RPAREN) {
4226 non_empty_function_call_parameter_list();
4227 if (token != TokenName.RPAREN) {
4228 throwSyntaxError("')' expected in method_or_not.");
4234 private void exit_expr() {
4238 if (token != TokenName.LPAREN) {
4242 if (token == TokenName.RPAREN) {
4247 if (token != TokenName.RPAREN) {
4248 throwSyntaxError("')' expected after keyword 'exit'");
4253 // private void encaps_list() {
4254 // // encaps_list encaps_var
4255 // // | encaps_list T_STRING
4256 // // | encaps_list T_NUM_STRING
4257 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
4258 // // | encaps_list T_CHARACTER
4259 // // | encaps_list T_BAD_CHARACTER
4260 // // | encaps_list '['
4261 // // | encaps_list ']'
4262 // // | encaps_list '{'
4263 // // | encaps_list '}'
4264 // // | encaps_list T_OBJECT_OPERATOR
4268 // case TokenName.STRING:
4271 // case TokenName.LBRACE:
4272 // // scanner.encapsedStringStack.pop();
4275 // case TokenName.RBRACE:
4276 // // scanner.encapsedStringStack.pop();
4279 // case TokenName.LBRACKET:
4280 // // scanner.encapsedStringStack.pop();
4283 // case TokenName.RBRACKET:
4284 // // scanner.encapsedStringStack.pop();
4287 // case TokenName.MINUS_GREATER:
4288 // // scanner.encapsedStringStack.pop();
4291 // case TokenName.Variable:
4292 // case TokenName.DOLLAR_LBRACE:
4293 // case TokenName.LBRACE_DOLLAR:
4297 // char encapsedChar = ((Character)
4298 // scanner.encapsedStringStack.peek()).charValue();
4299 // if (encapsedChar == '$') {
4300 // scanner.encapsedStringStack.pop();
4301 // encapsedChar = ((Character)
4302 // scanner.encapsedStringStack.peek()).charValue();
4303 // switch (encapsedChar) {
4305 // if (token == TokenName.EncapsedString0) {
4308 // token = TokenName.STRING;
4311 // if (token == TokenName.EncapsedString1) {
4314 // token = TokenName.STRING;
4317 // if (token == TokenName.EncapsedString2) {
4320 // token = TokenName.STRING;
4329 // private void encaps_var() {
4331 // // | T_VARIABLE '[' encaps_var_offset ']'
4332 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
4333 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
4334 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
4335 // // | T_CURLY_OPEN variable '}'
4337 // case TokenName.Variable:
4339 // if (token == TokenName.LBRACKET) {
4341 // expr(); //encaps_var_offset();
4342 // if (token != TokenName.RBRACKET) {
4343 // throwSyntaxError("']' expected after variable.");
4345 // // scanner.encapsedStringStack.pop();
4348 // } else if (token == TokenName.MINUS_GREATER) {
4350 // if (token != TokenName.Identifier) {
4351 // throwSyntaxError("Identifier expected after '->'.");
4353 // // scanner.encapsedStringStack.pop();
4357 // // // scanner.encapsedStringStack.pop();
4358 // // int tempToken = TokenName.STRING;
4359 // // if (!scanner.encapsedStringStack.isEmpty()
4360 // // && (token == TokenName.EncapsedString0
4361 // // || token == TokenName.EncapsedString1
4362 // // || token == TokenName.EncapsedString2 || token ==
4363 // // TokenName.ERROR)) {
4364 // // char encapsedChar = ((Character)
4365 // // scanner.encapsedStringStack.peek())
4367 // // switch (token) {
4368 // // case TokenName.EncapsedString0 :
4369 // // if (encapsedChar == '`') {
4370 // // tempToken = TokenName.EncapsedString0;
4373 // // case TokenName.EncapsedString1 :
4374 // // if (encapsedChar == '\'') {
4375 // // tempToken = TokenName.EncapsedString1;
4378 // // case TokenName.EncapsedString2 :
4379 // // if (encapsedChar == '"') {
4380 // // tempToken = TokenName.EncapsedString2;
4383 // // case TokenName.ERROR :
4384 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
4385 // // scanner.currentPosition--;
4386 // // getNextToken();
4391 // // token = tempToken;
4394 // case TokenName.DOLLAR_LBRACE:
4396 // if (token == TokenName.DOLLAR_LBRACE) {
4398 // } else if (token == TokenName.Identifier) {
4400 // if (token == TokenName.LBRACKET) {
4402 // // if (token == TokenName.RBRACKET) {
4403 // // getNextToken();
4406 // if (token != TokenName.RBRACKET) {
4407 // throwSyntaxError("']' expected after '${'.");
4415 // if (token != TokenName.RBRACE) {
4416 // throwSyntaxError("'}' expected.");
4420 // case TokenName.LBRACE_DOLLAR:
4422 // if (token == TokenName.LBRACE_DOLLAR) {
4424 // } else if (token == TokenName.Identifier || token > TokenName.KEYWORD) {
4426 // if (token == TokenName.LBRACKET) {
4428 // // if (token == TokenName.RBRACKET) {
4429 // // getNextToken();
4432 // if (token != TokenName.RBRACKET) {
4433 // throwSyntaxError("']' expected.");
4437 // } else if (token == TokenName.MINUS_GREATER) {
4439 // if (token != TokenName.Identifier && token != TokenName.Variable) {
4440 // throwSyntaxError("String or Variable token expected.");
4443 // if (token == TokenName.LBRACKET) {
4445 // // if (token == TokenName.RBRACKET) {
4446 // // getNextToken();
4449 // if (token != TokenName.RBRACKET) {
4450 // throwSyntaxError("']' expected after '${'.");
4456 // // if (token != TokenName.RBRACE) {
4457 // // throwSyntaxError("'}' expected after '{$'.");
4459 // // // scanner.encapsedStringStack.pop();
4460 // // getNextToken();
4463 // if (token != TokenName.RBRACE) {
4464 // throwSyntaxError("'}' expected.");
4466 // // scanner.encapsedStringStack.pop();
4473 // private void encaps_var_offset() {
4475 // // | T_NUM_STRING
4478 // case TokenName.STRING:
4481 // case TokenName.IntegerLiteral:
4484 // case TokenName.Variable:
4487 // case TokenName.Identifier:
4491 // throwSyntaxError("Variable or String token expected.");
4499 private void internal_functions_in_yacc() {
4502 // case TokenName.isset:
4503 // // T_ISSET '(' isset_variables ')'
4505 // if (token != TokenName.LPAREN) {
4506 // throwSyntaxError("'(' expected after keyword 'isset'");
4509 // isset_variables();
4510 // if (token != TokenName.RPAREN) {
4511 // throwSyntaxError("')' expected after keyword 'isset'");
4515 // case TokenName.empty:
4516 // // T_EMPTY '(' variable ')'
4518 // if (token != TokenName.LPAREN) {
4519 // throwSyntaxError("'(' expected after keyword 'empty'");
4523 // if (token != TokenName.RPAREN) {
4524 // throwSyntaxError("')' expected after keyword 'empty'");
4530 checkFileName(token);
4533 // T_INCLUDE_ONCE expr
4534 checkFileName(token);
4537 // T_EVAL '(' expr ')'
4539 if (token != TokenName.LPAREN) {
4540 throwSyntaxError("'(' expected after keyword 'eval'");
4544 if (token != TokenName.RPAREN) {
4545 throwSyntaxError("')' expected after keyword 'eval'");
4551 checkFileName(token);
4554 // T_REQUIRE_ONCE expr
4555 checkFileName(token);
4561 * Parse and check the include file name
4563 * @param includeToken
4565 private void checkFileName(TokenName includeToken) {
4566 // <include-token> expr
4567 int start = scanner.getCurrentTokenStartPosition();
4568 boolean hasLPAREN = false;
4570 if (token == TokenName.LPAREN) {
4574 Expression expression = expr();
4576 if (token == TokenName.RPAREN) {
4579 throwSyntaxError("')' expected for keyword '"
4580 + scanner.toStringAction(includeToken) + "'");
4583 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4585 if (scanner.compilationUnit != null) {
4586 IResource resource = scanner.compilationUnit.getResource();
4587 if (resource != null && resource instanceof IFile) {
4588 file = (IFile) resource;
4592 tokens = new char[1][];
4593 tokens[0] = currTokenSource;
4595 ImportReference impt = new ImportReference(tokens, currTokenSource,
4596 start, scanner.getCurrentTokenEndPosition(), false);
4597 impt.declarationSourceEnd = impt.sourceEnd;
4598 impt.declarationEnd = impt.declarationSourceEnd;
4599 // endPosition is just before the ;
4600 impt.declarationSourceStart = start;
4601 includesList.add(impt);
4603 if (expression instanceof StringLiteral) {
4604 StringLiteral literal = (StringLiteral) expression;
4605 char[] includeName = literal.source();
4606 if (includeName.length == 0) {
4607 reportSyntaxError("Empty filename after keyword '"
4608 + scanner.toStringAction(includeToken) + "'",
4609 literal.sourceStart, literal.sourceStart + 1);
4611 String includeNameString = new String(includeName);
4612 if (literal instanceof StringLiteralDQ) {
4613 if (includeNameString.indexOf('$') >= 0) {
4614 // assuming that the filename contains a variable => no
4619 if (includeNameString.startsWith("http://")) {
4620 // assuming external include location
4624 // check the filename:
4625 // System.out.println(new
4626 // String(compilationUnit.getFileName())+" - "+
4627 // expression.toStringExpression());
4628 IProject project = file.getProject();
4629 if (project != null) {
4630 IPath path = PHPFileUtil.determineFilePath(
4631 includeNameString, file, project);
4634 // SyntaxError: "File: << >> doesn't exist in project."
4635 String[] args = { expression.toStringExpression(),
4636 project.getFullPath().toString() };
4637 problemReporter.phpIncludeNotExistWarning(args,
4638 literal.sourceStart, literal.sourceEnd,
4640 compilationUnit.compilationResult);
4643 String filePath = path.toString();
4644 String ext = file.getRawLocation()
4645 .getFileExtension();
4646 int fileExtensionLength = ext == null ? 0 : ext
4649 IFile f = PHPFileUtil.createFile(path, project);
4651 impt.tokens = CharOperation.splitOn('/', filePath
4652 .toCharArray(), 0, filePath.length()
4653 - fileExtensionLength);
4655 } catch (Exception e) {
4656 // the file is outside of the workspace
4664 private void isset_variables() {
4666 // | isset_variables ','
4667 if (token == TokenName.RPAREN) {
4668 throwSyntaxError("Variable expected after keyword 'isset'");
4671 variable(true, false);
4672 if (token == TokenName.COMMA) {
4680 private boolean common_scalar() {
4684 // | T_CONSTANT_ENCAPSED_STRING
4691 case INTEGERLITERAL:
4697 case STRINGDOUBLEQUOTE:
4700 case STRINGSINGLEQUOTE:
4703 case STRINGINTERPOLATED:
4725 // private void scalar() {
4728 // // | T_STRING_VARNAME
4729 // // | class_constant
4730 // // | common_scalar
4731 // // | '"' encaps_list '"'
4732 // // | '\'' encaps_list '\''
4733 // // | T_START_HEREDOC encaps_list T_END_HEREDOC
4734 // throwSyntaxError("Not yet implemented (scalar).");
4737 private void static_scalar() {
4738 // static_scalar: /* compile-time evaluated scalars */
4741 // | '+' static_scalar
4742 // | '-' static_scalar
4743 // | T_ARRAY '(' static_array_pair_list ')'
4744 // | static_class_constant
4745 if (common_scalar()) {
4751 // static_class_constant:
4752 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4753 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
4755 if (token == TokenName.IDENTIFIER) {
4758 throwSyntaxError("Identifier expected after '::' operator.");
4762 case ENCAPSEDSTRING0:
4764 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4765 while (scanner.currentCharacter != '`') {
4766 if (scanner.currentCharacter == '\\') {
4767 scanner.currentPosition++;
4769 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4772 } catch (IndexOutOfBoundsException e) {
4773 throwSyntaxError("'`' expected at end of static string.");
4776 // case TokenName.EncapsedString1:
4778 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4779 // while (scanner.currentCharacter != '\'') {
4780 // if (scanner.currentCharacter == '\\') {
4781 // scanner.currentPosition++;
4783 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4786 // } catch (IndexOutOfBoundsException e) {
4787 // throwSyntaxError("'\'' expected at end of static string.");
4790 // case TokenName.EncapsedString2:
4792 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4793 // while (scanner.currentCharacter != '"') {
4794 // if (scanner.currentCharacter == '\\') {
4795 // scanner.currentPosition++;
4797 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4800 // } catch (IndexOutOfBoundsException e) {
4801 // throwSyntaxError("'\"' expected at end of static string.");
4804 case STRINGSINGLEQUOTE:
4807 case STRINGDOUBLEQUOTE:
4820 if (token != TokenName.LPAREN) {
4821 throwSyntaxError("'(' expected after keyword 'array'");
4824 if (token == TokenName.RPAREN) {
4828 non_empty_static_array_pair_list();
4829 if (token != TokenName.RPAREN) {
4830 throwSyntaxError("')' or ',' expected after keyword 'array'");
4834 // case TokenName.null :
4837 // case TokenName.false :
4840 // case TokenName.true :
4844 throwSyntaxError("Static scalar/constant expected.");
4848 private void non_empty_static_array_pair_list() {
4849 // non_empty_static_array_pair_list:
4850 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4852 // | non_empty_static_array_pair_list ',' static_scalar
4853 // | static_scalar T_DOUBLE_ARROW static_scalar
4857 if (token == TokenName.EQUAL_GREATER) {
4861 if (token != TokenName.COMMA) {
4865 if (token == TokenName.RPAREN) {
4871 // public void reportSyntaxError() { //int act, int currentKind, int
4872 // // stateStackTop) {
4873 // /* remember current scanner position */
4874 // int startPos = scanner.startPosition;
4875 // int currentPos = scanner.currentPosition;
4877 // this.checkAndReportBracketAnomalies(problemReporter());
4878 // /* reset scanner where it was */
4879 // scanner.startPosition = startPos;
4880 // scanner.currentPosition = currentPos;
4883 public static final int RoundBracket = 0;
4885 public static final int SquareBracket = 1;
4887 public static final int CurlyBracket = 2;
4889 public static final int BracketKinds = 3;
4891 protected int[] nestedMethod; // the ptr is nestedType
4893 protected int nestedType, dimensions;
4895 // variable set stack
4896 final static int VariableStackIncrement = 10;
4898 HashMap fTypeVariables = null;
4900 HashMap fMethodVariables = null;
4902 ArrayList fStackUnassigned = new ArrayList();
4905 final static int AstStackIncrement = 100;
4907 protected int astPtr;
4909 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4911 protected int astLengthPtr;
4913 protected int[] astLengthStack;
4915 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4917 public CompilationUnitDeclaration compilationUnit; /*
4922 protected ReferenceContext referenceContext;
4924 protected ProblemReporter problemReporter;
4926 protected CompilerOptions options;
4928 private ArrayList includesList;
4930 // protected CompilationResult compilationResult;
4932 * Returns this parser's problem reporter initialized with its reference
4933 * context. Also it is assumed that a problem is going to be reported, so
4934 * initializes the compilation result's line positions.
4936 public ProblemReporter problemReporter() {
4937 if (scanner.recordLineSeparator) {
4938 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4941 problemReporter.referenceContext = referenceContext;
4942 return problemReporter;
4946 * Reconsider the entire source looking for inconsistencies in {} () []
4948 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4949 // problemReporter) {
4950 // scanner.wasAcr = false;
4951 // boolean anomaliesDetected = false;
4953 // char[] source = scanner.source;
4954 // int[] leftCount = { 0, 0, 0 };
4955 // int[] rightCount = { 0, 0, 0 };
4956 // int[] depths = { 0, 0, 0 };
4957 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4960 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4962 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4964 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4966 // scanner.currentPosition = scanner.initialPosition; //starting
4968 // // (first-zero-based
4970 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4975 // // ---------Consume white space and handles
4976 // // startPosition---------
4977 // boolean isWhiteSpace;
4979 // scanner.startPosition = scanner.currentPosition;
4980 // // if (((scanner.currentCharacter =
4981 // // source[scanner.currentPosition++]) == '\\') &&
4982 // // (source[scanner.currentPosition] == 'u')) {
4983 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4985 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4986 // (scanner.currentCharacter == '\n'))) {
4987 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4988 // // only record line positions we have not
4990 // scanner.pushLineSeparator();
4993 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4995 // } while (isWhiteSpace && (scanner.currentPosition <
4996 // scanner.eofPosition));
4997 // // -------consume token until } is found---------
4998 // switch (scanner.currentCharacter) {
5000 // int index = leftCount[CurlyBracket]++;
5001 // if (index == leftPositions[CurlyBracket].length) {
5002 // System.arraycopy(leftPositions[CurlyBracket], 0,
5003 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
5004 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
5005 // new int[index * 2]), 0, index);
5007 // leftPositions[CurlyBracket][index] = scanner.startPosition;
5008 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
5012 // int index = rightCount[CurlyBracket]++;
5013 // if (index == rightPositions[CurlyBracket].length) {
5014 // System.arraycopy(rightPositions[CurlyBracket], 0,
5015 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
5016 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
5018 // new int[index * 2]), 0, index);
5020 // rightPositions[CurlyBracket][index] = scanner.startPosition;
5021 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
5025 // int index = leftCount[RoundBracket]++;
5026 // if (index == leftPositions[RoundBracket].length) {
5027 // System.arraycopy(leftPositions[RoundBracket], 0,
5028 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
5029 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
5030 // new int[index * 2]), 0, index);
5032 // leftPositions[RoundBracket][index] = scanner.startPosition;
5033 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
5037 // int index = rightCount[RoundBracket]++;
5038 // if (index == rightPositions[RoundBracket].length) {
5039 // System.arraycopy(rightPositions[RoundBracket], 0,
5040 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
5041 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
5043 // new int[index * 2]), 0, index);
5045 // rightPositions[RoundBracket][index] = scanner.startPosition;
5046 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
5050 // int index = leftCount[SquareBracket]++;
5051 // if (index == leftPositions[SquareBracket].length) {
5052 // System.arraycopy(leftPositions[SquareBracket], 0,
5053 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
5054 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
5056 // new int[index * 2]), 0, index);
5058 // leftPositions[SquareBracket][index] = scanner.startPosition;
5059 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
5063 // int index = rightCount[SquareBracket]++;
5064 // if (index == rightPositions[SquareBracket].length) {
5065 // System.arraycopy(rightPositions[SquareBracket], 0,
5066 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
5067 // System.arraycopy(rightDepths[SquareBracket], 0,
5068 // (rightDepths[SquareBracket]
5069 // = new int[index * 2]), 0, index);
5071 // rightPositions[SquareBracket][index] = scanner.startPosition;
5072 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
5076 // if (scanner.getNextChar('\\')) {
5077 // scanner.scanEscapeCharacter();
5078 // } else { // consume next character
5079 // scanner.unicodeAsBackSlash = false;
5080 // // if (((scanner.currentCharacter =
5081 // // source[scanner.currentPosition++]) ==
5083 // // (source[scanner.currentPosition] ==
5085 // // scanner.getNextUnicodeChar();
5087 // if (scanner.withoutUnicodePtr != 0) {
5088 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5089 // scanner.currentCharacter;
5093 // scanner.getNextChar('\'');
5097 // // consume next character
5098 // scanner.unicodeAsBackSlash = false;
5099 // // if (((scanner.currentCharacter =
5100 // // source[scanner.currentPosition++]) == '\\') &&
5101 // // (source[scanner.currentPosition] == 'u')) {
5102 // // scanner.getNextUnicodeChar();
5104 // if (scanner.withoutUnicodePtr != 0) {
5105 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5106 // scanner.currentCharacter;
5109 // while (scanner.currentCharacter != '"') {
5110 // if (scanner.currentCharacter == '\r') {
5111 // if (source[scanner.currentPosition] == '\n')
5112 // scanner.currentPosition++;
5113 // break; // the string cannot go further that
5116 // if (scanner.currentCharacter == '\n') {
5117 // break; // the string cannot go further that
5120 // if (scanner.currentCharacter == '\\') {
5121 // scanner.scanEscapeCharacter();
5123 // // consume next character
5124 // scanner.unicodeAsBackSlash = false;
5125 // // if (((scanner.currentCharacter =
5126 // // source[scanner.currentPosition++]) == '\\')
5127 // // && (source[scanner.currentPosition] == 'u'))
5129 // // scanner.getNextUnicodeChar();
5131 // if (scanner.withoutUnicodePtr != 0) {
5132 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5133 // scanner.currentCharacter;
5140 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
5142 // //get the next char
5143 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5145 // && (source[scanner.currentPosition] == 'u')) {
5146 // //-------------unicode traitement
5148 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5149 // scanner.currentPosition++;
5150 // while (source[scanner.currentPosition] == 'u') {
5151 // scanner.currentPosition++;
5153 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5155 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5158 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5161 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5163 // || c4 < 0) { //error
5167 // scanner.currentCharacter = 'A';
5168 // } //something different from \n and \r
5170 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5173 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
5175 // //get the next char
5176 // scanner.startPosition = scanner.currentPosition;
5177 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5179 // && (source[scanner.currentPosition] == 'u')) {
5180 // //-------------unicode traitement
5182 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5183 // scanner.currentPosition++;
5184 // while (source[scanner.currentPosition] == 'u') {
5185 // scanner.currentPosition++;
5187 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5189 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5192 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5195 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5197 // || c4 < 0) { //error
5201 // scanner.currentCharacter = 'A';
5202 // } //something different from \n
5205 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5209 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
5210 // (scanner.currentCharacter == '\n'))) {
5211 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
5212 // // only record line positions we
5213 // // have not recorded yet
5214 // scanner.pushLineSeparator();
5215 // if (this.scanner.taskTags != null) {
5216 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5218 // .getCurrentTokenEndPosition());
5224 // if (test > 0) { //traditional and annotation
5226 // boolean star = false;
5227 // // consume next character
5228 // scanner.unicodeAsBackSlash = false;
5229 // // if (((scanner.currentCharacter =
5230 // // source[scanner.currentPosition++]) ==
5232 // // (source[scanner.currentPosition] ==
5234 // // scanner.getNextUnicodeChar();
5236 // if (scanner.withoutUnicodePtr != 0) {
5237 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5238 // scanner.currentCharacter;
5241 // if (scanner.currentCharacter == '*') {
5244 // //get the next char
5245 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5247 // && (source[scanner.currentPosition] == 'u')) {
5248 // //-------------unicode traitement
5250 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5251 // scanner.currentPosition++;
5252 // while (source[scanner.currentPosition] == 'u') {
5253 // scanner.currentPosition++;
5255 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5257 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5260 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5263 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5265 // || c4 < 0) { //error
5269 // scanner.currentCharacter = 'A';
5270 // } //something different from * and /
5272 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5275 // //loop until end of comment */
5276 // while ((scanner.currentCharacter != '/') || (!star)) {
5277 // star = scanner.currentCharacter == '*';
5279 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5281 // && (source[scanner.currentPosition] == 'u')) {
5282 // //-------------unicode traitement
5284 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5285 // scanner.currentPosition++;
5286 // while (source[scanner.currentPosition] == 'u') {
5287 // scanner.currentPosition++;
5289 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5291 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5294 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5297 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5299 // || c4 < 0) { //error
5303 // scanner.currentCharacter = 'A';
5304 // } //something different from * and
5307 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5311 // if (this.scanner.taskTags != null) {
5312 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5313 // this.scanner.getCurrentTokenEndPosition());
5320 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
5321 // scanner.scanIdentifierOrKeyword(false);
5324 // if (Character.isDigit(scanner.currentCharacter)) {
5325 // scanner.scanNumber(false);
5329 // //-----------------end switch while
5330 // // try--------------------
5331 // } catch (IndexOutOfBoundsException e) {
5332 // break; // read until EOF
5333 // } catch (InvalidInputException e) {
5334 // return false; // no clue
5337 // if (scanner.recordLineSeparator) {
5338 // compilationUnit.compilationResult.lineSeparatorPositions =
5339 // scanner.getLineEnds();
5341 // // check placement anomalies against other kinds of brackets
5342 // for (int kind = 0; kind < BracketKinds; kind++) {
5343 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
5344 // int start = leftPositions[kind][leftIndex]; // deepest
5346 // // find matching closing bracket
5347 // int depth = leftDepths[kind][leftIndex];
5349 // for (int i = 0; i < rightCount[kind]; i++) {
5350 // int pos = rightPositions[kind][i];
5351 // // want matching bracket further in source with same
5353 // if ((pos > start) && (depth == rightDepths[kind][i])) {
5358 // if (end < 0) { // did not find a good closing match
5359 // problemReporter.unmatchedBracket(start, referenceContext,
5360 // compilationUnit.compilationResult);
5363 // // check if even number of opening/closing other brackets
5364 // // in between this pair of brackets
5366 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
5368 // for (int i = 0; i < leftCount[otherKind]; i++) {
5369 // int pos = leftPositions[otherKind][i];
5370 // if ((pos > start) && (pos < end))
5373 // for (int i = 0; i < rightCount[otherKind]; i++) {
5374 // int pos = rightPositions[otherKind][i];
5375 // if ((pos > start) && (pos < end))
5378 // if (balance != 0) {
5379 // problemReporter.unmatchedBracket(start, referenceContext,
5380 // compilationUnit.compilationResult); //bracket
5386 // // too many opening brackets ?
5387 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
5388 // anomaliesDetected = true;
5389 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
5391 // 1], referenceContext,
5392 // compilationUnit.compilationResult);
5394 // // too many closing brackets ?
5395 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
5396 // anomaliesDetected = true;
5397 // problemReporter.unmatchedBracket(rightPositions[kind][i],
5398 // referenceContext,
5399 // compilationUnit.compilationResult);
5401 // if (anomaliesDetected)
5404 // return anomaliesDetected;
5405 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
5406 // return anomaliesDetected;
5407 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
5408 // return anomaliesDetected;
5411 // protected void pushOnAstLengthStack(int pos) {
5413 // astLengthStack[++astLengthPtr] = pos;
5414 // } catch (IndexOutOfBoundsException e) {
5415 // int oldStackLength = astLengthStack.length;
5416 // int[] oldPos = astLengthStack;
5417 // astLengthStack = new int[oldStackLength + StackIncrement];
5418 // System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5419 // astLengthStack[astLengthPtr] = pos;
5423 protected void pushOnAstStack(ASTNode node) {
5425 * add a new obj on top of the ast stack
5428 astStack[++astPtr] = node;
5429 } catch (IndexOutOfBoundsException e) {
5430 int oldStackLength = astStack.length;
5431 ASTNode[] oldStack = astStack;
5432 astStack = new ASTNode[oldStackLength + AstStackIncrement];
5433 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
5434 astPtr = oldStackLength;
5435 astStack[astPtr] = node;
5438 astLengthStack[++astLengthPtr] = 1;
5439 } catch (IndexOutOfBoundsException e) {
5440 int oldStackLength = astLengthStack.length;
5441 int[] oldPos = astLengthStack;
5442 astLengthStack = new int[oldStackLength + AstStackIncrement];
5443 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5444 astLengthStack[astLengthPtr] = 1;
5448 protected void resetModifiers() {
5449 this.modifiers = AccDefault;
5450 this.modifiersSourceStart = -1; // <-- see comment into
5451 // modifiersFlag(int)
5452 this.scanner.commentPtr = -1;
5455 protected void consumePackageDeclarationName(IFile file) {
5456 // create a package name similar to java package names
5458 //String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
5460 //String filePath = file.getFullPath().toString();
5462 String ext = file.getFileExtension();
5463 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
5464 ImportReference impt;
5467 /*if (filePath.startsWith(projectPath)) {
5468 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
5469 projectPath.length() + 1, filePath.length()
5470 - fileExtensionLength);
5472 String name = file.getName();
5473 tokens = new char[1][];
5474 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5478 this.compilationUnit.currentPackage = impt = new ImportReference(
5479 tokens, new char[0], 0, 0, true);
5481 impt.declarationSourceStart = 0;
5482 impt.declarationSourceEnd = 0;
5483 impt.declarationEnd = 0;
5484 // endPosition is just before the ;
5488 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5489 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5495 private void pushFunctionVariableSet() {
5496 HashSet set = new HashSet();
5497 if (fStackUnassigned.isEmpty()) {
5498 for (int i = 0; i < GLOBALS.length; i++) {
5499 set.add(GLOBALS[i]);
5502 fStackUnassigned.add(set);
5505 private void pushIfVariableSet() {
5506 if (!fStackUnassigned.isEmpty()) {
5507 HashSet set = new HashSet();
5508 fStackUnassigned.add(set);
5512 private HashSet removeIfVariableSet() {
5513 if (!fStackUnassigned.isEmpty()) {
5514 return (HashSet) fStackUnassigned
5515 .remove(fStackUnassigned.size() - 1);
5521 * Returns the <i>set of assigned variables </i> returns null if no Set is
5522 * defined at the current scanner position
5524 private HashSet peekVariableSet() {
5525 if (!fStackUnassigned.isEmpty()) {
5526 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5532 * add the current identifier source to the <i>set of assigned variables
5537 private void addVariableSet(HashSet set) {
5539 set.add(new String(scanner.getCurrentTokenSource()));
5544 * add the current identifier source to the <i>set of assigned variables
5548 private void addVariableSet() {
5549 HashSet set = peekVariableSet();
5551 set.add(new String(scanner.getCurrentTokenSource()));
5556 * add the current identifier source to the <i>set of assigned variables
5560 private void addVariableSet(char[] token) {
5561 HashSet set = peekVariableSet();
5563 set.add(new String(token));
5568 * check if the current identifier source is in the <i>set of assigned
5569 * variables </i> Returns true, if no set is defined for the current scanner
5573 private boolean containsVariableSet() {
5574 return containsVariableSet(scanner.getCurrentTokenSource());
5577 private boolean containsVariableSet(char[] token) {
5579 if (!fStackUnassigned.isEmpty()) {
5581 String str = new String(token);
5582 for (int i = 0; i < fStackUnassigned.size(); i++) {
5583 set = (HashSet) fStackUnassigned.get(i);
5584 if (set.contains(str)) {