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.internal.compiler.ast.AND_AND_Expression;
18 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
19 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
20 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
21 import net.sourceforge.phpdt.internal.compiler.ast.Block;
22 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
23 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
24 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
26 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
27 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
28 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
30 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
31 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
32 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
35 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
36 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
37 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
39 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
44 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
45 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
46 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
47 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
48 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
49 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
50 import net.sourceforge.phpdt.internal.compiler.util.Util;
51 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
52 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
53 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
55 import org.eclipse.core.resources.IFile;
56 import org.eclipse.core.resources.IProject;
57 import org.eclipse.core.resources.IResource;
58 import org.eclipse.core.runtime.IPath;
60 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
61 protected final static int StackIncrement = 255;
63 protected int stateStackTop;
65 // protected int[] stack = new int[StackIncrement];
67 public int firstToken; // handle for multiple parsing goals
69 public int lastAct; // handle for multiple parsing goals
71 // protected RecoveredElement currentElement;
73 public static boolean VERBOSE_RECOVERY = false;
75 protected boolean diet = false; // tells the scanner to jump over some
78 * the PHP token scanner
80 public Scanner scanner;
84 protected int modifiers;
86 protected int modifiersSourceStart;
88 protected Parser(ProblemReporter problemReporter) {
89 this.problemReporter = problemReporter;
90 this.options = problemReporter.options;
91 this.token = TokenNameEOF;
92 this.initializeScanner();
95 public void setFileToParse(IFile fileToParse) {
96 this.token = TokenNameEOF;
97 this.initializeScanner();
101 * ClassDeclaration Constructor.
105 * Description of Parameter
108 public Parser(IFile fileToParse) {
109 // if (keywordMap == null) {
110 // keywordMap = new HashMap();
111 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
112 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
115 // this.currentPHPString = 0;
116 // PHPParserSuperclass.fileToParse = fileToParse;
117 // this.phpList = null;
118 this.includesList = null;
120 this.token = TokenNameEOF;
122 // this.rowCount = 1;
123 // this.columnCount = 0;
124 // this.phpEnd = false;
126 this.initializeScanner();
129 public void initializeScanner() {
130 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
131 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
132 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
136 * Create marker for the parse error
138 // private void setMarker(String message, int charStart, int charEnd, int
140 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
143 * This method will throw the SyntaxError. It will add the good lines and
144 * columns to the Error
148 * @throws SyntaxError
151 private void throwSyntaxError(String error) {
152 int problemStartPosition = scanner.getCurrentTokenStartPosition();
153 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
154 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
155 problemEndPosition = scanner.source.length - 1;
156 if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
157 problemStartPosition = problemEndPosition - 1;
160 throwSyntaxError(error, problemStartPosition, problemEndPosition);
164 * This method will throw the SyntaxError. It will add the good lines and
165 * columns to the Error
169 * @throws SyntaxError
172 // private void throwSyntaxError(String error, int startRow) {
173 // throw new SyntaxError(startRow, 0, " ", error);
175 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
176 if (referenceContext != null) {
177 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
178 compilationUnit.compilationResult);
180 throw new SyntaxError(1, 0, " ", error);
183 private void reportSyntaxError(String error) {
184 int problemStartPosition = scanner.getCurrentTokenStartPosition();
185 int problemEndPosition = scanner.getCurrentTokenEndPosition();
186 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
189 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
190 if (referenceContext != null) {
191 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
192 compilationUnit.compilationResult);
196 // private void reportSyntaxWarning(String error, int problemStartPosition,
197 // int problemEndPosition) {
198 // if (referenceContext != null) {
199 // problemReporter.phpParsingWarning(new String[] { error },
200 // problemStartPosition, problemEndPosition, referenceContext,
201 // compilationUnit.compilationResult);
206 * gets the next token from input
208 private void getNextToken() {
210 token = scanner.getNextToken();
212 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213 int currentStartPosition = scanner.getCurrentTokenStartPosition();
214 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
215 System.out.println(scanner.toStringAction(token));
217 } catch (InvalidInputException e) {
218 token = TokenNameERROR;
219 String detailedMessage = e.getMessage();
221 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
222 throwSyntaxError("Unterminated string.");
223 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
224 throwSyntaxError("Unterminated commment.");
230 public void init(String s) {
232 this.token = TokenNameEOF;
233 this.includesList = new ArrayList();
235 // this.rowCount = 1;
236 // this.columnCount = 0;
237 // this.phpEnd = false;
238 // this.phpMode = false;
239 /* scanner initialization */
240 scanner.setSource(s.toCharArray());
241 scanner.setPHPMode(false);
245 protected void initialize(boolean phpMode) {
246 initialize(phpMode, null);
249 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
250 compilationUnit = null;
251 referenceContext = null;
252 this.includesList = new ArrayList();
253 // this.indexManager = indexManager;
255 this.token = TokenNameEOF;
257 // this.rowCount = 1;
258 // this.columnCount = 0;
259 // this.phpEnd = false;
260 // this.phpMode = phpMode;
261 scanner.setPHPMode(phpMode);
266 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
269 public void parse(String s) {
274 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
277 public void parse(String s, HashMap variables) {
278 fMethodVariables = variables;
279 fStackUnassigned = new ArrayList();
285 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
288 protected void parse() {
289 if (scanner.compilationUnit != null) {
290 IResource resource = scanner.compilationUnit.getResource();
291 if (resource != null && resource instanceof IFile) {
292 // set the package name
293 consumePackageDeclarationName((IFile) resource);
299 if (token != TokenNameEOF && token != TokenNameERROR) {
302 if (token != TokenNameEOF) {
303 if (token == TokenNameERROR) {
304 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
306 if (token == TokenNameRPAREN) {
307 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
309 if (token == TokenNameRBRACE) {
310 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
312 if (token == TokenNameRBRACKET) {
313 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
315 if (token == TokenNameLPAREN) {
316 throwSyntaxError("Read character '('; end-of-file not reached.");
318 if (token == TokenNameLBRACE) {
319 throwSyntaxError("Read character '{'; end-of-file not reached.");
321 if (token == TokenNameLBRACKET) {
322 throwSyntaxError("Read character '['; end-of-file not reached.");
324 throwSyntaxError("End-of-file not reached.");
327 } catch (SyntaxError syntaxError) {
328 // syntaxError.printStackTrace();
337 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
340 public void parseFunction(String s, HashMap variables) {
342 scanner.phpMode = true;
343 parseFunction(variables);
347 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
350 protected void parseFunction(HashMap variables) {
352 boolean hasModifiers = member_modifiers();
353 if (token == TokenNamefunction) {
355 checkAndSetModifiers(AccPublic);
357 this.fMethodVariables = variables;
359 MethodDeclaration methodDecl = new MethodDeclaration(null);
360 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
361 methodDecl.modifiers = this.modifiers;
362 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
365 functionDefinition(methodDecl);
366 } catch (SyntaxError sytaxErr1) {
369 int sourceEnd = methodDecl.sourceEnd;
370 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
371 sourceEnd = methodDecl.declarationSourceStart + 1;
373 methodDecl.sourceEnd = sourceEnd;
374 methodDecl.declarationSourceEnd = sourceEnd;
379 protected CompilationUnitDeclaration endParse(int act) {
383 // if (currentElement != null) {
384 // currentElement.topElement().updateParseTree();
385 // if (VERBOSE_RECOVERY) {
386 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
387 // System.out.println("--------------------------"); //$NON-NLS-1$
388 // System.out.println(compilationUnit);
389 // System.out.println("----------------------------------"); //$NON-NLS-1$
392 if (diet & VERBOSE_RECOVERY) {
393 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
394 System.out.println("--------------------------"); //$NON-NLS-1$
395 System.out.println(compilationUnit);
396 System.out.println("----------------------------------"); //$NON-NLS-1$
399 if (scanner.recordLineSeparator) {
400 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
402 if (scanner.taskTags != null) {
403 for (int i = 0; i < scanner.foundTaskCount; i++) {
404 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
405 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
406 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
409 compilationUnit.imports = new ImportReference[includesList.size()];
410 for (int i = 0; i < includesList.size(); i++) {
411 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
413 return compilationUnit;
416 private Block statementList() {
417 boolean branchStatement = false;
419 int blockStart = scanner.getCurrentTokenStartPosition();
420 ArrayList blockStatements = new ArrayList();
423 statement = statement();
424 blockStatements.add(statement);
425 if (token == TokenNameEOF) {
428 if (branchStatement && statement != null) {
429 // reportSyntaxError("Unreachable code", statement.sourceStart,
430 // statement.sourceEnd);
431 if (! (statement instanceof BreakStatement)) {
432 /* don't give an error for break statement following return statement
433 Technically it's unreachable code, but in switch-case it's recommended to
434 avoid accidental fall-through later when editing the code */
435 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
436 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
439 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
440 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
441 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
442 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
443 return createBlock(blockStart, blockStatements);
445 branchStatement = checkUnreachableStatements(statement);
446 } catch (SyntaxError sytaxErr1) {
447 // if an error occured,
448 // try to find keywords
449 // to parse the rest of the string
450 boolean tokenize = scanner.tokenizeStrings;
452 scanner.tokenizeStrings = true;
455 while (token != TokenNameEOF) {
456 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
457 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
458 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
459 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
460 return createBlock(blockStart, blockStatements);
462 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
463 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
464 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameECHO_INVISIBLE
465 || token == TokenNameglobal || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction
466 || token == TokenNamedeclare || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow
467 || token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
470 // System.out.println(scanner.toStringAction(token));
472 // System.out.println(scanner.toStringAction(token));
474 if (token == TokenNameEOF) {
478 scanner.tokenizeStrings = tokenize;
488 private boolean checkUnreachableStatements(Statement statement) {
489 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
491 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
499 * @param blockStatements
502 private Block createBlock(int blockStart, ArrayList blockStatements) {
503 int blockEnd = scanner.getCurrentTokenEndPosition();
504 Block b = Block.EmptyWith(blockStart, blockEnd);
505 b.statements = new Statement[blockStatements.size()];
506 blockStatements.toArray(b.statements);
510 private void functionBody(MethodDeclaration methodDecl) {
511 // '{' [statement-list] '}'
512 if (token == TokenNameLBRACE) {
515 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
516 throwSyntaxError("'{' expected in compound-statement.");
518 if (token != TokenNameRBRACE) {
521 if (token == TokenNameRBRACE) {
522 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
525 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
526 throwSyntaxError("'}' expected in compound-statement.");
530 private Statement statement() {
531 Statement statement = null;
532 Expression expression;
533 int sourceStart = scanner.getCurrentTokenStartPosition();
535 if (token == TokenNameif) {
536 // T_IF '(' expr ')' statement elseif_list else_single
537 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
538 // new_else_single T_ENDIF ';'
540 if (token == TokenNameLPAREN) {
543 throwSyntaxError("'(' expected after 'if' keyword.");
546 if (token == TokenNameRPAREN) {
549 throwSyntaxError("')' expected after 'if' condition.");
551 // create basic IfStatement
552 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
553 if (token == TokenNameCOLON) {
555 ifStatementColon(ifStatement);
557 ifStatement(ifStatement);
560 } else if (token == TokenNameswitch) {
562 if (token == TokenNameLPAREN) {
565 throwSyntaxError("'(' expected after 'switch' keyword.");
568 if (token == TokenNameRPAREN) {
571 throwSyntaxError("')' expected after 'switch' condition.");
575 } else if (token == TokenNamefor) {
577 if (token == TokenNameLPAREN) {
580 throwSyntaxError("'(' expected after 'for' keyword.");
582 if (token == TokenNameSEMICOLON) {
586 if (token == TokenNameSEMICOLON) {
589 throwSyntaxError("';' expected after 'for'.");
592 if (token == TokenNameSEMICOLON) {
596 if (token == TokenNameSEMICOLON) {
599 throwSyntaxError("';' expected after 'for'.");
602 if (token == TokenNameRPAREN) {
606 if (token == TokenNameRPAREN) {
609 throwSyntaxError("')' expected after 'for'.");
614 } else if (token == TokenNamewhile) {
616 if (token == TokenNameLPAREN) {
619 throwSyntaxError("'(' expected after 'while' keyword.");
622 if (token == TokenNameRPAREN) {
625 throwSyntaxError("')' expected after 'while' condition.");
629 } else if (token == TokenNamedo) {
631 if (token == TokenNameLBRACE) {
633 if (token != TokenNameRBRACE) {
636 if (token == TokenNameRBRACE) {
639 throwSyntaxError("'}' expected after 'do' keyword.");
644 if (token == TokenNamewhile) {
646 if (token == TokenNameLPAREN) {
649 throwSyntaxError("'(' expected after 'while' keyword.");
652 if (token == TokenNameRPAREN) {
655 throwSyntaxError("')' expected after 'while' condition.");
658 throwSyntaxError("'while' expected after 'do' keyword.");
660 if (token == TokenNameSEMICOLON) {
663 if (token != TokenNameINLINE_HTML) {
664 throwSyntaxError("';' expected after do-while statement.");
669 } else if (token == TokenNameforeach) {
671 if (token == TokenNameLPAREN) {
674 throwSyntaxError("'(' expected after 'foreach' keyword.");
677 if (token == TokenNameas) {
680 throwSyntaxError("'as' expected after 'foreach' exxpression.");
684 foreach_optional_arg();
685 if (token == TokenNameEQUAL_GREATER) {
687 variable(false, false);
689 if (token == TokenNameRPAREN) {
692 throwSyntaxError("')' expected after 'foreach' expression.");
696 } else if (token == TokenNamebreak) {
699 if (token != TokenNameSEMICOLON) {
702 if (token == TokenNameSEMICOLON) {
703 sourceEnd = scanner.getCurrentTokenEndPosition();
706 if (token != TokenNameINLINE_HTML) {
707 throwSyntaxError("';' expected after 'break'.");
709 sourceEnd = scanner.getCurrentTokenEndPosition();
712 return new BreakStatement(null, sourceStart, sourceEnd);
713 } else if (token == TokenNamecontinue) {
716 if (token != TokenNameSEMICOLON) {
719 if (token == TokenNameSEMICOLON) {
720 sourceEnd = scanner.getCurrentTokenEndPosition();
723 if (token != TokenNameINLINE_HTML) {
724 throwSyntaxError("';' expected after 'continue'.");
726 sourceEnd = scanner.getCurrentTokenEndPosition();
729 return new ContinueStatement(null, sourceStart, sourceEnd);
730 } else if (token == TokenNamereturn) {
733 if (token != TokenNameSEMICOLON) {
736 if (token == TokenNameSEMICOLON) {
737 sourceEnd = scanner.getCurrentTokenEndPosition();
740 if (token != TokenNameINLINE_HTML) {
741 throwSyntaxError("';' expected after 'return'.");
743 sourceEnd = scanner.getCurrentTokenEndPosition();
746 return new ReturnStatement(expression, sourceStart, sourceEnd);
747 } else if (token == TokenNameecho) {
750 if (token == TokenNameSEMICOLON) {
753 if (token != TokenNameINLINE_HTML) {
754 throwSyntaxError("';' expected after 'echo' statement.");
759 } else if (token == TokenNameECHO_INVISIBLE) {
760 // 0-length token directly after PHP short tag <?=
763 if (token == TokenNameSEMICOLON) {
765 // if (token != TokenNameINLINE_HTML) {
766 // // TODO should this become a configurable warning?
767 // reportSyntaxError("Probably '?>' expected after PHP short tag
768 // expression (only the first expression will be echoed).");
771 if (token != TokenNameINLINE_HTML) {
772 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
777 } else if (token == TokenNameINLINE_HTML) {
780 } else if (token == TokenNameglobal) {
783 if (token == TokenNameSEMICOLON) {
786 if (token != TokenNameINLINE_HTML) {
787 throwSyntaxError("';' expected after 'global' statement.");
792 } else if (token == TokenNamestatic) {
795 if (token == TokenNameSEMICOLON) {
798 if (token != TokenNameINLINE_HTML) {
799 throwSyntaxError("';' expected after 'static' statement.");
804 } else if (token == TokenNameunset) {
806 if (token == TokenNameLPAREN) {
809 throwSyntaxError("'(' expected after 'unset' statement.");
812 if (token == TokenNameRPAREN) {
815 throwSyntaxError("')' expected after 'unset' statement.");
817 if (token == TokenNameSEMICOLON) {
820 if (token != TokenNameINLINE_HTML) {
821 throwSyntaxError("';' expected after 'unset' statement.");
826 } else if (token == TokenNamefunction) {
827 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
828 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
829 methodDecl.modifiers = AccDefault;
830 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
833 functionDefinition(methodDecl);
835 sourceEnd = methodDecl.sourceEnd;
836 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
837 sourceEnd = methodDecl.declarationSourceStart + 1;
839 methodDecl.declarationSourceEnd = sourceEnd;
840 methodDecl.sourceEnd = sourceEnd;
843 } else if (token == TokenNamedeclare) {
844 // T_DECLARE '(' declare_list ')' declare_statement
846 if (token != TokenNameLPAREN) {
847 throwSyntaxError("'(' expected in 'declare' statement.");
851 if (token != TokenNameRPAREN) {
852 throwSyntaxError("')' expected in 'declare' statement.");
857 } else if (token == TokenNametry) {
859 if (token != TokenNameLBRACE) {
860 throwSyntaxError("'{' expected in 'try' statement.");
864 if (token != TokenNameRBRACE) {
865 throwSyntaxError("'}' expected in 'try' statement.");
869 } else if (token == TokenNamecatch) {
871 if (token != TokenNameLPAREN) {
872 throwSyntaxError("'(' expected in 'catch' statement.");
875 fully_qualified_class_name();
876 if (token != TokenNameVariable) {
877 throwSyntaxError("Variable expected in 'catch' statement.");
881 if (token != TokenNameRPAREN) {
882 throwSyntaxError("')' expected in 'catch' statement.");
885 if (token != TokenNameLBRACE) {
886 throwSyntaxError("'{' expected in 'catch' statement.");
889 if (token != TokenNameRBRACE) {
891 if (token != TokenNameRBRACE) {
892 throwSyntaxError("'}' expected in 'catch' statement.");
896 additional_catches();
898 } else if (token == TokenNamethrow) {
901 if (token == TokenNameSEMICOLON) {
904 throwSyntaxError("';' expected after 'throw' exxpression.");
907 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
909 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
910 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
911 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
912 typeDecl.name = new char[] { ' ' };
913 // default super class
914 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
915 compilationUnit.types.add(typeDecl);
916 pushOnAstStack(typeDecl);
917 unticked_class_declaration_statement(typeDecl);
925 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
926 } else if (token == TokenNameLBRACE) {
928 if (token != TokenNameRBRACE) {
929 statement = statementList();
931 if (token == TokenNameRBRACE) {
935 throwSyntaxError("'}' expected.");
938 if (token != TokenNameSEMICOLON) {
941 if (token == TokenNameSEMICOLON) {
945 if (token == TokenNameRBRACE) {
946 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
948 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
949 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
959 private void declare_statement() {
961 // | ':' inner_statement_list T_ENDDECLARE ';'
963 if (token == TokenNameCOLON) {
965 // TODO: implement inner_statement_list();
967 if (token != TokenNameenddeclare) {
968 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
971 if (token != TokenNameSEMICOLON) {
972 throwSyntaxError("';' expected after 'enddeclare' keyword.");
980 private void declare_list() {
981 // T_STRING '=' static_scalar
982 // | declare_list ',' T_STRING '=' static_scalar
984 if (token != TokenNameIdentifier) {
985 throwSyntaxError("Identifier expected in 'declare' list.");
988 if (token != TokenNameEQUAL) {
989 throwSyntaxError("'=' expected in 'declare' list.");
993 if (token != TokenNameCOMMA) {
1000 private void additional_catches() {
1001 while (token == TokenNamecatch) {
1003 if (token != TokenNameLPAREN) {
1004 throwSyntaxError("'(' expected in 'catch' statement.");
1007 fully_qualified_class_name();
1008 if (token != TokenNameVariable) {
1009 throwSyntaxError("Variable expected in 'catch' statement.");
1013 if (token != TokenNameRPAREN) {
1014 throwSyntaxError("')' expected in 'catch' statement.");
1017 if (token != TokenNameLBRACE) {
1018 throwSyntaxError("'{' expected in 'catch' statement.");
1021 if (token != TokenNameRBRACE) {
1024 if (token != TokenNameRBRACE) {
1025 throwSyntaxError("'}' expected in 'catch' statement.");
1031 private void foreach_variable() {
1034 if (token == TokenNameAND) {
1040 private void foreach_optional_arg() {
1042 // | T_DOUBLE_ARROW foreach_variable
1043 if (token == TokenNameEQUAL_GREATER) {
1049 private void global_var_list() {
1051 // global_var_list ',' global_var
1053 HashSet set = peekVariableSet();
1056 if (token != TokenNameCOMMA) {
1063 private void global_var(HashSet set) {
1067 // | '$' '{' expr '}'
1068 if (token == TokenNameVariable) {
1069 if (fMethodVariables != null) {
1070 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1071 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1073 addVariableSet(set);
1075 } else if (token == TokenNameDOLLAR) {
1077 if (token == TokenNameLBRACE) {
1080 if (token != TokenNameRBRACE) {
1081 throwSyntaxError("'}' expected in global variable.");
1090 private void static_var_list() {
1092 // static_var_list ',' T_VARIABLE
1093 // | static_var_list ',' T_VARIABLE '=' static_scalar
1095 // | T_VARIABLE '=' static_scalar,
1096 HashSet set = peekVariableSet();
1098 if (token == TokenNameVariable) {
1099 if (fMethodVariables != null) {
1100 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1101 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1103 addVariableSet(set);
1105 if (token == TokenNameEQUAL) {
1109 if (token != TokenNameCOMMA) {
1119 private void unset_variables() {
1122 // | unset_variables ',' unset_variable
1126 variable(false, false);
1127 if (token != TokenNameCOMMA) {
1134 private final void initializeModifiers() {
1136 this.modifiersSourceStart = -1;
1139 private final void checkAndSetModifiers(int flag) {
1140 this.modifiers |= flag;
1141 if (this.modifiersSourceStart < 0)
1142 this.modifiersSourceStart = this.scanner.startPosition;
1145 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1146 initializeModifiers();
1147 if (token == TokenNameinterface) {
1148 // interface_entry T_STRING
1149 // interface_extends_list
1150 // '{' class_statement_list '}'
1151 checkAndSetModifiers(AccInterface);
1153 typeDecl.modifiers = this.modifiers;
1154 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1155 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1156 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1157 typeDecl.name = scanner.getCurrentIdentifierSource();
1158 if (token > TokenNameKEYWORD) {
1159 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1160 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1161 // throwSyntaxError("Don't use a keyword for interface declaration ["
1162 // + scanner.toStringAction(token) + "].",
1163 // typeDecl.sourceStart, typeDecl.sourceEnd);
1166 interface_extends_list(typeDecl);
1168 typeDecl.name = new char[] { ' ' };
1169 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1173 // class_entry_type T_STRING extends_from
1175 // '{' class_statement_list'}'
1177 typeDecl.modifiers = this.modifiers;
1178 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1179 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1181 // identifier 'extends' identifier
1182 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1183 typeDecl.name = scanner.getCurrentIdentifierSource();
1184 if (token > TokenNameKEYWORD) {
1185 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1186 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1187 // throwSyntaxError("Don't use a keyword for class declaration [" +
1188 // scanner.toStringAction(token) + "].",
1189 // typeDecl.sourceStart, typeDecl.sourceEnd);
1194 // | T_EXTENDS fully_qualified_class_name
1195 if (token == TokenNameextends) {
1196 interface_extends_list(typeDecl);
1198 // if (token != TokenNameIdentifier) {
1199 // throwSyntaxError("Class name expected after keyword
1201 // scanner.getCurrentTokenStartPosition(), scanner
1202 // .getCurrentTokenEndPosition());
1205 implements_list(typeDecl);
1207 typeDecl.name = new char[] { ' ' };
1208 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1212 // '{' class_statement_list '}'
1213 if (token == TokenNameLBRACE) {
1215 if (token != TokenNameRBRACE) {
1216 ArrayList list = new ArrayList();
1217 class_statement_list(list);
1218 typeDecl.fields = new FieldDeclaration[list.size()];
1219 for (int i = 0; i < list.size(); i++) {
1220 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1223 if (token == TokenNameRBRACE) {
1224 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1227 throwSyntaxError("'}' expected at end of class body.");
1230 throwSyntaxError("'{' expected at start of class body.");
1234 private void class_entry_type() {
1236 // | T_ABSTRACT T_CLASS
1237 // | T_FINAL T_CLASS
1238 if (token == TokenNameclass) {
1240 } else if (token == TokenNameabstract) {
1241 checkAndSetModifiers(AccAbstract);
1243 if (token != TokenNameclass) {
1244 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1247 } else if (token == TokenNamefinal) {
1248 checkAndSetModifiers(AccFinal);
1250 if (token != TokenNameclass) {
1251 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1255 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1259 // private void class_extends(TypeDeclaration typeDecl) {
1261 // // | T_EXTENDS interface_list
1262 // if (token == TokenNameextends) {
1265 // if (token == TokenNameIdentifier) {
1268 // throwSyntaxError("Class name expected after keyword 'extends'.");
1273 private void interface_extends_list(TypeDeclaration typeDecl) {
1275 // | T_EXTENDS interface_list
1276 if (token == TokenNameextends) {
1278 class_list(typeDecl);
1282 private void implements_list(TypeDeclaration typeDecl) {
1284 // | T_IMPLEMENTS interface_list
1285 if (token == TokenNameimplements) {
1287 interface_list(typeDecl);
1291 private void class_list(TypeDeclaration typeDecl) {
1293 // fully_qualified_class_name
1295 if (token == TokenNameIdentifier) {
1296 char[] ident = scanner.getCurrentIdentifierSource();
1297 // TODO make this code working better:
1298 // SingleTypeReference ref = ParserUtil.getTypeReference(scanner,
1299 // includesList, ident);
1300 // if (ref != null) {
1301 // typeDecl.superclass = ref;
1305 throwSyntaxError("Classname expected after keyword 'extends'.");
1307 if (token == TokenNameCOMMA) {
1308 reportSyntaxError("No multiple inheritence allowed. Expected token 'implements' or '{'.");
1317 private void interface_list(TypeDeclaration typeDecl) {
1319 // fully_qualified_class_name
1320 // | interface_list ',' fully_qualified_class_name
1322 if (token == TokenNameIdentifier) {
1325 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1327 if (token != TokenNameCOMMA) {
1334 // private void classBody(TypeDeclaration typeDecl) {
1335 // //'{' [class-element-list] '}'
1336 // if (token == TokenNameLBRACE) {
1338 // if (token != TokenNameRBRACE) {
1339 // class_statement_list();
1341 // if (token == TokenNameRBRACE) {
1342 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1345 // throwSyntaxError("'}' expected at end of class body.");
1348 // throwSyntaxError("'{' expected at start of class body.");
1351 private void class_statement_list(ArrayList list) {
1354 class_statement(list);
1355 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1356 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1357 || token == TokenNameconst) {
1360 if (token == TokenNameRBRACE) {
1363 throwSyntaxError("'}' at end of class statement.");
1364 } catch (SyntaxError sytaxErr1) {
1365 boolean tokenize = scanner.tokenizeStrings;
1367 scanner.tokenizeStrings = true;
1370 // if an error occured,
1371 // try to find keywords
1372 // to parse the rest of the string
1373 while (token != TokenNameEOF) {
1374 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1375 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1376 || token == TokenNameconst) {
1379 // System.out.println(scanner.toStringAction(token));
1382 if (token == TokenNameEOF) {
1386 scanner.tokenizeStrings = tokenize;
1392 private void class_statement(ArrayList list) {
1394 // variable_modifiers class_variable_declaration ';'
1395 // | class_constant_declaration ';'
1396 // | method_modifiers T_FUNCTION is_reference T_STRING
1397 // '(' parameter_list ')' method_body
1398 initializeModifiers();
1399 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1401 if (token == TokenNamevar) {
1402 checkAndSetModifiers(AccPublic);
1403 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1404 referenceContext, compilationUnit.compilationResult);
1406 class_variable_declaration(declarationSourceStart, list);
1407 } else if (token == TokenNameconst) {
1408 checkAndSetModifiers(AccFinal | AccPublic);
1409 class_constant_declaration(declarationSourceStart, list);
1410 if (token != TokenNameSEMICOLON) {
1411 throwSyntaxError("';' expected after class const declaration.");
1415 boolean hasModifiers = member_modifiers();
1416 if (token == TokenNamefunction) {
1417 if (!hasModifiers) {
1418 checkAndSetModifiers(AccPublic);
1420 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1421 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1422 methodDecl.modifiers = this.modifiers;
1423 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1426 functionDefinition(methodDecl);
1428 int sourceEnd = methodDecl.sourceEnd;
1429 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1430 sourceEnd = methodDecl.declarationSourceStart + 1;
1432 methodDecl.declarationSourceEnd = sourceEnd;
1433 methodDecl.sourceEnd = sourceEnd;
1436 if (!hasModifiers) {
1437 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1439 class_variable_declaration(declarationSourceStart, list);
1444 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1445 // class_constant_declaration ',' T_STRING '=' static_scalar
1446 // | T_CONST T_STRING '=' static_scalar
1447 if (token != TokenNameconst) {
1448 throwSyntaxError("'const' keyword expected in class declaration.");
1453 if (token != TokenNameIdentifier) {
1454 throwSyntaxError("Identifier expected in class const declaration.");
1456 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1457 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1458 fieldDeclaration.modifiers = this.modifiers;
1459 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1460 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1461 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1462 // fieldDeclaration.type
1463 list.add(fieldDeclaration);
1465 if (token != TokenNameEQUAL) {
1466 throwSyntaxError("'=' expected in class const declaration.");
1470 if (token != TokenNameCOMMA) {
1471 break; // while(true)-loop
1477 // private void variable_modifiers() {
1478 // // variable_modifiers:
1479 // // non_empty_member_modifiers
1481 // initializeModifiers();
1482 // if (token == TokenNamevar) {
1483 // checkAndSetModifiers(AccPublic);
1484 // reportSyntaxError(
1485 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1487 // modifier for field declarations.",
1488 // scanner.getCurrentTokenStartPosition(), scanner
1489 // .getCurrentTokenEndPosition());
1492 // if (!member_modifiers()) {
1493 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1494 // field declarations.");
1498 // private void method_modifiers() {
1499 // //method_modifiers:
1501 // //| non_empty_member_modifiers
1502 // initializeModifiers();
1503 // if (!member_modifiers()) {
1504 // checkAndSetModifiers(AccPublic);
1507 private boolean member_modifiers() {
1514 boolean foundToken = false;
1516 if (token == TokenNamepublic) {
1517 checkAndSetModifiers(AccPublic);
1520 } else if (token == TokenNameprotected) {
1521 checkAndSetModifiers(AccProtected);
1524 } else if (token == TokenNameprivate) {
1525 checkAndSetModifiers(AccPrivate);
1528 } else if (token == TokenNamestatic) {
1529 checkAndSetModifiers(AccStatic);
1532 } else if (token == TokenNameabstract) {
1533 checkAndSetModifiers(AccAbstract);
1536 } else if (token == TokenNamefinal) {
1537 checkAndSetModifiers(AccFinal);
1547 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1548 // class_variable_declaration:
1549 // class_variable_declaration ',' T_VARIABLE
1550 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1552 // | T_VARIABLE '=' static_scalar
1553 char[] classVariable;
1555 if (token == TokenNameVariable) {
1556 classVariable = scanner.getCurrentIdentifierSource();
1557 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1559 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1560 .getCurrentTokenEndPosition());
1561 fieldDeclaration.modifiers = this.modifiers;
1562 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1563 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1564 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1565 list.add(fieldDeclaration);
1566 if (fTypeVariables != null) {
1567 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1568 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1571 if (token == TokenNameEQUAL) {
1576 // if (token == TokenNamethis) {
1577 // throwSyntaxError("'$this' not allowed after keyword 'public'
1578 // 'protected' 'private' 'var'.");
1580 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1582 if (token != TokenNameCOMMA) {
1587 if (token != TokenNameSEMICOLON) {
1588 throwSyntaxError("';' expected after field declaration.");
1593 private void functionDefinition(MethodDeclaration methodDecl) {
1594 boolean isAbstract = false;
1596 if (compilationUnit != null) {
1597 compilationUnit.types.add(methodDecl);
1600 ASTNode node = astStack[astPtr];
1601 if (node instanceof TypeDeclaration) {
1602 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1603 if (typeDecl.methods == null) {
1604 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1606 AbstractMethodDeclaration[] newMethods;
1607 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1608 typeDecl.methods.length);
1609 newMethods[typeDecl.methods.length] = methodDecl;
1610 typeDecl.methods = newMethods;
1612 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1614 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1620 pushFunctionVariableSet();
1621 functionDeclarator(methodDecl);
1622 if (token == TokenNameSEMICOLON) {
1624 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1625 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1630 functionBody(methodDecl);
1632 if (!fStackUnassigned.isEmpty()) {
1633 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1638 private void functionDeclarator(MethodDeclaration methodDecl) {
1639 // identifier '(' [parameter-list] ')'
1640 if (token == TokenNameAND) {
1643 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1644 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1645 if (Scanner.isIdentifierOrKeyword(token)) {
1646 methodDecl.selector = scanner.getCurrentIdentifierSource();
1647 if (token > TokenNameKEYWORD) {
1648 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1649 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1652 if (token == TokenNameLPAREN) {
1655 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1656 throwSyntaxError("'(' expected in function declaration.");
1658 if (token != TokenNameRPAREN) {
1659 parameter_list(methodDecl);
1661 if (token != TokenNameRPAREN) {
1662 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1663 throwSyntaxError("')' expected in function declaration.");
1665 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1669 methodDecl.selector = "<undefined>".toCharArray();
1670 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1671 throwSyntaxError("Function name expected after keyword 'function'.");
1676 private void parameter_list(MethodDeclaration methodDecl) {
1677 // non_empty_parameter_list
1679 non_empty_parameter_list(methodDecl, true);
1682 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1683 // optional_class_type T_VARIABLE
1684 // | optional_class_type '&' T_VARIABLE
1685 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1686 // | optional_class_type T_VARIABLE '=' static_scalar
1687 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1688 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1689 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1691 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1693 char[] typeIdentifier = null;
1694 if (token == TokenNameIdentifier || token == TokenNamearray || token == TokenNameVariable || token == TokenNameAND) {
1695 HashSet set = peekVariableSet();
1697 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature req. #1254275
1698 typeIdentifier = scanner.getCurrentIdentifierSource();
1701 if (token == TokenNameAND) {
1704 if (token == TokenNameVariable) {
1705 if (fMethodVariables != null) {
1707 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1708 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1710 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1712 info.typeIdentifier = typeIdentifier;
1713 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1715 addVariableSet(set);
1717 if (token == TokenNameEQUAL) {
1722 throwSyntaxError("Variable expected in parameter list.");
1724 if (token != TokenNameCOMMA) {
1731 if (!empty_allowed) {
1732 throwSyntaxError("Identifier expected in parameter list.");
1736 private void optional_class_type() {
1741 // private void parameterDeclaration() {
1743 // //variable-reference
1744 // if (token == TokenNameAND) {
1746 // if (isVariable()) {
1749 // throwSyntaxError("Variable expected after reference operator '&'.");
1752 // //variable '=' constant
1753 // if (token == TokenNameVariable) {
1755 // if (token == TokenNameEQUAL) {
1761 // // if (token == TokenNamethis) {
1762 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1763 // // declaration.");
1767 private void labeledStatementList() {
1768 if (token != TokenNamecase && token != TokenNamedefault) {
1769 throwSyntaxError("'case' or 'default' expected.");
1772 if (token == TokenNamecase) {
1774 expr(); // constant();
1775 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1777 if (token == TokenNameRBRACE) {
1778 // empty case; assumes that the '}' token belongs to the wrapping
1779 // switch statement - #1371992
1782 if (token == TokenNamecase || token == TokenNamedefault) {
1783 // empty case statement ?
1788 // else if (token == TokenNameSEMICOLON) {
1790 // "':' expected after 'case' keyword (Found token: " +
1791 // scanner.toStringAction(token) + ")",
1792 // scanner.getCurrentTokenStartPosition(),
1793 // scanner.getCurrentTokenEndPosition(),
1796 // if (token == TokenNamecase) { // empty case statement ?
1802 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1804 } else { // TokenNamedefault
1806 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1808 if (token == TokenNameRBRACE) {
1809 // empty default case; ; assumes that the '}' token belongs to the
1810 // wrapping switch statement - #1371992
1813 if (token != TokenNamecase) {
1817 throwSyntaxError("':' character expected after 'default'.");
1820 } while (token == TokenNamecase || token == TokenNamedefault);
1823 private void ifStatementColon(IfStatement iState) {
1824 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1825 // new_else_single T_ENDIF ';'
1826 HashSet assignedVariableSet = null;
1828 Block b = inner_statement_list();
1829 iState.thenStatement = b;
1830 checkUnreachable(iState, b);
1832 assignedVariableSet = removeIfVariableSet();
1834 if (token == TokenNameelseif) {
1836 pushIfVariableSet();
1837 new_elseif_list(iState);
1839 HashSet set = removeIfVariableSet();
1840 if (assignedVariableSet != null && set != null) {
1841 assignedVariableSet.addAll(set);
1846 pushIfVariableSet();
1847 new_else_single(iState);
1849 HashSet set = removeIfVariableSet();
1850 if (assignedVariableSet != null) {
1851 HashSet topSet = peekVariableSet();
1852 if (topSet != null) {
1856 topSet.addAll(assignedVariableSet);
1860 if (token != TokenNameendif) {
1861 throwSyntaxError("'endif' expected.");
1864 if (token != TokenNameSEMICOLON) {
1865 reportSyntaxError("';' expected after if-statement.");
1866 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1868 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1873 private void ifStatement(IfStatement iState) {
1874 // T_IF '(' expr ')' statement elseif_list else_single
1875 HashSet assignedVariableSet = null;
1877 pushIfVariableSet();
1878 Statement s = statement();
1879 iState.thenStatement = s;
1880 checkUnreachable(iState, s);
1882 assignedVariableSet = removeIfVariableSet();
1885 if (token == TokenNameelseif) {
1887 pushIfVariableSet();
1888 elseif_list(iState);
1890 HashSet set = removeIfVariableSet();
1891 if (assignedVariableSet != null && set != null) {
1892 assignedVariableSet.addAll(set);
1897 pushIfVariableSet();
1898 else_single(iState);
1900 HashSet set = removeIfVariableSet();
1901 if (assignedVariableSet != null) {
1902 HashSet topSet = peekVariableSet();
1903 if (topSet != null) {
1907 topSet.addAll(assignedVariableSet);
1913 private void elseif_list(IfStatement iState) {
1915 // | elseif_list T_ELSEIF '(' expr ')' statement
1916 ArrayList conditionList = new ArrayList();
1917 ArrayList statementList = new ArrayList();
1920 while (token == TokenNameelseif) {
1922 if (token == TokenNameLPAREN) {
1925 throwSyntaxError("'(' expected after 'elseif' keyword.");
1928 conditionList.add(e);
1929 if (token == TokenNameRPAREN) {
1932 throwSyntaxError("')' expected after 'elseif' condition.");
1935 statementList.add(s);
1936 checkUnreachable(iState, s);
1938 iState.elseifConditions = new Expression[conditionList.size()];
1939 iState.elseifStatements = new Statement[statementList.size()];
1940 conditionList.toArray(iState.elseifConditions);
1941 statementList.toArray(iState.elseifStatements);
1944 private void new_elseif_list(IfStatement iState) {
1946 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1947 ArrayList conditionList = new ArrayList();
1948 ArrayList statementList = new ArrayList();
1951 while (token == TokenNameelseif) {
1953 if (token == TokenNameLPAREN) {
1956 throwSyntaxError("'(' expected after 'elseif' keyword.");
1959 conditionList.add(e);
1960 if (token == TokenNameRPAREN) {
1963 throwSyntaxError("')' expected after 'elseif' condition.");
1965 if (token == TokenNameCOLON) {
1968 throwSyntaxError("':' expected after 'elseif' keyword.");
1970 b = inner_statement_list();
1971 statementList.add(b);
1972 checkUnreachable(iState, b);
1974 iState.elseifConditions = new Expression[conditionList.size()];
1975 iState.elseifStatements = new Statement[statementList.size()];
1976 conditionList.toArray(iState.elseifConditions);
1977 statementList.toArray(iState.elseifStatements);
1980 private void else_single(IfStatement iState) {
1983 if (token == TokenNameelse) {
1985 Statement s = statement();
1986 iState.elseStatement = s;
1987 checkUnreachable(iState, s);
1989 iState.checkUnreachable = false;
1991 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1994 private void new_else_single(IfStatement iState) {
1996 // | T_ELSE ':' inner_statement_list
1997 if (token == TokenNameelse) {
1999 if (token == TokenNameCOLON) {
2002 throwSyntaxError("':' expected after 'else' keyword.");
2004 Block b = inner_statement_list();
2005 iState.elseStatement = b;
2006 checkUnreachable(iState, b);
2008 iState.checkUnreachable = false;
2012 private Block inner_statement_list() {
2013 // inner_statement_list inner_statement
2015 return statementList();
2022 private void checkUnreachable(IfStatement iState, Statement s) {
2023 if (s instanceof Block) {
2024 Block b = (Block) s;
2025 if (b.statements == null || b.statements.length == 0) {
2026 iState.checkUnreachable = false;
2028 int off = b.statements.length - 1;
2029 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2030 && !(b.statements[off] instanceof BreakStatement)) {
2031 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2032 iState.checkUnreachable = false;
2037 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2038 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2039 iState.checkUnreachable = false;
2045 // private void elseifStatementList() {
2047 // elseifStatement();
2049 // case TokenNameelse:
2051 // if (token == TokenNameCOLON) {
2053 // if (token != TokenNameendif) {
2058 // if (token == TokenNameif) { //'else if'
2061 // throwSyntaxError("':' expected after 'else'.");
2065 // case TokenNameelseif:
2074 // private void elseifStatement() {
2075 // if (token == TokenNameLPAREN) {
2078 // if (token != TokenNameRPAREN) {
2079 // throwSyntaxError("')' expected in else-if-statement.");
2082 // if (token != TokenNameCOLON) {
2083 // throwSyntaxError("':' expected in else-if-statement.");
2086 // if (token != TokenNameendif) {
2092 private void switchStatement() {
2093 if (token == TokenNameCOLON) {
2094 // ':' [labeled-statement-list] 'endswitch' ';'
2096 labeledStatementList();
2097 if (token != TokenNameendswitch) {
2098 throwSyntaxError("'endswitch' expected.");
2101 if (token != TokenNameSEMICOLON) {
2102 throwSyntaxError("';' expected after switch-statement.");
2106 // '{' [labeled-statement-list] '}'
2107 if (token != TokenNameLBRACE) {
2108 throwSyntaxError("'{' expected in switch statement.");
2111 if (token != TokenNameRBRACE) {
2112 labeledStatementList();
2114 if (token != TokenNameRBRACE) {
2115 throwSyntaxError("'}' expected in switch statement.");
2121 private void forStatement() {
2122 if (token == TokenNameCOLON) {
2125 if (token != TokenNameendfor) {
2126 throwSyntaxError("'endfor' expected.");
2129 if (token != TokenNameSEMICOLON) {
2130 throwSyntaxError("';' expected after for-statement.");
2138 private void whileStatement() {
2139 // ':' statement-list 'endwhile' ';'
2140 if (token == TokenNameCOLON) {
2143 if (token != TokenNameendwhile) {
2144 throwSyntaxError("'endwhile' expected.");
2147 if (token != TokenNameSEMICOLON) {
2148 throwSyntaxError("';' expected after while-statement.");
2156 private void foreachStatement() {
2157 if (token == TokenNameCOLON) {
2160 if (token != TokenNameendforeach) {
2161 throwSyntaxError("'endforeach' expected.");
2164 if (token != TokenNameSEMICOLON) {
2165 throwSyntaxError("';' expected after foreach-statement.");
2173 // private void exitStatus() {
2174 // if (token == TokenNameLPAREN) {
2177 // throwSyntaxError("'(' expected in 'exit-status'.");
2179 // if (token != TokenNameRPAREN) {
2182 // if (token == TokenNameRPAREN) {
2185 // throwSyntaxError("')' expected after 'exit-status'.");
2188 private void expressionList() {
2191 if (token == TokenNameCOMMA) {
2199 private Expression expr() {
2201 // | expr_without_variable
2202 // if (token!=TokenNameEOF) {
2203 if (Scanner.TRACE) {
2204 System.out.println("TRACE: expr()");
2206 return expr_without_variable(true,null);
2210 private Expression expr_without_variable(boolean only_variable, UninitializedVariableHandler initHandler) {
2211 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2212 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2213 Expression expression = new Expression();
2214 expression.sourceStart = exprSourceStart;
2215 // default, may be overwritten
2216 expression.sourceEnd = exprSourceEnd;
2218 // internal_functions_in_yacc
2227 // | T_INC rw_variable
2228 // | T_DEC rw_variable
2229 // | T_INT_CAST expr
2230 // | T_DOUBLE_CAST expr
2231 // | T_STRING_CAST expr
2232 // | T_ARRAY_CAST expr
2233 // | T_OBJECT_CAST expr
2234 // | T_BOOL_CAST expr
2235 // | T_UNSET_CAST expr
2236 // | T_EXIT exit_expr
2238 // | T_ARRAY '(' array_pair_list ')'
2239 // | '`' encaps_list '`'
2240 // | T_LIST '(' assignment_list ')' '=' expr
2241 // | T_NEW class_name_reference ctor_arguments
2242 // | variable '=' expr
2243 // | variable '=' '&' variable
2244 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2245 // | variable T_PLUS_EQUAL expr
2246 // | variable T_MINUS_EQUAL expr
2247 // | variable T_MUL_EQUAL expr
2248 // | variable T_DIV_EQUAL expr
2249 // | variable T_CONCAT_EQUAL expr
2250 // | variable T_MOD_EQUAL expr
2251 // | variable T_AND_EQUAL expr
2252 // | variable T_OR_EQUAL expr
2253 // | variable T_XOR_EQUAL expr
2254 // | variable T_SL_EQUAL expr
2255 // | variable T_SR_EQUAL expr
2256 // | rw_variable T_INC
2257 // | rw_variable T_DEC
2258 // | expr T_BOOLEAN_OR expr
2259 // | expr T_BOOLEAN_AND expr
2260 // | expr T_LOGICAL_OR expr
2261 // | expr T_LOGICAL_AND expr
2262 // | expr T_LOGICAL_XOR expr
2274 // | expr T_IS_IDENTICAL expr
2275 // | expr T_IS_NOT_IDENTICAL expr
2276 // | expr T_IS_EQUAL expr
2277 // | expr T_IS_NOT_EQUAL expr
2279 // | expr T_IS_SMALLER_OR_EQUAL expr
2281 // | expr T_IS_GREATER_OR_EQUAL expr
2282 // | expr T_INSTANCEOF class_name_reference
2283 // | expr '?' expr ':' expr
2284 if (Scanner.TRACE) {
2285 System.out.println("TRACE: expr_without_variable() PART 1");
2288 case TokenNameisset:
2289 // T_ISSET '(' isset_variables ')'
2291 if (token != TokenNameLPAREN) {
2292 throwSyntaxError("'(' expected after keyword 'isset'");
2296 if (token != TokenNameRPAREN) {
2297 throwSyntaxError("')' expected after keyword 'isset'");
2301 case TokenNameempty:
2303 if (token != TokenNameLPAREN) {
2304 throwSyntaxError("'(' expected after keyword 'empty'");
2307 variable(true, false);
2308 if (token != TokenNameRPAREN) {
2309 throwSyntaxError("')' expected after keyword 'empty'");
2314 case TokenNameinclude:
2315 case TokenNameinclude_once:
2316 case TokenNamerequire:
2317 case TokenNamerequire_once:
2318 internal_functions_in_yacc();
2321 case TokenNameLPAREN:
2324 if (token == TokenNameRPAREN) {
2327 throwSyntaxError("')' expected in expression.");
2337 // | T_INT_CAST expr
2338 // | T_DOUBLE_CAST expr
2339 // | T_STRING_CAST expr
2340 // | T_ARRAY_CAST expr
2341 // | T_OBJECT_CAST expr
2342 // | T_BOOL_CAST expr
2343 // | T_UNSET_CAST expr
2344 case TokenNameclone:
2345 case TokenNameprint:
2348 case TokenNameMINUS:
2350 case TokenNameTWIDDLE:
2351 case TokenNameintCAST:
2352 case TokenNamedoubleCAST:
2353 case TokenNamestringCAST:
2354 case TokenNamearrayCAST:
2355 case TokenNameobjectCAST:
2356 case TokenNameboolCAST:
2357 case TokenNameunsetCAST:
2367 // | T_STRING_VARNAME
2369 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2370 // | '`' encaps_list '`'
2372 // | '`' encaps_list '`'
2373 // case TokenNameEncapsedString0:
2374 // scanner.encapsedStringStack.push(new Character('`'));
2377 // if (token == TokenNameEncapsedString0) {
2380 // if (token != TokenNameEncapsedString0) {
2381 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2382 // scanner.toStringAction(token) + " )");
2386 // scanner.encapsedStringStack.pop();
2390 // // | '\'' encaps_list '\''
2391 // case TokenNameEncapsedString1:
2392 // scanner.encapsedStringStack.push(new Character('\''));
2395 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2396 // if (token == TokenNameEncapsedString1) {
2398 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2399 // exprSourceStart, scanner
2400 // .getCurrentTokenEndPosition());
2403 // if (token != TokenNameEncapsedString1) {
2404 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2405 // + scanner.toStringAction(token) + " )");
2408 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2409 // exprSourceStart, scanner
2410 // .getCurrentTokenEndPosition());
2414 // scanner.encapsedStringStack.pop();
2418 // //| '"' encaps_list '"'
2419 // case TokenNameEncapsedString2:
2420 // scanner.encapsedStringStack.push(new Character('"'));
2423 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2424 // if (token == TokenNameEncapsedString2) {
2426 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2427 // exprSourceStart, scanner
2428 // .getCurrentTokenEndPosition());
2431 // if (token != TokenNameEncapsedString2) {
2432 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2433 // scanner.toStringAction(token) + " )");
2436 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2437 // exprSourceStart, scanner
2438 // .getCurrentTokenEndPosition());
2442 // scanner.encapsedStringStack.pop();
2446 case TokenNameStringDoubleQuote:
2447 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2448 .getCurrentTokenEndPosition());
2451 case TokenNameStringSingleQuote:
2452 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2453 .getCurrentTokenEndPosition());
2456 case TokenNameIntegerLiteral:
2457 case TokenNameDoubleLiteral:
2458 case TokenNameStringInterpolated:
2461 case TokenNameCLASS_C:
2462 case TokenNameMETHOD_C:
2463 case TokenNameFUNC_C:
2466 case TokenNameHEREDOC:
2469 case TokenNamearray:
2470 // T_ARRAY '(' array_pair_list ')'
2472 if (token == TokenNameLPAREN) {
2474 if (token == TokenNameRPAREN) {
2479 if (token != TokenNameRPAREN) {
2480 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2484 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2488 // | T_LIST '(' assignment_list ')' '=' expr
2490 if (token == TokenNameLPAREN) {
2493 if (token != TokenNameRPAREN) {
2494 throwSyntaxError("')' expected after 'list' keyword.");
2497 if (token != TokenNameEQUAL) {
2498 throwSyntaxError("'=' expected after 'list' keyword.");
2503 throwSyntaxError("'(' expected after 'list' keyword.");
2507 // | T_NEW class_name_reference ctor_arguments
2509 Expression typeRef = class_name_reference();
2511 if (typeRef != null) {
2512 expression = typeRef;
2515 // | T_INC rw_variable
2516 // | T_DEC rw_variable
2517 case TokenNamePLUS_PLUS:
2518 case TokenNameMINUS_MINUS:
2522 // | variable '=' expr
2523 // | variable '=' '&' variable
2524 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2525 // | variable T_PLUS_EQUAL expr
2526 // | variable T_MINUS_EQUAL expr
2527 // | variable T_MUL_EQUAL expr
2528 // | variable T_DIV_EQUAL expr
2529 // | variable T_CONCAT_EQUAL expr
2530 // | variable T_MOD_EQUAL expr
2531 // | variable T_AND_EQUAL expr
2532 // | variable T_OR_EQUAL expr
2533 // | variable T_XOR_EQUAL expr
2534 // | variable T_SL_EQUAL expr
2535 // | variable T_SR_EQUAL expr
2536 // | rw_variable T_INC
2537 // | rw_variable T_DEC
2538 case TokenNameIdentifier:
2539 case TokenNameVariable:
2540 case TokenNameDOLLAR:
2541 Expression lhs = null;
2542 boolean rememberedVar = false;
2543 if (token == TokenNameIdentifier) {
2544 lhs = identifier(true, true);
2549 lhs = variable(true, true);
2553 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2554 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2555 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2556 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2557 && token != TokenNameLEFT_SHIFT_EQUAL) {
2558 FieldReference ref = (FieldReference) lhs;
2559 if (!containsVariableSet(ref.token)) {
2560 if (null==initHandler || initHandler.reportError()) {
2561 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart, ref.sourceEnd,
2562 referenceContext, compilationUnit.compilationResult);
2564 addVariableSet(ref.token);
2569 case TokenNameEQUAL:
2570 if (lhs != null && lhs instanceof FieldReference) {
2571 addVariableSet(((FieldReference) lhs).token);
2574 if (token == TokenNameAND) {
2576 if (token == TokenNamenew) {
2577 // | variable '=' '&' T_NEW class_name_reference
2580 SingleTypeReference classRef = class_name_reference();
2582 if (classRef != null) {
2583 if (lhs != null && lhs instanceof FieldReference) {
2585 // $var = & new Object();
2586 if (fMethodVariables != null) {
2587 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2588 lhsInfo.reference = classRef;
2589 lhsInfo.typeIdentifier = classRef.token;
2590 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2591 rememberedVar = true;
2596 Expression rhs = variable(false, false);
2597 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2600 if (fMethodVariables != null) {
2601 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2602 if (rhsInfo != null && rhsInfo.reference != null) {
2603 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2604 lhsInfo.reference = rhsInfo.reference;
2605 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2606 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2607 rememberedVar = true;
2613 Expression rhs = expr();
2614 if (lhs != null && lhs instanceof FieldReference) {
2615 if (rhs != null && rhs instanceof FieldReference) {
2618 if (fMethodVariables != null) {
2619 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2620 if (rhsInfo != null && rhsInfo.reference != null) {
2621 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2622 lhsInfo.reference = rhsInfo.reference;
2623 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2624 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2625 rememberedVar = true;
2628 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2630 // $var = new Object();
2631 if (fMethodVariables != null) {
2632 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2633 lhsInfo.reference = (SingleTypeReference) rhs;
2634 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2635 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2636 rememberedVar = true;
2641 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2642 if (fMethodVariables != null) {
2643 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2644 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2648 case TokenNamePLUS_EQUAL:
2649 case TokenNameMINUS_EQUAL:
2650 case TokenNameMULTIPLY_EQUAL:
2651 case TokenNameDIVIDE_EQUAL:
2652 case TokenNameDOT_EQUAL:
2653 case TokenNameREMAINDER_EQUAL:
2654 case TokenNameAND_EQUAL:
2655 case TokenNameOR_EQUAL:
2656 case TokenNameXOR_EQUAL:
2657 case TokenNameRIGHT_SHIFT_EQUAL:
2658 case TokenNameLEFT_SHIFT_EQUAL:
2659 if (lhs != null && lhs instanceof FieldReference) {
2660 addVariableSet(((FieldReference) lhs).token);
2665 case TokenNamePLUS_PLUS:
2666 case TokenNameMINUS_MINUS:
2670 if (!only_variable) {
2671 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2679 if (token != TokenNameINLINE_HTML) {
2680 if (token > TokenNameKEYWORD) {
2684 // System.out.println(scanner.getCurrentTokenStartPosition());
2685 // System.out.println(scanner.getCurrentTokenEndPosition());
2687 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2692 if (Scanner.TRACE) {
2693 System.out.println("TRACE: expr_without_variable() PART 2");
2695 // | expr T_BOOLEAN_OR expr
2696 // | expr T_BOOLEAN_AND expr
2697 // | expr T_LOGICAL_OR expr
2698 // | expr T_LOGICAL_AND expr
2699 // | expr T_LOGICAL_XOR expr
2711 // | expr T_IS_IDENTICAL expr
2712 // | expr T_IS_NOT_IDENTICAL expr
2713 // | expr T_IS_EQUAL expr
2714 // | expr T_IS_NOT_EQUAL expr
2716 // | expr T_IS_SMALLER_OR_EQUAL expr
2718 // | expr T_IS_GREATER_OR_EQUAL expr
2721 case TokenNameOR_OR:
2723 expression = new OR_OR_Expression(expression, expr(), token);
2725 case TokenNameAND_AND:
2727 expression = new AND_AND_Expression(expression, expr(), token);
2729 case TokenNameEQUAL_EQUAL:
2731 expression = new EqualExpression(expression, expr(), token);
2741 case TokenNameMINUS:
2742 case TokenNameMULTIPLY:
2743 case TokenNameDIVIDE:
2744 case TokenNameREMAINDER:
2745 case TokenNameLEFT_SHIFT:
2746 case TokenNameRIGHT_SHIFT:
2747 case TokenNameEQUAL_EQUAL_EQUAL:
2748 case TokenNameNOT_EQUAL_EQUAL:
2749 case TokenNameNOT_EQUAL:
2751 case TokenNameLESS_EQUAL:
2752 case TokenNameGREATER:
2753 case TokenNameGREATER_EQUAL:
2755 expression = new BinaryExpression(expression, expr(), token);
2757 // | expr T_INSTANCEOF class_name_reference
2758 // | expr '?' expr ':' expr
2759 case TokenNameinstanceof:
2761 TypeReference classRef = class_name_reference();
2762 if (classRef != null) {
2763 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2764 expression.sourceStart = exprSourceStart;
2765 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2768 case TokenNameQUESTION:
2770 Expression valueIfTrue = expr();
2771 if (token != TokenNameCOLON) {
2772 throwSyntaxError("':' expected in conditional expression.");
2775 Expression valueIfFalse = expr();
2777 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2783 } catch (SyntaxError e) {
2784 // try to find next token after expression with errors:
2785 if (token == TokenNameSEMICOLON) {
2789 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2797 private SingleTypeReference class_name_reference() {
2798 // class_name_reference:
2800 // | dynamic_class_name_reference
2801 SingleTypeReference ref = null;
2802 if (Scanner.TRACE) {
2803 System.out.println("TRACE: class_name_reference()");
2805 if (token == TokenNameIdentifier) {
2806 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2810 dynamic_class_name_reference();
2815 private void dynamic_class_name_reference() {
2816 // dynamic_class_name_reference:
2817 // base_variable T_OBJECT_OPERATOR object_property
2818 // dynamic_class_name_variable_properties
2820 if (Scanner.TRACE) {
2821 System.out.println("TRACE: dynamic_class_name_reference()");
2823 base_variable(true);
2824 if (token == TokenNameMINUS_GREATER) {
2827 dynamic_class_name_variable_properties();
2831 private void dynamic_class_name_variable_properties() {
2832 // dynamic_class_name_variable_properties:
2833 // dynamic_class_name_variable_properties
2834 // dynamic_class_name_variable_property
2836 if (Scanner.TRACE) {
2837 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2839 while (token == TokenNameMINUS_GREATER) {
2840 dynamic_class_name_variable_property();
2844 private void dynamic_class_name_variable_property() {
2845 // dynamic_class_name_variable_property:
2846 // T_OBJECT_OPERATOR object_property
2847 if (Scanner.TRACE) {
2848 System.out.println("TRACE: dynamic_class_name_variable_property()");
2850 if (token == TokenNameMINUS_GREATER) {
2856 private void ctor_arguments() {
2859 // | '(' function_call_parameter_list ')'
2860 if (token == TokenNameLPAREN) {
2862 if (token == TokenNameRPAREN) {
2866 non_empty_function_call_parameter_list();
2867 if (token != TokenNameRPAREN) {
2868 throwSyntaxError("')' expected in ctor_arguments.");
2874 private void assignment_list() {
2876 // assignment_list ',' assignment_list_element
2877 // | assignment_list_element
2879 assignment_list_element();
2880 if (token != TokenNameCOMMA) {
2887 private void assignment_list_element() {
2888 // assignment_list_element:
2890 // | T_LIST '(' assignment_list ')'
2892 if (token == TokenNameVariable) {
2893 variable(true, false);
2894 } else if (token == TokenNameDOLLAR) {
2895 variable(false, false);
2896 } else if (token == TokenNameIdentifier) {
2897 identifier(true, true);
2899 if (token == TokenNamelist) {
2901 if (token == TokenNameLPAREN) {
2904 if (token != TokenNameRPAREN) {
2905 throwSyntaxError("')' expected after 'list' keyword.");
2909 throwSyntaxError("'(' expected after 'list' keyword.");
2915 private void array_pair_list() {
2918 // | non_empty_array_pair_list possible_comma
2919 non_empty_array_pair_list();
2920 if (token == TokenNameCOMMA) {
2925 private void non_empty_array_pair_list() {
2926 // non_empty_array_pair_list:
2927 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2928 // | non_empty_array_pair_list ',' expr
2929 // | expr T_DOUBLE_ARROW expr
2931 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2932 // | non_empty_array_pair_list ',' '&' w_variable
2933 // | expr T_DOUBLE_ARROW '&' w_variable
2936 if (token == TokenNameAND) {
2938 variable(true, false);
2941 if (token == TokenNameAND) {
2943 variable(true, false);
2944 } else if (token == TokenNameEQUAL_GREATER) {
2946 if (token == TokenNameAND) {
2948 variable(true, false);
2954 if (token != TokenNameCOMMA) {
2958 if (token == TokenNameRPAREN) {
2964 // private void variableList() {
2967 // if (token == TokenNameCOMMA) {
2974 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2975 // variable_without_objects:
2976 // reference_variable
2977 // | simple_indirect_reference reference_variable
2978 if (Scanner.TRACE) {
2979 System.out.println("TRACE: variable_without_objects()");
2981 while (token == TokenNameDOLLAR) {
2984 return reference_variable(lefthandside, ignoreVar);
2987 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2989 // T_STRING '(' function_call_parameter_list ')'
2990 // | class_constant '(' function_call_parameter_list ')'
2991 // | static_member '(' function_call_parameter_list ')'
2992 // | variable_without_objects '(' function_call_parameter_list ')'
2993 char[] defineName = null;
2994 char[] ident = null;
2997 Expression ref = null;
2998 if (Scanner.TRACE) {
2999 System.out.println("TRACE: function_call()");
3001 if (token == TokenNameIdentifier) {
3002 ident = scanner.getCurrentIdentifierSource();
3004 startPos = scanner.getCurrentTokenStartPosition();
3005 endPos = scanner.getCurrentTokenEndPosition();
3008 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3012 if (token == TokenNameIdentifier) {
3017 variable_without_objects(true, false);
3022 ref = variable_without_objects(lefthandside, ignoreVar);
3024 if (token != TokenNameLPAREN) {
3025 if (defineName != null) {
3026 // does this identifier contain only uppercase characters?
3027 if (defineName.length == 3) {
3028 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3031 } else if (defineName.length == 4) {
3032 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3034 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3037 } else if (defineName.length == 5) {
3038 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3042 if (defineName != null) {
3043 for (int i = 0; i < defineName.length; i++) {
3044 if (Character.isLowerCase(defineName[i])) {
3045 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3053 if (token == TokenNameRPAREN) {
3057 non_empty_function_call_parameter_list();
3058 if (token != TokenNameRPAREN) {
3059 String functionName;
3060 if (ident == null) {
3061 functionName = new String(" ");
3063 functionName = new String(ident);
3065 throwSyntaxError("')' expected in function call (" + functionName + ").");
3072 private void non_empty_function_call_parameter_list() {
3073 this.non_empty_function_call_parameter_list(null);
3076 // private void function_call_parameter_list() {
3077 // function_call_parameter_list:
3078 // non_empty_function_call_parameter_list { $$ = $1; }
3081 private void non_empty_function_call_parameter_list(String functionName) {
3082 // non_empty_function_call_parameter_list:
3083 // expr_without_variable
3086 // | non_empty_function_call_parameter_list ',' expr_without_variable
3087 // | non_empty_function_call_parameter_list ',' variable
3088 // | non_empty_function_call_parameter_list ',' '&' w_variable
3089 if (Scanner.TRACE) {
3090 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3092 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3093 initHandler.setFunctionName(functionName);
3095 initHandler.incrementArgumentCount();
3096 if (token == TokenNameAND) {
3100 // if (token == TokenNameIdentifier || token ==
3101 // TokenNameVariable
3102 // || token == TokenNameDOLLAR) {
3105 expr_without_variable(true, initHandler);
3108 if (token != TokenNameCOMMA) {
3115 private void fully_qualified_class_name() {
3116 if (token == TokenNameIdentifier) {
3119 throwSyntaxError("Class name expected.");
3123 private void static_member() {
3125 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3126 // variable_without_objects
3127 if (Scanner.TRACE) {
3128 System.out.println("TRACE: static_member()");
3130 fully_qualified_class_name();
3131 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3132 throwSyntaxError("'::' expected after class name (static_member).");
3135 variable_without_objects(false, false);
3138 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3139 // base_variable_with_function_calls:
3142 if (Scanner.TRACE) {
3143 System.out.println("TRACE: base_variable_with_function_calls()");
3145 return function_call(lefthandside, ignoreVar);
3148 private Expression base_variable(boolean lefthandside) {
3150 // reference_variable
3151 // | simple_indirect_reference reference_variable
3153 Expression ref = null;
3154 if (Scanner.TRACE) {
3155 System.out.println("TRACE: base_variable()");
3157 if (token == TokenNameIdentifier) {
3160 while (token == TokenNameDOLLAR) {
3163 reference_variable(lefthandside, false);
3168 // private void simple_indirect_reference() {
3169 // // simple_indirect_reference:
3171 // //| simple_indirect_reference '$'
3173 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3174 // reference_variable:
3175 // reference_variable '[' dim_offset ']'
3176 // | reference_variable '{' expr '}'
3177 // | compound_variable
3178 Expression ref = null;
3179 if (Scanner.TRACE) {
3180 System.out.println("TRACE: reference_variable()");
3182 ref = compound_variable(lefthandside, ignoreVar);
3184 if (token == TokenNameLBRACE) {
3188 if (token != TokenNameRBRACE) {
3189 throwSyntaxError("'}' expected in reference variable.");
3192 } else if (token == TokenNameLBRACKET) {
3193 // To remove "ref = null;" here, is probably better than the patch
3194 // commented in #1368081 - axelcl
3196 if (token != TokenNameRBRACKET) {
3199 if (token != TokenNameRBRACKET) {
3200 throwSyntaxError("']' expected in reference variable.");
3211 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3212 // compound_variable:
3214 // | '$' '{' expr '}'
3215 if (Scanner.TRACE) {
3216 System.out.println("TRACE: compound_variable()");
3218 if (token == TokenNameVariable) {
3219 if (!lefthandside) {
3220 if (!containsVariableSet()) {
3221 // reportSyntaxError("The local variable " + new
3222 // String(scanner.getCurrentIdentifierSource())
3223 // + " may not have been initialized");
3224 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3225 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3226 compilationUnit.compilationResult);
3233 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3237 // because of simple_indirect_reference
3238 while (token == TokenNameDOLLAR) {
3241 if (token != TokenNameLBRACE) {
3242 reportSyntaxError("'{' expected after compound variable token '$'.");
3247 if (token != TokenNameRBRACE) {
3248 throwSyntaxError("'}' expected after compound variable token '$'.");
3253 } // private void dim_offset() { // // dim_offset: // // /* empty */
3258 private void object_property() {
3261 // | variable_without_objects
3262 if (Scanner.TRACE) {
3263 System.out.println("TRACE: object_property()");
3265 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3266 variable_without_objects(false, false);
3272 private void object_dim_list() {
3274 // object_dim_list '[' dim_offset ']'
3275 // | object_dim_list '{' expr '}'
3277 if (Scanner.TRACE) {
3278 System.out.println("TRACE: object_dim_list()");
3282 if (token == TokenNameLBRACE) {
3285 if (token != TokenNameRBRACE) {
3286 throwSyntaxError("'}' expected in object_dim_list.");
3289 } else if (token == TokenNameLBRACKET) {
3291 if (token == TokenNameRBRACKET) {
3296 if (token != TokenNameRBRACKET) {
3297 throwSyntaxError("']' expected in object_dim_list.");
3306 private void variable_name() {
3310 if (Scanner.TRACE) {
3311 System.out.println("TRACE: variable_name()");
3313 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3314 if (token > TokenNameKEYWORD) {
3315 // TODO show a warning "Keyword used as variable" ?
3319 if (token != TokenNameLBRACE) {
3320 throwSyntaxError("'{' expected in variable name.");
3324 if (token != TokenNameRBRACE) {
3325 throwSyntaxError("'}' expected in variable name.");
3331 private void r_variable() {
3332 variable(false, false);
3335 private void w_variable(boolean lefthandside) {
3336 variable(lefthandside, false);
3339 private void rw_variable() {
3340 variable(false, false);
3343 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3345 // base_variable_with_function_calls T_OBJECT_OPERATOR
3346 // object_property method_or_not variable_properties
3347 // | base_variable_with_function_calls
3348 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3349 if (token == TokenNameMINUS_GREATER) {
3354 variable_properties();
3359 private void variable_properties() {
3360 // variable_properties:
3361 // variable_properties variable_property
3363 while (token == TokenNameMINUS_GREATER) {
3364 variable_property();
3368 private void variable_property() {
3369 // variable_property:
3370 // T_OBJECT_OPERATOR object_property method_or_not
3371 if (Scanner.TRACE) {
3372 System.out.println("TRACE: variable_property()");
3374 if (token == TokenNameMINUS_GREATER) {
3379 throwSyntaxError("'->' expected in variable_property.");
3383 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3385 // base_variable_with_function_calls T_OBJECT_OPERATOR
3386 // object_property method_or_not variable_properties
3387 // | base_variable_with_function_calls
3389 // Expression ref = function_call(lefthandside, ignoreVar);
3392 // T_STRING '(' function_call_parameter_list ')'
3393 // | class_constant '(' function_call_parameter_list ')'
3394 // | static_member '(' function_call_parameter_list ')'
3395 // | variable_without_objects '(' function_call_parameter_list ')'
3396 char[] defineName = null;
3397 char[] ident = null;
3400 Expression ref = null;
3401 if (Scanner.TRACE) {
3402 System.out.println("TRACE: function_call()");
3404 if (token == TokenNameIdentifier) {
3405 ident = scanner.getCurrentIdentifierSource();
3407 startPos = scanner.getCurrentTokenStartPosition();
3408 endPos = scanner.getCurrentTokenEndPosition();
3411 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3412 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3413 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3414 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3415 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3416 + new String(ident) + "' (use 'define(...)' to define constants).";
3417 reportSyntaxError(error);
3421 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3425 if (token == TokenNameIdentifier) {
3430 variable_without_objects(true, false);
3435 ref = variable_without_objects(lefthandside, ignoreVar);
3437 if (token != TokenNameLPAREN) {
3438 if (defineName != null) {
3439 // does this identifier contain only uppercase characters?
3440 if (defineName.length == 3) {
3441 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3444 } else if (defineName.length == 4) {
3445 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3447 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3450 } else if (defineName.length == 5) {
3451 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3455 if (defineName != null) {
3456 for (int i = 0; i < defineName.length; i++) {
3457 if (Character.isLowerCase(defineName[i])) {
3458 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3464 // TODO is this ok ?
3466 // throwSyntaxError("'(' expected in function call.");
3470 if (token == TokenNameRPAREN) {
3474 String functionName;
3475 if (ident == null) {
3476 functionName = new String(" ");
3478 functionName = new String(ident);
3480 non_empty_function_call_parameter_list(functionName);
3481 if (token != TokenNameRPAREN) {
3482 throwSyntaxError("')' expected in function call (" + functionName + ").");
3487 if (token == TokenNameMINUS_GREATER) {
3492 variable_properties();
3497 private void method_or_not() {
3499 // '(' function_call_parameter_list ')'
3501 if (Scanner.TRACE) {
3502 System.out.println("TRACE: method_or_not()");
3504 if (token == TokenNameLPAREN) {
3506 if (token == TokenNameRPAREN) {
3510 non_empty_function_call_parameter_list();
3511 if (token != TokenNameRPAREN) {
3512 throwSyntaxError("')' expected in method_or_not.");
3518 private void exit_expr() {
3522 if (token != TokenNameLPAREN) {
3526 if (token == TokenNameRPAREN) {
3531 if (token != TokenNameRPAREN) {
3532 throwSyntaxError("')' expected after keyword 'exit'");
3537 // private void encaps_list() {
3538 // // encaps_list encaps_var
3539 // // | encaps_list T_STRING
3540 // // | encaps_list T_NUM_STRING
3541 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3542 // // | encaps_list T_CHARACTER
3543 // // | encaps_list T_BAD_CHARACTER
3544 // // | encaps_list '['
3545 // // | encaps_list ']'
3546 // // | encaps_list '{'
3547 // // | encaps_list '}'
3548 // // | encaps_list T_OBJECT_OPERATOR
3552 // case TokenNameSTRING:
3555 // case TokenNameLBRACE:
3556 // // scanner.encapsedStringStack.pop();
3559 // case TokenNameRBRACE:
3560 // // scanner.encapsedStringStack.pop();
3563 // case TokenNameLBRACKET:
3564 // // scanner.encapsedStringStack.pop();
3567 // case TokenNameRBRACKET:
3568 // // scanner.encapsedStringStack.pop();
3571 // case TokenNameMINUS_GREATER:
3572 // // scanner.encapsedStringStack.pop();
3575 // case TokenNameVariable:
3576 // case TokenNameDOLLAR_LBRACE:
3577 // case TokenNameLBRACE_DOLLAR:
3581 // char encapsedChar = ((Character)
3582 // scanner.encapsedStringStack.peek()).charValue();
3583 // if (encapsedChar == '$') {
3584 // scanner.encapsedStringStack.pop();
3585 // encapsedChar = ((Character)
3586 // scanner.encapsedStringStack.peek()).charValue();
3587 // switch (encapsedChar) {
3589 // if (token == TokenNameEncapsedString0) {
3592 // token = TokenNameSTRING;
3595 // if (token == TokenNameEncapsedString1) {
3598 // token = TokenNameSTRING;
3601 // if (token == TokenNameEncapsedString2) {
3604 // token = TokenNameSTRING;
3613 // private void encaps_var() {
3615 // // | T_VARIABLE '[' encaps_var_offset ']'
3616 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3617 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3618 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3619 // // | T_CURLY_OPEN variable '}'
3621 // case TokenNameVariable:
3623 // if (token == TokenNameLBRACKET) {
3625 // expr(); //encaps_var_offset();
3626 // if (token != TokenNameRBRACKET) {
3627 // throwSyntaxError("']' expected after variable.");
3629 // // scanner.encapsedStringStack.pop();
3632 // } else if (token == TokenNameMINUS_GREATER) {
3634 // if (token != TokenNameIdentifier) {
3635 // throwSyntaxError("Identifier expected after '->'.");
3637 // // scanner.encapsedStringStack.pop();
3641 // // // scanner.encapsedStringStack.pop();
3642 // // int tempToken = TokenNameSTRING;
3643 // // if (!scanner.encapsedStringStack.isEmpty()
3644 // // && (token == TokenNameEncapsedString0
3645 // // || token == TokenNameEncapsedString1
3646 // // || token == TokenNameEncapsedString2 || token ==
3647 // // TokenNameERROR)) {
3648 // // char encapsedChar = ((Character)
3649 // // scanner.encapsedStringStack.peek())
3651 // // switch (token) {
3652 // // case TokenNameEncapsedString0 :
3653 // // if (encapsedChar == '`') {
3654 // // tempToken = TokenNameEncapsedString0;
3657 // // case TokenNameEncapsedString1 :
3658 // // if (encapsedChar == '\'') {
3659 // // tempToken = TokenNameEncapsedString1;
3662 // // case TokenNameEncapsedString2 :
3663 // // if (encapsedChar == '"') {
3664 // // tempToken = TokenNameEncapsedString2;
3667 // // case TokenNameERROR :
3668 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3669 // // scanner.currentPosition--;
3670 // // getNextToken();
3675 // // token = tempToken;
3678 // case TokenNameDOLLAR_LBRACE:
3680 // if (token == TokenNameDOLLAR_LBRACE) {
3682 // } else if (token == TokenNameIdentifier) {
3684 // if (token == TokenNameLBRACKET) {
3686 // // if (token == TokenNameRBRACKET) {
3687 // // getNextToken();
3690 // if (token != TokenNameRBRACKET) {
3691 // throwSyntaxError("']' expected after '${'.");
3699 // if (token != TokenNameRBRACE) {
3700 // throwSyntaxError("'}' expected.");
3704 // case TokenNameLBRACE_DOLLAR:
3706 // if (token == TokenNameLBRACE_DOLLAR) {
3708 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3710 // if (token == TokenNameLBRACKET) {
3712 // // if (token == TokenNameRBRACKET) {
3713 // // getNextToken();
3716 // if (token != TokenNameRBRACKET) {
3717 // throwSyntaxError("']' expected.");
3721 // } else if (token == TokenNameMINUS_GREATER) {
3723 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3724 // throwSyntaxError("String or Variable token expected.");
3727 // if (token == TokenNameLBRACKET) {
3729 // // if (token == TokenNameRBRACKET) {
3730 // // getNextToken();
3733 // if (token != TokenNameRBRACKET) {
3734 // throwSyntaxError("']' expected after '${'.");
3740 // // if (token != TokenNameRBRACE) {
3741 // // throwSyntaxError("'}' expected after '{$'.");
3743 // // // scanner.encapsedStringStack.pop();
3744 // // getNextToken();
3747 // if (token != TokenNameRBRACE) {
3748 // throwSyntaxError("'}' expected.");
3750 // // scanner.encapsedStringStack.pop();
3757 // private void encaps_var_offset() {
3759 // // | T_NUM_STRING
3762 // case TokenNameSTRING:
3765 // case TokenNameIntegerLiteral:
3768 // case TokenNameVariable:
3771 // case TokenNameIdentifier:
3775 // throwSyntaxError("Variable or String token expected.");
3780 private void internal_functions_in_yacc() {
3783 // case TokenNameisset:
3784 // // T_ISSET '(' isset_variables ')'
3786 // if (token != TokenNameLPAREN) {
3787 // throwSyntaxError("'(' expected after keyword 'isset'");
3790 // isset_variables();
3791 // if (token != TokenNameRPAREN) {
3792 // throwSyntaxError("')' expected after keyword 'isset'");
3796 // case TokenNameempty:
3797 // // T_EMPTY '(' variable ')'
3799 // if (token != TokenNameLPAREN) {
3800 // throwSyntaxError("'(' expected after keyword 'empty'");
3804 // if (token != TokenNameRPAREN) {
3805 // throwSyntaxError("')' expected after keyword 'empty'");
3809 case TokenNameinclude:
3811 checkFileName(token);
3813 case TokenNameinclude_once:
3814 // T_INCLUDE_ONCE expr
3815 checkFileName(token);
3818 // T_EVAL '(' expr ')'
3820 if (token != TokenNameLPAREN) {
3821 throwSyntaxError("'(' expected after keyword 'eval'");
3825 if (token != TokenNameRPAREN) {
3826 throwSyntaxError("')' expected after keyword 'eval'");
3830 case TokenNamerequire:
3832 checkFileName(token);
3834 case TokenNamerequire_once:
3835 // T_REQUIRE_ONCE expr
3836 checkFileName(token);
3842 * Parse and check the include file name
3844 * @param includeToken
3846 private void checkFileName(int includeToken) {
3847 // <include-token> expr
3848 int start = scanner.getCurrentTokenStartPosition();
3849 boolean hasLPAREN = false;
3851 if (token == TokenNameLPAREN) {
3855 Expression expression = expr();
3857 if (token == TokenNameRPAREN) {
3860 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3863 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3865 if (scanner.compilationUnit != null) {
3866 IResource resource = scanner.compilationUnit.getResource();
3867 if (resource != null && resource instanceof IFile) {
3868 file = (IFile) resource;
3872 tokens = new char[1][];
3873 tokens[0] = currTokenSource;
3875 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3876 impt.declarationSourceEnd = impt.sourceEnd;
3877 impt.declarationEnd = impt.declarationSourceEnd;
3878 // endPosition is just before the ;
3879 impt.declarationSourceStart = start;
3880 includesList.add(impt);
3882 if (expression instanceof StringLiteral) {
3883 StringLiteral literal = (StringLiteral) expression;
3884 char[] includeName = literal.source();
3885 if (includeName.length == 0) {
3886 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3887 literal.sourceStart + 1);
3889 String includeNameString = new String(includeName);
3890 if (literal instanceof StringLiteralDQ) {
3891 if (includeNameString.indexOf('$') >= 0) {
3892 // assuming that the filename contains a variable => no filename check
3896 if (includeNameString.startsWith("http://")) {
3897 // assuming external include location
3901 // check the filename:
3902 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3903 // expression.toStringExpression());
3904 IProject project = file.getProject();
3905 if (project != null) {
3906 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3909 // SyntaxError: "File: << >> doesn't exist in project."
3910 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3911 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3912 compilationUnit.compilationResult);
3915 String filePath = path.toString();
3916 String ext = file.getRawLocation().getFileExtension();
3917 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3919 IFile f = PHPFileUtil.createFile(path, project);
3921 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3923 } catch (Exception e) {
3924 // the file is outside of the workspace
3932 private void isset_variables() {
3934 // | isset_variables ','
3935 if (token == TokenNameRPAREN) {
3936 throwSyntaxError("Variable expected after keyword 'isset'");
3939 variable(true, false);
3940 if (token == TokenNameCOMMA) {
3948 private boolean common_scalar() {
3952 // | T_CONSTANT_ENCAPSED_STRING
3959 case TokenNameIntegerLiteral:
3962 case TokenNameDoubleLiteral:
3965 case TokenNameStringDoubleQuote:
3968 case TokenNameStringSingleQuote:
3971 case TokenNameStringInterpolated:
3980 case TokenNameCLASS_C:
3983 case TokenNameMETHOD_C:
3986 case TokenNameFUNC_C:
3993 private void scalar() {
3996 // | T_STRING_VARNAME
3999 // | '"' encaps_list '"'
4000 // | '\'' encaps_list '\''
4001 // | T_START_HEREDOC encaps_list T_END_HEREDOC
4002 throwSyntaxError("Not yet implemented (scalar).");
4005 private void static_scalar() {
4006 // static_scalar: /* compile-time evaluated scalars */
4009 // | '+' static_scalar
4010 // | '-' static_scalar
4011 // | T_ARRAY '(' static_array_pair_list ')'
4012 // | static_class_constant
4013 if (common_scalar()) {
4017 case TokenNameIdentifier:
4019 // static_class_constant:
4020 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4021 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
4023 if (token == TokenNameIdentifier) {
4026 throwSyntaxError("Identifier expected after '::' operator.");
4030 case TokenNameEncapsedString0:
4032 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4033 while (scanner.currentCharacter != '`') {
4034 if (scanner.currentCharacter == '\\') {
4035 scanner.currentPosition++;
4037 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4040 } catch (IndexOutOfBoundsException e) {
4041 throwSyntaxError("'`' expected at end of static string.");
4044 // case TokenNameEncapsedString1:
4046 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4047 // while (scanner.currentCharacter != '\'') {
4048 // if (scanner.currentCharacter == '\\') {
4049 // scanner.currentPosition++;
4051 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4054 // } catch (IndexOutOfBoundsException e) {
4055 // throwSyntaxError("'\'' expected at end of static string.");
4058 // case TokenNameEncapsedString2:
4060 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4061 // while (scanner.currentCharacter != '"') {
4062 // if (scanner.currentCharacter == '\\') {
4063 // scanner.currentPosition++;
4065 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4068 // } catch (IndexOutOfBoundsException e) {
4069 // throwSyntaxError("'\"' expected at end of static string.");
4072 case TokenNameStringSingleQuote:
4075 case TokenNameStringDoubleQuote:
4082 case TokenNameMINUS:
4086 case TokenNamearray:
4088 if (token != TokenNameLPAREN) {
4089 throwSyntaxError("'(' expected after keyword 'array'");
4092 if (token == TokenNameRPAREN) {
4096 non_empty_static_array_pair_list();
4097 if (token != TokenNameRPAREN) {
4098 throwSyntaxError("')' or ',' expected after keyword 'array'");
4102 // case TokenNamenull :
4105 // case TokenNamefalse :
4108 // case TokenNametrue :
4112 throwSyntaxError("Static scalar/constant expected.");
4116 private void non_empty_static_array_pair_list() {
4117 // non_empty_static_array_pair_list:
4118 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4120 // | non_empty_static_array_pair_list ',' static_scalar
4121 // | static_scalar T_DOUBLE_ARROW static_scalar
4125 if (token == TokenNameEQUAL_GREATER) {
4129 if (token != TokenNameCOMMA) {
4133 if (token == TokenNameRPAREN) {
4139 // public void reportSyntaxError() { //int act, int currentKind, int
4140 // // stateStackTop) {
4141 // /* remember current scanner position */
4142 // int startPos = scanner.startPosition;
4143 // int currentPos = scanner.currentPosition;
4145 // this.checkAndReportBracketAnomalies(problemReporter());
4146 // /* reset scanner where it was */
4147 // scanner.startPosition = startPos;
4148 // scanner.currentPosition = currentPos;
4151 public static final int RoundBracket = 0;
4153 public static final int SquareBracket = 1;
4155 public static final int CurlyBracket = 2;
4157 public static final int BracketKinds = 3;
4159 protected int[] nestedMethod; // the ptr is nestedType
4161 protected int nestedType, dimensions;
4163 // variable set stack
4164 final static int VariableStackIncrement = 10;
4166 HashMap fTypeVariables = null;
4168 HashMap fMethodVariables = null;
4170 ArrayList fStackUnassigned = new ArrayList();
4173 final static int AstStackIncrement = 100;
4175 protected int astPtr;
4177 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4179 protected int astLengthPtr;
4181 protected int[] astLengthStack;
4183 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4185 public CompilationUnitDeclaration compilationUnit; /*
4186 * the result from parse()
4189 protected ReferenceContext referenceContext;
4191 protected ProblemReporter problemReporter;
4193 protected CompilerOptions options;
4195 private ArrayList includesList;
4197 // protected CompilationResult compilationResult;
4199 * Returns this parser's problem reporter initialized with its reference
4200 * context. Also it is assumed that a problem is going to be reported, so
4201 * initializes the compilation result's line positions.
4203 public ProblemReporter problemReporter() {
4204 if (scanner.recordLineSeparator) {
4205 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4207 problemReporter.referenceContext = referenceContext;
4208 return problemReporter;
4212 * Reconsider the entire source looking for inconsistencies in {} () []
4214 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4215 // problemReporter) {
4216 // scanner.wasAcr = false;
4217 // boolean anomaliesDetected = false;
4219 // char[] source = scanner.source;
4220 // int[] leftCount = { 0, 0, 0 };
4221 // int[] rightCount = { 0, 0, 0 };
4222 // int[] depths = { 0, 0, 0 };
4223 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4225 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4226 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4228 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4230 // scanner.currentPosition = scanner.initialPosition; //starting
4232 // // (first-zero-based
4234 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4239 // // ---------Consume white space and handles
4240 // // startPosition---------
4241 // boolean isWhiteSpace;
4243 // scanner.startPosition = scanner.currentPosition;
4244 // // if (((scanner.currentCharacter =
4245 // // source[scanner.currentPosition++]) == '\\') &&
4246 // // (source[scanner.currentPosition] == 'u')) {
4247 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4249 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4250 // (scanner.currentCharacter == '\n'))) {
4251 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4252 // // only record line positions we have not
4254 // scanner.pushLineSeparator();
4257 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4259 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4260 // // -------consume token until } is found---------
4261 // switch (scanner.currentCharacter) {
4263 // int index = leftCount[CurlyBracket]++;
4264 // if (index == leftPositions[CurlyBracket].length) {
4265 // System.arraycopy(leftPositions[CurlyBracket], 0,
4266 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4267 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4268 // new int[index * 2]), 0, index);
4270 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4271 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4275 // int index = rightCount[CurlyBracket]++;
4276 // if (index == rightPositions[CurlyBracket].length) {
4277 // System.arraycopy(rightPositions[CurlyBracket], 0,
4278 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4279 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4280 // new int[index * 2]), 0, index);
4282 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4283 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4287 // int index = leftCount[RoundBracket]++;
4288 // if (index == leftPositions[RoundBracket].length) {
4289 // System.arraycopy(leftPositions[RoundBracket], 0,
4290 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4291 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4292 // new int[index * 2]), 0, index);
4294 // leftPositions[RoundBracket][index] = scanner.startPosition;
4295 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4299 // int index = rightCount[RoundBracket]++;
4300 // if (index == rightPositions[RoundBracket].length) {
4301 // System.arraycopy(rightPositions[RoundBracket], 0,
4302 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4303 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4304 // new int[index * 2]), 0, index);
4306 // rightPositions[RoundBracket][index] = scanner.startPosition;
4307 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4311 // int index = leftCount[SquareBracket]++;
4312 // if (index == leftPositions[SquareBracket].length) {
4313 // System.arraycopy(leftPositions[SquareBracket], 0,
4314 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4315 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4316 // new int[index * 2]), 0, index);
4318 // leftPositions[SquareBracket][index] = scanner.startPosition;
4319 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4323 // int index = rightCount[SquareBracket]++;
4324 // if (index == rightPositions[SquareBracket].length) {
4325 // System.arraycopy(rightPositions[SquareBracket], 0,
4326 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4327 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4328 // = new int[index * 2]), 0, index);
4330 // rightPositions[SquareBracket][index] = scanner.startPosition;
4331 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4335 // if (scanner.getNextChar('\\')) {
4336 // scanner.scanEscapeCharacter();
4337 // } else { // consume next character
4338 // scanner.unicodeAsBackSlash = false;
4339 // // if (((scanner.currentCharacter =
4340 // // source[scanner.currentPosition++]) ==
4342 // // (source[scanner.currentPosition] ==
4344 // // scanner.getNextUnicodeChar();
4346 // if (scanner.withoutUnicodePtr != 0) {
4347 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4348 // scanner.currentCharacter;
4352 // scanner.getNextChar('\'');
4356 // // consume next character
4357 // scanner.unicodeAsBackSlash = false;
4358 // // if (((scanner.currentCharacter =
4359 // // source[scanner.currentPosition++]) == '\\') &&
4360 // // (source[scanner.currentPosition] == 'u')) {
4361 // // scanner.getNextUnicodeChar();
4363 // if (scanner.withoutUnicodePtr != 0) {
4364 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4365 // scanner.currentCharacter;
4368 // while (scanner.currentCharacter != '"') {
4369 // if (scanner.currentCharacter == '\r') {
4370 // if (source[scanner.currentPosition] == '\n')
4371 // scanner.currentPosition++;
4372 // break; // the string cannot go further that
4375 // if (scanner.currentCharacter == '\n') {
4376 // break; // the string cannot go further that
4379 // if (scanner.currentCharacter == '\\') {
4380 // scanner.scanEscapeCharacter();
4382 // // consume next character
4383 // scanner.unicodeAsBackSlash = false;
4384 // // if (((scanner.currentCharacter =
4385 // // source[scanner.currentPosition++]) == '\\')
4386 // // && (source[scanner.currentPosition] == 'u'))
4388 // // scanner.getNextUnicodeChar();
4390 // if (scanner.withoutUnicodePtr != 0) {
4391 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4392 // scanner.currentCharacter;
4399 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4401 // //get the next char
4402 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4404 // && (source[scanner.currentPosition] == 'u')) {
4405 // //-------------unicode traitement
4407 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4408 // scanner.currentPosition++;
4409 // while (source[scanner.currentPosition] == 'u') {
4410 // scanner.currentPosition++;
4412 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4414 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4416 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4418 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4419 // || c4 < 0) { //error
4423 // scanner.currentCharacter = 'A';
4424 // } //something different from \n and \r
4426 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4429 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4431 // //get the next char
4432 // scanner.startPosition = scanner.currentPosition;
4433 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4435 // && (source[scanner.currentPosition] == 'u')) {
4436 // //-------------unicode traitement
4438 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4439 // scanner.currentPosition++;
4440 // while (source[scanner.currentPosition] == 'u') {
4441 // scanner.currentPosition++;
4443 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4445 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4447 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4449 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4450 // || c4 < 0) { //error
4454 // scanner.currentCharacter = 'A';
4455 // } //something different from \n
4458 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4462 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4463 // (scanner.currentCharacter == '\n'))) {
4464 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4465 // // only record line positions we
4466 // // have not recorded yet
4467 // scanner.pushLineSeparator();
4468 // if (this.scanner.taskTags != null) {
4469 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4471 // .getCurrentTokenEndPosition());
4477 // if (test > 0) { //traditional and annotation
4479 // boolean star = false;
4480 // // consume next character
4481 // scanner.unicodeAsBackSlash = false;
4482 // // if (((scanner.currentCharacter =
4483 // // source[scanner.currentPosition++]) ==
4485 // // (source[scanner.currentPosition] ==
4487 // // scanner.getNextUnicodeChar();
4489 // if (scanner.withoutUnicodePtr != 0) {
4490 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4491 // scanner.currentCharacter;
4494 // if (scanner.currentCharacter == '*') {
4497 // //get the next char
4498 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4500 // && (source[scanner.currentPosition] == 'u')) {
4501 // //-------------unicode traitement
4503 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4504 // scanner.currentPosition++;
4505 // while (source[scanner.currentPosition] == 'u') {
4506 // scanner.currentPosition++;
4508 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4510 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4512 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4514 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4515 // || c4 < 0) { //error
4519 // scanner.currentCharacter = 'A';
4520 // } //something different from * and /
4522 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4525 // //loop until end of comment */
4526 // while ((scanner.currentCharacter != '/') || (!star)) {
4527 // star = scanner.currentCharacter == '*';
4529 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4531 // && (source[scanner.currentPosition] == 'u')) {
4532 // //-------------unicode traitement
4534 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4535 // scanner.currentPosition++;
4536 // while (source[scanner.currentPosition] == 'u') {
4537 // scanner.currentPosition++;
4539 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4541 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4543 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4545 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4546 // || c4 < 0) { //error
4550 // scanner.currentCharacter = 'A';
4551 // } //something different from * and
4554 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4558 // if (this.scanner.taskTags != null) {
4559 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4560 // this.scanner.getCurrentTokenEndPosition());
4567 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4568 // scanner.scanIdentifierOrKeyword(false);
4571 // if (Character.isDigit(scanner.currentCharacter)) {
4572 // scanner.scanNumber(false);
4576 // //-----------------end switch while
4577 // // try--------------------
4578 // } catch (IndexOutOfBoundsException e) {
4579 // break; // read until EOF
4580 // } catch (InvalidInputException e) {
4581 // return false; // no clue
4584 // if (scanner.recordLineSeparator) {
4585 // compilationUnit.compilationResult.lineSeparatorPositions =
4586 // scanner.getLineEnds();
4588 // // check placement anomalies against other kinds of brackets
4589 // for (int kind = 0; kind < BracketKinds; kind++) {
4590 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4591 // int start = leftPositions[kind][leftIndex]; // deepest
4593 // // find matching closing bracket
4594 // int depth = leftDepths[kind][leftIndex];
4596 // for (int i = 0; i < rightCount[kind]; i++) {
4597 // int pos = rightPositions[kind][i];
4598 // // want matching bracket further in source with same
4600 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4605 // if (end < 0) { // did not find a good closing match
4606 // problemReporter.unmatchedBracket(start, referenceContext,
4607 // compilationUnit.compilationResult);
4610 // // check if even number of opening/closing other brackets
4611 // // in between this pair of brackets
4613 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4615 // for (int i = 0; i < leftCount[otherKind]; i++) {
4616 // int pos = leftPositions[otherKind][i];
4617 // if ((pos > start) && (pos < end))
4620 // for (int i = 0; i < rightCount[otherKind]; i++) {
4621 // int pos = rightPositions[otherKind][i];
4622 // if ((pos > start) && (pos < end))
4625 // if (balance != 0) {
4626 // problemReporter.unmatchedBracket(start, referenceContext,
4627 // compilationUnit.compilationResult); //bracket
4633 // // too many opening brackets ?
4634 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4635 // anomaliesDetected = true;
4636 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4637 // 1], referenceContext,
4638 // compilationUnit.compilationResult);
4640 // // too many closing brackets ?
4641 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4642 // anomaliesDetected = true;
4643 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4644 // compilationUnit.compilationResult);
4646 // if (anomaliesDetected)
4649 // return anomaliesDetected;
4650 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4651 // return anomaliesDetected;
4652 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4653 // return anomaliesDetected;
4656 protected void pushOnAstLengthStack(int pos) {
4658 astLengthStack[++astLengthPtr] = pos;
4659 } catch (IndexOutOfBoundsException e) {
4660 int oldStackLength = astLengthStack.length;
4661 int[] oldPos = astLengthStack;
4662 astLengthStack = new int[oldStackLength + StackIncrement];
4663 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4664 astLengthStack[astLengthPtr] = pos;
4668 protected void pushOnAstStack(ASTNode node) {
4670 * add a new obj on top of the ast stack
4673 astStack[++astPtr] = node;
4674 } catch (IndexOutOfBoundsException e) {
4675 int oldStackLength = astStack.length;
4676 ASTNode[] oldStack = astStack;
4677 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4678 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4679 astPtr = oldStackLength;
4680 astStack[astPtr] = node;
4683 astLengthStack[++astLengthPtr] = 1;
4684 } catch (IndexOutOfBoundsException e) {
4685 int oldStackLength = astLengthStack.length;
4686 int[] oldPos = astLengthStack;
4687 astLengthStack = new int[oldStackLength + AstStackIncrement];
4688 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4689 astLengthStack[astLengthPtr] = 1;
4693 protected void resetModifiers() {
4694 this.modifiers = AccDefault;
4695 this.modifiersSourceStart = -1; // <-- see comment into
4696 // modifiersFlag(int)
4697 this.scanner.commentPtr = -1;
4700 protected void consumePackageDeclarationName(IFile file) {
4701 // create a package name similar to java package names
4702 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4703 String filePath = file.getRawLocation().toString();
4704 String ext = file.getRawLocation().getFileExtension();
4705 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4706 ImportReference impt;
4708 if (filePath.startsWith(projectPath)) {
4709 tokens = CharOperation
4710 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4712 String name = file.getName();
4713 tokens = new char[1][];
4714 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4717 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4719 impt.declarationSourceStart = 0;
4720 impt.declarationSourceEnd = 0;
4721 impt.declarationEnd = 0;
4722 // endPosition is just before the ;
4726 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4727 "$_SESSION", "$_SERVER" };
4732 private void pushFunctionVariableSet() {
4733 HashSet set = new HashSet();
4734 if (fStackUnassigned.isEmpty()) {
4735 for (int i = 0; i < GLOBALS.length; i++) {
4736 set.add(GLOBALS[i]);
4739 fStackUnassigned.add(set);
4742 private void pushIfVariableSet() {
4743 if (!fStackUnassigned.isEmpty()) {
4744 HashSet set = new HashSet();
4745 fStackUnassigned.add(set);
4749 private HashSet removeIfVariableSet() {
4750 if (!fStackUnassigned.isEmpty()) {
4751 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4757 * Returns the <i>set of assigned variables </i> returns null if no Set is
4758 * defined at the current scanner position
4760 private HashSet peekVariableSet() {
4761 if (!fStackUnassigned.isEmpty()) {
4762 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4768 * add the current identifier source to the <i>set of assigned variables </i>
4772 private void addVariableSet(HashSet set) {
4774 set.add(new String(scanner.getCurrentTokenSource()));
4779 * add the current identifier source to the <i>set of assigned variables </i>
4782 private void addVariableSet() {
4783 HashSet set = peekVariableSet();
4785 set.add(new String(scanner.getCurrentTokenSource()));
4790 * add the current identifier source to the <i>set of assigned variables </i>
4793 private void addVariableSet(char[] token) {
4794 HashSet set = peekVariableSet();
4796 set.add(new String(token));
4801 * check if the current identifier source is in the <i>set of assigned
4802 * variables </i> Returns true, if no set is defined for the current scanner
4806 private boolean containsVariableSet() {
4807 return containsVariableSet(scanner.getCurrentTokenSource());
4810 private boolean containsVariableSet(char[] token) {
4812 if (!fStackUnassigned.isEmpty()) {
4814 String str = new String(token);
4815 for (int i = 0; i < fStackUnassigned.size(); i++) {
4816 set = (HashSet) fStackUnassigned.get(i);
4817 if (set.contains(str)) {