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);
865 if (token != TokenName.SEMICOLON) {
868 if (token == TokenName.SEMICOLON) {
869 sourceEnd = scanner.getCurrentTokenEndPosition();
872 if (token != TokenName.INLINE_HTML) {
873 throwSyntaxError("';' expected after 'return'.");
875 sourceEnd = scanner.getCurrentTokenEndPosition();
878 return new ReturnStatement(expression, sourceStart, sourceEnd);
881 getNextToken(); // Read the token after 'echo'
882 expressionList(); // Read everything after 'echo'
883 if (token == TokenName.SEMICOLON) {
886 if (token != TokenName.INLINE_HTML) {
887 throwSyntaxError("';' expected after 'echo' statement.");
891 return statement; // return null statement
894 // 0-length token directly after PHP short tag <?=
897 if (token == TokenName.SEMICOLON) {
899 // if (token != TokenName.INLINE_HTML) {
900 // // TODO should this become a configurable warning?
901 // reportSyntaxError("Probably '?>' expected after PHP short tag
902 // expression (only the first expression will be echoed).");
905 if (token != TokenName.INLINE_HTML) {
906 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
919 if (token == TokenName.SEMICOLON) {
922 if (token != TokenName.INLINE_HTML) {
923 throwSyntaxError("';' expected after 'global' statement.");
932 if (token == TokenName.SEMICOLON) {
935 if (token != TokenName.INLINE_HTML) {
936 throwSyntaxError("';' expected after 'static' statement.");
944 if (token == TokenName.LPAREN) {
947 throwSyntaxError("'(' expected after 'unset' statement.");
950 if (token == TokenName.RPAREN) {
953 throwSyntaxError("')' expected after 'unset' statement.");
955 if (token == TokenName.SEMICOLON) {
958 if (token != TokenName.INLINE_HTML) {
959 throwSyntaxError("';' expected after 'unset' statement.");
969 if (token == TokenName.SEMICOLON) { // After the namespace identifier there is a ';'
972 else if (token == TokenName.LBRACE) { // or a '{'
973 getNextToken(); // set to next token
975 if (token != TokenName.RBRACE) { // if next token is not a '}'
976 statementList(); // read the entire block
979 if (token == TokenName.RBRACE) { // If the end is a '}'
980 getNextToken(); // go for the next token
982 else { // Not a '}' as expected
983 throwSyntaxError("'}' expected after 'do' keyword.");
987 if (token != TokenName.INLINE_HTML) {
988 throwSyntaxError("';' expected after 'namespace' statement.");
995 getNextToken (); // This should get the label
997 if (token == TokenName.IDENTIFIER) {
1001 throwSyntaxError("expected a label after goto");
1004 if (token == TokenName.SEMICOLON) { // After the 'goto' label name there is a ';'
1008 throwSyntaxError("expected a ';' after goto label");
1013 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
1014 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1015 methodDecl.modifiers = AccDefault;
1016 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
1019 functionDefinition(methodDecl);
1021 sourceEnd = methodDecl.sourceEnd;
1022 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1023 sourceEnd = methodDecl.declarationSourceStart + 1;
1025 methodDecl.declarationSourceEnd = sourceEnd;
1026 methodDecl.sourceEnd = sourceEnd;
1031 // T_DECLARE '(' declare_list ')' declare_statement
1033 if (token != TokenName.LPAREN) {
1034 throwSyntaxError("'(' expected in 'declare' statement.");
1038 if (token != TokenName.RPAREN) {
1039 throwSyntaxError("')' expected in 'declare' statement.");
1042 declare_statement();
1047 if (token != TokenName.LBRACE) {
1048 throwSyntaxError("'{' expected in 'try' statement.");
1052 if (token != TokenName.RBRACE) {
1053 throwSyntaxError("'}' expected in 'try' statement.");
1060 if (token != TokenName.LPAREN) {
1061 throwSyntaxError("'(' expected in 'catch' statement.");
1064 fully_qualified_class_name();
1065 if (token != TokenName.VARIABLE) {
1066 throwSyntaxError("Variable expected in 'catch' statement.");
1070 if (token != TokenName.RPAREN) {
1071 throwSyntaxError("')' expected in 'catch' statement.");
1074 if (token != TokenName.LBRACE) {
1075 throwSyntaxError("'{' expected in 'catch' statement.");
1078 if (token != TokenName.RBRACE) {
1080 if (token != TokenName.RBRACE) {
1081 throwSyntaxError("'}' expected in 'catch' statement.");
1085 additional_catches();
1091 if (token == TokenName.SEMICOLON) {
1094 throwSyntaxError("';' expected after 'throw' exxpression.");
1103 TypeDeclaration typeDecl = new TypeDeclaration(
1104 this.compilationUnit.compilationResult);
1105 typeDecl.declarationSourceStart = scanner
1106 .getCurrentTokenStartPosition();
1107 typeDecl.declarationSourceEnd = scanner
1108 .getCurrentTokenEndPosition();
1109 typeDecl.name = new char[] { ' ' };
1110 // default super class
1111 typeDecl.superclass = new SingleTypeReference(
1112 TypeConstants.OBJECT, 0);
1113 compilationUnit.types.add(typeDecl);
1114 pushOnAstStack(typeDecl);
1115 unticked_class_declaration_statement(typeDecl);
1124 if (token != TokenName.RBRACE) {
1125 statement = statementList();
1127 if (token == TokenName.RBRACE) {
1131 throwSyntaxError("'}' expected.");
1136 if (token != TokenName.SEMICOLON) {
1140 if (token == TokenName.SEMICOLON) {
1144 else if (token == TokenName.COLON) { // Colon after Label identifier
1149 if (token == TokenName.RBRACE) {
1150 reportSyntaxError("';' expected after expression (Found token: "
1151 + scanner.toStringAction(token) + ")");
1154 if (token != TokenName.INLINE_HTML && token != TokenName.EOF) {
1155 throwSyntaxError("';' expected after expression (Found token: "
1156 + scanner.toStringAction(token) + ")");
1167 private void declare_statement() {
1169 // | ':' inner_statement_list T_ENDDECLARE ';'
1171 if (token == TokenName.COLON) {
1173 // TODO: implement inner_statement_list();
1175 if (token != TokenName.ENDDECLARE) {
1176 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1179 if (token != TokenName.SEMICOLON) {
1180 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1188 private void declare_list() {
1189 // T_STRING '=' static_scalar
1190 // | declare_list ',' T_STRING '=' static_scalar
1192 if (token != TokenName.IDENTIFIER) {
1193 throwSyntaxError("Identifier expected in 'declare' list.");
1196 if (token != TokenName.EQUAL) {
1197 throwSyntaxError("'=' expected in 'declare' list.");
1201 if (token != TokenName.COMMA) {
1208 private void additional_catches() {
1209 while (token == TokenName.CATCH) {
1211 if (token != TokenName.LPAREN) {
1212 throwSyntaxError("'(' expected in 'catch' statement.");
1215 fully_qualified_class_name();
1216 if (token != TokenName.VARIABLE) {
1217 throwSyntaxError("Variable expected in 'catch' statement.");
1221 if (token != TokenName.RPAREN) {
1222 throwSyntaxError("')' expected in 'catch' statement.");
1225 if (token != TokenName.LBRACE) {
1226 throwSyntaxError("'{' expected in 'catch' statement.");
1229 if (token != TokenName.RBRACE) {
1232 if (token != TokenName.RBRACE) {
1233 throwSyntaxError("'}' expected in 'catch' statement.");
1239 private void foreach_variable() {
1242 if (token == TokenName.OP_AND) {
1248 private void foreach_optional_arg() {
1250 // | T_DOUBLE_ARROW foreach_variable
1251 if (token == TokenName.EQUAL_GREATER) {
1257 private void global_var_list() {
1259 // global_var_list ',' global_var
1261 HashSet set = peekVariableSet();
1264 if (token != TokenName.COMMA) {
1271 private void global_var(HashSet set) {
1275 // | '$' '{' expr '}'
1276 if (token == TokenName.VARIABLE) {
1277 if (fMethodVariables != null) {
1278 VariableInfo info = new VariableInfo(scanner
1279 .getCurrentTokenStartPosition(),
1280 VariableInfo.LEVEL_GLOBAL_VAR);
1281 fMethodVariables.put(new String(scanner
1282 .getCurrentIdentifierSource()), info);
1284 addVariableSet(set);
1286 } else if (token == TokenName.DOLLAR) {
1288 if (token == TokenName.LBRACE) {
1291 if (token != TokenName.RBRACE) {
1292 throwSyntaxError("'}' expected in global variable.");
1301 private void static_var_list() {
1303 // static_var_list ',' T_VARIABLE
1304 // | static_var_list ',' T_VARIABLE '=' static_scalar
1306 // | T_VARIABLE '=' static_scalar,
1307 HashSet set = peekVariableSet();
1309 if (token == TokenName.VARIABLE) {
1310 if (fMethodVariables != null) {
1311 VariableInfo info = new VariableInfo(scanner
1312 .getCurrentTokenStartPosition(),
1313 VariableInfo.LEVEL_STATIC_VAR);
1314 fMethodVariables.put(new String(scanner
1315 .getCurrentIdentifierSource()), info);
1317 addVariableSet(set);
1319 if (token == TokenName.EQUAL) {
1323 if (token != TokenName.COMMA) {
1333 private void unset_variables() {
1336 // | unset_variables ',' unset_variable
1340 variable(false, false);
1341 if (token != TokenName.COMMA) {
1348 private final void initializeModifiers() {
1350 this.modifiersSourceStart = -1;
1353 private final void checkAndSetModifiers(int flag) {
1354 this.modifiers |= flag;
1355 if (this.modifiersSourceStart < 0)
1356 this.modifiersSourceStart = this.scanner.startPosition;
1359 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1360 initializeModifiers();
1361 if (token == TokenName.INTERFACE) {
1362 // interface_entry T_STRING
1363 // interface_extends_list
1364 // '{' class_statement_list '}'
1365 checkAndSetModifiers(AccInterface);
1367 typeDecl.modifiers = this.modifiers;
1368 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1369 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1370 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1371 typeDecl.name = scanner.getCurrentIdentifierSource();
1372 if (token.compareTo (TokenName.KEYWORD) > 0) {
1373 problemReporter.phpKeywordWarning(new String[] { scanner
1374 .toStringAction(token) }, scanner
1375 .getCurrentTokenStartPosition(), scanner
1376 .getCurrentTokenEndPosition(), referenceContext,
1377 compilationUnit.compilationResult);
1378 // throwSyntaxError("Don't use a keyword for interface
1380 // + scanner.toStringAction(token) + "].",
1381 // typeDecl.sourceStart, typeDecl.sourceEnd);
1384 interface_extends_list(typeDecl);
1386 typeDecl.name = new char[] { ' ' };
1388 "Interface name expected after keyword 'interface'.",
1389 typeDecl.sourceStart, typeDecl.sourceEnd);
1393 // class_entry_type T_STRING extends_from
1395 // '{' class_statement_list'}'
1397 typeDecl.modifiers = this.modifiers;
1398 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1399 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1401 // identifier 'extends' identifier
1402 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
1403 typeDecl.name = scanner.getCurrentIdentifierSource();
1404 if (token.compareTo (TokenName.KEYWORD) > 0) {
1405 problemReporter.phpKeywordWarning(new String[] { scanner
1406 .toStringAction(token) }, scanner
1407 .getCurrentTokenStartPosition(), scanner
1408 .getCurrentTokenEndPosition(), referenceContext,
1409 compilationUnit.compilationResult);
1410 // throwSyntaxError("Don't use a keyword for class
1412 // scanner.toStringAction(token) + "].",
1413 // typeDecl.sourceStart, typeDecl.sourceEnd);
1418 // | T_EXTENDS fully_qualified_class_name
1419 if (token == TokenName.EXTENDS) {
1420 class_extends_list(typeDecl);
1422 // if (token != TokenName.IDENTIFIER) {
1423 // throwSyntaxError("Class name expected after keyword
1425 // scanner.getCurrentTokenStartPosition(), scanner
1426 // .getCurrentTokenEndPosition());
1429 implements_list(typeDecl);
1431 typeDecl.name = new char[] { ' ' };
1432 throwSyntaxError("Class name expected after keyword 'class'.",
1433 typeDecl.sourceStart, typeDecl.sourceEnd);
1437 // '{' class_statement_list '}'
1438 if (token == TokenName.LBRACE) {
1440 if (token != TokenName.RBRACE) {
1441 ArrayList list = new ArrayList();
1442 class_statement_list(list);
1443 typeDecl.fields = new FieldDeclaration[list.size()];
1444 for (int i = 0; i < list.size(); i++) {
1445 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1448 if (token == TokenName.RBRACE) {
1449 typeDecl.declarationSourceEnd = scanner
1450 .getCurrentTokenEndPosition();
1453 throwSyntaxError("'}' expected at end of class body.");
1456 throwSyntaxError("'{' expected at start of class body.");
1460 private void class_entry_type() {
1462 // | T_ABSTRACT T_CLASS
1463 // | T_FINAL T_CLASS
1464 if (token == TokenName.CLASS) {
1466 } else if (token == TokenName.ABSTRACT) {
1467 checkAndSetModifiers(AccAbstract);
1469 if (token != TokenName.CLASS) {
1470 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1473 } else if (token == TokenName.FINAL) {
1474 checkAndSetModifiers(AccFinal);
1476 if (token != TokenName.CLASS) {
1477 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1481 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1485 // private void class_extends(TypeDeclaration typeDecl) {
1487 // // | T_EXTENDS interface_list
1488 // if (token == TokenName.EXTENDS) {
1491 // if (token == TokenName.IDENTIFIER) {
1494 // throwSyntaxError("Class name expected after keyword 'extends'.");
1499 private void interface_extends_list(TypeDeclaration typeDecl) {
1501 // | T_EXTENDS interface_list
1502 if (token == TokenName.EXTENDS) {
1504 interface_list(typeDecl);
1508 private void class_extends_list(TypeDeclaration typeDecl) {
1510 // | T_EXTENDS interface_list
1511 if (token == TokenName.EXTENDS) {
1513 class_list(typeDecl);
1517 private void implements_list(TypeDeclaration typeDecl) {
1519 // | T_IMPLEMENTS interface_list
1520 if (token == TokenName.IMPLEMENTS) {
1522 interface_list(typeDecl);
1526 private void class_list(TypeDeclaration typeDecl) {
1528 // fully_qualified_class_name
1530 if (token == TokenName.IDENTIFIER) {
1531 //char[] ident = scanner.getCurrentIdentifierSource();
1532 // TODO make this code working better:
1533 // SingleTypeReference ref =
1534 // ParserUtil.getTypeReference(scanner,
1535 // includesList, ident);
1536 // if (ref != null) {
1537 // typeDecl.superclass = ref;
1541 throwSyntaxError("Classname expected after keyword 'extends'.");
1543 if (token == TokenName.COMMA) {
1544 reportSyntaxError("No multiple inheritance allowed. Expected token 'implements' or '{'.");
1553 private void interface_list(TypeDeclaration typeDecl) {
1555 // fully_qualified_class_name
1556 // | interface_list ',' fully_qualified_class_name
1558 if (token == TokenName.IDENTIFIER) {
1561 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1563 if (token != TokenName.COMMA) {
1570 // private void classBody(TypeDeclaration typeDecl) {
1571 // //'{' [class-element-list] '}'
1572 // if (token == TokenName.LBRACE) {
1574 // if (token != TokenName.RBRACE) {
1575 // class_statement_list();
1577 // if (token == TokenName.RBRACE) {
1578 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1581 // throwSyntaxError("'}' expected at end of class body.");
1584 // throwSyntaxError("'{' expected at start of class body.");
1587 private void class_statement_list(ArrayList list) {
1590 class_statement(list);
1591 if (token == TokenName.PUBLIC ||
1592 token == TokenName.PROTECTED ||
1593 token == TokenName.PRIVATE ||
1594 token == TokenName.STATIC ||
1595 token == TokenName.ABSTRACT ||
1596 token == TokenName.FINAL ||
1597 token == TokenName.FUNCTION ||
1598 token == TokenName.VAR ||
1599 token == TokenName.CONST) {
1603 if (token == TokenName.RBRACE) {
1607 throwSyntaxError("'}' at end of class statement.");
1609 catch (SyntaxError sytaxErr1) {
1610 boolean tokenize = scanner.tokenizeStrings;
1613 scanner.tokenizeStrings = true;
1616 // if an error occured,
1617 // try to find keywords
1618 // to parse the rest of the string
1619 while (token != TokenName.EOF) {
1620 if (token == TokenName.PUBLIC ||
1621 token == TokenName.PROTECTED ||
1622 token == TokenName.PRIVATE ||
1623 token == TokenName.STATIC ||
1624 token == TokenName.ABSTRACT ||
1625 token == TokenName.FINAL ||
1626 token == TokenName.FUNCTION ||
1627 token == TokenName.VAR ||
1628 token == TokenName.CONST) {
1631 // System.out.println(scanner.toStringAction(token));
1634 if (token == TokenName.EOF) {
1638 scanner.tokenizeStrings = tokenize;
1647 private void class_statement(ArrayList list) {
1649 // variable_modifiers class_variable_declaration ';'
1650 // | class_constant_declaration ';'
1651 // | method_modifiers T_FUNCTION is_reference T_STRING
1652 // '(' parameter_list ')' method_body
1653 initializeModifiers();
1654 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1656 if (token == TokenName.VAR) {
1657 checkAndSetModifiers(AccPublic);
1658 problemReporter.phpVarDeprecatedWarning(scanner
1659 .getCurrentTokenStartPosition(), scanner
1660 .getCurrentTokenEndPosition(), referenceContext,
1661 compilationUnit.compilationResult);
1663 class_variable_declaration(declarationSourceStart, list);
1664 } else if (token == TokenName.CONST) {
1665 checkAndSetModifiers(AccFinal | AccPublic);
1666 class_constant_declaration(declarationSourceStart, list);
1667 if (token != TokenName.SEMICOLON) {
1668 throwSyntaxError("';' expected after class const declaration.");
1672 boolean hasModifiers = member_modifiers();
1673 if (token == TokenName.FUNCTION) {
1674 if (!hasModifiers) {
1675 checkAndSetModifiers(AccPublic);
1677 MethodDeclaration methodDecl = new MethodDeclaration(
1678 this.compilationUnit.compilationResult);
1679 methodDecl.declarationSourceStart = scanner
1680 .getCurrentTokenStartPosition();
1681 methodDecl.modifiers = this.modifiers;
1682 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1685 functionDefinition(methodDecl);
1687 int sourceEnd = methodDecl.sourceEnd;
1689 || methodDecl.declarationSourceStart > sourceEnd) {
1690 sourceEnd = methodDecl.declarationSourceStart + 1;
1692 methodDecl.declarationSourceEnd = sourceEnd;
1693 methodDecl.sourceEnd = sourceEnd;
1696 if (!hasModifiers) {
1697 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1699 class_variable_declaration(declarationSourceStart, list);
1704 private void class_constant_declaration(int declarationSourceStart,
1706 // class_constant_declaration ',' T_STRING '=' static_scalar
1707 // | T_CONST T_STRING '=' static_scalar
1708 if (token != TokenName.CONST) {
1709 throwSyntaxError("'const' keyword expected in class declaration.");
1714 if (token != TokenName.IDENTIFIER) {
1715 throwSyntaxError("Identifier expected in class const declaration.");
1717 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner
1718 .getCurrentIdentifierSource(), scanner
1719 .getCurrentTokenStartPosition(), scanner
1720 .getCurrentTokenEndPosition());
1721 fieldDeclaration.modifiers = this.modifiers;
1722 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1723 fieldDeclaration.declarationSourceEnd = scanner
1724 .getCurrentTokenEndPosition();
1725 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1726 // fieldDeclaration.type
1727 list.add(fieldDeclaration);
1729 if (token != TokenName.EQUAL) {
1730 throwSyntaxError("'=' expected in class const declaration.");
1734 if (token != TokenName.COMMA) {
1735 break; // while(true)-loop
1741 // private void variable_modifiers() {
1742 // // variable_modifiers:
1743 // // non_empty_member_modifiers
1745 // initializeModifiers();
1746 // if (token == TokenName.var) {
1747 // checkAndSetModifiers(AccPublic);
1748 // reportSyntaxError(
1749 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1751 // modifier for field declarations.",
1752 // scanner.getCurrentTokenStartPosition(), scanner
1753 // .getCurrentTokenEndPosition());
1756 // if (!member_modifiers()) {
1757 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1758 // field declarations.");
1762 // private void method_modifiers() {
1763 // //method_modifiers:
1765 // //| non_empty_member_modifiers
1766 // initializeModifiers();
1767 // if (!member_modifiers()) {
1768 // checkAndSetModifiers(AccPublic);
1771 private boolean member_modifiers() {
1778 boolean foundToken = false;
1780 if (token == TokenName.PUBLIC) {
1781 checkAndSetModifiers(AccPublic);
1784 } else if (token == TokenName.PROTECTED) {
1785 checkAndSetModifiers(AccProtected);
1788 } else if (token == TokenName.PRIVATE) {
1789 checkAndSetModifiers(AccPrivate);
1792 } else if (token == TokenName.STATIC) {
1793 checkAndSetModifiers(AccStatic);
1796 } else if (token == TokenName.ABSTRACT) {
1797 checkAndSetModifiers(AccAbstract);
1800 } else if (token == TokenName.FINAL) {
1801 checkAndSetModifiers(AccFinal);
1811 private void class_variable_declaration(int declarationSourceStart,
1813 // class_variable_declaration:
1814 // class_variable_declaration ',' T_VARIABLE
1815 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1817 // | T_VARIABLE '=' static_scalar
1818 char[] classVariable;
1820 if (token == TokenName.VARIABLE) {
1821 classVariable = scanner.getCurrentIdentifierSource();
1822 // indexManager.addIdentifierInformation('v', classVariable,
1825 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1826 classVariable, scanner.getCurrentTokenStartPosition(),
1827 scanner.getCurrentTokenEndPosition());
1828 fieldDeclaration.modifiers = this.modifiers;
1829 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1830 fieldDeclaration.declarationSourceEnd = scanner
1831 .getCurrentTokenEndPosition();
1832 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1833 list.add(fieldDeclaration);
1834 if (fTypeVariables != null) {
1835 VariableInfo info = new VariableInfo(scanner
1836 .getCurrentTokenStartPosition(),
1837 VariableInfo.LEVEL_CLASS_UNIT);
1838 fTypeVariables.put(new String(scanner
1839 .getCurrentIdentifierSource()), info);
1842 if (token == TokenName.EQUAL) {
1847 // if (token == TokenName.THIS) {
1848 // throwSyntaxError("'$this' not allowed after keyword 'public'
1849 // 'protected' 'private' 'var'.");
1851 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1853 if (token != TokenName.COMMA) {
1858 if (token != TokenName.SEMICOLON) {
1859 throwSyntaxError("';' expected after field declaration.");
1864 private void functionDefinition(MethodDeclaration methodDecl) {
1865 boolean isAbstract = false;
1867 if (compilationUnit != null) {
1868 compilationUnit.types.add(methodDecl);
1871 ASTNode node = astStack[astPtr];
1872 if (node instanceof TypeDeclaration) {
1873 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1874 if (typeDecl.methods == null) {
1875 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1877 AbstractMethodDeclaration[] newMethods;
1882 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1883 0, typeDecl.methods.length);
1884 newMethods[typeDecl.methods.length] = methodDecl;
1885 typeDecl.methods = newMethods;
1887 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1889 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1895 pushFunctionVariableSet();
1896 functionDeclarator(methodDecl);
1897 if (token == TokenName.SEMICOLON) {
1899 methodDecl.sourceEnd = scanner
1900 .getCurrentTokenStartPosition() - 1;
1901 throwSyntaxError("Body declaration expected for method: "
1902 + new String(methodDecl.selector));
1907 functionBody(methodDecl);
1909 if (!fStackUnassigned.isEmpty()) {
1910 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1915 private void functionDeclarator(MethodDeclaration methodDecl) {
1916 // identifier '(' [parameter-list] ')'
1917 if (token == TokenName.OP_AND) {
1921 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1922 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1924 if (Scanner.isIdentifierOrKeyword (token) ||
1925 token == TokenName.LPAREN) {
1927 if (token == TokenName.LPAREN) {
1928 methodDecl.selector = scanner.getCurrentIdentifierSource();
1930 if (token.compareTo (TokenName.KEYWORD) > 0) {
1931 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1932 scanner.getCurrentTokenStartPosition(),
1933 scanner.getCurrentTokenEndPosition(),
1935 compilationUnit.compilationResult);
1939 methodDecl.selector = scanner.getCurrentIdentifierSource();
1941 if (token.compareTo (TokenName.KEYWORD) > 0) {
1942 problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
1943 scanner.getCurrentTokenStartPosition(),
1944 scanner.getCurrentTokenEndPosition(),
1946 compilationUnit.compilationResult);
1952 if (token == TokenName.LPAREN) {
1956 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1957 throwSyntaxError("'(' expected in function declaration.");
1960 if (token != TokenName.RPAREN) {
1961 parameter_list(methodDecl);
1964 if (token != TokenName.RPAREN) {
1965 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1966 throwSyntaxError("')' expected in function declaration.");
1969 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1974 methodDecl.selector = "<undefined>".toCharArray();
1975 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1976 throwSyntaxError("Function name expected after keyword 'function'.");
1981 private void parameter_list(MethodDeclaration methodDecl) {
1982 // non_empty_parameter_list
1984 non_empty_parameter_list(methodDecl, true);
1987 private void non_empty_parameter_list(MethodDeclaration methodDecl,
1988 boolean empty_allowed) {
1989 // optional_class_type T_VARIABLE
1990 // | optional_class_type '&' T_VARIABLE
1991 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1992 // | optional_class_type T_VARIABLE '=' static_scalar
1993 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1994 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1995 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1997 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1999 char[] typeIdentifier = null;
2000 if (token == TokenName.IDENTIFIER ||
2001 token == TokenName.ARRAY ||
2002 token == TokenName.VARIABLE ||
2003 token == TokenName.OP_AND) {
2004 HashSet set = peekVariableSet();
2007 if (token == TokenName.IDENTIFIER || token == TokenName.ARRAY) {// feature req. #1254275
2008 typeIdentifier = scanner.getCurrentIdentifierSource();
2011 if (token == TokenName.OP_AND) {
2014 if (token == TokenName.VARIABLE) {
2015 if (fMethodVariables != null) {
2017 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
2018 info = new VariableInfo(scanner
2019 .getCurrentTokenStartPosition(),
2020 VariableInfo.LEVEL_FUNCTION_DEFINITION);
2022 info = new VariableInfo(scanner
2023 .getCurrentTokenStartPosition(),
2024 VariableInfo.LEVEL_METHOD_DEFINITION);
2026 info.typeIdentifier = typeIdentifier;
2027 fMethodVariables.put(new String(scanner
2028 .getCurrentIdentifierSource()), info);
2030 addVariableSet(set);
2032 if (token == TokenName.EQUAL) {
2037 throwSyntaxError("Variable expected in parameter list.");
2039 if (token != TokenName.COMMA) {
2046 if (!empty_allowed) {
2047 throwSyntaxError("Identifier expected in parameter list.");
2051 // private void optional_class_type() {
2056 // private void parameterDeclaration() {
2058 // //variable-reference
2059 // if (token == TokenName.AND) {
2061 // if (isVariable()) {
2064 // throwSyntaxError("Variable expected after reference operator '&'.");
2067 // //variable '=' constant
2068 // if (token == TokenName.VARIABLE) {
2070 // if (token == TokenName.EQUAL) {
2076 // // if (token == TokenName.THIS) {
2077 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
2078 // // declaration.");
2082 private void labeledStatementList() {
2083 if (token != TokenName.CASE && token != TokenName.DEFAULT) {
2084 throwSyntaxError("'case' or 'default' expected.");
2087 if (token == TokenName.CASE) {
2089 expr_without_variable (true, null, true); // constant();
2090 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2092 if (token == TokenName.RBRACE) {
2093 // empty case; assumes that the '}' token belongs to the wrapping
2094 // switch statement - #1371992
2097 if (token == TokenName.CASE || token == TokenName.DEFAULT) {
2098 // empty case statement ?
2103 // else if (token == TokenName.SEMICOLON) {
2105 // "':' expected after 'case' keyword (Found token: " +
2106 // scanner.toStringAction(token) + ")",
2107 // scanner.getCurrentTokenStartPosition(),
2108 // scanner.getCurrentTokenEndPosition(),
2111 // if (token == TokenName.CASE) { // empty case statement ?
2117 throwSyntaxError("':' character expected after 'case' constant (Found token: "
2118 + scanner.toStringAction(token) + ")");
2120 } else { // TokenName.DEFAULT
2122 if (token == TokenName.COLON || token == TokenName.SEMICOLON) {
2124 if (token == TokenName.RBRACE) {
2125 // empty default case; ; assumes that the '}' token belongs to the
2126 // wrapping switch statement - #1371992
2129 if (token != TokenName.CASE) {
2133 throwSyntaxError("':' character expected after 'default'.");
2136 } while (token == TokenName.CASE || token == TokenName.DEFAULT);
2139 private void ifStatementColon(IfStatement iState) {
2140 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
2141 // new_else_single T_ENDIF ';'
2142 HashSet assignedVariableSet = null;
2144 Block b = inner_statement_list();
2145 iState.thenStatement = b;
2146 checkUnreachable(iState, b);
2148 assignedVariableSet = removeIfVariableSet();
2150 if (token == TokenName.ELSEIF) {
2152 pushIfVariableSet();
2153 new_elseif_list(iState);
2155 HashSet set = removeIfVariableSet();
2156 if (assignedVariableSet != null && set != null) {
2157 assignedVariableSet.addAll(set);
2162 pushIfVariableSet();
2163 new_else_single(iState);
2165 HashSet set = removeIfVariableSet();
2166 if (assignedVariableSet != null) {
2167 HashSet topSet = peekVariableSet();
2168 if (topSet != null) {
2172 topSet.addAll(assignedVariableSet);
2176 if (token != TokenName.ENDIF) {
2177 throwSyntaxError("'endif' expected.");
2180 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2181 reportSyntaxError("';' expected after if-statement.");
2182 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2184 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
2189 private void ifStatement(IfStatement iState) {
2190 // T_IF '(' expr ')' statement elseif_list else_single
2191 HashSet assignedVariableSet = null;
2193 pushIfVariableSet();
2194 Statement s = statement();
2195 iState.thenStatement = s;
2196 checkUnreachable(iState, s);
2198 assignedVariableSet = removeIfVariableSet();
2201 if (token == TokenName.ELSEIF) {
2203 pushIfVariableSet();
2204 elseif_list(iState);
2206 HashSet set = removeIfVariableSet();
2207 if (assignedVariableSet != null && set != null) {
2208 assignedVariableSet.addAll(set);
2213 pushIfVariableSet();
2214 else_single(iState);
2216 HashSet set = removeIfVariableSet();
2217 if (assignedVariableSet != null) {
2218 HashSet topSet = peekVariableSet();
2219 if (topSet != null) {
2223 topSet.addAll(assignedVariableSet);
2229 private void elseif_list(IfStatement iState) {
2231 // | elseif_list T_ELSEIF '(' expr ')' statement
2232 ArrayList conditionList = new ArrayList();
2233 ArrayList statementList = new ArrayList();
2236 while (token == TokenName.ELSEIF) {
2238 if (token == TokenName.LPAREN) {
2241 throwSyntaxError("'(' expected after 'elseif' keyword.");
2244 conditionList.add(e);
2245 if (token == TokenName.RPAREN) {
2248 throwSyntaxError("')' expected after 'elseif' condition.");
2251 statementList.add(s);
2252 checkUnreachable(iState, s);
2254 iState.elseifConditions = new Expression[conditionList.size()];
2255 iState.elseifStatements = new Statement[statementList.size()];
2256 conditionList.toArray(iState.elseifConditions);
2257 statementList.toArray(iState.elseifStatements);
2260 private void new_elseif_list(IfStatement iState) {
2262 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
2263 ArrayList conditionList = new ArrayList();
2264 ArrayList statementList = new ArrayList();
2267 while (token == TokenName.ELSEIF) {
2269 if (token == TokenName.LPAREN) {
2272 throwSyntaxError("'(' expected after 'elseif' keyword.");
2275 conditionList.add(e);
2276 if (token == TokenName.RPAREN) {
2279 throwSyntaxError("')' expected after 'elseif' condition.");
2281 if (token == TokenName.COLON) {
2284 throwSyntaxError("':' expected after 'elseif' keyword.");
2286 b = inner_statement_list();
2287 statementList.add(b);
2288 checkUnreachable(iState, b);
2290 iState.elseifConditions = new Expression[conditionList.size()];
2291 iState.elseifStatements = new Statement[statementList.size()];
2292 conditionList.toArray(iState.elseifConditions);
2293 statementList.toArray(iState.elseifStatements);
2296 private void else_single(IfStatement iState) {
2299 if (token == TokenName.ELSE) {
2301 Statement s = statement();
2302 iState.elseStatement = s;
2303 checkUnreachable(iState, s);
2305 iState.checkUnreachable = false;
2307 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2310 private void new_else_single(IfStatement iState) {
2312 // | T_ELSE ':' inner_statement_list
2313 if (token == TokenName.ELSE) {
2315 if (token == TokenName.COLON) {
2318 throwSyntaxError("':' expected after 'else' keyword.");
2320 Block b = inner_statement_list();
2321 iState.elseStatement = b;
2322 checkUnreachable(iState, b);
2324 iState.checkUnreachable = false;
2328 private Block inner_statement_list() {
2329 // inner_statement_list inner_statement
2331 return statementList();
2338 private void checkUnreachable(IfStatement iState, Statement s) {
2339 if (s instanceof Block) {
2340 Block b = (Block) s;
2341 if (b.statements == null || b.statements.length == 0) {
2342 iState.checkUnreachable = false;
2344 int off = b.statements.length - 1;
2345 if (!(b.statements[off] instanceof ReturnStatement)
2346 && !(b.statements[off] instanceof ContinueStatement)
2347 && !(b.statements[off] instanceof BreakStatement)) {
2348 if (!(b.statements[off] instanceof IfStatement)
2349 || !((IfStatement) b.statements[off]).checkUnreachable) {
2350 iState.checkUnreachable = false;
2355 if (!(s instanceof ReturnStatement)
2356 && !(s instanceof ContinueStatement)
2357 && !(s instanceof BreakStatement)) {
2358 if (!(s instanceof IfStatement)
2359 || !((IfStatement) s).checkUnreachable) {
2360 iState.checkUnreachable = false;
2366 // private void elseifStatementList() {
2368 // elseifStatement();
2370 // case TokenName.else:
2372 // if (token == TokenName.COLON) {
2374 // if (token != TokenName.endif) {
2379 // if (token == TokenName.if) { //'else if'
2382 // throwSyntaxError("':' expected after 'else'.");
2386 // case TokenName.elseif:
2395 // private void elseifStatement() {
2396 // if (token == TokenName.LPAREN) {
2399 // if (token != TokenName.RPAREN) {
2400 // throwSyntaxError("')' expected in else-if-statement.");
2403 // if (token != TokenName.COLON) {
2404 // throwSyntaxError("':' expected in else-if-statement.");
2407 // if (token != TokenName.endif) {
2413 private void switchStatement() {
2414 if (token == TokenName.COLON) {
2415 // ':' [labeled-statement-list] 'endswitch' ';'
2417 labeledStatementList();
2418 if (token != TokenName.ENDSWITCH) {
2419 throwSyntaxError("'endswitch' expected.");
2422 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2423 throwSyntaxError("';' expected after switch-statement.");
2427 // '{' [labeled-statement-list] '}'
2428 if (token != TokenName.LBRACE) {
2429 throwSyntaxError("'{' expected in switch statement.");
2432 if (token != TokenName.RBRACE) {
2433 labeledStatementList();
2435 if (token != TokenName.RBRACE) {
2436 throwSyntaxError("'}' expected in switch statement.");
2442 private void forStatement() {
2443 if (token == TokenName.COLON) {
2446 if (token != TokenName.ENDFOR) {
2447 throwSyntaxError("'endfor' expected.");
2450 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2451 throwSyntaxError("';' expected after for-statement.");
2459 private void whileStatement() {
2460 // ':' statement-list 'endwhile' ';'
2461 if (token == TokenName.COLON) {
2464 if (token != TokenName.ENDWHILE) {
2465 throwSyntaxError("'endwhile' expected.");
2468 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2469 throwSyntaxError("';' expected after while-statement.");
2477 private void foreachStatement() {
2478 if (token == TokenName.COLON) {
2481 if (token != TokenName.ENDFOREACH) {
2482 throwSyntaxError("'endforeach' expected.");
2485 if (token != TokenName.SEMICOLON && token != TokenName.INLINE_HTML) {
2486 throwSyntaxError("';' expected after foreach-statement.");
2494 // private void exitStatus() {
2495 // if (token == TokenName.LPAREN) {
2498 // throwSyntaxError("'(' expected in 'exit-status'.");
2500 // if (token != TokenName.RPAREN) {
2503 // if (token == TokenName.RPAREN) {
2506 // throwSyntaxError("')' expected after 'exit-status'.");
2512 private void namespacePath () {
2514 expr_without_variable (true, null, false);
2516 if (token == TokenName.BACKSLASH) {
2527 private void expressionList() {
2529 expr_without_variable (true, null, false);
2531 if (token == TokenName.COMMA) { // If it's a list of (comma separated) expressions
2532 getNextToken(); // read all in, untill no more found
2539 private Expression expr() {
2540 return expr_without_variable(true, null, false);
2545 * @param only_variable
2546 * @param initHandler
2548 private Expression expr_without_variable (boolean only_variable,
2549 UninitializedVariableHandler initHandler,
2550 boolean bColonAllowed) {
2551 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2552 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2553 Expression expression = new Expression();
2555 expression.sourceStart = exprSourceStart;
2556 expression.sourceEnd = exprSourceEnd; // default, may be overwritten
2559 // internal_functions_in_yacc
2568 // | T_INC rw_variable
2569 // | T_DEC rw_variable
2570 // | T_INT_CAST expr
2571 // | T_DOUBLE_CAST expr
2572 // | T_STRING_CAST expr
2573 // | T_ARRAY_CAST expr
2574 // | T_OBJECT_CAST expr
2575 // | T_BOOL_CAST expr
2576 // | T_UNSET_CAST expr
2577 // | T_EXIT exit_expr
2579 // | T_ARRAY '(' array_pair_list ')'
2580 // | '`' encaps_list '`'
2581 // | T_LIST '(' assignment_list ')' '=' expr
2582 // | T_NEW class_name_reference ctor_arguments
2583 // | variable '=' expr
2584 // | variable '=' '&' variable
2585 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2586 // | variable T_PLUS_EQUAL expr
2587 // | variable T_MINUS_EQUAL expr
2588 // | variable T_MUL_EQUAL expr
2589 // | variable T_DIV_EQUAL expr
2590 // | variable T_CONCAT_EQUAL expr
2591 // | variable T_MOD_EQUAL expr
2592 // | variable T_AND_EQUAL expr
2593 // | variable T_OR_EQUAL expr
2594 // | variable T_XOR_EQUAL expr
2595 // | variable T_SL_EQUAL expr
2596 // | variable T_SR_EQUAL expr
2597 // | rw_variable T_INC
2598 // | rw_variable T_DEC
2599 // | expr T_BOOLEAN_OR expr
2600 // | expr T_BOOLEAN_AND expr
2601 // | expr T_LOGICAL_OR expr
2602 // | expr T_LOGICAL_AND expr
2603 // | expr T_LOGICAL_XOR expr
2615 // | expr T_IS_IDENTICAL expr
2616 // | expr T_IS_NOT_IDENTICAL expr
2617 // | expr T_IS_EQUAL expr
2618 // | expr T_IS_NOT_EQUAL expr
2620 // | expr T_IS_SMALLER_OR_EQUAL expr
2622 // | expr T_IS_GREATER_OR_EQUAL expr
2623 // | expr T_INSTANCEOF class_name_reference
2624 // | expr '?' expr ':' expr
2625 if (Scanner.TRACE) {
2626 System.out.println("TRACE: expr_without_variable() PART 1");
2631 // T_ISSET '(' isset_variables ')'
2633 if (token != TokenName.LPAREN) {
2634 throwSyntaxError("'(' expected after keyword 'isset'");
2638 if (token != TokenName.RPAREN) {
2639 throwSyntaxError("')' expected after keyword 'isset'");
2645 if (token != TokenName.LPAREN) {
2646 throwSyntaxError("'(' expected after keyword 'empty'");
2649 variable(true, false);
2650 if (token != TokenName.RPAREN) {
2651 throwSyntaxError("')' expected after keyword 'empty'");
2660 internal_functions_in_yacc();
2667 if (token == TokenName.RPAREN) {
2670 throwSyntaxError("')' expected in expression.");
2680 // | T_INT_CAST expr
2681 // | T_DOUBLE_CAST expr
2682 // | T_STRING_CAST expr
2683 // | T_ARRAY_CAST expr
2684 // | T_OBJECT_CAST expr
2685 // | T_BOOL_CAST expr
2686 // | T_UNSET_CAST expr
2702 expr_without_variable (only_variable, initHandler, bColonAllowed);
2710 // | T_STRING_VARNAME
2712 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2713 // | '`' encaps_list '`'
2715 // | '`' encaps_list '`'
2716 // case TokenName.EncapsedString0:
2717 // scanner.encapsedStringStack.push(new Character('`'));
2720 // if (token == TokenName.EncapsedString0) {
2723 // if (token != TokenName.EncapsedString0) {
2724 // throwSyntaxError("\'`\' expected at end of string" + "(Found
2726 // scanner.toStringAction(token) + " )");
2730 // scanner.encapsedStringStack.pop();
2734 // // | '\'' encaps_list '\''
2735 // case TokenName.EncapsedString1:
2736 // scanner.encapsedStringStack.push(new Character('\''));
2739 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2740 // if (token == TokenName.EncapsedString1) {
2742 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2743 // exprSourceStart, scanner
2744 // .getCurrentTokenEndPosition());
2747 // if (token != TokenName.EncapsedString1) {
2748 // throwSyntaxError("\'\'\' expected at end of string" + "(Found
2750 // + scanner.toStringAction(token) + " )");
2753 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2754 // exprSourceStart, scanner
2755 // .getCurrentTokenEndPosition());
2759 // scanner.encapsedStringStack.pop();
2763 // //| '"' encaps_list '"'
2764 // case TokenName.EncapsedString2:
2765 // scanner.encapsedStringStack.push(new Character('"'));
2768 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2769 // if (token == TokenName.EncapsedString2) {
2771 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2772 // exprSourceStart, scanner
2773 // .getCurrentTokenEndPosition());
2776 // if (token != TokenName.EncapsedString2) {
2777 // throwSyntaxError("'\"' expected at end of string" + "(Found
2779 // scanner.toStringAction(token) + " )");
2782 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2783 // exprSourceStart, scanner
2784 // .getCurrentTokenEndPosition());
2788 // scanner.encapsedStringStack.pop();
2792 case STRINGDOUBLEQUOTE:
2793 expression = new StringLiteralDQ (scanner.getCurrentStringLiteralSource(),
2794 scanner.getCurrentTokenStartPosition(),
2795 scanner.getCurrentTokenEndPosition());
2798 case STRINGSINGLEQUOTE:
2799 expression = new StringLiteralSQ (scanner.getCurrentStringLiteralSource(),
2800 scanner.getCurrentTokenStartPosition(),
2801 scanner.getCurrentTokenEndPosition());
2804 case INTEGERLITERAL:
2806 case STRINGINTERPOLATED:
2818 // T_ARRAY '(' array_pair_list ')'
2820 if (token == TokenName.LPAREN) {
2822 if (token == TokenName.RPAREN) {
2827 if (token != TokenName.RPAREN) {
2828 throwSyntaxError("')' or ',' expected after keyword 'array'"
2830 + scanner.toStringAction(token) + ")");
2834 throwSyntaxError("'(' expected after keyword 'array'"
2835 + "(Found token: " + scanner.toStringAction(token)
2840 // | T_LIST '(' assignment_list ')' '=' expr
2842 if (token == TokenName.LPAREN) {
2845 if (token != TokenName.RPAREN) {
2846 throwSyntaxError("')' expected after 'list' keyword.");
2849 if (token != TokenName.EQUAL) {
2850 throwSyntaxError("'=' expected after 'list' keyword.");
2855 throwSyntaxError("'(' expected after 'list' keyword.");
2859 // | T_NEW class_name_reference ctor_arguments
2861 Expression typeRef = class_name_reference();
2863 if (typeRef != null) {
2864 expression = typeRef;
2867 // | T_INC rw_variable
2868 // | T_DEC rw_variable
2874 // | variable '=' expr
2875 // | variable '=' '&' variable
2876 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2877 // | variable T_PLUS_EQUAL expr
2878 // | variable T_MINUS_EQUAL expr
2879 // | variable T_MUL_EQUAL expr
2880 // | variable T_DIV_EQUAL expr
2881 // | variable T_CONCAT_EQUAL expr
2882 // | variable T_MOD_EQUAL expr
2883 // | variable T_AND_EQUAL expr
2884 // | variable T_OR_EQUAL expr
2885 // | variable T_XOR_EQUAL expr
2886 // | variable T_SL_EQUAL expr
2887 // | variable T_SR_EQUAL expr
2888 // | rw_variable T_INC
2889 // | rw_variable T_DEC
2893 Expression lhs = null;
2894 boolean rememberedVar = false;
2896 if (token == TokenName.IDENTIFIER) {
2897 lhs = identifier(true, true, bColonAllowed);
2902 lhs = variable(true, true);
2909 lhs instanceof FieldReference &&
2910 token != TokenName.EQUAL &&
2911 token != TokenName.PLUS_EQUAL &&
2912 token != TokenName.MINUS_EQUAL &&
2913 token != TokenName.MULTIPLY_EQUAL &&
2914 token != TokenName.DIVIDE_EQUAL &&
2915 token != TokenName.DOT_EQUAL &&
2916 token != TokenName.REMAINDER_EQUAL &&
2917 token != TokenName.AND_EQUAL &&
2918 token != TokenName.OR_EQUAL &&
2919 token != TokenName.XOR_EQUAL &&
2920 token != TokenName.RIGHT_SHIFT_EQUAL &&
2921 token != TokenName.LEFT_SHIFT_EQUAL) {
2923 FieldReference ref = (FieldReference) lhs;
2925 if (!containsVariableSet(ref.token)) {
2926 if (null == initHandler || initHandler.reportError()) {
2927 problemReporter.uninitializedLocalVariable(
2928 new String(ref.token), ref.sourceStart,
2929 ref.sourceEnd, referenceContext,
2930 compilationUnit.compilationResult);
2932 addVariableSet(ref.token);
2939 if (lhs != null && lhs instanceof FieldReference) {
2940 addVariableSet(((FieldReference) lhs).token);
2943 if (token == TokenName.OP_AND) {
2945 if (token == TokenName.NEW) {
2946 // | variable '=' '&' T_NEW class_name_reference
2949 SingleTypeReference classRef = class_name_reference();
2951 if (classRef != null) {
2953 && lhs instanceof FieldReference) {
2955 // $var = & new Object();
2956 if (fMethodVariables != null) {
2957 VariableInfo lhsInfo = new VariableInfo(
2958 ((FieldReference) lhs).sourceStart);
2959 lhsInfo.reference = classRef;
2960 lhsInfo.typeIdentifier = classRef.token;
2961 fMethodVariables.put(new String(
2962 ((FieldReference) lhs).token),
2964 rememberedVar = true;
2969 Expression rhs = variable(false, false);
2970 if (rhs != null && rhs instanceof FieldReference
2972 && lhs instanceof FieldReference) {
2975 if (fMethodVariables != null) {
2976 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
2977 .get(((FieldReference) rhs).token);
2979 && rhsInfo.reference != null) {
2980 VariableInfo lhsInfo = new VariableInfo(
2981 ((FieldReference) lhs).sourceStart);
2982 lhsInfo.reference = rhsInfo.reference;
2983 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2984 fMethodVariables.put(new String(
2985 ((FieldReference) lhs).token),
2987 rememberedVar = true;
2993 Expression rhs = expr_without_variable (only_variable, initHandler, bColonAllowed);
2995 if (lhs != null && lhs instanceof FieldReference) {
2996 if (rhs != null && rhs instanceof FieldReference) {
2999 if (fMethodVariables != null) {
3000 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
3001 .get(((FieldReference) rhs).token);
3003 && rhsInfo.reference != null) {
3004 VariableInfo lhsInfo = new VariableInfo(
3005 ((FieldReference) lhs).sourceStart);
3006 lhsInfo.reference = rhsInfo.reference;
3007 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
3008 fMethodVariables.put(new String(
3009 ((FieldReference) lhs).token),
3011 rememberedVar = true;
3014 } else if (rhs != null
3015 && rhs instanceof SingleTypeReference) {
3017 // $var = new Object();
3018 if (fMethodVariables != null) {
3019 VariableInfo lhsInfo = new VariableInfo(
3020 ((FieldReference) lhs).sourceStart);
3021 lhsInfo.reference = (SingleTypeReference) rhs;
3022 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
3023 fMethodVariables.put(new String(
3024 ((FieldReference) lhs).token),
3026 rememberedVar = true;
3031 if (rememberedVar == false && lhs != null
3032 && lhs instanceof FieldReference) {
3033 if (fMethodVariables != null) {
3034 VariableInfo lhsInfo = new VariableInfo(
3035 ((FieldReference) lhs).sourceStart);
3036 fMethodVariables.put(new String(
3037 ((FieldReference) lhs).token), lhsInfo);
3043 case MULTIPLY_EQUAL:
3046 case REMAINDER_EQUAL:
3050 case RIGHT_SHIFT_EQUAL:
3051 case LEFT_SHIFT_EQUAL:
3052 if (lhs != null && lhs instanceof FieldReference) {
3053 addVariableSet(((FieldReference) lhs).token);
3056 expr_without_variable (only_variable, initHandler, bColonAllowed);
3063 if (!only_variable) {
3064 throwSyntaxError("Variable expression not allowed (found token '"
3065 + scanner.toStringAction(token) + "').");
3070 } // case DOLLAR, VARIABLE, IDENTIFIER: switch token
3074 MethodDeclaration methodDecl = new MethodDeclaration (this.compilationUnit.compilationResult);
3075 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
3076 methodDecl.modifiers = AccDefault;
3077 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
3080 functionDefinition(methodDecl);
3082 int sourceEnd = methodDecl.sourceEnd;
3083 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
3084 sourceEnd = methodDecl.declarationSourceStart + 1;
3086 methodDecl.declarationSourceEnd = sourceEnd;
3087 methodDecl.sourceEnd = sourceEnd;
3092 if (token != TokenName.INLINE_HTML) {
3093 if (token.compareTo (TokenName.KEYWORD) > 0) {
3097 // System.out.println(scanner.getCurrentTokenStartPosition());
3098 // System.out.println(scanner.getCurrentTokenEndPosition());
3100 throwSyntaxError("Error in expression (found token '"
3101 + scanner.toStringAction(token) + "').");
3107 if (Scanner.TRACE) {
3108 System.out.println("TRACE: expr_without_variable() PART 2");
3111 // | expr T_BOOLEAN_OR expr
3112 // | expr T_BOOLEAN_AND expr
3113 // | expr T_LOGICAL_OR expr
3114 // | expr T_LOGICAL_AND expr
3115 // | expr T_LOGICAL_XOR expr
3127 // | expr T_IS_IDENTICAL expr
3128 // | expr T_IS_NOT_IDENTICAL expr
3129 // | expr T_IS_EQUAL expr
3130 // | expr T_IS_NOT_EQUAL expr
3132 // | expr T_IS_SMALLER_OR_EQUAL expr
3134 // | expr T_IS_GREATER_OR_EQUAL expr
3139 expression = new OR_OR_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR_OR);
3143 expression = new AND_AND_Expression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND_AND);
3147 expression = new EqualExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3151 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3155 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3159 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3163 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.AND);
3167 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.OR);
3171 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.XOR);
3175 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.TWIDDLE);
3179 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.PLUS);
3183 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MINUS);
3187 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.MULTIPLY);
3191 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.DIVIDE);
3195 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.REMAINDER);
3199 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LEFT_SHIFT);
3203 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.RIGHT_SHIFT);
3205 case EQUAL_EQUAL_EQUAL:
3207 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.EQUAL_EQUAL);
3209 case NOT_EQUAL_EQUAL:
3211 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3215 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.NOT_EQUAL);
3219 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS);
3223 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.LESS_EQUAL);
3227 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER);
3231 expression = new BinaryExpression(expression, expr_without_variable (only_variable, initHandler, bColonAllowed), OperatorIds.GREATER_EQUAL);
3233 // | expr T_INSTANCEOF class_name_reference
3234 // | expr '?' expr ':' expr
3237 TypeReference classRef = class_name_reference();
3239 if (classRef != null) {
3240 expression = new InstanceOfExpression (expression, classRef, OperatorIds.INSTANCEOF);
3241 expression.sourceStart = exprSourceStart;
3242 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
3247 Expression valueIfTrue = expr_without_variable (true, null, true);
3248 if (token != TokenName.COLON) {
3249 throwSyntaxError("':' expected in conditional expression.");
3252 Expression valueIfFalse = expr();
3254 expression = new ConditionalExpression(expression,
3255 valueIfTrue, valueIfFalse);
3261 } catch (SyntaxError e) {
3262 // try to find next token after expression with errors:
3263 if (token == TokenName.SEMICOLON) {
3268 if (token == TokenName.RBRACE ||
3269 token == TokenName.RPAREN ||
3270 token == TokenName.RBRACKET) {
3281 private SingleTypeReference class_name_reference() {
3282 // class_name_reference:
3284 // | dynamic_class_name_reference
3285 SingleTypeReference ref = null;
3286 if (Scanner.TRACE) {
3287 System.out.println("TRACE: class_name_reference()");
3289 if (token == TokenName.IDENTIFIER) {
3290 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3291 scanner.getCurrentTokenStartPosition());
3292 int pos = scanner.currentPosition;
3294 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
3295 // Not terminated by T_STRING, reduce to dynamic_class_name_reference
3296 scanner.currentPosition = pos;
3297 token = TokenName.IDENTIFIER;
3299 dynamic_class_name_reference();
3303 dynamic_class_name_reference();
3308 private void dynamic_class_name_reference() {
3309 // dynamic_class_name_reference:
3310 // base_variable T_OBJECT_OPERATOR object_property
3311 // dynamic_class_name_variable_properties
3313 if (Scanner.TRACE) {
3314 System.out.println("TRACE: dynamic_class_name_reference()");
3316 base_variable(true);
3317 if (token == TokenName.MINUS_GREATER) {
3320 dynamic_class_name_variable_properties();
3324 private void dynamic_class_name_variable_properties() {
3325 // dynamic_class_name_variable_properties:
3326 // dynamic_class_name_variable_properties
3327 // dynamic_class_name_variable_property
3329 if (Scanner.TRACE) {
3331 .println("TRACE: dynamic_class_name_variable_properties()");
3333 while (token == TokenName.MINUS_GREATER) {
3334 dynamic_class_name_variable_property();
3338 private void dynamic_class_name_variable_property() {
3339 // dynamic_class_name_variable_property:
3340 // T_OBJECT_OPERATOR object_property
3341 if (Scanner.TRACE) {
3342 System.out.println("TRACE: dynamic_class_name_variable_property()");
3344 if (token == TokenName.MINUS_GREATER) {
3350 private void ctor_arguments() {
3353 // | '(' function_call_parameter_list ')'
3354 if (token == TokenName.LPAREN) {
3356 if (token == TokenName.RPAREN) {
3360 non_empty_function_call_parameter_list();
3361 if (token != TokenName.RPAREN) {
3362 throwSyntaxError("')' expected in ctor_arguments.");
3368 private void assignment_list() {
3370 // assignment_list ',' assignment_list_element
3371 // | assignment_list_element
3373 assignment_list_element();
3374 if (token != TokenName.COMMA) {
3381 private void assignment_list_element() {
3382 // assignment_list_element:
3384 // | T_LIST '(' assignment_list ')'
3386 if (token == TokenName.VARIABLE) {
3387 variable(true, false);
3388 } else if (token == TokenName.DOLLAR) {
3389 variable(false, false);
3390 } else if (token == TokenName.IDENTIFIER) {
3391 identifier(true, true, false);
3393 if (token == TokenName.LIST) {
3395 if (token == TokenName.LPAREN) {
3398 if (token != TokenName.RPAREN) {
3399 throwSyntaxError("')' expected after 'list' keyword.");
3403 throwSyntaxError("'(' expected after 'list' keyword.");
3409 private void array_pair_list() {
3412 // | non_empty_array_pair_list possible_comma
3413 non_empty_array_pair_list();
3414 if (token == TokenName.COMMA) {
3419 private void non_empty_array_pair_list() {
3420 // non_empty_array_pair_list:
3421 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3422 // | non_empty_array_pair_list ',' expr
3423 // | expr T_DOUBLE_ARROW expr
3425 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3426 // | non_empty_array_pair_list ',' '&' w_variable
3427 // | expr T_DOUBLE_ARROW '&' w_variable
3430 if (token == TokenName.OP_AND) {
3432 variable(true, false);
3435 if (token == TokenName.OP_AND) {
3437 variable(true, false);
3438 } else if (token == TokenName.EQUAL_GREATER) {
3440 if (token == TokenName.OP_AND) {
3442 variable(true, false);
3448 if (token != TokenName.COMMA) {
3452 if (token == TokenName.RPAREN) {
3458 // private void variableList() {
3461 // if (token == TokenName.COMMA) {
3468 private Expression variable_without_objects(boolean lefthandside,
3469 boolean ignoreVar) {
3470 // variable_without_objects:
3471 // reference_variable
3472 // | simple_indirect_reference reference_variable
3473 if (Scanner.TRACE) {
3474 System.out.println("TRACE: variable_without_objects()");
3476 while (token == TokenName.DOLLAR) {
3479 return reference_variable(lefthandside, ignoreVar);
3482 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3484 // T_STRING '(' function_call_parameter_list ')'
3485 // | class_constant '(' function_call_parameter_list ')'
3486 // | static_member '(' function_call_parameter_list ')'
3487 // | variable_without_objects '(' function_call_parameter_list ')'
3488 char[] defineName = null;
3489 char[] ident = null;
3492 Expression ref = null;
3493 if (Scanner.TRACE) {
3494 System.out.println("TRACE: function_call()");
3496 if (token == TokenName.IDENTIFIER) {
3497 ident = scanner.getCurrentIdentifierSource();
3499 startPos = scanner.getCurrentTokenStartPosition();
3500 endPos = scanner.getCurrentTokenEndPosition();
3503 case PAAMAYIM_NEKUDOTAYIM:
3507 if (token == TokenName.IDENTIFIER) {
3512 variable_without_objects(true, false);
3517 ref = variable_without_objects(lefthandside, ignoreVar);
3519 if (token != TokenName.LPAREN) {
3520 if (defineName != null) {
3521 // does this identifier contain only uppercase characters?
3522 if (defineName.length == 3) {
3523 if (defineName[0] == 'd' &&
3524 defineName[1] == 'i' &&
3525 defineName[2] == 'e') {
3528 } else if (defineName.length == 4) {
3529 if (defineName[0] == 't' &&
3530 defineName[1] == 'r' &&
3531 defineName[2] == 'u' &&
3532 defineName[3] == 'e') {
3534 } else if (defineName[0] == 'n' &&
3535 defineName[1] == 'u' &&
3536 defineName[2] == 'l' &&
3537 defineName[3] == 'l') {
3540 } else if (defineName.length == 5) {
3541 if (defineName[0] == 'f' &&
3542 defineName[1] == 'a' &&
3543 defineName[2] == 'l' &&
3544 defineName[3] == 's' &&
3545 defineName[4] == 'e') {
3549 if (defineName != null) {
3550 for (int i = 0; i < defineName.length; i++) {
3551 if (Character.isLowerCase(defineName[i])) {
3552 problemReporter.phpUppercaseIdentifierWarning(
3553 startPos, endPos, referenceContext,
3554 compilationUnit.compilationResult);
3562 if (token == TokenName.RPAREN) {
3567 non_empty_function_call_parameter_list();
3569 if (token != TokenName.RPAREN) {
3570 String functionName;
3572 if (ident == null) {
3573 functionName = new String(" ");
3575 functionName = new String(ident);
3578 throwSyntaxError("')' expected in function call (" + functionName + ").");
3585 private void non_empty_function_call_parameter_list() {
3586 this.non_empty_function_call_parameter_list(null);
3589 // private void function_call_parameter_list() {
3590 // function_call_parameter_list:
3591 // non_empty_function_call_parameter_list { $$ = $1; }
3594 private void non_empty_function_call_parameter_list(String functionName) {
3595 // non_empty_function_call_parameter_list:
3596 // expr_without_variable
3599 // | non_empty_function_call_parameter_list ',' expr_without_variable
3600 // | non_empty_function_call_parameter_list ',' variable
3601 // | non_empty_function_call_parameter_list ',' '&' w_variable
3602 if (Scanner.TRACE) {
3604 .println("TRACE: non_empty_function_call_parameter_list()");
3606 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3607 initHandler.setFunctionName(functionName);
3609 initHandler.incrementArgumentCount();
3610 if (token == TokenName.OP_AND) {
3614 // if (token == TokenName.Identifier || token ==
3615 // TokenName.Variable
3616 // || token == TokenName.DOLLAR) {
3619 expr_without_variable(true, initHandler, false);
3622 if (token != TokenName.COMMA) {
3629 private void fully_qualified_class_name() {
3630 if (token == TokenName.IDENTIFIER) {
3633 throwSyntaxError("Class name expected.");
3637 private void static_member() {
3639 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3640 // variable_without_objects
3641 if (Scanner.TRACE) {
3642 System.out.println("TRACE: static_member()");
3644 fully_qualified_class_name();
3645 if (token != TokenName.PAAMAYIM_NEKUDOTAYIM) {
3646 throwSyntaxError("'::' expected after class name (static_member).");
3649 variable_without_objects(false, false);
3652 private Expression base_variable_with_function_calls(boolean lefthandside,
3653 boolean ignoreVar) {
3654 // base_variable_with_function_calls:
3657 if (Scanner.TRACE) {
3658 System.out.println("TRACE: base_variable_with_function_calls()");
3660 return function_call(lefthandside, ignoreVar);
3663 private Expression base_variable(boolean lefthandside) {
3665 // reference_variable
3666 // | simple_indirect_reference reference_variable
3668 Expression ref = null;
3669 if (Scanner.TRACE) {
3670 System.out.println("TRACE: base_variable()");
3672 if (token == TokenName.IDENTIFIER) {
3675 while (token == TokenName.DOLLAR) {
3678 reference_variable(lefthandside, false);
3683 // private void simple_indirect_reference() {
3684 // // simple_indirect_reference:
3686 // //| simple_indirect_reference '$'
3688 private Expression reference_variable(boolean lefthandside,
3689 boolean ignoreVar) {
3690 // reference_variable:
3691 // reference_variable '[' dim_offset ']'
3692 // | reference_variable '{' expr '}'
3693 // | compound_variable
3694 Expression ref = null;
3695 if (Scanner.TRACE) {
3696 System.out.println("TRACE: reference_variable()");
3698 ref = compound_variable(lefthandside, ignoreVar);
3700 if (token == TokenName.LBRACE) {
3704 if (token != TokenName.RBRACE) {
3705 throwSyntaxError("'}' expected in reference variable.");
3708 } else if (token == TokenName.LBRACKET) {
3709 // To remove "ref = null;" here, is probably better than the
3711 // commented in #1368081 - axelcl
3713 if (token != TokenName.RBRACKET) {
3716 if (token != TokenName.RBRACKET) {
3717 throwSyntaxError("']' expected in reference variable.");
3728 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3729 // compound_variable:
3731 // | '$' '{' expr '}'
3732 if (Scanner.TRACE) {
3733 System.out.println("TRACE: compound_variable()");
3735 if (token == TokenName.VARIABLE) {
3736 if (!lefthandside) {
3737 if (!containsVariableSet()) {
3738 // reportSyntaxError("The local variable " + new
3739 // String(scanner.getCurrentIdentifierSource())
3740 // + " may not have been initialized");
3741 problemReporter.uninitializedLocalVariable(new String(
3742 scanner.getCurrentIdentifierSource()), scanner
3743 .getCurrentTokenStartPosition(), scanner
3744 .getCurrentTokenEndPosition(), referenceContext,
3745 compilationUnit.compilationResult);
3752 FieldReference ref = new FieldReference(scanner
3753 .getCurrentIdentifierSource(), scanner
3754 .getCurrentTokenStartPosition());
3758 // because of simple_indirect_reference
3759 while (token == TokenName.DOLLAR) {
3762 if (token != TokenName.LBRACE) {
3763 reportSyntaxError("'{' expected after compound variable token '$'.");
3768 if (token != TokenName.RBRACE) {
3769 throwSyntaxError("'}' expected after compound variable token '$'.");
3774 } // private void dim_offset() { // // dim_offset: // // /* empty */
3779 private void object_property() {
3782 // | variable_without_objects
3783 if (Scanner.TRACE) {
3784 System.out.println("TRACE: object_property()");
3786 if (token == TokenName.VARIABLE || token == TokenName.DOLLAR) {
3787 variable_without_objects(false, false);
3793 private void object_dim_list() {
3795 // object_dim_list '[' dim_offset ']'
3796 // | object_dim_list '{' expr '}'
3798 if (Scanner.TRACE) {
3799 System.out.println("TRACE: object_dim_list()");
3803 if (token == TokenName.LBRACE) {
3806 if (token != TokenName.RBRACE) {
3807 throwSyntaxError("'}' expected in object_dim_list.");
3810 } else if (token == TokenName.LBRACKET) {
3812 if (token == TokenName.RBRACKET) {
3817 if (token != TokenName.RBRACKET) {
3818 throwSyntaxError("']' expected in object_dim_list.");
3827 private void variable_name() {
3831 if (Scanner.TRACE) {
3832 System.out.println("TRACE: variable_name()");
3834 if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
3835 if (token.compareTo (TokenName.KEYWORD) > 0) {
3836 // TODO show a warning "Keyword used as variable" ?
3840 if (token != TokenName.LBRACE) {
3841 throwSyntaxError("'{' expected in variable name.");
3845 if (token != TokenName.RBRACE) {
3846 throwSyntaxError("'}' expected in variable name.");
3852 private void r_variable() {
3853 variable(false, false);
3856 private void w_variable(boolean lefthandside) {
3857 variable(lefthandside, false);
3860 private void rw_variable() {
3861 variable(false, false);
3864 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3866 // base_variable_with_function_calls T_OBJECT_OPERATOR
3867 // object_property method_or_not variable_properties
3868 // | base_variable_with_function_calls
3869 Expression ref = base_variable_with_function_calls(lefthandside,
3871 if (token == TokenName.MINUS_GREATER) {
3876 variable_properties();
3881 private void variable_properties() {
3882 // variable_properties:
3883 // variable_properties variable_property
3885 while (token == TokenName.MINUS_GREATER) {
3886 variable_property();
3890 private void variable_property() {
3891 // variable_property:
3892 // T_OBJECT_OPERATOR object_property method_or_not
3893 if (Scanner.TRACE) {
3894 System.out.println("TRACE: variable_property()");
3896 if (token == TokenName.MINUS_GREATER) {
3901 throwSyntaxError("'->' expected in variable_property.");
3908 * base_variable_with_function_calls T_OBJECT_OPERATOR
3909 * object_property method_or_not variable_properties
3910 * | base_variable_with_function_calls
3912 * Expression ref = function_call(lefthandside, ignoreVar);
3915 * T_STRING '(' function_call_parameter_list ')'
3916 * | class_constant '(' function_call_parameter_list ')'
3917 * | static_member '(' function_call_parameter_list ')'
3918 * | variable_without_objects '(' function_call_parameter_list ')'
3920 * @param lefthandside
3925 private Expression identifier (boolean lefthandside, boolean ignoreVar, boolean bColonAllowed) {
3926 char[] defineName = null;
3927 char[] ident = null;
3930 Expression ref = null;
3932 if (Scanner.TRACE) {
3933 System.out.println("TRACE: function_call()");
3936 if (token == TokenName.IDENTIFIER) {
3937 ident = scanner.getCurrentIdentifierSource();
3939 startPos = scanner.getCurrentTokenStartPosition();
3940 endPos = scanner.getCurrentTokenEndPosition();
3942 getNextToken(); // Get the token after the identifier
3948 case MULTIPLY_EQUAL:
3951 case REMAINDER_EQUAL:
3955 case RIGHT_SHIFT_EQUAL:
3956 case LEFT_SHIFT_EQUAL:
3957 String error = "Assignment operator '"
3958 + scanner.toStringAction(token)
3959 + "' not allowed after identifier '"
3961 + "' (use 'define(...)' to define constants).";
3962 reportSyntaxError(error);
3966 if (token == TokenName.COLON) { // If it's a ':', the identifier is a label
3971 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) { // '::'
3974 getNextToken (); // Read the identifier
3976 if (token == TokenName.IDENTIFIER) { // class _constant
3979 else { // static member:
3980 variable_without_objects (true, false);
3984 else if (token == TokenName.BACKSLASH) { // '\' namespace path separator
3987 if (token == TokenName.IDENTIFIER) { // If it's an identifier
3988 getNextToken (); // go for the next token
3990 else { // It's not an identifiere, something wrong
3991 throwSyntaxError ("an identifier expected after '\\' ");
3999 else { // Token is not an identifier
4000 ref = variable_without_objects(lefthandside, ignoreVar);
4003 if (token == TokenName.LPAREN) { // If token is '('
4006 if (token == TokenName.RPAREN) { // If token is ')'
4011 String functionName;
4013 if (ident == null) {
4014 functionName = new String(" ");
4016 functionName = new String(ident);
4019 non_empty_function_call_parameter_list(functionName); // Get the parameter list for the given function name
4021 if (token != TokenName.RPAREN) { // If token is not a ')', throw error
4022 throwSyntaxError ("')' expected in function call (" + functionName + ").");
4025 getNextToken(); // Get the token after ')'
4028 else { // It's not an '('
4029 if (defineName != null) { // does this identifier contain only uppercase characters?
4030 if (defineName.length == 3) { // If it's a 'die'
4031 if (defineName[0] == 'd' &&
4032 defineName[1] == 'i' &&
4033 defineName[2] == 'e') {
4037 else if (defineName.length == 4) { // If it's a 'true'
4038 if (defineName[0] == 't' &&
4039 defineName[1] == 'r' &&
4040 defineName[2] == 'u' &&
4041 defineName[3] == 'e') {
4044 else if (defineName[0] == 'n' && // If it's a 'null'
4045 defineName[1] == 'u' &&
4046 defineName[2] == 'l' &&
4047 defineName[3] == 'l') {
4051 else if (defineName.length == 5) { // If it's a 'false'
4052 if (defineName[0] == 'f' &&
4053 defineName[1] == 'a' &&
4054 defineName[2] == 'l' &&
4055 defineName[3] == 's' &&
4056 defineName[4] == 'e') {
4061 if (defineName != null) {
4062 for (int i = 0; i < defineName.length; i++) {
4063 if (Character.isLowerCase (defineName[i])) {
4064 problemReporter.phpUppercaseIdentifierWarning (startPos, endPos, referenceContext,
4065 compilationUnit.compilationResult);
4071 // TODO is this ok ?
4073 // throwSyntaxError("'(' expected in function call.");
4076 if (token == TokenName.MINUS_GREATER) {
4081 variable_properties();
4084 // A colon is only allowed here if it is an expression read after a '?'
4086 if ((token == TokenName.COLON) &&
4088 throwSyntaxError ("No ':' allowed");
4094 private void method_or_not() {
4096 // '(' function_call_parameter_list ')'
4098 if (Scanner.TRACE) {
4099 System.out.println("TRACE: method_or_not()");
4101 if (token == TokenName.LPAREN) {
4103 if (token == TokenName.RPAREN) {
4107 non_empty_function_call_parameter_list();
4108 if (token != TokenName.RPAREN) {
4109 throwSyntaxError("')' expected in method_or_not.");
4115 private void exit_expr() {
4119 if (token != TokenName.LPAREN) {
4123 if (token == TokenName.RPAREN) {
4128 if (token != TokenName.RPAREN) {
4129 throwSyntaxError("')' expected after keyword 'exit'");
4134 // private void encaps_list() {
4135 // // encaps_list encaps_var
4136 // // | encaps_list T_STRING
4137 // // | encaps_list T_NUM_STRING
4138 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
4139 // // | encaps_list T_CHARACTER
4140 // // | encaps_list T_BAD_CHARACTER
4141 // // | encaps_list '['
4142 // // | encaps_list ']'
4143 // // | encaps_list '{'
4144 // // | encaps_list '}'
4145 // // | encaps_list T_OBJECT_OPERATOR
4149 // case TokenName.STRING:
4152 // case TokenName.LBRACE:
4153 // // scanner.encapsedStringStack.pop();
4156 // case TokenName.RBRACE:
4157 // // scanner.encapsedStringStack.pop();
4160 // case TokenName.LBRACKET:
4161 // // scanner.encapsedStringStack.pop();
4164 // case TokenName.RBRACKET:
4165 // // scanner.encapsedStringStack.pop();
4168 // case TokenName.MINUS_GREATER:
4169 // // scanner.encapsedStringStack.pop();
4172 // case TokenName.Variable:
4173 // case TokenName.DOLLAR_LBRACE:
4174 // case TokenName.LBRACE_DOLLAR:
4178 // char encapsedChar = ((Character)
4179 // scanner.encapsedStringStack.peek()).charValue();
4180 // if (encapsedChar == '$') {
4181 // scanner.encapsedStringStack.pop();
4182 // encapsedChar = ((Character)
4183 // scanner.encapsedStringStack.peek()).charValue();
4184 // switch (encapsedChar) {
4186 // if (token == TokenName.EncapsedString0) {
4189 // token = TokenName.STRING;
4192 // if (token == TokenName.EncapsedString1) {
4195 // token = TokenName.STRING;
4198 // if (token == TokenName.EncapsedString2) {
4201 // token = TokenName.STRING;
4210 // private void encaps_var() {
4212 // // | T_VARIABLE '[' encaps_var_offset ']'
4213 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
4214 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
4215 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
4216 // // | T_CURLY_OPEN variable '}'
4218 // case TokenName.Variable:
4220 // if (token == TokenName.LBRACKET) {
4222 // expr(); //encaps_var_offset();
4223 // if (token != TokenName.RBRACKET) {
4224 // throwSyntaxError("']' expected after variable.");
4226 // // scanner.encapsedStringStack.pop();
4229 // } else if (token == TokenName.MINUS_GREATER) {
4231 // if (token != TokenName.Identifier) {
4232 // throwSyntaxError("Identifier expected after '->'.");
4234 // // scanner.encapsedStringStack.pop();
4238 // // // scanner.encapsedStringStack.pop();
4239 // // int tempToken = TokenName.STRING;
4240 // // if (!scanner.encapsedStringStack.isEmpty()
4241 // // && (token == TokenName.EncapsedString0
4242 // // || token == TokenName.EncapsedString1
4243 // // || token == TokenName.EncapsedString2 || token ==
4244 // // TokenName.ERROR)) {
4245 // // char encapsedChar = ((Character)
4246 // // scanner.encapsedStringStack.peek())
4248 // // switch (token) {
4249 // // case TokenName.EncapsedString0 :
4250 // // if (encapsedChar == '`') {
4251 // // tempToken = TokenName.EncapsedString0;
4254 // // case TokenName.EncapsedString1 :
4255 // // if (encapsedChar == '\'') {
4256 // // tempToken = TokenName.EncapsedString1;
4259 // // case TokenName.EncapsedString2 :
4260 // // if (encapsedChar == '"') {
4261 // // tempToken = TokenName.EncapsedString2;
4264 // // case TokenName.ERROR :
4265 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
4266 // // scanner.currentPosition--;
4267 // // getNextToken();
4272 // // token = tempToken;
4275 // case TokenName.DOLLAR_LBRACE:
4277 // if (token == TokenName.DOLLAR_LBRACE) {
4279 // } else if (token == TokenName.Identifier) {
4281 // if (token == TokenName.LBRACKET) {
4283 // // if (token == TokenName.RBRACKET) {
4284 // // getNextToken();
4287 // if (token != TokenName.RBRACKET) {
4288 // throwSyntaxError("']' expected after '${'.");
4296 // if (token != TokenName.RBRACE) {
4297 // throwSyntaxError("'}' expected.");
4301 // case TokenName.LBRACE_DOLLAR:
4303 // if (token == TokenName.LBRACE_DOLLAR) {
4305 // } else if (token == TokenName.Identifier || token > TokenName.KEYWORD) {
4307 // if (token == TokenName.LBRACKET) {
4309 // // if (token == TokenName.RBRACKET) {
4310 // // getNextToken();
4313 // if (token != TokenName.RBRACKET) {
4314 // throwSyntaxError("']' expected.");
4318 // } else if (token == TokenName.MINUS_GREATER) {
4320 // if (token != TokenName.Identifier && token != TokenName.Variable) {
4321 // throwSyntaxError("String or Variable token expected.");
4324 // if (token == TokenName.LBRACKET) {
4326 // // if (token == TokenName.RBRACKET) {
4327 // // getNextToken();
4330 // if (token != TokenName.RBRACKET) {
4331 // throwSyntaxError("']' expected after '${'.");
4337 // // if (token != TokenName.RBRACE) {
4338 // // throwSyntaxError("'}' expected after '{$'.");
4340 // // // scanner.encapsedStringStack.pop();
4341 // // getNextToken();
4344 // if (token != TokenName.RBRACE) {
4345 // throwSyntaxError("'}' expected.");
4347 // // scanner.encapsedStringStack.pop();
4354 // private void encaps_var_offset() {
4356 // // | T_NUM_STRING
4359 // case TokenName.STRING:
4362 // case TokenName.IntegerLiteral:
4365 // case TokenName.Variable:
4368 // case TokenName.Identifier:
4372 // throwSyntaxError("Variable or String token expected.");
4380 private void internal_functions_in_yacc() {
4383 // case TokenName.isset:
4384 // // T_ISSET '(' isset_variables ')'
4386 // if (token != TokenName.LPAREN) {
4387 // throwSyntaxError("'(' expected after keyword 'isset'");
4390 // isset_variables();
4391 // if (token != TokenName.RPAREN) {
4392 // throwSyntaxError("')' expected after keyword 'isset'");
4396 // case TokenName.empty:
4397 // // T_EMPTY '(' variable ')'
4399 // if (token != TokenName.LPAREN) {
4400 // throwSyntaxError("'(' expected after keyword 'empty'");
4404 // if (token != TokenName.RPAREN) {
4405 // throwSyntaxError("')' expected after keyword 'empty'");
4411 checkFileName(token);
4414 // T_INCLUDE_ONCE expr
4415 checkFileName(token);
4418 // T_EVAL '(' expr ')'
4420 if (token != TokenName.LPAREN) {
4421 throwSyntaxError("'(' expected after keyword 'eval'");
4425 if (token != TokenName.RPAREN) {
4426 throwSyntaxError("')' expected after keyword 'eval'");
4432 checkFileName(token);
4435 // T_REQUIRE_ONCE expr
4436 checkFileName(token);
4442 * Parse and check the include file name
4444 * @param includeToken
4446 private void checkFileName(TokenName includeToken) {
4447 // <include-token> expr
4448 int start = scanner.getCurrentTokenStartPosition();
4449 boolean hasLPAREN = false;
4451 if (token == TokenName.LPAREN) {
4455 Expression expression = expr();
4457 if (token == TokenName.RPAREN) {
4460 throwSyntaxError("')' expected for keyword '"
4461 + scanner.toStringAction(includeToken) + "'");
4464 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4466 if (scanner.compilationUnit != null) {
4467 IResource resource = scanner.compilationUnit.getResource();
4468 if (resource != null && resource instanceof IFile) {
4469 file = (IFile) resource;
4473 tokens = new char[1][];
4474 tokens[0] = currTokenSource;
4476 ImportReference impt = new ImportReference(tokens, currTokenSource,
4477 start, scanner.getCurrentTokenEndPosition(), false);
4478 impt.declarationSourceEnd = impt.sourceEnd;
4479 impt.declarationEnd = impt.declarationSourceEnd;
4480 // endPosition is just before the ;
4481 impt.declarationSourceStart = start;
4482 includesList.add(impt);
4484 if (expression instanceof StringLiteral) {
4485 StringLiteral literal = (StringLiteral) expression;
4486 char[] includeName = literal.source();
4487 if (includeName.length == 0) {
4488 reportSyntaxError("Empty filename after keyword '"
4489 + scanner.toStringAction(includeToken) + "'",
4490 literal.sourceStart, literal.sourceStart + 1);
4492 String includeNameString = new String(includeName);
4493 if (literal instanceof StringLiteralDQ) {
4494 if (includeNameString.indexOf('$') >= 0) {
4495 // assuming that the filename contains a variable => no
4500 if (includeNameString.startsWith("http://")) {
4501 // assuming external include location
4505 // check the filename:
4506 // System.out.println(new
4507 // String(compilationUnit.getFileName())+" - "+
4508 // expression.toStringExpression());
4509 IProject project = file.getProject();
4510 if (project != null) {
4511 IPath path = PHPFileUtil.determineFilePath(
4512 includeNameString, file, project);
4515 // SyntaxError: "File: << >> doesn't exist in project."
4516 String[] args = { expression.toStringExpression(),
4517 project.getFullPath().toString() };
4518 problemReporter.phpIncludeNotExistWarning(args,
4519 literal.sourceStart, literal.sourceEnd,
4521 compilationUnit.compilationResult);
4524 String filePath = path.toString();
4525 String ext = file.getRawLocation()
4526 .getFileExtension();
4527 int fileExtensionLength = ext == null ? 0 : ext
4530 IFile f = PHPFileUtil.createFile(path, project);
4532 impt.tokens = CharOperation.splitOn('/', filePath
4533 .toCharArray(), 0, filePath.length()
4534 - fileExtensionLength);
4536 } catch (Exception e) {
4537 // the file is outside of the workspace
4545 private void isset_variables() {
4547 // | isset_variables ','
4548 if (token == TokenName.RPAREN) {
4549 throwSyntaxError("Variable expected after keyword 'isset'");
4552 variable(true, false);
4553 if (token == TokenName.COMMA) {
4561 private boolean common_scalar() {
4565 // | T_CONSTANT_ENCAPSED_STRING
4572 case INTEGERLITERAL:
4578 case STRINGDOUBLEQUOTE:
4581 case STRINGSINGLEQUOTE:
4584 case STRINGINTERPOLATED:
4606 // private void scalar() {
4609 // // | T_STRING_VARNAME
4610 // // | class_constant
4611 // // | common_scalar
4612 // // | '"' encaps_list '"'
4613 // // | '\'' encaps_list '\''
4614 // // | T_START_HEREDOC encaps_list T_END_HEREDOC
4615 // throwSyntaxError("Not yet implemented (scalar).");
4618 private void static_scalar() {
4619 // static_scalar: /* compile-time evaluated scalars */
4622 // | '+' static_scalar
4623 // | '-' static_scalar
4624 // | T_ARRAY '(' static_array_pair_list ')'
4625 // | static_class_constant
4626 if (common_scalar()) {
4632 // static_class_constant:
4633 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4634 if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
4636 if (token == TokenName.IDENTIFIER) {
4639 throwSyntaxError("Identifier expected after '::' operator.");
4643 case ENCAPSEDSTRING0:
4645 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4646 while (scanner.currentCharacter != '`') {
4647 if (scanner.currentCharacter == '\\') {
4648 scanner.currentPosition++;
4650 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4653 } catch (IndexOutOfBoundsException e) {
4654 throwSyntaxError("'`' expected at end of static string.");
4657 // case TokenName.EncapsedString1:
4659 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4660 // while (scanner.currentCharacter != '\'') {
4661 // if (scanner.currentCharacter == '\\') {
4662 // scanner.currentPosition++;
4664 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4667 // } catch (IndexOutOfBoundsException e) {
4668 // throwSyntaxError("'\'' expected at end of static string.");
4671 // case TokenName.EncapsedString2:
4673 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4674 // while (scanner.currentCharacter != '"') {
4675 // if (scanner.currentCharacter == '\\') {
4676 // scanner.currentPosition++;
4678 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4681 // } catch (IndexOutOfBoundsException e) {
4682 // throwSyntaxError("'\"' expected at end of static string.");
4685 case STRINGSINGLEQUOTE:
4688 case STRINGDOUBLEQUOTE:
4701 if (token != TokenName.LPAREN) {
4702 throwSyntaxError("'(' expected after keyword 'array'");
4705 if (token == TokenName.RPAREN) {
4709 non_empty_static_array_pair_list();
4710 if (token != TokenName.RPAREN) {
4711 throwSyntaxError("')' or ',' expected after keyword 'array'");
4715 // case TokenName.null :
4718 // case TokenName.false :
4721 // case TokenName.true :
4725 throwSyntaxError("Static scalar/constant expected.");
4729 private void non_empty_static_array_pair_list() {
4730 // non_empty_static_array_pair_list:
4731 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4733 // | non_empty_static_array_pair_list ',' static_scalar
4734 // | static_scalar T_DOUBLE_ARROW static_scalar
4738 if (token == TokenName.EQUAL_GREATER) {
4742 if (token != TokenName.COMMA) {
4746 if (token == TokenName.RPAREN) {
4752 // public void reportSyntaxError() { //int act, int currentKind, int
4753 // // stateStackTop) {
4754 // /* remember current scanner position */
4755 // int startPos = scanner.startPosition;
4756 // int currentPos = scanner.currentPosition;
4758 // this.checkAndReportBracketAnomalies(problemReporter());
4759 // /* reset scanner where it was */
4760 // scanner.startPosition = startPos;
4761 // scanner.currentPosition = currentPos;
4764 public static final int RoundBracket = 0;
4766 public static final int SquareBracket = 1;
4768 public static final int CurlyBracket = 2;
4770 public static final int BracketKinds = 3;
4772 protected int[] nestedMethod; // the ptr is nestedType
4774 protected int nestedType, dimensions;
4776 // variable set stack
4777 final static int VariableStackIncrement = 10;
4779 HashMap fTypeVariables = null;
4781 HashMap fMethodVariables = null;
4783 ArrayList fStackUnassigned = new ArrayList();
4786 final static int AstStackIncrement = 100;
4788 protected int astPtr;
4790 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4792 protected int astLengthPtr;
4794 protected int[] astLengthStack;
4796 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4798 public CompilationUnitDeclaration compilationUnit; /*
4803 protected ReferenceContext referenceContext;
4805 protected ProblemReporter problemReporter;
4807 protected CompilerOptions options;
4809 private ArrayList includesList;
4811 // protected CompilationResult compilationResult;
4813 * Returns this parser's problem reporter initialized with its reference
4814 * context. Also it is assumed that a problem is going to be reported, so
4815 * initializes the compilation result's line positions.
4817 public ProblemReporter problemReporter() {
4818 if (scanner.recordLineSeparator) {
4819 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4822 problemReporter.referenceContext = referenceContext;
4823 return problemReporter;
4827 * Reconsider the entire source looking for inconsistencies in {} () []
4829 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4830 // problemReporter) {
4831 // scanner.wasAcr = false;
4832 // boolean anomaliesDetected = false;
4834 // char[] source = scanner.source;
4835 // int[] leftCount = { 0, 0, 0 };
4836 // int[] rightCount = { 0, 0, 0 };
4837 // int[] depths = { 0, 0, 0 };
4838 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4841 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4843 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4845 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4847 // scanner.currentPosition = scanner.initialPosition; //starting
4849 // // (first-zero-based
4851 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4856 // // ---------Consume white space and handles
4857 // // startPosition---------
4858 // boolean isWhiteSpace;
4860 // scanner.startPosition = scanner.currentPosition;
4861 // // if (((scanner.currentCharacter =
4862 // // source[scanner.currentPosition++]) == '\\') &&
4863 // // (source[scanner.currentPosition] == 'u')) {
4864 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4866 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4867 // (scanner.currentCharacter == '\n'))) {
4868 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4869 // // only record line positions we have not
4871 // scanner.pushLineSeparator();
4874 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4876 // } while (isWhiteSpace && (scanner.currentPosition <
4877 // scanner.eofPosition));
4878 // // -------consume token until } is found---------
4879 // switch (scanner.currentCharacter) {
4881 // int index = leftCount[CurlyBracket]++;
4882 // if (index == leftPositions[CurlyBracket].length) {
4883 // System.arraycopy(leftPositions[CurlyBracket], 0,
4884 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4885 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4886 // new int[index * 2]), 0, index);
4888 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4889 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4893 // int index = rightCount[CurlyBracket]++;
4894 // if (index == rightPositions[CurlyBracket].length) {
4895 // System.arraycopy(rightPositions[CurlyBracket], 0,
4896 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4897 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
4899 // new int[index * 2]), 0, index);
4901 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4902 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4906 // int index = leftCount[RoundBracket]++;
4907 // if (index == leftPositions[RoundBracket].length) {
4908 // System.arraycopy(leftPositions[RoundBracket], 0,
4909 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4910 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4911 // new int[index * 2]), 0, index);
4913 // leftPositions[RoundBracket][index] = scanner.startPosition;
4914 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4918 // int index = rightCount[RoundBracket]++;
4919 // if (index == rightPositions[RoundBracket].length) {
4920 // System.arraycopy(rightPositions[RoundBracket], 0,
4921 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4922 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
4924 // new int[index * 2]), 0, index);
4926 // rightPositions[RoundBracket][index] = scanner.startPosition;
4927 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4931 // int index = leftCount[SquareBracket]++;
4932 // if (index == leftPositions[SquareBracket].length) {
4933 // System.arraycopy(leftPositions[SquareBracket], 0,
4934 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4935 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
4937 // new int[index * 2]), 0, index);
4939 // leftPositions[SquareBracket][index] = scanner.startPosition;
4940 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4944 // int index = rightCount[SquareBracket]++;
4945 // if (index == rightPositions[SquareBracket].length) {
4946 // System.arraycopy(rightPositions[SquareBracket], 0,
4947 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4948 // System.arraycopy(rightDepths[SquareBracket], 0,
4949 // (rightDepths[SquareBracket]
4950 // = new int[index * 2]), 0, index);
4952 // rightPositions[SquareBracket][index] = scanner.startPosition;
4953 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4957 // if (scanner.getNextChar('\\')) {
4958 // scanner.scanEscapeCharacter();
4959 // } else { // consume next character
4960 // scanner.unicodeAsBackSlash = false;
4961 // // if (((scanner.currentCharacter =
4962 // // source[scanner.currentPosition++]) ==
4964 // // (source[scanner.currentPosition] ==
4966 // // scanner.getNextUnicodeChar();
4968 // if (scanner.withoutUnicodePtr != 0) {
4969 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4970 // scanner.currentCharacter;
4974 // scanner.getNextChar('\'');
4978 // // consume next character
4979 // scanner.unicodeAsBackSlash = false;
4980 // // if (((scanner.currentCharacter =
4981 // // source[scanner.currentPosition++]) == '\\') &&
4982 // // (source[scanner.currentPosition] == 'u')) {
4983 // // scanner.getNextUnicodeChar();
4985 // if (scanner.withoutUnicodePtr != 0) {
4986 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4987 // scanner.currentCharacter;
4990 // while (scanner.currentCharacter != '"') {
4991 // if (scanner.currentCharacter == '\r') {
4992 // if (source[scanner.currentPosition] == '\n')
4993 // scanner.currentPosition++;
4994 // break; // the string cannot go further that
4997 // if (scanner.currentCharacter == '\n') {
4998 // break; // the string cannot go further that
5001 // if (scanner.currentCharacter == '\\') {
5002 // scanner.scanEscapeCharacter();
5004 // // consume next character
5005 // scanner.unicodeAsBackSlash = false;
5006 // // if (((scanner.currentCharacter =
5007 // // source[scanner.currentPosition++]) == '\\')
5008 // // && (source[scanner.currentPosition] == 'u'))
5010 // // scanner.getNextUnicodeChar();
5012 // if (scanner.withoutUnicodePtr != 0) {
5013 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5014 // scanner.currentCharacter;
5021 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
5023 // //get the next char
5024 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5026 // && (source[scanner.currentPosition] == 'u')) {
5027 // //-------------unicode traitement
5029 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5030 // scanner.currentPosition++;
5031 // while (source[scanner.currentPosition] == 'u') {
5032 // scanner.currentPosition++;
5034 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5036 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5039 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5042 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5044 // || c4 < 0) { //error
5048 // scanner.currentCharacter = 'A';
5049 // } //something different from \n and \r
5051 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5054 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
5056 // //get the next char
5057 // scanner.startPosition = scanner.currentPosition;
5058 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5060 // && (source[scanner.currentPosition] == 'u')) {
5061 // //-------------unicode traitement
5063 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5064 // scanner.currentPosition++;
5065 // while (source[scanner.currentPosition] == 'u') {
5066 // scanner.currentPosition++;
5068 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5070 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5073 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5076 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5078 // || c4 < 0) { //error
5082 // scanner.currentCharacter = 'A';
5083 // } //something different from \n
5086 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5090 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
5091 // (scanner.currentCharacter == '\n'))) {
5092 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
5093 // // only record line positions we
5094 // // have not recorded yet
5095 // scanner.pushLineSeparator();
5096 // if (this.scanner.taskTags != null) {
5097 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5099 // .getCurrentTokenEndPosition());
5105 // if (test > 0) { //traditional and annotation
5107 // boolean star = false;
5108 // // consume next character
5109 // scanner.unicodeAsBackSlash = false;
5110 // // if (((scanner.currentCharacter =
5111 // // source[scanner.currentPosition++]) ==
5113 // // (source[scanner.currentPosition] ==
5115 // // scanner.getNextUnicodeChar();
5117 // if (scanner.withoutUnicodePtr != 0) {
5118 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
5119 // scanner.currentCharacter;
5122 // if (scanner.currentCharacter == '*') {
5125 // //get the next char
5126 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5128 // && (source[scanner.currentPosition] == 'u')) {
5129 // //-------------unicode traitement
5131 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5132 // scanner.currentPosition++;
5133 // while (source[scanner.currentPosition] == 'u') {
5134 // scanner.currentPosition++;
5136 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5138 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5141 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5144 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5146 // || c4 < 0) { //error
5150 // scanner.currentCharacter = 'A';
5151 // } //something different from * and /
5153 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5156 // //loop until end of comment */
5157 // while ((scanner.currentCharacter != '/') || (!star)) {
5158 // star = scanner.currentCharacter == '*';
5160 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
5162 // && (source[scanner.currentPosition] == 'u')) {
5163 // //-------------unicode traitement
5165 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
5166 // scanner.currentPosition++;
5167 // while (source[scanner.currentPosition] == 'u') {
5168 // scanner.currentPosition++;
5170 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
5172 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
5175 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
5178 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
5180 // || c4 < 0) { //error
5184 // scanner.currentCharacter = 'A';
5185 // } //something different from * and
5188 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
5192 // if (this.scanner.taskTags != null) {
5193 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
5194 // this.scanner.getCurrentTokenEndPosition());
5201 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
5202 // scanner.scanIdentifierOrKeyword(false);
5205 // if (Character.isDigit(scanner.currentCharacter)) {
5206 // scanner.scanNumber(false);
5210 // //-----------------end switch while
5211 // // try--------------------
5212 // } catch (IndexOutOfBoundsException e) {
5213 // break; // read until EOF
5214 // } catch (InvalidInputException e) {
5215 // return false; // no clue
5218 // if (scanner.recordLineSeparator) {
5219 // compilationUnit.compilationResult.lineSeparatorPositions =
5220 // scanner.getLineEnds();
5222 // // check placement anomalies against other kinds of brackets
5223 // for (int kind = 0; kind < BracketKinds; kind++) {
5224 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
5225 // int start = leftPositions[kind][leftIndex]; // deepest
5227 // // find matching closing bracket
5228 // int depth = leftDepths[kind][leftIndex];
5230 // for (int i = 0; i < rightCount[kind]; i++) {
5231 // int pos = rightPositions[kind][i];
5232 // // want matching bracket further in source with same
5234 // if ((pos > start) && (depth == rightDepths[kind][i])) {
5239 // if (end < 0) { // did not find a good closing match
5240 // problemReporter.unmatchedBracket(start, referenceContext,
5241 // compilationUnit.compilationResult);
5244 // // check if even number of opening/closing other brackets
5245 // // in between this pair of brackets
5247 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
5249 // for (int i = 0; i < leftCount[otherKind]; i++) {
5250 // int pos = leftPositions[otherKind][i];
5251 // if ((pos > start) && (pos < end))
5254 // for (int i = 0; i < rightCount[otherKind]; i++) {
5255 // int pos = rightPositions[otherKind][i];
5256 // if ((pos > start) && (pos < end))
5259 // if (balance != 0) {
5260 // problemReporter.unmatchedBracket(start, referenceContext,
5261 // compilationUnit.compilationResult); //bracket
5267 // // too many opening brackets ?
5268 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
5269 // anomaliesDetected = true;
5270 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
5272 // 1], referenceContext,
5273 // compilationUnit.compilationResult);
5275 // // too many closing brackets ?
5276 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
5277 // anomaliesDetected = true;
5278 // problemReporter.unmatchedBracket(rightPositions[kind][i],
5279 // referenceContext,
5280 // compilationUnit.compilationResult);
5282 // if (anomaliesDetected)
5285 // return anomaliesDetected;
5286 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
5287 // return anomaliesDetected;
5288 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
5289 // return anomaliesDetected;
5292 // protected void pushOnAstLengthStack(int pos) {
5294 // astLengthStack[++astLengthPtr] = pos;
5295 // } catch (IndexOutOfBoundsException e) {
5296 // int oldStackLength = astLengthStack.length;
5297 // int[] oldPos = astLengthStack;
5298 // astLengthStack = new int[oldStackLength + StackIncrement];
5299 // System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5300 // astLengthStack[astLengthPtr] = pos;
5304 protected void pushOnAstStack(ASTNode node) {
5306 * add a new obj on top of the ast stack
5309 astStack[++astPtr] = node;
5310 } catch (IndexOutOfBoundsException e) {
5311 int oldStackLength = astStack.length;
5312 ASTNode[] oldStack = astStack;
5313 astStack = new ASTNode[oldStackLength + AstStackIncrement];
5314 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
5315 astPtr = oldStackLength;
5316 astStack[astPtr] = node;
5319 astLengthStack[++astLengthPtr] = 1;
5320 } catch (IndexOutOfBoundsException e) {
5321 int oldStackLength = astLengthStack.length;
5322 int[] oldPos = astLengthStack;
5323 astLengthStack = new int[oldStackLength + AstStackIncrement];
5324 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5325 astLengthStack[astLengthPtr] = 1;
5329 protected void resetModifiers() {
5330 this.modifiers = AccDefault;
5331 this.modifiersSourceStart = -1; // <-- see comment into
5332 // modifiersFlag(int)
5333 this.scanner.commentPtr = -1;
5336 protected void consumePackageDeclarationName(IFile file) {
5337 // create a package name similar to java package names
5339 //String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
5341 //String filePath = file.getFullPath().toString();
5343 String ext = file.getFileExtension();
5344 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
5345 ImportReference impt;
5348 /*if (filePath.startsWith(projectPath)) {
5349 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
5350 projectPath.length() + 1, filePath.length()
5351 - fileExtensionLength);
5353 String name = file.getName();
5354 tokens = new char[1][];
5355 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5359 this.compilationUnit.currentPackage = impt = new ImportReference(
5360 tokens, new char[0], 0, 0, true);
5362 impt.declarationSourceStart = 0;
5363 impt.declarationSourceEnd = 0;
5364 impt.declarationEnd = 0;
5365 // endPosition is just before the ;
5369 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5370 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5376 private void pushFunctionVariableSet() {
5377 HashSet set = new HashSet();
5378 if (fStackUnassigned.isEmpty()) {
5379 for (int i = 0; i < GLOBALS.length; i++) {
5380 set.add(GLOBALS[i]);
5383 fStackUnassigned.add(set);
5386 private void pushIfVariableSet() {
5387 if (!fStackUnassigned.isEmpty()) {
5388 HashSet set = new HashSet();
5389 fStackUnassigned.add(set);
5393 private HashSet removeIfVariableSet() {
5394 if (!fStackUnassigned.isEmpty()) {
5395 return (HashSet) fStackUnassigned
5396 .remove(fStackUnassigned.size() - 1);
5402 * Returns the <i>set of assigned variables </i> returns null if no Set is
5403 * defined at the current scanner position
5405 private HashSet peekVariableSet() {
5406 if (!fStackUnassigned.isEmpty()) {
5407 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5413 * add the current identifier source to the <i>set of assigned variables
5418 private void addVariableSet(HashSet set) {
5420 set.add(new String(scanner.getCurrentTokenSource()));
5425 * add the current identifier source to the <i>set of assigned variables
5429 private void addVariableSet() {
5430 HashSet set = peekVariableSet();
5432 set.add(new String(scanner.getCurrentTokenSource()));
5437 * add the current identifier source to the <i>set of assigned variables
5441 private void addVariableSet(char[] token) {
5442 HashSet set = peekVariableSet();
5444 set.add(new String(token));
5449 * check if the current identifier source is in the <i>set of assigned
5450 * variables </i> Returns true, if no set is defined for the current scanner
5454 private boolean containsVariableSet() {
5455 return containsVariableSet(scanner.getCurrentTokenSource());
5458 private boolean containsVariableSet(char[] token) {
5460 if (!fStackUnassigned.isEmpty()) {
5462 String str = new String(token);
5463 for (int i = 0; i < fStackUnassigned.size(); i++) {
5464 set = (HashSet) fStackUnassigned.get(i);
5465 if (set.contains(str)) {