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;
3134 if (token != TokenName.INLINE_HTML) {
3135 if (token.compareTo (TokenName.KEYWORD) > 0) {
3139 // System.out.println(scanner.getCurrentTokenStartPosition());
3140 // System.out.println(scanner.getCurrentTokenEndPosition());
3142 throwSyntaxError("Error in expression (found token '"
3143 + scanner.toStringAction(token) + "').");
3149 if (Scanner.TRACE) {
3150 System.out.println("TRACE: expr_without_variable() PART 2");
3153 // | expr T_BOOLEAN_OR expr
3154 // | expr T_BOOLEAN_AND expr
3155 // | expr T_LOGICAL_OR expr
3156 // | expr T_LOGICAL_AND expr
3157 // | expr T_LOGICAL_XOR expr
3169 // | expr T_IS_IDENTICAL expr
3170 // | expr T_IS_NOT_IDENTICAL expr
3171 // | expr T_IS_EQUAL expr
3172 // | expr T_IS_NOT_EQUAL expr
3174 // | expr T_IS_SMALLER_OR_EQUAL expr
3176 // | expr T_IS_GREATER_OR_EQUAL expr
3181 expression = new OR_OR_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR_OR);
3185 expression = new AND_AND_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND_AND);
3189 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3193 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3197 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3201 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3205 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3209 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3213 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3217 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TWIDDLE);
3221 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.PLUS);
3225 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MINUS);
3229 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MULTIPLY);
3233 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.DIVIDE);
3237 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.REMAINDER);
3241 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LEFT_SHIFT);
3245 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.RIGHT_SHIFT);
3247 case EQUAL_EQUAL_EQUAL:
3249 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3251 case NOT_EQUAL_EQUAL:
3253 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3257 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3261 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS);
3265 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS_EQUAL);
3269 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER);
3273 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER_EQUAL);
3275 // | expr T_INSTANCEOF class_name_reference
3276 // | expr '?' expr ':' expr
3279 TypeReference classRef = class_name_reference();
3281 if (classRef != null) {
3282 expression = new InstanceOfExpression (expression, classRef, OperatorIds.INSTANCEOF);
3283 expression.sourceStart = exprSourceStart;
3284 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
3290 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TERNARY_SHORT);
3295 Expression valueIfTrue = expr_without_variable (true, null, true);
3296 if (token != TokenName.COLON) {
3297 throwSyntaxError("':' expected in conditional expression.");
3300 Expression valueIfFalse = expr();
3302 expression = new ConditionalExpression (expression, valueIfTrue, valueIfFalse);
3308 } catch (SyntaxError e) {
3309 // try to find next token after expression with errors:
3310 if (token == TokenName.SEMICOLON) {
3315 if (token == TokenName.RBRACE ||
3316 token == TokenName.RPAREN ||
3317 token == TokenName.RBRACKET) {
3328 private SingleTypeReference class_name_reference() {
3329 // class_name_reference:
3331 // | dynamic_class_name_reference
3332 SingleTypeReference ref = null;
3333 if (Scanner.TRACE) {
3334 System.out.println("TRACE: class_name_reference()");
3336 if (token == TokenName.IDENTIFIER) {
3337 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3338 scanner.getCurrentTokenStartPosition());
3339 int pos = scanner.currentPosition;
3341 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
3342 // Not terminated by T_STRING, reduce to dynamic_class_name_reference
3343 scanner.currentPosition = pos;
3344 token = TokenName.IDENTIFIER;
3346 dynamic_class_name_reference();
3350 dynamic_class_name_reference();
3355 private void dynamic_class_name_reference() {
3356 // dynamic_class_name_reference:
3357 // base_variable T_OBJECT_OPERATOR object_property
3358 // dynamic_class_name_variable_properties
3360 if (Scanner.TRACE) {
3361 System.out.println("TRACE: dynamic_class_name_reference()");
3363 base_variable(true);
3364 if (token == TokenName.MINUS_GREATER) {
3367 dynamic_class_name_variable_properties();
3371 private void dynamic_class_name_variable_properties() {
3372 // dynamic_class_name_variable_properties:
3373 // dynamic_class_name_variable_properties
3374 // dynamic_class_name_variable_property
3376 if (Scanner.TRACE) {
3378 .println("TRACE: dynamic_class_name_variable_properties()");
3380 while (token == TokenName.MINUS_GREATER) {
3381 dynamic_class_name_variable_property();
3385 private void dynamic_class_name_variable_property() {
3386 // dynamic_class_name_variable_property:
3387 // T_OBJECT_OPERATOR object_property
3388 if (Scanner.TRACE) {
3389 System.out.println("TRACE: dynamic_class_name_variable_property()");
3391 if (token == TokenName.MINUS_GREATER) {
3397 private void ctor_arguments() {
3400 // | '(' function_call_parameter_list ')'
3401 if (token == TokenName.LPAREN) {
3403 if (token == TokenName.RPAREN) {
3407 non_empty_function_call_parameter_list();
3408 if (token != TokenName.RPAREN) {
3409 throwSyntaxError("')' expected in ctor_arguments.");
3415 private void assignment_list() {
3417 // assignment_list ',' assignment_list_element
3418 // | assignment_list_element
3420 assignment_list_element();
3421 if (token != TokenName.COMMA) {
3428 private void assignment_list_element() {
3429 // assignment_list_element:
3431 // | T_LIST '(' assignment_list ')'
3433 if (token == TokenName.VARIABLE) {
3434 variable(true, false);
3435 } else if (token == TokenName.DOLLAR) {
3436 variable(false, false);
3437 } else if (token == TokenName.IDENTIFIER) {
3438 identifier(true, true, false);
3440 if (token == TokenName.LIST) {
3442 if (token == TokenName.LPAREN) {
3445 if (token != TokenName.RPAREN) {
3446 throwSyntaxError("')' expected after 'list' keyword.");
3450 throwSyntaxError("'(' expected after 'list' keyword.");
3456 private void array_pair_list() {
3459 // | non_empty_array_pair_list possible_comma
3460 non_empty_array_pair_list();
3461 if (token == TokenName.COMMA) {
3466 private void non_empty_array_pair_list() {
3467 // non_empty_array_pair_list:
3468 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3469 // | non_empty_array_pair_list ',' expr
3470 // | expr T_DOUBLE_ARROW expr
3472 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3473 // | non_empty_array_pair_list ',' '&' w_variable
3474 // | expr T_DOUBLE_ARROW '&' w_variable
3477 if (token == TokenName.OP_AND) {
3479 variable(true, false);
3482 if (token == TokenName.OP_AND) {
3484 variable(true, false);
3485 } else if (token == TokenName.EQUAL_GREATER) {
3487 if (token == TokenName.OP_AND) {
3489 variable(true, false);
3495 if (token != TokenName.COMMA) {
3499 if (token == TokenName.RPAREN) {
3505 // private void variableList() {
3508 // if (token == TokenName.COMMA) {
3515 private Expression variable_without_objects(boolean lefthandside,
3516 boolean ignoreVar) {
3517 // variable_without_objects:
3518 // reference_variable
3519 // | simple_indirect_reference reference_variable
3520 if (Scanner.TRACE) {
3521 System.out.println("TRACE: variable_without_objects()");
3523 while (token == TokenName.DOLLAR) {
3526 return reference_variable(lefthandside, ignoreVar);
3529 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3531 // T_STRING '(' function_call_parameter_list ')'
3532 // | class_constant '(' function_call_parameter_list ')'
3533 // | static_member '(' function_call_parameter_list ')'
3534 // | variable_without_objects '(' function_call_parameter_list ')'
3535 char[] defineName = null;
3536 char[] ident = null;
3539 Expression ref = null;
3540 if (Scanner.TRACE) {
3541 System.out.println("TRACE: function_call()");
3543 if (token == TokenName.IDENTIFIER) {
3544 ident = scanner.getCurrentIdentifierSource();
3546 startPos = scanner.getCurrentTokenStartPosition();
3547 endPos = scanner.getCurrentTokenEndPosition();
3550 case PAAMAYIM_NEKUDOTAYIM:
3554 if (token == TokenName.IDENTIFIER) {
3559 variable_without_objects(true, false);
3564 ref = variable_without_objects(lefthandside, ignoreVar);
3566 if (token != TokenName.LPAREN) {
3567 if (defineName != null) {
3568 // does this identifier contain only uppercase characters?
3569 if (defineName.length == 3) {
3570 if (defineName[0] == 'd' &&
3571 defineName[1] == 'i' &&
3572 defineName[2] == 'e') {
3575 } else if (defineName.length == 4) {
3576 if (defineName[0] == 't' &&
3577 defineName[1] == 'r' &&
3578 defineName[2] == 'u' &&
3579 defineName[3] == 'e') {
3581 } else if (defineName[0] == 'n' &&
3582 defineName[1] == 'u' &&
3583 defineName[2] == 'l' &&
3584 defineName[3] == 'l') {
3587 } else if (defineName.length == 5) {
3588 if (defineName[0] == 'f' &&
3589 defineName[1] == 'a' &&
3590 defineName[2] == 'l' &&
3591 defineName[3] == 's' &&
3592 defineName[4] == 'e') {
3596 if (defineName != null) {
3597 for (int i = 0; i < defineName.length; i++) {
3598 if (Character.isLowerCase(defineName[i])) {
3599 problemReporter.phpUppercaseIdentifierWarning(
3600 startPos, endPos, referenceContext,
3601 compilationUnit.compilationResult);
3609 if (token == TokenName.RPAREN) {
3614 non_empty_function_call_parameter_list();
3616 if (token != TokenName.RPAREN) {
3617 String functionName;
3619 if (ident == null) {
3620 functionName = new String(" ");
3622 functionName = new String(ident);
3625 throwSyntaxError("')' expected in function call (" + functionName + ").");
3632 private void non_empty_function_call_parameter_list() {
3633 this.non_empty_function_call_parameter_list(null);
3636 // private void function_call_parameter_list() {
3637 // function_call_parameter_list:
3638 // non_empty_function_call_parameter_list { $$ = $1; }
3641 private void non_empty_function_call_parameter_list(String functionName) {
3642 // non_empty_function_call_parameter_list:
3643 // expr_without_variable
3646 // | non_empty_function_call_parameter_list ',' expr_without_variable
3647 // | non_empty_function_call_parameter_list ',' variable
3648 // | non_empty_function_call_parameter_list ',' '&' w_variable
3649 if (Scanner.TRACE) {
3651 .println("TRACE: non_empty_function_call_parameter_list()");
3653 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3654 initHandler.setFunctionName(functionName);
3656 initHandler.incrementArgumentCount();
3657 if (token == TokenName.OP_AND) {
3661 // if (token == TokenName.Identifier || token ==
3662 // TokenName.Variable
3663 // || token == TokenName.DOLLAR) {
3666 expr_without_variable(true, initHandler, false);
3669 if (token != TokenName.COMMA) {
3676 private void fully_qualified_class_name() {
3677 if (token == TokenName.IDENTIFIER) {
3680 throwSyntaxError("Class name expected.");
3684 private void static_member() {
3686 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3687 // variable_without_objects
3688 if (Scanner.TRACE) {
3689 System.out.println("TRACE: static_member()");
3691 fully_qualified_class_name();
3692 if (token != TokenName.PAAMAYIM_NEKUDOTAYIM) {
3693 throwSyntaxError("'::' expected after class name (static_member).");
3696 variable_without_objects(false, false);
3700 * base_variable_with_function_calls:
3701 * base_variable | function_call
3703 * @param lefthandside
3707 private Expression base_variable_with_function_calls (boolean lefthandside, boolean ignoreVar) {
3708 if (Scanner.TRACE) {
3709 System.out.println("TRACE: base_variable_with_function_calls()");
3712 return function_call(lefthandside, ignoreVar);
3717 * reference_variable
3718 * | simple_indirect_reference reference_variable
3721 * @param lefthandside
3724 private Expression base_variable (boolean lefthandside) {
3725 Expression ref = null;
3727 if (Scanner.TRACE) {
3728 System.out.println ("TRACE: base_variable()");
3731 if (token == TokenName.IDENTIFIER) {
3735 while (token == TokenName.DOLLAR) {
3739 reference_variable (lefthandside, false);
3745 // private void simple_indirect_reference() {
3746 // // simple_indirect_reference:
3748 // //| simple_indirect_reference '$'
3750 private Expression reference_variable (boolean lefthandside, boolean ignoreVar) {
3751 // reference_variable:
3752 // reference_variable '[' dim_offset ']'
3753 // | reference_variable '{' expr '}'
3754 // | compound_variable
3755 Expression ref = null;
3756 if (Scanner.TRACE) {
3757 System.out.println("TRACE: reference_variable()");
3759 ref = compound_variable(lefthandside, ignoreVar);
3761 if (token == TokenName.LBRACE) {
3765 if (token != TokenName.RBRACE) {
3766 throwSyntaxError("'}' expected in reference variable.");
3769 } else if (token == TokenName.LBRACKET) {
3770 // To remove "ref = null;" here, is probably better than the
3772 // commented in #1368081 - axelcl
3774 if (token != TokenName.RBRACKET) {
3777 if (token != TokenName.RBRACKET) {
3778 throwSyntaxError("']' expected in reference variable.");
3789 private Expression compound_variable (boolean lefthandside, boolean ignoreVar) {
3790 // compound_variable:
3792 // | '$' '{' expr '}'
3793 if (Scanner.TRACE) {
3794 System.out.println("TRACE: compound_variable()");
3797 if (token == TokenName.VARIABLE) {
3798 if (!lefthandside) {
3799 if (!containsVariableSet()) {
3800 // reportSyntaxError("The local variable " + new
3801 // String(scanner.getCurrentIdentifierSource())
3802 // + " may not have been initialized");
3803 problemReporter.uninitializedLocalVariable (
3804 new String (scanner.getCurrentIdentifierSource()),
3805 scanner.getCurrentTokenStartPosition(),
3806 scanner.getCurrentTokenEndPosition(),
3808 compilationUnit.compilationResult);
3816 FieldReference ref = new FieldReference (scanner.getCurrentIdentifierSource(),
3817 scanner.getCurrentTokenStartPosition());
3822 // because of simple_indirect_reference
3823 while (token == TokenName.DOLLAR) {
3827 if (token != TokenName.LBRACE) {
3828 reportSyntaxError("'{' expected after compound variable token '$'.");
3835 if (token != TokenName.RBRACE) {
3836 throwSyntaxError("'}' expected after compound variable token '$'.");
3843 } // private void dim_offset() { // // dim_offset: // // /* empty */
3848 private void object_property() {
3851 // | variable_without_objects
3852 if (Scanner.TRACE) {
3853 System.out.println("TRACE: object_property()");
3856 if ((token == TokenName.VARIABLE) ||
3857 (token == TokenName.DOLLAR)) {
3858 variable_without_objects (false, false);
3865 private void object_dim_list() {
3867 // object_dim_list '[' dim_offset ']'
3868 // | object_dim_list '{' expr '}'
3870 if (Scanner.TRACE) {
3871 System.out.println("TRACE: object_dim_list()");
3877 if (token == TokenName.LBRACE) {
3881 if (token != TokenName.RBRACE) {
3882 throwSyntaxError("'}' expected in object_dim_list.");
3887 else if (token == TokenName.LBRACKET) {
3890 if (token == TokenName.RBRACKET) {
3897 if (token != TokenName.RBRACKET) {
3898 throwSyntaxError("']' expected in object_dim_list.");
3909 private void variable_name() {
3913 if (Scanner.TRACE) {
3914 System.out.println("TRACE: variable_name()");
3917 if ((token == TokenName.IDENTIFIER) ||
3918 (token.compareTo (TokenName.KEYWORD) > 0)) {
3919 if (token.compareTo (TokenName.KEYWORD) > 0) {
3920 // TODO show a warning "Keyword used as variable" ?
3925 else if ((token == TokenName.OP_AND_OLD) || // If the found token is e.g $var->and
3926 (token == TokenName.OP_OR_OLD) || // or is $var->or
3927 (token == TokenName.OP_XOR_OLD)) { // or is $var->xor
3928 getNextToken (); // get the next token. Maybe we should issue an warning?
3931 if (token != TokenName.LBRACE) {
3932 throwSyntaxError("'{' expected in variable name.");
3938 if (token != TokenName.RBRACE) {
3939 throwSyntaxError("'}' expected in variable name.");
3946 private void r_variable() {
3947 variable(false, false);
3950 private void w_variable(boolean lefthandside) {
3951 variable(lefthandside, false);
3954 private void rw_variable() {
3955 variable(false, false);
3961 * base_variable_with_function_calls T_OBJECT_OPERATOR
3962 * object_property method_or_not variable_properties
3963 * | base_variable_with_function_calls
3965 * @param lefthandside
3969 private Expression variable (boolean lefthandside, boolean ignoreVar) {
3970 Expression ref = base_variable_with_function_calls (lefthandside, ignoreVar);
3972 if ((token == TokenName.MINUS_GREATER) ||
3973 (token == TokenName.PAAMAYIM_NEKUDOTAYIM)) {
3974 /* 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,
3975 * nor would it be checked for beeing unitialized. So I don't set it to null!
3981 variable_properties();
3987 private void variable_properties() {
3988 // variable_properties:
3989 // variable_properties variable_property
3991 while (token == TokenName.MINUS_GREATER) {
3992 variable_property();
3996 private void variable_property() {
3997 // variable_property:
3998 // T_OBJECT_OPERATOR object_property method_or_not
3999 if (Scanner.TRACE) {
4000 System.out.println("TRACE: variable_property()");
4003 if (token == TokenName.MINUS_GREATER) {
4009 throwSyntaxError("'->' expected in variable_property.");
4016 * base_variable_with_function_calls T_OBJECT_OPERATOR
4017 * object_property method_or_not variable_properties
4018 * | base_variable_with_function_calls
4020 * Expression ref = function_call(lefthandside, ignoreVar);
4023 * T_STRING '(' function_call_parameter_list ')'
4024 * | class_constant '(' function_call_parameter_list ')'
4025 * | static_member '(' function_call_parameter_list ')'
4026 * | variable_without_objects '(' function_call_parameter_list ')'
4028 * @param lefthandside
4033 private Expression identifier (boolean lefthandside, boolean ignoreVar, boolean bColonAllowed) {
4034 char[] defineName = null;
4035 char[] ident = null;
4038 Expression ref = null;
4040 if (Scanner.TRACE) {
4041 System.out.println("TRACE: function_call()");
4044 if (token == TokenName.IDENTIFIER) {
4045 ident = scanner.getCurrentIdentifierSource();
4047 startPos = scanner.getCurrentTokenStartPosition();
4048 endPos = scanner.getCurrentTokenEndPosition();
4050 getNextToken(); // Get the token after the identifier
4056 case MULTIPLY_EQUAL:
4059 case REMAINDER_EQUAL:
4063 case RIGHT_SHIFT_EQUAL:
4064 case LEFT_SHIFT_EQUAL:
4065 String error = "Assignment operator '"
4066 + scanner.toStringAction(token)
4067 + "' not allowed after identifier '"
4069 + "' (use 'define(...)' to define constants).";
4070 reportSyntaxError(error);
4074 if (token == TokenName.COLON) { // If it's a ':', the identifier is a label
4079 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) { // '::'
4082 getNextToken (); // Read the identifier
4084 if (token == TokenName.IDENTIFIER) { // class _constant
4087 else { // static member:
4088 variable_without_objects (true, false);
4092 else if (token == TokenName.BACKSLASH) { // '\' namespace path separator
4095 if (token == TokenName.IDENTIFIER) { // If it's an identifier
4096 getNextToken (); // go for the next token
4098 else { // It's not an identifiere, something wrong
4099 throwSyntaxError ("an identifier expected after '\\' ");
4107 else { // Token is not an identifier
4108 ref = variable_without_objects(lefthandside, ignoreVar);
4111 if (token == TokenName.LPAREN) { // If token is '('
4114 if (token == TokenName.RPAREN) { // If token is ')'
4119 String functionName;
4121 if (ident == null) {
4122 functionName = new String(" ");
4124 functionName = new String(ident);
4127 non_empty_function_call_parameter_list(functionName); // Get the parameter list for the given function name
4129 if (token != TokenName.RPAREN) { // If token is not a ')', throw error
4130 throwSyntaxError ("')' expected in function call (" + functionName + ").");
4133 getNextToken(); // Get the token after ')'
4136 else { // It's not an '('
4137 if (defineName != null) { // does this identifier contain only uppercase characters?
4138 if (defineName.length == 3) { // If it's a 'die'
4139 if (defineName[0] == 'd' &&
4140 defineName[1] == 'i' &&
4141 defineName[2] == 'e') {
4145 else if (defineName.length == 4) { // If it's a 'true'
4146 if (defineName[0] == 't' &&
4147 defineName[1] == 'r' &&
4148 defineName[2] == 'u' &&
4149 defineName[3] == 'e') {
4152 else if (defineName[0] == 'n' && // If it's a 'null'
4153 defineName[1] == 'u' &&
4154 defineName[2] == 'l' &&
4155 defineName[3] == 'l') {
4159 else if (defineName.length == 5) { // If it's a 'false'
4160 if (defineName[0] == 'f' &&
4161 defineName[1] == 'a' &&
4162 defineName[2] == 'l' &&
4163 defineName[3] == 's' &&
4164 defineName[4] == 'e') {
4169 if (defineName != null) {
4170 for (int i = 0; i < defineName.length; i++) {
4171 if (Character.isLowerCase (defineName[i])) {
4172 problemReporter.phpUppercaseIdentifierWarning (startPos, endPos, referenceContext,
4173 compilationUnit.compilationResult);
4179 // TODO is this ok ?
4181 // throwSyntaxError("'(' expected in function call.");
4184 if (token == TokenName.MINUS_GREATER) {
4189 variable_properties();
4192 // A colon is only allowed here if it is an expression read after a '?'
4194 if ((token == TokenName.COLON) &&
4196 throwSyntaxError ("No ':' allowed");
4202 private void method_or_not() {
4204 // '(' function_call_parameter_list ')'
4206 if (Scanner.TRACE) {
4207 System.out.println("TRACE: method_or_not()");
4209 if (token == TokenName.LPAREN) {
4211 if (token == TokenName.RPAREN) {
4215 non_empty_function_call_parameter_list();
4216 if (token != TokenName.RPAREN) {
4217 throwSyntaxError("')' expected in method_or_not.");
4223 private void exit_expr() {
4227 if (token != TokenName.LPAREN) {
4231 if (token == TokenName.RPAREN) {
4236 if (token != TokenName.RPAREN) {
4237 throwSyntaxError("')' expected after keyword 'exit'");
4242 // private void encaps_list() {
4243 // // encaps_list encaps_var
4244 // // | encaps_list T_STRING
4245 // // | encaps_list T_NUM_STRING
4246 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
4247 // // | encaps_list T_CHARACTER
4248 // // | encaps_list T_BAD_CHARACTER
4249 // // | encaps_list '['
4250 // // | encaps_list ']'
4251 // // | encaps_list '{'
4252 // // | encaps_list '}'
4253 // // | encaps_list T_OBJECT_OPERATOR
4257 // case TokenName.STRING:
4260 // case TokenName.LBRACE:
4261 // // scanner.encapsedStringStack.pop();
4264 // case TokenName.RBRACE:
4265 // // scanner.encapsedStringStack.pop();
4268 // case TokenName.LBRACKET:
4269 // // scanner.encapsedStringStack.pop();
4272 // case TokenName.RBRACKET:
4273 // // scanner.encapsedStringStack.pop();
4276 // case TokenName.MINUS_GREATER:
4277 // // scanner.encapsedStringStack.pop();
4280 // case TokenName.Variable:
4281 // case TokenName.DOLLAR_LBRACE:
4282 // case TokenName.LBRACE_DOLLAR:
4286 // char encapsedChar = ((Character)
4287 // scanner.encapsedStringStack.peek()).charValue();
4288 // if (encapsedChar == '$') {
4289 // scanner.encapsedStringStack.pop();
4290 // encapsedChar = ((Character)
4291 // scanner.encapsedStringStack.peek()).charValue();
4292 // switch (encapsedChar) {
4294 // if (token == TokenName.EncapsedString0) {
4297 // token = TokenName.STRING;
4300 // if (token == TokenName.EncapsedString1) {
4303 // token = TokenName.STRING;
4306 // if (token == TokenName.EncapsedString2) {
4309 // token = TokenName.STRING;
4318 // private void encaps_var() {
4320 // // | T_VARIABLE '[' encaps_var_offset ']'
4321 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
4322 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
4323 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
4324 // // | T_CURLY_OPEN variable '}'
4326 // case TokenName.Variable:
4328 // if (token == TokenName.LBRACKET) {
4330 // expr(); //encaps_var_offset();
4331 // if (token != TokenName.RBRACKET) {
4332 // throwSyntaxError("']' expected after variable.");
4334 // // scanner.encapsedStringStack.pop();
4337 // } else if (token == TokenName.MINUS_GREATER) {
4339 // if (token != TokenName.Identifier) {
4340 // throwSyntaxError("Identifier expected after '->'.");
4342 // // scanner.encapsedStringStack.pop();
4346 // // // scanner.encapsedStringStack.pop();
4347 // // int tempToken = TokenName.STRING;
4348 // // if (!scanner.encapsedStringStack.isEmpty()
4349 // // && (token == TokenName.EncapsedString0
4350 // // || token == TokenName.EncapsedString1
4351 // // || token == TokenName.EncapsedString2 || token ==
4352 // // TokenName.ERROR)) {
4353 // // char encapsedChar = ((Character)
4354 // // scanner.encapsedStringStack.peek())
4356 // // switch (token) {
4357 // // case TokenName.EncapsedString0 :
4358 // // if (encapsedChar == '`') {
4359 // // tempToken = TokenName.EncapsedString0;
4362 // // case TokenName.EncapsedString1 :
4363 // // if (encapsedChar == '\'') {
4364 // // tempToken = TokenName.EncapsedString1;
4367 // // case TokenName.EncapsedString2 :
4368 // // if (encapsedChar == '"') {
4369 // // tempToken = TokenName.EncapsedString2;
4372 // // case TokenName.ERROR :
4373 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
4374 // // scanner.currentPosition--;
4375 // // getNextToken();
4380 // // token = tempToken;
4383 // case TokenName.DOLLAR_LBRACE:
4385 // if (token == TokenName.DOLLAR_LBRACE) {
4387 // } else if (token == TokenName.Identifier) {
4389 // if (token == TokenName.LBRACKET) {
4391 // // if (token == TokenName.RBRACKET) {
4392 // // getNextToken();
4395 // if (token != TokenName.RBRACKET) {
4396 // throwSyntaxError("']' expected after '${'.");
4404 // if (token != TokenName.RBRACE) {
4405 // throwSyntaxError("'}' expected.");
4409 // case TokenName.LBRACE_DOLLAR:
4411 // if (token == TokenName.LBRACE_DOLLAR) {
4413 // } else if (token == TokenName.Identifier || token > TokenName.KEYWORD) {
4415 // if (token == TokenName.LBRACKET) {
4417 // // if (token == TokenName.RBRACKET) {
4418 // // getNextToken();
4421 // if (token != TokenName.RBRACKET) {
4422 // throwSyntaxError("']' expected.");
4426 // } else if (token == TokenName.MINUS_GREATER) {
4428 // if (token != TokenName.Identifier && token != TokenName.Variable) {
4429 // throwSyntaxError("String or Variable token expected.");
4432 // if (token == TokenName.LBRACKET) {
4434 // // if (token == TokenName.RBRACKET) {
4435 // // getNextToken();
4438 // if (token != TokenName.RBRACKET) {
4439 // throwSyntaxError("']' expected after '${'.");
4445 // // if (token != TokenName.RBRACE) {
4446 // // throwSyntaxError("'}' expected after '{$'.");
4448 // // // scanner.encapsedStringStack.pop();
4449 // // getNextToken();
4452 // if (token != TokenName.RBRACE) {
4453 // throwSyntaxError("'}' expected.");
4455 // // scanner.encapsedStringStack.pop();
4462 // private void encaps_var_offset() {
4464 // // | T_NUM_STRING
4467 // case TokenName.STRING:
4470 // case TokenName.IntegerLiteral:
4473 // case TokenName.Variable:
4476 // case TokenName.Identifier:
4480 // throwSyntaxError("Variable or String token expected.");
4488 private void internal_functions_in_yacc() {
4491 // case TokenName.isset:
4492 // // T_ISSET '(' isset_variables ')'
4494 // if (token != TokenName.LPAREN) {
4495 // throwSyntaxError("'(' expected after keyword 'isset'");
4498 // isset_variables();
4499 // if (token != TokenName.RPAREN) {
4500 // throwSyntaxError("')' expected after keyword 'isset'");
4504 // case TokenName.empty:
4505 // // T_EMPTY '(' variable ')'
4507 // if (token != TokenName.LPAREN) {
4508 // throwSyntaxError("'(' expected after keyword 'empty'");
4512 // if (token != TokenName.RPAREN) {
4513 // throwSyntaxError("')' expected after keyword 'empty'");
4519 checkFileName(token);
4522 // T_INCLUDE_ONCE expr
4523 checkFileName(token);
4526 // T_EVAL '(' expr ')'
4528 if (token != TokenName.LPAREN) {
4529 throwSyntaxError("'(' expected after keyword 'eval'");
4533 if (token != TokenName.RPAREN) {
4534 throwSyntaxError("')' expected after keyword 'eval'");
4540 checkFileName(token);
4543 // T_REQUIRE_ONCE expr
4544 checkFileName(token);
4550 * Parse and check the include file name
4552 * @param includeToken
4554 private void checkFileName(TokenName includeToken) {
4555 // <include-token> expr
4556 int start = scanner.getCurrentTokenStartPosition();
4557 boolean hasLPAREN = false;
4559 if (token == TokenName.LPAREN) {
4563 Expression expression = expr();
4565 if (token == TokenName.RPAREN) {
4568 throwSyntaxError("')' expected for keyword '"
4569 + scanner.toStringAction(includeToken) + "'");
4572 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4574 if (scanner.compilationUnit != null) {
4575 IResource resource = scanner.compilationUnit.getResource();
4576 if (resource != null && resource instanceof IFile) {
4577 file = (IFile) resource;
4581 tokens = new char[1][];
4582 tokens[0] = currTokenSource;
4584 ImportReference impt = new ImportReference(tokens, currTokenSource,
4585 start, scanner.getCurrentTokenEndPosition(), false);
4586 impt.declarationSourceEnd = impt.sourceEnd;
4587 impt.declarationEnd = impt.declarationSourceEnd;
4588 // endPosition is just before the ;
4589 impt.declarationSourceStart = start;
4590 includesList.add(impt);
4592 if (expression instanceof StringLiteral) {
4593 StringLiteral literal = (StringLiteral) expression;
4594 char[] includeName = literal.source();
4595 if (includeName.length == 0) {
4596 reportSyntaxError("Empty filename after keyword '"
4597 + scanner.toStringAction(includeToken) + "'",
4598 literal.sourceStart, literal.sourceStart + 1);
4600 String includeNameString = new String(includeName);
4601 if (literal instanceof StringLiteralDQ) {
4602 if (includeNameString.indexOf('$') >= 0) {
4603 // assuming that the filename contains a variable => no
4608 if (includeNameString.startsWith("http://")) {
4609 // assuming external include location
4613 // check the filename:
4614 // System.out.println(new
4615 // String(compilationUnit.getFileName())+" - "+
4616 // expression.toStringExpression());
4617 IProject project = file.getProject();
4618 if (project != null) {
4619 IPath path = PHPFileUtil.determineFilePath(
4620 includeNameString, file, project);
4623 // SyntaxError: "File: << >> doesn't exist in project."
4624 String[] args = { expression.toStringExpression(),
4625 project.getFullPath().toString() };
4626 problemReporter.phpIncludeNotExistWarning(args,
4627 literal.sourceStart, literal.sourceEnd,
4629 compilationUnit.compilationResult);
4632 String filePath = path.toString();
4633 String ext = file.getRawLocation()
4634 .getFileExtension();
4635 int fileExtensionLength = ext == null ? 0 : ext
4638 IFile f = PHPFileUtil.createFile(path, project);
4640 impt.tokens = CharOperation.splitOn('/', filePath
4641 .toCharArray(), 0, filePath.length()
4642 - fileExtensionLength);
4644 } catch (Exception e) {
4645 // the file is outside of the workspace
4653 private void isset_variables() {
4655 // | isset_variables ','
4656 if (token == TokenName.RPAREN) {
4657 throwSyntaxError("Variable expected after keyword 'isset'");
4660 variable(true, false);
4661 if (token == TokenName.COMMA) {
4669 private boolean common_scalar() {
4673 // | T_CONSTANT_ENCAPSED_STRING
4680 case INTEGERLITERAL:
4686 case STRINGDOUBLEQUOTE:
4689 case STRINGSINGLEQUOTE:
4692 case STRINGINTERPOLATED:
4714 // private void scalar() {
4717 // // | T_STRING_VARNAME
4718 // // | class_constant
4719 // // | common_scalar
4720 // // | '"' encaps_list '"'
4721 // // | '\'' encaps_list '\''
4722 // // | T_START_HEREDOC encaps_list T_END_HEREDOC
4723 // throwSyntaxError("Not yet implemented (scalar).");
4726 private void static_scalar() {
4727 // static_scalar: /* compile-time evaluated scalars */
4730 // | '+' static_scalar
4731 // | '-' static_scalar
4732 // | T_ARRAY '(' static_array_pair_list ')'
4733 // | static_class_constant
4734 if (common_scalar()) {
4740 // static_class_constant:
4741 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4742 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
4744 if (token == TokenName.IDENTIFIER) {
4747 throwSyntaxError("Identifier expected after '::' operator.");
4751 case ENCAPSEDSTRING0:
4753 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4754 while (scanner.currentCharacter != '`') {
4755 if (scanner.currentCharacter == '\\') {
4756 scanner.currentPosition++;
4758 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4761 } catch (IndexOutOfBoundsException e) {
4762 throwSyntaxError("'`' expected at end of static string.");
4765 // case TokenName.EncapsedString1:
4767 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4768 // while (scanner.currentCharacter != '\'') {
4769 // if (scanner.currentCharacter == '\\') {
4770 // scanner.currentPosition++;
4772 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4775 // } catch (IndexOutOfBoundsException e) {
4776 // throwSyntaxError("'\'' expected at end of static string.");
4779 // case TokenName.EncapsedString2:
4781 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4782 // while (scanner.currentCharacter != '"') {
4783 // if (scanner.currentCharacter == '\\') {
4784 // scanner.currentPosition++;
4786 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4789 // } catch (IndexOutOfBoundsException e) {
4790 // throwSyntaxError("'\"' expected at end of static string.");
4793 case STRINGSINGLEQUOTE:
4796 case STRINGDOUBLEQUOTE:
4809 if (token != TokenName.LPAREN) {
4810 throwSyntaxError("'(' expected after keyword 'array'");
4813 if (token == TokenName.RPAREN) {
4817 non_empty_static_array_pair_list();
4818 if (token != TokenName.RPAREN) {
4819 throwSyntaxError("')' or ',' expected after keyword 'array'");
4823 // case TokenName.null :
4826 // case TokenName.false :
4829 // case TokenName.true :
4833 throwSyntaxError("Static scalar/constant expected.");
4837 private void non_empty_static_array_pair_list() {
4838 // non_empty_static_array_pair_list:
4839 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4841 // | non_empty_static_array_pair_list ',' static_scalar
4842 // | static_scalar T_DOUBLE_ARROW static_scalar
4846 if (token == TokenName.EQUAL_GREATER) {
4850 if (token != TokenName.COMMA) {
4854 if (token == TokenName.RPAREN) {
4860 // public void reportSyntaxError() { //int act, int currentKind, int
4861 // // stateStackTop) {
4862 // /* remember current scanner position */
4863 // int startPos = scanner.startPosition;
4864 // int currentPos = scanner.currentPosition;
4866 // this.checkAndReportBracketAnomalies(problemReporter());
4867 // /* reset scanner where it was */
4868 // scanner.startPosition = startPos;
4869 // scanner.currentPosition = currentPos;
4872 public static final int RoundBracket = 0;
4874 public static final int SquareBracket = 1;
4876 public static final int CurlyBracket = 2;
4878 public static final int BracketKinds = 3;
4880 protected int[] nestedMethod; // the ptr is nestedType
4882 protected int nestedType, dimensions;
4884 // variable set stack
4885 final static int VariableStackIncrement = 10;
4887 HashMap fTypeVariables = null;
4889 HashMap fMethodVariables = null;
4891 ArrayList fStackUnassigned = new ArrayList();
4894 final static int AstStackIncrement = 100;
4896 protected int astPtr;
4898 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4900 protected int astLengthPtr;
4902 protected int[] astLengthStack;
4904 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4906 public CompilationUnitDeclaration compilationUnit; /*
4911 protected ReferenceContext referenceContext;
4913 protected ProblemReporter problemReporter;
4915 protected CompilerOptions options;
4917 private ArrayList includesList;
4919 // protected CompilationResult compilationResult;
4921 * Returns this parser's problem reporter initialized with its reference
4922 * context. Also it is assumed that a problem is going to be reported, so
4923 * initializes the compilation result's line positions.
4925 public ProblemReporter problemReporter() {
4926 if (scanner.recordLineSeparator) {
4927 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4930 problemReporter.referenceContext = referenceContext;
4931 return problemReporter;
4935 * Reconsider the entire source looking for inconsistencies in {} () []
4937 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4938 // problemReporter) {
4939 // scanner.wasAcr = false;
4940 // boolean anomaliesDetected = false;
4942 // char[] source = scanner.source;
4943 // int[] leftCount = { 0, 0, 0 };
4944 // int[] rightCount = { 0, 0, 0 };
4945 // int[] depths = { 0, 0, 0 };
4946 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4949 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4951 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4953 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4955 // scanner.currentPosition = scanner.initialPosition; //starting
4957 // // (first-zero-based
4959 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4964 // // ---------Consume white space and handles
4965 // // startPosition---------
4966 // boolean isWhiteSpace;
4968 // scanner.startPosition = scanner.currentPosition;
4969 // // if (((scanner.currentCharacter =
4970 // // source[scanner.currentPosition++]) == '\\') &&
4971 // // (source[scanner.currentPosition] == 'u')) {
4972 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4974 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4975 // (scanner.currentCharacter == '\n'))) {
4976 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4977 // // only record line positions we have not
4979 // scanner.pushLineSeparator();
4982 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4984 // } while (isWhiteSpace && (scanner.currentPosition <
4985 // scanner.eofPosition));
4986 // // -------consume token until } is found---------
4987 // switch (scanner.currentCharacter) {
4989 // int index = leftCount[CurlyBracket]++;
4990 // if (index == leftPositions[CurlyBracket].length) {
4991 // System.arraycopy(leftPositions[CurlyBracket], 0,
4992 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4993 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4994 // new int[index * 2]), 0, index);
4996 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4997 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
5001 // int index = rightCount[CurlyBracket]++;
5002 // if (index == rightPositions[CurlyBracket].length) {
5003 // System.arraycopy(rightPositions[CurlyBracket], 0,
5004 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
5005 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
5007 // new int[index * 2]), 0, index);
5009 // rightPositions[CurlyBracket][index] = scanner.startPosition;
5010 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
5014 // int index = leftCount[RoundBracket]++;
5015 // if (index == leftPositions[RoundBracket].length) {
5016 // System.arraycopy(leftPositions[RoundBracket], 0,
5017 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
5018 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
5019 // new int[index * 2]), 0, index);
5021 // leftPositions[RoundBracket][index] = scanner.startPosition;
5022 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
5026 // int index = rightCount[RoundBracket]++;
5027 // if (index == rightPositions[RoundBracket].length) {
5028 // System.arraycopy(rightPositions[RoundBracket], 0,
5029 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
5030 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
5032 // new int[index * 2]), 0, index);
5034 // rightPositions[RoundBracket][index] = scanner.startPosition;
5035 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
5039 // int index = leftCount[SquareBracket]++;
5040 // if (index == leftPositions[SquareBracket].length) {
5041 // System.arraycopy(leftPositions[SquareBracket], 0,
5042 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
5043 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
5045 // new int[index * 2]), 0, index);
5047 // leftPositions[SquareBracket][index] = scanner.startPosition;
5048 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
5052 // int index = rightCount[SquareBracket]++;
5053 // if (index == rightPositions[SquareBracket].length) {
5054 // System.arraycopy(rightPositions[SquareBracket], 0,
5055 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
5056 // System.arraycopy(rightDepths[SquareBracket], 0,
5057 // (rightDepths[SquareBracket]
5058 // = new int[index * 2]), 0, index);
5060 // rightPositions[SquareBracket][index] = scanner.startPosition;
5061 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
5065 // if (scanner.getNextChar('\\')) {
5066 // scanner.scanEscapeCharacter();
5067 // } else { // consume next character
5068 // scanner.unicodeAsBackSlash = false;
5069 // // if (((scanner.currentCharacter =
5070 // // source[scanner.currentPosition++]) ==
5072 // // (source[scanner.currentPosition] ==
5074 // // scanner.getNextUnicodeChar();
5076 // if (scanner.withoutUnicodePtr != 0) {
5077 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5078 // scanner.currentCharacter;
5082 // scanner.getNextChar('\'');
5086 // // consume next character
5087 // scanner.unicodeAsBackSlash = false;
5088 // // if (((scanner.currentCharacter =
5089 // // source[scanner.currentPosition++]) == '\\') &&
5090 // // (source[scanner.currentPosition] == 'u')) {
5091 // // scanner.getNextUnicodeChar();
5093 // if (scanner.withoutUnicodePtr != 0) {
5094 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5095 // scanner.currentCharacter;
5098 // while (scanner.currentCharacter != '"') {
5099 // if (scanner.currentCharacter == '\r') {
5100 // if (source[scanner.currentPosition] == '\n')
5101 // scanner.currentPosition++;
5102 // break; // the string cannot go further that
5105 // if (scanner.currentCharacter == '\n') {
5106 // break; // the string cannot go further that
5109 // if (scanner.currentCharacter == '\\') {
5110 // scanner.scanEscapeCharacter();
5112 // // consume next character
5113 // scanner.unicodeAsBackSlash = false;
5114 // // if (((scanner.currentCharacter =
5115 // // source[scanner.currentPosition++]) == '\\')
5116 // // && (source[scanner.currentPosition] == 'u'))
5118 // // scanner.getNextUnicodeChar();
5120 // if (scanner.withoutUnicodePtr != 0) {
5121 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5122 // scanner.currentCharacter;
5129 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
5131 // //get the next char
5132 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5134 // && (source[scanner.currentPosition] == 'u')) {
5135 // //-------------unicode traitement
5137 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5138 // scanner.currentPosition++;
5139 // while (source[scanner.currentPosition] == 'u') {
5140 // scanner.currentPosition++;
5142 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5144 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5147 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5150 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5152 // || c4 < 0) { //error
5156 // scanner.currentCharacter = 'A';
5157 // } //something different from \n and \r
5159 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5162 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
5164 // //get the next char
5165 // scanner.startPosition = scanner.currentPosition;
5166 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5168 // && (source[scanner.currentPosition] == 'u')) {
5169 // //-------------unicode traitement
5171 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5172 // scanner.currentPosition++;
5173 // while (source[scanner.currentPosition] == 'u') {
5174 // scanner.currentPosition++;
5176 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5178 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5181 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5184 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5186 // || c4 < 0) { //error
5190 // scanner.currentCharacter = 'A';
5191 // } //something different from \n
5194 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5198 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
5199 // (scanner.currentCharacter == '\n'))) {
5200 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
5201 // // only record line positions we
5202 // // have not recorded yet
5203 // scanner.pushLineSeparator();
5204 // if (this.scanner.taskTags != null) {
5205 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5207 // .getCurrentTokenEndPosition());
5213 // if (test > 0) { //traditional and annotation
5215 // boolean star = false;
5216 // // consume next character
5217 // scanner.unicodeAsBackSlash = false;
5218 // // if (((scanner.currentCharacter =
5219 // // source[scanner.currentPosition++]) ==
5221 // // (source[scanner.currentPosition] ==
5223 // // scanner.getNextUnicodeChar();
5225 // if (scanner.withoutUnicodePtr != 0) {
5226 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5227 // scanner.currentCharacter;
5230 // if (scanner.currentCharacter == '*') {
5233 // //get the next char
5234 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5236 // && (source[scanner.currentPosition] == 'u')) {
5237 // //-------------unicode traitement
5239 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5240 // scanner.currentPosition++;
5241 // while (source[scanner.currentPosition] == 'u') {
5242 // scanner.currentPosition++;
5244 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5246 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5249 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5252 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5254 // || c4 < 0) { //error
5258 // scanner.currentCharacter = 'A';
5259 // } //something different from * and /
5261 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5264 // //loop until end of comment */
5265 // while ((scanner.currentCharacter != '/') || (!star)) {
5266 // star = scanner.currentCharacter == '*';
5268 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5270 // && (source[scanner.currentPosition] == 'u')) {
5271 // //-------------unicode traitement
5273 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5274 // scanner.currentPosition++;
5275 // while (source[scanner.currentPosition] == 'u') {
5276 // scanner.currentPosition++;
5278 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5280 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5283 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5286 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5288 // || c4 < 0) { //error
5292 // scanner.currentCharacter = 'A';
5293 // } //something different from * and
5296 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5300 // if (this.scanner.taskTags != null) {
5301 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5302 // this.scanner.getCurrentTokenEndPosition());
5309 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
5310 // scanner.scanIdentifierOrKeyword(false);
5313 // if (Character.isDigit(scanner.currentCharacter)) {
5314 // scanner.scanNumber(false);
5318 // //-----------------end switch while
5319 // // try--------------------
5320 // } catch (IndexOutOfBoundsException e) {
5321 // break; // read until EOF
5322 // } catch (InvalidInputException e) {
5323 // return false; // no clue
5326 // if (scanner.recordLineSeparator) {
5327 // compilationUnit.compilationResult.lineSeparatorPositions =
5328 // scanner.getLineEnds();
5330 // // check placement anomalies against other kinds of brackets
5331 // for (int kind = 0; kind < BracketKinds; kind++) {
5332 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
5333 // int start = leftPositions[kind][leftIndex]; // deepest
5335 // // find matching closing bracket
5336 // int depth = leftDepths[kind][leftIndex];
5338 // for (int i = 0; i < rightCount[kind]; i++) {
5339 // int pos = rightPositions[kind][i];
5340 // // want matching bracket further in source with same
5342 // if ((pos > start) && (depth == rightDepths[kind][i])) {
5347 // if (end < 0) { // did not find a good closing match
5348 // problemReporter.unmatchedBracket(start, referenceContext,
5349 // compilationUnit.compilationResult);
5352 // // check if even number of opening/closing other brackets
5353 // // in between this pair of brackets
5355 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
5357 // for (int i = 0; i < leftCount[otherKind]; i++) {
5358 // int pos = leftPositions[otherKind][i];
5359 // if ((pos > start) && (pos < end))
5362 // for (int i = 0; i < rightCount[otherKind]; i++) {
5363 // int pos = rightPositions[otherKind][i];
5364 // if ((pos > start) && (pos < end))
5367 // if (balance != 0) {
5368 // problemReporter.unmatchedBracket(start, referenceContext,
5369 // compilationUnit.compilationResult); //bracket
5375 // // too many opening brackets ?
5376 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
5377 // anomaliesDetected = true;
5378 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
5380 // 1], referenceContext,
5381 // compilationUnit.compilationResult);
5383 // // too many closing brackets ?
5384 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
5385 // anomaliesDetected = true;
5386 // problemReporter.unmatchedBracket(rightPositions[kind][i],
5387 // referenceContext,
5388 // compilationUnit.compilationResult);
5390 // if (anomaliesDetected)
5393 // return anomaliesDetected;
5394 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
5395 // return anomaliesDetected;
5396 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
5397 // return anomaliesDetected;
5400 // protected void pushOnAstLengthStack(int pos) {
5402 // astLengthStack[++astLengthPtr] = pos;
5403 // } catch (IndexOutOfBoundsException e) {
5404 // int oldStackLength = astLengthStack.length;
5405 // int[] oldPos = astLengthStack;
5406 // astLengthStack = new int[oldStackLength + StackIncrement];
5407 // System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5408 // astLengthStack[astLengthPtr] = pos;
5412 protected void pushOnAstStack(ASTNode node) {
5414 * add a new obj on top of the ast stack
5417 astStack[++astPtr] = node;
5418 } catch (IndexOutOfBoundsException e) {
5419 int oldStackLength = astStack.length;
5420 ASTNode[] oldStack = astStack;
5421 astStack = new ASTNode[oldStackLength + AstStackIncrement];
5422 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
5423 astPtr = oldStackLength;
5424 astStack[astPtr] = node;
5427 astLengthStack[++astLengthPtr] = 1;
5428 } catch (IndexOutOfBoundsException e) {
5429 int oldStackLength = astLengthStack.length;
5430 int[] oldPos = astLengthStack;
5431 astLengthStack = new int[oldStackLength + AstStackIncrement];
5432 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5433 astLengthStack[astLengthPtr] = 1;
5437 protected void resetModifiers() {
5438 this.modifiers = AccDefault;
5439 this.modifiersSourceStart = -1; // <-- see comment into
5440 // modifiersFlag(int)
5441 this.scanner.commentPtr = -1;
5444 protected void consumePackageDeclarationName(IFile file) {
5445 // create a package name similar to java package names
5447 //String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
5449 //String filePath = file.getFullPath().toString();
5451 String ext = file.getFileExtension();
5452 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
5453 ImportReference impt;
5456 /*if (filePath.startsWith(projectPath)) {
5457 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
5458 projectPath.length() + 1, filePath.length()
5459 - fileExtensionLength);
5461 String name = file.getName();
5462 tokens = new char[1][];
5463 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5467 this.compilationUnit.currentPackage = impt = new ImportReference(
5468 tokens, new char[0], 0, 0, true);
5470 impt.declarationSourceStart = 0;
5471 impt.declarationSourceEnd = 0;
5472 impt.declarationEnd = 0;
5473 // endPosition is just before the ;
5477 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5478 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5484 private void pushFunctionVariableSet() {
5485 HashSet set = new HashSet();
5486 if (fStackUnassigned.isEmpty()) {
5487 for (int i = 0; i < GLOBALS.length; i++) {
5488 set.add(GLOBALS[i]);
5491 fStackUnassigned.add(set);
5494 private void pushIfVariableSet() {
5495 if (!fStackUnassigned.isEmpty()) {
5496 HashSet set = new HashSet();
5497 fStackUnassigned.add(set);
5501 private HashSet removeIfVariableSet() {
5502 if (!fStackUnassigned.isEmpty()) {
5503 return (HashSet) fStackUnassigned
5504 .remove(fStackUnassigned.size() - 1);
5510 * Returns the <i>set of assigned variables </i> returns null if no Set is
5511 * defined at the current scanner position
5513 private HashSet peekVariableSet() {
5514 if (!fStackUnassigned.isEmpty()) {
5515 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5521 * add the current identifier source to the <i>set of assigned variables
5526 private void addVariableSet(HashSet set) {
5528 set.add(new String(scanner.getCurrentTokenSource()));
5533 * add the current identifier source to the <i>set of assigned variables
5537 private void addVariableSet() {
5538 HashSet set = peekVariableSet();
5540 set.add(new String(scanner.getCurrentTokenSource()));
5545 * add the current identifier source to the <i>set of assigned variables
5549 private void addVariableSet(char[] token) {
5550 HashSet set = peekVariableSet();
5552 set.add(new String(token));
5557 * check if the current identifier source is in the <i>set of assigned
5558 * variables </i> Returns true, if no set is defined for the current scanner
5562 private boolean containsVariableSet() {
5563 return containsVariableSet(scanner.getCurrentTokenSource());
5566 private boolean containsVariableSet(char[] token) {
5568 if (!fStackUnassigned.isEmpty()) {
5570 String str = new String(token);
5571 for (int i = 0; i < fStackUnassigned.size(); i++) {
5572 set = (HashSet) fStackUnassigned.get(i);
5573 if (set.contains(str)) {