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) {
1282 private void implements_list(TypeDeclaration typeDecl) {
1284 // | T_IMPLEMENTS interface_list
1285 if (token == TokenNameimplements) {
1291 private void interface_list() {
1293 // fully_qualified_class_name
1294 // | interface_list ',' fully_qualified_class_name
1296 if (token == TokenNameIdentifier) {
1299 throwSyntaxError("Interface name expected after keyword 'implements'.");
1301 if (token != TokenNameCOMMA) {
1308 // private void classBody(TypeDeclaration typeDecl) {
1309 // //'{' [class-element-list] '}'
1310 // if (token == TokenNameLBRACE) {
1312 // if (token != TokenNameRBRACE) {
1313 // class_statement_list();
1315 // if (token == TokenNameRBRACE) {
1316 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1319 // throwSyntaxError("'}' expected at end of class body.");
1322 // throwSyntaxError("'{' expected at start of class body.");
1325 private void class_statement_list(ArrayList list) {
1328 class_statement(list);
1329 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1330 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1331 || token == TokenNameconst) {
1334 if (token == TokenNameRBRACE) {
1337 throwSyntaxError("'}' at end of class statement.");
1338 } catch (SyntaxError sytaxErr1) {
1339 boolean tokenize = scanner.tokenizeStrings;
1341 scanner.tokenizeStrings = true;
1344 // if an error occured,
1345 // try to find keywords
1346 // to parse the rest of the string
1347 while (token != TokenNameEOF) {
1348 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1349 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1350 || token == TokenNameconst) {
1353 // System.out.println(scanner.toStringAction(token));
1356 if (token == TokenNameEOF) {
1360 scanner.tokenizeStrings = tokenize;
1366 private void class_statement(ArrayList list) {
1368 // variable_modifiers class_variable_declaration ';'
1369 // | class_constant_declaration ';'
1370 // | method_modifiers T_FUNCTION is_reference T_STRING
1371 // '(' parameter_list ')' method_body
1372 initializeModifiers();
1373 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1375 if (token == TokenNamevar) {
1376 checkAndSetModifiers(AccPublic);
1377 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1378 referenceContext, compilationUnit.compilationResult);
1380 class_variable_declaration(declarationSourceStart, list);
1381 } else if (token == TokenNameconst) {
1382 checkAndSetModifiers(AccFinal | AccPublic);
1383 class_constant_declaration(declarationSourceStart, list);
1384 if (token != TokenNameSEMICOLON) {
1385 throwSyntaxError("';' expected after class const declaration.");
1389 boolean hasModifiers = member_modifiers();
1390 if (token == TokenNamefunction) {
1391 if (!hasModifiers) {
1392 checkAndSetModifiers(AccPublic);
1394 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1395 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1396 methodDecl.modifiers = this.modifiers;
1397 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1400 functionDefinition(methodDecl);
1402 int sourceEnd = methodDecl.sourceEnd;
1403 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1404 sourceEnd = methodDecl.declarationSourceStart + 1;
1406 methodDecl.declarationSourceEnd = sourceEnd;
1407 methodDecl.sourceEnd = sourceEnd;
1410 if (!hasModifiers) {
1411 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1413 class_variable_declaration(declarationSourceStart, list);
1418 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1419 // class_constant_declaration ',' T_STRING '=' static_scalar
1420 // | T_CONST T_STRING '=' static_scalar
1421 if (token != TokenNameconst) {
1422 throwSyntaxError("'const' keyword expected in class declaration.");
1427 if (token != TokenNameIdentifier) {
1428 throwSyntaxError("Identifier expected in class const declaration.");
1430 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1431 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1432 fieldDeclaration.modifiers = this.modifiers;
1433 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1434 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1435 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1436 // fieldDeclaration.type
1437 list.add(fieldDeclaration);
1439 if (token != TokenNameEQUAL) {
1440 throwSyntaxError("'=' expected in class const declaration.");
1444 if (token != TokenNameCOMMA) {
1445 break; // while(true)-loop
1451 // private void variable_modifiers() {
1452 // // variable_modifiers:
1453 // // non_empty_member_modifiers
1455 // initializeModifiers();
1456 // if (token == TokenNamevar) {
1457 // checkAndSetModifiers(AccPublic);
1458 // reportSyntaxError(
1459 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1461 // modifier for field declarations.",
1462 // scanner.getCurrentTokenStartPosition(), scanner
1463 // .getCurrentTokenEndPosition());
1466 // if (!member_modifiers()) {
1467 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1468 // field declarations.");
1472 // private void method_modifiers() {
1473 // //method_modifiers:
1475 // //| non_empty_member_modifiers
1476 // initializeModifiers();
1477 // if (!member_modifiers()) {
1478 // checkAndSetModifiers(AccPublic);
1481 private boolean member_modifiers() {
1488 boolean foundToken = false;
1490 if (token == TokenNamepublic) {
1491 checkAndSetModifiers(AccPublic);
1494 } else if (token == TokenNameprotected) {
1495 checkAndSetModifiers(AccProtected);
1498 } else if (token == TokenNameprivate) {
1499 checkAndSetModifiers(AccPrivate);
1502 } else if (token == TokenNamestatic) {
1503 checkAndSetModifiers(AccStatic);
1506 } else if (token == TokenNameabstract) {
1507 checkAndSetModifiers(AccAbstract);
1510 } else if (token == TokenNamefinal) {
1511 checkAndSetModifiers(AccFinal);
1521 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1522 // class_variable_declaration:
1523 // class_variable_declaration ',' T_VARIABLE
1524 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1526 // | T_VARIABLE '=' static_scalar
1527 char[] classVariable;
1529 if (token == TokenNameVariable) {
1530 classVariable = scanner.getCurrentIdentifierSource();
1531 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1533 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1534 .getCurrentTokenEndPosition());
1535 fieldDeclaration.modifiers = this.modifiers;
1536 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1537 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1538 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1539 list.add(fieldDeclaration);
1540 if (fTypeVariables != null) {
1541 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1542 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1545 if (token == TokenNameEQUAL) {
1550 // if (token == TokenNamethis) {
1551 // throwSyntaxError("'$this' not allowed after keyword 'public'
1552 // 'protected' 'private' 'var'.");
1554 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1556 if (token != TokenNameCOMMA) {
1561 if (token != TokenNameSEMICOLON) {
1562 throwSyntaxError("';' expected after field declaration.");
1567 private void functionDefinition(MethodDeclaration methodDecl) {
1568 boolean isAbstract = false;
1570 if (compilationUnit != null) {
1571 compilationUnit.types.add(methodDecl);
1574 ASTNode node = astStack[astPtr];
1575 if (node instanceof TypeDeclaration) {
1576 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1577 if (typeDecl.methods == null) {
1578 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1580 AbstractMethodDeclaration[] newMethods;
1581 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1582 typeDecl.methods.length);
1583 newMethods[typeDecl.methods.length] = methodDecl;
1584 typeDecl.methods = newMethods;
1586 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1588 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1594 pushFunctionVariableSet();
1595 functionDeclarator(methodDecl);
1596 if (token == TokenNameSEMICOLON) {
1598 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1599 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1604 functionBody(methodDecl);
1606 if (!fStackUnassigned.isEmpty()) {
1607 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1612 private void functionDeclarator(MethodDeclaration methodDecl) {
1613 // identifier '(' [parameter-list] ')'
1614 if (token == TokenNameAND) {
1617 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1618 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1619 if (Scanner.isIdentifierOrKeyword(token)) {
1620 methodDecl.selector = scanner.getCurrentIdentifierSource();
1621 if (token > TokenNameKEYWORD) {
1622 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1623 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1626 if (token == TokenNameLPAREN) {
1629 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1630 throwSyntaxError("'(' expected in function declaration.");
1632 if (token != TokenNameRPAREN) {
1633 parameter_list(methodDecl);
1635 if (token != TokenNameRPAREN) {
1636 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1637 throwSyntaxError("')' expected in function declaration.");
1639 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1643 methodDecl.selector = "<undefined>".toCharArray();
1644 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1645 throwSyntaxError("Function name expected after keyword 'function'.");
1650 private void parameter_list(MethodDeclaration methodDecl) {
1651 // non_empty_parameter_list
1653 non_empty_parameter_list(methodDecl, true);
1656 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1657 // optional_class_type T_VARIABLE
1658 // | optional_class_type '&' T_VARIABLE
1659 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1660 // | optional_class_type T_VARIABLE '=' static_scalar
1661 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1662 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1663 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1665 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1667 char[] typeIdentifier = null;
1668 if (token == TokenNameIdentifier || token == TokenNamearray || token == TokenNameVariable || token == TokenNameAND) {
1669 HashSet set = peekVariableSet();
1671 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature req. #1254275
1672 typeIdentifier = scanner.getCurrentIdentifierSource();
1675 if (token == TokenNameAND) {
1678 if (token == TokenNameVariable) {
1679 if (fMethodVariables != null) {
1681 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1682 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1684 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1686 info.typeIdentifier = typeIdentifier;
1687 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1689 addVariableSet(set);
1691 if (token == TokenNameEQUAL) {
1696 throwSyntaxError("Variable expected in parameter list.");
1698 if (token != TokenNameCOMMA) {
1705 if (!empty_allowed) {
1706 throwSyntaxError("Identifier expected in parameter list.");
1710 private void optional_class_type() {
1715 // private void parameterDeclaration() {
1717 // //variable-reference
1718 // if (token == TokenNameAND) {
1720 // if (isVariable()) {
1723 // throwSyntaxError("Variable expected after reference operator '&'.");
1726 // //variable '=' constant
1727 // if (token == TokenNameVariable) {
1729 // if (token == TokenNameEQUAL) {
1735 // // if (token == TokenNamethis) {
1736 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1737 // // declaration.");
1741 private void labeledStatementList() {
1742 if (token != TokenNamecase && token != TokenNamedefault) {
1743 throwSyntaxError("'case' or 'default' expected.");
1746 if (token == TokenNamecase) {
1748 expr(); // constant();
1749 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1751 if (token == TokenNameRBRACE) {
1752 // empty case; assumes that the '}' token belongs to the wrapping
1753 // switch statement - #1371992
1756 if (token == TokenNamecase || token == TokenNamedefault) {
1757 // empty case statement ?
1762 // else if (token == TokenNameSEMICOLON) {
1764 // "':' expected after 'case' keyword (Found token: " +
1765 // scanner.toStringAction(token) + ")",
1766 // scanner.getCurrentTokenStartPosition(),
1767 // scanner.getCurrentTokenEndPosition(),
1770 // if (token == TokenNamecase) { // empty case statement ?
1776 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1778 } else { // TokenNamedefault
1780 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1782 if (token == TokenNameRBRACE) {
1783 // empty default case; ; assumes that the '}' token belongs to the
1784 // wrapping switch statement - #1371992
1787 if (token != TokenNamecase) {
1791 throwSyntaxError("':' character expected after 'default'.");
1794 } while (token == TokenNamecase || token == TokenNamedefault);
1797 private void ifStatementColon(IfStatement iState) {
1798 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1799 // new_else_single T_ENDIF ';'
1800 HashSet assignedVariableSet = null;
1802 Block b = inner_statement_list();
1803 iState.thenStatement = b;
1804 checkUnreachable(iState, b);
1806 assignedVariableSet = removeIfVariableSet();
1808 if (token == TokenNameelseif) {
1810 pushIfVariableSet();
1811 new_elseif_list(iState);
1813 HashSet set = removeIfVariableSet();
1814 if (assignedVariableSet != null && set != null) {
1815 assignedVariableSet.addAll(set);
1820 pushIfVariableSet();
1821 new_else_single(iState);
1823 HashSet set = removeIfVariableSet();
1824 if (assignedVariableSet != null) {
1825 HashSet topSet = peekVariableSet();
1826 if (topSet != null) {
1830 topSet.addAll(assignedVariableSet);
1834 if (token != TokenNameendif) {
1835 throwSyntaxError("'endif' expected.");
1838 if (token != TokenNameSEMICOLON) {
1839 reportSyntaxError("';' expected after if-statement.");
1840 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1842 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1847 private void ifStatement(IfStatement iState) {
1848 // T_IF '(' expr ')' statement elseif_list else_single
1849 HashSet assignedVariableSet = null;
1851 pushIfVariableSet();
1852 Statement s = statement();
1853 iState.thenStatement = s;
1854 checkUnreachable(iState, s);
1856 assignedVariableSet = removeIfVariableSet();
1859 if (token == TokenNameelseif) {
1861 pushIfVariableSet();
1862 elseif_list(iState);
1864 HashSet set = removeIfVariableSet();
1865 if (assignedVariableSet != null && set != null) {
1866 assignedVariableSet.addAll(set);
1871 pushIfVariableSet();
1872 else_single(iState);
1874 HashSet set = removeIfVariableSet();
1875 if (assignedVariableSet != null) {
1876 HashSet topSet = peekVariableSet();
1877 if (topSet != null) {
1881 topSet.addAll(assignedVariableSet);
1887 private void elseif_list(IfStatement iState) {
1889 // | elseif_list T_ELSEIF '(' expr ')' statement
1890 ArrayList conditionList = new ArrayList();
1891 ArrayList statementList = new ArrayList();
1894 while (token == TokenNameelseif) {
1896 if (token == TokenNameLPAREN) {
1899 throwSyntaxError("'(' expected after 'elseif' keyword.");
1902 conditionList.add(e);
1903 if (token == TokenNameRPAREN) {
1906 throwSyntaxError("')' expected after 'elseif' condition.");
1909 statementList.add(s);
1910 checkUnreachable(iState, s);
1912 iState.elseifConditions = new Expression[conditionList.size()];
1913 iState.elseifStatements = new Statement[statementList.size()];
1914 conditionList.toArray(iState.elseifConditions);
1915 statementList.toArray(iState.elseifStatements);
1918 private void new_elseif_list(IfStatement iState) {
1920 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1921 ArrayList conditionList = new ArrayList();
1922 ArrayList statementList = new ArrayList();
1925 while (token == TokenNameelseif) {
1927 if (token == TokenNameLPAREN) {
1930 throwSyntaxError("'(' expected after 'elseif' keyword.");
1933 conditionList.add(e);
1934 if (token == TokenNameRPAREN) {
1937 throwSyntaxError("')' expected after 'elseif' condition.");
1939 if (token == TokenNameCOLON) {
1942 throwSyntaxError("':' expected after 'elseif' keyword.");
1944 b = inner_statement_list();
1945 statementList.add(b);
1946 checkUnreachable(iState, b);
1948 iState.elseifConditions = new Expression[conditionList.size()];
1949 iState.elseifStatements = new Statement[statementList.size()];
1950 conditionList.toArray(iState.elseifConditions);
1951 statementList.toArray(iState.elseifStatements);
1954 private void else_single(IfStatement iState) {
1957 if (token == TokenNameelse) {
1959 Statement s = statement();
1960 iState.elseStatement = s;
1961 checkUnreachable(iState, s);
1963 iState.checkUnreachable = false;
1965 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1968 private void new_else_single(IfStatement iState) {
1970 // | T_ELSE ':' inner_statement_list
1971 if (token == TokenNameelse) {
1973 if (token == TokenNameCOLON) {
1976 throwSyntaxError("':' expected after 'else' keyword.");
1978 Block b = inner_statement_list();
1979 iState.elseStatement = b;
1980 checkUnreachable(iState, b);
1982 iState.checkUnreachable = false;
1986 private Block inner_statement_list() {
1987 // inner_statement_list inner_statement
1989 return statementList();
1996 private void checkUnreachable(IfStatement iState, Statement s) {
1997 if (s instanceof Block) {
1998 Block b = (Block) s;
1999 if (b.statements == null || b.statements.length == 0) {
2000 iState.checkUnreachable = false;
2002 int off = b.statements.length - 1;
2003 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2004 && !(b.statements[off] instanceof BreakStatement)) {
2005 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2006 iState.checkUnreachable = false;
2011 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2012 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2013 iState.checkUnreachable = false;
2019 // private void elseifStatementList() {
2021 // elseifStatement();
2023 // case TokenNameelse:
2025 // if (token == TokenNameCOLON) {
2027 // if (token != TokenNameendif) {
2032 // if (token == TokenNameif) { //'else if'
2035 // throwSyntaxError("':' expected after 'else'.");
2039 // case TokenNameelseif:
2048 // private void elseifStatement() {
2049 // if (token == TokenNameLPAREN) {
2052 // if (token != TokenNameRPAREN) {
2053 // throwSyntaxError("')' expected in else-if-statement.");
2056 // if (token != TokenNameCOLON) {
2057 // throwSyntaxError("':' expected in else-if-statement.");
2060 // if (token != TokenNameendif) {
2066 private void switchStatement() {
2067 if (token == TokenNameCOLON) {
2068 // ':' [labeled-statement-list] 'endswitch' ';'
2070 labeledStatementList();
2071 if (token != TokenNameendswitch) {
2072 throwSyntaxError("'endswitch' expected.");
2075 if (token != TokenNameSEMICOLON) {
2076 throwSyntaxError("';' expected after switch-statement.");
2080 // '{' [labeled-statement-list] '}'
2081 if (token != TokenNameLBRACE) {
2082 throwSyntaxError("'{' expected in switch statement.");
2085 if (token != TokenNameRBRACE) {
2086 labeledStatementList();
2088 if (token != TokenNameRBRACE) {
2089 throwSyntaxError("'}' expected in switch statement.");
2095 private void forStatement() {
2096 if (token == TokenNameCOLON) {
2099 if (token != TokenNameendfor) {
2100 throwSyntaxError("'endfor' expected.");
2103 if (token != TokenNameSEMICOLON) {
2104 throwSyntaxError("';' expected after for-statement.");
2112 private void whileStatement() {
2113 // ':' statement-list 'endwhile' ';'
2114 if (token == TokenNameCOLON) {
2117 if (token != TokenNameendwhile) {
2118 throwSyntaxError("'endwhile' expected.");
2121 if (token != TokenNameSEMICOLON) {
2122 throwSyntaxError("';' expected after while-statement.");
2130 private void foreachStatement() {
2131 if (token == TokenNameCOLON) {
2134 if (token != TokenNameendforeach) {
2135 throwSyntaxError("'endforeach' expected.");
2138 if (token != TokenNameSEMICOLON) {
2139 throwSyntaxError("';' expected after foreach-statement.");
2147 // private void exitStatus() {
2148 // if (token == TokenNameLPAREN) {
2151 // throwSyntaxError("'(' expected in 'exit-status'.");
2153 // if (token != TokenNameRPAREN) {
2156 // if (token == TokenNameRPAREN) {
2159 // throwSyntaxError("')' expected after 'exit-status'.");
2162 private void expressionList() {
2165 if (token == TokenNameCOMMA) {
2173 private Expression expr() {
2175 // | expr_without_variable
2176 // if (token!=TokenNameEOF) {
2177 if (Scanner.TRACE) {
2178 System.out.println("TRACE: expr()");
2180 return expr_without_variable(true,null);
2184 private Expression expr_without_variable(boolean only_variable, UninitializedVariableHandler initHandler) {
2185 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2186 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2187 Expression expression = new Expression();
2188 expression.sourceStart = exprSourceStart;
2189 // default, may be overwritten
2190 expression.sourceEnd = exprSourceEnd;
2192 // internal_functions_in_yacc
2201 // | T_INC rw_variable
2202 // | T_DEC rw_variable
2203 // | T_INT_CAST expr
2204 // | T_DOUBLE_CAST expr
2205 // | T_STRING_CAST expr
2206 // | T_ARRAY_CAST expr
2207 // | T_OBJECT_CAST expr
2208 // | T_BOOL_CAST expr
2209 // | T_UNSET_CAST expr
2210 // | T_EXIT exit_expr
2212 // | T_ARRAY '(' array_pair_list ')'
2213 // | '`' encaps_list '`'
2214 // | T_LIST '(' assignment_list ')' '=' expr
2215 // | T_NEW class_name_reference ctor_arguments
2216 // | variable '=' expr
2217 // | variable '=' '&' variable
2218 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2219 // | variable T_PLUS_EQUAL expr
2220 // | variable T_MINUS_EQUAL expr
2221 // | variable T_MUL_EQUAL expr
2222 // | variable T_DIV_EQUAL expr
2223 // | variable T_CONCAT_EQUAL expr
2224 // | variable T_MOD_EQUAL expr
2225 // | variable T_AND_EQUAL expr
2226 // | variable T_OR_EQUAL expr
2227 // | variable T_XOR_EQUAL expr
2228 // | variable T_SL_EQUAL expr
2229 // | variable T_SR_EQUAL expr
2230 // | rw_variable T_INC
2231 // | rw_variable T_DEC
2232 // | expr T_BOOLEAN_OR expr
2233 // | expr T_BOOLEAN_AND expr
2234 // | expr T_LOGICAL_OR expr
2235 // | expr T_LOGICAL_AND expr
2236 // | expr T_LOGICAL_XOR expr
2248 // | expr T_IS_IDENTICAL expr
2249 // | expr T_IS_NOT_IDENTICAL expr
2250 // | expr T_IS_EQUAL expr
2251 // | expr T_IS_NOT_EQUAL expr
2253 // | expr T_IS_SMALLER_OR_EQUAL expr
2255 // | expr T_IS_GREATER_OR_EQUAL expr
2256 // | expr T_INSTANCEOF class_name_reference
2257 // | expr '?' expr ':' expr
2258 if (Scanner.TRACE) {
2259 System.out.println("TRACE: expr_without_variable() PART 1");
2262 case TokenNameisset:
2263 // T_ISSET '(' isset_variables ')'
2265 if (token != TokenNameLPAREN) {
2266 throwSyntaxError("'(' expected after keyword 'isset'");
2270 if (token != TokenNameRPAREN) {
2271 throwSyntaxError("')' expected after keyword 'isset'");
2275 case TokenNameempty:
2277 if (token != TokenNameLPAREN) {
2278 throwSyntaxError("'(' expected after keyword 'empty'");
2281 variable(true, false);
2282 if (token != TokenNameRPAREN) {
2283 throwSyntaxError("')' expected after keyword 'empty'");
2288 case TokenNameinclude:
2289 case TokenNameinclude_once:
2290 case TokenNamerequire:
2291 case TokenNamerequire_once:
2292 internal_functions_in_yacc();
2295 case TokenNameLPAREN:
2298 if (token == TokenNameRPAREN) {
2301 throwSyntaxError("')' expected in expression.");
2311 // | T_INT_CAST expr
2312 // | T_DOUBLE_CAST expr
2313 // | T_STRING_CAST expr
2314 // | T_ARRAY_CAST expr
2315 // | T_OBJECT_CAST expr
2316 // | T_BOOL_CAST expr
2317 // | T_UNSET_CAST expr
2318 case TokenNameclone:
2319 case TokenNameprint:
2322 case TokenNameMINUS:
2324 case TokenNameTWIDDLE:
2325 case TokenNameintCAST:
2326 case TokenNamedoubleCAST:
2327 case TokenNamestringCAST:
2328 case TokenNamearrayCAST:
2329 case TokenNameobjectCAST:
2330 case TokenNameboolCAST:
2331 case TokenNameunsetCAST:
2341 // | T_STRING_VARNAME
2343 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2344 // | '`' encaps_list '`'
2346 // | '`' encaps_list '`'
2347 // case TokenNameEncapsedString0:
2348 // scanner.encapsedStringStack.push(new Character('`'));
2351 // if (token == TokenNameEncapsedString0) {
2354 // if (token != TokenNameEncapsedString0) {
2355 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2356 // scanner.toStringAction(token) + " )");
2360 // scanner.encapsedStringStack.pop();
2364 // // | '\'' encaps_list '\''
2365 // case TokenNameEncapsedString1:
2366 // scanner.encapsedStringStack.push(new Character('\''));
2369 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2370 // if (token == TokenNameEncapsedString1) {
2372 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2373 // exprSourceStart, scanner
2374 // .getCurrentTokenEndPosition());
2377 // if (token != TokenNameEncapsedString1) {
2378 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2379 // + scanner.toStringAction(token) + " )");
2382 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2383 // exprSourceStart, scanner
2384 // .getCurrentTokenEndPosition());
2388 // scanner.encapsedStringStack.pop();
2392 // //| '"' encaps_list '"'
2393 // case TokenNameEncapsedString2:
2394 // scanner.encapsedStringStack.push(new Character('"'));
2397 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2398 // if (token == TokenNameEncapsedString2) {
2400 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2401 // exprSourceStart, scanner
2402 // .getCurrentTokenEndPosition());
2405 // if (token != TokenNameEncapsedString2) {
2406 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2407 // scanner.toStringAction(token) + " )");
2410 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2411 // exprSourceStart, scanner
2412 // .getCurrentTokenEndPosition());
2416 // scanner.encapsedStringStack.pop();
2420 case TokenNameStringDoubleQuote:
2421 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2422 .getCurrentTokenEndPosition());
2425 case TokenNameStringSingleQuote:
2426 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2427 .getCurrentTokenEndPosition());
2430 case TokenNameIntegerLiteral:
2431 case TokenNameDoubleLiteral:
2432 case TokenNameStringInterpolated:
2435 case TokenNameCLASS_C:
2436 case TokenNameMETHOD_C:
2437 case TokenNameFUNC_C:
2440 case TokenNameHEREDOC:
2443 case TokenNamearray:
2444 // T_ARRAY '(' array_pair_list ')'
2446 if (token == TokenNameLPAREN) {
2448 if (token == TokenNameRPAREN) {
2453 if (token != TokenNameRPAREN) {
2454 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2458 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2462 // | T_LIST '(' assignment_list ')' '=' expr
2464 if (token == TokenNameLPAREN) {
2467 if (token != TokenNameRPAREN) {
2468 throwSyntaxError("')' expected after 'list' keyword.");
2471 if (token != TokenNameEQUAL) {
2472 throwSyntaxError("'=' expected after 'list' keyword.");
2477 throwSyntaxError("'(' expected after 'list' keyword.");
2481 // | T_NEW class_name_reference ctor_arguments
2483 Expression typeRef = class_name_reference();
2485 if (typeRef != null) {
2486 expression = typeRef;
2489 // | T_INC rw_variable
2490 // | T_DEC rw_variable
2491 case TokenNamePLUS_PLUS:
2492 case TokenNameMINUS_MINUS:
2496 // | variable '=' expr
2497 // | variable '=' '&' variable
2498 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2499 // | variable T_PLUS_EQUAL expr
2500 // | variable T_MINUS_EQUAL expr
2501 // | variable T_MUL_EQUAL expr
2502 // | variable T_DIV_EQUAL expr
2503 // | variable T_CONCAT_EQUAL expr
2504 // | variable T_MOD_EQUAL expr
2505 // | variable T_AND_EQUAL expr
2506 // | variable T_OR_EQUAL expr
2507 // | variable T_XOR_EQUAL expr
2508 // | variable T_SL_EQUAL expr
2509 // | variable T_SR_EQUAL expr
2510 // | rw_variable T_INC
2511 // | rw_variable T_DEC
2512 case TokenNameIdentifier:
2513 case TokenNameVariable:
2514 case TokenNameDOLLAR:
2515 Expression lhs = null;
2516 boolean rememberedVar = false;
2517 if (token == TokenNameIdentifier) {
2518 lhs = identifier(true, true);
2523 lhs = variable(true, true);
2527 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2528 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2529 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2530 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2531 && token != TokenNameLEFT_SHIFT_EQUAL) {
2532 FieldReference ref = (FieldReference) lhs;
2533 if (!containsVariableSet(ref.token)) {
2534 if (null==initHandler || initHandler.reportError()) {
2535 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart, ref.sourceEnd,
2536 referenceContext, compilationUnit.compilationResult);
2538 addVariableSet(ref.token);
2543 case TokenNameEQUAL:
2544 if (lhs != null && lhs instanceof FieldReference) {
2545 addVariableSet(((FieldReference) lhs).token);
2548 if (token == TokenNameAND) {
2550 if (token == TokenNamenew) {
2551 // | variable '=' '&' T_NEW class_name_reference
2554 SingleTypeReference classRef = class_name_reference();
2556 if (classRef != null) {
2557 if (lhs != null && lhs instanceof FieldReference) {
2559 // $var = & new Object();
2560 if (fMethodVariables != null) {
2561 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2562 lhsInfo.reference = classRef;
2563 lhsInfo.typeIdentifier = classRef.token;
2564 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2565 rememberedVar = true;
2570 Expression rhs = variable(false, false);
2571 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2574 if (fMethodVariables != null) {
2575 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2576 if (rhsInfo != null && rhsInfo.reference != null) {
2577 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2578 lhsInfo.reference = rhsInfo.reference;
2579 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2580 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2581 rememberedVar = true;
2587 Expression rhs = expr();
2588 if (lhs != null && lhs instanceof FieldReference) {
2589 if (rhs != null && rhs instanceof FieldReference) {
2592 if (fMethodVariables != null) {
2593 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2594 if (rhsInfo != null && rhsInfo.reference != null) {
2595 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2596 lhsInfo.reference = rhsInfo.reference;
2597 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2598 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2599 rememberedVar = true;
2602 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2604 // $var = new Object();
2605 if (fMethodVariables != null) {
2606 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2607 lhsInfo.reference = (SingleTypeReference) rhs;
2608 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2609 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2610 rememberedVar = true;
2615 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2616 if (fMethodVariables != null) {
2617 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2618 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2622 case TokenNamePLUS_EQUAL:
2623 case TokenNameMINUS_EQUAL:
2624 case TokenNameMULTIPLY_EQUAL:
2625 case TokenNameDIVIDE_EQUAL:
2626 case TokenNameDOT_EQUAL:
2627 case TokenNameREMAINDER_EQUAL:
2628 case TokenNameAND_EQUAL:
2629 case TokenNameOR_EQUAL:
2630 case TokenNameXOR_EQUAL:
2631 case TokenNameRIGHT_SHIFT_EQUAL:
2632 case TokenNameLEFT_SHIFT_EQUAL:
2633 if (lhs != null && lhs instanceof FieldReference) {
2634 addVariableSet(((FieldReference) lhs).token);
2639 case TokenNamePLUS_PLUS:
2640 case TokenNameMINUS_MINUS:
2644 if (!only_variable) {
2645 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2653 if (token != TokenNameINLINE_HTML) {
2654 if (token > TokenNameKEYWORD) {
2658 // System.out.println(scanner.getCurrentTokenStartPosition());
2659 // System.out.println(scanner.getCurrentTokenEndPosition());
2661 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2666 if (Scanner.TRACE) {
2667 System.out.println("TRACE: expr_without_variable() PART 2");
2669 // | expr T_BOOLEAN_OR expr
2670 // | expr T_BOOLEAN_AND expr
2671 // | expr T_LOGICAL_OR expr
2672 // | expr T_LOGICAL_AND expr
2673 // | expr T_LOGICAL_XOR expr
2685 // | expr T_IS_IDENTICAL expr
2686 // | expr T_IS_NOT_IDENTICAL expr
2687 // | expr T_IS_EQUAL expr
2688 // | expr T_IS_NOT_EQUAL expr
2690 // | expr T_IS_SMALLER_OR_EQUAL expr
2692 // | expr T_IS_GREATER_OR_EQUAL expr
2695 case TokenNameOR_OR:
2697 expression = new OR_OR_Expression(expression, expr(), token);
2699 case TokenNameAND_AND:
2701 expression = new AND_AND_Expression(expression, expr(), token);
2703 case TokenNameEQUAL_EQUAL:
2705 expression = new EqualExpression(expression, expr(), token);
2715 case TokenNameMINUS:
2716 case TokenNameMULTIPLY:
2717 case TokenNameDIVIDE:
2718 case TokenNameREMAINDER:
2719 case TokenNameLEFT_SHIFT:
2720 case TokenNameRIGHT_SHIFT:
2721 case TokenNameEQUAL_EQUAL_EQUAL:
2722 case TokenNameNOT_EQUAL_EQUAL:
2723 case TokenNameNOT_EQUAL:
2725 case TokenNameLESS_EQUAL:
2726 case TokenNameGREATER:
2727 case TokenNameGREATER_EQUAL:
2729 expression = new BinaryExpression(expression, expr(), token);
2731 // | expr T_INSTANCEOF class_name_reference
2732 // | expr '?' expr ':' expr
2733 case TokenNameinstanceof:
2735 TypeReference classRef = class_name_reference();
2736 if (classRef != null) {
2737 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2738 expression.sourceStart = exprSourceStart;
2739 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2742 case TokenNameQUESTION:
2744 Expression valueIfTrue = expr();
2745 if (token != TokenNameCOLON) {
2746 throwSyntaxError("':' expected in conditional expression.");
2749 Expression valueIfFalse = expr();
2751 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2757 } catch (SyntaxError e) {
2758 // try to find next token after expression with errors:
2759 if (token == TokenNameSEMICOLON) {
2763 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2771 private SingleTypeReference class_name_reference() {
2772 // class_name_reference:
2774 // | dynamic_class_name_reference
2775 SingleTypeReference ref = null;
2776 if (Scanner.TRACE) {
2777 System.out.println("TRACE: class_name_reference()");
2779 if (token == TokenNameIdentifier) {
2780 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2784 dynamic_class_name_reference();
2789 private void dynamic_class_name_reference() {
2790 // dynamic_class_name_reference:
2791 // base_variable T_OBJECT_OPERATOR object_property
2792 // dynamic_class_name_variable_properties
2794 if (Scanner.TRACE) {
2795 System.out.println("TRACE: dynamic_class_name_reference()");
2797 base_variable(true);
2798 if (token == TokenNameMINUS_GREATER) {
2801 dynamic_class_name_variable_properties();
2805 private void dynamic_class_name_variable_properties() {
2806 // dynamic_class_name_variable_properties:
2807 // dynamic_class_name_variable_properties
2808 // dynamic_class_name_variable_property
2810 if (Scanner.TRACE) {
2811 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2813 while (token == TokenNameMINUS_GREATER) {
2814 dynamic_class_name_variable_property();
2818 private void dynamic_class_name_variable_property() {
2819 // dynamic_class_name_variable_property:
2820 // T_OBJECT_OPERATOR object_property
2821 if (Scanner.TRACE) {
2822 System.out.println("TRACE: dynamic_class_name_variable_property()");
2824 if (token == TokenNameMINUS_GREATER) {
2830 private void ctor_arguments() {
2833 // | '(' function_call_parameter_list ')'
2834 if (token == TokenNameLPAREN) {
2836 if (token == TokenNameRPAREN) {
2840 non_empty_function_call_parameter_list();
2841 if (token != TokenNameRPAREN) {
2842 throwSyntaxError("')' expected in ctor_arguments.");
2848 private void assignment_list() {
2850 // assignment_list ',' assignment_list_element
2851 // | assignment_list_element
2853 assignment_list_element();
2854 if (token != TokenNameCOMMA) {
2861 private void assignment_list_element() {
2862 // assignment_list_element:
2864 // | T_LIST '(' assignment_list ')'
2866 if (token == TokenNameVariable) {
2867 variable(true, false);
2868 } else if (token == TokenNameDOLLAR) {
2869 variable(false, false);
2871 if (token == TokenNamelist) {
2873 if (token == TokenNameLPAREN) {
2876 if (token != TokenNameRPAREN) {
2877 throwSyntaxError("')' expected after 'list' keyword.");
2881 throwSyntaxError("'(' expected after 'list' keyword.");
2887 private void array_pair_list() {
2890 // | non_empty_array_pair_list possible_comma
2891 non_empty_array_pair_list();
2892 if (token == TokenNameCOMMA) {
2897 private void non_empty_array_pair_list() {
2898 // non_empty_array_pair_list:
2899 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2900 // | non_empty_array_pair_list ',' expr
2901 // | expr T_DOUBLE_ARROW expr
2903 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2904 // | non_empty_array_pair_list ',' '&' w_variable
2905 // | expr T_DOUBLE_ARROW '&' w_variable
2908 if (token == TokenNameAND) {
2910 variable(true, false);
2913 if (token == TokenNameAND) {
2915 variable(true, false);
2916 } else if (token == TokenNameEQUAL_GREATER) {
2918 if (token == TokenNameAND) {
2920 variable(true, false);
2926 if (token != TokenNameCOMMA) {
2930 if (token == TokenNameRPAREN) {
2936 // private void variableList() {
2939 // if (token == TokenNameCOMMA) {
2946 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2947 // variable_without_objects:
2948 // reference_variable
2949 // | simple_indirect_reference reference_variable
2950 if (Scanner.TRACE) {
2951 System.out.println("TRACE: variable_without_objects()");
2953 while (token == TokenNameDOLLAR) {
2956 return reference_variable(lefthandside, ignoreVar);
2959 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2961 // T_STRING '(' function_call_parameter_list ')'
2962 // | class_constant '(' function_call_parameter_list ')'
2963 // | static_member '(' function_call_parameter_list ')'
2964 // | variable_without_objects '(' function_call_parameter_list ')'
2965 char[] defineName = null;
2966 char[] ident = null;
2969 Expression ref = null;
2970 if (Scanner.TRACE) {
2971 System.out.println("TRACE: function_call()");
2973 if (token == TokenNameIdentifier) {
2974 ident = scanner.getCurrentIdentifierSource();
2976 startPos = scanner.getCurrentTokenStartPosition();
2977 endPos = scanner.getCurrentTokenEndPosition();
2980 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2984 if (token == TokenNameIdentifier) {
2989 variable_without_objects(true, false);
2994 ref = variable_without_objects(lefthandside, ignoreVar);
2996 if (token != TokenNameLPAREN) {
2997 if (defineName != null) {
2998 // does this identifier contain only uppercase characters?
2999 if (defineName.length == 3) {
3000 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3003 } else if (defineName.length == 4) {
3004 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3006 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3009 } else if (defineName.length == 5) {
3010 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3014 if (defineName != null) {
3015 for (int i = 0; i < defineName.length; i++) {
3016 if (Character.isLowerCase(defineName[i])) {
3017 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3025 if (token == TokenNameRPAREN) {
3029 non_empty_function_call_parameter_list();
3030 if (token != TokenNameRPAREN) {
3031 String functionName;
3032 if (ident == null) {
3033 functionName = new String(" ");
3035 functionName = new String(ident);
3037 throwSyntaxError("')' expected in function call (" + functionName + ").");
3044 private void non_empty_function_call_parameter_list() {
3045 this.non_empty_function_call_parameter_list(null);
3048 // private void function_call_parameter_list() {
3049 // function_call_parameter_list:
3050 // non_empty_function_call_parameter_list { $$ = $1; }
3053 private void non_empty_function_call_parameter_list(String functionName) {
3054 // non_empty_function_call_parameter_list:
3055 // expr_without_variable
3058 // | non_empty_function_call_parameter_list ',' expr_without_variable
3059 // | non_empty_function_call_parameter_list ',' variable
3060 // | non_empty_function_call_parameter_list ',' '&' w_variable
3061 if (Scanner.TRACE) {
3062 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3064 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3065 initHandler.setFunctionName(functionName);
3067 initHandler.incrementArgumentCount();
3068 if (token == TokenNameAND) {
3072 // if (token == TokenNameIdentifier || token ==
3073 // TokenNameVariable
3074 // || token == TokenNameDOLLAR) {
3077 expr_without_variable(true, initHandler);
3080 if (token != TokenNameCOMMA) {
3087 private void fully_qualified_class_name() {
3088 if (token == TokenNameIdentifier) {
3091 throwSyntaxError("Class name expected.");
3095 private void static_member() {
3097 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3098 // variable_without_objects
3099 if (Scanner.TRACE) {
3100 System.out.println("TRACE: static_member()");
3102 fully_qualified_class_name();
3103 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3104 throwSyntaxError("'::' expected after class name (static_member).");
3107 variable_without_objects(false, false);
3110 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3111 // base_variable_with_function_calls:
3114 if (Scanner.TRACE) {
3115 System.out.println("TRACE: base_variable_with_function_calls()");
3117 return function_call(lefthandside, ignoreVar);
3120 private Expression base_variable(boolean lefthandside) {
3122 // reference_variable
3123 // | simple_indirect_reference reference_variable
3125 Expression ref = null;
3126 if (Scanner.TRACE) {
3127 System.out.println("TRACE: base_variable()");
3129 if (token == TokenNameIdentifier) {
3132 while (token == TokenNameDOLLAR) {
3135 reference_variable(lefthandside, false);
3140 // private void simple_indirect_reference() {
3141 // // simple_indirect_reference:
3143 // //| simple_indirect_reference '$'
3145 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3146 // reference_variable:
3147 // reference_variable '[' dim_offset ']'
3148 // | reference_variable '{' expr '}'
3149 // | compound_variable
3150 Expression ref = null;
3151 if (Scanner.TRACE) {
3152 System.out.println("TRACE: reference_variable()");
3154 ref = compound_variable(lefthandside, ignoreVar);
3156 if (token == TokenNameLBRACE) {
3160 if (token != TokenNameRBRACE) {
3161 throwSyntaxError("'}' expected in reference variable.");
3164 } else if (token == TokenNameLBRACKET) {
3165 // To remove "ref = null;" here, is probably better than the patch
3166 // commented in #1368081 - axelcl
3168 if (token != TokenNameRBRACKET) {
3171 if (token != TokenNameRBRACKET) {
3172 throwSyntaxError("']' expected in reference variable.");
3183 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3184 // compound_variable:
3186 // | '$' '{' expr '}'
3187 if (Scanner.TRACE) {
3188 System.out.println("TRACE: compound_variable()");
3190 if (token == TokenNameVariable) {
3191 if (!lefthandside) {
3192 if (!containsVariableSet()) {
3193 // reportSyntaxError("The local variable " + new
3194 // String(scanner.getCurrentIdentifierSource())
3195 // + " may not have been initialized");
3196 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3197 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3198 compilationUnit.compilationResult);
3205 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3209 // because of simple_indirect_reference
3210 while (token == TokenNameDOLLAR) {
3213 if (token != TokenNameLBRACE) {
3214 reportSyntaxError("'{' expected after compound variable token '$'.");
3219 if (token != TokenNameRBRACE) {
3220 throwSyntaxError("'}' expected after compound variable token '$'.");
3225 } // private void dim_offset() { // // dim_offset: // // /* empty */
3230 private void object_property() {
3233 // | variable_without_objects
3234 if (Scanner.TRACE) {
3235 System.out.println("TRACE: object_property()");
3237 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3238 variable_without_objects(false, false);
3244 private void object_dim_list() {
3246 // object_dim_list '[' dim_offset ']'
3247 // | object_dim_list '{' expr '}'
3249 if (Scanner.TRACE) {
3250 System.out.println("TRACE: object_dim_list()");
3254 if (token == TokenNameLBRACE) {
3257 if (token != TokenNameRBRACE) {
3258 throwSyntaxError("'}' expected in object_dim_list.");
3261 } else if (token == TokenNameLBRACKET) {
3263 if (token == TokenNameRBRACKET) {
3268 if (token != TokenNameRBRACKET) {
3269 throwSyntaxError("']' expected in object_dim_list.");
3278 private void variable_name() {
3282 if (Scanner.TRACE) {
3283 System.out.println("TRACE: variable_name()");
3285 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3286 if (token > TokenNameKEYWORD) {
3287 // TODO show a warning "Keyword used as variable" ?
3291 if (token != TokenNameLBRACE) {
3292 throwSyntaxError("'{' expected in variable name.");
3296 if (token != TokenNameRBRACE) {
3297 throwSyntaxError("'}' expected in variable name.");
3303 private void r_variable() {
3304 variable(false, false);
3307 private void w_variable(boolean lefthandside) {
3308 variable(lefthandside, false);
3311 private void rw_variable() {
3312 variable(false, false);
3315 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3317 // base_variable_with_function_calls T_OBJECT_OPERATOR
3318 // object_property method_or_not variable_properties
3319 // | base_variable_with_function_calls
3320 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3321 if (token == TokenNameMINUS_GREATER) {
3326 variable_properties();
3331 private void variable_properties() {
3332 // variable_properties:
3333 // variable_properties variable_property
3335 while (token == TokenNameMINUS_GREATER) {
3336 variable_property();
3340 private void variable_property() {
3341 // variable_property:
3342 // T_OBJECT_OPERATOR object_property method_or_not
3343 if (Scanner.TRACE) {
3344 System.out.println("TRACE: variable_property()");
3346 if (token == TokenNameMINUS_GREATER) {
3351 throwSyntaxError("'->' expected in variable_property.");
3355 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3357 // base_variable_with_function_calls T_OBJECT_OPERATOR
3358 // object_property method_or_not variable_properties
3359 // | base_variable_with_function_calls
3361 // Expression ref = function_call(lefthandside, ignoreVar);
3364 // T_STRING '(' function_call_parameter_list ')'
3365 // | class_constant '(' function_call_parameter_list ')'
3366 // | static_member '(' function_call_parameter_list ')'
3367 // | variable_without_objects '(' function_call_parameter_list ')'
3368 char[] defineName = null;
3369 char[] ident = null;
3372 Expression ref = null;
3373 if (Scanner.TRACE) {
3374 System.out.println("TRACE: function_call()");
3376 if (token == TokenNameIdentifier) {
3377 ident = scanner.getCurrentIdentifierSource();
3379 startPos = scanner.getCurrentTokenStartPosition();
3380 endPos = scanner.getCurrentTokenEndPosition();
3383 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3384 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3385 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3386 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3387 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3388 + new String(ident) + "' (use 'define(...)' to define constants).";
3389 reportSyntaxError(error);
3393 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3397 if (token == TokenNameIdentifier) {
3402 variable_without_objects(true, false);
3407 ref = variable_without_objects(lefthandside, ignoreVar);
3409 if (token != TokenNameLPAREN) {
3410 if (defineName != null) {
3411 // does this identifier contain only uppercase characters?
3412 if (defineName.length == 3) {
3413 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3416 } else if (defineName.length == 4) {
3417 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3419 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3422 } else if (defineName.length == 5) {
3423 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3427 if (defineName != null) {
3428 for (int i = 0; i < defineName.length; i++) {
3429 if (Character.isLowerCase(defineName[i])) {
3430 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3436 // TODO is this ok ?
3438 // throwSyntaxError("'(' expected in function call.");
3442 if (token == TokenNameRPAREN) {
3446 String functionName;
3447 if (ident == null) {
3448 functionName = new String(" ");
3450 functionName = new String(ident);
3452 non_empty_function_call_parameter_list(functionName);
3453 if (token != TokenNameRPAREN) {
3454 throwSyntaxError("')' expected in function call (" + functionName + ").");
3459 if (token == TokenNameMINUS_GREATER) {
3464 variable_properties();
3469 private void method_or_not() {
3471 // '(' function_call_parameter_list ')'
3473 if (Scanner.TRACE) {
3474 System.out.println("TRACE: method_or_not()");
3476 if (token == TokenNameLPAREN) {
3478 if (token == TokenNameRPAREN) {
3482 non_empty_function_call_parameter_list();
3483 if (token != TokenNameRPAREN) {
3484 throwSyntaxError("')' expected in method_or_not.");
3490 private void exit_expr() {
3494 if (token != TokenNameLPAREN) {
3498 if (token == TokenNameRPAREN) {
3503 if (token != TokenNameRPAREN) {
3504 throwSyntaxError("')' expected after keyword 'exit'");
3509 // private void encaps_list() {
3510 // // encaps_list encaps_var
3511 // // | encaps_list T_STRING
3512 // // | encaps_list T_NUM_STRING
3513 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3514 // // | encaps_list T_CHARACTER
3515 // // | encaps_list T_BAD_CHARACTER
3516 // // | encaps_list '['
3517 // // | encaps_list ']'
3518 // // | encaps_list '{'
3519 // // | encaps_list '}'
3520 // // | encaps_list T_OBJECT_OPERATOR
3524 // case TokenNameSTRING:
3527 // case TokenNameLBRACE:
3528 // // scanner.encapsedStringStack.pop();
3531 // case TokenNameRBRACE:
3532 // // scanner.encapsedStringStack.pop();
3535 // case TokenNameLBRACKET:
3536 // // scanner.encapsedStringStack.pop();
3539 // case TokenNameRBRACKET:
3540 // // scanner.encapsedStringStack.pop();
3543 // case TokenNameMINUS_GREATER:
3544 // // scanner.encapsedStringStack.pop();
3547 // case TokenNameVariable:
3548 // case TokenNameDOLLAR_LBRACE:
3549 // case TokenNameLBRACE_DOLLAR:
3553 // char encapsedChar = ((Character)
3554 // scanner.encapsedStringStack.peek()).charValue();
3555 // if (encapsedChar == '$') {
3556 // scanner.encapsedStringStack.pop();
3557 // encapsedChar = ((Character)
3558 // scanner.encapsedStringStack.peek()).charValue();
3559 // switch (encapsedChar) {
3561 // if (token == TokenNameEncapsedString0) {
3564 // token = TokenNameSTRING;
3567 // if (token == TokenNameEncapsedString1) {
3570 // token = TokenNameSTRING;
3573 // if (token == TokenNameEncapsedString2) {
3576 // token = TokenNameSTRING;
3585 // private void encaps_var() {
3587 // // | T_VARIABLE '[' encaps_var_offset ']'
3588 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3589 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3590 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3591 // // | T_CURLY_OPEN variable '}'
3593 // case TokenNameVariable:
3595 // if (token == TokenNameLBRACKET) {
3597 // expr(); //encaps_var_offset();
3598 // if (token != TokenNameRBRACKET) {
3599 // throwSyntaxError("']' expected after variable.");
3601 // // scanner.encapsedStringStack.pop();
3604 // } else if (token == TokenNameMINUS_GREATER) {
3606 // if (token != TokenNameIdentifier) {
3607 // throwSyntaxError("Identifier expected after '->'.");
3609 // // scanner.encapsedStringStack.pop();
3613 // // // scanner.encapsedStringStack.pop();
3614 // // int tempToken = TokenNameSTRING;
3615 // // if (!scanner.encapsedStringStack.isEmpty()
3616 // // && (token == TokenNameEncapsedString0
3617 // // || token == TokenNameEncapsedString1
3618 // // || token == TokenNameEncapsedString2 || token ==
3619 // // TokenNameERROR)) {
3620 // // char encapsedChar = ((Character)
3621 // // scanner.encapsedStringStack.peek())
3623 // // switch (token) {
3624 // // case TokenNameEncapsedString0 :
3625 // // if (encapsedChar == '`') {
3626 // // tempToken = TokenNameEncapsedString0;
3629 // // case TokenNameEncapsedString1 :
3630 // // if (encapsedChar == '\'') {
3631 // // tempToken = TokenNameEncapsedString1;
3634 // // case TokenNameEncapsedString2 :
3635 // // if (encapsedChar == '"') {
3636 // // tempToken = TokenNameEncapsedString2;
3639 // // case TokenNameERROR :
3640 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3641 // // scanner.currentPosition--;
3642 // // getNextToken();
3647 // // token = tempToken;
3650 // case TokenNameDOLLAR_LBRACE:
3652 // if (token == TokenNameDOLLAR_LBRACE) {
3654 // } else if (token == TokenNameIdentifier) {
3656 // if (token == TokenNameLBRACKET) {
3658 // // if (token == TokenNameRBRACKET) {
3659 // // getNextToken();
3662 // if (token != TokenNameRBRACKET) {
3663 // throwSyntaxError("']' expected after '${'.");
3671 // if (token != TokenNameRBRACE) {
3672 // throwSyntaxError("'}' expected.");
3676 // case TokenNameLBRACE_DOLLAR:
3678 // if (token == TokenNameLBRACE_DOLLAR) {
3680 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3682 // if (token == TokenNameLBRACKET) {
3684 // // if (token == TokenNameRBRACKET) {
3685 // // getNextToken();
3688 // if (token != TokenNameRBRACKET) {
3689 // throwSyntaxError("']' expected.");
3693 // } else if (token == TokenNameMINUS_GREATER) {
3695 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3696 // throwSyntaxError("String or Variable token expected.");
3699 // if (token == TokenNameLBRACKET) {
3701 // // if (token == TokenNameRBRACKET) {
3702 // // getNextToken();
3705 // if (token != TokenNameRBRACKET) {
3706 // throwSyntaxError("']' expected after '${'.");
3712 // // if (token != TokenNameRBRACE) {
3713 // // throwSyntaxError("'}' expected after '{$'.");
3715 // // // scanner.encapsedStringStack.pop();
3716 // // getNextToken();
3719 // if (token != TokenNameRBRACE) {
3720 // throwSyntaxError("'}' expected.");
3722 // // scanner.encapsedStringStack.pop();
3729 // private void encaps_var_offset() {
3731 // // | T_NUM_STRING
3734 // case TokenNameSTRING:
3737 // case TokenNameIntegerLiteral:
3740 // case TokenNameVariable:
3743 // case TokenNameIdentifier:
3747 // throwSyntaxError("Variable or String token expected.");
3752 private void internal_functions_in_yacc() {
3755 // case TokenNameisset:
3756 // // T_ISSET '(' isset_variables ')'
3758 // if (token != TokenNameLPAREN) {
3759 // throwSyntaxError("'(' expected after keyword 'isset'");
3762 // isset_variables();
3763 // if (token != TokenNameRPAREN) {
3764 // throwSyntaxError("')' expected after keyword 'isset'");
3768 // case TokenNameempty:
3769 // // T_EMPTY '(' variable ')'
3771 // if (token != TokenNameLPAREN) {
3772 // throwSyntaxError("'(' expected after keyword 'empty'");
3776 // if (token != TokenNameRPAREN) {
3777 // throwSyntaxError("')' expected after keyword 'empty'");
3781 case TokenNameinclude:
3783 checkFileName(token);
3785 case TokenNameinclude_once:
3786 // T_INCLUDE_ONCE expr
3787 checkFileName(token);
3790 // T_EVAL '(' expr ')'
3792 if (token != TokenNameLPAREN) {
3793 throwSyntaxError("'(' expected after keyword 'eval'");
3797 if (token != TokenNameRPAREN) {
3798 throwSyntaxError("')' expected after keyword 'eval'");
3802 case TokenNamerequire:
3804 checkFileName(token);
3806 case TokenNamerequire_once:
3807 // T_REQUIRE_ONCE expr
3808 checkFileName(token);
3814 * Parse and check the include file name
3816 * @param includeToken
3818 private void checkFileName(int includeToken) {
3819 // <include-token> expr
3820 int start = scanner.getCurrentTokenStartPosition();
3821 boolean hasLPAREN = false;
3823 if (token == TokenNameLPAREN) {
3827 Expression expression = expr();
3829 if (token == TokenNameRPAREN) {
3832 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3835 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3837 if (scanner.compilationUnit != null) {
3838 IResource resource = scanner.compilationUnit.getResource();
3839 if (resource != null && resource instanceof IFile) {
3840 file = (IFile) resource;
3844 tokens = new char[1][];
3845 tokens[0] = currTokenSource;
3847 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3848 impt.declarationSourceEnd = impt.sourceEnd;
3849 impt.declarationEnd = impt.declarationSourceEnd;
3850 // endPosition is just before the ;
3851 impt.declarationSourceStart = start;
3852 includesList.add(impt);
3854 if (expression instanceof StringLiteral) {
3855 StringLiteral literal = (StringLiteral) expression;
3856 char[] includeName = literal.source();
3857 if (includeName.length == 0) {
3858 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3859 literal.sourceStart + 1);
3861 String includeNameString = new String(includeName);
3862 if (literal instanceof StringLiteralDQ) {
3863 if (includeNameString.indexOf('$') >= 0) {
3864 // assuming that the filename contains a variable => no filename check
3868 if (includeNameString.startsWith("http://")) {
3869 // assuming external include location
3873 // check the filename:
3874 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3875 // expression.toStringExpression());
3876 IProject project = file.getProject();
3877 if (project != null) {
3878 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3881 // SyntaxError: "File: << >> doesn't exist in project."
3882 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3883 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3884 compilationUnit.compilationResult);
3887 String filePath = path.toString();
3888 String ext = file.getRawLocation().getFileExtension();
3889 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3891 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3892 impt.setFile(PHPFileUtil.createFile(path, project));
3893 } catch (Exception e) {
3894 // the file is outside of the workspace
3902 private void isset_variables() {
3904 // | isset_variables ','
3905 if (token == TokenNameRPAREN) {
3906 throwSyntaxError("Variable expected after keyword 'isset'");
3909 variable(true, false);
3910 if (token == TokenNameCOMMA) {
3918 private boolean common_scalar() {
3922 // | T_CONSTANT_ENCAPSED_STRING
3929 case TokenNameIntegerLiteral:
3932 case TokenNameDoubleLiteral:
3935 case TokenNameStringDoubleQuote:
3938 case TokenNameStringSingleQuote:
3941 case TokenNameStringInterpolated:
3950 case TokenNameCLASS_C:
3953 case TokenNameMETHOD_C:
3956 case TokenNameFUNC_C:
3963 private void scalar() {
3966 // | T_STRING_VARNAME
3969 // | '"' encaps_list '"'
3970 // | '\'' encaps_list '\''
3971 // | T_START_HEREDOC encaps_list T_END_HEREDOC
3972 throwSyntaxError("Not yet implemented (scalar).");
3975 private void static_scalar() {
3976 // static_scalar: /* compile-time evaluated scalars */
3979 // | '+' static_scalar
3980 // | '-' static_scalar
3981 // | T_ARRAY '(' static_array_pair_list ')'
3982 // | static_class_constant
3983 if (common_scalar()) {
3987 case TokenNameIdentifier:
3989 // static_class_constant:
3990 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3991 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3993 if (token == TokenNameIdentifier) {
3996 throwSyntaxError("Identifier expected after '::' operator.");
4000 case TokenNameEncapsedString0:
4002 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4003 while (scanner.currentCharacter != '`') {
4004 if (scanner.currentCharacter == '\\') {
4005 scanner.currentPosition++;
4007 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4010 } catch (IndexOutOfBoundsException e) {
4011 throwSyntaxError("'`' expected at end of static string.");
4014 // case TokenNameEncapsedString1:
4016 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4017 // while (scanner.currentCharacter != '\'') {
4018 // if (scanner.currentCharacter == '\\') {
4019 // scanner.currentPosition++;
4021 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4024 // } catch (IndexOutOfBoundsException e) {
4025 // throwSyntaxError("'\'' expected at end of static string.");
4028 // case TokenNameEncapsedString2:
4030 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4031 // while (scanner.currentCharacter != '"') {
4032 // if (scanner.currentCharacter == '\\') {
4033 // scanner.currentPosition++;
4035 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4038 // } catch (IndexOutOfBoundsException e) {
4039 // throwSyntaxError("'\"' expected at end of static string.");
4042 case TokenNameStringSingleQuote:
4045 case TokenNameStringDoubleQuote:
4052 case TokenNameMINUS:
4056 case TokenNamearray:
4058 if (token != TokenNameLPAREN) {
4059 throwSyntaxError("'(' expected after keyword 'array'");
4062 if (token == TokenNameRPAREN) {
4066 non_empty_static_array_pair_list();
4067 if (token != TokenNameRPAREN) {
4068 throwSyntaxError("')' or ',' expected after keyword 'array'");
4072 // case TokenNamenull :
4075 // case TokenNamefalse :
4078 // case TokenNametrue :
4082 throwSyntaxError("Static scalar/constant expected.");
4086 private void non_empty_static_array_pair_list() {
4087 // non_empty_static_array_pair_list:
4088 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4090 // | non_empty_static_array_pair_list ',' static_scalar
4091 // | static_scalar T_DOUBLE_ARROW static_scalar
4095 if (token == TokenNameEQUAL_GREATER) {
4099 if (token != TokenNameCOMMA) {
4103 if (token == TokenNameRPAREN) {
4109 // public void reportSyntaxError() { //int act, int currentKind, int
4110 // // stateStackTop) {
4111 // /* remember current scanner position */
4112 // int startPos = scanner.startPosition;
4113 // int currentPos = scanner.currentPosition;
4115 // this.checkAndReportBracketAnomalies(problemReporter());
4116 // /* reset scanner where it was */
4117 // scanner.startPosition = startPos;
4118 // scanner.currentPosition = currentPos;
4121 public static final int RoundBracket = 0;
4123 public static final int SquareBracket = 1;
4125 public static final int CurlyBracket = 2;
4127 public static final int BracketKinds = 3;
4129 protected int[] nestedMethod; // the ptr is nestedType
4131 protected int nestedType, dimensions;
4133 // variable set stack
4134 final static int VariableStackIncrement = 10;
4136 HashMap fTypeVariables = null;
4138 HashMap fMethodVariables = null;
4140 ArrayList fStackUnassigned = new ArrayList();
4143 final static int AstStackIncrement = 100;
4145 protected int astPtr;
4147 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4149 protected int astLengthPtr;
4151 protected int[] astLengthStack;
4153 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4155 public CompilationUnitDeclaration compilationUnit; /*
4156 * the result from parse()
4159 protected ReferenceContext referenceContext;
4161 protected ProblemReporter problemReporter;
4163 protected CompilerOptions options;
4165 private ArrayList includesList;
4167 // protected CompilationResult compilationResult;
4169 * Returns this parser's problem reporter initialized with its reference
4170 * context. Also it is assumed that a problem is going to be reported, so
4171 * initializes the compilation result's line positions.
4173 public ProblemReporter problemReporter() {
4174 if (scanner.recordLineSeparator) {
4175 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4177 problemReporter.referenceContext = referenceContext;
4178 return problemReporter;
4182 * Reconsider the entire source looking for inconsistencies in {} () []
4184 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4185 // problemReporter) {
4186 // scanner.wasAcr = false;
4187 // boolean anomaliesDetected = false;
4189 // char[] source = scanner.source;
4190 // int[] leftCount = { 0, 0, 0 };
4191 // int[] rightCount = { 0, 0, 0 };
4192 // int[] depths = { 0, 0, 0 };
4193 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4195 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4196 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4198 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4200 // scanner.currentPosition = scanner.initialPosition; //starting
4202 // // (first-zero-based
4204 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4209 // // ---------Consume white space and handles
4210 // // startPosition---------
4211 // boolean isWhiteSpace;
4213 // scanner.startPosition = scanner.currentPosition;
4214 // // if (((scanner.currentCharacter =
4215 // // source[scanner.currentPosition++]) == '\\') &&
4216 // // (source[scanner.currentPosition] == 'u')) {
4217 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4219 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4220 // (scanner.currentCharacter == '\n'))) {
4221 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4222 // // only record line positions we have not
4224 // scanner.pushLineSeparator();
4227 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4229 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4230 // // -------consume token until } is found---------
4231 // switch (scanner.currentCharacter) {
4233 // int index = leftCount[CurlyBracket]++;
4234 // if (index == leftPositions[CurlyBracket].length) {
4235 // System.arraycopy(leftPositions[CurlyBracket], 0,
4236 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4237 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4238 // new int[index * 2]), 0, index);
4240 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4241 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4245 // int index = rightCount[CurlyBracket]++;
4246 // if (index == rightPositions[CurlyBracket].length) {
4247 // System.arraycopy(rightPositions[CurlyBracket], 0,
4248 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4249 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4250 // new int[index * 2]), 0, index);
4252 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4253 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4257 // int index = leftCount[RoundBracket]++;
4258 // if (index == leftPositions[RoundBracket].length) {
4259 // System.arraycopy(leftPositions[RoundBracket], 0,
4260 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4261 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4262 // new int[index * 2]), 0, index);
4264 // leftPositions[RoundBracket][index] = scanner.startPosition;
4265 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4269 // int index = rightCount[RoundBracket]++;
4270 // if (index == rightPositions[RoundBracket].length) {
4271 // System.arraycopy(rightPositions[RoundBracket], 0,
4272 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4273 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4274 // new int[index * 2]), 0, index);
4276 // rightPositions[RoundBracket][index] = scanner.startPosition;
4277 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4281 // int index = leftCount[SquareBracket]++;
4282 // if (index == leftPositions[SquareBracket].length) {
4283 // System.arraycopy(leftPositions[SquareBracket], 0,
4284 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4285 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4286 // new int[index * 2]), 0, index);
4288 // leftPositions[SquareBracket][index] = scanner.startPosition;
4289 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4293 // int index = rightCount[SquareBracket]++;
4294 // if (index == rightPositions[SquareBracket].length) {
4295 // System.arraycopy(rightPositions[SquareBracket], 0,
4296 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4297 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4298 // = new int[index * 2]), 0, index);
4300 // rightPositions[SquareBracket][index] = scanner.startPosition;
4301 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4305 // if (scanner.getNextChar('\\')) {
4306 // scanner.scanEscapeCharacter();
4307 // } else { // consume next character
4308 // scanner.unicodeAsBackSlash = false;
4309 // // if (((scanner.currentCharacter =
4310 // // source[scanner.currentPosition++]) ==
4312 // // (source[scanner.currentPosition] ==
4314 // // scanner.getNextUnicodeChar();
4316 // if (scanner.withoutUnicodePtr != 0) {
4317 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4318 // scanner.currentCharacter;
4322 // scanner.getNextChar('\'');
4326 // // consume next character
4327 // scanner.unicodeAsBackSlash = false;
4328 // // if (((scanner.currentCharacter =
4329 // // source[scanner.currentPosition++]) == '\\') &&
4330 // // (source[scanner.currentPosition] == 'u')) {
4331 // // scanner.getNextUnicodeChar();
4333 // if (scanner.withoutUnicodePtr != 0) {
4334 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4335 // scanner.currentCharacter;
4338 // while (scanner.currentCharacter != '"') {
4339 // if (scanner.currentCharacter == '\r') {
4340 // if (source[scanner.currentPosition] == '\n')
4341 // scanner.currentPosition++;
4342 // break; // the string cannot go further that
4345 // if (scanner.currentCharacter == '\n') {
4346 // break; // the string cannot go further that
4349 // if (scanner.currentCharacter == '\\') {
4350 // scanner.scanEscapeCharacter();
4352 // // consume next character
4353 // scanner.unicodeAsBackSlash = false;
4354 // // if (((scanner.currentCharacter =
4355 // // source[scanner.currentPosition++]) == '\\')
4356 // // && (source[scanner.currentPosition] == 'u'))
4358 // // scanner.getNextUnicodeChar();
4360 // if (scanner.withoutUnicodePtr != 0) {
4361 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4362 // scanner.currentCharacter;
4369 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4371 // //get the next char
4372 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4374 // && (source[scanner.currentPosition] == 'u')) {
4375 // //-------------unicode traitement
4377 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4378 // scanner.currentPosition++;
4379 // while (source[scanner.currentPosition] == 'u') {
4380 // scanner.currentPosition++;
4382 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4384 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4386 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4388 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4389 // || c4 < 0) { //error
4393 // scanner.currentCharacter = 'A';
4394 // } //something different from \n and \r
4396 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4399 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4401 // //get the next char
4402 // scanner.startPosition = scanner.currentPosition;
4403 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4405 // && (source[scanner.currentPosition] == 'u')) {
4406 // //-------------unicode traitement
4408 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4409 // scanner.currentPosition++;
4410 // while (source[scanner.currentPosition] == 'u') {
4411 // scanner.currentPosition++;
4413 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4415 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4417 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4419 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4420 // || c4 < 0) { //error
4424 // scanner.currentCharacter = 'A';
4425 // } //something different from \n
4428 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4432 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4433 // (scanner.currentCharacter == '\n'))) {
4434 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4435 // // only record line positions we
4436 // // have not recorded yet
4437 // scanner.pushLineSeparator();
4438 // if (this.scanner.taskTags != null) {
4439 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4441 // .getCurrentTokenEndPosition());
4447 // if (test > 0) { //traditional and annotation
4449 // boolean star = false;
4450 // // consume next character
4451 // scanner.unicodeAsBackSlash = false;
4452 // // if (((scanner.currentCharacter =
4453 // // source[scanner.currentPosition++]) ==
4455 // // (source[scanner.currentPosition] ==
4457 // // scanner.getNextUnicodeChar();
4459 // if (scanner.withoutUnicodePtr != 0) {
4460 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4461 // scanner.currentCharacter;
4464 // if (scanner.currentCharacter == '*') {
4467 // //get the next char
4468 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4470 // && (source[scanner.currentPosition] == 'u')) {
4471 // //-------------unicode traitement
4473 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4474 // scanner.currentPosition++;
4475 // while (source[scanner.currentPosition] == 'u') {
4476 // scanner.currentPosition++;
4478 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4480 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4482 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4484 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4485 // || c4 < 0) { //error
4489 // scanner.currentCharacter = 'A';
4490 // } //something different from * and /
4492 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4495 // //loop until end of comment */
4496 // while ((scanner.currentCharacter != '/') || (!star)) {
4497 // star = scanner.currentCharacter == '*';
4499 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4501 // && (source[scanner.currentPosition] == 'u')) {
4502 // //-------------unicode traitement
4504 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4505 // scanner.currentPosition++;
4506 // while (source[scanner.currentPosition] == 'u') {
4507 // scanner.currentPosition++;
4509 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4511 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4513 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4515 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4516 // || c4 < 0) { //error
4520 // scanner.currentCharacter = 'A';
4521 // } //something different from * and
4524 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4528 // if (this.scanner.taskTags != null) {
4529 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4530 // this.scanner.getCurrentTokenEndPosition());
4537 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4538 // scanner.scanIdentifierOrKeyword(false);
4541 // if (Character.isDigit(scanner.currentCharacter)) {
4542 // scanner.scanNumber(false);
4546 // //-----------------end switch while
4547 // // try--------------------
4548 // } catch (IndexOutOfBoundsException e) {
4549 // break; // read until EOF
4550 // } catch (InvalidInputException e) {
4551 // return false; // no clue
4554 // if (scanner.recordLineSeparator) {
4555 // compilationUnit.compilationResult.lineSeparatorPositions =
4556 // scanner.getLineEnds();
4558 // // check placement anomalies against other kinds of brackets
4559 // for (int kind = 0; kind < BracketKinds; kind++) {
4560 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4561 // int start = leftPositions[kind][leftIndex]; // deepest
4563 // // find matching closing bracket
4564 // int depth = leftDepths[kind][leftIndex];
4566 // for (int i = 0; i < rightCount[kind]; i++) {
4567 // int pos = rightPositions[kind][i];
4568 // // want matching bracket further in source with same
4570 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4575 // if (end < 0) { // did not find a good closing match
4576 // problemReporter.unmatchedBracket(start, referenceContext,
4577 // compilationUnit.compilationResult);
4580 // // check if even number of opening/closing other brackets
4581 // // in between this pair of brackets
4583 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4585 // for (int i = 0; i < leftCount[otherKind]; i++) {
4586 // int pos = leftPositions[otherKind][i];
4587 // if ((pos > start) && (pos < end))
4590 // for (int i = 0; i < rightCount[otherKind]; i++) {
4591 // int pos = rightPositions[otherKind][i];
4592 // if ((pos > start) && (pos < end))
4595 // if (balance != 0) {
4596 // problemReporter.unmatchedBracket(start, referenceContext,
4597 // compilationUnit.compilationResult); //bracket
4603 // // too many opening brackets ?
4604 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4605 // anomaliesDetected = true;
4606 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4607 // 1], referenceContext,
4608 // compilationUnit.compilationResult);
4610 // // too many closing brackets ?
4611 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4612 // anomaliesDetected = true;
4613 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4614 // compilationUnit.compilationResult);
4616 // if (anomaliesDetected)
4619 // return anomaliesDetected;
4620 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4621 // return anomaliesDetected;
4622 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4623 // return anomaliesDetected;
4626 protected void pushOnAstLengthStack(int pos) {
4628 astLengthStack[++astLengthPtr] = pos;
4629 } catch (IndexOutOfBoundsException e) {
4630 int oldStackLength = astLengthStack.length;
4631 int[] oldPos = astLengthStack;
4632 astLengthStack = new int[oldStackLength + StackIncrement];
4633 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4634 astLengthStack[astLengthPtr] = pos;
4638 protected void pushOnAstStack(ASTNode node) {
4640 * add a new obj on top of the ast stack
4643 astStack[++astPtr] = node;
4644 } catch (IndexOutOfBoundsException e) {
4645 int oldStackLength = astStack.length;
4646 ASTNode[] oldStack = astStack;
4647 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4648 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4649 astPtr = oldStackLength;
4650 astStack[astPtr] = node;
4653 astLengthStack[++astLengthPtr] = 1;
4654 } catch (IndexOutOfBoundsException e) {
4655 int oldStackLength = astLengthStack.length;
4656 int[] oldPos = astLengthStack;
4657 astLengthStack = new int[oldStackLength + AstStackIncrement];
4658 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4659 astLengthStack[astLengthPtr] = 1;
4663 protected void resetModifiers() {
4664 this.modifiers = AccDefault;
4665 this.modifiersSourceStart = -1; // <-- see comment into
4666 // modifiersFlag(int)
4667 this.scanner.commentPtr = -1;
4670 protected void consumePackageDeclarationName(IFile file) {
4671 // create a package name similar to java package names
4672 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4673 String filePath = file.getRawLocation().toString();
4674 String ext = file.getRawLocation().getFileExtension();
4675 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4676 ImportReference impt;
4678 if (filePath.startsWith(projectPath)) {
4679 tokens = CharOperation
4680 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4682 String name = file.getName();
4683 tokens = new char[1][];
4684 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4687 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4689 impt.declarationSourceStart = 0;
4690 impt.declarationSourceEnd = 0;
4691 impt.declarationEnd = 0;
4692 // endPosition is just before the ;
4696 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4697 "$_SESSION", "$_SERVER" };
4702 private void pushFunctionVariableSet() {
4703 HashSet set = new HashSet();
4704 if (fStackUnassigned.isEmpty()) {
4705 for (int i = 0; i < GLOBALS.length; i++) {
4706 set.add(GLOBALS[i]);
4709 fStackUnassigned.add(set);
4712 private void pushIfVariableSet() {
4713 if (!fStackUnassigned.isEmpty()) {
4714 HashSet set = new HashSet();
4715 fStackUnassigned.add(set);
4719 private HashSet removeIfVariableSet() {
4720 if (!fStackUnassigned.isEmpty()) {
4721 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4727 * Returns the <i>set of assigned variables </i> returns null if no Set is
4728 * defined at the current scanner position
4730 private HashSet peekVariableSet() {
4731 if (!fStackUnassigned.isEmpty()) {
4732 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4738 * add the current identifier source to the <i>set of assigned variables </i>
4742 private void addVariableSet(HashSet set) {
4744 set.add(new String(scanner.getCurrentTokenSource()));
4749 * add the current identifier source to the <i>set of assigned variables </i>
4752 private void addVariableSet() {
4753 HashSet set = peekVariableSet();
4755 set.add(new String(scanner.getCurrentTokenSource()));
4760 * add the current identifier source to the <i>set of assigned variables </i>
4763 private void addVariableSet(char[] token) {
4764 HashSet set = peekVariableSet();
4766 set.add(new String(token));
4771 * check if the current identifier source is in the <i>set of assigned
4772 * variables </i> Returns true, if no set is defined for the current scanner
4776 private boolean containsVariableSet() {
4777 return containsVariableSet(scanner.getCurrentTokenSource());
4780 private boolean containsVariableSet(char[] token) {
4782 if (!fStackUnassigned.isEmpty()) {
4784 String str = new String(token);
4785 for (int i = 0; i < fStackUnassigned.size(); i++) {
4786 set = (HashSet) fStackUnassigned.get(i);
4787 if (set.contains(str)) {