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.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
19 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
20 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
21 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
23 import net.sourceforge.phpdt.internal.compiler.util.Util;
24 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
25 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
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
77 // parts of the code/expressions like
80 public Scanner scanner;
82 // private ArrayList phpList;
84 // private int currentPHPString;
86 // private boolean phpEnd;
88 // private static HashMap keywordMap = null;
96 // row counter for syntax errors:
98 // column counter for syntax errors:
102 // // current identifier
103 // String identifier;
106 // Double doubleNumber;
108 // private String stringValue;
110 /** Contains the current expression. */
111 // private StringBuffer expression;
112 //private boolean phpMode;
113 protected int modifiers;
115 protected int modifiersSourceStart;
117 protected Parser(ProblemReporter problemReporter) {
118 this.problemReporter = problemReporter;
119 this.options = problemReporter.options;
120 // this.currentPHPString = 0;
121 // PHPParserSuperclass.fileToParse = fileToParse;
122 // this.phpList = null;
123 // this.indexManager = null;
125 this.token = TokenNameEOF;
127 // this.rowCount = 1;
128 // this.columnCount = 0;
129 // this.phpEnd = false;
131 this.initializeScanner();
134 public void setFileToParse(IFile fileToParse) {
135 // this.currentPHPString = 0;
136 // PHPParserSuperclass.fileToParse = fileToParse;
137 // this.phpList = null;
138 // this.indexManager = null;
140 this.token = TokenNameEOF;
141 // this.phpEnd = false;
142 this.initializeScanner();
146 * ClassDeclaration Constructor.
150 * Description of Parameter
153 public Parser(IFile fileToParse) {
154 // if (keywordMap == null) {
155 // keywordMap = new HashMap();
156 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
157 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
160 // this.currentPHPString = 0;
161 // PHPParserSuperclass.fileToParse = fileToParse;
162 // this.phpList = null;
163 this.includesList = null;
165 this.token = TokenNameEOF;
167 // this.rowCount = 1;
168 // this.columnCount = 0;
169 // this.phpEnd = false;
171 this.initializeScanner();
174 public void initializeScanner() {
175 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
176 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
177 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
181 * Create marker for the parse error
183 // private void setMarker(String message, int charStart, int charEnd, int
185 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
188 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
192 * @throws SyntaxError
195 private void throwSyntaxError(String error) {
196 int problemStartPosition = scanner.getCurrentTokenStartPosition();
197 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
198 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
199 problemEndPosition = scanner.source.length - 1;
200 if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
201 problemStartPosition = problemEndPosition - 1;
204 throwSyntaxError(error, problemStartPosition, problemEndPosition);
208 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
212 * @throws SyntaxError
215 // private void throwSyntaxError(String error, int startRow) {
216 // throw new SyntaxError(startRow, 0, " ", error);
218 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
219 if (referenceContext != null) {
220 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
221 compilationUnit.compilationResult);
223 throw new SyntaxError(1, 0, " ", error);
226 private void reportSyntaxError(String error) {
227 int problemStartPosition = scanner.getCurrentTokenStartPosition();
228 int problemEndPosition = scanner.getCurrentTokenEndPosition();
229 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
232 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
233 if (referenceContext != null) {
234 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
235 compilationUnit.compilationResult);
239 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
240 if (referenceContext != null) {
241 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
242 compilationUnit.compilationResult);
247 * gets the next token from input
249 private void getNextToken() {
251 token = scanner.getNextToken();
253 int currentEndPosition = scanner.getCurrentTokenEndPosition();
254 int currentStartPosition = scanner.getCurrentTokenStartPosition();
255 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
256 System.out.println(scanner.toStringAction(token));
258 } catch (InvalidInputException e) {
259 token = TokenNameERROR;
260 String detailedMessage = e.getMessage();
262 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
263 throwSyntaxError("Unterminated string.");
264 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
265 throwSyntaxError("Unterminated commment.");
271 public void init(String s) {
273 this.token = TokenNameEOF;
274 this.includesList = new ArrayList();
276 // this.rowCount = 1;
277 // this.columnCount = 0;
278 // this.phpEnd = false;
279 // this.phpMode = false;
280 /* scanner initialization */
281 scanner.setSource(s.toCharArray());
282 scanner.setPHPMode(false);
286 protected void initialize(boolean phpMode) {
287 initialize(phpMode, null);
290 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
291 compilationUnit = null;
292 referenceContext = null;
293 this.includesList = new ArrayList();
294 // this.indexManager = indexManager;
296 this.token = TokenNameEOF;
298 // this.rowCount = 1;
299 // this.columnCount = 0;
300 // this.phpEnd = false;
301 // this.phpMode = phpMode;
302 scanner.setPHPMode(phpMode);
307 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
309 public void parse(String s) {
314 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
316 public void parse(String s, HashMap variables) {
317 fMethodVariables = variables;
318 fStackUnassigned = new ArrayList();
324 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
326 protected void parse() {
327 if (scanner.compilationUnit != null) {
328 IResource resource = scanner.compilationUnit.getResource();
329 if (resource != null && resource instanceof IFile) {
330 // set the package name
331 consumePackageDeclarationName((IFile) resource);
337 if (token != TokenNameEOF && token != TokenNameERROR) {
340 if (token != TokenNameEOF) {
341 if (token == TokenNameERROR) {
342 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
344 if (token == TokenNameRPAREN) {
345 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
347 if (token == TokenNameRBRACE) {
348 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
350 if (token == TokenNameRBRACKET) {
351 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
353 if (token == TokenNameLPAREN) {
354 throwSyntaxError("Read character '('; end-of-file not reached.");
356 if (token == TokenNameLBRACE) {
357 throwSyntaxError("Read character '{'; end-of-file not reached.");
359 if (token == TokenNameLBRACKET) {
360 throwSyntaxError("Read character '['; end-of-file not reached.");
362 throwSyntaxError("End-of-file not reached.");
365 } catch (SyntaxError syntaxError) {
366 // syntaxError.printStackTrace();
375 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
377 public void parseFunction(String s, HashMap variables) {
379 scanner.phpMode = true;
380 parseFunction(variables);
384 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
386 protected void parseFunction(HashMap variables) {
388 boolean hasModifiers = member_modifiers();
389 if (token == TokenNamefunction) {
391 checkAndSetModifiers(AccPublic);
393 this.fMethodVariables = variables;
395 MethodDeclaration methodDecl = new MethodDeclaration(null);
396 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
397 methodDecl.modifiers = this.modifiers;
398 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
401 functionDefinition(methodDecl);
402 } catch (SyntaxError sytaxErr1) {
405 int sourceEnd = methodDecl.sourceEnd;
406 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
407 sourceEnd = methodDecl.declarationSourceStart + 1;
409 methodDecl.sourceEnd = sourceEnd;
410 methodDecl.declarationSourceEnd = sourceEnd;
415 protected CompilationUnitDeclaration endParse(int act) {
419 // if (currentElement != null) {
420 // currentElement.topElement().updateParseTree();
421 // if (VERBOSE_RECOVERY) {
422 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
423 // System.out.println("--------------------------"); //$NON-NLS-1$
424 // System.out.println(compilationUnit);
425 // System.out.println("----------------------------------"); //$NON-NLS-1$
428 if (diet & VERBOSE_RECOVERY) {
429 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
430 System.out.println("--------------------------"); //$NON-NLS-1$
431 System.out.println(compilationUnit);
432 System.out.println("----------------------------------"); //$NON-NLS-1$
435 if (scanner.recordLineSeparator) {
436 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
438 if (scanner.taskTags != null) {
439 for (int i = 0; i < scanner.foundTaskCount; i++) {
440 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
441 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
442 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
445 compilationUnit.imports = new ImportReference[includesList.size()];
446 for (int i = 0; i < includesList.size(); i++) {
447 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
449 return compilationUnit;
452 private Block statementList() {
453 boolean branchStatement = false;
455 int blockStart = scanner.getCurrentTokenStartPosition();
456 ArrayList blockStatements = new ArrayList();
459 statement = statement();
460 blockStatements.add(statement);
461 if (branchStatement && statement != null) {
462 // reportSyntaxError("Unreachable code", statement.sourceStart, statement.sourceEnd);
463 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
464 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
466 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
467 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
468 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
469 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
470 return createBlock(blockStart, blockStatements);
472 branchStatement = checkUnreachableStatements(statement);
473 } catch (SyntaxError sytaxErr1) {
474 // if an error occured,
475 // try to find keywords
476 // to parse the rest of the string
477 boolean tokenize = scanner.tokenizeStrings;
479 scanner.tokenizeStrings = true;
482 while (token != TokenNameEOF) {
483 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
484 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
485 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
486 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
487 return createBlock(blockStart, blockStatements);
489 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
490 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
491 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
492 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
493 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
494 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
497 // System.out.println(scanner.toStringAction(token));
499 // System.out.println(scanner.toStringAction(token));
501 if (token == TokenNameEOF) {
505 scanner.tokenizeStrings = tokenize;
515 private boolean checkUnreachableStatements(Statement statement) {
516 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
518 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
526 * @param blockStatements
529 private Block createBlock(int blockStart, ArrayList blockStatements) {
530 int blockEnd = scanner.getCurrentTokenEndPosition();
531 Block b = Block.EmptyWith(blockStart, blockEnd);
532 b.statements = new Statement[blockStatements.size()];
533 blockStatements.toArray(b.statements);
537 private void functionBody(MethodDeclaration methodDecl) {
538 // '{' [statement-list] '}'
539 if (token == TokenNameLBRACE) {
542 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
543 throwSyntaxError("'{' expected in compound-statement.");
545 if (token != TokenNameRBRACE) {
548 if (token == TokenNameRBRACE) {
549 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
552 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
553 throwSyntaxError("'}' expected in compound-statement.");
557 private Statement statement() {
558 Statement statement = null;
559 Expression expression;
560 int sourceStart = scanner.getCurrentTokenStartPosition();
562 if (token == TokenNameif) {
563 // T_IF '(' expr ')' statement elseif_list else_single
564 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
566 if (token == TokenNameLPAREN) {
569 throwSyntaxError("'(' expected after 'if' keyword.");
572 if (token == TokenNameRPAREN) {
575 throwSyntaxError("')' expected after 'if' condition.");
577 // create basic IfStatement
578 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
579 if (token == TokenNameCOLON) {
581 ifStatementColon(ifStatement);
583 ifStatement(ifStatement);
586 } else if (token == TokenNameswitch) {
588 if (token == TokenNameLPAREN) {
591 throwSyntaxError("'(' expected after 'switch' keyword.");
594 if (token == TokenNameRPAREN) {
597 throwSyntaxError("')' expected after 'switch' condition.");
601 } else if (token == TokenNamefor) {
603 if (token == TokenNameLPAREN) {
606 throwSyntaxError("'(' expected after 'for' keyword.");
608 if (token == TokenNameSEMICOLON) {
612 if (token == TokenNameSEMICOLON) {
615 throwSyntaxError("';' expected after 'for'.");
618 if (token == TokenNameSEMICOLON) {
622 if (token == TokenNameSEMICOLON) {
625 throwSyntaxError("';' expected after 'for'.");
628 if (token == TokenNameRPAREN) {
632 if (token == TokenNameRPAREN) {
635 throwSyntaxError("')' expected after 'for'.");
640 } else if (token == TokenNamewhile) {
642 if (token == TokenNameLPAREN) {
645 throwSyntaxError("'(' expected after 'while' keyword.");
648 if (token == TokenNameRPAREN) {
651 throwSyntaxError("')' expected after 'while' condition.");
655 } else if (token == TokenNamedo) {
657 if (token == TokenNameLBRACE) {
659 if (token != TokenNameRBRACE) {
662 if (token == TokenNameRBRACE) {
665 throwSyntaxError("'}' expected after 'do' keyword.");
670 if (token == TokenNamewhile) {
672 if (token == TokenNameLPAREN) {
675 throwSyntaxError("'(' expected after 'while' keyword.");
678 if (token == TokenNameRPAREN) {
681 throwSyntaxError("')' expected after 'while' condition.");
684 throwSyntaxError("'while' expected after 'do' keyword.");
686 if (token == TokenNameSEMICOLON) {
689 if (token != TokenNameINLINE_HTML) {
690 throwSyntaxError("';' expected after do-while statement.");
695 } else if (token == TokenNameforeach) {
697 if (token == TokenNameLPAREN) {
700 throwSyntaxError("'(' expected after 'foreach' keyword.");
703 if (token == TokenNameas) {
706 throwSyntaxError("'as' expected after 'foreach' exxpression.");
710 foreach_optional_arg();
711 if (token == TokenNameEQUAL_GREATER) {
713 variable(false, false);
715 if (token == TokenNameRPAREN) {
718 throwSyntaxError("')' expected after 'foreach' expression.");
722 } else if (token == TokenNamebreak) {
725 if (token != TokenNameSEMICOLON) {
728 if (token == TokenNameSEMICOLON) {
729 sourceEnd = scanner.getCurrentTokenEndPosition();
732 if (token != TokenNameINLINE_HTML) {
733 throwSyntaxError("';' expected after 'break'.");
735 sourceEnd = scanner.getCurrentTokenEndPosition();
738 return new BreakStatement(null, sourceStart, sourceEnd);
739 } else if (token == TokenNamecontinue) {
742 if (token != TokenNameSEMICOLON) {
745 if (token == TokenNameSEMICOLON) {
746 sourceEnd = scanner.getCurrentTokenEndPosition();
749 if (token != TokenNameINLINE_HTML) {
750 throwSyntaxError("';' expected after 'continue'.");
752 sourceEnd = scanner.getCurrentTokenEndPosition();
755 return new ContinueStatement(null, sourceStart, sourceEnd);
756 } else if (token == TokenNamereturn) {
759 if (token != TokenNameSEMICOLON) {
762 if (token == TokenNameSEMICOLON) {
763 sourceEnd = scanner.getCurrentTokenEndPosition();
766 if (token != TokenNameINLINE_HTML) {
767 throwSyntaxError("';' expected after 'return'.");
769 sourceEnd = scanner.getCurrentTokenEndPosition();
772 return new ReturnStatement(expression, sourceStart, sourceEnd);
773 } else if (token == TokenNameecho) {
776 if (token == TokenNameSEMICOLON) {
779 if (token != TokenNameINLINE_HTML) {
780 throwSyntaxError("';' expected after 'echo' statement.");
785 } else if (token == TokenNameINLINE_HTML) {
786 if (scanner.phpExpressionTag) {
787 // start of <?= ... ?> block
790 if (token == TokenNameSEMICOLON) {
793 if (token != TokenNameINLINE_HTML) {
794 throwSyntaxError("Missing '?>' for open PHP expression block ('<?=').");
800 // } else if (token == TokenNameprint) {
803 // if (token == TokenNameSEMICOLON) {
806 // if (token != TokenNameStopPHP) {
807 // throwSyntaxError("';' expected after 'print' statement.");
812 } else if (token == TokenNameglobal) {
815 if (token == TokenNameSEMICOLON) {
818 if (token != TokenNameINLINE_HTML) {
819 throwSyntaxError("';' expected after 'global' statement.");
824 } else if (token == TokenNamestatic) {
827 if (token == TokenNameSEMICOLON) {
830 if (token != TokenNameINLINE_HTML) {
831 throwSyntaxError("';' expected after 'static' statement.");
836 } else if (token == TokenNameunset) {
838 if (token == TokenNameLPAREN) {
841 throwSyntaxError("'(' expected after 'unset' statement.");
844 if (token == TokenNameRPAREN) {
847 throwSyntaxError("')' expected after 'unset' statement.");
849 if (token == TokenNameSEMICOLON) {
852 if (token != TokenNameINLINE_HTML) {
853 throwSyntaxError("';' expected after 'unset' statement.");
858 } else if (token == TokenNamefunction) {
859 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
860 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
861 methodDecl.modifiers = AccDefault;
862 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
865 functionDefinition(methodDecl);
867 sourceEnd = methodDecl.sourceEnd;
868 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
869 sourceEnd = methodDecl.declarationSourceStart + 1;
871 methodDecl.declarationSourceEnd = sourceEnd;
872 methodDecl.sourceEnd = sourceEnd;
875 } else if (token == TokenNamedeclare) {
876 //T_DECLARE '(' declare_list ')' declare_statement
878 if (token != TokenNameLPAREN) {
879 throwSyntaxError("'(' expected in 'declare' statement.");
883 if (token != TokenNameRPAREN) {
884 throwSyntaxError("')' expected in 'declare' statement.");
889 } else if (token == TokenNametry) {
891 if (token != TokenNameLBRACE) {
892 throwSyntaxError("'{' expected in 'try' statement.");
896 if (token != TokenNameRBRACE) {
897 throwSyntaxError("'}' expected in 'try' statement.");
901 } else if (token == TokenNamecatch) {
903 if (token != TokenNameLPAREN) {
904 throwSyntaxError("'(' expected in 'catch' statement.");
907 fully_qualified_class_name();
908 if (token != TokenNameVariable) {
909 throwSyntaxError("Variable expected in 'catch' statement.");
912 if (token != TokenNameRPAREN) {
913 throwSyntaxError("')' expected in 'catch' statement.");
916 if (token != TokenNameLBRACE) {
917 throwSyntaxError("'{' expected in 'catch' statement.");
920 if (token != TokenNameRBRACE) {
922 if (token != TokenNameRBRACE) {
923 throwSyntaxError("'}' expected in 'catch' statement.");
927 additional_catches();
929 } else if (token == TokenNamethrow) {
932 if (token == TokenNameSEMICOLON) {
935 throwSyntaxError("';' expected after 'throw' exxpression.");
938 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
940 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
941 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
942 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
943 typeDecl.name = new char[] { ' ' };
944 // default super class
945 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
946 compilationUnit.types.add(typeDecl);
947 pushOnAstStack(typeDecl);
948 unticked_class_declaration_statement(typeDecl);
956 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
957 } else if (token == TokenNameLBRACE) {
959 if (token != TokenNameRBRACE) {
960 statement = statementList();
962 if (token == TokenNameRBRACE) {
966 throwSyntaxError("'}' expected.");
969 if (token != TokenNameSEMICOLON) {
972 if (token == TokenNameSEMICOLON) {
976 if (token == TokenNameRBRACE) {
977 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
979 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
980 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
990 private void declare_statement() {
992 //| ':' inner_statement_list T_ENDDECLARE ';'
994 if (token == TokenNameCOLON) {
996 // TODO: implement inner_statement_list();
998 if (token != TokenNameenddeclare) {
999 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1002 if (token != TokenNameSEMICOLON) {
1003 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1011 private void declare_list() {
1012 // T_STRING '=' static_scalar
1013 //| declare_list ',' T_STRING '=' static_scalar
1015 if (token != TokenNameIdentifier) {
1016 throwSyntaxError("Identifier expected in 'declare' list.");
1019 if (token != TokenNameEQUAL) {
1020 throwSyntaxError("'=' expected in 'declare' list.");
1024 if (token != TokenNameCOMMA) {
1031 private void additional_catches() {
1032 while (token == TokenNamecatch) {
1034 if (token != TokenNameLPAREN) {
1035 throwSyntaxError("'(' expected in 'catch' statement.");
1038 fully_qualified_class_name();
1039 if (token != TokenNameVariable) {
1040 throwSyntaxError("Variable expected in 'catch' statement.");
1043 if (token != TokenNameRPAREN) {
1044 throwSyntaxError("')' expected in 'catch' statement.");
1047 if (token != TokenNameLBRACE) {
1048 throwSyntaxError("'{' expected in 'catch' statement.");
1051 if (token != TokenNameRBRACE) {
1054 if (token != TokenNameRBRACE) {
1055 throwSyntaxError("'}' expected in 'catch' statement.");
1061 private void foreach_variable() {
1064 if (token == TokenNameAND) {
1070 private void foreach_optional_arg() {
1072 //| T_DOUBLE_ARROW foreach_variable
1073 if (token == TokenNameEQUAL_GREATER) {
1079 private void global_var_list() {
1081 // global_var_list ',' global_var
1083 HashSet set = peekVariableSet();
1086 if (token != TokenNameCOMMA) {
1093 private void global_var(HashSet set) {
1097 //| '$' '{' expr '}'
1098 if (token == TokenNameVariable) {
1099 if (fMethodVariables != null) {
1100 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1101 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1103 addVariableSet(set);
1105 } else if (token == TokenNameDOLLAR) {
1107 if (token == TokenNameLBRACE) {
1110 if (token != TokenNameRBRACE) {
1111 throwSyntaxError("'}' expected in global variable.");
1120 private void static_var_list() {
1122 // static_var_list ',' T_VARIABLE
1123 //| static_var_list ',' T_VARIABLE '=' static_scalar
1125 //| T_VARIABLE '=' static_scalar,
1126 HashSet set = peekVariableSet();
1128 if (token == TokenNameVariable) {
1129 if (fMethodVariables != null) {
1130 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1131 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1133 addVariableSet(set);
1135 if (token == TokenNameEQUAL) {
1139 if (token != TokenNameCOMMA) {
1149 private void unset_variables() {
1152 // | unset_variables ',' unset_variable
1156 variable(false, false);
1157 if (token != TokenNameCOMMA) {
1164 private final void initializeModifiers() {
1166 this.modifiersSourceStart = -1;
1169 private final void checkAndSetModifiers(int flag) {
1170 this.modifiers |= flag;
1171 if (this.modifiersSourceStart < 0)
1172 this.modifiersSourceStart = this.scanner.startPosition;
1175 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1176 initializeModifiers();
1177 if (token == TokenNameinterface) {
1178 // interface_entry T_STRING
1179 // interface_extends_list
1180 // '{' class_statement_list '}'
1181 checkAndSetModifiers(AccInterface);
1183 typeDecl.modifiers = this.modifiers;
1184 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1185 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1186 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1187 typeDecl.name = scanner.getCurrentIdentifierSource();
1188 if (token > TokenNameKEYWORD) {
1189 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1190 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1191 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1192 // typeDecl.sourceStart, typeDecl.sourceEnd);
1195 interface_extends_list(typeDecl);
1197 typeDecl.name = new char[] { ' ' };
1198 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1202 // class_entry_type T_STRING extends_from
1204 // '{' class_statement_list'}'
1206 typeDecl.modifiers = this.modifiers;
1207 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1208 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1210 //identifier 'extends' identifier
1211 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1212 typeDecl.name = scanner.getCurrentIdentifierSource();
1213 if (token > TokenNameKEYWORD) {
1214 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1215 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1216 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1217 // typeDecl.sourceStart, typeDecl.sourceEnd);
1222 // | T_EXTENDS fully_qualified_class_name
1223 if (token == TokenNameextends) {
1224 interface_extends_list(typeDecl);
1226 // if (token != TokenNameIdentifier) {
1227 // throwSyntaxError("Class name expected after keyword
1229 // scanner.getCurrentTokenStartPosition(), scanner
1230 // .getCurrentTokenEndPosition());
1233 implements_list(typeDecl);
1235 typeDecl.name = new char[] { ' ' };
1236 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1240 // '{' class_statement_list '}'
1241 if (token == TokenNameLBRACE) {
1243 if (token != TokenNameRBRACE) {
1244 ArrayList list = new ArrayList();
1245 class_statement_list(list);
1246 typeDecl.fields = new FieldDeclaration[list.size()];
1247 for (int i = 0; i < list.size(); i++) {
1248 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1251 if (token == TokenNameRBRACE) {
1252 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1255 throwSyntaxError("'}' expected at end of class body.");
1258 throwSyntaxError("'{' expected at start of class body.");
1262 private void class_entry_type() {
1264 // | T_ABSTRACT T_CLASS
1265 // | T_FINAL T_CLASS
1266 if (token == TokenNameclass) {
1268 } else if (token == TokenNameabstract) {
1269 checkAndSetModifiers(AccAbstract);
1271 if (token != TokenNameclass) {
1272 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1275 } else if (token == TokenNamefinal) {
1276 checkAndSetModifiers(AccFinal);
1278 if (token != TokenNameclass) {
1279 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1283 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1287 private void class_extends(TypeDeclaration typeDecl) {
1289 // | T_EXTENDS interface_list
1290 if (token == TokenNameextends) {
1293 if (token == TokenNameIdentifier) {
1296 throwSyntaxError("Class name expected after keyword 'extends'.");
1301 private void interface_extends_list(TypeDeclaration typeDecl) {
1303 // | T_EXTENDS interface_list
1304 if (token == TokenNameextends) {
1310 private void implements_list(TypeDeclaration typeDecl) {
1312 // | T_IMPLEMENTS interface_list
1313 if (token == TokenNameimplements) {
1319 private void interface_list() {
1321 // fully_qualified_class_name
1322 //| interface_list ',' fully_qualified_class_name
1324 if (token == TokenNameIdentifier) {
1327 throwSyntaxError("Interface name expected after keyword 'implements'.");
1329 if (token != TokenNameCOMMA) {
1336 // private void classBody(TypeDeclaration typeDecl) {
1337 // //'{' [class-element-list] '}'
1338 // if (token == TokenNameLBRACE) {
1340 // if (token != TokenNameRBRACE) {
1341 // class_statement_list();
1343 // if (token == TokenNameRBRACE) {
1344 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1347 // throwSyntaxError("'}' expected at end of class body.");
1350 // throwSyntaxError("'{' expected at start of class body.");
1353 private void class_statement_list(ArrayList list) {
1356 class_statement(list);
1357 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1358 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1359 || token == TokenNameconst) {
1362 if (token == TokenNameRBRACE) {
1365 throwSyntaxError("'}' at end of class statement.");
1366 } catch (SyntaxError sytaxErr1) {
1367 boolean tokenize = scanner.tokenizeStrings;
1369 scanner.tokenizeStrings = true;
1372 // if an error occured,
1373 // try to find keywords
1374 // to parse the rest of the string
1375 while (token != TokenNameEOF) {
1376 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1377 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1378 || token == TokenNameconst) {
1381 // System.out.println(scanner.toStringAction(token));
1384 if (token == TokenNameEOF) {
1388 scanner.tokenizeStrings = tokenize;
1394 private void class_statement(ArrayList list) {
1396 // variable_modifiers class_variable_declaration ';'
1397 // | class_constant_declaration ';'
1398 // | method_modifiers T_FUNCTION is_reference T_STRING
1399 // '(' parameter_list ')' method_body
1400 initializeModifiers();
1401 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1403 if (token == TokenNamevar) {
1404 checkAndSetModifiers(AccPublic);
1405 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1406 referenceContext, compilationUnit.compilationResult);
1408 class_variable_declaration(declarationSourceStart, list);
1409 } else if (token == TokenNameconst) {
1410 checkAndSetModifiers(AccFinal | AccPublic);
1411 class_constant_declaration(declarationSourceStart, list);
1412 if (token != TokenNameSEMICOLON) {
1413 throwSyntaxError("';' expected after class const declaration.");
1417 boolean hasModifiers = member_modifiers();
1418 if (token == TokenNamefunction) {
1419 if (!hasModifiers) {
1420 checkAndSetModifiers(AccPublic);
1422 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1423 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1424 methodDecl.modifiers = this.modifiers;
1425 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1428 functionDefinition(methodDecl);
1430 int sourceEnd = methodDecl.sourceEnd;
1431 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1432 sourceEnd = methodDecl.declarationSourceStart + 1;
1434 methodDecl.declarationSourceEnd = sourceEnd;
1435 methodDecl.sourceEnd = sourceEnd;
1438 if (!hasModifiers) {
1439 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1441 class_variable_declaration(declarationSourceStart, list);
1446 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1447 // class_constant_declaration ',' T_STRING '=' static_scalar
1448 // | T_CONST T_STRING '=' static_scalar
1449 if (token != TokenNameconst) {
1450 throwSyntaxError("'const' keyword expected in class declaration.");
1455 if (token != TokenNameIdentifier) {
1456 throwSyntaxError("Identifier expected in class const declaration.");
1458 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1459 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1460 fieldDeclaration.modifiers = this.modifiers;
1461 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1462 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1463 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1464 // fieldDeclaration.type
1465 list.add(fieldDeclaration);
1467 if (token != TokenNameEQUAL) {
1468 throwSyntaxError("'=' expected in class const declaration.");
1472 if (token != TokenNameCOMMA) {
1473 break; // while(true)-loop
1479 // private void variable_modifiers() {
1480 // // variable_modifiers:
1481 // // non_empty_member_modifiers
1483 // initializeModifiers();
1484 // if (token == TokenNamevar) {
1485 // checkAndSetModifiers(AccPublic);
1486 // reportSyntaxError(
1487 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1489 // modifier for field declarations.",
1490 // scanner.getCurrentTokenStartPosition(), scanner
1491 // .getCurrentTokenEndPosition());
1494 // if (!member_modifiers()) {
1495 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1496 // field declarations.");
1500 // private void method_modifiers() {
1501 // //method_modifiers:
1503 // //| non_empty_member_modifiers
1504 // initializeModifiers();
1505 // if (!member_modifiers()) {
1506 // checkAndSetModifiers(AccPublic);
1509 private boolean member_modifiers() {
1516 boolean foundToken = false;
1518 if (token == TokenNamepublic) {
1519 checkAndSetModifiers(AccPublic);
1522 } else if (token == TokenNameprotected) {
1523 checkAndSetModifiers(AccProtected);
1526 } else if (token == TokenNameprivate) {
1527 checkAndSetModifiers(AccPrivate);
1530 } else if (token == TokenNamestatic) {
1531 checkAndSetModifiers(AccStatic);
1534 } else if (token == TokenNameabstract) {
1535 checkAndSetModifiers(AccAbstract);
1538 } else if (token == TokenNamefinal) {
1539 checkAndSetModifiers(AccFinal);
1549 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1550 // class_variable_declaration:
1551 // class_variable_declaration ',' T_VARIABLE
1552 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1554 // | T_VARIABLE '=' static_scalar
1555 char[] classVariable;
1557 if (token == TokenNameVariable) {
1558 classVariable = scanner.getCurrentIdentifierSource();
1559 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1560 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1561 .getCurrentTokenEndPosition());
1562 fieldDeclaration.modifiers = this.modifiers;
1563 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1564 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1565 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1566 list.add(fieldDeclaration);
1567 if (fTypeVariables != null) {
1568 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1569 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1572 if (token == TokenNameEQUAL) {
1577 // if (token == TokenNamethis) {
1578 // throwSyntaxError("'$this' not allowed after keyword 'public'
1579 // 'protected' 'private' 'var'.");
1581 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1583 if (token != TokenNameCOMMA) {
1588 if (token != TokenNameSEMICOLON) {
1589 throwSyntaxError("';' expected after field declaration.");
1594 private void functionDefinition(MethodDeclaration methodDecl) {
1595 boolean isAbstract = false;
1597 if (compilationUnit != null) {
1598 compilationUnit.types.add(methodDecl);
1601 ASTNode node = astStack[astPtr];
1602 if (node instanceof TypeDeclaration) {
1603 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1604 if (typeDecl.methods == null) {
1605 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1607 AbstractMethodDeclaration[] newMethods;
1608 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1609 typeDecl.methods.length);
1610 newMethods[typeDecl.methods.length] = methodDecl;
1611 typeDecl.methods = newMethods;
1613 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1615 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1621 pushFunctionVariableSet();
1622 functionDeclarator(methodDecl);
1623 if (token == TokenNameSEMICOLON) {
1625 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1626 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1631 functionBody(methodDecl);
1633 if (!fStackUnassigned.isEmpty()) {
1634 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1639 private void functionDeclarator(MethodDeclaration methodDecl) {
1640 //identifier '(' [parameter-list] ')'
1641 if (token == TokenNameAND) {
1644 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1645 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1646 if (Scanner.isIdentifierOrKeyword(token)) {
1647 methodDecl.selector = scanner.getCurrentIdentifierSource();
1648 if (token > TokenNameKEYWORD) {
1649 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1650 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1653 if (token == TokenNameLPAREN) {
1656 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1657 throwSyntaxError("'(' expected in function declaration.");
1659 if (token != TokenNameRPAREN) {
1660 parameter_list(methodDecl);
1662 if (token != TokenNameRPAREN) {
1663 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1664 throwSyntaxError("')' expected in function declaration.");
1666 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1670 methodDecl.selector = "<undefined>".toCharArray();
1671 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1672 throwSyntaxError("Function name expected after keyword 'function'.");
1677 private void parameter_list(MethodDeclaration methodDecl) {
1678 // non_empty_parameter_list
1680 non_empty_parameter_list(methodDecl, true);
1683 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1684 // optional_class_type T_VARIABLE
1685 // | optional_class_type '&' T_VARIABLE
1686 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1687 // | optional_class_type T_VARIABLE '=' static_scalar
1688 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1689 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1690 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1692 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1694 char[] typeIdentifier = null;
1695 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1696 HashSet set = peekVariableSet();
1698 if (token == TokenNameIdentifier) {
1699 typeIdentifier = scanner.getCurrentIdentifierSource();
1702 if (token == TokenNameAND) {
1705 if (token == TokenNameVariable) {
1706 if (fMethodVariables != null) {
1708 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1709 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1711 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1713 info.typeIdentifier = typeIdentifier;
1714 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1716 addVariableSet(set);
1718 if (token == TokenNameEQUAL) {
1723 throwSyntaxError("Variable expected in parameter list.");
1725 if (token != TokenNameCOMMA) {
1732 if (!empty_allowed) {
1733 throwSyntaxError("Identifier expected in parameter list.");
1737 private void optional_class_type() {
1742 // private void parameterDeclaration() {
1744 // //variable-reference
1745 // if (token == TokenNameAND) {
1747 // if (isVariable()) {
1750 // throwSyntaxError("Variable expected after reference operator '&'.");
1753 // //variable '=' constant
1754 // if (token == TokenNameVariable) {
1756 // if (token == TokenNameEQUAL) {
1762 // // if (token == TokenNamethis) {
1763 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1764 // // declaration.");
1768 private void labeledStatementList() {
1769 if (token != TokenNamecase && token != TokenNamedefault) {
1770 throwSyntaxError("'case' or 'default' expected.");
1773 if (token == TokenNamecase) {
1775 expr(); //constant();
1776 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1778 if (token == TokenNamecase || token == TokenNamedefault) {
1779 // empty case statement ?
1784 // else if (token == TokenNameSEMICOLON) {
1786 // "':' expected after 'case' keyword (Found token: " +
1787 // scanner.toStringAction(token) + ")",
1788 // scanner.getCurrentTokenStartPosition(),
1789 // scanner.getCurrentTokenEndPosition(),
1792 // if (token == TokenNamecase) { // empty case statement ?
1798 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1800 } else { // TokenNamedefault
1802 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1804 if (token == TokenNameRBRACE) {
1805 // empty default case
1808 if (token != TokenNamecase) {
1812 throwSyntaxError("':' character expected after 'default'.");
1815 } while (token == TokenNamecase || token == TokenNamedefault);
1818 private void ifStatementColon(IfStatement iState) {
1819 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
1820 HashSet assignedVariableSet = null;
1822 Block b = inner_statement_list();
1823 iState.thenStatement = b;
1824 checkUnreachable(iState, b);
1826 assignedVariableSet = removeIfVariableSet();
1828 if (token == TokenNameelseif) {
1830 pushIfVariableSet();
1831 new_elseif_list(iState);
1833 HashSet set = removeIfVariableSet();
1834 if (assignedVariableSet != null) {
1835 assignedVariableSet.addAll(set);
1840 pushIfVariableSet();
1841 new_else_single(iState);
1843 HashSet set = removeIfVariableSet();
1844 if (assignedVariableSet != null) {
1845 HashSet topSet = peekVariableSet();
1846 if (topSet != null) {
1848 topSet.addAll(assignedVariableSet);
1852 if (token != TokenNameendif) {
1853 throwSyntaxError("'endif' expected.");
1856 if (token != TokenNameSEMICOLON) {
1857 reportSyntaxError("';' expected after if-statement.");
1858 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1860 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1865 private void ifStatement(IfStatement iState) {
1866 // T_IF '(' expr ')' statement elseif_list else_single
1867 HashSet assignedVariableSet = null;
1869 pushIfVariableSet();
1870 Statement s = statement();
1871 iState.thenStatement = s;
1872 checkUnreachable(iState, s);
1874 assignedVariableSet = removeIfVariableSet();
1877 if (token == TokenNameelseif) {
1879 pushIfVariableSet();
1880 elseif_list(iState);
1882 HashSet set = removeIfVariableSet();
1883 if (assignedVariableSet != null) {
1884 assignedVariableSet.addAll(set);
1889 pushIfVariableSet();
1890 else_single(iState);
1892 HashSet set = removeIfVariableSet();
1893 if (assignedVariableSet != null) {
1894 HashSet topSet = peekVariableSet();
1895 if (topSet != null) {
1897 topSet.addAll(assignedVariableSet);
1903 private void elseif_list(IfStatement iState) {
1905 //| elseif_list T_ELSEIF '(' expr ')' statement
1906 ArrayList conditionList = new ArrayList();
1907 ArrayList statementList = new ArrayList();
1910 while (token == TokenNameelseif) {
1912 if (token == TokenNameLPAREN) {
1915 throwSyntaxError("'(' expected after 'elseif' keyword.");
1918 conditionList.add(e);
1919 if (token == TokenNameRPAREN) {
1922 throwSyntaxError("')' expected after 'elseif' condition.");
1925 statementList.add(s);
1926 checkUnreachable(iState, s);
1928 iState.elseifConditions = new Expression[conditionList.size()];
1929 iState.elseifStatements = new Statement[statementList.size()];
1930 conditionList.toArray(iState.elseifConditions);
1931 statementList.toArray(iState.elseifStatements);
1934 private void new_elseif_list(IfStatement iState) {
1936 //| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1937 ArrayList conditionList = new ArrayList();
1938 ArrayList statementList = new ArrayList();
1941 while (token == TokenNameelseif) {
1943 if (token == TokenNameLPAREN) {
1946 throwSyntaxError("'(' expected after 'elseif' keyword.");
1949 conditionList.add(e);
1950 if (token == TokenNameRPAREN) {
1953 throwSyntaxError("')' expected after 'elseif' condition.");
1955 if (token == TokenNameCOLON) {
1958 throwSyntaxError("':' expected after 'elseif' keyword.");
1960 b = inner_statement_list();
1961 statementList.add(b);
1962 checkUnreachable(iState, b);
1964 iState.elseifConditions = new Expression[conditionList.size()];
1965 iState.elseifStatements = new Statement[statementList.size()];
1966 conditionList.toArray(iState.elseifConditions);
1967 statementList.toArray(iState.elseifStatements);
1970 private void else_single(IfStatement iState) {
1973 if (token == TokenNameelse) {
1975 Statement s = statement();
1976 iState.elseStatement = s;
1977 checkUnreachable(iState, s);
1979 iState.checkUnreachable = false;
1981 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1984 private void new_else_single(IfStatement iState) {
1986 //| T_ELSE ':' inner_statement_list
1987 if (token == TokenNameelse) {
1989 if (token == TokenNameCOLON) {
1992 throwSyntaxError("':' expected after 'else' keyword.");
1994 Block b = inner_statement_list();
1995 iState.elseStatement = b;
1996 checkUnreachable(iState, b);
1998 iState.checkUnreachable = false;
2002 private Block inner_statement_list() {
2003 // inner_statement_list inner_statement
2005 return statementList();
2012 private void checkUnreachable(IfStatement iState, Statement s) {
2013 if (s instanceof Block) {
2014 Block b = (Block) s;
2015 if (b.statements == null || b.statements.length == 0) {
2016 iState.checkUnreachable = false;
2018 int off = b.statements.length - 1;
2019 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2020 && !(b.statements[off] instanceof BreakStatement)) {
2021 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2022 iState.checkUnreachable = false;
2027 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2028 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2029 iState.checkUnreachable = false;
2035 // private void elseifStatementList() {
2037 // elseifStatement();
2039 // case TokenNameelse:
2041 // if (token == TokenNameCOLON) {
2043 // if (token != TokenNameendif) {
2048 // if (token == TokenNameif) { //'else if'
2051 // throwSyntaxError("':' expected after 'else'.");
2055 // case TokenNameelseif:
2064 // private void elseifStatement() {
2065 // if (token == TokenNameLPAREN) {
2068 // if (token != TokenNameRPAREN) {
2069 // throwSyntaxError("')' expected in else-if-statement.");
2072 // if (token != TokenNameCOLON) {
2073 // throwSyntaxError("':' expected in else-if-statement.");
2076 // if (token != TokenNameendif) {
2082 private void switchStatement() {
2083 if (token == TokenNameCOLON) {
2084 // ':' [labeled-statement-list] 'endswitch' ';'
2086 labeledStatementList();
2087 if (token != TokenNameendswitch) {
2088 throwSyntaxError("'endswitch' expected.");
2091 if (token != TokenNameSEMICOLON) {
2092 throwSyntaxError("';' expected after switch-statement.");
2096 // '{' [labeled-statement-list] '}'
2097 if (token != TokenNameLBRACE) {
2098 throwSyntaxError("'{' expected in switch statement.");
2101 if (token != TokenNameRBRACE) {
2102 labeledStatementList();
2104 if (token != TokenNameRBRACE) {
2105 throwSyntaxError("'}' expected in switch statement.");
2111 private void forStatement() {
2112 if (token == TokenNameCOLON) {
2115 if (token != TokenNameendfor) {
2116 throwSyntaxError("'endfor' expected.");
2119 if (token != TokenNameSEMICOLON) {
2120 throwSyntaxError("';' expected after for-statement.");
2128 private void whileStatement() {
2129 // ':' statement-list 'endwhile' ';'
2130 if (token == TokenNameCOLON) {
2133 if (token != TokenNameendwhile) {
2134 throwSyntaxError("'endwhile' expected.");
2137 if (token != TokenNameSEMICOLON) {
2138 throwSyntaxError("';' expected after while-statement.");
2146 private void foreachStatement() {
2147 if (token == TokenNameCOLON) {
2150 if (token != TokenNameendforeach) {
2151 throwSyntaxError("'endforeach' expected.");
2154 if (token != TokenNameSEMICOLON) {
2155 throwSyntaxError("';' expected after foreach-statement.");
2163 // private void exitStatus() {
2164 // if (token == TokenNameLPAREN) {
2167 // throwSyntaxError("'(' expected in 'exit-status'.");
2169 // if (token != TokenNameRPAREN) {
2172 // if (token == TokenNameRPAREN) {
2175 // throwSyntaxError("')' expected after 'exit-status'.");
2178 private void expressionList() {
2181 if (token == TokenNameCOMMA) {
2189 private Expression expr() {
2191 // | expr_without_variable
2192 // if (token!=TokenNameEOF) {
2193 if (Scanner.TRACE) {
2194 System.out.println("TRACE: expr()");
2196 return expr_without_variable(true);
2200 private Expression expr_without_variable(boolean only_variable) {
2201 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2202 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2203 Expression expression = new Expression();
2204 expression.sourceStart = exprSourceStart;
2205 // default, may be overwritten
2206 expression.sourceEnd = exprSourceEnd;
2208 // internal_functions_in_yacc
2217 // | T_INC rw_variable
2218 // | T_DEC rw_variable
2219 // | T_INT_CAST expr
2220 // | T_DOUBLE_CAST expr
2221 // | T_STRING_CAST expr
2222 // | T_ARRAY_CAST expr
2223 // | T_OBJECT_CAST expr
2224 // | T_BOOL_CAST expr
2225 // | T_UNSET_CAST expr
2226 // | T_EXIT exit_expr
2228 // | T_ARRAY '(' array_pair_list ')'
2229 // | '`' encaps_list '`'
2230 // | T_LIST '(' assignment_list ')' '=' expr
2231 // | T_NEW class_name_reference ctor_arguments
2232 // | variable '=' expr
2233 // | variable '=' '&' variable
2234 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2235 // | variable T_PLUS_EQUAL expr
2236 // | variable T_MINUS_EQUAL expr
2237 // | variable T_MUL_EQUAL expr
2238 // | variable T_DIV_EQUAL expr
2239 // | variable T_CONCAT_EQUAL expr
2240 // | variable T_MOD_EQUAL expr
2241 // | variable T_AND_EQUAL expr
2242 // | variable T_OR_EQUAL expr
2243 // | variable T_XOR_EQUAL expr
2244 // | variable T_SL_EQUAL expr
2245 // | variable T_SR_EQUAL expr
2246 // | rw_variable T_INC
2247 // | rw_variable T_DEC
2248 // | expr T_BOOLEAN_OR expr
2249 // | expr T_BOOLEAN_AND expr
2250 // | expr T_LOGICAL_OR expr
2251 // | expr T_LOGICAL_AND expr
2252 // | expr T_LOGICAL_XOR expr
2264 // | expr T_IS_IDENTICAL expr
2265 // | expr T_IS_NOT_IDENTICAL expr
2266 // | expr T_IS_EQUAL expr
2267 // | expr T_IS_NOT_EQUAL expr
2269 // | expr T_IS_SMALLER_OR_EQUAL expr
2271 // | expr T_IS_GREATER_OR_EQUAL expr
2272 // | expr T_INSTANCEOF class_name_reference
2273 // | expr '?' expr ':' expr
2274 if (Scanner.TRACE) {
2275 System.out.println("TRACE: expr_without_variable() PART 1");
2278 case TokenNameisset:
2279 // T_ISSET '(' isset_variables ')'
2281 if (token != TokenNameLPAREN) {
2282 throwSyntaxError("'(' expected after keyword 'isset'");
2286 if (token != TokenNameRPAREN) {
2287 throwSyntaxError("')' expected after keyword 'isset'");
2291 case TokenNameempty:
2293 if (token != TokenNameLPAREN) {
2294 throwSyntaxError("'(' expected after keyword 'empty'");
2297 variable(true, false);
2298 if (token != TokenNameRPAREN) {
2299 throwSyntaxError("')' expected after keyword 'empty'");
2304 case TokenNameinclude:
2305 case TokenNameinclude_once:
2306 case TokenNamerequire:
2307 case TokenNamerequire_once:
2308 internal_functions_in_yacc();
2311 case TokenNameLPAREN:
2314 if (token == TokenNameRPAREN) {
2317 throwSyntaxError("')' expected in expression.");
2327 // | T_INT_CAST expr
2328 // | T_DOUBLE_CAST expr
2329 // | T_STRING_CAST expr
2330 // | T_ARRAY_CAST expr
2331 // | T_OBJECT_CAST expr
2332 // | T_BOOL_CAST expr
2333 // | T_UNSET_CAST expr
2334 case TokenNameclone:
2335 case TokenNameprint:
2338 case TokenNameMINUS:
2340 case TokenNameTWIDDLE:
2341 case TokenNameintCAST:
2342 case TokenNamedoubleCAST:
2343 case TokenNamestringCAST:
2344 case TokenNamearrayCAST:
2345 case TokenNameobjectCAST:
2346 case TokenNameboolCAST:
2347 case TokenNameunsetCAST:
2357 //| T_STRING_VARNAME
2359 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2360 // | '`' encaps_list '`'
2362 // | '`' encaps_list '`'
2363 // case TokenNameEncapsedString0:
2364 // scanner.encapsedStringStack.push(new Character('`'));
2367 // if (token == TokenNameEncapsedString0) {
2370 // if (token != TokenNameEncapsedString0) {
2371 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2375 // scanner.encapsedStringStack.pop();
2379 // // | '\'' encaps_list '\''
2380 // case TokenNameEncapsedString1:
2381 // scanner.encapsedStringStack.push(new Character('\''));
2384 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2385 // if (token == TokenNameEncapsedString1) {
2386 // expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2387 // .getCurrentTokenEndPosition());
2390 // if (token != TokenNameEncapsedString1) {
2391 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2393 // expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2394 // .getCurrentTokenEndPosition());
2398 // scanner.encapsedStringStack.pop();
2402 // //| '"' encaps_list '"'
2403 // case TokenNameEncapsedString2:
2404 // scanner.encapsedStringStack.push(new Character('"'));
2407 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2408 // if (token == TokenNameEncapsedString2) {
2409 // expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2410 // .getCurrentTokenEndPosition());
2413 // if (token != TokenNameEncapsedString2) {
2414 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2416 // expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2417 // .getCurrentTokenEndPosition());
2421 // scanner.encapsedStringStack.pop();
2425 case TokenNameStringDoubleQuote:
2426 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2427 .getCurrentTokenEndPosition());
2430 case TokenNameStringSingleQuote:
2431 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2432 .getCurrentTokenEndPosition());
2435 case TokenNameIntegerLiteral:
2436 case TokenNameDoubleLiteral:
2437 case TokenNameStringInterpolated:
2440 case TokenNameCLASS_C:
2441 case TokenNameMETHOD_C:
2442 case TokenNameFUNC_C:
2445 case TokenNameHEREDOC:
2448 case TokenNamearray:
2449 // T_ARRAY '(' array_pair_list ')'
2451 if (token == TokenNameLPAREN) {
2453 if (token == TokenNameRPAREN) {
2458 if (token != TokenNameRPAREN) {
2459 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2463 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2467 // | T_LIST '(' assignment_list ')' '=' expr
2469 if (token == TokenNameLPAREN) {
2472 if (token != TokenNameRPAREN) {
2473 throwSyntaxError("')' expected after 'list' keyword.");
2476 if (token != TokenNameEQUAL) {
2477 throwSyntaxError("'=' expected after 'list' keyword.");
2482 throwSyntaxError("'(' expected after 'list' keyword.");
2486 // | T_NEW class_name_reference ctor_arguments
2488 Expression typeRef = class_name_reference();
2490 if (typeRef != null) {
2491 expression = typeRef;
2494 // | T_INC rw_variable
2495 // | T_DEC rw_variable
2496 case TokenNamePLUS_PLUS:
2497 case TokenNameMINUS_MINUS:
2501 // | variable '=' expr
2502 // | variable '=' '&' variable
2503 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2504 // | variable T_PLUS_EQUAL expr
2505 // | variable T_MINUS_EQUAL expr
2506 // | variable T_MUL_EQUAL expr
2507 // | variable T_DIV_EQUAL expr
2508 // | variable T_CONCAT_EQUAL expr
2509 // | variable T_MOD_EQUAL expr
2510 // | variable T_AND_EQUAL expr
2511 // | variable T_OR_EQUAL expr
2512 // | variable T_XOR_EQUAL expr
2513 // | variable T_SL_EQUAL expr
2514 // | variable T_SR_EQUAL expr
2515 // | rw_variable T_INC
2516 // | rw_variable T_DEC
2517 case TokenNameIdentifier:
2518 case TokenNameVariable:
2519 case TokenNameDOLLAR:
2520 boolean rememberedVar = false;
2521 Expression lhs = variable(true, true);
2522 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2523 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2524 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2525 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2526 && token != TokenNameLEFT_SHIFT_EQUAL) {
2527 FieldReference ref = (FieldReference) lhs;
2528 if (!containsVariableSet(ref.token)) {
2529 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(), referenceContext,
2530 compilationUnit.compilationResult);
2531 addVariableSet(ref.token);
2536 case TokenNameEQUAL:
2537 if (lhs != null && lhs instanceof FieldReference) {
2538 addVariableSet(((FieldReference) lhs).token);
2540 // if (lhsVar != null) {
2541 // addVariableSet(lhsVar);
2544 if (token == TokenNameAND) {
2546 if (token == TokenNamenew) {
2547 // | variable '=' '&' T_NEW class_name_reference
2550 SingleTypeReference classRef = class_name_reference();
2552 if (classRef != null) {
2553 if (lhs != null && lhs instanceof FieldReference) {
2555 // $var = & new Object();
2556 if (fMethodVariables != null) {
2557 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2558 lhsInfo.reference = classRef;
2559 lhsInfo.typeIdentifier = classRef.token;
2560 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2561 rememberedVar = true;
2566 Expression rhs = variable(false, false);
2567 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2570 if (fMethodVariables != null) {
2571 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2572 if (rhsInfo != null && rhsInfo.reference != null) {
2573 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2574 lhsInfo.reference = rhsInfo.reference;
2575 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2576 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2577 rememberedVar = true;
2583 Expression rhs = expr();
2584 if (lhs != null && lhs instanceof FieldReference) {
2585 if (rhs != null && rhs instanceof FieldReference) {
2588 if (fMethodVariables != null) {
2589 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2590 if (rhsInfo != null && rhsInfo.reference != null) {
2591 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2592 lhsInfo.reference = rhsInfo.reference;
2593 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2594 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2595 rememberedVar = true;
2598 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2600 // $var = new Object();
2601 if (fMethodVariables != null) {
2602 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2603 lhsInfo.reference = (SingleTypeReference) rhs;
2604 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2605 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2606 rememberedVar = true;
2611 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2612 if (fMethodVariables != null) {
2613 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2614 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2618 case TokenNamePLUS_EQUAL:
2619 case TokenNameMINUS_EQUAL:
2620 case TokenNameMULTIPLY_EQUAL:
2621 case TokenNameDIVIDE_EQUAL:
2622 case TokenNameDOT_EQUAL:
2623 case TokenNameREMAINDER_EQUAL:
2624 case TokenNameAND_EQUAL:
2625 case TokenNameOR_EQUAL:
2626 case TokenNameXOR_EQUAL:
2627 case TokenNameRIGHT_SHIFT_EQUAL:
2628 case TokenNameLEFT_SHIFT_EQUAL:
2629 if (lhs != null && lhs instanceof FieldReference) {
2630 addVariableSet(((FieldReference) lhs).token);
2635 case TokenNamePLUS_PLUS:
2636 case TokenNameMINUS_MINUS:
2640 if (!only_variable) {
2641 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2649 if (token != TokenNameINLINE_HTML) {
2650 if (token > TokenNameKEYWORD) {
2654 // System.out.println(scanner.getCurrentTokenStartPosition());
2655 // System.out.println(scanner.getCurrentTokenEndPosition());
2657 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2662 if (Scanner.TRACE) {
2663 System.out.println("TRACE: expr_without_variable() PART 2");
2665 // | expr T_BOOLEAN_OR expr
2666 // | expr T_BOOLEAN_AND expr
2667 // | expr T_LOGICAL_OR expr
2668 // | expr T_LOGICAL_AND expr
2669 // | expr T_LOGICAL_XOR expr
2681 // | expr T_IS_IDENTICAL expr
2682 // | expr T_IS_NOT_IDENTICAL expr
2683 // | expr T_IS_EQUAL expr
2684 // | expr T_IS_NOT_EQUAL expr
2686 // | expr T_IS_SMALLER_OR_EQUAL expr
2688 // | expr T_IS_GREATER_OR_EQUAL expr
2691 case TokenNameOR_OR:
2693 expression = new OR_OR_Expression(expression, expr(), token);
2695 case TokenNameAND_AND:
2697 expression = new AND_AND_Expression(expression, expr(), token);
2699 case TokenNameEQUAL_EQUAL:
2701 expression = new EqualExpression(expression, expr(), token);
2711 case TokenNameMINUS:
2712 case TokenNameMULTIPLY:
2713 case TokenNameDIVIDE:
2714 case TokenNameREMAINDER:
2715 case TokenNameLEFT_SHIFT:
2716 case TokenNameRIGHT_SHIFT:
2717 case TokenNameEQUAL_EQUAL_EQUAL:
2718 case TokenNameNOT_EQUAL_EQUAL:
2719 case TokenNameNOT_EQUAL:
2721 case TokenNameLESS_EQUAL:
2722 case TokenNameGREATER:
2723 case TokenNameGREATER_EQUAL:
2725 expression = new BinaryExpression(expression, expr(), token);
2727 // | expr T_INSTANCEOF class_name_reference
2728 // | expr '?' expr ':' expr
2729 case TokenNameinstanceof:
2731 TypeReference classRef = class_name_reference();
2732 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2733 expression.sourceStart = exprSourceStart;
2734 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2736 case TokenNameQUESTION:
2738 Expression valueIfTrue = expr();
2739 if (token != TokenNameCOLON) {
2740 throwSyntaxError("':' expected in conditional expression.");
2743 Expression valueIfFalse = expr();
2745 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2751 } catch (SyntaxError e) {
2752 // try to find next token after expression with errors:
2753 if (token == TokenNameSEMICOLON) {
2757 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2765 private SingleTypeReference class_name_reference() {
2766 // class_name_reference:
2768 //| dynamic_class_name_reference
2769 SingleTypeReference ref = null;
2770 if (Scanner.TRACE) {
2771 System.out.println("TRACE: class_name_reference()");
2773 if (token == TokenNameIdentifier) {
2774 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2778 dynamic_class_name_reference();
2783 private void dynamic_class_name_reference() {
2784 //dynamic_class_name_reference:
2785 // base_variable T_OBJECT_OPERATOR object_property
2786 // dynamic_class_name_variable_properties
2788 if (Scanner.TRACE) {
2789 System.out.println("TRACE: dynamic_class_name_reference()");
2792 if (token == TokenNameMINUS_GREATER) {
2795 dynamic_class_name_variable_properties();
2799 private void dynamic_class_name_variable_properties() {
2800 // dynamic_class_name_variable_properties:
2801 // dynamic_class_name_variable_properties
2802 // dynamic_class_name_variable_property
2804 if (Scanner.TRACE) {
2805 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2807 while (token == TokenNameMINUS_GREATER) {
2808 dynamic_class_name_variable_property();
2812 private void dynamic_class_name_variable_property() {
2813 // dynamic_class_name_variable_property:
2814 // T_OBJECT_OPERATOR object_property
2815 if (Scanner.TRACE) {
2816 System.out.println("TRACE: dynamic_class_name_variable_property()");
2818 if (token == TokenNameMINUS_GREATER) {
2824 private void ctor_arguments() {
2827 //| '(' function_call_parameter_list ')'
2828 if (token == TokenNameLPAREN) {
2830 if (token == TokenNameRPAREN) {
2834 non_empty_function_call_parameter_list();
2835 if (token != TokenNameRPAREN) {
2836 throwSyntaxError("')' expected in ctor_arguments.");
2842 private void assignment_list() {
2844 // assignment_list ',' assignment_list_element
2845 //| assignment_list_element
2847 assignment_list_element();
2848 if (token != TokenNameCOMMA) {
2855 private void assignment_list_element() {
2856 //assignment_list_element:
2858 //| T_LIST '(' assignment_list ')'
2860 if (token == TokenNameVariable) {
2861 variable(true, false);
2862 } else if (token == TokenNameDOLLAR) {
2863 variable(false, false);
2865 if (token == TokenNamelist) {
2867 if (token == TokenNameLPAREN) {
2870 if (token != TokenNameRPAREN) {
2871 throwSyntaxError("')' expected after 'list' keyword.");
2875 throwSyntaxError("'(' expected after 'list' keyword.");
2881 private void array_pair_list() {
2884 //| non_empty_array_pair_list possible_comma
2885 non_empty_array_pair_list();
2886 if (token == TokenNameCOMMA) {
2891 private void non_empty_array_pair_list() {
2892 //non_empty_array_pair_list:
2893 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2894 //| non_empty_array_pair_list ',' expr
2895 //| expr T_DOUBLE_ARROW expr
2897 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2898 //| non_empty_array_pair_list ',' '&' w_variable
2899 //| expr T_DOUBLE_ARROW '&' w_variable
2902 if (token == TokenNameAND) {
2904 variable(true, false);
2907 if (token == TokenNameAND) {
2909 variable(true, false);
2910 } else if (token == TokenNameEQUAL_GREATER) {
2912 if (token == TokenNameAND) {
2914 variable(true, false);
2920 if (token != TokenNameCOMMA) {
2924 if (token == TokenNameRPAREN) {
2930 // private void variableList() {
2933 // if (token == TokenNameCOMMA) {
2940 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2941 // variable_without_objects:
2942 // reference_variable
2943 // | simple_indirect_reference reference_variable
2944 if (Scanner.TRACE) {
2945 System.out.println("TRACE: variable_without_objects()");
2947 while (token == TokenNameDOLLAR) {
2950 return reference_variable(lefthandside, ignoreVar);
2953 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2955 // T_STRING '(' function_call_parameter_list ')'
2956 //| class_constant '(' function_call_parameter_list ')'
2957 //| static_member '(' function_call_parameter_list ')'
2958 //| variable_without_objects '(' function_call_parameter_list ')'
2959 char[] defineName = null;
2960 char[] ident = null;
2963 Expression ref = null;
2964 if (Scanner.TRACE) {
2965 System.out.println("TRACE: function_call()");
2967 if (token == TokenNameIdentifier) {
2968 ident = scanner.getCurrentIdentifierSource();
2970 startPos = scanner.getCurrentTokenStartPosition();
2971 endPos = scanner.getCurrentTokenEndPosition();
2974 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2978 if (token == TokenNameIdentifier) {
2983 variable_without_objects(true, false);
2988 ref = variable_without_objects(lefthandside, ignoreVar);
2990 if (token != TokenNameLPAREN) {
2991 if (defineName != null) {
2992 // does this identifier contain only uppercase characters?
2993 if (defineName.length == 3) {
2994 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2997 } else if (defineName.length == 4) {
2998 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3000 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3003 } else if (defineName.length == 5) {
3004 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3008 if (defineName != null) {
3009 for (int i = 0; i < defineName.length; i++) {
3010 if (Character.isLowerCase(defineName[i])) {
3011 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3017 // TODO is this ok ?
3019 // throwSyntaxError("'(' expected in function call.");
3022 if (token == TokenNameRPAREN) {
3026 non_empty_function_call_parameter_list();
3027 if (token != TokenNameRPAREN) {
3028 String functionName;
3029 if (ident == null) {
3030 functionName = new String(" ");
3032 functionName = new String(ident);
3034 throwSyntaxError("')' expected in function call (" + functionName + ").");
3040 // private void function_call_parameter_list() {
3041 // function_call_parameter_list:
3042 // non_empty_function_call_parameter_list { $$ = $1; }
3045 private void non_empty_function_call_parameter_list() {
3046 //non_empty_function_call_parameter_list:
3047 // expr_without_variable
3050 // | non_empty_function_call_parameter_list ',' expr_without_variable
3051 // | non_empty_function_call_parameter_list ',' variable
3052 // | non_empty_function_call_parameter_list ',' '&' w_variable
3053 if (Scanner.TRACE) {
3054 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3057 if (token == TokenNameAND) {
3061 // if (token == TokenNameIdentifier || token ==
3062 // TokenNameVariable
3063 // || token == TokenNameDOLLAR) {
3066 expr_without_variable(true);
3069 if (token != TokenNameCOMMA) {
3076 private void fully_qualified_class_name() {
3077 if (token == TokenNameIdentifier) {
3080 throwSyntaxError("Class name expected.");
3084 private void static_member() {
3086 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3087 // variable_without_objects
3088 if (Scanner.TRACE) {
3089 System.out.println("TRACE: static_member()");
3091 fully_qualified_class_name();
3092 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3093 throwSyntaxError("'::' expected after class name (static_member).");
3096 variable_without_objects(false, false);
3099 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3100 // base_variable_with_function_calls:
3103 boolean functionCall = false;
3104 if (Scanner.TRACE) {
3105 System.out.println("TRACE: base_variable_with_function_calls()");
3107 // if (token == TokenNameIdentifier) {
3108 // functionCall = true;
3109 // } else if (token == TokenNameVariable) {
3110 // int tempToken = token;
3111 // int tempPosition = scanner.currentPosition;
3113 // if (token == TokenNameLPAREN) {
3114 // functionCall = true;
3116 // token = tempToken;
3117 // scanner.currentPosition = tempPosition;
3118 // scanner.phpMode = true;
3120 // if (functionCall) {
3121 return function_call(lefthandside, ignoreVar);
3127 private Expression base_variable() {
3129 // reference_variable
3130 // | simple_indirect_reference reference_variable
3132 Expression ref = null;
3133 if (Scanner.TRACE) {
3134 System.out.println("TRACE: base_variable()");
3136 if (token == TokenNameIdentifier) {
3139 while (token == TokenNameDOLLAR) {
3142 reference_variable(false, false);
3147 // private void simple_indirect_reference() {
3148 // // simple_indirect_reference:
3150 // //| simple_indirect_reference '$'
3152 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3153 // reference_variable:
3154 // reference_variable '[' dim_offset ']'
3155 // | reference_variable '{' expr '}'
3156 // | compound_variable
3157 Expression ref = null;
3158 if (Scanner.TRACE) {
3159 System.out.println("TRACE: reference_variable()");
3161 ref = compound_variable(lefthandside, ignoreVar);
3163 if (token == TokenNameLBRACE) {
3167 if (token != TokenNameRBRACE) {
3168 throwSyntaxError("'}' expected in reference variable.");
3171 } else if (token == TokenNameLBRACKET) {
3172 if (ref != null && ref instanceof FieldReference) {
3173 FieldReference fref = (FieldReference) ref;
3174 addVariableSet(fref.token);
3178 if (token != TokenNameRBRACKET) {
3181 if (token != TokenNameRBRACKET) {
3182 throwSyntaxError("']' expected in reference variable.");
3193 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3194 // compound_variable:
3196 // | '$' '{' expr '}'
3197 if (Scanner.TRACE) {
3198 System.out.println("TRACE: compound_variable()");
3200 if (token == TokenNameVariable) {
3201 if (!lefthandside) {
3202 if (!containsVariableSet()) {
3203 // reportSyntaxError("The local variable " + new String(scanner.getCurrentIdentifierSource())
3204 // + " may not have been initialized");
3205 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3206 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3207 compilationUnit.compilationResult);
3214 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3218 // because of simple_indirect_reference
3219 while (token == TokenNameDOLLAR) {
3222 if (token != TokenNameLBRACE) {
3223 reportSyntaxError("'{' expected after compound variable token '$'.");
3228 if (token != TokenNameRBRACE) {
3229 throwSyntaxError("'}' expected after compound variable token '$'.");
3234 } // private void dim_offset() { // // dim_offset: // // /* empty */
3239 private void object_property() {
3242 //| variable_without_objects
3243 if (Scanner.TRACE) {
3244 System.out.println("TRACE: object_property()");
3246 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3247 variable_without_objects(false, false);
3253 private void object_dim_list() {
3255 // object_dim_list '[' dim_offset ']'
3256 //| object_dim_list '{' expr '}'
3258 if (Scanner.TRACE) {
3259 System.out.println("TRACE: object_dim_list()");
3263 if (token == TokenNameLBRACE) {
3266 if (token != TokenNameRBRACE) {
3267 throwSyntaxError("'}' expected in object_dim_list.");
3270 } else if (token == TokenNameLBRACKET) {
3272 if (token == TokenNameRBRACKET) {
3277 if (token != TokenNameRBRACKET) {
3278 throwSyntaxError("']' expected in object_dim_list.");
3287 private void variable_name() {
3291 if (Scanner.TRACE) {
3292 System.out.println("TRACE: variable_name()");
3294 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3295 if (token > TokenNameKEYWORD) {
3296 // TODO show a warning "Keyword used as variable" ?
3300 if (token != TokenNameLBRACE) {
3301 throwSyntaxError("'{' expected in variable name.");
3305 if (token != TokenNameRBRACE) {
3306 throwSyntaxError("'}' expected in variable name.");
3312 private void r_variable() {
3313 variable(false, false);
3316 private void w_variable(boolean lefthandside) {
3317 variable(lefthandside, false);
3320 private void rw_variable() {
3321 variable(false, false);
3324 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3326 // base_variable_with_function_calls T_OBJECT_OPERATOR
3327 // object_property method_or_not variable_properties
3328 // | base_variable_with_function_calls
3329 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3330 if (token == TokenNameMINUS_GREATER) {
3335 variable_properties();
3340 private void variable_properties() {
3341 // variable_properties:
3342 // variable_properties variable_property
3344 while (token == TokenNameMINUS_GREATER) {
3345 variable_property();
3349 private void variable_property() {
3350 // variable_property:
3351 // T_OBJECT_OPERATOR object_property method_or_not
3352 if (Scanner.TRACE) {
3353 System.out.println("TRACE: variable_property()");
3355 if (token == TokenNameMINUS_GREATER) {
3360 throwSyntaxError("'->' expected in variable_property.");
3364 private void method_or_not() {
3366 // '(' function_call_parameter_list ')'
3368 if (Scanner.TRACE) {
3369 System.out.println("TRACE: method_or_not()");
3371 if (token == TokenNameLPAREN) {
3373 if (token == TokenNameRPAREN) {
3377 non_empty_function_call_parameter_list();
3378 if (token != TokenNameRPAREN) {
3379 throwSyntaxError("')' expected in method_or_not.");
3385 private void exit_expr() {
3389 if (token != TokenNameLPAREN) {
3393 if (token == TokenNameRPAREN) {
3398 if (token != TokenNameRPAREN) {
3399 throwSyntaxError("')' expected after keyword 'exit'");
3404 // private void encaps_list() {
3405 // // encaps_list encaps_var
3406 // // | encaps_list T_STRING
3407 // // | encaps_list T_NUM_STRING
3408 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3409 // // | encaps_list T_CHARACTER
3410 // // | encaps_list T_BAD_CHARACTER
3411 // // | encaps_list '['
3412 // // | encaps_list ']'
3413 // // | encaps_list '{'
3414 // // | encaps_list '}'
3415 // // | encaps_list T_OBJECT_OPERATOR
3419 // case TokenNameSTRING:
3422 // case TokenNameLBRACE:
3423 // // scanner.encapsedStringStack.pop();
3426 // case TokenNameRBRACE:
3427 // // scanner.encapsedStringStack.pop();
3430 // case TokenNameLBRACKET:
3431 // // scanner.encapsedStringStack.pop();
3434 // case TokenNameRBRACKET:
3435 // // scanner.encapsedStringStack.pop();
3438 // case TokenNameMINUS_GREATER:
3439 // // scanner.encapsedStringStack.pop();
3442 // case TokenNameVariable:
3443 // case TokenNameDOLLAR_LBRACE:
3444 // case TokenNameLBRACE_DOLLAR:
3448 // char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3449 // if (encapsedChar == '$') {
3450 // scanner.encapsedStringStack.pop();
3451 // encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3452 // switch (encapsedChar) {
3454 // if (token == TokenNameEncapsedString0) {
3457 // token = TokenNameSTRING;
3460 // if (token == TokenNameEncapsedString1) {
3463 // token = TokenNameSTRING;
3466 // if (token == TokenNameEncapsedString2) {
3469 // token = TokenNameSTRING;
3478 // private void encaps_var() {
3480 // // | T_VARIABLE '[' encaps_var_offset ']'
3481 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3482 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3483 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3484 // // | T_CURLY_OPEN variable '}'
3486 // case TokenNameVariable:
3488 // if (token == TokenNameLBRACKET) {
3490 // expr(); //encaps_var_offset();
3491 // if (token != TokenNameRBRACKET) {
3492 // throwSyntaxError("']' expected after variable.");
3494 // // scanner.encapsedStringStack.pop();
3497 // } else if (token == TokenNameMINUS_GREATER) {
3499 // if (token != TokenNameIdentifier) {
3500 // throwSyntaxError("Identifier expected after '->'.");
3502 // // scanner.encapsedStringStack.pop();
3506 // // // scanner.encapsedStringStack.pop();
3507 // // int tempToken = TokenNameSTRING;
3508 // // if (!scanner.encapsedStringStack.isEmpty()
3509 // // && (token == TokenNameEncapsedString0
3510 // // || token == TokenNameEncapsedString1
3511 // // || token == TokenNameEncapsedString2 || token ==
3512 // // TokenNameERROR)) {
3513 // // char encapsedChar = ((Character)
3514 // // scanner.encapsedStringStack.peek())
3516 // // switch (token) {
3517 // // case TokenNameEncapsedString0 :
3518 // // if (encapsedChar == '`') {
3519 // // tempToken = TokenNameEncapsedString0;
3522 // // case TokenNameEncapsedString1 :
3523 // // if (encapsedChar == '\'') {
3524 // // tempToken = TokenNameEncapsedString1;
3527 // // case TokenNameEncapsedString2 :
3528 // // if (encapsedChar == '"') {
3529 // // tempToken = TokenNameEncapsedString2;
3532 // // case TokenNameERROR :
3533 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3534 // // scanner.currentPosition--;
3535 // // getNextToken();
3540 // // token = tempToken;
3543 // case TokenNameDOLLAR_LBRACE:
3545 // if (token == TokenNameDOLLAR_LBRACE) {
3547 // } else if (token == TokenNameIdentifier) {
3549 // if (token == TokenNameLBRACKET) {
3551 // // if (token == TokenNameRBRACKET) {
3552 // // getNextToken();
3555 // if (token != TokenNameRBRACKET) {
3556 // throwSyntaxError("']' expected after '${'.");
3564 // if (token != TokenNameRBRACE) {
3565 // throwSyntaxError("'}' expected.");
3569 // case TokenNameLBRACE_DOLLAR:
3571 // if (token == TokenNameLBRACE_DOLLAR) {
3573 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3575 // if (token == TokenNameLBRACKET) {
3577 // // if (token == TokenNameRBRACKET) {
3578 // // getNextToken();
3581 // if (token != TokenNameRBRACKET) {
3582 // throwSyntaxError("']' expected.");
3586 // } else if (token == TokenNameMINUS_GREATER) {
3588 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3589 // throwSyntaxError("String or Variable token expected.");
3592 // if (token == TokenNameLBRACKET) {
3594 // // if (token == TokenNameRBRACKET) {
3595 // // getNextToken();
3598 // if (token != TokenNameRBRACKET) {
3599 // throwSyntaxError("']' expected after '${'.");
3605 // // if (token != TokenNameRBRACE) {
3606 // // throwSyntaxError("'}' expected after '{$'.");
3608 // // // scanner.encapsedStringStack.pop();
3609 // // getNextToken();
3612 // if (token != TokenNameRBRACE) {
3613 // throwSyntaxError("'}' expected.");
3615 // // scanner.encapsedStringStack.pop();
3622 private void encaps_var_offset() {
3627 case TokenNameSTRING:
3630 case TokenNameIntegerLiteral:
3633 case TokenNameVariable:
3636 case TokenNameIdentifier:
3640 throwSyntaxError("Variable or String token expected.");
3645 private void internal_functions_in_yacc() {
3648 // case TokenNameisset:
3649 // // T_ISSET '(' isset_variables ')'
3651 // if (token != TokenNameLPAREN) {
3652 // throwSyntaxError("'(' expected after keyword 'isset'");
3655 // isset_variables();
3656 // if (token != TokenNameRPAREN) {
3657 // throwSyntaxError("')' expected after keyword 'isset'");
3661 // case TokenNameempty:
3662 // // T_EMPTY '(' variable ')'
3664 // if (token != TokenNameLPAREN) {
3665 // throwSyntaxError("'(' expected after keyword 'empty'");
3669 // if (token != TokenNameRPAREN) {
3670 // throwSyntaxError("')' expected after keyword 'empty'");
3674 case TokenNameinclude:
3676 checkFileName(token);
3678 case TokenNameinclude_once:
3679 // T_INCLUDE_ONCE expr
3680 checkFileName(token);
3683 // T_EVAL '(' expr ')'
3685 if (token != TokenNameLPAREN) {
3686 throwSyntaxError("'(' expected after keyword 'eval'");
3690 if (token != TokenNameRPAREN) {
3691 throwSyntaxError("')' expected after keyword 'eval'");
3695 case TokenNamerequire:
3697 checkFileName(token);
3699 case TokenNamerequire_once:
3700 // T_REQUIRE_ONCE expr
3701 checkFileName(token);
3707 * Parse and check the include file name
3709 * @param includeToken
3711 private void checkFileName(int includeToken) {
3712 //<include-token> expr
3713 int start = scanner.getCurrentTokenStartPosition();
3714 boolean hasLPAREN = false;
3716 if (token == TokenNameLPAREN) {
3720 Expression expression = expr();
3722 if (token == TokenNameRPAREN) {
3725 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3728 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3730 if (scanner.compilationUnit != null) {
3731 IResource resource = scanner.compilationUnit.getResource();
3732 if (resource != null && resource instanceof IFile) {
3733 file = (IFile) resource;
3737 tokens = new char[1][];
3738 tokens[0] = currTokenSource;
3740 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3741 impt.declarationSourceEnd = impt.sourceEnd;
3742 impt.declarationEnd = impt.declarationSourceEnd;
3743 //endPosition is just before the ;
3744 impt.declarationSourceStart = start;
3745 includesList.add(impt);
3747 if (expression instanceof StringLiteral) {
3748 StringLiteral literal = (StringLiteral) expression;
3749 char[] includeName = literal.source();
3750 if (includeName.length == 0) {
3751 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3752 literal.sourceStart + 1);
3754 String includeNameString = new String(includeName);
3755 if (literal instanceof StringLiteralDQ) {
3756 if (includeNameString.indexOf('$') >= 0) {
3757 // assuming that the filename contains a variable => no filename check
3761 if (includeNameString.startsWith("http://")) {
3762 // assuming external include location
3766 // check the filename:
3767 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3768 IProject project = file.getProject();
3769 if (project != null) {
3770 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3773 // SyntaxError: "File: << >> doesn't exist in project."
3774 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3775 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3776 compilationUnit.compilationResult);
3779 String filePath = path.toString();
3780 String ext = file.getRawLocation().getFileExtension();
3781 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3784 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3785 impt.setFile(PHPFileUtil.createFile(path, project));
3786 } catch (Exception e) {
3787 // the file is outside of the workspace
3795 private void isset_variables() {
3797 // | isset_variables ','
3798 if (token == TokenNameRPAREN) {
3799 throwSyntaxError("Variable expected after keyword 'isset'");
3802 variable(true, false);
3803 if (token == TokenNameCOMMA) {
3811 private boolean common_scalar() {
3815 // | T_CONSTANT_ENCAPSED_STRING
3822 case TokenNameIntegerLiteral:
3825 case TokenNameDoubleLiteral:
3828 case TokenNameStringDoubleQuote:
3831 case TokenNameStringSingleQuote:
3834 case TokenNameStringInterpolated:
3843 case TokenNameCLASS_C:
3846 case TokenNameMETHOD_C:
3849 case TokenNameFUNC_C:
3856 private void scalar() {
3859 //| T_STRING_VARNAME
3862 //| '"' encaps_list '"'
3863 //| '\'' encaps_list '\''
3864 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3865 throwSyntaxError("Not yet implemented (scalar).");
3868 private void static_scalar() {
3869 // static_scalar: /* compile-time evaluated scalars */
3872 // | '+' static_scalar
3873 // | '-' static_scalar
3874 // | T_ARRAY '(' static_array_pair_list ')'
3875 // | static_class_constant
3876 if (common_scalar()) {
3880 case TokenNameIdentifier:
3882 // static_class_constant:
3883 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3884 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3886 if (token == TokenNameIdentifier) {
3889 throwSyntaxError("Identifier expected after '::' operator.");
3893 case TokenNameEncapsedString0:
3895 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3896 while (scanner.currentCharacter != '`') {
3897 if (scanner.currentCharacter == '\\') {
3898 scanner.currentPosition++;
3900 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3903 } catch (IndexOutOfBoundsException e) {
3904 throwSyntaxError("'`' expected at end of static string.");
3907 // case TokenNameEncapsedString1:
3909 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3910 // while (scanner.currentCharacter != '\'') {
3911 // if (scanner.currentCharacter == '\\') {
3912 // scanner.currentPosition++;
3914 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3917 // } catch (IndexOutOfBoundsException e) {
3918 // throwSyntaxError("'\'' expected at end of static string.");
3921 // case TokenNameEncapsedString2:
3923 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3924 // while (scanner.currentCharacter != '"') {
3925 // if (scanner.currentCharacter == '\\') {
3926 // scanner.currentPosition++;
3928 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3931 // } catch (IndexOutOfBoundsException e) {
3932 // throwSyntaxError("'\"' expected at end of static string.");
3935 case TokenNameStringSingleQuote:
3938 case TokenNameStringDoubleQuote:
3945 case TokenNameMINUS:
3949 case TokenNamearray:
3951 if (token != TokenNameLPAREN) {
3952 throwSyntaxError("'(' expected after keyword 'array'");
3955 if (token == TokenNameRPAREN) {
3959 non_empty_static_array_pair_list();
3960 if (token != TokenNameRPAREN) {
3961 throwSyntaxError("')' or ',' expected after keyword 'array'");
3965 // case TokenNamenull :
3968 // case TokenNamefalse :
3971 // case TokenNametrue :
3975 throwSyntaxError("Static scalar/constant expected.");
3979 private void non_empty_static_array_pair_list() {
3980 // non_empty_static_array_pair_list:
3981 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3983 //| non_empty_static_array_pair_list ',' static_scalar
3984 //| static_scalar T_DOUBLE_ARROW static_scalar
3988 if (token == TokenNameEQUAL_GREATER) {
3992 if (token != TokenNameCOMMA) {
3996 if (token == TokenNameRPAREN) {
4002 public void reportSyntaxError() { //int act, int currentKind, int
4004 /* remember current scanner position */
4005 int startPos = scanner.startPosition;
4006 int currentPos = scanner.currentPosition;
4007 // String[] expectings;
4008 // String tokenName = name[symbol_index[currentKind]];
4009 //fetch all "accurate" possible terminals that could recover the error
4010 // int start, end = start = asi(stack[stateStackTop]);
4011 // while (asr[end] != 0)
4013 // int length = end - start;
4014 // expectings = new String[length];
4015 // if (length != 0) {
4016 // char[] indexes = new char[length];
4017 // System.arraycopy(asr, start, indexes, 0, length);
4018 // for (int i = 0; i < length; i++) {
4019 // expectings[i] = name[symbol_index[indexes[i]]];
4022 //if the pb is an EOF, try to tell the user that they are some
4023 // if (tokenName.equals(UNEXPECTED_EOF)) {
4024 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
4025 // char[] tokenSource;
4027 // tokenSource = this.scanner.getCurrentTokenSource();
4028 // } catch (Exception e) {
4029 // tokenSource = new char[] {};
4031 // problemReporter().parseError(
4032 // this.scanner.startPosition,
4033 // this.scanner.currentPosition - 1,
4038 // } else { //the next test is HEAVILY grammar DEPENDENT.
4039 // if ((length == 14)
4040 // && (expectings[0] == "=") //$NON-NLS-1$
4041 // && (expectings[1] == "*=") //$NON-NLS-1$
4042 // && (expressionPtr > -1)) {
4043 // switch(currentKind) {
4044 // case TokenNameSEMICOLON:
4045 // case TokenNamePLUS:
4046 // case TokenNameMINUS:
4047 // case TokenNameDIVIDE:
4048 // case TokenNameREMAINDER:
4049 // case TokenNameMULTIPLY:
4050 // case TokenNameLEFT_SHIFT:
4051 // case TokenNameRIGHT_SHIFT:
4052 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
4053 // case TokenNameLESS:
4054 // case TokenNameGREATER:
4055 // case TokenNameLESS_EQUAL:
4056 // case TokenNameGREATER_EQUAL:
4057 // case TokenNameEQUAL_EQUAL:
4058 // case TokenNameNOT_EQUAL:
4059 // case TokenNameXOR:
4060 // case TokenNameAND:
4061 // case TokenNameOR:
4062 // case TokenNameOR_OR:
4063 // case TokenNameAND_AND:
4064 // // the ; is not the expected token ==> it ends a statement when an
4065 // expression is not ended
4066 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
4068 // case TokenNameRBRACE :
4069 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
4072 // char[] tokenSource;
4074 // tokenSource = this.scanner.getCurrentTokenSource();
4075 // } catch (Exception e) {
4076 // tokenSource = new char[] {};
4078 // problemReporter().parseError(
4079 // this.scanner.startPosition,
4080 // this.scanner.currentPosition - 1,
4084 // this.checkAndReportBracketAnomalies(problemReporter());
4089 tokenSource = this.scanner.getCurrentTokenSource();
4090 } catch (Exception e) {
4091 tokenSource = new char[] {};
4093 // problemReporter().parseError(
4094 // this.scanner.startPosition,
4095 // this.scanner.currentPosition - 1,
4099 this.checkAndReportBracketAnomalies(problemReporter());
4102 /* reset scanner where it was */
4103 scanner.startPosition = startPos;
4104 scanner.currentPosition = currentPos;
4107 public static final int RoundBracket = 0;
4109 public static final int SquareBracket = 1;
4111 public static final int CurlyBracket = 2;
4113 public static final int BracketKinds = 3;
4115 protected int[] nestedMethod; //the ptr is nestedType
4117 protected int nestedType, dimensions;
4119 //variable set stack
4120 final static int VariableStackIncrement = 10;
4122 HashMap fTypeVariables = null;
4124 HashMap fMethodVariables = null;
4126 ArrayList fStackUnassigned = new ArrayList();
4129 final static int AstStackIncrement = 100;
4131 protected int astPtr;
4133 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4135 protected int astLengthPtr;
4137 protected int[] astLengthStack;
4139 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4141 public CompilationUnitDeclaration compilationUnit; /*
4142 * the result from parse()
4145 protected ReferenceContext referenceContext;
4147 protected ProblemReporter problemReporter;
4149 protected CompilerOptions options;
4151 private ArrayList includesList;
4153 // protected CompilationResult compilationResult;
4155 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
4156 * reported, so initializes the compilation result's line positions.
4158 public ProblemReporter problemReporter() {
4159 if (scanner.recordLineSeparator) {
4160 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4162 problemReporter.referenceContext = referenceContext;
4163 return problemReporter;
4167 * Reconsider the entire source looking for inconsistencies in {} () []
4169 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
4170 scanner.wasAcr = false;
4171 boolean anomaliesDetected = false;
4173 char[] source = scanner.source;
4174 int[] leftCount = { 0, 0, 0 };
4175 int[] rightCount = { 0, 0, 0 };
4176 int[] depths = { 0, 0, 0 };
4177 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
4178 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4179 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
4180 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
4181 scanner.currentPosition = scanner.initialPosition; //starting
4183 // (first-zero-based
4185 while (scanner.currentPosition < scanner.eofPosition) { //loop for
4190 // ---------Consume white space and handles
4191 // startPosition---------
4192 boolean isWhiteSpace;
4194 scanner.startPosition = scanner.currentPosition;
4195 // if (((scanner.currentCharacter =
4196 // source[scanner.currentPosition++]) == '\\') &&
4197 // (source[scanner.currentPosition] == 'u')) {
4198 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4200 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4201 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4202 // only record line positions we have not
4204 scanner.pushLineSeparator();
4207 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4209 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4210 // -------consume token until } is found---------
4211 switch (scanner.currentCharacter) {
4213 int index = leftCount[CurlyBracket]++;
4214 if (index == leftPositions[CurlyBracket].length) {
4215 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4216 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
4218 leftPositions[CurlyBracket][index] = scanner.startPosition;
4219 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4223 int index = rightCount[CurlyBracket]++;
4224 if (index == rightPositions[CurlyBracket].length) {
4225 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4226 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
4228 rightPositions[CurlyBracket][index] = scanner.startPosition;
4229 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4233 int index = leftCount[RoundBracket]++;
4234 if (index == leftPositions[RoundBracket].length) {
4235 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4236 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
4238 leftPositions[RoundBracket][index] = scanner.startPosition;
4239 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4243 int index = rightCount[RoundBracket]++;
4244 if (index == rightPositions[RoundBracket].length) {
4245 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4246 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
4248 rightPositions[RoundBracket][index] = scanner.startPosition;
4249 rightDepths[RoundBracket][index] = --depths[RoundBracket];
4253 int index = leftCount[SquareBracket]++;
4254 if (index == leftPositions[SquareBracket].length) {
4255 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4256 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
4258 leftPositions[SquareBracket][index] = scanner.startPosition;
4259 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4263 int index = rightCount[SquareBracket]++;
4264 if (index == rightPositions[SquareBracket].length) {
4265 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4266 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
4268 rightPositions[SquareBracket][index] = scanner.startPosition;
4269 rightDepths[SquareBracket][index] = --depths[SquareBracket];
4273 if (scanner.getNextChar('\\')) {
4274 scanner.scanEscapeCharacter();
4275 } else { // consume next character
4276 scanner.unicodeAsBackSlash = false;
4277 // if (((scanner.currentCharacter =
4278 // source[scanner.currentPosition++]) ==
4280 // (source[scanner.currentPosition] ==
4282 // scanner.getNextUnicodeChar();
4284 if (scanner.withoutUnicodePtr != 0) {
4285 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4289 scanner.getNextChar('\'');
4293 // consume next character
4294 scanner.unicodeAsBackSlash = false;
4295 // if (((scanner.currentCharacter =
4296 // source[scanner.currentPosition++]) == '\\') &&
4297 // (source[scanner.currentPosition] == 'u')) {
4298 // scanner.getNextUnicodeChar();
4300 if (scanner.withoutUnicodePtr != 0) {
4301 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4304 while (scanner.currentCharacter != '"') {
4305 if (scanner.currentCharacter == '\r') {
4306 if (source[scanner.currentPosition] == '\n')
4307 scanner.currentPosition++;
4308 break; // the string cannot go further that
4311 if (scanner.currentCharacter == '\n') {
4312 break; // the string cannot go further that
4315 if (scanner.currentCharacter == '\\') {
4316 scanner.scanEscapeCharacter();
4318 // consume next character
4319 scanner.unicodeAsBackSlash = false;
4320 // if (((scanner.currentCharacter =
4321 // source[scanner.currentPosition++]) == '\\')
4322 // && (source[scanner.currentPosition] == 'u'))
4324 // scanner.getNextUnicodeChar();
4326 if (scanner.withoutUnicodePtr != 0) {
4327 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4334 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4337 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4338 && (source[scanner.currentPosition] == 'u')) {
4339 //-------------unicode traitement
4341 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4342 scanner.currentPosition++;
4343 while (source[scanner.currentPosition] == 'u') {
4344 scanner.currentPosition++;
4346 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4347 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4348 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4349 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4353 scanner.currentCharacter = 'A';
4354 } //something different from \n and \r
4356 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4359 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
4361 scanner.startPosition = scanner.currentPosition;
4362 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4363 && (source[scanner.currentPosition] == 'u')) {
4364 //-------------unicode traitement
4366 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4367 scanner.currentPosition++;
4368 while (source[scanner.currentPosition] == 'u') {
4369 scanner.currentPosition++;
4371 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4372 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4373 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4374 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4378 scanner.currentCharacter = 'A';
4379 } //something different from \n
4382 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4386 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4387 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4388 // only record line positions we
4389 // have not recorded yet
4390 scanner.pushLineSeparator();
4391 if (this.scanner.taskTags != null) {
4392 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4393 .getCurrentTokenEndPosition());
4399 if (test > 0) { //traditional and annotation
4401 boolean star = false;
4402 // consume next character
4403 scanner.unicodeAsBackSlash = false;
4404 // if (((scanner.currentCharacter =
4405 // source[scanner.currentPosition++]) ==
4407 // (source[scanner.currentPosition] ==
4409 // scanner.getNextUnicodeChar();
4411 if (scanner.withoutUnicodePtr != 0) {
4412 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4415 if (scanner.currentCharacter == '*') {
4419 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4420 && (source[scanner.currentPosition] == 'u')) {
4421 //-------------unicode traitement
4423 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4424 scanner.currentPosition++;
4425 while (source[scanner.currentPosition] == 'u') {
4426 scanner.currentPosition++;
4428 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4429 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4430 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4431 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4435 scanner.currentCharacter = 'A';
4436 } //something different from * and /
4438 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4441 //loop until end of comment */
4442 while ((scanner.currentCharacter != '/') || (!star)) {
4443 star = scanner.currentCharacter == '*';
4445 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4446 && (source[scanner.currentPosition] == 'u')) {
4447 //-------------unicode traitement
4449 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4450 scanner.currentPosition++;
4451 while (source[scanner.currentPosition] == 'u') {
4452 scanner.currentPosition++;
4454 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4455 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4456 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4457 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4461 scanner.currentCharacter = 'A';
4462 } //something different from * and
4465 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4469 if (this.scanner.taskTags != null) {
4470 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4477 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4478 scanner.scanIdentifierOrKeyword(false);
4481 if (Character.isDigit(scanner.currentCharacter)) {
4482 scanner.scanNumber(false);
4486 //-----------------end switch while
4487 // try--------------------
4488 } catch (IndexOutOfBoundsException e) {
4489 break; // read until EOF
4490 } catch (InvalidInputException e) {
4491 return false; // no clue
4494 if (scanner.recordLineSeparator) {
4495 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4497 // check placement anomalies against other kinds of brackets
4498 for (int kind = 0; kind < BracketKinds; kind++) {
4499 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4500 int start = leftPositions[kind][leftIndex]; // deepest
4502 // find matching closing bracket
4503 int depth = leftDepths[kind][leftIndex];
4505 for (int i = 0; i < rightCount[kind]; i++) {
4506 int pos = rightPositions[kind][i];
4507 // want matching bracket further in source with same
4509 if ((pos > start) && (depth == rightDepths[kind][i])) {
4514 if (end < 0) { // did not find a good closing match
4515 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4518 // check if even number of opening/closing other brackets
4519 // in between this pair of brackets
4521 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4522 for (int i = 0; i < leftCount[otherKind]; i++) {
4523 int pos = leftPositions[otherKind][i];
4524 if ((pos > start) && (pos < end))
4527 for (int i = 0; i < rightCount[otherKind]; i++) {
4528 int pos = rightPositions[otherKind][i];
4529 if ((pos > start) && (pos < end))
4533 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4539 // too many opening brackets ?
4540 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4541 anomaliesDetected = true;
4542 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4543 compilationUnit.compilationResult);
4545 // too many closing brackets ?
4546 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4547 anomaliesDetected = true;
4548 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4550 if (anomaliesDetected)
4553 return anomaliesDetected;
4554 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4555 return anomaliesDetected;
4556 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4557 return anomaliesDetected;
4561 protected void pushOnAstLengthStack(int pos) {
4563 astLengthStack[++astLengthPtr] = pos;
4564 } catch (IndexOutOfBoundsException e) {
4565 int oldStackLength = astLengthStack.length;
4566 int[] oldPos = astLengthStack;
4567 astLengthStack = new int[oldStackLength + StackIncrement];
4568 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4569 astLengthStack[astLengthPtr] = pos;
4573 protected void pushOnAstStack(ASTNode node) {
4575 * add a new obj on top of the ast stack
4578 astStack[++astPtr] = node;
4579 } catch (IndexOutOfBoundsException e) {
4580 int oldStackLength = astStack.length;
4581 ASTNode[] oldStack = astStack;
4582 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4583 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4584 astPtr = oldStackLength;
4585 astStack[astPtr] = node;
4588 astLengthStack[++astLengthPtr] = 1;
4589 } catch (IndexOutOfBoundsException e) {
4590 int oldStackLength = astLengthStack.length;
4591 int[] oldPos = astLengthStack;
4592 astLengthStack = new int[oldStackLength + AstStackIncrement];
4593 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4594 astLengthStack[astLengthPtr] = 1;
4598 protected void resetModifiers() {
4599 this.modifiers = AccDefault;
4600 this.modifiersSourceStart = -1; // <-- see comment into
4601 // modifiersFlag(int)
4602 this.scanner.commentPtr = -1;
4605 protected void consumePackageDeclarationName(IFile file) {
4606 // create a package name similar to java package names
4607 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4608 String filePath = file.getRawLocation().toString();
4609 String ext = file.getRawLocation().getFileExtension();
4610 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4611 ImportReference impt;
4614 if (filePath.startsWith(projectPath)) {
4615 tokens = CharOperation
4616 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4618 String name = file.getName();
4619 tokens = new char[1][];
4620 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4623 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4625 impt.declarationSourceStart = 0;
4626 impt.declarationSourceEnd = 0;
4627 impt.declarationEnd = 0;
4628 //endPosition is just before the ;
4632 public final static String[] GLOBALS = {
4647 private void pushFunctionVariableSet() {
4648 HashSet set = new HashSet();
4649 if (fStackUnassigned.isEmpty()) {
4650 for (int i = 0; i < GLOBALS.length; i++) {
4651 set.add(GLOBALS[i]);
4654 fStackUnassigned.add(set);
4657 private void pushIfVariableSet() {
4658 if (!fStackUnassigned.isEmpty()) {
4659 HashSet set = new HashSet();
4660 fStackUnassigned.add(set);
4664 private HashSet removeIfVariableSet() {
4665 if (!fStackUnassigned.isEmpty()) {
4666 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4672 * Returns the <i>set of assigned variables </i> returns null if no Set is defined at the current scanner position
4674 private HashSet peekVariableSet() {
4675 if (!fStackUnassigned.isEmpty()) {
4676 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4682 * add the current identifier source to the <i>set of assigned variables </i>
4686 private void addVariableSet(HashSet set) {
4688 set.add(new String(scanner.getCurrentTokenSource()));
4693 * add the current identifier source to the <i>set of assigned variables </i>
4696 private void addVariableSet() {
4697 HashSet set = peekVariableSet();
4699 set.add(new String(scanner.getCurrentTokenSource()));
4704 * add the current identifier source to the <i>set of assigned variables </i>
4707 private void addVariableSet(char[] token) {
4708 HashSet set = peekVariableSet();
4710 set.add(new String(token));
4715 * check if the current identifier source is in the <i>set of assigned variables </i> Returns true, if no set is defined for the
4716 * current scanner position
4719 private boolean containsVariableSet() {
4720 return containsVariableSet(scanner.getCurrentTokenSource());
4721 // if (!fStackUnassigned.isEmpty()) {
4723 // String str = new String(scanner.getCurrentTokenSource());
4724 // for (int i = 0; i < fStackUnassigned.size(); i++) {
4725 // set = (HashSet) fStackUnassigned.get(i);
4726 // if (set.contains(str)) {
4735 private boolean containsVariableSet(char[] token) {
4737 if (!fStackUnassigned.isEmpty()) {
4739 String str = new String(token);
4740 for (int i = 0; i < fStackUnassigned.size(); i++) {
4741 set = (HashSet) fStackUnassigned.get(i);
4742 if (set.contains(str)) {