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.ICompilationUnit;
15 import net.sourceforge.phpdt.core.IJavaElement;
16 import net.sourceforge.phpdt.core.IType;
17 import net.sourceforge.phpdt.core.JavaCore;
18 import net.sourceforge.phpdt.core.JavaModelException;
19 import net.sourceforge.phpdt.core.compiler.CharOperation;
20 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
21 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
22 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
23 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
24 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
25 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
26 import net.sourceforge.phpdt.internal.compiler.ast.Block;
27 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
28 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
30 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
31 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
32 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
33 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
35 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
36 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
37 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
38 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
39 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
40 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
41 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
42 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
43 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
44 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
45 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
46 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
47 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
48 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
49 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
50 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
51 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
52 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
53 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
54 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
55 import net.sourceforge.phpdt.internal.compiler.util.Util;
56 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
57 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
58 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
60 import org.eclipse.core.resources.IFile;
61 import org.eclipse.core.resources.IProject;
62 import org.eclipse.core.resources.IResource;
63 import org.eclipse.core.runtime.IPath;
65 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
66 protected final static int StackIncrement = 255;
68 protected int stateStackTop;
70 // protected int[] stack = new int[StackIncrement];
72 public int firstToken; // handle for multiple parsing goals
74 public int lastAct; // handle for multiple parsing goals
76 // protected RecoveredElement currentElement;
78 public static boolean VERBOSE_RECOVERY = false;
80 protected boolean diet = false; // tells the scanner to jump over some
83 * the PHP token scanner
85 public Scanner scanner;
89 protected int modifiers;
91 protected int modifiersSourceStart;
93 protected Parser(ProblemReporter problemReporter) {
94 this.problemReporter = problemReporter;
95 this.options = problemReporter.options;
96 this.token = TokenNameEOF;
97 this.initializeScanner();
100 public void setFileToParse(IFile fileToParse) {
101 this.token = TokenNameEOF;
102 this.initializeScanner();
106 * ClassDeclaration Constructor.
110 * Description of Parameter
113 public Parser(IFile fileToParse) {
114 // if (keywordMap == null) {
115 // keywordMap = new HashMap();
116 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
117 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
120 // this.currentPHPString = 0;
121 // PHPParserSuperclass.fileToParse = fileToParse;
122 // this.phpList = null;
123 this.includesList = null;
125 this.token = TokenNameEOF;
127 // this.rowCount = 1;
128 // this.columnCount = 0;
129 // this.phpEnd = false;
131 this.initializeScanner();
134 public void initializeScanner() {
135 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
136 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
137 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
141 * Create marker for the parse error
143 // private void setMarker(String message, int charStart, int charEnd, int
145 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
148 * This method will throw the SyntaxError. It will add the good lines and
149 * columns to the Error
153 * @throws SyntaxError
156 private void throwSyntaxError(String error) {
157 int problemStartPosition = scanner.getCurrentTokenStartPosition();
158 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
159 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
160 problemEndPosition = scanner.source.length - 1;
161 if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
162 problemStartPosition = problemEndPosition - 1;
165 throwSyntaxError(error, problemStartPosition, problemEndPosition);
169 * This method will throw the SyntaxError. It will add the good lines and
170 * columns to the Error
174 * @throws SyntaxError
177 // private void throwSyntaxError(String error, int startRow) {
178 // throw new SyntaxError(startRow, 0, " ", error);
180 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
181 if (referenceContext != null) {
182 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
183 compilationUnit.compilationResult);
185 throw new SyntaxError(1, 0, " ", error);
188 private void reportSyntaxError(String error) {
189 int problemStartPosition = scanner.getCurrentTokenStartPosition();
190 int problemEndPosition = scanner.getCurrentTokenEndPosition();
191 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
194 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
195 if (referenceContext != null) {
196 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
197 compilationUnit.compilationResult);
201 // private void reportSyntaxWarning(String error, int problemStartPosition,
202 // int problemEndPosition) {
203 // if (referenceContext != null) {
204 // problemReporter.phpParsingWarning(new String[] { error },
205 // problemStartPosition, problemEndPosition, referenceContext,
206 // compilationUnit.compilationResult);
211 * gets the next token from input
213 private void getNextToken() {
215 token = scanner.getNextToken();
217 int currentEndPosition = scanner.getCurrentTokenEndPosition();
218 int currentStartPosition = scanner.getCurrentTokenStartPosition();
219 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
220 System.out.println(scanner.toStringAction(token));
222 } catch (InvalidInputException e) {
223 token = TokenNameERROR;
224 String detailedMessage = e.getMessage();
226 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
227 throwSyntaxError("Unterminated string.");
228 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
229 throwSyntaxError("Unterminated commment.");
235 public void init(String s) {
237 this.token = TokenNameEOF;
238 this.includesList = new ArrayList();
240 // this.rowCount = 1;
241 // this.columnCount = 0;
242 // this.phpEnd = false;
243 // this.phpMode = false;
244 /* scanner initialization */
245 scanner.setSource(s.toCharArray());
246 scanner.setPHPMode(false);
250 protected void initialize(boolean phpMode) {
251 initialize(phpMode, null);
254 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
255 compilationUnit = null;
256 referenceContext = null;
257 this.includesList = new ArrayList();
258 // this.indexManager = indexManager;
260 this.token = TokenNameEOF;
262 // this.rowCount = 1;
263 // this.columnCount = 0;
264 // this.phpEnd = false;
265 // this.phpMode = phpMode;
266 scanner.setPHPMode(phpMode);
271 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
274 public void parse(String s) {
279 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
282 public void parse(String s, HashMap variables) {
283 fMethodVariables = variables;
284 fStackUnassigned = new ArrayList();
290 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
293 protected void parse() {
294 if (scanner.compilationUnit != null) {
295 IResource resource = scanner.compilationUnit.getResource();
296 if (resource != null && resource instanceof IFile) {
297 // set the package name
298 consumePackageDeclarationName((IFile) resource);
304 if (token != TokenNameEOF && token != TokenNameERROR) {
307 if (token != TokenNameEOF) {
308 if (token == TokenNameERROR) {
309 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
311 if (token == TokenNameRPAREN) {
312 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
314 if (token == TokenNameRBRACE) {
315 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
317 if (token == TokenNameRBRACKET) {
318 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
320 if (token == TokenNameLPAREN) {
321 throwSyntaxError("Read character '('; end-of-file not reached.");
323 if (token == TokenNameLBRACE) {
324 throwSyntaxError("Read character '{'; end-of-file not reached.");
326 if (token == TokenNameLBRACKET) {
327 throwSyntaxError("Read character '['; end-of-file not reached.");
329 throwSyntaxError("End-of-file not reached.");
332 } catch (SyntaxError syntaxError) {
333 // syntaxError.printStackTrace();
342 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
345 public void parseFunction(String s, HashMap variables) {
347 scanner.phpMode = true;
348 parseFunction(variables);
352 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
355 protected void parseFunction(HashMap variables) {
357 boolean hasModifiers = member_modifiers();
358 if (token == TokenNamefunction) {
360 checkAndSetModifiers(AccPublic);
362 this.fMethodVariables = variables;
364 MethodDeclaration methodDecl = new MethodDeclaration(null);
365 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
366 methodDecl.modifiers = this.modifiers;
367 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
370 functionDefinition(methodDecl);
371 } catch (SyntaxError sytaxErr1) {
374 int sourceEnd = methodDecl.sourceEnd;
375 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
376 sourceEnd = methodDecl.declarationSourceStart + 1;
378 methodDecl.sourceEnd = sourceEnd;
379 methodDecl.declarationSourceEnd = sourceEnd;
384 protected CompilationUnitDeclaration endParse(int act) {
388 // if (currentElement != null) {
389 // currentElement.topElement().updateParseTree();
390 // if (VERBOSE_RECOVERY) {
391 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
392 // System.out.println("--------------------------"); //$NON-NLS-1$
393 // System.out.println(compilationUnit);
394 // System.out.println("----------------------------------"); //$NON-NLS-1$
397 if (diet & VERBOSE_RECOVERY) {
398 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
399 System.out.println("--------------------------"); //$NON-NLS-1$
400 System.out.println(compilationUnit);
401 System.out.println("----------------------------------"); //$NON-NLS-1$
404 if (scanner.recordLineSeparator) {
405 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
407 if (scanner.taskTags != null) {
408 for (int i = 0; i < scanner.foundTaskCount; i++) {
409 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
410 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
411 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
414 compilationUnit.imports = new ImportReference[includesList.size()];
415 for (int i = 0; i < includesList.size(); i++) {
416 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
418 return compilationUnit;
421 private Block statementList() {
422 boolean branchStatement = false;
424 int blockStart = scanner.getCurrentTokenStartPosition();
425 ArrayList blockStatements = new ArrayList();
428 statement = statement();
429 blockStatements.add(statement);
430 if (token == TokenNameEOF) {
433 if (branchStatement && statement != null) {
434 // reportSyntaxError("Unreachable code", statement.sourceStart,
435 // statement.sourceEnd);
436 if (! (statement instanceof BreakStatement)) {
437 /* don't give an error for break statement following return statement
438 Technically it's unreachable code, but in switch-case it's recommended to
439 avoid accidental fall-through later when editing the code */
440 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
441 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
444 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
445 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
446 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
447 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
448 return createBlock(blockStart, blockStatements);
450 branchStatement = checkUnreachableStatements(statement);
451 } catch (SyntaxError sytaxErr1) {
452 // if an error occured,
453 // try to find keywords
454 // to parse the rest of the string
455 boolean tokenize = scanner.tokenizeStrings;
457 scanner.tokenizeStrings = true;
460 while (token != TokenNameEOF) {
461 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
462 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
463 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
464 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
465 return createBlock(blockStart, blockStatements);
467 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
468 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
469 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameECHO_INVISIBLE
470 || token == TokenNameglobal || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction
471 || token == TokenNamedeclare || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow
472 || token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
475 // System.out.println(scanner.toStringAction(token));
477 // System.out.println(scanner.toStringAction(token));
479 if (token == TokenNameEOF) {
483 scanner.tokenizeStrings = tokenize;
493 private boolean checkUnreachableStatements(Statement statement) {
494 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
496 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
504 * @param blockStatements
507 private Block createBlock(int blockStart, ArrayList blockStatements) {
508 int blockEnd = scanner.getCurrentTokenEndPosition();
509 Block b = Block.EmptyWith(blockStart, blockEnd);
510 b.statements = new Statement[blockStatements.size()];
511 blockStatements.toArray(b.statements);
515 private void functionBody(MethodDeclaration methodDecl) {
516 // '{' [statement-list] '}'
517 if (token == TokenNameLBRACE) {
520 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
521 throwSyntaxError("'{' expected in compound-statement.");
523 if (token != TokenNameRBRACE) {
526 if (token == TokenNameRBRACE) {
527 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
530 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
531 throwSyntaxError("'}' expected in compound-statement.");
535 private Statement statement() {
536 Statement statement = null;
537 Expression expression;
538 int sourceStart = scanner.getCurrentTokenStartPosition();
540 if (token == TokenNameif) {
541 // T_IF '(' expr ')' statement elseif_list else_single
542 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
543 // new_else_single T_ENDIF ';'
545 if (token == TokenNameLPAREN) {
548 throwSyntaxError("'(' expected after 'if' keyword.");
551 if (token == TokenNameRPAREN) {
554 throwSyntaxError("')' expected after 'if' condition.");
556 // create basic IfStatement
557 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
558 if (token == TokenNameCOLON) {
560 ifStatementColon(ifStatement);
562 ifStatement(ifStatement);
565 } else if (token == TokenNameswitch) {
567 if (token == TokenNameLPAREN) {
570 throwSyntaxError("'(' expected after 'switch' keyword.");
573 if (token == TokenNameRPAREN) {
576 throwSyntaxError("')' expected after 'switch' condition.");
580 } else if (token == TokenNamefor) {
582 if (token == TokenNameLPAREN) {
585 throwSyntaxError("'(' expected after 'for' keyword.");
587 if (token == TokenNameSEMICOLON) {
591 if (token == TokenNameSEMICOLON) {
594 throwSyntaxError("';' expected after 'for'.");
597 if (token == TokenNameSEMICOLON) {
601 if (token == TokenNameSEMICOLON) {
604 throwSyntaxError("';' expected after 'for'.");
607 if (token == TokenNameRPAREN) {
611 if (token == TokenNameRPAREN) {
614 throwSyntaxError("')' expected after 'for'.");
619 } else if (token == TokenNamewhile) {
621 if (token == TokenNameLPAREN) {
624 throwSyntaxError("'(' expected after 'while' keyword.");
627 if (token == TokenNameRPAREN) {
630 throwSyntaxError("')' expected after 'while' condition.");
634 } else if (token == TokenNamedo) {
636 if (token == TokenNameLBRACE) {
638 if (token != TokenNameRBRACE) {
641 if (token == TokenNameRBRACE) {
644 throwSyntaxError("'}' expected after 'do' keyword.");
649 if (token == TokenNamewhile) {
651 if (token == TokenNameLPAREN) {
654 throwSyntaxError("'(' expected after 'while' keyword.");
657 if (token == TokenNameRPAREN) {
660 throwSyntaxError("')' expected after 'while' condition.");
663 throwSyntaxError("'while' expected after 'do' keyword.");
665 if (token == TokenNameSEMICOLON) {
668 if (token != TokenNameINLINE_HTML) {
669 throwSyntaxError("';' expected after do-while statement.");
674 } else if (token == TokenNameforeach) {
676 if (token == TokenNameLPAREN) {
679 throwSyntaxError("'(' expected after 'foreach' keyword.");
682 if (token == TokenNameas) {
685 throwSyntaxError("'as' expected after 'foreach' exxpression.");
689 foreach_optional_arg();
690 if (token == TokenNameEQUAL_GREATER) {
692 variable(false, false);
694 if (token == TokenNameRPAREN) {
697 throwSyntaxError("')' expected after 'foreach' expression.");
701 } else if (token == TokenNamebreak) {
704 if (token != TokenNameSEMICOLON) {
707 if (token == TokenNameSEMICOLON) {
708 sourceEnd = scanner.getCurrentTokenEndPosition();
711 if (token != TokenNameINLINE_HTML) {
712 throwSyntaxError("';' expected after 'break'.");
714 sourceEnd = scanner.getCurrentTokenEndPosition();
717 return new BreakStatement(null, sourceStart, sourceEnd);
718 } else if (token == TokenNamecontinue) {
721 if (token != TokenNameSEMICOLON) {
724 if (token == TokenNameSEMICOLON) {
725 sourceEnd = scanner.getCurrentTokenEndPosition();
728 if (token != TokenNameINLINE_HTML) {
729 throwSyntaxError("';' expected after 'continue'.");
731 sourceEnd = scanner.getCurrentTokenEndPosition();
734 return new ContinueStatement(null, sourceStart, sourceEnd);
735 } else if (token == TokenNamereturn) {
738 if (token != TokenNameSEMICOLON) {
741 if (token == TokenNameSEMICOLON) {
742 sourceEnd = scanner.getCurrentTokenEndPosition();
745 if (token != TokenNameINLINE_HTML) {
746 throwSyntaxError("';' expected after 'return'.");
748 sourceEnd = scanner.getCurrentTokenEndPosition();
751 return new ReturnStatement(expression, sourceStart, sourceEnd);
752 } else if (token == TokenNameecho) {
755 if (token == TokenNameSEMICOLON) {
758 if (token != TokenNameINLINE_HTML) {
759 throwSyntaxError("';' expected after 'echo' statement.");
764 } else if (token == TokenNameECHO_INVISIBLE) {
765 // 0-length token directly after PHP short tag <?=
768 if (token == TokenNameSEMICOLON) {
770 // if (token != TokenNameINLINE_HTML) {
771 // // TODO should this become a configurable warning?
772 // reportSyntaxError("Probably '?>' expected after PHP short tag
773 // expression (only the first expression will be echoed).");
776 if (token != TokenNameINLINE_HTML) {
777 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
782 } else if (token == TokenNameINLINE_HTML) {
785 } else if (token == TokenNameglobal) {
788 if (token == TokenNameSEMICOLON) {
791 if (token != TokenNameINLINE_HTML) {
792 throwSyntaxError("';' expected after 'global' statement.");
797 } else if (token == TokenNamestatic) {
800 if (token == TokenNameSEMICOLON) {
803 if (token != TokenNameINLINE_HTML) {
804 throwSyntaxError("';' expected after 'static' statement.");
809 } else if (token == TokenNameunset) {
811 if (token == TokenNameLPAREN) {
814 throwSyntaxError("'(' expected after 'unset' statement.");
817 if (token == TokenNameRPAREN) {
820 throwSyntaxError("')' expected after 'unset' statement.");
822 if (token == TokenNameSEMICOLON) {
825 if (token != TokenNameINLINE_HTML) {
826 throwSyntaxError("';' expected after 'unset' statement.");
831 } else if (token == TokenNamefunction) {
832 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
833 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
834 methodDecl.modifiers = AccDefault;
835 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
838 functionDefinition(methodDecl);
840 sourceEnd = methodDecl.sourceEnd;
841 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
842 sourceEnd = methodDecl.declarationSourceStart + 1;
844 methodDecl.declarationSourceEnd = sourceEnd;
845 methodDecl.sourceEnd = sourceEnd;
848 } else if (token == TokenNamedeclare) {
849 // T_DECLARE '(' declare_list ')' declare_statement
851 if (token != TokenNameLPAREN) {
852 throwSyntaxError("'(' expected in 'declare' statement.");
856 if (token != TokenNameRPAREN) {
857 throwSyntaxError("')' expected in 'declare' statement.");
862 } else if (token == TokenNametry) {
864 if (token != TokenNameLBRACE) {
865 throwSyntaxError("'{' expected in 'try' statement.");
869 if (token != TokenNameRBRACE) {
870 throwSyntaxError("'}' expected in 'try' statement.");
874 } else if (token == TokenNamecatch) {
876 if (token != TokenNameLPAREN) {
877 throwSyntaxError("'(' expected in 'catch' statement.");
880 fully_qualified_class_name();
881 if (token != TokenNameVariable) {
882 throwSyntaxError("Variable expected in 'catch' statement.");
886 if (token != TokenNameRPAREN) {
887 throwSyntaxError("')' expected in 'catch' statement.");
890 if (token != TokenNameLBRACE) {
891 throwSyntaxError("'{' expected in 'catch' statement.");
894 if (token != TokenNameRBRACE) {
896 if (token != TokenNameRBRACE) {
897 throwSyntaxError("'}' expected in 'catch' statement.");
901 additional_catches();
903 } else if (token == TokenNamethrow) {
906 if (token == TokenNameSEMICOLON) {
909 throwSyntaxError("';' expected after 'throw' exxpression.");
912 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
914 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
915 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
916 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
917 typeDecl.name = new char[] { ' ' };
918 // default super class
919 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
920 compilationUnit.types.add(typeDecl);
921 pushOnAstStack(typeDecl);
922 unticked_class_declaration_statement(typeDecl);
930 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
931 } else if (token == TokenNameLBRACE) {
933 if (token != TokenNameRBRACE) {
934 statement = statementList();
936 if (token == TokenNameRBRACE) {
940 throwSyntaxError("'}' expected.");
943 if (token != TokenNameSEMICOLON) {
946 if (token == TokenNameSEMICOLON) {
950 if (token == TokenNameRBRACE) {
951 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
953 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
954 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
964 private void declare_statement() {
966 // | ':' inner_statement_list T_ENDDECLARE ';'
968 if (token == TokenNameCOLON) {
970 // TODO: implement inner_statement_list();
972 if (token != TokenNameenddeclare) {
973 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
976 if (token != TokenNameSEMICOLON) {
977 throwSyntaxError("';' expected after 'enddeclare' keyword.");
985 private void declare_list() {
986 // T_STRING '=' static_scalar
987 // | declare_list ',' T_STRING '=' static_scalar
989 if (token != TokenNameIdentifier) {
990 throwSyntaxError("Identifier expected in 'declare' list.");
993 if (token != TokenNameEQUAL) {
994 throwSyntaxError("'=' expected in 'declare' list.");
998 if (token != TokenNameCOMMA) {
1005 private void additional_catches() {
1006 while (token == TokenNamecatch) {
1008 if (token != TokenNameLPAREN) {
1009 throwSyntaxError("'(' expected in 'catch' statement.");
1012 fully_qualified_class_name();
1013 if (token != TokenNameVariable) {
1014 throwSyntaxError("Variable expected in 'catch' statement.");
1018 if (token != TokenNameRPAREN) {
1019 throwSyntaxError("')' expected in 'catch' statement.");
1022 if (token != TokenNameLBRACE) {
1023 throwSyntaxError("'{' expected in 'catch' statement.");
1026 if (token != TokenNameRBRACE) {
1029 if (token != TokenNameRBRACE) {
1030 throwSyntaxError("'}' expected in 'catch' statement.");
1036 private void foreach_variable() {
1039 if (token == TokenNameAND) {
1045 private void foreach_optional_arg() {
1047 // | T_DOUBLE_ARROW foreach_variable
1048 if (token == TokenNameEQUAL_GREATER) {
1054 private void global_var_list() {
1056 // global_var_list ',' global_var
1058 HashSet set = peekVariableSet();
1061 if (token != TokenNameCOMMA) {
1068 private void global_var(HashSet set) {
1072 // | '$' '{' expr '}'
1073 if (token == TokenNameVariable) {
1074 if (fMethodVariables != null) {
1075 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1076 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1078 addVariableSet(set);
1080 } else if (token == TokenNameDOLLAR) {
1082 if (token == TokenNameLBRACE) {
1085 if (token != TokenNameRBRACE) {
1086 throwSyntaxError("'}' expected in global variable.");
1095 private void static_var_list() {
1097 // static_var_list ',' T_VARIABLE
1098 // | static_var_list ',' T_VARIABLE '=' static_scalar
1100 // | T_VARIABLE '=' static_scalar,
1101 HashSet set = peekVariableSet();
1103 if (token == TokenNameVariable) {
1104 if (fMethodVariables != null) {
1105 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1106 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1108 addVariableSet(set);
1110 if (token == TokenNameEQUAL) {
1114 if (token != TokenNameCOMMA) {
1124 private void unset_variables() {
1127 // | unset_variables ',' unset_variable
1131 variable(false, false);
1132 if (token != TokenNameCOMMA) {
1139 private final void initializeModifiers() {
1141 this.modifiersSourceStart = -1;
1144 private final void checkAndSetModifiers(int flag) {
1145 this.modifiers |= flag;
1146 if (this.modifiersSourceStart < 0)
1147 this.modifiersSourceStart = this.scanner.startPosition;
1150 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1151 initializeModifiers();
1152 if (token == TokenNameinterface) {
1153 // interface_entry T_STRING
1154 // interface_extends_list
1155 // '{' class_statement_list '}'
1156 checkAndSetModifiers(AccInterface);
1158 typeDecl.modifiers = this.modifiers;
1159 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1160 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1161 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1162 typeDecl.name = scanner.getCurrentIdentifierSource();
1163 if (token > TokenNameKEYWORD) {
1164 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1165 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1166 // throwSyntaxError("Don't use a keyword for interface declaration ["
1167 // + scanner.toStringAction(token) + "].",
1168 // typeDecl.sourceStart, typeDecl.sourceEnd);
1171 interface_extends_list(typeDecl);
1173 typeDecl.name = new char[] { ' ' };
1174 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1178 // class_entry_type T_STRING extends_from
1180 // '{' class_statement_list'}'
1182 typeDecl.modifiers = this.modifiers;
1183 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1184 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1186 // identifier 'extends' identifier
1187 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1188 typeDecl.name = scanner.getCurrentIdentifierSource();
1189 if (token > TokenNameKEYWORD) {
1190 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1191 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1192 // throwSyntaxError("Don't use a keyword for class declaration [" +
1193 // scanner.toStringAction(token) + "].",
1194 // typeDecl.sourceStart, typeDecl.sourceEnd);
1199 // | T_EXTENDS fully_qualified_class_name
1200 if (token == TokenNameextends) {
1201 interface_extends_list(typeDecl);
1203 // if (token != TokenNameIdentifier) {
1204 // throwSyntaxError("Class name expected after keyword
1206 // scanner.getCurrentTokenStartPosition(), scanner
1207 // .getCurrentTokenEndPosition());
1210 implements_list(typeDecl);
1212 typeDecl.name = new char[] { ' ' };
1213 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1217 // '{' class_statement_list '}'
1218 if (token == TokenNameLBRACE) {
1220 if (token != TokenNameRBRACE) {
1221 ArrayList list = new ArrayList();
1222 class_statement_list(list);
1223 typeDecl.fields = new FieldDeclaration[list.size()];
1224 for (int i = 0; i < list.size(); i++) {
1225 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1228 if (token == TokenNameRBRACE) {
1229 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1232 throwSyntaxError("'}' expected at end of class body.");
1235 throwSyntaxError("'{' expected at start of class body.");
1239 private void class_entry_type() {
1241 // | T_ABSTRACT T_CLASS
1242 // | T_FINAL T_CLASS
1243 if (token == TokenNameclass) {
1245 } else if (token == TokenNameabstract) {
1246 checkAndSetModifiers(AccAbstract);
1248 if (token != TokenNameclass) {
1249 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1252 } else if (token == TokenNamefinal) {
1253 checkAndSetModifiers(AccFinal);
1255 if (token != TokenNameclass) {
1256 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1260 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1264 // private void class_extends(TypeDeclaration typeDecl) {
1266 // // | T_EXTENDS interface_list
1267 // if (token == TokenNameextends) {
1270 // if (token == TokenNameIdentifier) {
1273 // throwSyntaxError("Class name expected after keyword 'extends'.");
1278 private void interface_extends_list(TypeDeclaration typeDecl) {
1280 // | T_EXTENDS interface_list
1281 if (token == TokenNameextends) {
1283 class_list(typeDecl);
1287 private void implements_list(TypeDeclaration typeDecl) {
1289 // | T_IMPLEMENTS interface_list
1290 if (token == TokenNameimplements) {
1292 interface_list(typeDecl);
1296 private void class_list(TypeDeclaration typeDecl) {
1298 // fully_qualified_class_name
1300 if (token == TokenNameIdentifier) {
1301 char[] ident = scanner.getCurrentIdentifierSource();
1302 // TODO make this code working better:
1303 // SingleTypeReference ref = ParserUtil.getTypeReference(scanner,
1304 // includesList, ident);
1305 // if (ref != null) {
1306 // typeDecl.superclass = ref;
1310 throwSyntaxError("Classname expected after keyword 'extends'.");
1312 if (token == TokenNameCOMMA) {
1313 reportSyntaxError("No multiple inheritence allowed. Expected token 'implements' or '{'.");
1322 private void interface_list(TypeDeclaration typeDecl) {
1324 // fully_qualified_class_name
1325 // | interface_list ',' fully_qualified_class_name
1327 if (token == TokenNameIdentifier) {
1330 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1332 if (token != TokenNameCOMMA) {
1339 // private void classBody(TypeDeclaration typeDecl) {
1340 // //'{' [class-element-list] '}'
1341 // if (token == TokenNameLBRACE) {
1343 // if (token != TokenNameRBRACE) {
1344 // class_statement_list();
1346 // if (token == TokenNameRBRACE) {
1347 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1350 // throwSyntaxError("'}' expected at end of class body.");
1353 // throwSyntaxError("'{' expected at start of class body.");
1356 private void class_statement_list(ArrayList list) {
1359 class_statement(list);
1360 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1361 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1362 || token == TokenNameconst) {
1365 if (token == TokenNameRBRACE) {
1368 throwSyntaxError("'}' at end of class statement.");
1369 } catch (SyntaxError sytaxErr1) {
1370 boolean tokenize = scanner.tokenizeStrings;
1372 scanner.tokenizeStrings = true;
1375 // if an error occured,
1376 // try to find keywords
1377 // to parse the rest of the string
1378 while (token != TokenNameEOF) {
1379 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1380 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1381 || token == TokenNameconst) {
1384 // System.out.println(scanner.toStringAction(token));
1387 if (token == TokenNameEOF) {
1391 scanner.tokenizeStrings = tokenize;
1397 private void class_statement(ArrayList list) {
1399 // variable_modifiers class_variable_declaration ';'
1400 // | class_constant_declaration ';'
1401 // | method_modifiers T_FUNCTION is_reference T_STRING
1402 // '(' parameter_list ')' method_body
1403 initializeModifiers();
1404 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1406 if (token == TokenNamevar) {
1407 checkAndSetModifiers(AccPublic);
1408 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1409 referenceContext, compilationUnit.compilationResult);
1411 class_variable_declaration(declarationSourceStart, list);
1412 } else if (token == TokenNameconst) {
1413 checkAndSetModifiers(AccFinal | AccPublic);
1414 class_constant_declaration(declarationSourceStart, list);
1415 if (token != TokenNameSEMICOLON) {
1416 throwSyntaxError("';' expected after class const declaration.");
1420 boolean hasModifiers = member_modifiers();
1421 if (token == TokenNamefunction) {
1422 if (!hasModifiers) {
1423 checkAndSetModifiers(AccPublic);
1425 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1426 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1427 methodDecl.modifiers = this.modifiers;
1428 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1431 functionDefinition(methodDecl);
1433 int sourceEnd = methodDecl.sourceEnd;
1434 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1435 sourceEnd = methodDecl.declarationSourceStart + 1;
1437 methodDecl.declarationSourceEnd = sourceEnd;
1438 methodDecl.sourceEnd = sourceEnd;
1441 if (!hasModifiers) {
1442 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1444 class_variable_declaration(declarationSourceStart, list);
1449 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1450 // class_constant_declaration ',' T_STRING '=' static_scalar
1451 // | T_CONST T_STRING '=' static_scalar
1452 if (token != TokenNameconst) {
1453 throwSyntaxError("'const' keyword expected in class declaration.");
1458 if (token != TokenNameIdentifier) {
1459 throwSyntaxError("Identifier expected in class const declaration.");
1461 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1462 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1463 fieldDeclaration.modifiers = this.modifiers;
1464 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1465 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1466 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1467 // fieldDeclaration.type
1468 list.add(fieldDeclaration);
1470 if (token != TokenNameEQUAL) {
1471 throwSyntaxError("'=' expected in class const declaration.");
1475 if (token != TokenNameCOMMA) {
1476 break; // while(true)-loop
1482 // private void variable_modifiers() {
1483 // // variable_modifiers:
1484 // // non_empty_member_modifiers
1486 // initializeModifiers();
1487 // if (token == TokenNamevar) {
1488 // checkAndSetModifiers(AccPublic);
1489 // reportSyntaxError(
1490 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1492 // modifier for field declarations.",
1493 // scanner.getCurrentTokenStartPosition(), scanner
1494 // .getCurrentTokenEndPosition());
1497 // if (!member_modifiers()) {
1498 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1499 // field declarations.");
1503 // private void method_modifiers() {
1504 // //method_modifiers:
1506 // //| non_empty_member_modifiers
1507 // initializeModifiers();
1508 // if (!member_modifiers()) {
1509 // checkAndSetModifiers(AccPublic);
1512 private boolean member_modifiers() {
1519 boolean foundToken = false;
1521 if (token == TokenNamepublic) {
1522 checkAndSetModifiers(AccPublic);
1525 } else if (token == TokenNameprotected) {
1526 checkAndSetModifiers(AccProtected);
1529 } else if (token == TokenNameprivate) {
1530 checkAndSetModifiers(AccPrivate);
1533 } else if (token == TokenNamestatic) {
1534 checkAndSetModifiers(AccStatic);
1537 } else if (token == TokenNameabstract) {
1538 checkAndSetModifiers(AccAbstract);
1541 } else if (token == TokenNamefinal) {
1542 checkAndSetModifiers(AccFinal);
1552 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1553 // class_variable_declaration:
1554 // class_variable_declaration ',' T_VARIABLE
1555 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1557 // | T_VARIABLE '=' static_scalar
1558 char[] classVariable;
1560 if (token == TokenNameVariable) {
1561 classVariable = scanner.getCurrentIdentifierSource();
1562 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1564 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1565 .getCurrentTokenEndPosition());
1566 fieldDeclaration.modifiers = this.modifiers;
1567 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1568 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1569 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1570 list.add(fieldDeclaration);
1571 if (fTypeVariables != null) {
1572 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1573 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1576 if (token == TokenNameEQUAL) {
1581 // if (token == TokenNamethis) {
1582 // throwSyntaxError("'$this' not allowed after keyword 'public'
1583 // 'protected' 'private' 'var'.");
1585 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1587 if (token != TokenNameCOMMA) {
1592 if (token != TokenNameSEMICOLON) {
1593 throwSyntaxError("';' expected after field declaration.");
1598 private void functionDefinition(MethodDeclaration methodDecl) {
1599 boolean isAbstract = false;
1601 if (compilationUnit != null) {
1602 compilationUnit.types.add(methodDecl);
1605 ASTNode node = astStack[astPtr];
1606 if (node instanceof TypeDeclaration) {
1607 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1608 if (typeDecl.methods == null) {
1609 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1611 AbstractMethodDeclaration[] newMethods;
1612 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1613 typeDecl.methods.length);
1614 newMethods[typeDecl.methods.length] = methodDecl;
1615 typeDecl.methods = newMethods;
1617 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1619 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1625 pushFunctionVariableSet();
1626 functionDeclarator(methodDecl);
1627 if (token == TokenNameSEMICOLON) {
1629 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1630 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1635 functionBody(methodDecl);
1637 if (!fStackUnassigned.isEmpty()) {
1638 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1643 private void functionDeclarator(MethodDeclaration methodDecl) {
1644 // identifier '(' [parameter-list] ')'
1645 if (token == TokenNameAND) {
1648 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1649 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1650 if (Scanner.isIdentifierOrKeyword(token)) {
1651 methodDecl.selector = scanner.getCurrentIdentifierSource();
1652 if (token > TokenNameKEYWORD) {
1653 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1654 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1657 if (token == TokenNameLPAREN) {
1660 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1661 throwSyntaxError("'(' expected in function declaration.");
1663 if (token != TokenNameRPAREN) {
1664 parameter_list(methodDecl);
1666 if (token != TokenNameRPAREN) {
1667 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1668 throwSyntaxError("')' expected in function declaration.");
1670 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1674 methodDecl.selector = "<undefined>".toCharArray();
1675 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1676 throwSyntaxError("Function name expected after keyword 'function'.");
1681 private void parameter_list(MethodDeclaration methodDecl) {
1682 // non_empty_parameter_list
1684 non_empty_parameter_list(methodDecl, true);
1687 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1688 // optional_class_type T_VARIABLE
1689 // | optional_class_type '&' T_VARIABLE
1690 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1691 // | optional_class_type T_VARIABLE '=' static_scalar
1692 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1693 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1694 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1696 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1698 char[] typeIdentifier = null;
1699 if (token == TokenNameIdentifier || token == TokenNamearray || token == TokenNameVariable || token == TokenNameAND) {
1700 HashSet set = peekVariableSet();
1702 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature req. #1254275
1703 typeIdentifier = scanner.getCurrentIdentifierSource();
1706 if (token == TokenNameAND) {
1709 if (token == TokenNameVariable) {
1710 if (fMethodVariables != null) {
1712 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1713 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1715 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1717 info.typeIdentifier = typeIdentifier;
1718 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1720 addVariableSet(set);
1722 if (token == TokenNameEQUAL) {
1727 throwSyntaxError("Variable expected in parameter list.");
1729 if (token != TokenNameCOMMA) {
1736 if (!empty_allowed) {
1737 throwSyntaxError("Identifier expected in parameter list.");
1741 private void optional_class_type() {
1746 // private void parameterDeclaration() {
1748 // //variable-reference
1749 // if (token == TokenNameAND) {
1751 // if (isVariable()) {
1754 // throwSyntaxError("Variable expected after reference operator '&'.");
1757 // //variable '=' constant
1758 // if (token == TokenNameVariable) {
1760 // if (token == TokenNameEQUAL) {
1766 // // if (token == TokenNamethis) {
1767 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1768 // // declaration.");
1772 private void labeledStatementList() {
1773 if (token != TokenNamecase && token != TokenNamedefault) {
1774 throwSyntaxError("'case' or 'default' expected.");
1777 if (token == TokenNamecase) {
1779 expr(); // constant();
1780 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1782 if (token == TokenNameRBRACE) {
1783 // empty case; assumes that the '}' token belongs to the wrapping
1784 // switch statement - #1371992
1787 if (token == TokenNamecase || token == TokenNamedefault) {
1788 // empty case statement ?
1793 // else if (token == TokenNameSEMICOLON) {
1795 // "':' expected after 'case' keyword (Found token: " +
1796 // scanner.toStringAction(token) + ")",
1797 // scanner.getCurrentTokenStartPosition(),
1798 // scanner.getCurrentTokenEndPosition(),
1801 // if (token == TokenNamecase) { // empty case statement ?
1807 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1809 } else { // TokenNamedefault
1811 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1813 if (token == TokenNameRBRACE) {
1814 // empty default case; ; assumes that the '}' token belongs to the
1815 // wrapping switch statement - #1371992
1818 if (token != TokenNamecase) {
1822 throwSyntaxError("':' character expected after 'default'.");
1825 } while (token == TokenNamecase || token == TokenNamedefault);
1828 private void ifStatementColon(IfStatement iState) {
1829 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1830 // new_else_single T_ENDIF ';'
1831 HashSet assignedVariableSet = null;
1833 Block b = inner_statement_list();
1834 iState.thenStatement = b;
1835 checkUnreachable(iState, b);
1837 assignedVariableSet = removeIfVariableSet();
1839 if (token == TokenNameelseif) {
1841 pushIfVariableSet();
1842 new_elseif_list(iState);
1844 HashSet set = removeIfVariableSet();
1845 if (assignedVariableSet != null && set != null) {
1846 assignedVariableSet.addAll(set);
1851 pushIfVariableSet();
1852 new_else_single(iState);
1854 HashSet set = removeIfVariableSet();
1855 if (assignedVariableSet != null) {
1856 HashSet topSet = peekVariableSet();
1857 if (topSet != null) {
1861 topSet.addAll(assignedVariableSet);
1865 if (token != TokenNameendif) {
1866 throwSyntaxError("'endif' expected.");
1869 if (token != TokenNameSEMICOLON) {
1870 reportSyntaxError("';' expected after if-statement.");
1871 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1873 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1878 private void ifStatement(IfStatement iState) {
1879 // T_IF '(' expr ')' statement elseif_list else_single
1880 HashSet assignedVariableSet = null;
1882 pushIfVariableSet();
1883 Statement s = statement();
1884 iState.thenStatement = s;
1885 checkUnreachable(iState, s);
1887 assignedVariableSet = removeIfVariableSet();
1890 if (token == TokenNameelseif) {
1892 pushIfVariableSet();
1893 elseif_list(iState);
1895 HashSet set = removeIfVariableSet();
1896 if (assignedVariableSet != null && set != null) {
1897 assignedVariableSet.addAll(set);
1902 pushIfVariableSet();
1903 else_single(iState);
1905 HashSet set = removeIfVariableSet();
1906 if (assignedVariableSet != null) {
1907 HashSet topSet = peekVariableSet();
1908 if (topSet != null) {
1912 topSet.addAll(assignedVariableSet);
1918 private void elseif_list(IfStatement iState) {
1920 // | elseif_list T_ELSEIF '(' expr ')' statement
1921 ArrayList conditionList = new ArrayList();
1922 ArrayList statementList = new ArrayList();
1925 while (token == TokenNameelseif) {
1927 if (token == TokenNameLPAREN) {
1930 throwSyntaxError("'(' expected after 'elseif' keyword.");
1933 conditionList.add(e);
1934 if (token == TokenNameRPAREN) {
1937 throwSyntaxError("')' expected after 'elseif' condition.");
1940 statementList.add(s);
1941 checkUnreachable(iState, s);
1943 iState.elseifConditions = new Expression[conditionList.size()];
1944 iState.elseifStatements = new Statement[statementList.size()];
1945 conditionList.toArray(iState.elseifConditions);
1946 statementList.toArray(iState.elseifStatements);
1949 private void new_elseif_list(IfStatement iState) {
1951 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1952 ArrayList conditionList = new ArrayList();
1953 ArrayList statementList = new ArrayList();
1956 while (token == TokenNameelseif) {
1958 if (token == TokenNameLPAREN) {
1961 throwSyntaxError("'(' expected after 'elseif' keyword.");
1964 conditionList.add(e);
1965 if (token == TokenNameRPAREN) {
1968 throwSyntaxError("')' expected after 'elseif' condition.");
1970 if (token == TokenNameCOLON) {
1973 throwSyntaxError("':' expected after 'elseif' keyword.");
1975 b = inner_statement_list();
1976 statementList.add(b);
1977 checkUnreachable(iState, b);
1979 iState.elseifConditions = new Expression[conditionList.size()];
1980 iState.elseifStatements = new Statement[statementList.size()];
1981 conditionList.toArray(iState.elseifConditions);
1982 statementList.toArray(iState.elseifStatements);
1985 private void else_single(IfStatement iState) {
1988 if (token == TokenNameelse) {
1990 Statement s = statement();
1991 iState.elseStatement = s;
1992 checkUnreachable(iState, s);
1994 iState.checkUnreachable = false;
1996 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1999 private void new_else_single(IfStatement iState) {
2001 // | T_ELSE ':' inner_statement_list
2002 if (token == TokenNameelse) {
2004 if (token == TokenNameCOLON) {
2007 throwSyntaxError("':' expected after 'else' keyword.");
2009 Block b = inner_statement_list();
2010 iState.elseStatement = b;
2011 checkUnreachable(iState, b);
2013 iState.checkUnreachable = false;
2017 private Block inner_statement_list() {
2018 // inner_statement_list inner_statement
2020 return statementList();
2027 private void checkUnreachable(IfStatement iState, Statement s) {
2028 if (s instanceof Block) {
2029 Block b = (Block) s;
2030 if (b.statements == null || b.statements.length == 0) {
2031 iState.checkUnreachable = false;
2033 int off = b.statements.length - 1;
2034 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2035 && !(b.statements[off] instanceof BreakStatement)) {
2036 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2037 iState.checkUnreachable = false;
2042 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2043 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2044 iState.checkUnreachable = false;
2050 // private void elseifStatementList() {
2052 // elseifStatement();
2054 // case TokenNameelse:
2056 // if (token == TokenNameCOLON) {
2058 // if (token != TokenNameendif) {
2063 // if (token == TokenNameif) { //'else if'
2066 // throwSyntaxError("':' expected after 'else'.");
2070 // case TokenNameelseif:
2079 // private void elseifStatement() {
2080 // if (token == TokenNameLPAREN) {
2083 // if (token != TokenNameRPAREN) {
2084 // throwSyntaxError("')' expected in else-if-statement.");
2087 // if (token != TokenNameCOLON) {
2088 // throwSyntaxError("':' expected in else-if-statement.");
2091 // if (token != TokenNameendif) {
2097 private void switchStatement() {
2098 if (token == TokenNameCOLON) {
2099 // ':' [labeled-statement-list] 'endswitch' ';'
2101 labeledStatementList();
2102 if (token != TokenNameendswitch) {
2103 throwSyntaxError("'endswitch' expected.");
2106 if (token != TokenNameSEMICOLON) {
2107 throwSyntaxError("';' expected after switch-statement.");
2111 // '{' [labeled-statement-list] '}'
2112 if (token != TokenNameLBRACE) {
2113 throwSyntaxError("'{' expected in switch statement.");
2116 if (token != TokenNameRBRACE) {
2117 labeledStatementList();
2119 if (token != TokenNameRBRACE) {
2120 throwSyntaxError("'}' expected in switch statement.");
2126 private void forStatement() {
2127 if (token == TokenNameCOLON) {
2130 if (token != TokenNameendfor) {
2131 throwSyntaxError("'endfor' expected.");
2134 if (token != TokenNameSEMICOLON) {
2135 throwSyntaxError("';' expected after for-statement.");
2143 private void whileStatement() {
2144 // ':' statement-list 'endwhile' ';'
2145 if (token == TokenNameCOLON) {
2148 if (token != TokenNameendwhile) {
2149 throwSyntaxError("'endwhile' expected.");
2152 if (token != TokenNameSEMICOLON) {
2153 throwSyntaxError("';' expected after while-statement.");
2161 private void foreachStatement() {
2162 if (token == TokenNameCOLON) {
2165 if (token != TokenNameendforeach) {
2166 throwSyntaxError("'endforeach' expected.");
2169 if (token != TokenNameSEMICOLON) {
2170 throwSyntaxError("';' expected after foreach-statement.");
2178 // private void exitStatus() {
2179 // if (token == TokenNameLPAREN) {
2182 // throwSyntaxError("'(' expected in 'exit-status'.");
2184 // if (token != TokenNameRPAREN) {
2187 // if (token == TokenNameRPAREN) {
2190 // throwSyntaxError("')' expected after 'exit-status'.");
2193 private void expressionList() {
2196 if (token == TokenNameCOMMA) {
2204 private Expression expr() {
2206 // | expr_without_variable
2207 // if (token!=TokenNameEOF) {
2208 if (Scanner.TRACE) {
2209 System.out.println("TRACE: expr()");
2211 return expr_without_variable(true,null);
2215 private Expression expr_without_variable(boolean only_variable, UninitializedVariableHandler initHandler) {
2216 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2217 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2218 Expression expression = new Expression();
2219 expression.sourceStart = exprSourceStart;
2220 // default, may be overwritten
2221 expression.sourceEnd = exprSourceEnd;
2223 // internal_functions_in_yacc
2232 // | T_INC rw_variable
2233 // | T_DEC rw_variable
2234 // | T_INT_CAST expr
2235 // | T_DOUBLE_CAST expr
2236 // | T_STRING_CAST expr
2237 // | T_ARRAY_CAST expr
2238 // | T_OBJECT_CAST expr
2239 // | T_BOOL_CAST expr
2240 // | T_UNSET_CAST expr
2241 // | T_EXIT exit_expr
2243 // | T_ARRAY '(' array_pair_list ')'
2244 // | '`' encaps_list '`'
2245 // | T_LIST '(' assignment_list ')' '=' expr
2246 // | T_NEW class_name_reference ctor_arguments
2247 // | variable '=' expr
2248 // | variable '=' '&' variable
2249 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2250 // | variable T_PLUS_EQUAL expr
2251 // | variable T_MINUS_EQUAL expr
2252 // | variable T_MUL_EQUAL expr
2253 // | variable T_DIV_EQUAL expr
2254 // | variable T_CONCAT_EQUAL expr
2255 // | variable T_MOD_EQUAL expr
2256 // | variable T_AND_EQUAL expr
2257 // | variable T_OR_EQUAL expr
2258 // | variable T_XOR_EQUAL expr
2259 // | variable T_SL_EQUAL expr
2260 // | variable T_SR_EQUAL expr
2261 // | rw_variable T_INC
2262 // | rw_variable T_DEC
2263 // | expr T_BOOLEAN_OR expr
2264 // | expr T_BOOLEAN_AND expr
2265 // | expr T_LOGICAL_OR expr
2266 // | expr T_LOGICAL_AND expr
2267 // | expr T_LOGICAL_XOR expr
2279 // | expr T_IS_IDENTICAL expr
2280 // | expr T_IS_NOT_IDENTICAL expr
2281 // | expr T_IS_EQUAL expr
2282 // | expr T_IS_NOT_EQUAL expr
2284 // | expr T_IS_SMALLER_OR_EQUAL expr
2286 // | expr T_IS_GREATER_OR_EQUAL expr
2287 // | expr T_INSTANCEOF class_name_reference
2288 // | expr '?' expr ':' expr
2289 if (Scanner.TRACE) {
2290 System.out.println("TRACE: expr_without_variable() PART 1");
2293 case TokenNameisset:
2294 // T_ISSET '(' isset_variables ')'
2296 if (token != TokenNameLPAREN) {
2297 throwSyntaxError("'(' expected after keyword 'isset'");
2301 if (token != TokenNameRPAREN) {
2302 throwSyntaxError("')' expected after keyword 'isset'");
2306 case TokenNameempty:
2308 if (token != TokenNameLPAREN) {
2309 throwSyntaxError("'(' expected after keyword 'empty'");
2312 variable(true, false);
2313 if (token != TokenNameRPAREN) {
2314 throwSyntaxError("')' expected after keyword 'empty'");
2319 case TokenNameinclude:
2320 case TokenNameinclude_once:
2321 case TokenNamerequire:
2322 case TokenNamerequire_once:
2323 internal_functions_in_yacc();
2326 case TokenNameLPAREN:
2329 if (token == TokenNameRPAREN) {
2332 throwSyntaxError("')' expected in expression.");
2342 // | T_INT_CAST expr
2343 // | T_DOUBLE_CAST expr
2344 // | T_STRING_CAST expr
2345 // | T_ARRAY_CAST expr
2346 // | T_OBJECT_CAST expr
2347 // | T_BOOL_CAST expr
2348 // | T_UNSET_CAST expr
2349 case TokenNameclone:
2350 case TokenNameprint:
2353 case TokenNameMINUS:
2355 case TokenNameTWIDDLE:
2356 case TokenNameintCAST:
2357 case TokenNamedoubleCAST:
2358 case TokenNamestringCAST:
2359 case TokenNamearrayCAST:
2360 case TokenNameobjectCAST:
2361 case TokenNameboolCAST:
2362 case TokenNameunsetCAST:
2372 // | T_STRING_VARNAME
2374 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2375 // | '`' encaps_list '`'
2377 // | '`' encaps_list '`'
2378 // case TokenNameEncapsedString0:
2379 // scanner.encapsedStringStack.push(new Character('`'));
2382 // if (token == TokenNameEncapsedString0) {
2385 // if (token != TokenNameEncapsedString0) {
2386 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2387 // scanner.toStringAction(token) + " )");
2391 // scanner.encapsedStringStack.pop();
2395 // // | '\'' encaps_list '\''
2396 // case TokenNameEncapsedString1:
2397 // scanner.encapsedStringStack.push(new Character('\''));
2400 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2401 // if (token == TokenNameEncapsedString1) {
2403 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2404 // exprSourceStart, scanner
2405 // .getCurrentTokenEndPosition());
2408 // if (token != TokenNameEncapsedString1) {
2409 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2410 // + scanner.toStringAction(token) + " )");
2413 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2414 // exprSourceStart, scanner
2415 // .getCurrentTokenEndPosition());
2419 // scanner.encapsedStringStack.pop();
2423 // //| '"' encaps_list '"'
2424 // case TokenNameEncapsedString2:
2425 // scanner.encapsedStringStack.push(new Character('"'));
2428 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2429 // if (token == TokenNameEncapsedString2) {
2431 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2432 // exprSourceStart, scanner
2433 // .getCurrentTokenEndPosition());
2436 // if (token != TokenNameEncapsedString2) {
2437 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2438 // scanner.toStringAction(token) + " )");
2441 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2442 // exprSourceStart, scanner
2443 // .getCurrentTokenEndPosition());
2447 // scanner.encapsedStringStack.pop();
2451 case TokenNameStringDoubleQuote:
2452 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2453 .getCurrentTokenEndPosition());
2456 case TokenNameStringSingleQuote:
2457 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2458 .getCurrentTokenEndPosition());
2461 case TokenNameIntegerLiteral:
2462 case TokenNameDoubleLiteral:
2463 case TokenNameStringInterpolated:
2466 case TokenNameCLASS_C:
2467 case TokenNameMETHOD_C:
2468 case TokenNameFUNC_C:
2471 case TokenNameHEREDOC:
2474 case TokenNamearray:
2475 // T_ARRAY '(' array_pair_list ')'
2477 if (token == TokenNameLPAREN) {
2479 if (token == TokenNameRPAREN) {
2484 if (token != TokenNameRPAREN) {
2485 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2489 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2493 // | T_LIST '(' assignment_list ')' '=' expr
2495 if (token == TokenNameLPAREN) {
2498 if (token != TokenNameRPAREN) {
2499 throwSyntaxError("')' expected after 'list' keyword.");
2502 if (token != TokenNameEQUAL) {
2503 throwSyntaxError("'=' expected after 'list' keyword.");
2508 throwSyntaxError("'(' expected after 'list' keyword.");
2512 // | T_NEW class_name_reference ctor_arguments
2514 Expression typeRef = class_name_reference();
2516 if (typeRef != null) {
2517 expression = typeRef;
2520 // | T_INC rw_variable
2521 // | T_DEC rw_variable
2522 case TokenNamePLUS_PLUS:
2523 case TokenNameMINUS_MINUS:
2527 // | variable '=' expr
2528 // | variable '=' '&' variable
2529 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2530 // | variable T_PLUS_EQUAL expr
2531 // | variable T_MINUS_EQUAL expr
2532 // | variable T_MUL_EQUAL expr
2533 // | variable T_DIV_EQUAL expr
2534 // | variable T_CONCAT_EQUAL expr
2535 // | variable T_MOD_EQUAL expr
2536 // | variable T_AND_EQUAL expr
2537 // | variable T_OR_EQUAL expr
2538 // | variable T_XOR_EQUAL expr
2539 // | variable T_SL_EQUAL expr
2540 // | variable T_SR_EQUAL expr
2541 // | rw_variable T_INC
2542 // | rw_variable T_DEC
2543 case TokenNameIdentifier:
2544 case TokenNameVariable:
2545 case TokenNameDOLLAR:
2546 Expression lhs = null;
2547 boolean rememberedVar = false;
2548 if (token == TokenNameIdentifier) {
2549 lhs = identifier(true, true);
2554 lhs = variable(true, true);
2558 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2559 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2560 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2561 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2562 && token != TokenNameLEFT_SHIFT_EQUAL) {
2563 FieldReference ref = (FieldReference) lhs;
2564 if (!containsVariableSet(ref.token)) {
2565 if (null==initHandler || initHandler.reportError()) {
2566 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart, ref.sourceEnd,
2567 referenceContext, compilationUnit.compilationResult);
2569 addVariableSet(ref.token);
2574 case TokenNameEQUAL:
2575 if (lhs != null && lhs instanceof FieldReference) {
2576 addVariableSet(((FieldReference) lhs).token);
2579 if (token == TokenNameAND) {
2581 if (token == TokenNamenew) {
2582 // | variable '=' '&' T_NEW class_name_reference
2585 SingleTypeReference classRef = class_name_reference();
2587 if (classRef != null) {
2588 if (lhs != null && lhs instanceof FieldReference) {
2590 // $var = & new Object();
2591 if (fMethodVariables != null) {
2592 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2593 lhsInfo.reference = classRef;
2594 lhsInfo.typeIdentifier = classRef.token;
2595 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2596 rememberedVar = true;
2601 Expression rhs = variable(false, false);
2602 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2605 if (fMethodVariables != null) {
2606 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2607 if (rhsInfo != null && rhsInfo.reference != null) {
2608 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2609 lhsInfo.reference = rhsInfo.reference;
2610 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2611 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2612 rememberedVar = true;
2618 Expression rhs = expr();
2619 if (lhs != null && lhs instanceof FieldReference) {
2620 if (rhs != null && rhs instanceof FieldReference) {
2623 if (fMethodVariables != null) {
2624 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2625 if (rhsInfo != null && rhsInfo.reference != null) {
2626 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2627 lhsInfo.reference = rhsInfo.reference;
2628 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2629 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2630 rememberedVar = true;
2633 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2635 // $var = new Object();
2636 if (fMethodVariables != null) {
2637 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2638 lhsInfo.reference = (SingleTypeReference) rhs;
2639 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2640 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2641 rememberedVar = true;
2646 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2647 if (fMethodVariables != null) {
2648 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2649 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2653 case TokenNamePLUS_EQUAL:
2654 case TokenNameMINUS_EQUAL:
2655 case TokenNameMULTIPLY_EQUAL:
2656 case TokenNameDIVIDE_EQUAL:
2657 case TokenNameDOT_EQUAL:
2658 case TokenNameREMAINDER_EQUAL:
2659 case TokenNameAND_EQUAL:
2660 case TokenNameOR_EQUAL:
2661 case TokenNameXOR_EQUAL:
2662 case TokenNameRIGHT_SHIFT_EQUAL:
2663 case TokenNameLEFT_SHIFT_EQUAL:
2664 if (lhs != null && lhs instanceof FieldReference) {
2665 addVariableSet(((FieldReference) lhs).token);
2670 case TokenNamePLUS_PLUS:
2671 case TokenNameMINUS_MINUS:
2675 if (!only_variable) {
2676 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2684 if (token != TokenNameINLINE_HTML) {
2685 if (token > TokenNameKEYWORD) {
2689 // System.out.println(scanner.getCurrentTokenStartPosition());
2690 // System.out.println(scanner.getCurrentTokenEndPosition());
2692 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2697 if (Scanner.TRACE) {
2698 System.out.println("TRACE: expr_without_variable() PART 2");
2700 // | expr T_BOOLEAN_OR expr
2701 // | expr T_BOOLEAN_AND expr
2702 // | expr T_LOGICAL_OR expr
2703 // | expr T_LOGICAL_AND expr
2704 // | expr T_LOGICAL_XOR expr
2716 // | expr T_IS_IDENTICAL expr
2717 // | expr T_IS_NOT_IDENTICAL expr
2718 // | expr T_IS_EQUAL expr
2719 // | expr T_IS_NOT_EQUAL expr
2721 // | expr T_IS_SMALLER_OR_EQUAL expr
2723 // | expr T_IS_GREATER_OR_EQUAL expr
2726 case TokenNameOR_OR:
2728 expression = new OR_OR_Expression(expression, expr(), token);
2730 case TokenNameAND_AND:
2732 expression = new AND_AND_Expression(expression, expr(), token);
2734 case TokenNameEQUAL_EQUAL:
2736 expression = new EqualExpression(expression, expr(), token);
2746 case TokenNameMINUS:
2747 case TokenNameMULTIPLY:
2748 case TokenNameDIVIDE:
2749 case TokenNameREMAINDER:
2750 case TokenNameLEFT_SHIFT:
2751 case TokenNameRIGHT_SHIFT:
2752 case TokenNameEQUAL_EQUAL_EQUAL:
2753 case TokenNameNOT_EQUAL_EQUAL:
2754 case TokenNameNOT_EQUAL:
2756 case TokenNameLESS_EQUAL:
2757 case TokenNameGREATER:
2758 case TokenNameGREATER_EQUAL:
2760 expression = new BinaryExpression(expression, expr(), token);
2762 // | expr T_INSTANCEOF class_name_reference
2763 // | expr '?' expr ':' expr
2764 case TokenNameinstanceof:
2766 TypeReference classRef = class_name_reference();
2767 if (classRef != null) {
2768 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2769 expression.sourceStart = exprSourceStart;
2770 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2773 case TokenNameQUESTION:
2775 Expression valueIfTrue = expr();
2776 if (token != TokenNameCOLON) {
2777 throwSyntaxError("':' expected in conditional expression.");
2780 Expression valueIfFalse = expr();
2782 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2788 } catch (SyntaxError e) {
2789 // try to find next token after expression with errors:
2790 if (token == TokenNameSEMICOLON) {
2794 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2802 private SingleTypeReference class_name_reference() {
2803 // class_name_reference:
2805 // | dynamic_class_name_reference
2806 SingleTypeReference ref = null;
2807 if (Scanner.TRACE) {
2808 System.out.println("TRACE: class_name_reference()");
2810 if (token == TokenNameIdentifier) {
2811 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2815 dynamic_class_name_reference();
2820 private void dynamic_class_name_reference() {
2821 // dynamic_class_name_reference:
2822 // base_variable T_OBJECT_OPERATOR object_property
2823 // dynamic_class_name_variable_properties
2825 if (Scanner.TRACE) {
2826 System.out.println("TRACE: dynamic_class_name_reference()");
2828 base_variable(true);
2829 if (token == TokenNameMINUS_GREATER) {
2832 dynamic_class_name_variable_properties();
2836 private void dynamic_class_name_variable_properties() {
2837 // dynamic_class_name_variable_properties:
2838 // dynamic_class_name_variable_properties
2839 // dynamic_class_name_variable_property
2841 if (Scanner.TRACE) {
2842 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2844 while (token == TokenNameMINUS_GREATER) {
2845 dynamic_class_name_variable_property();
2849 private void dynamic_class_name_variable_property() {
2850 // dynamic_class_name_variable_property:
2851 // T_OBJECT_OPERATOR object_property
2852 if (Scanner.TRACE) {
2853 System.out.println("TRACE: dynamic_class_name_variable_property()");
2855 if (token == TokenNameMINUS_GREATER) {
2861 private void ctor_arguments() {
2864 // | '(' function_call_parameter_list ')'
2865 if (token == TokenNameLPAREN) {
2867 if (token == TokenNameRPAREN) {
2871 non_empty_function_call_parameter_list();
2872 if (token != TokenNameRPAREN) {
2873 throwSyntaxError("')' expected in ctor_arguments.");
2879 private void assignment_list() {
2881 // assignment_list ',' assignment_list_element
2882 // | assignment_list_element
2884 assignment_list_element();
2885 if (token != TokenNameCOMMA) {
2892 private void assignment_list_element() {
2893 // assignment_list_element:
2895 // | T_LIST '(' assignment_list ')'
2897 if (token == TokenNameVariable) {
2898 variable(true, false);
2899 } else if (token == TokenNameDOLLAR) {
2900 variable(false, false);
2902 if (token == TokenNamelist) {
2904 if (token == TokenNameLPAREN) {
2907 if (token != TokenNameRPAREN) {
2908 throwSyntaxError("')' expected after 'list' keyword.");
2912 throwSyntaxError("'(' expected after 'list' keyword.");
2918 private void array_pair_list() {
2921 // | non_empty_array_pair_list possible_comma
2922 non_empty_array_pair_list();
2923 if (token == TokenNameCOMMA) {
2928 private void non_empty_array_pair_list() {
2929 // non_empty_array_pair_list:
2930 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2931 // | non_empty_array_pair_list ',' expr
2932 // | expr T_DOUBLE_ARROW expr
2934 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2935 // | non_empty_array_pair_list ',' '&' w_variable
2936 // | expr T_DOUBLE_ARROW '&' w_variable
2939 if (token == TokenNameAND) {
2941 variable(true, false);
2944 if (token == TokenNameAND) {
2946 variable(true, false);
2947 } else if (token == TokenNameEQUAL_GREATER) {
2949 if (token == TokenNameAND) {
2951 variable(true, false);
2957 if (token != TokenNameCOMMA) {
2961 if (token == TokenNameRPAREN) {
2967 // private void variableList() {
2970 // if (token == TokenNameCOMMA) {
2977 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2978 // variable_without_objects:
2979 // reference_variable
2980 // | simple_indirect_reference reference_variable
2981 if (Scanner.TRACE) {
2982 System.out.println("TRACE: variable_without_objects()");
2984 while (token == TokenNameDOLLAR) {
2987 return reference_variable(lefthandside, ignoreVar);
2990 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2992 // T_STRING '(' function_call_parameter_list ')'
2993 // | class_constant '(' function_call_parameter_list ')'
2994 // | static_member '(' function_call_parameter_list ')'
2995 // | variable_without_objects '(' function_call_parameter_list ')'
2996 char[] defineName = null;
2997 char[] ident = null;
3000 Expression ref = null;
3001 if (Scanner.TRACE) {
3002 System.out.println("TRACE: function_call()");
3004 if (token == TokenNameIdentifier) {
3005 ident = scanner.getCurrentIdentifierSource();
3007 startPos = scanner.getCurrentTokenStartPosition();
3008 endPos = scanner.getCurrentTokenEndPosition();
3011 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3015 if (token == TokenNameIdentifier) {
3020 variable_without_objects(true, false);
3025 ref = variable_without_objects(lefthandside, ignoreVar);
3027 if (token != TokenNameLPAREN) {
3028 if (defineName != null) {
3029 // does this identifier contain only uppercase characters?
3030 if (defineName.length == 3) {
3031 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3034 } else if (defineName.length == 4) {
3035 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3037 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3040 } else if (defineName.length == 5) {
3041 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3045 if (defineName != null) {
3046 for (int i = 0; i < defineName.length; i++) {
3047 if (Character.isLowerCase(defineName[i])) {
3048 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3056 if (token == TokenNameRPAREN) {
3060 non_empty_function_call_parameter_list();
3061 if (token != TokenNameRPAREN) {
3062 String functionName;
3063 if (ident == null) {
3064 functionName = new String(" ");
3066 functionName = new String(ident);
3068 throwSyntaxError("')' expected in function call (" + functionName + ").");
3075 private void non_empty_function_call_parameter_list() {
3076 this.non_empty_function_call_parameter_list(null);
3079 // private void function_call_parameter_list() {
3080 // function_call_parameter_list:
3081 // non_empty_function_call_parameter_list { $$ = $1; }
3084 private void non_empty_function_call_parameter_list(String functionName) {
3085 // non_empty_function_call_parameter_list:
3086 // expr_without_variable
3089 // | non_empty_function_call_parameter_list ',' expr_without_variable
3090 // | non_empty_function_call_parameter_list ',' variable
3091 // | non_empty_function_call_parameter_list ',' '&' w_variable
3092 if (Scanner.TRACE) {
3093 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3095 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3096 initHandler.setFunctionName(functionName);
3098 initHandler.incrementArgumentCount();
3099 if (token == TokenNameAND) {
3103 // if (token == TokenNameIdentifier || token ==
3104 // TokenNameVariable
3105 // || token == TokenNameDOLLAR) {
3108 expr_without_variable(true, initHandler);
3111 if (token != TokenNameCOMMA) {
3118 private void fully_qualified_class_name() {
3119 if (token == TokenNameIdentifier) {
3122 throwSyntaxError("Class name expected.");
3126 private void static_member() {
3128 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3129 // variable_without_objects
3130 if (Scanner.TRACE) {
3131 System.out.println("TRACE: static_member()");
3133 fully_qualified_class_name();
3134 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3135 throwSyntaxError("'::' expected after class name (static_member).");
3138 variable_without_objects(false, false);
3141 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3142 // base_variable_with_function_calls:
3145 if (Scanner.TRACE) {
3146 System.out.println("TRACE: base_variable_with_function_calls()");
3148 return function_call(lefthandside, ignoreVar);
3151 private Expression base_variable(boolean lefthandside) {
3153 // reference_variable
3154 // | simple_indirect_reference reference_variable
3156 Expression ref = null;
3157 if (Scanner.TRACE) {
3158 System.out.println("TRACE: base_variable()");
3160 if (token == TokenNameIdentifier) {
3163 while (token == TokenNameDOLLAR) {
3166 reference_variable(lefthandside, false);
3171 // private void simple_indirect_reference() {
3172 // // simple_indirect_reference:
3174 // //| simple_indirect_reference '$'
3176 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3177 // reference_variable:
3178 // reference_variable '[' dim_offset ']'
3179 // | reference_variable '{' expr '}'
3180 // | compound_variable
3181 Expression ref = null;
3182 if (Scanner.TRACE) {
3183 System.out.println("TRACE: reference_variable()");
3185 ref = compound_variable(lefthandside, ignoreVar);
3187 if (token == TokenNameLBRACE) {
3191 if (token != TokenNameRBRACE) {
3192 throwSyntaxError("'}' expected in reference variable.");
3195 } else if (token == TokenNameLBRACKET) {
3196 // To remove "ref = null;" here, is probably better than the patch
3197 // commented in #1368081 - axelcl
3199 if (token != TokenNameRBRACKET) {
3202 if (token != TokenNameRBRACKET) {
3203 throwSyntaxError("']' expected in reference variable.");
3214 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3215 // compound_variable:
3217 // | '$' '{' expr '}'
3218 if (Scanner.TRACE) {
3219 System.out.println("TRACE: compound_variable()");
3221 if (token == TokenNameVariable) {
3222 if (!lefthandside) {
3223 if (!containsVariableSet()) {
3224 // reportSyntaxError("The local variable " + new
3225 // String(scanner.getCurrentIdentifierSource())
3226 // + " may not have been initialized");
3227 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3228 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3229 compilationUnit.compilationResult);
3236 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3240 // because of simple_indirect_reference
3241 while (token == TokenNameDOLLAR) {
3244 if (token != TokenNameLBRACE) {
3245 reportSyntaxError("'{' expected after compound variable token '$'.");
3250 if (token != TokenNameRBRACE) {
3251 throwSyntaxError("'}' expected after compound variable token '$'.");
3256 } // private void dim_offset() { // // dim_offset: // // /* empty */
3261 private void object_property() {
3264 // | variable_without_objects
3265 if (Scanner.TRACE) {
3266 System.out.println("TRACE: object_property()");
3268 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3269 variable_without_objects(false, false);
3275 private void object_dim_list() {
3277 // object_dim_list '[' dim_offset ']'
3278 // | object_dim_list '{' expr '}'
3280 if (Scanner.TRACE) {
3281 System.out.println("TRACE: object_dim_list()");
3285 if (token == TokenNameLBRACE) {
3288 if (token != TokenNameRBRACE) {
3289 throwSyntaxError("'}' expected in object_dim_list.");
3292 } else if (token == TokenNameLBRACKET) {
3294 if (token == TokenNameRBRACKET) {
3299 if (token != TokenNameRBRACKET) {
3300 throwSyntaxError("']' expected in object_dim_list.");
3309 private void variable_name() {
3313 if (Scanner.TRACE) {
3314 System.out.println("TRACE: variable_name()");
3316 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3317 if (token > TokenNameKEYWORD) {
3318 // TODO show a warning "Keyword used as variable" ?
3322 if (token != TokenNameLBRACE) {
3323 throwSyntaxError("'{' expected in variable name.");
3327 if (token != TokenNameRBRACE) {
3328 throwSyntaxError("'}' expected in variable name.");
3334 private void r_variable() {
3335 variable(false, false);
3338 private void w_variable(boolean lefthandside) {
3339 variable(lefthandside, false);
3342 private void rw_variable() {
3343 variable(false, false);
3346 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3348 // base_variable_with_function_calls T_OBJECT_OPERATOR
3349 // object_property method_or_not variable_properties
3350 // | base_variable_with_function_calls
3351 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3352 if (token == TokenNameMINUS_GREATER) {
3357 variable_properties();
3362 private void variable_properties() {
3363 // variable_properties:
3364 // variable_properties variable_property
3366 while (token == TokenNameMINUS_GREATER) {
3367 variable_property();
3371 private void variable_property() {
3372 // variable_property:
3373 // T_OBJECT_OPERATOR object_property method_or_not
3374 if (Scanner.TRACE) {
3375 System.out.println("TRACE: variable_property()");
3377 if (token == TokenNameMINUS_GREATER) {
3382 throwSyntaxError("'->' expected in variable_property.");
3386 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3388 // base_variable_with_function_calls T_OBJECT_OPERATOR
3389 // object_property method_or_not variable_properties
3390 // | base_variable_with_function_calls
3392 // Expression ref = function_call(lefthandside, ignoreVar);
3395 // T_STRING '(' function_call_parameter_list ')'
3396 // | class_constant '(' function_call_parameter_list ')'
3397 // | static_member '(' function_call_parameter_list ')'
3398 // | variable_without_objects '(' function_call_parameter_list ')'
3399 char[] defineName = null;
3400 char[] ident = null;
3403 Expression ref = null;
3404 if (Scanner.TRACE) {
3405 System.out.println("TRACE: function_call()");
3407 if (token == TokenNameIdentifier) {
3408 ident = scanner.getCurrentIdentifierSource();
3410 startPos = scanner.getCurrentTokenStartPosition();
3411 endPos = scanner.getCurrentTokenEndPosition();
3414 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3415 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3416 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3417 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3418 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3419 + new String(ident) + "' (use 'define(...)' to define constants).";
3420 reportSyntaxError(error);
3424 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3428 if (token == TokenNameIdentifier) {
3433 variable_without_objects(true, false);
3438 ref = variable_without_objects(lefthandside, ignoreVar);
3440 if (token != TokenNameLPAREN) {
3441 if (defineName != null) {
3442 // does this identifier contain only uppercase characters?
3443 if (defineName.length == 3) {
3444 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3447 } else if (defineName.length == 4) {
3448 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3450 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3453 } else if (defineName.length == 5) {
3454 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3458 if (defineName != null) {
3459 for (int i = 0; i < defineName.length; i++) {
3460 if (Character.isLowerCase(defineName[i])) {
3461 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3467 // TODO is this ok ?
3469 // throwSyntaxError("'(' expected in function call.");
3473 if (token == TokenNameRPAREN) {
3477 String functionName;
3478 if (ident == null) {
3479 functionName = new String(" ");
3481 functionName = new String(ident);
3483 non_empty_function_call_parameter_list(functionName);
3484 if (token != TokenNameRPAREN) {
3485 throwSyntaxError("')' expected in function call (" + functionName + ").");
3490 if (token == TokenNameMINUS_GREATER) {
3495 variable_properties();
3500 private void method_or_not() {
3502 // '(' function_call_parameter_list ')'
3504 if (Scanner.TRACE) {
3505 System.out.println("TRACE: method_or_not()");
3507 if (token == TokenNameLPAREN) {
3509 if (token == TokenNameRPAREN) {
3513 non_empty_function_call_parameter_list();
3514 if (token != TokenNameRPAREN) {
3515 throwSyntaxError("')' expected in method_or_not.");
3521 private void exit_expr() {
3525 if (token != TokenNameLPAREN) {
3529 if (token == TokenNameRPAREN) {
3534 if (token != TokenNameRPAREN) {
3535 throwSyntaxError("')' expected after keyword 'exit'");
3540 // private void encaps_list() {
3541 // // encaps_list encaps_var
3542 // // | encaps_list T_STRING
3543 // // | encaps_list T_NUM_STRING
3544 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3545 // // | encaps_list T_CHARACTER
3546 // // | encaps_list T_BAD_CHARACTER
3547 // // | encaps_list '['
3548 // // | encaps_list ']'
3549 // // | encaps_list '{'
3550 // // | encaps_list '}'
3551 // // | encaps_list T_OBJECT_OPERATOR
3555 // case TokenNameSTRING:
3558 // case TokenNameLBRACE:
3559 // // scanner.encapsedStringStack.pop();
3562 // case TokenNameRBRACE:
3563 // // scanner.encapsedStringStack.pop();
3566 // case TokenNameLBRACKET:
3567 // // scanner.encapsedStringStack.pop();
3570 // case TokenNameRBRACKET:
3571 // // scanner.encapsedStringStack.pop();
3574 // case TokenNameMINUS_GREATER:
3575 // // scanner.encapsedStringStack.pop();
3578 // case TokenNameVariable:
3579 // case TokenNameDOLLAR_LBRACE:
3580 // case TokenNameLBRACE_DOLLAR:
3584 // char encapsedChar = ((Character)
3585 // scanner.encapsedStringStack.peek()).charValue();
3586 // if (encapsedChar == '$') {
3587 // scanner.encapsedStringStack.pop();
3588 // encapsedChar = ((Character)
3589 // scanner.encapsedStringStack.peek()).charValue();
3590 // switch (encapsedChar) {
3592 // if (token == TokenNameEncapsedString0) {
3595 // token = TokenNameSTRING;
3598 // if (token == TokenNameEncapsedString1) {
3601 // token = TokenNameSTRING;
3604 // if (token == TokenNameEncapsedString2) {
3607 // token = TokenNameSTRING;
3616 // private void encaps_var() {
3618 // // | T_VARIABLE '[' encaps_var_offset ']'
3619 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3620 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3621 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3622 // // | T_CURLY_OPEN variable '}'
3624 // case TokenNameVariable:
3626 // if (token == TokenNameLBRACKET) {
3628 // expr(); //encaps_var_offset();
3629 // if (token != TokenNameRBRACKET) {
3630 // throwSyntaxError("']' expected after variable.");
3632 // // scanner.encapsedStringStack.pop();
3635 // } else if (token == TokenNameMINUS_GREATER) {
3637 // if (token != TokenNameIdentifier) {
3638 // throwSyntaxError("Identifier expected after '->'.");
3640 // // scanner.encapsedStringStack.pop();
3644 // // // scanner.encapsedStringStack.pop();
3645 // // int tempToken = TokenNameSTRING;
3646 // // if (!scanner.encapsedStringStack.isEmpty()
3647 // // && (token == TokenNameEncapsedString0
3648 // // || token == TokenNameEncapsedString1
3649 // // || token == TokenNameEncapsedString2 || token ==
3650 // // TokenNameERROR)) {
3651 // // char encapsedChar = ((Character)
3652 // // scanner.encapsedStringStack.peek())
3654 // // switch (token) {
3655 // // case TokenNameEncapsedString0 :
3656 // // if (encapsedChar == '`') {
3657 // // tempToken = TokenNameEncapsedString0;
3660 // // case TokenNameEncapsedString1 :
3661 // // if (encapsedChar == '\'') {
3662 // // tempToken = TokenNameEncapsedString1;
3665 // // case TokenNameEncapsedString2 :
3666 // // if (encapsedChar == '"') {
3667 // // tempToken = TokenNameEncapsedString2;
3670 // // case TokenNameERROR :
3671 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3672 // // scanner.currentPosition--;
3673 // // getNextToken();
3678 // // token = tempToken;
3681 // case TokenNameDOLLAR_LBRACE:
3683 // if (token == TokenNameDOLLAR_LBRACE) {
3685 // } else if (token == TokenNameIdentifier) {
3687 // if (token == TokenNameLBRACKET) {
3689 // // if (token == TokenNameRBRACKET) {
3690 // // getNextToken();
3693 // if (token != TokenNameRBRACKET) {
3694 // throwSyntaxError("']' expected after '${'.");
3702 // if (token != TokenNameRBRACE) {
3703 // throwSyntaxError("'}' expected.");
3707 // case TokenNameLBRACE_DOLLAR:
3709 // if (token == TokenNameLBRACE_DOLLAR) {
3711 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3713 // if (token == TokenNameLBRACKET) {
3715 // // if (token == TokenNameRBRACKET) {
3716 // // getNextToken();
3719 // if (token != TokenNameRBRACKET) {
3720 // throwSyntaxError("']' expected.");
3724 // } else if (token == TokenNameMINUS_GREATER) {
3726 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3727 // throwSyntaxError("String or Variable token expected.");
3730 // if (token == TokenNameLBRACKET) {
3732 // // if (token == TokenNameRBRACKET) {
3733 // // getNextToken();
3736 // if (token != TokenNameRBRACKET) {
3737 // throwSyntaxError("']' expected after '${'.");
3743 // // if (token != TokenNameRBRACE) {
3744 // // throwSyntaxError("'}' expected after '{$'.");
3746 // // // scanner.encapsedStringStack.pop();
3747 // // getNextToken();
3750 // if (token != TokenNameRBRACE) {
3751 // throwSyntaxError("'}' expected.");
3753 // // scanner.encapsedStringStack.pop();
3760 // private void encaps_var_offset() {
3762 // // | T_NUM_STRING
3765 // case TokenNameSTRING:
3768 // case TokenNameIntegerLiteral:
3771 // case TokenNameVariable:
3774 // case TokenNameIdentifier:
3778 // throwSyntaxError("Variable or String token expected.");
3783 private void internal_functions_in_yacc() {
3786 // case TokenNameisset:
3787 // // T_ISSET '(' isset_variables ')'
3789 // if (token != TokenNameLPAREN) {
3790 // throwSyntaxError("'(' expected after keyword 'isset'");
3793 // isset_variables();
3794 // if (token != TokenNameRPAREN) {
3795 // throwSyntaxError("')' expected after keyword 'isset'");
3799 // case TokenNameempty:
3800 // // T_EMPTY '(' variable ')'
3802 // if (token != TokenNameLPAREN) {
3803 // throwSyntaxError("'(' expected after keyword 'empty'");
3807 // if (token != TokenNameRPAREN) {
3808 // throwSyntaxError("')' expected after keyword 'empty'");
3812 case TokenNameinclude:
3814 checkFileName(token);
3816 case TokenNameinclude_once:
3817 // T_INCLUDE_ONCE expr
3818 checkFileName(token);
3821 // T_EVAL '(' expr ')'
3823 if (token != TokenNameLPAREN) {
3824 throwSyntaxError("'(' expected after keyword 'eval'");
3828 if (token != TokenNameRPAREN) {
3829 throwSyntaxError("')' expected after keyword 'eval'");
3833 case TokenNamerequire:
3835 checkFileName(token);
3837 case TokenNamerequire_once:
3838 // T_REQUIRE_ONCE expr
3839 checkFileName(token);
3845 * Parse and check the include file name
3847 * @param includeToken
3849 private void checkFileName(int includeToken) {
3850 // <include-token> expr
3851 int start = scanner.getCurrentTokenStartPosition();
3852 boolean hasLPAREN = false;
3854 if (token == TokenNameLPAREN) {
3858 Expression expression = expr();
3860 if (token == TokenNameRPAREN) {
3863 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3866 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3868 if (scanner.compilationUnit != null) {
3869 IResource resource = scanner.compilationUnit.getResource();
3870 if (resource != null && resource instanceof IFile) {
3871 file = (IFile) resource;
3875 tokens = new char[1][];
3876 tokens[0] = currTokenSource;
3878 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3879 impt.declarationSourceEnd = impt.sourceEnd;
3880 impt.declarationEnd = impt.declarationSourceEnd;
3881 // endPosition is just before the ;
3882 impt.declarationSourceStart = start;
3883 includesList.add(impt);
3885 if (expression instanceof StringLiteral) {
3886 StringLiteral literal = (StringLiteral) expression;
3887 char[] includeName = literal.source();
3888 if (includeName.length == 0) {
3889 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3890 literal.sourceStart + 1);
3892 String includeNameString = new String(includeName);
3893 if (literal instanceof StringLiteralDQ) {
3894 if (includeNameString.indexOf('$') >= 0) {
3895 // assuming that the filename contains a variable => no filename check
3899 if (includeNameString.startsWith("http://")) {
3900 // assuming external include location
3904 // check the filename:
3905 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3906 // expression.toStringExpression());
3907 IProject project = file.getProject();
3908 if (project != null) {
3909 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3912 // SyntaxError: "File: << >> doesn't exist in project."
3913 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3914 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3915 compilationUnit.compilationResult);
3918 String filePath = path.toString();
3919 String ext = file.getRawLocation().getFileExtension();
3920 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3922 IFile f = PHPFileUtil.createFile(path, project);
3924 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3926 } catch (Exception e) {
3927 // the file is outside of the workspace
3935 private void isset_variables() {
3937 // | isset_variables ','
3938 if (token == TokenNameRPAREN) {
3939 throwSyntaxError("Variable expected after keyword 'isset'");
3942 variable(true, false);
3943 if (token == TokenNameCOMMA) {
3951 private boolean common_scalar() {
3955 // | T_CONSTANT_ENCAPSED_STRING
3962 case TokenNameIntegerLiteral:
3965 case TokenNameDoubleLiteral:
3968 case TokenNameStringDoubleQuote:
3971 case TokenNameStringSingleQuote:
3974 case TokenNameStringInterpolated:
3983 case TokenNameCLASS_C:
3986 case TokenNameMETHOD_C:
3989 case TokenNameFUNC_C:
3996 private void scalar() {
3999 // | T_STRING_VARNAME
4002 // | '"' encaps_list '"'
4003 // | '\'' encaps_list '\''
4004 // | T_START_HEREDOC encaps_list T_END_HEREDOC
4005 throwSyntaxError("Not yet implemented (scalar).");
4008 private void static_scalar() {
4009 // static_scalar: /* compile-time evaluated scalars */
4012 // | '+' static_scalar
4013 // | '-' static_scalar
4014 // | T_ARRAY '(' static_array_pair_list ')'
4015 // | static_class_constant
4016 if (common_scalar()) {
4020 case TokenNameIdentifier:
4022 // static_class_constant:
4023 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4024 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
4026 if (token == TokenNameIdentifier) {
4029 throwSyntaxError("Identifier expected after '::' operator.");
4033 case TokenNameEncapsedString0:
4035 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4036 while (scanner.currentCharacter != '`') {
4037 if (scanner.currentCharacter == '\\') {
4038 scanner.currentPosition++;
4040 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4043 } catch (IndexOutOfBoundsException e) {
4044 throwSyntaxError("'`' expected at end of static string.");
4047 // case TokenNameEncapsedString1:
4049 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4050 // while (scanner.currentCharacter != '\'') {
4051 // if (scanner.currentCharacter == '\\') {
4052 // scanner.currentPosition++;
4054 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4057 // } catch (IndexOutOfBoundsException e) {
4058 // throwSyntaxError("'\'' expected at end of static string.");
4061 // case TokenNameEncapsedString2:
4063 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4064 // while (scanner.currentCharacter != '"') {
4065 // if (scanner.currentCharacter == '\\') {
4066 // scanner.currentPosition++;
4068 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4071 // } catch (IndexOutOfBoundsException e) {
4072 // throwSyntaxError("'\"' expected at end of static string.");
4075 case TokenNameStringSingleQuote:
4078 case TokenNameStringDoubleQuote:
4085 case TokenNameMINUS:
4089 case TokenNamearray:
4091 if (token != TokenNameLPAREN) {
4092 throwSyntaxError("'(' expected after keyword 'array'");
4095 if (token == TokenNameRPAREN) {
4099 non_empty_static_array_pair_list();
4100 if (token != TokenNameRPAREN) {
4101 throwSyntaxError("')' or ',' expected after keyword 'array'");
4105 // case TokenNamenull :
4108 // case TokenNamefalse :
4111 // case TokenNametrue :
4115 throwSyntaxError("Static scalar/constant expected.");
4119 private void non_empty_static_array_pair_list() {
4120 // non_empty_static_array_pair_list:
4121 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4123 // | non_empty_static_array_pair_list ',' static_scalar
4124 // | static_scalar T_DOUBLE_ARROW static_scalar
4128 if (token == TokenNameEQUAL_GREATER) {
4132 if (token != TokenNameCOMMA) {
4136 if (token == TokenNameRPAREN) {
4142 // public void reportSyntaxError() { //int act, int currentKind, int
4143 // // stateStackTop) {
4144 // /* remember current scanner position */
4145 // int startPos = scanner.startPosition;
4146 // int currentPos = scanner.currentPosition;
4148 // this.checkAndReportBracketAnomalies(problemReporter());
4149 // /* reset scanner where it was */
4150 // scanner.startPosition = startPos;
4151 // scanner.currentPosition = currentPos;
4154 public static final int RoundBracket = 0;
4156 public static final int SquareBracket = 1;
4158 public static final int CurlyBracket = 2;
4160 public static final int BracketKinds = 3;
4162 protected int[] nestedMethod; // the ptr is nestedType
4164 protected int nestedType, dimensions;
4166 // variable set stack
4167 final static int VariableStackIncrement = 10;
4169 HashMap fTypeVariables = null;
4171 HashMap fMethodVariables = null;
4173 ArrayList fStackUnassigned = new ArrayList();
4176 final static int AstStackIncrement = 100;
4178 protected int astPtr;
4180 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4182 protected int astLengthPtr;
4184 protected int[] astLengthStack;
4186 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4188 public CompilationUnitDeclaration compilationUnit; /*
4189 * the result from parse()
4192 protected ReferenceContext referenceContext;
4194 protected ProblemReporter problemReporter;
4196 protected CompilerOptions options;
4198 private ArrayList includesList;
4200 // protected CompilationResult compilationResult;
4202 * Returns this parser's problem reporter initialized with its reference
4203 * context. Also it is assumed that a problem is going to be reported, so
4204 * initializes the compilation result's line positions.
4206 public ProblemReporter problemReporter() {
4207 if (scanner.recordLineSeparator) {
4208 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4210 problemReporter.referenceContext = referenceContext;
4211 return problemReporter;
4215 * Reconsider the entire source looking for inconsistencies in {} () []
4217 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4218 // problemReporter) {
4219 // scanner.wasAcr = false;
4220 // boolean anomaliesDetected = false;
4222 // char[] source = scanner.source;
4223 // int[] leftCount = { 0, 0, 0 };
4224 // int[] rightCount = { 0, 0, 0 };
4225 // int[] depths = { 0, 0, 0 };
4226 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4228 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4229 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4231 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4233 // scanner.currentPosition = scanner.initialPosition; //starting
4235 // // (first-zero-based
4237 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4242 // // ---------Consume white space and handles
4243 // // startPosition---------
4244 // boolean isWhiteSpace;
4246 // scanner.startPosition = scanner.currentPosition;
4247 // // if (((scanner.currentCharacter =
4248 // // source[scanner.currentPosition++]) == '\\') &&
4249 // // (source[scanner.currentPosition] == 'u')) {
4250 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4252 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4253 // (scanner.currentCharacter == '\n'))) {
4254 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4255 // // only record line positions we have not
4257 // scanner.pushLineSeparator();
4260 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4262 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4263 // // -------consume token until } is found---------
4264 // switch (scanner.currentCharacter) {
4266 // int index = leftCount[CurlyBracket]++;
4267 // if (index == leftPositions[CurlyBracket].length) {
4268 // System.arraycopy(leftPositions[CurlyBracket], 0,
4269 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4270 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4271 // new int[index * 2]), 0, index);
4273 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4274 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4278 // int index = rightCount[CurlyBracket]++;
4279 // if (index == rightPositions[CurlyBracket].length) {
4280 // System.arraycopy(rightPositions[CurlyBracket], 0,
4281 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4282 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4283 // new int[index * 2]), 0, index);
4285 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4286 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4290 // int index = leftCount[RoundBracket]++;
4291 // if (index == leftPositions[RoundBracket].length) {
4292 // System.arraycopy(leftPositions[RoundBracket], 0,
4293 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4294 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4295 // new int[index * 2]), 0, index);
4297 // leftPositions[RoundBracket][index] = scanner.startPosition;
4298 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4302 // int index = rightCount[RoundBracket]++;
4303 // if (index == rightPositions[RoundBracket].length) {
4304 // System.arraycopy(rightPositions[RoundBracket], 0,
4305 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4306 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4307 // new int[index * 2]), 0, index);
4309 // rightPositions[RoundBracket][index] = scanner.startPosition;
4310 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4314 // int index = leftCount[SquareBracket]++;
4315 // if (index == leftPositions[SquareBracket].length) {
4316 // System.arraycopy(leftPositions[SquareBracket], 0,
4317 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4318 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4319 // new int[index * 2]), 0, index);
4321 // leftPositions[SquareBracket][index] = scanner.startPosition;
4322 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4326 // int index = rightCount[SquareBracket]++;
4327 // if (index == rightPositions[SquareBracket].length) {
4328 // System.arraycopy(rightPositions[SquareBracket], 0,
4329 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4330 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4331 // = new int[index * 2]), 0, index);
4333 // rightPositions[SquareBracket][index] = scanner.startPosition;
4334 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4338 // if (scanner.getNextChar('\\')) {
4339 // scanner.scanEscapeCharacter();
4340 // } else { // consume next character
4341 // scanner.unicodeAsBackSlash = false;
4342 // // if (((scanner.currentCharacter =
4343 // // source[scanner.currentPosition++]) ==
4345 // // (source[scanner.currentPosition] ==
4347 // // scanner.getNextUnicodeChar();
4349 // if (scanner.withoutUnicodePtr != 0) {
4350 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4351 // scanner.currentCharacter;
4355 // scanner.getNextChar('\'');
4359 // // consume next character
4360 // scanner.unicodeAsBackSlash = false;
4361 // // if (((scanner.currentCharacter =
4362 // // source[scanner.currentPosition++]) == '\\') &&
4363 // // (source[scanner.currentPosition] == 'u')) {
4364 // // scanner.getNextUnicodeChar();
4366 // if (scanner.withoutUnicodePtr != 0) {
4367 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4368 // scanner.currentCharacter;
4371 // while (scanner.currentCharacter != '"') {
4372 // if (scanner.currentCharacter == '\r') {
4373 // if (source[scanner.currentPosition] == '\n')
4374 // scanner.currentPosition++;
4375 // break; // the string cannot go further that
4378 // if (scanner.currentCharacter == '\n') {
4379 // break; // the string cannot go further that
4382 // if (scanner.currentCharacter == '\\') {
4383 // scanner.scanEscapeCharacter();
4385 // // consume next character
4386 // scanner.unicodeAsBackSlash = false;
4387 // // if (((scanner.currentCharacter =
4388 // // source[scanner.currentPosition++]) == '\\')
4389 // // && (source[scanner.currentPosition] == 'u'))
4391 // // scanner.getNextUnicodeChar();
4393 // if (scanner.withoutUnicodePtr != 0) {
4394 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4395 // scanner.currentCharacter;
4402 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4404 // //get the next char
4405 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4407 // && (source[scanner.currentPosition] == 'u')) {
4408 // //-------------unicode traitement
4410 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4411 // scanner.currentPosition++;
4412 // while (source[scanner.currentPosition] == 'u') {
4413 // scanner.currentPosition++;
4415 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4417 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4419 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4421 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4422 // || c4 < 0) { //error
4426 // scanner.currentCharacter = 'A';
4427 // } //something different from \n and \r
4429 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4432 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4434 // //get the next char
4435 // scanner.startPosition = scanner.currentPosition;
4436 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4438 // && (source[scanner.currentPosition] == 'u')) {
4439 // //-------------unicode traitement
4441 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4442 // scanner.currentPosition++;
4443 // while (source[scanner.currentPosition] == 'u') {
4444 // scanner.currentPosition++;
4446 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4448 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4450 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4452 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4453 // || c4 < 0) { //error
4457 // scanner.currentCharacter = 'A';
4458 // } //something different from \n
4461 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4465 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4466 // (scanner.currentCharacter == '\n'))) {
4467 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4468 // // only record line positions we
4469 // // have not recorded yet
4470 // scanner.pushLineSeparator();
4471 // if (this.scanner.taskTags != null) {
4472 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4474 // .getCurrentTokenEndPosition());
4480 // if (test > 0) { //traditional and annotation
4482 // boolean star = false;
4483 // // consume next character
4484 // scanner.unicodeAsBackSlash = false;
4485 // // if (((scanner.currentCharacter =
4486 // // source[scanner.currentPosition++]) ==
4488 // // (source[scanner.currentPosition] ==
4490 // // scanner.getNextUnicodeChar();
4492 // if (scanner.withoutUnicodePtr != 0) {
4493 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4494 // scanner.currentCharacter;
4497 // if (scanner.currentCharacter == '*') {
4500 // //get the next char
4501 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4503 // && (source[scanner.currentPosition] == 'u')) {
4504 // //-------------unicode traitement
4506 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4507 // scanner.currentPosition++;
4508 // while (source[scanner.currentPosition] == 'u') {
4509 // scanner.currentPosition++;
4511 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4513 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4515 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4517 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4518 // || c4 < 0) { //error
4522 // scanner.currentCharacter = 'A';
4523 // } //something different from * and /
4525 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4528 // //loop until end of comment */
4529 // while ((scanner.currentCharacter != '/') || (!star)) {
4530 // star = scanner.currentCharacter == '*';
4532 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4534 // && (source[scanner.currentPosition] == 'u')) {
4535 // //-------------unicode traitement
4537 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4538 // scanner.currentPosition++;
4539 // while (source[scanner.currentPosition] == 'u') {
4540 // scanner.currentPosition++;
4542 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4544 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4546 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4548 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4549 // || c4 < 0) { //error
4553 // scanner.currentCharacter = 'A';
4554 // } //something different from * and
4557 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4561 // if (this.scanner.taskTags != null) {
4562 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4563 // this.scanner.getCurrentTokenEndPosition());
4570 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4571 // scanner.scanIdentifierOrKeyword(false);
4574 // if (Character.isDigit(scanner.currentCharacter)) {
4575 // scanner.scanNumber(false);
4579 // //-----------------end switch while
4580 // // try--------------------
4581 // } catch (IndexOutOfBoundsException e) {
4582 // break; // read until EOF
4583 // } catch (InvalidInputException e) {
4584 // return false; // no clue
4587 // if (scanner.recordLineSeparator) {
4588 // compilationUnit.compilationResult.lineSeparatorPositions =
4589 // scanner.getLineEnds();
4591 // // check placement anomalies against other kinds of brackets
4592 // for (int kind = 0; kind < BracketKinds; kind++) {
4593 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4594 // int start = leftPositions[kind][leftIndex]; // deepest
4596 // // find matching closing bracket
4597 // int depth = leftDepths[kind][leftIndex];
4599 // for (int i = 0; i < rightCount[kind]; i++) {
4600 // int pos = rightPositions[kind][i];
4601 // // want matching bracket further in source with same
4603 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4608 // if (end < 0) { // did not find a good closing match
4609 // problemReporter.unmatchedBracket(start, referenceContext,
4610 // compilationUnit.compilationResult);
4613 // // check if even number of opening/closing other brackets
4614 // // in between this pair of brackets
4616 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4618 // for (int i = 0; i < leftCount[otherKind]; i++) {
4619 // int pos = leftPositions[otherKind][i];
4620 // if ((pos > start) && (pos < end))
4623 // for (int i = 0; i < rightCount[otherKind]; i++) {
4624 // int pos = rightPositions[otherKind][i];
4625 // if ((pos > start) && (pos < end))
4628 // if (balance != 0) {
4629 // problemReporter.unmatchedBracket(start, referenceContext,
4630 // compilationUnit.compilationResult); //bracket
4636 // // too many opening brackets ?
4637 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4638 // anomaliesDetected = true;
4639 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4640 // 1], referenceContext,
4641 // compilationUnit.compilationResult);
4643 // // too many closing brackets ?
4644 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4645 // anomaliesDetected = true;
4646 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4647 // compilationUnit.compilationResult);
4649 // if (anomaliesDetected)
4652 // return anomaliesDetected;
4653 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4654 // return anomaliesDetected;
4655 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4656 // return anomaliesDetected;
4659 protected void pushOnAstLengthStack(int pos) {
4661 astLengthStack[++astLengthPtr] = pos;
4662 } catch (IndexOutOfBoundsException e) {
4663 int oldStackLength = astLengthStack.length;
4664 int[] oldPos = astLengthStack;
4665 astLengthStack = new int[oldStackLength + StackIncrement];
4666 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4667 astLengthStack[astLengthPtr] = pos;
4671 protected void pushOnAstStack(ASTNode node) {
4673 * add a new obj on top of the ast stack
4676 astStack[++astPtr] = node;
4677 } catch (IndexOutOfBoundsException e) {
4678 int oldStackLength = astStack.length;
4679 ASTNode[] oldStack = astStack;
4680 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4681 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4682 astPtr = oldStackLength;
4683 astStack[astPtr] = node;
4686 astLengthStack[++astLengthPtr] = 1;
4687 } catch (IndexOutOfBoundsException e) {
4688 int oldStackLength = astLengthStack.length;
4689 int[] oldPos = astLengthStack;
4690 astLengthStack = new int[oldStackLength + AstStackIncrement];
4691 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4692 astLengthStack[astLengthPtr] = 1;
4696 protected void resetModifiers() {
4697 this.modifiers = AccDefault;
4698 this.modifiersSourceStart = -1; // <-- see comment into
4699 // modifiersFlag(int)
4700 this.scanner.commentPtr = -1;
4703 protected void consumePackageDeclarationName(IFile file) {
4704 // create a package name similar to java package names
4705 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4706 String filePath = file.getRawLocation().toString();
4707 String ext = file.getRawLocation().getFileExtension();
4708 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4709 ImportReference impt;
4711 if (filePath.startsWith(projectPath)) {
4712 tokens = CharOperation
4713 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4715 String name = file.getName();
4716 tokens = new char[1][];
4717 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4720 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4722 impt.declarationSourceStart = 0;
4723 impt.declarationSourceEnd = 0;
4724 impt.declarationEnd = 0;
4725 // endPosition is just before the ;
4729 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4730 "$_SESSION", "$_SERVER" };
4735 private void pushFunctionVariableSet() {
4736 HashSet set = new HashSet();
4737 if (fStackUnassigned.isEmpty()) {
4738 for (int i = 0; i < GLOBALS.length; i++) {
4739 set.add(GLOBALS[i]);
4742 fStackUnassigned.add(set);
4745 private void pushIfVariableSet() {
4746 if (!fStackUnassigned.isEmpty()) {
4747 HashSet set = new HashSet();
4748 fStackUnassigned.add(set);
4752 private HashSet removeIfVariableSet() {
4753 if (!fStackUnassigned.isEmpty()) {
4754 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4760 * Returns the <i>set of assigned variables </i> returns null if no Set is
4761 * defined at the current scanner position
4763 private HashSet peekVariableSet() {
4764 if (!fStackUnassigned.isEmpty()) {
4765 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4771 * add the current identifier source to the <i>set of assigned variables </i>
4775 private void addVariableSet(HashSet set) {
4777 set.add(new String(scanner.getCurrentTokenSource()));
4782 * add the current identifier source to the <i>set of assigned variables </i>
4785 private void addVariableSet() {
4786 HashSet set = peekVariableSet();
4788 set.add(new String(scanner.getCurrentTokenSource()));
4793 * add the current identifier source to the <i>set of assigned variables </i>
4796 private void addVariableSet(char[] token) {
4797 HashSet set = peekVariableSet();
4799 set.add(new String(token));
4804 * check if the current identifier source is in the <i>set of assigned
4805 * variables </i> Returns true, if no set is defined for the current scanner
4809 private boolean containsVariableSet() {
4810 return containsVariableSet(scanner.getCurrentTokenSource());
4813 private boolean containsVariableSet(char[] token) {
4815 if (!fStackUnassigned.isEmpty()) {
4817 String str = new String(token);
4818 for (int i = 0; i < fStackUnassigned.size(); i++) {
4819 set = (HashSet) fStackUnassigned.get(i);
4820 if (set.contains(str)) {