1 /***********************************************************************************************************************************
2 * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3 * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
18 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
19 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
20 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
21 import net.sourceforge.phpdt.internal.compiler.ast.Block;
22 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
23 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
24 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
26 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
27 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
28 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
30 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
31 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
32 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
35 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
36 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
37 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
39 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
44 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
45 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
46 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
47 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
48 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
49 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
50 import net.sourceforge.phpdt.internal.compiler.util.Util;
51 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
52 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
53 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
55 import org.eclipse.core.resources.IFile;
56 import org.eclipse.core.resources.IProject;
57 import org.eclipse.core.resources.IResource;
58 import org.eclipse.core.runtime.IPath;
60 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
61 protected final static int StackIncrement = 255;
63 protected int stateStackTop;
65 // protected int[] stack = new int[StackIncrement];
67 public int firstToken; // handle for multiple parsing goals
69 public int lastAct; // handle for multiple parsing goals
71 // protected RecoveredElement currentElement;
73 public static boolean VERBOSE_RECOVERY = false;
75 protected boolean diet = false; // tells the scanner to jump over some
78 * the PHP token scanner
80 public Scanner scanner;
84 protected int modifiers;
86 protected int modifiersSourceStart;
88 protected Parser(ProblemReporter problemReporter) {
89 this.problemReporter = problemReporter;
90 this.options = problemReporter.options;
91 this.token = TokenNameEOF;
92 this.initializeScanner();
95 public void setFileToParse(IFile fileToParse) {
96 this.token = TokenNameEOF;
97 this.initializeScanner();
101 * ClassDeclaration Constructor.
105 * Description of Parameter
108 public Parser(IFile fileToParse) {
109 // if (keywordMap == null) {
110 // keywordMap = new HashMap();
111 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
112 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
115 // this.currentPHPString = 0;
116 // PHPParserSuperclass.fileToParse = fileToParse;
117 // this.phpList = null;
118 this.includesList = null;
120 this.token = TokenNameEOF;
122 // this.rowCount = 1;
123 // this.columnCount = 0;
124 // this.phpEnd = false;
126 this.initializeScanner();
129 public void initializeScanner() {
130 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
131 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
132 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
136 * Create marker for the parse error
138 // private void setMarker(String message, int charStart, int charEnd, int
140 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
143 * This method will throw the SyntaxError. It will add the good lines and
144 * columns to the Error
148 * @throws SyntaxError
151 private void throwSyntaxError(String error) {
152 int problemStartPosition = scanner.getCurrentTokenStartPosition();
153 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
154 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
155 problemEndPosition = scanner.source.length - 1;
156 if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
157 problemStartPosition = problemEndPosition - 1;
160 throwSyntaxError(error, problemStartPosition, problemEndPosition);
164 * This method will throw the SyntaxError. It will add the good lines and
165 * columns to the Error
169 * @throws SyntaxError
172 // private void throwSyntaxError(String error, int startRow) {
173 // throw new SyntaxError(startRow, 0, " ", error);
175 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
176 if (referenceContext != null) {
177 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
178 compilationUnit.compilationResult);
180 throw new SyntaxError(1, 0, " ", error);
183 private void reportSyntaxError(String error) {
184 int problemStartPosition = scanner.getCurrentTokenStartPosition();
185 int problemEndPosition = scanner.getCurrentTokenEndPosition();
186 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
189 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
190 if (referenceContext != null) {
191 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
192 compilationUnit.compilationResult);
196 // private void reportSyntaxWarning(String error, int problemStartPosition,
197 // int problemEndPosition) {
198 // if (referenceContext != null) {
199 // problemReporter.phpParsingWarning(new String[] { error },
200 // problemStartPosition, problemEndPosition, referenceContext,
201 // compilationUnit.compilationResult);
206 * gets the next token from input
208 private void getNextToken() {
210 token = scanner.getNextToken();
212 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213 int currentStartPosition = scanner.getCurrentTokenStartPosition();
214 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
215 System.out.println(scanner.toStringAction(token));
217 } catch (InvalidInputException e) {
218 token = TokenNameERROR;
219 String detailedMessage = e.getMessage();
221 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
222 throwSyntaxError("Unterminated string.");
223 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
224 throwSyntaxError("Unterminated commment.");
230 public void init(String s) {
232 this.token = TokenNameEOF;
233 this.includesList = new ArrayList();
235 // this.rowCount = 1;
236 // this.columnCount = 0;
237 // this.phpEnd = false;
238 // this.phpMode = false;
239 /* scanner initialization */
240 scanner.setSource(s.toCharArray());
241 scanner.setPHPMode(false);
245 protected void initialize(boolean phpMode) {
246 initialize(phpMode, null);
249 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
250 compilationUnit = null;
251 referenceContext = null;
252 this.includesList = new ArrayList();
253 // this.indexManager = indexManager;
255 this.token = TokenNameEOF;
257 // this.rowCount = 1;
258 // this.columnCount = 0;
259 // this.phpEnd = false;
260 // this.phpMode = phpMode;
261 scanner.setPHPMode(phpMode);
266 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
269 public void parse(String s) {
274 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
277 public void parse(String s, HashMap variables) {
278 fMethodVariables = variables;
279 fStackUnassigned = new ArrayList();
285 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
288 protected void parse() {
289 if (scanner.compilationUnit != null) {
290 IResource resource = scanner.compilationUnit.getResource();
291 if (resource != null && resource instanceof IFile) {
292 // set the package name
293 consumePackageDeclarationName((IFile) resource);
299 if (token != TokenNameEOF && token != TokenNameERROR) {
302 if (token != TokenNameEOF) {
303 if (token == TokenNameERROR) {
304 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
306 if (token == TokenNameRPAREN) {
307 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
309 if (token == TokenNameRBRACE) {
310 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
312 if (token == TokenNameRBRACKET) {
313 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
315 if (token == TokenNameLPAREN) {
316 throwSyntaxError("Read character '('; end-of-file not reached.");
318 if (token == TokenNameLBRACE) {
319 throwSyntaxError("Read character '{'; end-of-file not reached.");
321 if (token == TokenNameLBRACKET) {
322 throwSyntaxError("Read character '['; end-of-file not reached.");
324 throwSyntaxError("End-of-file not reached.");
327 } catch (SyntaxError syntaxError) {
328 // syntaxError.printStackTrace();
337 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
340 public void parseFunction(String s, HashMap variables) {
342 scanner.phpMode = true;
343 parseFunction(variables);
347 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
350 protected void parseFunction(HashMap variables) {
352 boolean hasModifiers = member_modifiers();
353 if (token == TokenNamefunction) {
355 checkAndSetModifiers(AccPublic);
357 this.fMethodVariables = variables;
359 MethodDeclaration methodDecl = new MethodDeclaration(null);
360 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
361 methodDecl.modifiers = this.modifiers;
362 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
365 functionDefinition(methodDecl);
366 } catch (SyntaxError sytaxErr1) {
369 int sourceEnd = methodDecl.sourceEnd;
370 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
371 sourceEnd = methodDecl.declarationSourceStart + 1;
373 methodDecl.sourceEnd = sourceEnd;
374 methodDecl.declarationSourceEnd = sourceEnd;
379 protected CompilationUnitDeclaration endParse(int act) {
383 // if (currentElement != null) {
384 // currentElement.topElement().updateParseTree();
385 // if (VERBOSE_RECOVERY) {
386 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
387 // System.out.println("--------------------------"); //$NON-NLS-1$
388 // System.out.println(compilationUnit);
389 // System.out.println("----------------------------------"); //$NON-NLS-1$
392 if (diet & VERBOSE_RECOVERY) {
393 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
394 System.out.println("--------------------------"); //$NON-NLS-1$
395 System.out.println(compilationUnit);
396 System.out.println("----------------------------------"); //$NON-NLS-1$
399 if (scanner.recordLineSeparator) {
400 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
402 if (scanner.taskTags != null) {
403 for (int i = 0; i < scanner.foundTaskCount; i++) {
404 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
405 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
406 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
409 compilationUnit.imports = new ImportReference[includesList.size()];
410 for (int i = 0; i < includesList.size(); i++) {
411 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
413 return compilationUnit;
416 private Block statementList() {
417 boolean branchStatement = false;
419 int blockStart = scanner.getCurrentTokenStartPosition();
420 ArrayList blockStatements = new ArrayList();
423 statement = statement();
424 blockStatements.add(statement);
425 if (branchStatement && statement != null) {
426 // reportSyntaxError("Unreachable code", statement.sourceStart,
427 // statement.sourceEnd);
428 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
429 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
431 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
432 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
433 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
434 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
435 return createBlock(blockStart, blockStatements);
437 branchStatement = checkUnreachableStatements(statement);
438 } catch (SyntaxError sytaxErr1) {
439 // if an error occured,
440 // try to find keywords
441 // to parse the rest of the string
442 boolean tokenize = scanner.tokenizeStrings;
444 scanner.tokenizeStrings = true;
447 while (token != TokenNameEOF) {
448 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
449 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
450 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
451 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
452 return createBlock(blockStart, blockStatements);
454 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
455 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
456 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
457 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
458 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
459 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
462 // System.out.println(scanner.toStringAction(token));
464 // System.out.println(scanner.toStringAction(token));
466 if (token == TokenNameEOF) {
470 scanner.tokenizeStrings = tokenize;
480 private boolean checkUnreachableStatements(Statement statement) {
481 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
483 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
491 * @param blockStatements
494 private Block createBlock(int blockStart, ArrayList blockStatements) {
495 int blockEnd = scanner.getCurrentTokenEndPosition();
496 Block b = Block.EmptyWith(blockStart, blockEnd);
497 b.statements = new Statement[blockStatements.size()];
498 blockStatements.toArray(b.statements);
502 private void functionBody(MethodDeclaration methodDecl) {
503 // '{' [statement-list] '}'
504 if (token == TokenNameLBRACE) {
507 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
508 throwSyntaxError("'{' expected in compound-statement.");
510 if (token != TokenNameRBRACE) {
513 if (token == TokenNameRBRACE) {
514 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
517 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
518 throwSyntaxError("'}' expected in compound-statement.");
522 private Statement statement() {
523 Statement statement = null;
524 Expression expression;
525 int sourceStart = scanner.getCurrentTokenStartPosition();
527 if (token == TokenNameif) {
528 // T_IF '(' expr ')' statement elseif_list else_single
529 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
530 // new_else_single T_ENDIF ';'
532 if (token == TokenNameLPAREN) {
535 throwSyntaxError("'(' expected after 'if' keyword.");
538 if (token == TokenNameRPAREN) {
541 throwSyntaxError("')' expected after 'if' condition.");
543 // create basic IfStatement
544 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
545 if (token == TokenNameCOLON) {
547 ifStatementColon(ifStatement);
549 ifStatement(ifStatement);
552 } else if (token == TokenNameswitch) {
554 if (token == TokenNameLPAREN) {
557 throwSyntaxError("'(' expected after 'switch' keyword.");
560 if (token == TokenNameRPAREN) {
563 throwSyntaxError("')' expected after 'switch' condition.");
567 } else if (token == TokenNamefor) {
569 if (token == TokenNameLPAREN) {
572 throwSyntaxError("'(' expected after 'for' keyword.");
574 if (token == TokenNameSEMICOLON) {
578 if (token == TokenNameSEMICOLON) {
581 throwSyntaxError("';' expected after 'for'.");
584 if (token == TokenNameSEMICOLON) {
588 if (token == TokenNameSEMICOLON) {
591 throwSyntaxError("';' expected after 'for'.");
594 if (token == TokenNameRPAREN) {
598 if (token == TokenNameRPAREN) {
601 throwSyntaxError("')' expected after 'for'.");
606 } else if (token == TokenNamewhile) {
608 if (token == TokenNameLPAREN) {
611 throwSyntaxError("'(' expected after 'while' keyword.");
614 if (token == TokenNameRPAREN) {
617 throwSyntaxError("')' expected after 'while' condition.");
621 } else if (token == TokenNamedo) {
623 if (token == TokenNameLBRACE) {
625 if (token != TokenNameRBRACE) {
628 if (token == TokenNameRBRACE) {
631 throwSyntaxError("'}' expected after 'do' keyword.");
636 if (token == TokenNamewhile) {
638 if (token == TokenNameLPAREN) {
641 throwSyntaxError("'(' expected after 'while' keyword.");
644 if (token == TokenNameRPAREN) {
647 throwSyntaxError("')' expected after 'while' condition.");
650 throwSyntaxError("'while' expected after 'do' keyword.");
652 if (token == TokenNameSEMICOLON) {
655 if (token != TokenNameINLINE_HTML) {
656 throwSyntaxError("';' expected after do-while statement.");
661 } else if (token == TokenNameforeach) {
663 if (token == TokenNameLPAREN) {
666 throwSyntaxError("'(' expected after 'foreach' keyword.");
669 if (token == TokenNameas) {
672 throwSyntaxError("'as' expected after 'foreach' exxpression.");
676 foreach_optional_arg();
677 if (token == TokenNameEQUAL_GREATER) {
679 variable(false, false);
681 if (token == TokenNameRPAREN) {
684 throwSyntaxError("')' expected after 'foreach' expression.");
688 } else if (token == TokenNamebreak) {
691 if (token != TokenNameSEMICOLON) {
694 if (token == TokenNameSEMICOLON) {
695 sourceEnd = scanner.getCurrentTokenEndPosition();
698 if (token != TokenNameINLINE_HTML) {
699 throwSyntaxError("';' expected after 'break'.");
701 sourceEnd = scanner.getCurrentTokenEndPosition();
704 return new BreakStatement(null, sourceStart, sourceEnd);
705 } else if (token == TokenNamecontinue) {
708 if (token != TokenNameSEMICOLON) {
711 if (token == TokenNameSEMICOLON) {
712 sourceEnd = scanner.getCurrentTokenEndPosition();
715 if (token != TokenNameINLINE_HTML) {
716 throwSyntaxError("';' expected after 'continue'.");
718 sourceEnd = scanner.getCurrentTokenEndPosition();
721 return new ContinueStatement(null, sourceStart, sourceEnd);
722 } else if (token == TokenNamereturn) {
725 if (token != TokenNameSEMICOLON) {
728 if (token == TokenNameSEMICOLON) {
729 sourceEnd = scanner.getCurrentTokenEndPosition();
732 if (token != TokenNameINLINE_HTML) {
733 throwSyntaxError("';' expected after 'return'.");
735 sourceEnd = scanner.getCurrentTokenEndPosition();
738 return new ReturnStatement(expression, sourceStart, sourceEnd);
739 } else if (token == TokenNameecho) {
742 if (token == TokenNameSEMICOLON) {
745 if (token != TokenNameINLINE_HTML) {
746 throwSyntaxError("';' expected after 'echo' statement.");
751 } else if (token == TokenNameINLINE_HTML) {
752 if (scanner.phpExpressionTag) {
753 // start of <?= ... ?> block
756 if (token == TokenNameSEMICOLON) {
759 if (token != TokenNameINLINE_HTML) {
760 throwSyntaxError("Missing '?>' for open PHP expression block ('<?=').");
766 // } else if (token == TokenNameprint) {
769 // if (token == TokenNameSEMICOLON) {
772 // if (token != TokenNameStopPHP) {
773 // throwSyntaxError("';' expected after 'print' statement.");
778 } else if (token == TokenNameglobal) {
781 if (token == TokenNameSEMICOLON) {
784 if (token != TokenNameINLINE_HTML) {
785 throwSyntaxError("';' expected after 'global' statement.");
790 } else if (token == TokenNamestatic) {
793 if (token == TokenNameSEMICOLON) {
796 if (token != TokenNameINLINE_HTML) {
797 throwSyntaxError("';' expected after 'static' statement.");
802 } else if (token == TokenNameunset) {
804 if (token == TokenNameLPAREN) {
807 throwSyntaxError("'(' expected after 'unset' statement.");
810 if (token == TokenNameRPAREN) {
813 throwSyntaxError("')' expected after 'unset' statement.");
815 if (token == TokenNameSEMICOLON) {
818 if (token != TokenNameINLINE_HTML) {
819 throwSyntaxError("';' expected after 'unset' statement.");
824 } else if (token == TokenNamefunction) {
825 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
826 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
827 methodDecl.modifiers = AccDefault;
828 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
831 functionDefinition(methodDecl);
833 sourceEnd = methodDecl.sourceEnd;
834 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
835 sourceEnd = methodDecl.declarationSourceStart + 1;
837 methodDecl.declarationSourceEnd = sourceEnd;
838 methodDecl.sourceEnd = sourceEnd;
841 } else if (token == TokenNamedeclare) {
842 // T_DECLARE '(' declare_list ')' declare_statement
844 if (token != TokenNameLPAREN) {
845 throwSyntaxError("'(' expected in 'declare' statement.");
849 if (token != TokenNameRPAREN) {
850 throwSyntaxError("')' expected in 'declare' statement.");
855 } else if (token == TokenNametry) {
857 if (token != TokenNameLBRACE) {
858 throwSyntaxError("'{' expected in 'try' statement.");
862 if (token != TokenNameRBRACE) {
863 throwSyntaxError("'}' expected in 'try' statement.");
867 } else if (token == TokenNamecatch) {
869 if (token != TokenNameLPAREN) {
870 throwSyntaxError("'(' expected in 'catch' statement.");
873 fully_qualified_class_name();
874 if (token != TokenNameVariable) {
875 throwSyntaxError("Variable expected in 'catch' statement.");
879 if (token != TokenNameRPAREN) {
880 throwSyntaxError("')' expected in 'catch' statement.");
883 if (token != TokenNameLBRACE) {
884 throwSyntaxError("'{' expected in 'catch' statement.");
887 if (token != TokenNameRBRACE) {
889 if (token != TokenNameRBRACE) {
890 throwSyntaxError("'}' expected in 'catch' statement.");
894 additional_catches();
896 } else if (token == TokenNamethrow) {
899 if (token == TokenNameSEMICOLON) {
902 throwSyntaxError("';' expected after 'throw' exxpression.");
905 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
907 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
908 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
909 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
910 typeDecl.name = new char[] { ' ' };
911 // default super class
912 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
913 compilationUnit.types.add(typeDecl);
914 pushOnAstStack(typeDecl);
915 unticked_class_declaration_statement(typeDecl);
923 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
924 } else if (token == TokenNameLBRACE) {
926 if (token != TokenNameRBRACE) {
927 statement = statementList();
929 if (token == TokenNameRBRACE) {
933 throwSyntaxError("'}' expected.");
936 if (token != TokenNameSEMICOLON) {
939 if (token == TokenNameSEMICOLON) {
943 if (token == TokenNameRBRACE) {
944 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
946 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
947 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
957 private void declare_statement() {
959 // | ':' inner_statement_list T_ENDDECLARE ';'
961 if (token == TokenNameCOLON) {
963 // TODO: implement inner_statement_list();
965 if (token != TokenNameenddeclare) {
966 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
969 if (token != TokenNameSEMICOLON) {
970 throwSyntaxError("';' expected after 'enddeclare' keyword.");
978 private void declare_list() {
979 // T_STRING '=' static_scalar
980 // | declare_list ',' T_STRING '=' static_scalar
982 if (token != TokenNameIdentifier) {
983 throwSyntaxError("Identifier expected in 'declare' list.");
986 if (token != TokenNameEQUAL) {
987 throwSyntaxError("'=' expected in 'declare' list.");
991 if (token != TokenNameCOMMA) {
998 private void additional_catches() {
999 while (token == TokenNamecatch) {
1001 if (token != TokenNameLPAREN) {
1002 throwSyntaxError("'(' expected in 'catch' statement.");
1005 fully_qualified_class_name();
1006 if (token != TokenNameVariable) {
1007 throwSyntaxError("Variable expected in 'catch' statement.");
1011 if (token != TokenNameRPAREN) {
1012 throwSyntaxError("')' expected in 'catch' statement.");
1015 if (token != TokenNameLBRACE) {
1016 throwSyntaxError("'{' expected in 'catch' statement.");
1019 if (token != TokenNameRBRACE) {
1022 if (token != TokenNameRBRACE) {
1023 throwSyntaxError("'}' expected in 'catch' statement.");
1029 private void foreach_variable() {
1032 if (token == TokenNameAND) {
1038 private void foreach_optional_arg() {
1040 // | T_DOUBLE_ARROW foreach_variable
1041 if (token == TokenNameEQUAL_GREATER) {
1047 private void global_var_list() {
1049 // global_var_list ',' global_var
1051 HashSet set = peekVariableSet();
1054 if (token != TokenNameCOMMA) {
1061 private void global_var(HashSet set) {
1065 // | '$' '{' expr '}'
1066 if (token == TokenNameVariable) {
1067 if (fMethodVariables != null) {
1068 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1069 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1071 addVariableSet(set);
1073 } else if (token == TokenNameDOLLAR) {
1075 if (token == TokenNameLBRACE) {
1078 if (token != TokenNameRBRACE) {
1079 throwSyntaxError("'}' expected in global variable.");
1088 private void static_var_list() {
1090 // static_var_list ',' T_VARIABLE
1091 // | static_var_list ',' T_VARIABLE '=' static_scalar
1093 // | T_VARIABLE '=' static_scalar,
1094 HashSet set = peekVariableSet();
1096 if (token == TokenNameVariable) {
1097 if (fMethodVariables != null) {
1098 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1099 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1101 addVariableSet(set);
1103 if (token == TokenNameEQUAL) {
1107 if (token != TokenNameCOMMA) {
1117 private void unset_variables() {
1120 // | unset_variables ',' unset_variable
1124 variable(false, false);
1125 if (token != TokenNameCOMMA) {
1132 private final void initializeModifiers() {
1134 this.modifiersSourceStart = -1;
1137 private final void checkAndSetModifiers(int flag) {
1138 this.modifiers |= flag;
1139 if (this.modifiersSourceStart < 0)
1140 this.modifiersSourceStart = this.scanner.startPosition;
1143 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1144 initializeModifiers();
1145 if (token == TokenNameinterface) {
1146 // interface_entry T_STRING
1147 // interface_extends_list
1148 // '{' class_statement_list '}'
1149 checkAndSetModifiers(AccInterface);
1151 typeDecl.modifiers = this.modifiers;
1152 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1153 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1154 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1155 typeDecl.name = scanner.getCurrentIdentifierSource();
1156 if (token > TokenNameKEYWORD) {
1157 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1158 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1159 // throwSyntaxError("Don't use a keyword for interface declaration ["
1160 // + scanner.toStringAction(token) + "].",
1161 // typeDecl.sourceStart, typeDecl.sourceEnd);
1164 interface_extends_list(typeDecl);
1166 typeDecl.name = new char[] { ' ' };
1167 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1171 // class_entry_type T_STRING extends_from
1173 // '{' class_statement_list'}'
1175 typeDecl.modifiers = this.modifiers;
1176 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1177 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1179 // identifier 'extends' identifier
1180 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1181 typeDecl.name = scanner.getCurrentIdentifierSource();
1182 if (token > TokenNameKEYWORD) {
1183 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1184 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1185 // throwSyntaxError("Don't use a keyword for class declaration [" +
1186 // scanner.toStringAction(token) + "].",
1187 // typeDecl.sourceStart, typeDecl.sourceEnd);
1192 // | T_EXTENDS fully_qualified_class_name
1193 if (token == TokenNameextends) {
1194 interface_extends_list(typeDecl);
1196 // if (token != TokenNameIdentifier) {
1197 // throwSyntaxError("Class name expected after keyword
1199 // scanner.getCurrentTokenStartPosition(), scanner
1200 // .getCurrentTokenEndPosition());
1203 implements_list(typeDecl);
1205 typeDecl.name = new char[] { ' ' };
1206 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1210 // '{' class_statement_list '}'
1211 if (token == TokenNameLBRACE) {
1213 if (token != TokenNameRBRACE) {
1214 ArrayList list = new ArrayList();
1215 class_statement_list(list);
1216 typeDecl.fields = new FieldDeclaration[list.size()];
1217 for (int i = 0; i < list.size(); i++) {
1218 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1221 if (token == TokenNameRBRACE) {
1222 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1225 throwSyntaxError("'}' expected at end of class body.");
1228 throwSyntaxError("'{' expected at start of class body.");
1232 private void class_entry_type() {
1234 // | T_ABSTRACT T_CLASS
1235 // | T_FINAL T_CLASS
1236 if (token == TokenNameclass) {
1238 } else if (token == TokenNameabstract) {
1239 checkAndSetModifiers(AccAbstract);
1241 if (token != TokenNameclass) {
1242 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1245 } else if (token == TokenNamefinal) {
1246 checkAndSetModifiers(AccFinal);
1248 if (token != TokenNameclass) {
1249 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1253 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1257 // private void class_extends(TypeDeclaration typeDecl) {
1259 // // | T_EXTENDS interface_list
1260 // if (token == TokenNameextends) {
1263 // if (token == TokenNameIdentifier) {
1266 // throwSyntaxError("Class name expected after keyword 'extends'.");
1271 private void interface_extends_list(TypeDeclaration typeDecl) {
1273 // | T_EXTENDS interface_list
1274 if (token == TokenNameextends) {
1280 private void implements_list(TypeDeclaration typeDecl) {
1282 // | T_IMPLEMENTS interface_list
1283 if (token == TokenNameimplements) {
1289 private void interface_list() {
1291 // fully_qualified_class_name
1292 // | interface_list ',' fully_qualified_class_name
1294 if (token == TokenNameIdentifier) {
1297 throwSyntaxError("Interface name expected after keyword 'implements'.");
1299 if (token != TokenNameCOMMA) {
1306 // private void classBody(TypeDeclaration typeDecl) {
1307 // //'{' [class-element-list] '}'
1308 // if (token == TokenNameLBRACE) {
1310 // if (token != TokenNameRBRACE) {
1311 // class_statement_list();
1313 // if (token == TokenNameRBRACE) {
1314 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1317 // throwSyntaxError("'}' expected at end of class body.");
1320 // throwSyntaxError("'{' expected at start of class body.");
1323 private void class_statement_list(ArrayList list) {
1326 class_statement(list);
1327 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1328 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1329 || token == TokenNameconst) {
1332 if (token == TokenNameRBRACE) {
1335 throwSyntaxError("'}' at end of class statement.");
1336 } catch (SyntaxError sytaxErr1) {
1337 boolean tokenize = scanner.tokenizeStrings;
1339 scanner.tokenizeStrings = true;
1342 // if an error occured,
1343 // try to find keywords
1344 // to parse the rest of the string
1345 while (token != TokenNameEOF) {
1346 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1347 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1348 || token == TokenNameconst) {
1351 // System.out.println(scanner.toStringAction(token));
1354 if (token == TokenNameEOF) {
1358 scanner.tokenizeStrings = tokenize;
1364 private void class_statement(ArrayList list) {
1366 // variable_modifiers class_variable_declaration ';'
1367 // | class_constant_declaration ';'
1368 // | method_modifiers T_FUNCTION is_reference T_STRING
1369 // '(' parameter_list ')' method_body
1370 initializeModifiers();
1371 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1373 if (token == TokenNamevar) {
1374 checkAndSetModifiers(AccPublic);
1375 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1376 referenceContext, compilationUnit.compilationResult);
1378 class_variable_declaration(declarationSourceStart, list);
1379 } else if (token == TokenNameconst) {
1380 checkAndSetModifiers(AccFinal | AccPublic);
1381 class_constant_declaration(declarationSourceStart, list);
1382 if (token != TokenNameSEMICOLON) {
1383 throwSyntaxError("';' expected after class const declaration.");
1387 boolean hasModifiers = member_modifiers();
1388 if (token == TokenNamefunction) {
1389 if (!hasModifiers) {
1390 checkAndSetModifiers(AccPublic);
1392 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1393 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1394 methodDecl.modifiers = this.modifiers;
1395 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1398 functionDefinition(methodDecl);
1400 int sourceEnd = methodDecl.sourceEnd;
1401 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1402 sourceEnd = methodDecl.declarationSourceStart + 1;
1404 methodDecl.declarationSourceEnd = sourceEnd;
1405 methodDecl.sourceEnd = sourceEnd;
1408 if (!hasModifiers) {
1409 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1411 class_variable_declaration(declarationSourceStart, list);
1416 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1417 // class_constant_declaration ',' T_STRING '=' static_scalar
1418 // | T_CONST T_STRING '=' static_scalar
1419 if (token != TokenNameconst) {
1420 throwSyntaxError("'const' keyword expected in class declaration.");
1425 if (token != TokenNameIdentifier) {
1426 throwSyntaxError("Identifier expected in class const declaration.");
1428 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1429 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1430 fieldDeclaration.modifiers = this.modifiers;
1431 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1432 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1433 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1434 // fieldDeclaration.type
1435 list.add(fieldDeclaration);
1437 if (token != TokenNameEQUAL) {
1438 throwSyntaxError("'=' expected in class const declaration.");
1442 if (token != TokenNameCOMMA) {
1443 break; // while(true)-loop
1449 // private void variable_modifiers() {
1450 // // variable_modifiers:
1451 // // non_empty_member_modifiers
1453 // initializeModifiers();
1454 // if (token == TokenNamevar) {
1455 // checkAndSetModifiers(AccPublic);
1456 // reportSyntaxError(
1457 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1459 // modifier for field declarations.",
1460 // scanner.getCurrentTokenStartPosition(), scanner
1461 // .getCurrentTokenEndPosition());
1464 // if (!member_modifiers()) {
1465 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1466 // field declarations.");
1470 // private void method_modifiers() {
1471 // //method_modifiers:
1473 // //| non_empty_member_modifiers
1474 // initializeModifiers();
1475 // if (!member_modifiers()) {
1476 // checkAndSetModifiers(AccPublic);
1479 private boolean member_modifiers() {
1486 boolean foundToken = false;
1488 if (token == TokenNamepublic) {
1489 checkAndSetModifiers(AccPublic);
1492 } else if (token == TokenNameprotected) {
1493 checkAndSetModifiers(AccProtected);
1496 } else if (token == TokenNameprivate) {
1497 checkAndSetModifiers(AccPrivate);
1500 } else if (token == TokenNamestatic) {
1501 checkAndSetModifiers(AccStatic);
1504 } else if (token == TokenNameabstract) {
1505 checkAndSetModifiers(AccAbstract);
1508 } else if (token == TokenNamefinal) {
1509 checkAndSetModifiers(AccFinal);
1519 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1520 // class_variable_declaration:
1521 // class_variable_declaration ',' T_VARIABLE
1522 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1524 // | T_VARIABLE '=' static_scalar
1525 char[] classVariable;
1527 if (token == TokenNameVariable) {
1528 classVariable = scanner.getCurrentIdentifierSource();
1529 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1531 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1532 .getCurrentTokenEndPosition());
1533 fieldDeclaration.modifiers = this.modifiers;
1534 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1535 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1536 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1537 list.add(fieldDeclaration);
1538 if (fTypeVariables != null) {
1539 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1540 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1543 if (token == TokenNameEQUAL) {
1548 // if (token == TokenNamethis) {
1549 // throwSyntaxError("'$this' not allowed after keyword 'public'
1550 // 'protected' 'private' 'var'.");
1552 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1554 if (token != TokenNameCOMMA) {
1559 if (token != TokenNameSEMICOLON) {
1560 throwSyntaxError("';' expected after field declaration.");
1565 private void functionDefinition(MethodDeclaration methodDecl) {
1566 boolean isAbstract = false;
1568 if (compilationUnit != null) {
1569 compilationUnit.types.add(methodDecl);
1572 ASTNode node = astStack[astPtr];
1573 if (node instanceof TypeDeclaration) {
1574 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1575 if (typeDecl.methods == null) {
1576 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1578 AbstractMethodDeclaration[] newMethods;
1579 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1580 typeDecl.methods.length);
1581 newMethods[typeDecl.methods.length] = methodDecl;
1582 typeDecl.methods = newMethods;
1584 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1586 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1592 pushFunctionVariableSet();
1593 functionDeclarator(methodDecl);
1594 if (token == TokenNameSEMICOLON) {
1596 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1597 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1602 functionBody(methodDecl);
1604 if (!fStackUnassigned.isEmpty()) {
1605 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1610 private void functionDeclarator(MethodDeclaration methodDecl) {
1611 // identifier '(' [parameter-list] ')'
1612 if (token == TokenNameAND) {
1615 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1616 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1617 if (Scanner.isIdentifierOrKeyword(token)) {
1618 methodDecl.selector = scanner.getCurrentIdentifierSource();
1619 if (token > TokenNameKEYWORD) {
1620 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1621 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1624 if (token == TokenNameLPAREN) {
1627 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1628 throwSyntaxError("'(' expected in function declaration.");
1630 if (token != TokenNameRPAREN) {
1631 parameter_list(methodDecl);
1633 if (token != TokenNameRPAREN) {
1634 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1635 throwSyntaxError("')' expected in function declaration.");
1637 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1641 methodDecl.selector = "<undefined>".toCharArray();
1642 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1643 throwSyntaxError("Function name expected after keyword 'function'.");
1648 private void parameter_list(MethodDeclaration methodDecl) {
1649 // non_empty_parameter_list
1651 non_empty_parameter_list(methodDecl, true);
1654 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1655 // optional_class_type T_VARIABLE
1656 // | optional_class_type '&' T_VARIABLE
1657 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1658 // | optional_class_type T_VARIABLE '=' static_scalar
1659 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1660 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1661 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1663 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1665 char[] typeIdentifier = null;
1666 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1667 HashSet set = peekVariableSet();
1669 if (token == TokenNameIdentifier) {
1670 typeIdentifier = scanner.getCurrentIdentifierSource();
1673 if (token == TokenNameAND) {
1676 if (token == TokenNameVariable) {
1677 if (fMethodVariables != null) {
1679 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1680 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1682 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1684 info.typeIdentifier = typeIdentifier;
1685 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1687 addVariableSet(set);
1689 if (token == TokenNameEQUAL) {
1694 throwSyntaxError("Variable expected in parameter list.");
1696 if (token != TokenNameCOMMA) {
1703 if (!empty_allowed) {
1704 throwSyntaxError("Identifier expected in parameter list.");
1708 private void optional_class_type() {
1713 // private void parameterDeclaration() {
1715 // //variable-reference
1716 // if (token == TokenNameAND) {
1718 // if (isVariable()) {
1721 // throwSyntaxError("Variable expected after reference operator '&'.");
1724 // //variable '=' constant
1725 // if (token == TokenNameVariable) {
1727 // if (token == TokenNameEQUAL) {
1733 // // if (token == TokenNamethis) {
1734 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1735 // // declaration.");
1739 private void labeledStatementList() {
1740 if (token != TokenNamecase && token != TokenNamedefault) {
1741 throwSyntaxError("'case' or 'default' expected.");
1744 if (token == TokenNamecase) {
1746 expr(); // constant();
1747 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1749 if (token == TokenNamecase || token == TokenNamedefault) {
1750 // empty case statement ?
1755 // else if (token == TokenNameSEMICOLON) {
1757 // "':' expected after 'case' keyword (Found token: " +
1758 // scanner.toStringAction(token) + ")",
1759 // scanner.getCurrentTokenStartPosition(),
1760 // scanner.getCurrentTokenEndPosition(),
1763 // if (token == TokenNamecase) { // empty case statement ?
1769 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1771 } else { // TokenNamedefault
1773 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1775 if (token == TokenNameRBRACE) {
1776 // empty default case
1779 if (token != TokenNamecase) {
1783 throwSyntaxError("':' character expected after 'default'.");
1786 } while (token == TokenNamecase || token == TokenNamedefault);
1789 private void ifStatementColon(IfStatement iState) {
1790 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1791 // new_else_single T_ENDIF ';'
1792 HashSet assignedVariableSet = null;
1794 Block b = inner_statement_list();
1795 iState.thenStatement = b;
1796 checkUnreachable(iState, b);
1798 assignedVariableSet = removeIfVariableSet();
1800 if (token == TokenNameelseif) {
1802 pushIfVariableSet();
1803 new_elseif_list(iState);
1805 HashSet set = removeIfVariableSet();
1806 if (assignedVariableSet != null && set != null) {
1807 assignedVariableSet.addAll(set);
1812 pushIfVariableSet();
1813 new_else_single(iState);
1815 HashSet set = removeIfVariableSet();
1816 if (assignedVariableSet != null) {
1817 HashSet topSet = peekVariableSet();
1818 if (topSet != null) {
1822 topSet.addAll(assignedVariableSet);
1826 if (token != TokenNameendif) {
1827 throwSyntaxError("'endif' expected.");
1830 if (token != TokenNameSEMICOLON) {
1831 reportSyntaxError("';' expected after if-statement.");
1832 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1834 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1839 private void ifStatement(IfStatement iState) {
1840 // T_IF '(' expr ')' statement elseif_list else_single
1841 HashSet assignedVariableSet = null;
1843 pushIfVariableSet();
1844 Statement s = statement();
1845 iState.thenStatement = s;
1846 checkUnreachable(iState, s);
1848 assignedVariableSet = removeIfVariableSet();
1851 if (token == TokenNameelseif) {
1853 pushIfVariableSet();
1854 elseif_list(iState);
1856 HashSet set = removeIfVariableSet();
1857 if (assignedVariableSet != null && set != null) {
1858 assignedVariableSet.addAll(set);
1863 pushIfVariableSet();
1864 else_single(iState);
1866 HashSet set = removeIfVariableSet();
1867 if (assignedVariableSet != null) {
1868 HashSet topSet = peekVariableSet();
1869 if (topSet != null) {
1873 topSet.addAll(assignedVariableSet);
1879 private void elseif_list(IfStatement iState) {
1881 // | elseif_list T_ELSEIF '(' expr ')' statement
1882 ArrayList conditionList = new ArrayList();
1883 ArrayList statementList = new ArrayList();
1886 while (token == TokenNameelseif) {
1888 if (token == TokenNameLPAREN) {
1891 throwSyntaxError("'(' expected after 'elseif' keyword.");
1894 conditionList.add(e);
1895 if (token == TokenNameRPAREN) {
1898 throwSyntaxError("')' expected after 'elseif' condition.");
1901 statementList.add(s);
1902 checkUnreachable(iState, s);
1904 iState.elseifConditions = new Expression[conditionList.size()];
1905 iState.elseifStatements = new Statement[statementList.size()];
1906 conditionList.toArray(iState.elseifConditions);
1907 statementList.toArray(iState.elseifStatements);
1910 private void new_elseif_list(IfStatement iState) {
1912 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1913 ArrayList conditionList = new ArrayList();
1914 ArrayList statementList = new ArrayList();
1917 while (token == TokenNameelseif) {
1919 if (token == TokenNameLPAREN) {
1922 throwSyntaxError("'(' expected after 'elseif' keyword.");
1925 conditionList.add(e);
1926 if (token == TokenNameRPAREN) {
1929 throwSyntaxError("')' expected after 'elseif' condition.");
1931 if (token == TokenNameCOLON) {
1934 throwSyntaxError("':' expected after 'elseif' keyword.");
1936 b = inner_statement_list();
1937 statementList.add(b);
1938 checkUnreachable(iState, b);
1940 iState.elseifConditions = new Expression[conditionList.size()];
1941 iState.elseifStatements = new Statement[statementList.size()];
1942 conditionList.toArray(iState.elseifConditions);
1943 statementList.toArray(iState.elseifStatements);
1946 private void else_single(IfStatement iState) {
1949 if (token == TokenNameelse) {
1951 Statement s = statement();
1952 iState.elseStatement = s;
1953 checkUnreachable(iState, s);
1955 iState.checkUnreachable = false;
1957 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1960 private void new_else_single(IfStatement iState) {
1962 // | T_ELSE ':' inner_statement_list
1963 if (token == TokenNameelse) {
1965 if (token == TokenNameCOLON) {
1968 throwSyntaxError("':' expected after 'else' keyword.");
1970 Block b = inner_statement_list();
1971 iState.elseStatement = b;
1972 checkUnreachable(iState, b);
1974 iState.checkUnreachable = false;
1978 private Block inner_statement_list() {
1979 // inner_statement_list inner_statement
1981 return statementList();
1988 private void checkUnreachable(IfStatement iState, Statement s) {
1989 if (s instanceof Block) {
1990 Block b = (Block) s;
1991 if (b.statements == null || b.statements.length == 0) {
1992 iState.checkUnreachable = false;
1994 int off = b.statements.length - 1;
1995 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
1996 && !(b.statements[off] instanceof BreakStatement)) {
1997 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
1998 iState.checkUnreachable = false;
2003 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2004 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2005 iState.checkUnreachable = false;
2011 // private void elseifStatementList() {
2013 // elseifStatement();
2015 // case TokenNameelse:
2017 // if (token == TokenNameCOLON) {
2019 // if (token != TokenNameendif) {
2024 // if (token == TokenNameif) { //'else if'
2027 // throwSyntaxError("':' expected after 'else'.");
2031 // case TokenNameelseif:
2040 // private void elseifStatement() {
2041 // if (token == TokenNameLPAREN) {
2044 // if (token != TokenNameRPAREN) {
2045 // throwSyntaxError("')' expected in else-if-statement.");
2048 // if (token != TokenNameCOLON) {
2049 // throwSyntaxError("':' expected in else-if-statement.");
2052 // if (token != TokenNameendif) {
2058 private void switchStatement() {
2059 if (token == TokenNameCOLON) {
2060 // ':' [labeled-statement-list] 'endswitch' ';'
2062 labeledStatementList();
2063 if (token != TokenNameendswitch) {
2064 throwSyntaxError("'endswitch' expected.");
2067 if (token != TokenNameSEMICOLON) {
2068 throwSyntaxError("';' expected after switch-statement.");
2072 // '{' [labeled-statement-list] '}'
2073 if (token != TokenNameLBRACE) {
2074 throwSyntaxError("'{' expected in switch statement.");
2077 if (token != TokenNameRBRACE) {
2078 labeledStatementList();
2080 if (token != TokenNameRBRACE) {
2081 throwSyntaxError("'}' expected in switch statement.");
2087 private void forStatement() {
2088 if (token == TokenNameCOLON) {
2091 if (token != TokenNameendfor) {
2092 throwSyntaxError("'endfor' expected.");
2095 if (token != TokenNameSEMICOLON) {
2096 throwSyntaxError("';' expected after for-statement.");
2104 private void whileStatement() {
2105 // ':' statement-list 'endwhile' ';'
2106 if (token == TokenNameCOLON) {
2109 if (token != TokenNameendwhile) {
2110 throwSyntaxError("'endwhile' expected.");
2113 if (token != TokenNameSEMICOLON) {
2114 throwSyntaxError("';' expected after while-statement.");
2122 private void foreachStatement() {
2123 if (token == TokenNameCOLON) {
2126 if (token != TokenNameendforeach) {
2127 throwSyntaxError("'endforeach' expected.");
2130 if (token != TokenNameSEMICOLON) {
2131 throwSyntaxError("';' expected after foreach-statement.");
2139 // private void exitStatus() {
2140 // if (token == TokenNameLPAREN) {
2143 // throwSyntaxError("'(' expected in 'exit-status'.");
2145 // if (token != TokenNameRPAREN) {
2148 // if (token == TokenNameRPAREN) {
2151 // throwSyntaxError("')' expected after 'exit-status'.");
2154 private void expressionList() {
2157 if (token == TokenNameCOMMA) {
2165 private Expression expr() {
2167 // | expr_without_variable
2168 // if (token!=TokenNameEOF) {
2169 if (Scanner.TRACE) {
2170 System.out.println("TRACE: expr()");
2172 return expr_without_variable(true);
2176 private Expression expr_without_variable(boolean only_variable) {
2177 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2178 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2179 Expression expression = new Expression();
2180 expression.sourceStart = exprSourceStart;
2181 // default, may be overwritten
2182 expression.sourceEnd = exprSourceEnd;
2184 // internal_functions_in_yacc
2193 // | T_INC rw_variable
2194 // | T_DEC rw_variable
2195 // | T_INT_CAST expr
2196 // | T_DOUBLE_CAST expr
2197 // | T_STRING_CAST expr
2198 // | T_ARRAY_CAST expr
2199 // | T_OBJECT_CAST expr
2200 // | T_BOOL_CAST expr
2201 // | T_UNSET_CAST expr
2202 // | T_EXIT exit_expr
2204 // | T_ARRAY '(' array_pair_list ')'
2205 // | '`' encaps_list '`'
2206 // | T_LIST '(' assignment_list ')' '=' expr
2207 // | T_NEW class_name_reference ctor_arguments
2208 // | variable '=' expr
2209 // | variable '=' '&' variable
2210 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2211 // | variable T_PLUS_EQUAL expr
2212 // | variable T_MINUS_EQUAL expr
2213 // | variable T_MUL_EQUAL expr
2214 // | variable T_DIV_EQUAL expr
2215 // | variable T_CONCAT_EQUAL expr
2216 // | variable T_MOD_EQUAL expr
2217 // | variable T_AND_EQUAL expr
2218 // | variable T_OR_EQUAL expr
2219 // | variable T_XOR_EQUAL expr
2220 // | variable T_SL_EQUAL expr
2221 // | variable T_SR_EQUAL expr
2222 // | rw_variable T_INC
2223 // | rw_variable T_DEC
2224 // | expr T_BOOLEAN_OR expr
2225 // | expr T_BOOLEAN_AND expr
2226 // | expr T_LOGICAL_OR expr
2227 // | expr T_LOGICAL_AND expr
2228 // | expr T_LOGICAL_XOR expr
2240 // | expr T_IS_IDENTICAL expr
2241 // | expr T_IS_NOT_IDENTICAL expr
2242 // | expr T_IS_EQUAL expr
2243 // | expr T_IS_NOT_EQUAL expr
2245 // | expr T_IS_SMALLER_OR_EQUAL expr
2247 // | expr T_IS_GREATER_OR_EQUAL expr
2248 // | expr T_INSTANCEOF class_name_reference
2249 // | expr '?' expr ':' expr
2250 if (Scanner.TRACE) {
2251 System.out.println("TRACE: expr_without_variable() PART 1");
2254 case TokenNameisset:
2255 // T_ISSET '(' isset_variables ')'
2257 if (token != TokenNameLPAREN) {
2258 throwSyntaxError("'(' expected after keyword 'isset'");
2262 if (token != TokenNameRPAREN) {
2263 throwSyntaxError("')' expected after keyword 'isset'");
2267 case TokenNameempty:
2269 if (token != TokenNameLPAREN) {
2270 throwSyntaxError("'(' expected after keyword 'empty'");
2273 variable(true, false);
2274 if (token != TokenNameRPAREN) {
2275 throwSyntaxError("')' expected after keyword 'empty'");
2280 case TokenNameinclude:
2281 case TokenNameinclude_once:
2282 case TokenNamerequire:
2283 case TokenNamerequire_once:
2284 internal_functions_in_yacc();
2287 case TokenNameLPAREN:
2290 if (token == TokenNameRPAREN) {
2293 throwSyntaxError("')' expected in expression.");
2303 // | T_INT_CAST expr
2304 // | T_DOUBLE_CAST expr
2305 // | T_STRING_CAST expr
2306 // | T_ARRAY_CAST expr
2307 // | T_OBJECT_CAST expr
2308 // | T_BOOL_CAST expr
2309 // | T_UNSET_CAST expr
2310 case TokenNameclone:
2311 case TokenNameprint:
2314 case TokenNameMINUS:
2316 case TokenNameTWIDDLE:
2317 case TokenNameintCAST:
2318 case TokenNamedoubleCAST:
2319 case TokenNamestringCAST:
2320 case TokenNamearrayCAST:
2321 case TokenNameobjectCAST:
2322 case TokenNameboolCAST:
2323 case TokenNameunsetCAST:
2333 // | T_STRING_VARNAME
2335 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2336 // | '`' encaps_list '`'
2338 // | '`' encaps_list '`'
2339 // case TokenNameEncapsedString0:
2340 // scanner.encapsedStringStack.push(new Character('`'));
2343 // if (token == TokenNameEncapsedString0) {
2346 // if (token != TokenNameEncapsedString0) {
2347 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2348 // scanner.toStringAction(token) + " )");
2352 // scanner.encapsedStringStack.pop();
2356 // // | '\'' encaps_list '\''
2357 // case TokenNameEncapsedString1:
2358 // scanner.encapsedStringStack.push(new Character('\''));
2361 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2362 // if (token == TokenNameEncapsedString1) {
2364 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2365 // exprSourceStart, scanner
2366 // .getCurrentTokenEndPosition());
2369 // if (token != TokenNameEncapsedString1) {
2370 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2371 // + scanner.toStringAction(token) + " )");
2374 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2375 // exprSourceStart, scanner
2376 // .getCurrentTokenEndPosition());
2380 // scanner.encapsedStringStack.pop();
2384 // //| '"' encaps_list '"'
2385 // case TokenNameEncapsedString2:
2386 // scanner.encapsedStringStack.push(new Character('"'));
2389 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2390 // if (token == TokenNameEncapsedString2) {
2392 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2393 // exprSourceStart, scanner
2394 // .getCurrentTokenEndPosition());
2397 // if (token != TokenNameEncapsedString2) {
2398 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2399 // scanner.toStringAction(token) + " )");
2402 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2403 // exprSourceStart, scanner
2404 // .getCurrentTokenEndPosition());
2408 // scanner.encapsedStringStack.pop();
2412 case TokenNameStringDoubleQuote:
2413 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2414 .getCurrentTokenEndPosition());
2417 case TokenNameStringSingleQuote:
2418 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2419 .getCurrentTokenEndPosition());
2422 case TokenNameIntegerLiteral:
2423 case TokenNameDoubleLiteral:
2424 case TokenNameStringInterpolated:
2427 case TokenNameCLASS_C:
2428 case TokenNameMETHOD_C:
2429 case TokenNameFUNC_C:
2432 case TokenNameHEREDOC:
2435 case TokenNamearray:
2436 // T_ARRAY '(' array_pair_list ')'
2438 if (token == TokenNameLPAREN) {
2440 if (token == TokenNameRPAREN) {
2445 if (token != TokenNameRPAREN) {
2446 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2450 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2454 // | T_LIST '(' assignment_list ')' '=' expr
2456 if (token == TokenNameLPAREN) {
2459 if (token != TokenNameRPAREN) {
2460 throwSyntaxError("')' expected after 'list' keyword.");
2463 if (token != TokenNameEQUAL) {
2464 throwSyntaxError("'=' expected after 'list' keyword.");
2469 throwSyntaxError("'(' expected after 'list' keyword.");
2473 // | T_NEW class_name_reference ctor_arguments
2475 Expression typeRef = class_name_reference();
2477 if (typeRef != null) {
2478 expression = typeRef;
2481 // | T_INC rw_variable
2482 // | T_DEC rw_variable
2483 case TokenNamePLUS_PLUS:
2484 case TokenNameMINUS_MINUS:
2488 // | variable '=' expr
2489 // | variable '=' '&' variable
2490 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2491 // | variable T_PLUS_EQUAL expr
2492 // | variable T_MINUS_EQUAL expr
2493 // | variable T_MUL_EQUAL expr
2494 // | variable T_DIV_EQUAL expr
2495 // | variable T_CONCAT_EQUAL expr
2496 // | variable T_MOD_EQUAL expr
2497 // | variable T_AND_EQUAL expr
2498 // | variable T_OR_EQUAL expr
2499 // | variable T_XOR_EQUAL expr
2500 // | variable T_SL_EQUAL expr
2501 // | variable T_SR_EQUAL expr
2502 // | rw_variable T_INC
2503 // | rw_variable T_DEC
2504 case TokenNameIdentifier:
2505 case TokenNameVariable:
2506 case TokenNameDOLLAR:
2507 Expression lhs = null;
2508 boolean rememberedVar = false;
2509 if (token == TokenNameIdentifier) {
2510 lhs = identifier(true, true);
2515 lhs = variable(true, true);
2519 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2520 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2521 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2522 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2523 && token != TokenNameLEFT_SHIFT_EQUAL) {
2524 FieldReference ref = (FieldReference) lhs;
2525 if (!containsVariableSet(ref.token)) {
2526 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(),
2527 referenceContext, compilationUnit.compilationResult);
2528 addVariableSet(ref.token);
2533 case TokenNameEQUAL:
2534 if (lhs != null && lhs instanceof FieldReference) {
2535 addVariableSet(((FieldReference) lhs).token);
2538 if (token == TokenNameAND) {
2540 if (token == TokenNamenew) {
2541 // | variable '=' '&' T_NEW class_name_reference
2544 SingleTypeReference classRef = class_name_reference();
2546 if (classRef != null) {
2547 if (lhs != null && lhs instanceof FieldReference) {
2549 // $var = & new Object();
2550 if (fMethodVariables != null) {
2551 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2552 lhsInfo.reference = classRef;
2553 lhsInfo.typeIdentifier = classRef.token;
2554 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2555 rememberedVar = true;
2560 Expression rhs = variable(false, false);
2561 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2564 if (fMethodVariables != null) {
2565 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2566 if (rhsInfo != null && rhsInfo.reference != null) {
2567 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2568 lhsInfo.reference = rhsInfo.reference;
2569 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2570 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2571 rememberedVar = true;
2577 Expression rhs = expr();
2578 if (lhs != null && lhs instanceof FieldReference) {
2579 if (rhs != null && rhs instanceof FieldReference) {
2582 if (fMethodVariables != null) {
2583 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2584 if (rhsInfo != null && rhsInfo.reference != null) {
2585 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2586 lhsInfo.reference = rhsInfo.reference;
2587 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2588 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2589 rememberedVar = true;
2592 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2594 // $var = new Object();
2595 if (fMethodVariables != null) {
2596 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2597 lhsInfo.reference = (SingleTypeReference) rhs;
2598 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2599 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2600 rememberedVar = true;
2605 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2606 if (fMethodVariables != null) {
2607 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2608 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2612 case TokenNamePLUS_EQUAL:
2613 case TokenNameMINUS_EQUAL:
2614 case TokenNameMULTIPLY_EQUAL:
2615 case TokenNameDIVIDE_EQUAL:
2616 case TokenNameDOT_EQUAL:
2617 case TokenNameREMAINDER_EQUAL:
2618 case TokenNameAND_EQUAL:
2619 case TokenNameOR_EQUAL:
2620 case TokenNameXOR_EQUAL:
2621 case TokenNameRIGHT_SHIFT_EQUAL:
2622 case TokenNameLEFT_SHIFT_EQUAL:
2623 if (lhs != null && lhs instanceof FieldReference) {
2624 addVariableSet(((FieldReference) lhs).token);
2629 case TokenNamePLUS_PLUS:
2630 case TokenNameMINUS_MINUS:
2634 if (!only_variable) {
2635 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2643 if (token != TokenNameINLINE_HTML) {
2644 if (token > TokenNameKEYWORD) {
2648 // System.out.println(scanner.getCurrentTokenStartPosition());
2649 // System.out.println(scanner.getCurrentTokenEndPosition());
2651 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2656 if (Scanner.TRACE) {
2657 System.out.println("TRACE: expr_without_variable() PART 2");
2659 // | expr T_BOOLEAN_OR expr
2660 // | expr T_BOOLEAN_AND expr
2661 // | expr T_LOGICAL_OR expr
2662 // | expr T_LOGICAL_AND expr
2663 // | expr T_LOGICAL_XOR expr
2675 // | expr T_IS_IDENTICAL expr
2676 // | expr T_IS_NOT_IDENTICAL expr
2677 // | expr T_IS_EQUAL expr
2678 // | expr T_IS_NOT_EQUAL expr
2680 // | expr T_IS_SMALLER_OR_EQUAL expr
2682 // | expr T_IS_GREATER_OR_EQUAL expr
2685 case TokenNameOR_OR:
2687 expression = new OR_OR_Expression(expression, expr(), token);
2689 case TokenNameAND_AND:
2691 expression = new AND_AND_Expression(expression, expr(), token);
2693 case TokenNameEQUAL_EQUAL:
2695 expression = new EqualExpression(expression, expr(), token);
2705 case TokenNameMINUS:
2706 case TokenNameMULTIPLY:
2707 case TokenNameDIVIDE:
2708 case TokenNameREMAINDER:
2709 case TokenNameLEFT_SHIFT:
2710 case TokenNameRIGHT_SHIFT:
2711 case TokenNameEQUAL_EQUAL_EQUAL:
2712 case TokenNameNOT_EQUAL_EQUAL:
2713 case TokenNameNOT_EQUAL:
2715 case TokenNameLESS_EQUAL:
2716 case TokenNameGREATER:
2717 case TokenNameGREATER_EQUAL:
2719 expression = new BinaryExpression(expression, expr(), token);
2721 // | expr T_INSTANCEOF class_name_reference
2722 // | expr '?' expr ':' expr
2723 case TokenNameinstanceof:
2725 TypeReference classRef = class_name_reference();
2726 if (classRef != null) {
2727 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2728 expression.sourceStart = exprSourceStart;
2729 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2732 case TokenNameQUESTION:
2734 Expression valueIfTrue = expr();
2735 if (token != TokenNameCOLON) {
2736 throwSyntaxError("':' expected in conditional expression.");
2739 Expression valueIfFalse = expr();
2741 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2747 } catch (SyntaxError e) {
2748 // try to find next token after expression with errors:
2749 if (token == TokenNameSEMICOLON) {
2753 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2761 private SingleTypeReference class_name_reference() {
2762 // class_name_reference:
2764 // | dynamic_class_name_reference
2765 SingleTypeReference ref = null;
2766 if (Scanner.TRACE) {
2767 System.out.println("TRACE: class_name_reference()");
2769 if (token == TokenNameIdentifier) {
2770 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2774 dynamic_class_name_reference();
2779 private void dynamic_class_name_reference() {
2780 // dynamic_class_name_reference:
2781 // base_variable T_OBJECT_OPERATOR object_property
2782 // dynamic_class_name_variable_properties
2784 if (Scanner.TRACE) {
2785 System.out.println("TRACE: dynamic_class_name_reference()");
2788 if (token == TokenNameMINUS_GREATER) {
2791 dynamic_class_name_variable_properties();
2795 private void dynamic_class_name_variable_properties() {
2796 // dynamic_class_name_variable_properties:
2797 // dynamic_class_name_variable_properties
2798 // dynamic_class_name_variable_property
2800 if (Scanner.TRACE) {
2801 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2803 while (token == TokenNameMINUS_GREATER) {
2804 dynamic_class_name_variable_property();
2808 private void dynamic_class_name_variable_property() {
2809 // dynamic_class_name_variable_property:
2810 // T_OBJECT_OPERATOR object_property
2811 if (Scanner.TRACE) {
2812 System.out.println("TRACE: dynamic_class_name_variable_property()");
2814 if (token == TokenNameMINUS_GREATER) {
2820 private void ctor_arguments() {
2823 // | '(' function_call_parameter_list ')'
2824 if (token == TokenNameLPAREN) {
2826 if (token == TokenNameRPAREN) {
2830 non_empty_function_call_parameter_list();
2831 if (token != TokenNameRPAREN) {
2832 throwSyntaxError("')' expected in ctor_arguments.");
2838 private void assignment_list() {
2840 // assignment_list ',' assignment_list_element
2841 // | assignment_list_element
2843 assignment_list_element();
2844 if (token != TokenNameCOMMA) {
2851 private void assignment_list_element() {
2852 // assignment_list_element:
2854 // | T_LIST '(' assignment_list ')'
2856 if (token == TokenNameVariable) {
2857 variable(true, false);
2858 } else if (token == TokenNameDOLLAR) {
2859 variable(false, false);
2861 if (token == TokenNamelist) {
2863 if (token == TokenNameLPAREN) {
2866 if (token != TokenNameRPAREN) {
2867 throwSyntaxError("')' expected after 'list' keyword.");
2871 throwSyntaxError("'(' expected after 'list' keyword.");
2877 private void array_pair_list() {
2880 // | non_empty_array_pair_list possible_comma
2881 non_empty_array_pair_list();
2882 if (token == TokenNameCOMMA) {
2887 private void non_empty_array_pair_list() {
2888 // non_empty_array_pair_list:
2889 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2890 // | non_empty_array_pair_list ',' expr
2891 // | expr T_DOUBLE_ARROW expr
2893 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2894 // | non_empty_array_pair_list ',' '&' w_variable
2895 // | expr T_DOUBLE_ARROW '&' w_variable
2898 if (token == TokenNameAND) {
2900 variable(true, false);
2903 if (token == TokenNameAND) {
2905 variable(true, false);
2906 } else if (token == TokenNameEQUAL_GREATER) {
2908 if (token == TokenNameAND) {
2910 variable(true, false);
2916 if (token != TokenNameCOMMA) {
2920 if (token == TokenNameRPAREN) {
2926 // private void variableList() {
2929 // if (token == TokenNameCOMMA) {
2936 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2937 // variable_without_objects:
2938 // reference_variable
2939 // | simple_indirect_reference reference_variable
2940 if (Scanner.TRACE) {
2941 System.out.println("TRACE: variable_without_objects()");
2943 while (token == TokenNameDOLLAR) {
2946 return reference_variable(lefthandside, ignoreVar);
2949 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2951 // T_STRING '(' function_call_parameter_list ')'
2952 // | class_constant '(' function_call_parameter_list ')'
2953 // | static_member '(' function_call_parameter_list ')'
2954 // | variable_without_objects '(' function_call_parameter_list ')'
2955 char[] defineName = null;
2956 char[] ident = null;
2959 Expression ref = null;
2960 if (Scanner.TRACE) {
2961 System.out.println("TRACE: function_call()");
2963 if (token == TokenNameIdentifier) {
2964 ident = scanner.getCurrentIdentifierSource();
2966 startPos = scanner.getCurrentTokenStartPosition();
2967 endPos = scanner.getCurrentTokenEndPosition();
2970 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2974 if (token == TokenNameIdentifier) {
2979 variable_without_objects(true, false);
2984 ref = variable_without_objects(lefthandside, ignoreVar);
2986 if (token != TokenNameLPAREN) {
2987 if (defineName != null) {
2988 // does this identifier contain only uppercase characters?
2989 if (defineName.length == 3) {
2990 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2993 } else if (defineName.length == 4) {
2994 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2996 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2999 } else if (defineName.length == 5) {
3000 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3004 if (defineName != null) {
3005 for (int i = 0; i < defineName.length; i++) {
3006 if (Character.isLowerCase(defineName[i])) {
3007 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3013 // TODO is this ok ?
3015 // throwSyntaxError("'(' expected in function call.");
3018 if (token == TokenNameRPAREN) {
3022 non_empty_function_call_parameter_list();
3023 if (token != TokenNameRPAREN) {
3024 String functionName;
3025 if (ident == null) {
3026 functionName = new String(" ");
3028 functionName = new String(ident);
3030 throwSyntaxError("')' expected in function call (" + functionName + ").");
3036 // private void function_call_parameter_list() {
3037 // function_call_parameter_list:
3038 // non_empty_function_call_parameter_list { $$ = $1; }
3041 private void non_empty_function_call_parameter_list() {
3042 // non_empty_function_call_parameter_list:
3043 // expr_without_variable
3046 // | non_empty_function_call_parameter_list ',' expr_without_variable
3047 // | non_empty_function_call_parameter_list ',' variable
3048 // | non_empty_function_call_parameter_list ',' '&' w_variable
3049 if (Scanner.TRACE) {
3050 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3053 if (token == TokenNameAND) {
3057 // if (token == TokenNameIdentifier || token ==
3058 // TokenNameVariable
3059 // || token == TokenNameDOLLAR) {
3062 expr_without_variable(true);
3065 if (token != TokenNameCOMMA) {
3072 private void fully_qualified_class_name() {
3073 if (token == TokenNameIdentifier) {
3076 throwSyntaxError("Class name expected.");
3080 private void static_member() {
3082 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3083 // variable_without_objects
3084 if (Scanner.TRACE) {
3085 System.out.println("TRACE: static_member()");
3087 fully_qualified_class_name();
3088 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3089 throwSyntaxError("'::' expected after class name (static_member).");
3092 variable_without_objects(false, false);
3095 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3096 // base_variable_with_function_calls:
3099 if (Scanner.TRACE) {
3100 System.out.println("TRACE: base_variable_with_function_calls()");
3102 return function_call(lefthandside, ignoreVar);
3105 private Expression base_variable() {
3107 // reference_variable
3108 // | simple_indirect_reference reference_variable
3110 Expression ref = null;
3111 if (Scanner.TRACE) {
3112 System.out.println("TRACE: base_variable()");
3114 if (token == TokenNameIdentifier) {
3117 while (token == TokenNameDOLLAR) {
3120 reference_variable(false, false);
3125 // private void simple_indirect_reference() {
3126 // // simple_indirect_reference:
3128 // //| simple_indirect_reference '$'
3130 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3131 // reference_variable:
3132 // reference_variable '[' dim_offset ']'
3133 // | reference_variable '{' expr '}'
3134 // | compound_variable
3135 Expression ref = null;
3136 if (Scanner.TRACE) {
3137 System.out.println("TRACE: reference_variable()");
3139 ref = compound_variable(lefthandside, ignoreVar);
3141 if (token == TokenNameLBRACE) {
3145 if (token != TokenNameRBRACE) {
3146 throwSyntaxError("'}' expected in reference variable.");
3149 } else if (token == TokenNameLBRACKET) {
3150 if (ref != null && ref instanceof FieldReference) {
3151 FieldReference fref = (FieldReference) ref;
3152 addVariableSet(fref.token);
3156 if (token != TokenNameRBRACKET) {
3159 if (token != TokenNameRBRACKET) {
3160 throwSyntaxError("']' expected in reference variable.");
3171 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3172 // compound_variable:
3174 // | '$' '{' expr '}'
3175 if (Scanner.TRACE) {
3176 System.out.println("TRACE: compound_variable()");
3178 if (token == TokenNameVariable) {
3179 if (!lefthandside) {
3180 if (!containsVariableSet()) {
3181 // reportSyntaxError("The local variable " + new
3182 // String(scanner.getCurrentIdentifierSource())
3183 // + " may not have been initialized");
3184 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3185 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3186 compilationUnit.compilationResult);
3193 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3197 // because of simple_indirect_reference
3198 while (token == TokenNameDOLLAR) {
3201 if (token != TokenNameLBRACE) {
3202 reportSyntaxError("'{' expected after compound variable token '$'.");
3207 if (token != TokenNameRBRACE) {
3208 throwSyntaxError("'}' expected after compound variable token '$'.");
3213 } // private void dim_offset() { // // dim_offset: // // /* empty */
3218 private void object_property() {
3221 // | variable_without_objects
3222 if (Scanner.TRACE) {
3223 System.out.println("TRACE: object_property()");
3225 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3226 variable_without_objects(false, false);
3232 private void object_dim_list() {
3234 // object_dim_list '[' dim_offset ']'
3235 // | object_dim_list '{' expr '}'
3237 if (Scanner.TRACE) {
3238 System.out.println("TRACE: object_dim_list()");
3242 if (token == TokenNameLBRACE) {
3245 if (token != TokenNameRBRACE) {
3246 throwSyntaxError("'}' expected in object_dim_list.");
3249 } else if (token == TokenNameLBRACKET) {
3251 if (token == TokenNameRBRACKET) {
3256 if (token != TokenNameRBRACKET) {
3257 throwSyntaxError("']' expected in object_dim_list.");
3266 private void variable_name() {
3270 if (Scanner.TRACE) {
3271 System.out.println("TRACE: variable_name()");
3273 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3274 if (token > TokenNameKEYWORD) {
3275 // TODO show a warning "Keyword used as variable" ?
3279 if (token != TokenNameLBRACE) {
3280 throwSyntaxError("'{' expected in variable name.");
3284 if (token != TokenNameRBRACE) {
3285 throwSyntaxError("'}' expected in variable name.");
3291 private void r_variable() {
3292 variable(false, false);
3295 private void w_variable(boolean lefthandside) {
3296 variable(lefthandside, false);
3299 private void rw_variable() {
3300 variable(false, false);
3303 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3305 // base_variable_with_function_calls T_OBJECT_OPERATOR
3306 // object_property method_or_not variable_properties
3307 // | base_variable_with_function_calls
3308 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3309 if (token == TokenNameMINUS_GREATER) {
3314 variable_properties();
3319 private void variable_properties() {
3320 // variable_properties:
3321 // variable_properties variable_property
3323 while (token == TokenNameMINUS_GREATER) {
3324 variable_property();
3328 private void variable_property() {
3329 // variable_property:
3330 // T_OBJECT_OPERATOR object_property method_or_not
3331 if (Scanner.TRACE) {
3332 System.out.println("TRACE: variable_property()");
3334 if (token == TokenNameMINUS_GREATER) {
3339 throwSyntaxError("'->' expected in variable_property.");
3343 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3345 // base_variable_with_function_calls T_OBJECT_OPERATOR
3346 // object_property method_or_not variable_properties
3347 // | base_variable_with_function_calls
3349 // Expression ref = function_call(lefthandside, ignoreVar);
3352 // T_STRING '(' function_call_parameter_list ')'
3353 // | class_constant '(' function_call_parameter_list ')'
3354 // | static_member '(' function_call_parameter_list ')'
3355 // | variable_without_objects '(' function_call_parameter_list ')'
3356 char[] defineName = null;
3357 char[] ident = null;
3360 Expression ref = null;
3361 if (Scanner.TRACE) {
3362 System.out.println("TRACE: function_call()");
3364 if (token == TokenNameIdentifier) {
3365 ident = scanner.getCurrentIdentifierSource();
3367 startPos = scanner.getCurrentTokenStartPosition();
3368 endPos = scanner.getCurrentTokenEndPosition();
3371 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3372 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3373 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3374 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3375 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3376 + new String(ident) + "' (use 'define(...)' to define constants).";
3377 reportSyntaxError(error);
3381 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3385 if (token == TokenNameIdentifier) {
3390 variable_without_objects(true, false);
3395 ref = variable_without_objects(lefthandside, ignoreVar);
3397 if (token != TokenNameLPAREN) {
3398 if (defineName != null) {
3399 // does this identifier contain only uppercase characters?
3400 if (defineName.length == 3) {
3401 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3404 } else if (defineName.length == 4) {
3405 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3407 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3410 } else if (defineName.length == 5) {
3411 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3415 if (defineName != null) {
3416 for (int i = 0; i < defineName.length; i++) {
3417 if (Character.isLowerCase(defineName[i])) {
3418 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3424 // TODO is this ok ?
3426 // throwSyntaxError("'(' expected in function call.");
3429 if (token == TokenNameRPAREN) {
3433 non_empty_function_call_parameter_list();
3434 if (token != TokenNameRPAREN) {
3435 String functionName;
3436 if (ident == null) {
3437 functionName = new String(" ");
3439 functionName = new String(ident);
3441 throwSyntaxError("')' expected in function call (" + functionName + ").");
3445 if (token == TokenNameMINUS_GREATER) {
3450 variable_properties();
3455 private void method_or_not() {
3457 // '(' function_call_parameter_list ')'
3459 if (Scanner.TRACE) {
3460 System.out.println("TRACE: method_or_not()");
3462 if (token == TokenNameLPAREN) {
3464 if (token == TokenNameRPAREN) {
3468 non_empty_function_call_parameter_list();
3469 if (token != TokenNameRPAREN) {
3470 throwSyntaxError("')' expected in method_or_not.");
3476 private void exit_expr() {
3480 if (token != TokenNameLPAREN) {
3484 if (token == TokenNameRPAREN) {
3489 if (token != TokenNameRPAREN) {
3490 throwSyntaxError("')' expected after keyword 'exit'");
3495 // private void encaps_list() {
3496 // // encaps_list encaps_var
3497 // // | encaps_list T_STRING
3498 // // | encaps_list T_NUM_STRING
3499 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3500 // // | encaps_list T_CHARACTER
3501 // // | encaps_list T_BAD_CHARACTER
3502 // // | encaps_list '['
3503 // // | encaps_list ']'
3504 // // | encaps_list '{'
3505 // // | encaps_list '}'
3506 // // | encaps_list T_OBJECT_OPERATOR
3510 // case TokenNameSTRING:
3513 // case TokenNameLBRACE:
3514 // // scanner.encapsedStringStack.pop();
3517 // case TokenNameRBRACE:
3518 // // scanner.encapsedStringStack.pop();
3521 // case TokenNameLBRACKET:
3522 // // scanner.encapsedStringStack.pop();
3525 // case TokenNameRBRACKET:
3526 // // scanner.encapsedStringStack.pop();
3529 // case TokenNameMINUS_GREATER:
3530 // // scanner.encapsedStringStack.pop();
3533 // case TokenNameVariable:
3534 // case TokenNameDOLLAR_LBRACE:
3535 // case TokenNameLBRACE_DOLLAR:
3539 // char encapsedChar = ((Character)
3540 // scanner.encapsedStringStack.peek()).charValue();
3541 // if (encapsedChar == '$') {
3542 // scanner.encapsedStringStack.pop();
3543 // encapsedChar = ((Character)
3544 // scanner.encapsedStringStack.peek()).charValue();
3545 // switch (encapsedChar) {
3547 // if (token == TokenNameEncapsedString0) {
3550 // token = TokenNameSTRING;
3553 // if (token == TokenNameEncapsedString1) {
3556 // token = TokenNameSTRING;
3559 // if (token == TokenNameEncapsedString2) {
3562 // token = TokenNameSTRING;
3571 // private void encaps_var() {
3573 // // | T_VARIABLE '[' encaps_var_offset ']'
3574 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3575 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3576 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3577 // // | T_CURLY_OPEN variable '}'
3579 // case TokenNameVariable:
3581 // if (token == TokenNameLBRACKET) {
3583 // expr(); //encaps_var_offset();
3584 // if (token != TokenNameRBRACKET) {
3585 // throwSyntaxError("']' expected after variable.");
3587 // // scanner.encapsedStringStack.pop();
3590 // } else if (token == TokenNameMINUS_GREATER) {
3592 // if (token != TokenNameIdentifier) {
3593 // throwSyntaxError("Identifier expected after '->'.");
3595 // // scanner.encapsedStringStack.pop();
3599 // // // scanner.encapsedStringStack.pop();
3600 // // int tempToken = TokenNameSTRING;
3601 // // if (!scanner.encapsedStringStack.isEmpty()
3602 // // && (token == TokenNameEncapsedString0
3603 // // || token == TokenNameEncapsedString1
3604 // // || token == TokenNameEncapsedString2 || token ==
3605 // // TokenNameERROR)) {
3606 // // char encapsedChar = ((Character)
3607 // // scanner.encapsedStringStack.peek())
3609 // // switch (token) {
3610 // // case TokenNameEncapsedString0 :
3611 // // if (encapsedChar == '`') {
3612 // // tempToken = TokenNameEncapsedString0;
3615 // // case TokenNameEncapsedString1 :
3616 // // if (encapsedChar == '\'') {
3617 // // tempToken = TokenNameEncapsedString1;
3620 // // case TokenNameEncapsedString2 :
3621 // // if (encapsedChar == '"') {
3622 // // tempToken = TokenNameEncapsedString2;
3625 // // case TokenNameERROR :
3626 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3627 // // scanner.currentPosition--;
3628 // // getNextToken();
3633 // // token = tempToken;
3636 // case TokenNameDOLLAR_LBRACE:
3638 // if (token == TokenNameDOLLAR_LBRACE) {
3640 // } else if (token == TokenNameIdentifier) {
3642 // if (token == TokenNameLBRACKET) {
3644 // // if (token == TokenNameRBRACKET) {
3645 // // getNextToken();
3648 // if (token != TokenNameRBRACKET) {
3649 // throwSyntaxError("']' expected after '${'.");
3657 // if (token != TokenNameRBRACE) {
3658 // throwSyntaxError("'}' expected.");
3662 // case TokenNameLBRACE_DOLLAR:
3664 // if (token == TokenNameLBRACE_DOLLAR) {
3666 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3668 // if (token == TokenNameLBRACKET) {
3670 // // if (token == TokenNameRBRACKET) {
3671 // // getNextToken();
3674 // if (token != TokenNameRBRACKET) {
3675 // throwSyntaxError("']' expected.");
3679 // } else if (token == TokenNameMINUS_GREATER) {
3681 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3682 // throwSyntaxError("String or Variable token expected.");
3685 // if (token == TokenNameLBRACKET) {
3687 // // if (token == TokenNameRBRACKET) {
3688 // // getNextToken();
3691 // if (token != TokenNameRBRACKET) {
3692 // throwSyntaxError("']' expected after '${'.");
3698 // // if (token != TokenNameRBRACE) {
3699 // // throwSyntaxError("'}' expected after '{$'.");
3701 // // // scanner.encapsedStringStack.pop();
3702 // // getNextToken();
3705 // if (token != TokenNameRBRACE) {
3706 // throwSyntaxError("'}' expected.");
3708 // // scanner.encapsedStringStack.pop();
3715 // private void encaps_var_offset() {
3717 // // | T_NUM_STRING
3720 // case TokenNameSTRING:
3723 // case TokenNameIntegerLiteral:
3726 // case TokenNameVariable:
3729 // case TokenNameIdentifier:
3733 // throwSyntaxError("Variable or String token expected.");
3738 private void internal_functions_in_yacc() {
3741 // case TokenNameisset:
3742 // // T_ISSET '(' isset_variables ')'
3744 // if (token != TokenNameLPAREN) {
3745 // throwSyntaxError("'(' expected after keyword 'isset'");
3748 // isset_variables();
3749 // if (token != TokenNameRPAREN) {
3750 // throwSyntaxError("')' expected after keyword 'isset'");
3754 // case TokenNameempty:
3755 // // T_EMPTY '(' variable ')'
3757 // if (token != TokenNameLPAREN) {
3758 // throwSyntaxError("'(' expected after keyword 'empty'");
3762 // if (token != TokenNameRPAREN) {
3763 // throwSyntaxError("')' expected after keyword 'empty'");
3767 case TokenNameinclude:
3769 checkFileName(token);
3771 case TokenNameinclude_once:
3772 // T_INCLUDE_ONCE expr
3773 checkFileName(token);
3776 // T_EVAL '(' expr ')'
3778 if (token != TokenNameLPAREN) {
3779 throwSyntaxError("'(' expected after keyword 'eval'");
3783 if (token != TokenNameRPAREN) {
3784 throwSyntaxError("')' expected after keyword 'eval'");
3788 case TokenNamerequire:
3790 checkFileName(token);
3792 case TokenNamerequire_once:
3793 // T_REQUIRE_ONCE expr
3794 checkFileName(token);
3800 * Parse and check the include file name
3802 * @param includeToken
3804 private void checkFileName(int includeToken) {
3805 // <include-token> expr
3806 int start = scanner.getCurrentTokenStartPosition();
3807 boolean hasLPAREN = false;
3809 if (token == TokenNameLPAREN) {
3813 Expression expression = expr();
3815 if (token == TokenNameRPAREN) {
3818 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3821 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3823 if (scanner.compilationUnit != null) {
3824 IResource resource = scanner.compilationUnit.getResource();
3825 if (resource != null && resource instanceof IFile) {
3826 file = (IFile) resource;
3830 tokens = new char[1][];
3831 tokens[0] = currTokenSource;
3833 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3834 impt.declarationSourceEnd = impt.sourceEnd;
3835 impt.declarationEnd = impt.declarationSourceEnd;
3836 // endPosition is just before the ;
3837 impt.declarationSourceStart = start;
3838 includesList.add(impt);
3840 if (expression instanceof StringLiteral) {
3841 StringLiteral literal = (StringLiteral) expression;
3842 char[] includeName = literal.source();
3843 if (includeName.length == 0) {
3844 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3845 literal.sourceStart + 1);
3847 String includeNameString = new String(includeName);
3848 if (literal instanceof StringLiteralDQ) {
3849 if (includeNameString.indexOf('$') >= 0) {
3850 // assuming that the filename contains a variable => no filename check
3854 if (includeNameString.startsWith("http://")) {
3855 // assuming external include location
3859 // check the filename:
3860 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3861 // expression.toStringExpression());
3862 IProject project = file.getProject();
3863 if (project != null) {
3864 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3867 // SyntaxError: "File: << >> doesn't exist in project."
3868 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3869 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3870 compilationUnit.compilationResult);
3873 String filePath = path.toString();
3874 String ext = file.getRawLocation().getFileExtension();
3875 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3877 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3878 impt.setFile(PHPFileUtil.createFile(path, project));
3879 } catch (Exception e) {
3880 // the file is outside of the workspace
3888 private void isset_variables() {
3890 // | isset_variables ','
3891 if (token == TokenNameRPAREN) {
3892 throwSyntaxError("Variable expected after keyword 'isset'");
3895 variable(true, false);
3896 if (token == TokenNameCOMMA) {
3904 private boolean common_scalar() {
3908 // | T_CONSTANT_ENCAPSED_STRING
3915 case TokenNameIntegerLiteral:
3918 case TokenNameDoubleLiteral:
3921 case TokenNameStringDoubleQuote:
3924 case TokenNameStringSingleQuote:
3927 case TokenNameStringInterpolated:
3936 case TokenNameCLASS_C:
3939 case TokenNameMETHOD_C:
3942 case TokenNameFUNC_C:
3949 private void scalar() {
3952 // | T_STRING_VARNAME
3955 // | '"' encaps_list '"'
3956 // | '\'' encaps_list '\''
3957 // | T_START_HEREDOC encaps_list T_END_HEREDOC
3958 throwSyntaxError("Not yet implemented (scalar).");
3961 private void static_scalar() {
3962 // static_scalar: /* compile-time evaluated scalars */
3965 // | '+' static_scalar
3966 // | '-' static_scalar
3967 // | T_ARRAY '(' static_array_pair_list ')'
3968 // | static_class_constant
3969 if (common_scalar()) {
3973 case TokenNameIdentifier:
3975 // static_class_constant:
3976 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3977 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3979 if (token == TokenNameIdentifier) {
3982 throwSyntaxError("Identifier expected after '::' operator.");
3986 case TokenNameEncapsedString0:
3988 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3989 while (scanner.currentCharacter != '`') {
3990 if (scanner.currentCharacter == '\\') {
3991 scanner.currentPosition++;
3993 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3996 } catch (IndexOutOfBoundsException e) {
3997 throwSyntaxError("'`' expected at end of static string.");
4000 // case TokenNameEncapsedString1:
4002 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4003 // while (scanner.currentCharacter != '\'') {
4004 // if (scanner.currentCharacter == '\\') {
4005 // scanner.currentPosition++;
4007 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4010 // } catch (IndexOutOfBoundsException e) {
4011 // throwSyntaxError("'\'' expected at end of static string.");
4014 // case TokenNameEncapsedString2:
4016 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4017 // while (scanner.currentCharacter != '"') {
4018 // if (scanner.currentCharacter == '\\') {
4019 // scanner.currentPosition++;
4021 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4024 // } catch (IndexOutOfBoundsException e) {
4025 // throwSyntaxError("'\"' expected at end of static string.");
4028 case TokenNameStringSingleQuote:
4031 case TokenNameStringDoubleQuote:
4038 case TokenNameMINUS:
4042 case TokenNamearray:
4044 if (token != TokenNameLPAREN) {
4045 throwSyntaxError("'(' expected after keyword 'array'");
4048 if (token == TokenNameRPAREN) {
4052 non_empty_static_array_pair_list();
4053 if (token != TokenNameRPAREN) {
4054 throwSyntaxError("')' or ',' expected after keyword 'array'");
4058 // case TokenNamenull :
4061 // case TokenNamefalse :
4064 // case TokenNametrue :
4068 throwSyntaxError("Static scalar/constant expected.");
4072 private void non_empty_static_array_pair_list() {
4073 // non_empty_static_array_pair_list:
4074 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4076 // | non_empty_static_array_pair_list ',' static_scalar
4077 // | static_scalar T_DOUBLE_ARROW static_scalar
4081 if (token == TokenNameEQUAL_GREATER) {
4085 if (token != TokenNameCOMMA) {
4089 if (token == TokenNameRPAREN) {
4095 // public void reportSyntaxError() { //int act, int currentKind, int
4096 // // stateStackTop) {
4097 // /* remember current scanner position */
4098 // int startPos = scanner.startPosition;
4099 // int currentPos = scanner.currentPosition;
4101 // this.checkAndReportBracketAnomalies(problemReporter());
4102 // /* reset scanner where it was */
4103 // scanner.startPosition = startPos;
4104 // scanner.currentPosition = currentPos;
4107 public static final int RoundBracket = 0;
4109 public static final int SquareBracket = 1;
4111 public static final int CurlyBracket = 2;
4113 public static final int BracketKinds = 3;
4115 protected int[] nestedMethod; // the ptr is nestedType
4117 protected int nestedType, dimensions;
4119 // variable set stack
4120 final static int VariableStackIncrement = 10;
4122 HashMap fTypeVariables = null;
4124 HashMap fMethodVariables = null;
4126 ArrayList fStackUnassigned = new ArrayList();
4129 final static int AstStackIncrement = 100;
4131 protected int astPtr;
4133 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4135 protected int astLengthPtr;
4137 protected int[] astLengthStack;
4139 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4141 public CompilationUnitDeclaration compilationUnit; /*
4142 * the result from parse()
4145 protected ReferenceContext referenceContext;
4147 protected ProblemReporter problemReporter;
4149 protected CompilerOptions options;
4151 private ArrayList includesList;
4153 // protected CompilationResult compilationResult;
4155 * Returns this parser's problem reporter initialized with its reference
4156 * context. Also it is assumed that a problem is going to be reported, so
4157 * initializes the compilation result's line positions.
4159 public ProblemReporter problemReporter() {
4160 if (scanner.recordLineSeparator) {
4161 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4163 problemReporter.referenceContext = referenceContext;
4164 return problemReporter;
4168 * Reconsider the entire source looking for inconsistencies in {} () []
4170 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4171 // problemReporter) {
4172 // scanner.wasAcr = false;
4173 // boolean anomaliesDetected = false;
4175 // char[] source = scanner.source;
4176 // int[] leftCount = { 0, 0, 0 };
4177 // int[] rightCount = { 0, 0, 0 };
4178 // int[] depths = { 0, 0, 0 };
4179 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4181 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4182 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4184 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4186 // scanner.currentPosition = scanner.initialPosition; //starting
4188 // // (first-zero-based
4190 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4195 // // ---------Consume white space and handles
4196 // // startPosition---------
4197 // boolean isWhiteSpace;
4199 // scanner.startPosition = scanner.currentPosition;
4200 // // if (((scanner.currentCharacter =
4201 // // source[scanner.currentPosition++]) == '\\') &&
4202 // // (source[scanner.currentPosition] == 'u')) {
4203 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4205 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4206 // (scanner.currentCharacter == '\n'))) {
4207 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4208 // // only record line positions we have not
4210 // scanner.pushLineSeparator();
4213 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4215 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4216 // // -------consume token until } is found---------
4217 // switch (scanner.currentCharacter) {
4219 // int index = leftCount[CurlyBracket]++;
4220 // if (index == leftPositions[CurlyBracket].length) {
4221 // System.arraycopy(leftPositions[CurlyBracket], 0,
4222 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4223 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4224 // new int[index * 2]), 0, index);
4226 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4227 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4231 // int index = rightCount[CurlyBracket]++;
4232 // if (index == rightPositions[CurlyBracket].length) {
4233 // System.arraycopy(rightPositions[CurlyBracket], 0,
4234 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4235 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4236 // new int[index * 2]), 0, index);
4238 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4239 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4243 // int index = leftCount[RoundBracket]++;
4244 // if (index == leftPositions[RoundBracket].length) {
4245 // System.arraycopy(leftPositions[RoundBracket], 0,
4246 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4247 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4248 // new int[index * 2]), 0, index);
4250 // leftPositions[RoundBracket][index] = scanner.startPosition;
4251 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4255 // int index = rightCount[RoundBracket]++;
4256 // if (index == rightPositions[RoundBracket].length) {
4257 // System.arraycopy(rightPositions[RoundBracket], 0,
4258 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4259 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4260 // new int[index * 2]), 0, index);
4262 // rightPositions[RoundBracket][index] = scanner.startPosition;
4263 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4267 // int index = leftCount[SquareBracket]++;
4268 // if (index == leftPositions[SquareBracket].length) {
4269 // System.arraycopy(leftPositions[SquareBracket], 0,
4270 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4271 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4272 // new int[index * 2]), 0, index);
4274 // leftPositions[SquareBracket][index] = scanner.startPosition;
4275 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4279 // int index = rightCount[SquareBracket]++;
4280 // if (index == rightPositions[SquareBracket].length) {
4281 // System.arraycopy(rightPositions[SquareBracket], 0,
4282 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4283 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4284 // = new int[index * 2]), 0, index);
4286 // rightPositions[SquareBracket][index] = scanner.startPosition;
4287 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4291 // if (scanner.getNextChar('\\')) {
4292 // scanner.scanEscapeCharacter();
4293 // } else { // consume next character
4294 // scanner.unicodeAsBackSlash = false;
4295 // // if (((scanner.currentCharacter =
4296 // // source[scanner.currentPosition++]) ==
4298 // // (source[scanner.currentPosition] ==
4300 // // scanner.getNextUnicodeChar();
4302 // if (scanner.withoutUnicodePtr != 0) {
4303 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4304 // scanner.currentCharacter;
4308 // scanner.getNextChar('\'');
4312 // // consume next character
4313 // scanner.unicodeAsBackSlash = false;
4314 // // if (((scanner.currentCharacter =
4315 // // source[scanner.currentPosition++]) == '\\') &&
4316 // // (source[scanner.currentPosition] == 'u')) {
4317 // // scanner.getNextUnicodeChar();
4319 // if (scanner.withoutUnicodePtr != 0) {
4320 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4321 // scanner.currentCharacter;
4324 // while (scanner.currentCharacter != '"') {
4325 // if (scanner.currentCharacter == '\r') {
4326 // if (source[scanner.currentPosition] == '\n')
4327 // scanner.currentPosition++;
4328 // break; // the string cannot go further that
4331 // if (scanner.currentCharacter == '\n') {
4332 // break; // the string cannot go further that
4335 // if (scanner.currentCharacter == '\\') {
4336 // scanner.scanEscapeCharacter();
4338 // // consume next character
4339 // scanner.unicodeAsBackSlash = false;
4340 // // if (((scanner.currentCharacter =
4341 // // source[scanner.currentPosition++]) == '\\')
4342 // // && (source[scanner.currentPosition] == 'u'))
4344 // // scanner.getNextUnicodeChar();
4346 // if (scanner.withoutUnicodePtr != 0) {
4347 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4348 // scanner.currentCharacter;
4355 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4357 // //get the next char
4358 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4360 // && (source[scanner.currentPosition] == 'u')) {
4361 // //-------------unicode traitement
4363 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4364 // scanner.currentPosition++;
4365 // while (source[scanner.currentPosition] == 'u') {
4366 // scanner.currentPosition++;
4368 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4370 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4372 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4374 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4375 // || c4 < 0) { //error
4379 // scanner.currentCharacter = 'A';
4380 // } //something different from \n and \r
4382 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4385 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4387 // //get the next char
4388 // scanner.startPosition = scanner.currentPosition;
4389 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4391 // && (source[scanner.currentPosition] == 'u')) {
4392 // //-------------unicode traitement
4394 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4395 // scanner.currentPosition++;
4396 // while (source[scanner.currentPosition] == 'u') {
4397 // scanner.currentPosition++;
4399 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4401 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4403 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4405 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4406 // || c4 < 0) { //error
4410 // scanner.currentCharacter = 'A';
4411 // } //something different from \n
4414 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4418 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4419 // (scanner.currentCharacter == '\n'))) {
4420 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4421 // // only record line positions we
4422 // // have not recorded yet
4423 // scanner.pushLineSeparator();
4424 // if (this.scanner.taskTags != null) {
4425 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4427 // .getCurrentTokenEndPosition());
4433 // if (test > 0) { //traditional and annotation
4435 // boolean star = false;
4436 // // consume next character
4437 // scanner.unicodeAsBackSlash = false;
4438 // // if (((scanner.currentCharacter =
4439 // // source[scanner.currentPosition++]) ==
4441 // // (source[scanner.currentPosition] ==
4443 // // scanner.getNextUnicodeChar();
4445 // if (scanner.withoutUnicodePtr != 0) {
4446 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4447 // scanner.currentCharacter;
4450 // if (scanner.currentCharacter == '*') {
4453 // //get the next char
4454 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4456 // && (source[scanner.currentPosition] == 'u')) {
4457 // //-------------unicode traitement
4459 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4460 // scanner.currentPosition++;
4461 // while (source[scanner.currentPosition] == 'u') {
4462 // scanner.currentPosition++;
4464 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4466 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4468 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4470 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4471 // || c4 < 0) { //error
4475 // scanner.currentCharacter = 'A';
4476 // } //something different from * and /
4478 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4481 // //loop until end of comment */
4482 // while ((scanner.currentCharacter != '/') || (!star)) {
4483 // star = scanner.currentCharacter == '*';
4485 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4487 // && (source[scanner.currentPosition] == 'u')) {
4488 // //-------------unicode traitement
4490 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4491 // scanner.currentPosition++;
4492 // while (source[scanner.currentPosition] == 'u') {
4493 // scanner.currentPosition++;
4495 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4497 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4499 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4501 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4502 // || c4 < 0) { //error
4506 // scanner.currentCharacter = 'A';
4507 // } //something different from * and
4510 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4514 // if (this.scanner.taskTags != null) {
4515 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4516 // this.scanner.getCurrentTokenEndPosition());
4523 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4524 // scanner.scanIdentifierOrKeyword(false);
4527 // if (Character.isDigit(scanner.currentCharacter)) {
4528 // scanner.scanNumber(false);
4532 // //-----------------end switch while
4533 // // try--------------------
4534 // } catch (IndexOutOfBoundsException e) {
4535 // break; // read until EOF
4536 // } catch (InvalidInputException e) {
4537 // return false; // no clue
4540 // if (scanner.recordLineSeparator) {
4541 // compilationUnit.compilationResult.lineSeparatorPositions =
4542 // scanner.getLineEnds();
4544 // // check placement anomalies against other kinds of brackets
4545 // for (int kind = 0; kind < BracketKinds; kind++) {
4546 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4547 // int start = leftPositions[kind][leftIndex]; // deepest
4549 // // find matching closing bracket
4550 // int depth = leftDepths[kind][leftIndex];
4552 // for (int i = 0; i < rightCount[kind]; i++) {
4553 // int pos = rightPositions[kind][i];
4554 // // want matching bracket further in source with same
4556 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4561 // if (end < 0) { // did not find a good closing match
4562 // problemReporter.unmatchedBracket(start, referenceContext,
4563 // compilationUnit.compilationResult);
4566 // // check if even number of opening/closing other brackets
4567 // // in between this pair of brackets
4569 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4571 // for (int i = 0; i < leftCount[otherKind]; i++) {
4572 // int pos = leftPositions[otherKind][i];
4573 // if ((pos > start) && (pos < end))
4576 // for (int i = 0; i < rightCount[otherKind]; i++) {
4577 // int pos = rightPositions[otherKind][i];
4578 // if ((pos > start) && (pos < end))
4581 // if (balance != 0) {
4582 // problemReporter.unmatchedBracket(start, referenceContext,
4583 // compilationUnit.compilationResult); //bracket
4589 // // too many opening brackets ?
4590 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4591 // anomaliesDetected = true;
4592 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4593 // 1], referenceContext,
4594 // compilationUnit.compilationResult);
4596 // // too many closing brackets ?
4597 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4598 // anomaliesDetected = true;
4599 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4600 // compilationUnit.compilationResult);
4602 // if (anomaliesDetected)
4605 // return anomaliesDetected;
4606 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4607 // return anomaliesDetected;
4608 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4609 // return anomaliesDetected;
4612 protected void pushOnAstLengthStack(int pos) {
4614 astLengthStack[++astLengthPtr] = pos;
4615 } catch (IndexOutOfBoundsException e) {
4616 int oldStackLength = astLengthStack.length;
4617 int[] oldPos = astLengthStack;
4618 astLengthStack = new int[oldStackLength + StackIncrement];
4619 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4620 astLengthStack[astLengthPtr] = pos;
4624 protected void pushOnAstStack(ASTNode node) {
4626 * add a new obj on top of the ast stack
4629 astStack[++astPtr] = node;
4630 } catch (IndexOutOfBoundsException e) {
4631 int oldStackLength = astStack.length;
4632 ASTNode[] oldStack = astStack;
4633 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4634 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4635 astPtr = oldStackLength;
4636 astStack[astPtr] = node;
4639 astLengthStack[++astLengthPtr] = 1;
4640 } catch (IndexOutOfBoundsException e) {
4641 int oldStackLength = astLengthStack.length;
4642 int[] oldPos = astLengthStack;
4643 astLengthStack = new int[oldStackLength + AstStackIncrement];
4644 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4645 astLengthStack[astLengthPtr] = 1;
4649 protected void resetModifiers() {
4650 this.modifiers = AccDefault;
4651 this.modifiersSourceStart = -1; // <-- see comment into
4652 // modifiersFlag(int)
4653 this.scanner.commentPtr = -1;
4656 protected void consumePackageDeclarationName(IFile file) {
4657 // create a package name similar to java package names
4658 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4659 String filePath = file.getRawLocation().toString();
4660 String ext = file.getRawLocation().getFileExtension();
4661 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4662 ImportReference impt;
4664 if (filePath.startsWith(projectPath)) {
4665 tokens = CharOperation
4666 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4668 String name = file.getName();
4669 tokens = new char[1][];
4670 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4673 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4675 impt.declarationSourceStart = 0;
4676 impt.declarationSourceEnd = 0;
4677 impt.declarationEnd = 0;
4678 // endPosition is just before the ;
4682 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4683 "$_SESSION", "$_SERVER" };
4688 private void pushFunctionVariableSet() {
4689 HashSet set = new HashSet();
4690 if (fStackUnassigned.isEmpty()) {
4691 for (int i = 0; i < GLOBALS.length; i++) {
4692 set.add(GLOBALS[i]);
4695 fStackUnassigned.add(set);
4698 private void pushIfVariableSet() {
4699 if (!fStackUnassigned.isEmpty()) {
4700 HashSet set = new HashSet();
4701 fStackUnassigned.add(set);
4705 private HashSet removeIfVariableSet() {
4706 if (!fStackUnassigned.isEmpty()) {
4707 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4713 * Returns the <i>set of assigned variables </i> returns null if no Set is
4714 * defined at the current scanner position
4716 private HashSet peekVariableSet() {
4717 if (!fStackUnassigned.isEmpty()) {
4718 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4724 * add the current identifier source to the <i>set of assigned variables </i>
4728 private void addVariableSet(HashSet set) {
4730 set.add(new String(scanner.getCurrentTokenSource()));
4735 * add the current identifier source to the <i>set of assigned variables </i>
4738 private void addVariableSet() {
4739 HashSet set = peekVariableSet();
4741 set.add(new String(scanner.getCurrentTokenSource()));
4746 * add the current identifier source to the <i>set of assigned variables </i>
4749 private void addVariableSet(char[] token) {
4750 HashSet set = peekVariableSet();
4752 set.add(new String(token));
4757 * check if the current identifier source is in the <i>set of assigned
4758 * variables </i> Returns true, if no set is defined for the current scanner
4762 private boolean containsVariableSet() {
4763 return containsVariableSet(scanner.getCurrentTokenSource());
4766 private boolean containsVariableSet(char[] token) {
4768 if (!fStackUnassigned.isEmpty()) {
4770 String str = new String(token);
4771 for (int i = 0; i < fStackUnassigned.size(); i++) {
4772 set = (HashSet) fStackUnassigned.get(i);
4773 if (set.contains(str)) {