1 /***********************************************************************************************************************************
2 * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3 * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
18 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
19 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
20 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
21 import net.sourceforge.phpdt.internal.compiler.ast.Block;
22 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
23 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
24 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
26 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
27 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
28 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
30 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
31 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
32 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
35 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
36 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
37 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
39 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
44 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
45 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
46 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
47 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
48 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
49 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
50 import net.sourceforge.phpdt.internal.compiler.util.Util;
51 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
52 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
53 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
55 import org.eclipse.core.resources.IFile;
56 import org.eclipse.core.resources.IProject;
57 import org.eclipse.core.resources.IResource;
58 import org.eclipse.core.runtime.IPath;
60 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
61 protected final static int StackIncrement = 255;
63 protected int stateStackTop;
65 // protected int[] stack = new int[StackIncrement];
67 public int firstToken; // handle for multiple parsing goals
69 public int lastAct; // handle for multiple parsing goals
71 // protected RecoveredElement currentElement;
73 public static boolean VERBOSE_RECOVERY = false;
75 protected boolean diet = false; // tells the scanner to jump over some
78 * the PHP token scanner
80 public Scanner scanner;
84 protected int modifiers;
86 protected int modifiersSourceStart;
88 protected Parser(ProblemReporter problemReporter) {
89 this.problemReporter = problemReporter;
90 this.options = problemReporter.options;
91 this.token = TokenNameEOF;
92 this.initializeScanner();
95 public void setFileToParse(IFile fileToParse) {
96 this.token = TokenNameEOF;
97 this.initializeScanner();
101 * ClassDeclaration Constructor.
105 * Description of Parameter
108 public Parser(IFile fileToParse) {
109 // if (keywordMap == null) {
110 // keywordMap = new HashMap();
111 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
112 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
115 // this.currentPHPString = 0;
116 // PHPParserSuperclass.fileToParse = fileToParse;
117 // this.phpList = null;
118 this.includesList = null;
120 this.token = TokenNameEOF;
122 // this.rowCount = 1;
123 // this.columnCount = 0;
124 // this.phpEnd = false;
126 this.initializeScanner();
129 public void initializeScanner() {
130 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
131 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
132 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
136 * Create marker for the parse error
138 // private void setMarker(String message, int charStart, int charEnd, int
140 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
143 * This method will throw the SyntaxError. It will add the good lines and
144 * columns to the Error
148 * @throws SyntaxError
151 private void throwSyntaxError(String error) {
152 int problemStartPosition = scanner.getCurrentTokenStartPosition();
153 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
154 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
155 problemEndPosition = scanner.source.length - 1;
156 if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
157 problemStartPosition = problemEndPosition - 1;
160 throwSyntaxError(error, problemStartPosition, problemEndPosition);
164 * This method will throw the SyntaxError. It will add the good lines and
165 * columns to the Error
169 * @throws SyntaxError
172 // private void throwSyntaxError(String error, int startRow) {
173 // throw new SyntaxError(startRow, 0, " ", error);
175 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
176 if (referenceContext != null) {
177 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
178 compilationUnit.compilationResult);
180 throw new SyntaxError(1, 0, " ", error);
183 private void reportSyntaxError(String error) {
184 int problemStartPosition = scanner.getCurrentTokenStartPosition();
185 int problemEndPosition = scanner.getCurrentTokenEndPosition();
186 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
189 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
190 if (referenceContext != null) {
191 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
192 compilationUnit.compilationResult);
196 // private void reportSyntaxWarning(String error, int problemStartPosition,
197 // int problemEndPosition) {
198 // if (referenceContext != null) {
199 // problemReporter.phpParsingWarning(new String[] { error },
200 // problemStartPosition, problemEndPosition, referenceContext,
201 // compilationUnit.compilationResult);
206 * gets the next token from input
208 private void getNextToken() {
210 token = scanner.getNextToken();
212 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213 int currentStartPosition = scanner.getCurrentTokenStartPosition();
214 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
215 System.out.println(scanner.toStringAction(token));
217 } catch (InvalidInputException e) {
218 token = TokenNameERROR;
219 String detailedMessage = e.getMessage();
221 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
222 throwSyntaxError("Unterminated string.");
223 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
224 throwSyntaxError("Unterminated commment.");
230 public void init(String s) {
232 this.token = TokenNameEOF;
233 this.includesList = new ArrayList();
235 // this.rowCount = 1;
236 // this.columnCount = 0;
237 // this.phpEnd = false;
238 // this.phpMode = false;
239 /* scanner initialization */
240 scanner.setSource(s.toCharArray());
241 scanner.setPHPMode(false);
245 protected void initialize(boolean phpMode) {
246 initialize(phpMode, null);
249 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
250 compilationUnit = null;
251 referenceContext = null;
252 this.includesList = new ArrayList();
253 // this.indexManager = indexManager;
255 this.token = TokenNameEOF;
257 // this.rowCount = 1;
258 // this.columnCount = 0;
259 // this.phpEnd = false;
260 // this.phpMode = phpMode;
261 scanner.setPHPMode(phpMode);
266 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
269 public void parse(String s) {
274 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
277 public void parse(String s, HashMap variables) {
278 fMethodVariables = variables;
279 fStackUnassigned = new ArrayList();
285 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
288 protected void parse() {
289 if (scanner.compilationUnit != null) {
290 IResource resource = scanner.compilationUnit.getResource();
291 if (resource != null && resource instanceof IFile) {
292 // set the package name
293 consumePackageDeclarationName((IFile) resource);
299 if (token != TokenNameEOF && token != TokenNameERROR) {
302 if (token != TokenNameEOF) {
303 if (token == TokenNameERROR) {
304 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
306 if (token == TokenNameRPAREN) {
307 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
309 if (token == TokenNameRBRACE) {
310 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
312 if (token == TokenNameRBRACKET) {
313 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
315 if (token == TokenNameLPAREN) {
316 throwSyntaxError("Read character '('; end-of-file not reached.");
318 if (token == TokenNameLBRACE) {
319 throwSyntaxError("Read character '{'; end-of-file not reached.");
321 if (token == TokenNameLBRACKET) {
322 throwSyntaxError("Read character '['; end-of-file not reached.");
324 throwSyntaxError("End-of-file not reached.");
327 } catch (SyntaxError syntaxError) {
328 // syntaxError.printStackTrace();
337 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
340 public void parseFunction(String s, HashMap variables) {
342 scanner.phpMode = true;
343 parseFunction(variables);
347 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
350 protected void parseFunction(HashMap variables) {
352 boolean hasModifiers = member_modifiers();
353 if (token == TokenNamefunction) {
355 checkAndSetModifiers(AccPublic);
357 this.fMethodVariables = variables;
359 MethodDeclaration methodDecl = new MethodDeclaration(null);
360 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
361 methodDecl.modifiers = this.modifiers;
362 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
365 functionDefinition(methodDecl);
366 } catch (SyntaxError sytaxErr1) {
369 int sourceEnd = methodDecl.sourceEnd;
370 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
371 sourceEnd = methodDecl.declarationSourceStart + 1;
373 methodDecl.sourceEnd = sourceEnd;
374 methodDecl.declarationSourceEnd = sourceEnd;
379 protected CompilationUnitDeclaration endParse(int act) {
383 // if (currentElement != null) {
384 // currentElement.topElement().updateParseTree();
385 // if (VERBOSE_RECOVERY) {
386 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
387 // System.out.println("--------------------------"); //$NON-NLS-1$
388 // System.out.println(compilationUnit);
389 // System.out.println("----------------------------------"); //$NON-NLS-1$
392 if (diet & VERBOSE_RECOVERY) {
393 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
394 System.out.println("--------------------------"); //$NON-NLS-1$
395 System.out.println(compilationUnit);
396 System.out.println("----------------------------------"); //$NON-NLS-1$
399 if (scanner.recordLineSeparator) {
400 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
402 if (scanner.taskTags != null) {
403 for (int i = 0; i < scanner.foundTaskCount; i++) {
404 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
405 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
406 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
409 compilationUnit.imports = new ImportReference[includesList.size()];
410 for (int i = 0; i < includesList.size(); i++) {
411 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
413 return compilationUnit;
416 private Block statementList() {
417 boolean branchStatement = false;
419 int blockStart = scanner.getCurrentTokenStartPosition();
420 ArrayList blockStatements = new ArrayList();
423 statement = statement();
424 blockStatements.add(statement);
425 if (token == TokenNameEOF) {
428 if (branchStatement && statement != null) {
429 // reportSyntaxError("Unreachable code", statement.sourceStart,
430 // statement.sourceEnd);
431 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
432 statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
434 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
435 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
436 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
437 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
438 return createBlock(blockStart, blockStatements);
440 branchStatement = checkUnreachableStatements(statement);
441 } catch (SyntaxError sytaxErr1) {
442 // if an error occured,
443 // try to find keywords
444 // to parse the rest of the string
445 boolean tokenize = scanner.tokenizeStrings;
447 scanner.tokenizeStrings = true;
450 while (token != TokenNameEOF) {
451 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
452 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
453 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
454 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
455 return createBlock(blockStart, blockStatements);
457 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
458 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
459 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameglobal
460 || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction || token == TokenNamedeclare
461 || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow || token == TokenNamefinal
462 || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
465 // System.out.println(scanner.toStringAction(token));
467 // System.out.println(scanner.toStringAction(token));
469 if (token == TokenNameEOF) {
473 scanner.tokenizeStrings = tokenize;
483 private boolean checkUnreachableStatements(Statement statement) {
484 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
486 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
494 * @param blockStatements
497 private Block createBlock(int blockStart, ArrayList blockStatements) {
498 int blockEnd = scanner.getCurrentTokenEndPosition();
499 Block b = Block.EmptyWith(blockStart, blockEnd);
500 b.statements = new Statement[blockStatements.size()];
501 blockStatements.toArray(b.statements);
505 private void functionBody(MethodDeclaration methodDecl) {
506 // '{' [statement-list] '}'
507 if (token == TokenNameLBRACE) {
510 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
511 throwSyntaxError("'{' expected in compound-statement.");
513 if (token != TokenNameRBRACE) {
516 if (token == TokenNameRBRACE) {
517 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
520 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
521 throwSyntaxError("'}' expected in compound-statement.");
525 private Statement statement() {
526 Statement statement = null;
527 Expression expression;
528 int sourceStart = scanner.getCurrentTokenStartPosition();
530 if (token == TokenNameif) {
531 // T_IF '(' expr ')' statement elseif_list else_single
532 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
533 // new_else_single T_ENDIF ';'
535 if (token == TokenNameLPAREN) {
538 throwSyntaxError("'(' expected after 'if' keyword.");
541 if (token == TokenNameRPAREN) {
544 throwSyntaxError("')' expected after 'if' condition.");
546 // create basic IfStatement
547 IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
548 if (token == TokenNameCOLON) {
550 ifStatementColon(ifStatement);
552 ifStatement(ifStatement);
555 } else if (token == TokenNameswitch) {
557 if (token == TokenNameLPAREN) {
560 throwSyntaxError("'(' expected after 'switch' keyword.");
563 if (token == TokenNameRPAREN) {
566 throwSyntaxError("')' expected after 'switch' condition.");
570 } else if (token == TokenNamefor) {
572 if (token == TokenNameLPAREN) {
575 throwSyntaxError("'(' expected after 'for' keyword.");
577 if (token == TokenNameSEMICOLON) {
581 if (token == TokenNameSEMICOLON) {
584 throwSyntaxError("';' expected after 'for'.");
587 if (token == TokenNameSEMICOLON) {
591 if (token == TokenNameSEMICOLON) {
594 throwSyntaxError("';' expected after 'for'.");
597 if (token == TokenNameRPAREN) {
601 if (token == TokenNameRPAREN) {
604 throwSyntaxError("')' expected after 'for'.");
609 } else if (token == TokenNamewhile) {
611 if (token == TokenNameLPAREN) {
614 throwSyntaxError("'(' expected after 'while' keyword.");
617 if (token == TokenNameRPAREN) {
620 throwSyntaxError("')' expected after 'while' condition.");
624 } else if (token == TokenNamedo) {
626 if (token == TokenNameLBRACE) {
628 if (token != TokenNameRBRACE) {
631 if (token == TokenNameRBRACE) {
634 throwSyntaxError("'}' expected after 'do' keyword.");
639 if (token == TokenNamewhile) {
641 if (token == TokenNameLPAREN) {
644 throwSyntaxError("'(' expected after 'while' keyword.");
647 if (token == TokenNameRPAREN) {
650 throwSyntaxError("')' expected after 'while' condition.");
653 throwSyntaxError("'while' expected after 'do' keyword.");
655 if (token == TokenNameSEMICOLON) {
658 if (token != TokenNameINLINE_HTML) {
659 throwSyntaxError("';' expected after do-while statement.");
664 } else if (token == TokenNameforeach) {
666 if (token == TokenNameLPAREN) {
669 throwSyntaxError("'(' expected after 'foreach' keyword.");
672 if (token == TokenNameas) {
675 throwSyntaxError("'as' expected after 'foreach' exxpression.");
679 foreach_optional_arg();
680 if (token == TokenNameEQUAL_GREATER) {
682 variable(false, false);
684 if (token == TokenNameRPAREN) {
687 throwSyntaxError("')' expected after 'foreach' expression.");
691 } else if (token == TokenNamebreak) {
694 if (token != TokenNameSEMICOLON) {
697 if (token == TokenNameSEMICOLON) {
698 sourceEnd = scanner.getCurrentTokenEndPosition();
701 if (token != TokenNameINLINE_HTML) {
702 throwSyntaxError("';' expected after 'break'.");
704 sourceEnd = scanner.getCurrentTokenEndPosition();
707 return new BreakStatement(null, sourceStart, sourceEnd);
708 } else if (token == TokenNamecontinue) {
711 if (token != TokenNameSEMICOLON) {
714 if (token == TokenNameSEMICOLON) {
715 sourceEnd = scanner.getCurrentTokenEndPosition();
718 if (token != TokenNameINLINE_HTML) {
719 throwSyntaxError("';' expected after 'continue'.");
721 sourceEnd = scanner.getCurrentTokenEndPosition();
724 return new ContinueStatement(null, sourceStart, sourceEnd);
725 } else if (token == TokenNamereturn) {
728 if (token != TokenNameSEMICOLON) {
731 if (token == TokenNameSEMICOLON) {
732 sourceEnd = scanner.getCurrentTokenEndPosition();
735 if (token != TokenNameINLINE_HTML) {
736 throwSyntaxError("';' expected after 'return'.");
738 sourceEnd = scanner.getCurrentTokenEndPosition();
741 return new ReturnStatement(expression, sourceStart, sourceEnd);
742 } else if (token == TokenNameecho) {
745 if (token == TokenNameSEMICOLON) {
748 if (token != TokenNameINLINE_HTML) {
749 throwSyntaxError("';' expected after 'echo' statement.");
754 } else if (token == TokenNameINLINE_HTML) {
757 } else if (token == TokenNameglobal) {
760 if (token == TokenNameSEMICOLON) {
763 if (token != TokenNameINLINE_HTML) {
764 throwSyntaxError("';' expected after 'global' statement.");
769 } else if (token == TokenNamestatic) {
772 if (token == TokenNameSEMICOLON) {
775 if (token != TokenNameINLINE_HTML) {
776 throwSyntaxError("';' expected after 'static' statement.");
781 } else if (token == TokenNameunset) {
783 if (token == TokenNameLPAREN) {
786 throwSyntaxError("'(' expected after 'unset' statement.");
789 if (token == TokenNameRPAREN) {
792 throwSyntaxError("')' expected after 'unset' statement.");
794 if (token == TokenNameSEMICOLON) {
797 if (token != TokenNameINLINE_HTML) {
798 throwSyntaxError("';' expected after 'unset' statement.");
803 } else if (token == TokenNamefunction) {
804 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
805 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
806 methodDecl.modifiers = AccDefault;
807 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
810 functionDefinition(methodDecl);
812 sourceEnd = methodDecl.sourceEnd;
813 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
814 sourceEnd = methodDecl.declarationSourceStart + 1;
816 methodDecl.declarationSourceEnd = sourceEnd;
817 methodDecl.sourceEnd = sourceEnd;
820 } else if (token == TokenNamedeclare) {
821 // T_DECLARE '(' declare_list ')' declare_statement
823 if (token != TokenNameLPAREN) {
824 throwSyntaxError("'(' expected in 'declare' statement.");
828 if (token != TokenNameRPAREN) {
829 throwSyntaxError("')' expected in 'declare' statement.");
834 } else if (token == TokenNametry) {
836 if (token != TokenNameLBRACE) {
837 throwSyntaxError("'{' expected in 'try' statement.");
841 if (token != TokenNameRBRACE) {
842 throwSyntaxError("'}' expected in 'try' statement.");
846 } else if (token == TokenNamecatch) {
848 if (token != TokenNameLPAREN) {
849 throwSyntaxError("'(' expected in 'catch' statement.");
852 fully_qualified_class_name();
853 if (token != TokenNameVariable) {
854 throwSyntaxError("Variable expected in 'catch' statement.");
858 if (token != TokenNameRPAREN) {
859 throwSyntaxError("')' expected in 'catch' statement.");
862 if (token != TokenNameLBRACE) {
863 throwSyntaxError("'{' expected in 'catch' statement.");
866 if (token != TokenNameRBRACE) {
868 if (token != TokenNameRBRACE) {
869 throwSyntaxError("'}' expected in 'catch' statement.");
873 additional_catches();
875 } else if (token == TokenNamethrow) {
878 if (token == TokenNameSEMICOLON) {
881 throwSyntaxError("';' expected after 'throw' exxpression.");
884 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
886 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
887 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
888 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
889 typeDecl.name = new char[] { ' ' };
890 // default super class
891 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
892 compilationUnit.types.add(typeDecl);
893 pushOnAstStack(typeDecl);
894 unticked_class_declaration_statement(typeDecl);
902 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
903 } else if (token == TokenNameLBRACE) {
905 if (token != TokenNameRBRACE) {
906 statement = statementList();
908 if (token == TokenNameRBRACE) {
912 throwSyntaxError("'}' expected.");
915 if (token != TokenNameSEMICOLON) {
918 if (token == TokenNameSEMICOLON) {
922 if (token == TokenNameRBRACE) {
923 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
925 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
926 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
936 private void declare_statement() {
938 // | ':' inner_statement_list T_ENDDECLARE ';'
940 if (token == TokenNameCOLON) {
942 // TODO: implement inner_statement_list();
944 if (token != TokenNameenddeclare) {
945 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
948 if (token != TokenNameSEMICOLON) {
949 throwSyntaxError("';' expected after 'enddeclare' keyword.");
957 private void declare_list() {
958 // T_STRING '=' static_scalar
959 // | declare_list ',' T_STRING '=' static_scalar
961 if (token != TokenNameIdentifier) {
962 throwSyntaxError("Identifier expected in 'declare' list.");
965 if (token != TokenNameEQUAL) {
966 throwSyntaxError("'=' expected in 'declare' list.");
970 if (token != TokenNameCOMMA) {
977 private void additional_catches() {
978 while (token == TokenNamecatch) {
980 if (token != TokenNameLPAREN) {
981 throwSyntaxError("'(' expected in 'catch' statement.");
984 fully_qualified_class_name();
985 if (token != TokenNameVariable) {
986 throwSyntaxError("Variable expected in 'catch' statement.");
990 if (token != TokenNameRPAREN) {
991 throwSyntaxError("')' expected in 'catch' statement.");
994 if (token != TokenNameLBRACE) {
995 throwSyntaxError("'{' expected in 'catch' statement.");
998 if (token != TokenNameRBRACE) {
1001 if (token != TokenNameRBRACE) {
1002 throwSyntaxError("'}' expected in 'catch' statement.");
1008 private void foreach_variable() {
1011 if (token == TokenNameAND) {
1017 private void foreach_optional_arg() {
1019 // | T_DOUBLE_ARROW foreach_variable
1020 if (token == TokenNameEQUAL_GREATER) {
1026 private void global_var_list() {
1028 // global_var_list ',' global_var
1030 HashSet set = peekVariableSet();
1033 if (token != TokenNameCOMMA) {
1040 private void global_var(HashSet set) {
1044 // | '$' '{' expr '}'
1045 if (token == TokenNameVariable) {
1046 if (fMethodVariables != null) {
1047 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1048 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1050 addVariableSet(set);
1052 } else if (token == TokenNameDOLLAR) {
1054 if (token == TokenNameLBRACE) {
1057 if (token != TokenNameRBRACE) {
1058 throwSyntaxError("'}' expected in global variable.");
1067 private void static_var_list() {
1069 // static_var_list ',' T_VARIABLE
1070 // | static_var_list ',' T_VARIABLE '=' static_scalar
1072 // | T_VARIABLE '=' static_scalar,
1073 HashSet set = peekVariableSet();
1075 if (token == TokenNameVariable) {
1076 if (fMethodVariables != null) {
1077 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1078 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1080 addVariableSet(set);
1082 if (token == TokenNameEQUAL) {
1086 if (token != TokenNameCOMMA) {
1096 private void unset_variables() {
1099 // | unset_variables ',' unset_variable
1103 variable(false, false);
1104 if (token != TokenNameCOMMA) {
1111 private final void initializeModifiers() {
1113 this.modifiersSourceStart = -1;
1116 private final void checkAndSetModifiers(int flag) {
1117 this.modifiers |= flag;
1118 if (this.modifiersSourceStart < 0)
1119 this.modifiersSourceStart = this.scanner.startPosition;
1122 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1123 initializeModifiers();
1124 if (token == TokenNameinterface) {
1125 // interface_entry T_STRING
1126 // interface_extends_list
1127 // '{' class_statement_list '}'
1128 checkAndSetModifiers(AccInterface);
1130 typeDecl.modifiers = this.modifiers;
1131 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1132 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1133 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1134 typeDecl.name = scanner.getCurrentIdentifierSource();
1135 if (token > TokenNameKEYWORD) {
1136 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1137 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1138 // throwSyntaxError("Don't use a keyword for interface declaration ["
1139 // + scanner.toStringAction(token) + "].",
1140 // typeDecl.sourceStart, typeDecl.sourceEnd);
1143 interface_extends_list(typeDecl);
1145 typeDecl.name = new char[] { ' ' };
1146 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1150 // class_entry_type T_STRING extends_from
1152 // '{' class_statement_list'}'
1154 typeDecl.modifiers = this.modifiers;
1155 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1156 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1158 // identifier 'extends' identifier
1159 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1160 typeDecl.name = scanner.getCurrentIdentifierSource();
1161 if (token > TokenNameKEYWORD) {
1162 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1163 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1164 // throwSyntaxError("Don't use a keyword for class declaration [" +
1165 // scanner.toStringAction(token) + "].",
1166 // typeDecl.sourceStart, typeDecl.sourceEnd);
1171 // | T_EXTENDS fully_qualified_class_name
1172 if (token == TokenNameextends) {
1173 interface_extends_list(typeDecl);
1175 // if (token != TokenNameIdentifier) {
1176 // throwSyntaxError("Class name expected after keyword
1178 // scanner.getCurrentTokenStartPosition(), scanner
1179 // .getCurrentTokenEndPosition());
1182 implements_list(typeDecl);
1184 typeDecl.name = new char[] { ' ' };
1185 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1189 // '{' class_statement_list '}'
1190 if (token == TokenNameLBRACE) {
1192 if (token != TokenNameRBRACE) {
1193 ArrayList list = new ArrayList();
1194 class_statement_list(list);
1195 typeDecl.fields = new FieldDeclaration[list.size()];
1196 for (int i = 0; i < list.size(); i++) {
1197 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1200 if (token == TokenNameRBRACE) {
1201 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1204 throwSyntaxError("'}' expected at end of class body.");
1207 throwSyntaxError("'{' expected at start of class body.");
1211 private void class_entry_type() {
1213 // | T_ABSTRACT T_CLASS
1214 // | T_FINAL T_CLASS
1215 if (token == TokenNameclass) {
1217 } else if (token == TokenNameabstract) {
1218 checkAndSetModifiers(AccAbstract);
1220 if (token != TokenNameclass) {
1221 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1224 } else if (token == TokenNamefinal) {
1225 checkAndSetModifiers(AccFinal);
1227 if (token != TokenNameclass) {
1228 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1232 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1236 // private void class_extends(TypeDeclaration typeDecl) {
1238 // // | T_EXTENDS interface_list
1239 // if (token == TokenNameextends) {
1242 // if (token == TokenNameIdentifier) {
1245 // throwSyntaxError("Class name expected after keyword 'extends'.");
1250 private void interface_extends_list(TypeDeclaration typeDecl) {
1252 // | T_EXTENDS interface_list
1253 if (token == TokenNameextends) {
1259 private void implements_list(TypeDeclaration typeDecl) {
1261 // | T_IMPLEMENTS interface_list
1262 if (token == TokenNameimplements) {
1268 private void interface_list() {
1270 // fully_qualified_class_name
1271 // | interface_list ',' fully_qualified_class_name
1273 if (token == TokenNameIdentifier) {
1276 throwSyntaxError("Interface name expected after keyword 'implements'.");
1278 if (token != TokenNameCOMMA) {
1285 // private void classBody(TypeDeclaration typeDecl) {
1286 // //'{' [class-element-list] '}'
1287 // if (token == TokenNameLBRACE) {
1289 // if (token != TokenNameRBRACE) {
1290 // class_statement_list();
1292 // if (token == TokenNameRBRACE) {
1293 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1296 // throwSyntaxError("'}' expected at end of class body.");
1299 // throwSyntaxError("'{' expected at start of class body.");
1302 private void class_statement_list(ArrayList list) {
1305 class_statement(list);
1306 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1307 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1308 || token == TokenNameconst) {
1311 if (token == TokenNameRBRACE) {
1314 throwSyntaxError("'}' at end of class statement.");
1315 } catch (SyntaxError sytaxErr1) {
1316 boolean tokenize = scanner.tokenizeStrings;
1318 scanner.tokenizeStrings = true;
1321 // if an error occured,
1322 // try to find keywords
1323 // to parse the rest of the string
1324 while (token != TokenNameEOF) {
1325 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1326 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1327 || token == TokenNameconst) {
1330 // System.out.println(scanner.toStringAction(token));
1333 if (token == TokenNameEOF) {
1337 scanner.tokenizeStrings = tokenize;
1343 private void class_statement(ArrayList list) {
1345 // variable_modifiers class_variable_declaration ';'
1346 // | class_constant_declaration ';'
1347 // | method_modifiers T_FUNCTION is_reference T_STRING
1348 // '(' parameter_list ')' method_body
1349 initializeModifiers();
1350 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1352 if (token == TokenNamevar) {
1353 checkAndSetModifiers(AccPublic);
1354 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1355 referenceContext, compilationUnit.compilationResult);
1357 class_variable_declaration(declarationSourceStart, list);
1358 } else if (token == TokenNameconst) {
1359 checkAndSetModifiers(AccFinal | AccPublic);
1360 class_constant_declaration(declarationSourceStart, list);
1361 if (token != TokenNameSEMICOLON) {
1362 throwSyntaxError("';' expected after class const declaration.");
1366 boolean hasModifiers = member_modifiers();
1367 if (token == TokenNamefunction) {
1368 if (!hasModifiers) {
1369 checkAndSetModifiers(AccPublic);
1371 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1372 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1373 methodDecl.modifiers = this.modifiers;
1374 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1377 functionDefinition(methodDecl);
1379 int sourceEnd = methodDecl.sourceEnd;
1380 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1381 sourceEnd = methodDecl.declarationSourceStart + 1;
1383 methodDecl.declarationSourceEnd = sourceEnd;
1384 methodDecl.sourceEnd = sourceEnd;
1387 if (!hasModifiers) {
1388 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1390 class_variable_declaration(declarationSourceStart, list);
1395 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1396 // class_constant_declaration ',' T_STRING '=' static_scalar
1397 // | T_CONST T_STRING '=' static_scalar
1398 if (token != TokenNameconst) {
1399 throwSyntaxError("'const' keyword expected in class declaration.");
1404 if (token != TokenNameIdentifier) {
1405 throwSyntaxError("Identifier expected in class const declaration.");
1407 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1408 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1409 fieldDeclaration.modifiers = this.modifiers;
1410 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1411 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1412 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1413 // fieldDeclaration.type
1414 list.add(fieldDeclaration);
1416 if (token != TokenNameEQUAL) {
1417 throwSyntaxError("'=' expected in class const declaration.");
1421 if (token != TokenNameCOMMA) {
1422 break; // while(true)-loop
1428 // private void variable_modifiers() {
1429 // // variable_modifiers:
1430 // // non_empty_member_modifiers
1432 // initializeModifiers();
1433 // if (token == TokenNamevar) {
1434 // checkAndSetModifiers(AccPublic);
1435 // reportSyntaxError(
1436 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1438 // modifier for field declarations.",
1439 // scanner.getCurrentTokenStartPosition(), scanner
1440 // .getCurrentTokenEndPosition());
1443 // if (!member_modifiers()) {
1444 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1445 // field declarations.");
1449 // private void method_modifiers() {
1450 // //method_modifiers:
1452 // //| non_empty_member_modifiers
1453 // initializeModifiers();
1454 // if (!member_modifiers()) {
1455 // checkAndSetModifiers(AccPublic);
1458 private boolean member_modifiers() {
1465 boolean foundToken = false;
1467 if (token == TokenNamepublic) {
1468 checkAndSetModifiers(AccPublic);
1471 } else if (token == TokenNameprotected) {
1472 checkAndSetModifiers(AccProtected);
1475 } else if (token == TokenNameprivate) {
1476 checkAndSetModifiers(AccPrivate);
1479 } else if (token == TokenNamestatic) {
1480 checkAndSetModifiers(AccStatic);
1483 } else if (token == TokenNameabstract) {
1484 checkAndSetModifiers(AccAbstract);
1487 } else if (token == TokenNamefinal) {
1488 checkAndSetModifiers(AccFinal);
1498 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1499 // class_variable_declaration:
1500 // class_variable_declaration ',' T_VARIABLE
1501 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1503 // | T_VARIABLE '=' static_scalar
1504 char[] classVariable;
1506 if (token == TokenNameVariable) {
1507 classVariable = scanner.getCurrentIdentifierSource();
1508 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1510 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1511 .getCurrentTokenEndPosition());
1512 fieldDeclaration.modifiers = this.modifiers;
1513 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1514 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1515 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1516 list.add(fieldDeclaration);
1517 if (fTypeVariables != null) {
1518 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1519 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1522 if (token == TokenNameEQUAL) {
1527 // if (token == TokenNamethis) {
1528 // throwSyntaxError("'$this' not allowed after keyword 'public'
1529 // 'protected' 'private' 'var'.");
1531 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1533 if (token != TokenNameCOMMA) {
1538 if (token != TokenNameSEMICOLON) {
1539 throwSyntaxError("';' expected after field declaration.");
1544 private void functionDefinition(MethodDeclaration methodDecl) {
1545 boolean isAbstract = false;
1547 if (compilationUnit != null) {
1548 compilationUnit.types.add(methodDecl);
1551 ASTNode node = astStack[astPtr];
1552 if (node instanceof TypeDeclaration) {
1553 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1554 if (typeDecl.methods == null) {
1555 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1557 AbstractMethodDeclaration[] newMethods;
1558 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1559 typeDecl.methods.length);
1560 newMethods[typeDecl.methods.length] = methodDecl;
1561 typeDecl.methods = newMethods;
1563 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1565 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1571 pushFunctionVariableSet();
1572 functionDeclarator(methodDecl);
1573 if (token == TokenNameSEMICOLON) {
1575 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1576 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1581 functionBody(methodDecl);
1583 if (!fStackUnassigned.isEmpty()) {
1584 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1589 private void functionDeclarator(MethodDeclaration methodDecl) {
1590 // identifier '(' [parameter-list] ')'
1591 if (token == TokenNameAND) {
1594 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1595 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1596 if (Scanner.isIdentifierOrKeyword(token)) {
1597 methodDecl.selector = scanner.getCurrentIdentifierSource();
1598 if (token > TokenNameKEYWORD) {
1599 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1600 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1603 if (token == TokenNameLPAREN) {
1606 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1607 throwSyntaxError("'(' expected in function declaration.");
1609 if (token != TokenNameRPAREN) {
1610 parameter_list(methodDecl);
1612 if (token != TokenNameRPAREN) {
1613 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1614 throwSyntaxError("')' expected in function declaration.");
1616 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1620 methodDecl.selector = "<undefined>".toCharArray();
1621 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1622 throwSyntaxError("Function name expected after keyword 'function'.");
1627 private void parameter_list(MethodDeclaration methodDecl) {
1628 // non_empty_parameter_list
1630 non_empty_parameter_list(methodDecl, true);
1633 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1634 // optional_class_type T_VARIABLE
1635 // | optional_class_type '&' T_VARIABLE
1636 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1637 // | optional_class_type T_VARIABLE '=' static_scalar
1638 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1639 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1640 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1642 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1644 char[] typeIdentifier = null;
1645 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1646 HashSet set = peekVariableSet();
1648 if (token == TokenNameIdentifier) {
1649 typeIdentifier = scanner.getCurrentIdentifierSource();
1652 if (token == TokenNameAND) {
1655 if (token == TokenNameVariable) {
1656 if (fMethodVariables != null) {
1658 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1659 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1661 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1663 info.typeIdentifier = typeIdentifier;
1664 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1666 addVariableSet(set);
1668 if (token == TokenNameEQUAL) {
1673 throwSyntaxError("Variable expected in parameter list.");
1675 if (token != TokenNameCOMMA) {
1682 if (!empty_allowed) {
1683 throwSyntaxError("Identifier expected in parameter list.");
1687 private void optional_class_type() {
1692 // private void parameterDeclaration() {
1694 // //variable-reference
1695 // if (token == TokenNameAND) {
1697 // if (isVariable()) {
1700 // throwSyntaxError("Variable expected after reference operator '&'.");
1703 // //variable '=' constant
1704 // if (token == TokenNameVariable) {
1706 // if (token == TokenNameEQUAL) {
1712 // // if (token == TokenNamethis) {
1713 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1714 // // declaration.");
1718 private void labeledStatementList() {
1719 if (token != TokenNamecase && token != TokenNamedefault) {
1720 throwSyntaxError("'case' or 'default' expected.");
1723 if (token == TokenNamecase) {
1725 expr(); // constant();
1726 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1728 if (token == TokenNamecase || token == TokenNamedefault) {
1729 // empty case statement ?
1734 // else if (token == TokenNameSEMICOLON) {
1736 // "':' expected after 'case' keyword (Found token: " +
1737 // scanner.toStringAction(token) + ")",
1738 // scanner.getCurrentTokenStartPosition(),
1739 // scanner.getCurrentTokenEndPosition(),
1742 // if (token == TokenNamecase) { // empty case statement ?
1748 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1750 } else { // TokenNamedefault
1752 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1754 if (token == TokenNameRBRACE) {
1755 // empty default case
1758 if (token != TokenNamecase) {
1762 throwSyntaxError("':' character expected after 'default'.");
1765 } while (token == TokenNamecase || token == TokenNamedefault);
1768 private void ifStatementColon(IfStatement iState) {
1769 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1770 // new_else_single T_ENDIF ';'
1771 HashSet assignedVariableSet = null;
1773 Block b = inner_statement_list();
1774 iState.thenStatement = b;
1775 checkUnreachable(iState, b);
1777 assignedVariableSet = removeIfVariableSet();
1779 if (token == TokenNameelseif) {
1781 pushIfVariableSet();
1782 new_elseif_list(iState);
1784 HashSet set = removeIfVariableSet();
1785 if (assignedVariableSet != null && set != null) {
1786 assignedVariableSet.addAll(set);
1791 pushIfVariableSet();
1792 new_else_single(iState);
1794 HashSet set = removeIfVariableSet();
1795 if (assignedVariableSet != null) {
1796 HashSet topSet = peekVariableSet();
1797 if (topSet != null) {
1801 topSet.addAll(assignedVariableSet);
1805 if (token != TokenNameendif) {
1806 throwSyntaxError("'endif' expected.");
1809 if (token != TokenNameSEMICOLON) {
1810 reportSyntaxError("';' expected after if-statement.");
1811 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1813 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1818 private void ifStatement(IfStatement iState) {
1819 // T_IF '(' expr ')' statement elseif_list else_single
1820 HashSet assignedVariableSet = null;
1822 pushIfVariableSet();
1823 Statement s = statement();
1824 iState.thenStatement = s;
1825 checkUnreachable(iState, s);
1827 assignedVariableSet = removeIfVariableSet();
1830 if (token == TokenNameelseif) {
1832 pushIfVariableSet();
1833 elseif_list(iState);
1835 HashSet set = removeIfVariableSet();
1836 if (assignedVariableSet != null && set != null) {
1837 assignedVariableSet.addAll(set);
1842 pushIfVariableSet();
1843 else_single(iState);
1845 HashSet set = removeIfVariableSet();
1846 if (assignedVariableSet != null) {
1847 HashSet topSet = peekVariableSet();
1848 if (topSet != null) {
1852 topSet.addAll(assignedVariableSet);
1858 private void elseif_list(IfStatement iState) {
1860 // | elseif_list T_ELSEIF '(' expr ')' statement
1861 ArrayList conditionList = new ArrayList();
1862 ArrayList statementList = new ArrayList();
1865 while (token == TokenNameelseif) {
1867 if (token == TokenNameLPAREN) {
1870 throwSyntaxError("'(' expected after 'elseif' keyword.");
1873 conditionList.add(e);
1874 if (token == TokenNameRPAREN) {
1877 throwSyntaxError("')' expected after 'elseif' condition.");
1880 statementList.add(s);
1881 checkUnreachable(iState, s);
1883 iState.elseifConditions = new Expression[conditionList.size()];
1884 iState.elseifStatements = new Statement[statementList.size()];
1885 conditionList.toArray(iState.elseifConditions);
1886 statementList.toArray(iState.elseifStatements);
1889 private void new_elseif_list(IfStatement iState) {
1891 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1892 ArrayList conditionList = new ArrayList();
1893 ArrayList statementList = new ArrayList();
1896 while (token == TokenNameelseif) {
1898 if (token == TokenNameLPAREN) {
1901 throwSyntaxError("'(' expected after 'elseif' keyword.");
1904 conditionList.add(e);
1905 if (token == TokenNameRPAREN) {
1908 throwSyntaxError("')' expected after 'elseif' condition.");
1910 if (token == TokenNameCOLON) {
1913 throwSyntaxError("':' expected after 'elseif' keyword.");
1915 b = inner_statement_list();
1916 statementList.add(b);
1917 checkUnreachable(iState, b);
1919 iState.elseifConditions = new Expression[conditionList.size()];
1920 iState.elseifStatements = new Statement[statementList.size()];
1921 conditionList.toArray(iState.elseifConditions);
1922 statementList.toArray(iState.elseifStatements);
1925 private void else_single(IfStatement iState) {
1928 if (token == TokenNameelse) {
1930 Statement s = statement();
1931 iState.elseStatement = s;
1932 checkUnreachable(iState, s);
1934 iState.checkUnreachable = false;
1936 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1939 private void new_else_single(IfStatement iState) {
1941 // | T_ELSE ':' inner_statement_list
1942 if (token == TokenNameelse) {
1944 if (token == TokenNameCOLON) {
1947 throwSyntaxError("':' expected after 'else' keyword.");
1949 Block b = inner_statement_list();
1950 iState.elseStatement = b;
1951 checkUnreachable(iState, b);
1953 iState.checkUnreachable = false;
1957 private Block inner_statement_list() {
1958 // inner_statement_list inner_statement
1960 return statementList();
1967 private void checkUnreachable(IfStatement iState, Statement s) {
1968 if (s instanceof Block) {
1969 Block b = (Block) s;
1970 if (b.statements == null || b.statements.length == 0) {
1971 iState.checkUnreachable = false;
1973 int off = b.statements.length - 1;
1974 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
1975 && !(b.statements[off] instanceof BreakStatement)) {
1976 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
1977 iState.checkUnreachable = false;
1982 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
1983 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
1984 iState.checkUnreachable = false;
1990 // private void elseifStatementList() {
1992 // elseifStatement();
1994 // case TokenNameelse:
1996 // if (token == TokenNameCOLON) {
1998 // if (token != TokenNameendif) {
2003 // if (token == TokenNameif) { //'else if'
2006 // throwSyntaxError("':' expected after 'else'.");
2010 // case TokenNameelseif:
2019 // private void elseifStatement() {
2020 // if (token == TokenNameLPAREN) {
2023 // if (token != TokenNameRPAREN) {
2024 // throwSyntaxError("')' expected in else-if-statement.");
2027 // if (token != TokenNameCOLON) {
2028 // throwSyntaxError("':' expected in else-if-statement.");
2031 // if (token != TokenNameendif) {
2037 private void switchStatement() {
2038 if (token == TokenNameCOLON) {
2039 // ':' [labeled-statement-list] 'endswitch' ';'
2041 labeledStatementList();
2042 if (token != TokenNameendswitch) {
2043 throwSyntaxError("'endswitch' expected.");
2046 if (token != TokenNameSEMICOLON) {
2047 throwSyntaxError("';' expected after switch-statement.");
2051 // '{' [labeled-statement-list] '}'
2052 if (token != TokenNameLBRACE) {
2053 throwSyntaxError("'{' expected in switch statement.");
2056 if (token != TokenNameRBRACE) {
2057 labeledStatementList();
2059 if (token != TokenNameRBRACE) {
2060 throwSyntaxError("'}' expected in switch statement.");
2066 private void forStatement() {
2067 if (token == TokenNameCOLON) {
2070 if (token != TokenNameendfor) {
2071 throwSyntaxError("'endfor' expected.");
2074 if (token != TokenNameSEMICOLON) {
2075 throwSyntaxError("';' expected after for-statement.");
2083 private void whileStatement() {
2084 // ':' statement-list 'endwhile' ';'
2085 if (token == TokenNameCOLON) {
2088 if (token != TokenNameendwhile) {
2089 throwSyntaxError("'endwhile' expected.");
2092 if (token != TokenNameSEMICOLON) {
2093 throwSyntaxError("';' expected after while-statement.");
2101 private void foreachStatement() {
2102 if (token == TokenNameCOLON) {
2105 if (token != TokenNameendforeach) {
2106 throwSyntaxError("'endforeach' expected.");
2109 if (token != TokenNameSEMICOLON) {
2110 throwSyntaxError("';' expected after foreach-statement.");
2118 // private void exitStatus() {
2119 // if (token == TokenNameLPAREN) {
2122 // throwSyntaxError("'(' expected in 'exit-status'.");
2124 // if (token != TokenNameRPAREN) {
2127 // if (token == TokenNameRPAREN) {
2130 // throwSyntaxError("')' expected after 'exit-status'.");
2133 private void expressionList() {
2136 if (token == TokenNameCOMMA) {
2144 private Expression expr() {
2146 // | expr_without_variable
2147 // if (token!=TokenNameEOF) {
2148 if (Scanner.TRACE) {
2149 System.out.println("TRACE: expr()");
2151 return expr_without_variable(true);
2155 private Expression expr_without_variable(boolean only_variable) {
2156 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2157 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2158 Expression expression = new Expression();
2159 expression.sourceStart = exprSourceStart;
2160 // default, may be overwritten
2161 expression.sourceEnd = exprSourceEnd;
2163 // internal_functions_in_yacc
2172 // | T_INC rw_variable
2173 // | T_DEC rw_variable
2174 // | T_INT_CAST expr
2175 // | T_DOUBLE_CAST expr
2176 // | T_STRING_CAST expr
2177 // | T_ARRAY_CAST expr
2178 // | T_OBJECT_CAST expr
2179 // | T_BOOL_CAST expr
2180 // | T_UNSET_CAST expr
2181 // | T_EXIT exit_expr
2183 // | T_ARRAY '(' array_pair_list ')'
2184 // | '`' encaps_list '`'
2185 // | T_LIST '(' assignment_list ')' '=' expr
2186 // | T_NEW class_name_reference ctor_arguments
2187 // | variable '=' expr
2188 // | variable '=' '&' variable
2189 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2190 // | variable T_PLUS_EQUAL expr
2191 // | variable T_MINUS_EQUAL expr
2192 // | variable T_MUL_EQUAL expr
2193 // | variable T_DIV_EQUAL expr
2194 // | variable T_CONCAT_EQUAL expr
2195 // | variable T_MOD_EQUAL expr
2196 // | variable T_AND_EQUAL expr
2197 // | variable T_OR_EQUAL expr
2198 // | variable T_XOR_EQUAL expr
2199 // | variable T_SL_EQUAL expr
2200 // | variable T_SR_EQUAL expr
2201 // | rw_variable T_INC
2202 // | rw_variable T_DEC
2203 // | expr T_BOOLEAN_OR expr
2204 // | expr T_BOOLEAN_AND expr
2205 // | expr T_LOGICAL_OR expr
2206 // | expr T_LOGICAL_AND expr
2207 // | expr T_LOGICAL_XOR expr
2219 // | expr T_IS_IDENTICAL expr
2220 // | expr T_IS_NOT_IDENTICAL expr
2221 // | expr T_IS_EQUAL expr
2222 // | expr T_IS_NOT_EQUAL expr
2224 // | expr T_IS_SMALLER_OR_EQUAL expr
2226 // | expr T_IS_GREATER_OR_EQUAL expr
2227 // | expr T_INSTANCEOF class_name_reference
2228 // | expr '?' expr ':' expr
2229 if (Scanner.TRACE) {
2230 System.out.println("TRACE: expr_without_variable() PART 1");
2233 case TokenNameisset:
2234 // T_ISSET '(' isset_variables ')'
2236 if (token != TokenNameLPAREN) {
2237 throwSyntaxError("'(' expected after keyword 'isset'");
2241 if (token != TokenNameRPAREN) {
2242 throwSyntaxError("')' expected after keyword 'isset'");
2246 case TokenNameempty:
2248 if (token != TokenNameLPAREN) {
2249 throwSyntaxError("'(' expected after keyword 'empty'");
2252 variable(true, false);
2253 if (token != TokenNameRPAREN) {
2254 throwSyntaxError("')' expected after keyword 'empty'");
2259 case TokenNameinclude:
2260 case TokenNameinclude_once:
2261 case TokenNamerequire:
2262 case TokenNamerequire_once:
2263 internal_functions_in_yacc();
2266 case TokenNameLPAREN:
2269 if (token == TokenNameRPAREN) {
2272 throwSyntaxError("')' expected in expression.");
2282 // | T_INT_CAST expr
2283 // | T_DOUBLE_CAST expr
2284 // | T_STRING_CAST expr
2285 // | T_ARRAY_CAST expr
2286 // | T_OBJECT_CAST expr
2287 // | T_BOOL_CAST expr
2288 // | T_UNSET_CAST expr
2289 case TokenNameclone:
2290 case TokenNameprint:
2293 case TokenNameMINUS:
2295 case TokenNameTWIDDLE:
2296 case TokenNameintCAST:
2297 case TokenNamedoubleCAST:
2298 case TokenNamestringCAST:
2299 case TokenNamearrayCAST:
2300 case TokenNameobjectCAST:
2301 case TokenNameboolCAST:
2302 case TokenNameunsetCAST:
2312 // | T_STRING_VARNAME
2314 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2315 // | '`' encaps_list '`'
2317 // | '`' encaps_list '`'
2318 // case TokenNameEncapsedString0:
2319 // scanner.encapsedStringStack.push(new Character('`'));
2322 // if (token == TokenNameEncapsedString0) {
2325 // if (token != TokenNameEncapsedString0) {
2326 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2327 // scanner.toStringAction(token) + " )");
2331 // scanner.encapsedStringStack.pop();
2335 // // | '\'' encaps_list '\''
2336 // case TokenNameEncapsedString1:
2337 // scanner.encapsedStringStack.push(new Character('\''));
2340 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2341 // if (token == TokenNameEncapsedString1) {
2343 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2344 // exprSourceStart, scanner
2345 // .getCurrentTokenEndPosition());
2348 // if (token != TokenNameEncapsedString1) {
2349 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2350 // + scanner.toStringAction(token) + " )");
2353 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2354 // exprSourceStart, scanner
2355 // .getCurrentTokenEndPosition());
2359 // scanner.encapsedStringStack.pop();
2363 // //| '"' encaps_list '"'
2364 // case TokenNameEncapsedString2:
2365 // scanner.encapsedStringStack.push(new Character('"'));
2368 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2369 // if (token == TokenNameEncapsedString2) {
2371 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2372 // exprSourceStart, scanner
2373 // .getCurrentTokenEndPosition());
2376 // if (token != TokenNameEncapsedString2) {
2377 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2378 // scanner.toStringAction(token) + " )");
2381 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2382 // exprSourceStart, scanner
2383 // .getCurrentTokenEndPosition());
2387 // scanner.encapsedStringStack.pop();
2391 case TokenNameStringDoubleQuote:
2392 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2393 .getCurrentTokenEndPosition());
2396 case TokenNameStringSingleQuote:
2397 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2398 .getCurrentTokenEndPosition());
2401 case TokenNameIntegerLiteral:
2402 case TokenNameDoubleLiteral:
2403 case TokenNameStringInterpolated:
2406 case TokenNameCLASS_C:
2407 case TokenNameMETHOD_C:
2408 case TokenNameFUNC_C:
2411 case TokenNameHEREDOC:
2414 case TokenNamearray:
2415 // T_ARRAY '(' array_pair_list ')'
2417 if (token == TokenNameLPAREN) {
2419 if (token == TokenNameRPAREN) {
2424 if (token != TokenNameRPAREN) {
2425 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2429 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2433 // | T_LIST '(' assignment_list ')' '=' expr
2435 if (token == TokenNameLPAREN) {
2438 if (token != TokenNameRPAREN) {
2439 throwSyntaxError("')' expected after 'list' keyword.");
2442 if (token != TokenNameEQUAL) {
2443 throwSyntaxError("'=' expected after 'list' keyword.");
2448 throwSyntaxError("'(' expected after 'list' keyword.");
2452 // | T_NEW class_name_reference ctor_arguments
2454 Expression typeRef = class_name_reference();
2456 if (typeRef != null) {
2457 expression = typeRef;
2460 // | T_INC rw_variable
2461 // | T_DEC rw_variable
2462 case TokenNamePLUS_PLUS:
2463 case TokenNameMINUS_MINUS:
2467 // | variable '=' expr
2468 // | variable '=' '&' variable
2469 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2470 // | variable T_PLUS_EQUAL expr
2471 // | variable T_MINUS_EQUAL expr
2472 // | variable T_MUL_EQUAL expr
2473 // | variable T_DIV_EQUAL expr
2474 // | variable T_CONCAT_EQUAL expr
2475 // | variable T_MOD_EQUAL expr
2476 // | variable T_AND_EQUAL expr
2477 // | variable T_OR_EQUAL expr
2478 // | variable T_XOR_EQUAL expr
2479 // | variable T_SL_EQUAL expr
2480 // | variable T_SR_EQUAL expr
2481 // | rw_variable T_INC
2482 // | rw_variable T_DEC
2483 case TokenNameIdentifier:
2484 case TokenNameVariable:
2485 case TokenNameDOLLAR:
2486 Expression lhs = null;
2487 boolean rememberedVar = false;
2488 if (token == TokenNameIdentifier) {
2489 lhs = identifier(true, true);
2494 lhs = variable(true, true);
2498 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2499 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2500 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2501 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2502 && token != TokenNameLEFT_SHIFT_EQUAL) {
2503 FieldReference ref = (FieldReference) lhs;
2504 if (!containsVariableSet(ref.token)) {
2505 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(),
2506 referenceContext, compilationUnit.compilationResult);
2507 addVariableSet(ref.token);
2512 case TokenNameEQUAL:
2513 if (lhs != null && lhs instanceof FieldReference) {
2514 addVariableSet(((FieldReference) lhs).token);
2517 if (token == TokenNameAND) {
2519 if (token == TokenNamenew) {
2520 // | variable '=' '&' T_NEW class_name_reference
2523 SingleTypeReference classRef = class_name_reference();
2525 if (classRef != null) {
2526 if (lhs != null && lhs instanceof FieldReference) {
2528 // $var = & new Object();
2529 if (fMethodVariables != null) {
2530 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2531 lhsInfo.reference = classRef;
2532 lhsInfo.typeIdentifier = classRef.token;
2533 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2534 rememberedVar = true;
2539 Expression rhs = variable(false, false);
2540 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2543 if (fMethodVariables != null) {
2544 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2545 if (rhsInfo != null && rhsInfo.reference != null) {
2546 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2547 lhsInfo.reference = rhsInfo.reference;
2548 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2549 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2550 rememberedVar = true;
2556 Expression rhs = expr();
2557 if (lhs != null && lhs instanceof FieldReference) {
2558 if (rhs != null && rhs instanceof FieldReference) {
2561 if (fMethodVariables != null) {
2562 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2563 if (rhsInfo != null && rhsInfo.reference != null) {
2564 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2565 lhsInfo.reference = rhsInfo.reference;
2566 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2567 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2568 rememberedVar = true;
2571 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2573 // $var = new Object();
2574 if (fMethodVariables != null) {
2575 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2576 lhsInfo.reference = (SingleTypeReference) rhs;
2577 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2578 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2579 rememberedVar = true;
2584 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2585 if (fMethodVariables != null) {
2586 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2587 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2591 case TokenNamePLUS_EQUAL:
2592 case TokenNameMINUS_EQUAL:
2593 case TokenNameMULTIPLY_EQUAL:
2594 case TokenNameDIVIDE_EQUAL:
2595 case TokenNameDOT_EQUAL:
2596 case TokenNameREMAINDER_EQUAL:
2597 case TokenNameAND_EQUAL:
2598 case TokenNameOR_EQUAL:
2599 case TokenNameXOR_EQUAL:
2600 case TokenNameRIGHT_SHIFT_EQUAL:
2601 case TokenNameLEFT_SHIFT_EQUAL:
2602 if (lhs != null && lhs instanceof FieldReference) {
2603 addVariableSet(((FieldReference) lhs).token);
2608 case TokenNamePLUS_PLUS:
2609 case TokenNameMINUS_MINUS:
2613 if (!only_variable) {
2614 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2622 if (token != TokenNameINLINE_HTML) {
2623 if (token > TokenNameKEYWORD) {
2627 // System.out.println(scanner.getCurrentTokenStartPosition());
2628 // System.out.println(scanner.getCurrentTokenEndPosition());
2630 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2635 if (Scanner.TRACE) {
2636 System.out.println("TRACE: expr_without_variable() PART 2");
2638 // | expr T_BOOLEAN_OR expr
2639 // | expr T_BOOLEAN_AND expr
2640 // | expr T_LOGICAL_OR expr
2641 // | expr T_LOGICAL_AND expr
2642 // | expr T_LOGICAL_XOR expr
2654 // | expr T_IS_IDENTICAL expr
2655 // | expr T_IS_NOT_IDENTICAL expr
2656 // | expr T_IS_EQUAL expr
2657 // | expr T_IS_NOT_EQUAL expr
2659 // | expr T_IS_SMALLER_OR_EQUAL expr
2661 // | expr T_IS_GREATER_OR_EQUAL expr
2664 case TokenNameOR_OR:
2666 expression = new OR_OR_Expression(expression, expr(), token);
2668 case TokenNameAND_AND:
2670 expression = new AND_AND_Expression(expression, expr(), token);
2672 case TokenNameEQUAL_EQUAL:
2674 expression = new EqualExpression(expression, expr(), token);
2684 case TokenNameMINUS:
2685 case TokenNameMULTIPLY:
2686 case TokenNameDIVIDE:
2687 case TokenNameREMAINDER:
2688 case TokenNameLEFT_SHIFT:
2689 case TokenNameRIGHT_SHIFT:
2690 case TokenNameEQUAL_EQUAL_EQUAL:
2691 case TokenNameNOT_EQUAL_EQUAL:
2692 case TokenNameNOT_EQUAL:
2694 case TokenNameLESS_EQUAL:
2695 case TokenNameGREATER:
2696 case TokenNameGREATER_EQUAL:
2698 expression = new BinaryExpression(expression, expr(), token);
2700 // | expr T_INSTANCEOF class_name_reference
2701 // | expr '?' expr ':' expr
2702 case TokenNameinstanceof:
2704 TypeReference classRef = class_name_reference();
2705 if (classRef != null) {
2706 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2707 expression.sourceStart = exprSourceStart;
2708 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2711 case TokenNameQUESTION:
2713 Expression valueIfTrue = expr();
2714 if (token != TokenNameCOLON) {
2715 throwSyntaxError("':' expected in conditional expression.");
2718 Expression valueIfFalse = expr();
2720 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2726 } catch (SyntaxError e) {
2727 // try to find next token after expression with errors:
2728 if (token == TokenNameSEMICOLON) {
2732 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2740 private SingleTypeReference class_name_reference() {
2741 // class_name_reference:
2743 // | dynamic_class_name_reference
2744 SingleTypeReference ref = null;
2745 if (Scanner.TRACE) {
2746 System.out.println("TRACE: class_name_reference()");
2748 if (token == TokenNameIdentifier) {
2749 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2753 dynamic_class_name_reference();
2758 private void dynamic_class_name_reference() {
2759 // dynamic_class_name_reference:
2760 // base_variable T_OBJECT_OPERATOR object_property
2761 // dynamic_class_name_variable_properties
2763 if (Scanner.TRACE) {
2764 System.out.println("TRACE: dynamic_class_name_reference()");
2766 base_variable(true);
2767 if (token == TokenNameMINUS_GREATER) {
2770 dynamic_class_name_variable_properties();
2774 private void dynamic_class_name_variable_properties() {
2775 // dynamic_class_name_variable_properties:
2776 // dynamic_class_name_variable_properties
2777 // dynamic_class_name_variable_property
2779 if (Scanner.TRACE) {
2780 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2782 while (token == TokenNameMINUS_GREATER) {
2783 dynamic_class_name_variable_property();
2787 private void dynamic_class_name_variable_property() {
2788 // dynamic_class_name_variable_property:
2789 // T_OBJECT_OPERATOR object_property
2790 if (Scanner.TRACE) {
2791 System.out.println("TRACE: dynamic_class_name_variable_property()");
2793 if (token == TokenNameMINUS_GREATER) {
2799 private void ctor_arguments() {
2802 // | '(' function_call_parameter_list ')'
2803 if (token == TokenNameLPAREN) {
2805 if (token == TokenNameRPAREN) {
2809 non_empty_function_call_parameter_list();
2810 if (token != TokenNameRPAREN) {
2811 throwSyntaxError("')' expected in ctor_arguments.");
2817 private void assignment_list() {
2819 // assignment_list ',' assignment_list_element
2820 // | assignment_list_element
2822 assignment_list_element();
2823 if (token != TokenNameCOMMA) {
2830 private void assignment_list_element() {
2831 // assignment_list_element:
2833 // | T_LIST '(' assignment_list ')'
2835 if (token == TokenNameVariable) {
2836 variable(true, false);
2837 } else if (token == TokenNameDOLLAR) {
2838 variable(false, false);
2840 if (token == TokenNamelist) {
2842 if (token == TokenNameLPAREN) {
2845 if (token != TokenNameRPAREN) {
2846 throwSyntaxError("')' expected after 'list' keyword.");
2850 throwSyntaxError("'(' expected after 'list' keyword.");
2856 private void array_pair_list() {
2859 // | non_empty_array_pair_list possible_comma
2860 non_empty_array_pair_list();
2861 if (token == TokenNameCOMMA) {
2866 private void non_empty_array_pair_list() {
2867 // non_empty_array_pair_list:
2868 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2869 // | non_empty_array_pair_list ',' expr
2870 // | expr T_DOUBLE_ARROW expr
2872 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2873 // | non_empty_array_pair_list ',' '&' w_variable
2874 // | expr T_DOUBLE_ARROW '&' w_variable
2877 if (token == TokenNameAND) {
2879 variable(true, false);
2882 if (token == TokenNameAND) {
2884 variable(true, false);
2885 } else if (token == TokenNameEQUAL_GREATER) {
2887 if (token == TokenNameAND) {
2889 variable(true, false);
2895 if (token != TokenNameCOMMA) {
2899 if (token == TokenNameRPAREN) {
2905 // private void variableList() {
2908 // if (token == TokenNameCOMMA) {
2915 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2916 // variable_without_objects:
2917 // reference_variable
2918 // | simple_indirect_reference reference_variable
2919 if (Scanner.TRACE) {
2920 System.out.println("TRACE: variable_without_objects()");
2922 while (token == TokenNameDOLLAR) {
2925 return reference_variable(lefthandside, ignoreVar);
2928 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2930 // T_STRING '(' function_call_parameter_list ')'
2931 // | class_constant '(' function_call_parameter_list ')'
2932 // | static_member '(' function_call_parameter_list ')'
2933 // | variable_without_objects '(' function_call_parameter_list ')'
2934 char[] defineName = null;
2935 char[] ident = null;
2938 Expression ref = null;
2939 if (Scanner.TRACE) {
2940 System.out.println("TRACE: function_call()");
2942 if (token == TokenNameIdentifier) {
2943 ident = scanner.getCurrentIdentifierSource();
2945 startPos = scanner.getCurrentTokenStartPosition();
2946 endPos = scanner.getCurrentTokenEndPosition();
2949 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2953 if (token == TokenNameIdentifier) {
2958 variable_without_objects(true, false);
2963 ref = variable_without_objects(lefthandside, ignoreVar);
2965 if (token != TokenNameLPAREN) {
2966 if (defineName != null) {
2967 // does this identifier contain only uppercase characters?
2968 if (defineName.length == 3) {
2969 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2972 } else if (defineName.length == 4) {
2973 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2975 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2978 } else if (defineName.length == 5) {
2979 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2983 if (defineName != null) {
2984 for (int i = 0; i < defineName.length; i++) {
2985 if (Character.isLowerCase(defineName[i])) {
2986 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2994 if (token == TokenNameRPAREN) {
2998 non_empty_function_call_parameter_list();
2999 if (token != TokenNameRPAREN) {
3000 String functionName;
3001 if (ident == null) {
3002 functionName = new String(" ");
3004 functionName = new String(ident);
3006 throwSyntaxError("')' expected in function call (" + functionName + ").");
3013 // private void function_call_parameter_list() {
3014 // function_call_parameter_list:
3015 // non_empty_function_call_parameter_list { $$ = $1; }
3018 private void non_empty_function_call_parameter_list() {
3019 // non_empty_function_call_parameter_list:
3020 // expr_without_variable
3023 // | non_empty_function_call_parameter_list ',' expr_without_variable
3024 // | non_empty_function_call_parameter_list ',' variable
3025 // | non_empty_function_call_parameter_list ',' '&' w_variable
3026 if (Scanner.TRACE) {
3027 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3030 if (token == TokenNameAND) {
3034 // if (token == TokenNameIdentifier || token ==
3035 // TokenNameVariable
3036 // || token == TokenNameDOLLAR) {
3039 expr_without_variable(true);
3042 if (token != TokenNameCOMMA) {
3049 private void fully_qualified_class_name() {
3050 if (token == TokenNameIdentifier) {
3053 throwSyntaxError("Class name expected.");
3057 private void static_member() {
3059 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3060 // variable_without_objects
3061 if (Scanner.TRACE) {
3062 System.out.println("TRACE: static_member()");
3064 fully_qualified_class_name();
3065 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3066 throwSyntaxError("'::' expected after class name (static_member).");
3069 variable_without_objects(false, false);
3072 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3073 // base_variable_with_function_calls:
3076 if (Scanner.TRACE) {
3077 System.out.println("TRACE: base_variable_with_function_calls()");
3079 return function_call(lefthandside, ignoreVar);
3082 private Expression base_variable(boolean lefthandside) {
3084 // reference_variable
3085 // | simple_indirect_reference reference_variable
3087 Expression ref = null;
3088 if (Scanner.TRACE) {
3089 System.out.println("TRACE: base_variable()");
3091 if (token == TokenNameIdentifier) {
3094 while (token == TokenNameDOLLAR) {
3097 reference_variable(lefthandside, false);
3102 // private void simple_indirect_reference() {
3103 // // simple_indirect_reference:
3105 // //| simple_indirect_reference '$'
3107 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3108 // reference_variable:
3109 // reference_variable '[' dim_offset ']'
3110 // | reference_variable '{' expr '}'
3111 // | compound_variable
3112 Expression ref = null;
3113 if (Scanner.TRACE) {
3114 System.out.println("TRACE: reference_variable()");
3116 ref = compound_variable(lefthandside, ignoreVar);
3118 if (token == TokenNameLBRACE) {
3122 if (token != TokenNameRBRACE) {
3123 throwSyntaxError("'}' expected in reference variable.");
3126 } else if (token == TokenNameLBRACKET) {
3127 // To remove "ref = null;" here, is probably better than the patch commented in #1368081 - axelcl
3129 if (token != TokenNameRBRACKET) {
3132 if (token != TokenNameRBRACKET) {
3133 throwSyntaxError("']' expected in reference variable.");
3144 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3145 // compound_variable:
3147 // | '$' '{' expr '}'
3148 if (Scanner.TRACE) {
3149 System.out.println("TRACE: compound_variable()");
3151 if (token == TokenNameVariable) {
3152 if (!lefthandside) {
3153 if (!containsVariableSet()) {
3154 // reportSyntaxError("The local variable " + new
3155 // String(scanner.getCurrentIdentifierSource())
3156 // + " may not have been initialized");
3157 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3158 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3159 compilationUnit.compilationResult);
3166 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3170 // because of simple_indirect_reference
3171 while (token == TokenNameDOLLAR) {
3174 if (token != TokenNameLBRACE) {
3175 reportSyntaxError("'{' expected after compound variable token '$'.");
3180 if (token != TokenNameRBRACE) {
3181 throwSyntaxError("'}' expected after compound variable token '$'.");
3186 } // private void dim_offset() { // // dim_offset: // // /* empty */
3191 private void object_property() {
3194 // | variable_without_objects
3195 if (Scanner.TRACE) {
3196 System.out.println("TRACE: object_property()");
3198 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3199 variable_without_objects(false, false);
3205 private void object_dim_list() {
3207 // object_dim_list '[' dim_offset ']'
3208 // | object_dim_list '{' expr '}'
3210 if (Scanner.TRACE) {
3211 System.out.println("TRACE: object_dim_list()");
3215 if (token == TokenNameLBRACE) {
3218 if (token != TokenNameRBRACE) {
3219 throwSyntaxError("'}' expected in object_dim_list.");
3222 } else if (token == TokenNameLBRACKET) {
3224 if (token == TokenNameRBRACKET) {
3229 if (token != TokenNameRBRACKET) {
3230 throwSyntaxError("']' expected in object_dim_list.");
3239 private void variable_name() {
3243 if (Scanner.TRACE) {
3244 System.out.println("TRACE: variable_name()");
3246 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3247 if (token > TokenNameKEYWORD) {
3248 // TODO show a warning "Keyword used as variable" ?
3252 if (token != TokenNameLBRACE) {
3253 throwSyntaxError("'{' expected in variable name.");
3257 if (token != TokenNameRBRACE) {
3258 throwSyntaxError("'}' expected in variable name.");
3264 private void r_variable() {
3265 variable(false, false);
3268 private void w_variable(boolean lefthandside) {
3269 variable(lefthandside, false);
3272 private void rw_variable() {
3273 variable(false, false);
3276 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3278 // base_variable_with_function_calls T_OBJECT_OPERATOR
3279 // object_property method_or_not variable_properties
3280 // | base_variable_with_function_calls
3281 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3282 if (token == TokenNameMINUS_GREATER) {
3287 variable_properties();
3292 private void variable_properties() {
3293 // variable_properties:
3294 // variable_properties variable_property
3296 while (token == TokenNameMINUS_GREATER) {
3297 variable_property();
3301 private void variable_property() {
3302 // variable_property:
3303 // T_OBJECT_OPERATOR object_property method_or_not
3304 if (Scanner.TRACE) {
3305 System.out.println("TRACE: variable_property()");
3307 if (token == TokenNameMINUS_GREATER) {
3312 throwSyntaxError("'->' expected in variable_property.");
3316 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3318 // base_variable_with_function_calls T_OBJECT_OPERATOR
3319 // object_property method_or_not variable_properties
3320 // | base_variable_with_function_calls
3322 // Expression ref = function_call(lefthandside, ignoreVar);
3325 // T_STRING '(' function_call_parameter_list ')'
3326 // | class_constant '(' function_call_parameter_list ')'
3327 // | static_member '(' function_call_parameter_list ')'
3328 // | variable_without_objects '(' function_call_parameter_list ')'
3329 char[] defineName = null;
3330 char[] ident = null;
3333 Expression ref = null;
3334 if (Scanner.TRACE) {
3335 System.out.println("TRACE: function_call()");
3337 if (token == TokenNameIdentifier) {
3338 ident = scanner.getCurrentIdentifierSource();
3340 startPos = scanner.getCurrentTokenStartPosition();
3341 endPos = scanner.getCurrentTokenEndPosition();
3344 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3345 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3346 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3347 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3348 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3349 + new String(ident) + "' (use 'define(...)' to define constants).";
3350 reportSyntaxError(error);
3354 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3358 if (token == TokenNameIdentifier) {
3363 variable_without_objects(true, false);
3368 ref = variable_without_objects(lefthandside, ignoreVar);
3370 if (token != TokenNameLPAREN) {
3371 if (defineName != null) {
3372 // does this identifier contain only uppercase characters?
3373 if (defineName.length == 3) {
3374 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3377 } else if (defineName.length == 4) {
3378 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3380 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3383 } else if (defineName.length == 5) {
3384 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3388 if (defineName != null) {
3389 for (int i = 0; i < defineName.length; i++) {
3390 if (Character.isLowerCase(defineName[i])) {
3391 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3397 // TODO is this ok ?
3399 // throwSyntaxError("'(' expected in function call.");
3403 if (token == TokenNameRPAREN) {
3407 non_empty_function_call_parameter_list();
3408 if (token != TokenNameRPAREN) {
3409 String functionName;
3410 if (ident == null) {
3411 functionName = new String(" ");
3413 functionName = new String(ident);
3415 throwSyntaxError("')' expected in function call (" + functionName + ").");
3420 if (token == TokenNameMINUS_GREATER) {
3425 variable_properties();
3430 private void method_or_not() {
3432 // '(' function_call_parameter_list ')'
3434 if (Scanner.TRACE) {
3435 System.out.println("TRACE: method_or_not()");
3437 if (token == TokenNameLPAREN) {
3439 if (token == TokenNameRPAREN) {
3443 non_empty_function_call_parameter_list();
3444 if (token != TokenNameRPAREN) {
3445 throwSyntaxError("')' expected in method_or_not.");
3451 private void exit_expr() {
3455 if (token != TokenNameLPAREN) {
3459 if (token == TokenNameRPAREN) {
3464 if (token != TokenNameRPAREN) {
3465 throwSyntaxError("')' expected after keyword 'exit'");
3470 // private void encaps_list() {
3471 // // encaps_list encaps_var
3472 // // | encaps_list T_STRING
3473 // // | encaps_list T_NUM_STRING
3474 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3475 // // | encaps_list T_CHARACTER
3476 // // | encaps_list T_BAD_CHARACTER
3477 // // | encaps_list '['
3478 // // | encaps_list ']'
3479 // // | encaps_list '{'
3480 // // | encaps_list '}'
3481 // // | encaps_list T_OBJECT_OPERATOR
3485 // case TokenNameSTRING:
3488 // case TokenNameLBRACE:
3489 // // scanner.encapsedStringStack.pop();
3492 // case TokenNameRBRACE:
3493 // // scanner.encapsedStringStack.pop();
3496 // case TokenNameLBRACKET:
3497 // // scanner.encapsedStringStack.pop();
3500 // case TokenNameRBRACKET:
3501 // // scanner.encapsedStringStack.pop();
3504 // case TokenNameMINUS_GREATER:
3505 // // scanner.encapsedStringStack.pop();
3508 // case TokenNameVariable:
3509 // case TokenNameDOLLAR_LBRACE:
3510 // case TokenNameLBRACE_DOLLAR:
3514 // char encapsedChar = ((Character)
3515 // scanner.encapsedStringStack.peek()).charValue();
3516 // if (encapsedChar == '$') {
3517 // scanner.encapsedStringStack.pop();
3518 // encapsedChar = ((Character)
3519 // scanner.encapsedStringStack.peek()).charValue();
3520 // switch (encapsedChar) {
3522 // if (token == TokenNameEncapsedString0) {
3525 // token = TokenNameSTRING;
3528 // if (token == TokenNameEncapsedString1) {
3531 // token = TokenNameSTRING;
3534 // if (token == TokenNameEncapsedString2) {
3537 // token = TokenNameSTRING;
3546 // private void encaps_var() {
3548 // // | T_VARIABLE '[' encaps_var_offset ']'
3549 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3550 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3551 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3552 // // | T_CURLY_OPEN variable '}'
3554 // case TokenNameVariable:
3556 // if (token == TokenNameLBRACKET) {
3558 // expr(); //encaps_var_offset();
3559 // if (token != TokenNameRBRACKET) {
3560 // throwSyntaxError("']' expected after variable.");
3562 // // scanner.encapsedStringStack.pop();
3565 // } else if (token == TokenNameMINUS_GREATER) {
3567 // if (token != TokenNameIdentifier) {
3568 // throwSyntaxError("Identifier expected after '->'.");
3570 // // scanner.encapsedStringStack.pop();
3574 // // // scanner.encapsedStringStack.pop();
3575 // // int tempToken = TokenNameSTRING;
3576 // // if (!scanner.encapsedStringStack.isEmpty()
3577 // // && (token == TokenNameEncapsedString0
3578 // // || token == TokenNameEncapsedString1
3579 // // || token == TokenNameEncapsedString2 || token ==
3580 // // TokenNameERROR)) {
3581 // // char encapsedChar = ((Character)
3582 // // scanner.encapsedStringStack.peek())
3584 // // switch (token) {
3585 // // case TokenNameEncapsedString0 :
3586 // // if (encapsedChar == '`') {
3587 // // tempToken = TokenNameEncapsedString0;
3590 // // case TokenNameEncapsedString1 :
3591 // // if (encapsedChar == '\'') {
3592 // // tempToken = TokenNameEncapsedString1;
3595 // // case TokenNameEncapsedString2 :
3596 // // if (encapsedChar == '"') {
3597 // // tempToken = TokenNameEncapsedString2;
3600 // // case TokenNameERROR :
3601 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3602 // // scanner.currentPosition--;
3603 // // getNextToken();
3608 // // token = tempToken;
3611 // case TokenNameDOLLAR_LBRACE:
3613 // if (token == TokenNameDOLLAR_LBRACE) {
3615 // } else if (token == TokenNameIdentifier) {
3617 // if (token == TokenNameLBRACKET) {
3619 // // if (token == TokenNameRBRACKET) {
3620 // // getNextToken();
3623 // if (token != TokenNameRBRACKET) {
3624 // throwSyntaxError("']' expected after '${'.");
3632 // if (token != TokenNameRBRACE) {
3633 // throwSyntaxError("'}' expected.");
3637 // case TokenNameLBRACE_DOLLAR:
3639 // if (token == TokenNameLBRACE_DOLLAR) {
3641 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3643 // if (token == TokenNameLBRACKET) {
3645 // // if (token == TokenNameRBRACKET) {
3646 // // getNextToken();
3649 // if (token != TokenNameRBRACKET) {
3650 // throwSyntaxError("']' expected.");
3654 // } else if (token == TokenNameMINUS_GREATER) {
3656 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3657 // throwSyntaxError("String or Variable token expected.");
3660 // if (token == TokenNameLBRACKET) {
3662 // // if (token == TokenNameRBRACKET) {
3663 // // getNextToken();
3666 // if (token != TokenNameRBRACKET) {
3667 // throwSyntaxError("']' expected after '${'.");
3673 // // if (token != TokenNameRBRACE) {
3674 // // throwSyntaxError("'}' expected after '{$'.");
3676 // // // scanner.encapsedStringStack.pop();
3677 // // getNextToken();
3680 // if (token != TokenNameRBRACE) {
3681 // throwSyntaxError("'}' expected.");
3683 // // scanner.encapsedStringStack.pop();
3690 // private void encaps_var_offset() {
3692 // // | T_NUM_STRING
3695 // case TokenNameSTRING:
3698 // case TokenNameIntegerLiteral:
3701 // case TokenNameVariable:
3704 // case TokenNameIdentifier:
3708 // throwSyntaxError("Variable or String token expected.");
3713 private void internal_functions_in_yacc() {
3716 // case TokenNameisset:
3717 // // T_ISSET '(' isset_variables ')'
3719 // if (token != TokenNameLPAREN) {
3720 // throwSyntaxError("'(' expected after keyword 'isset'");
3723 // isset_variables();
3724 // if (token != TokenNameRPAREN) {
3725 // throwSyntaxError("')' expected after keyword 'isset'");
3729 // case TokenNameempty:
3730 // // T_EMPTY '(' variable ')'
3732 // if (token != TokenNameLPAREN) {
3733 // throwSyntaxError("'(' expected after keyword 'empty'");
3737 // if (token != TokenNameRPAREN) {
3738 // throwSyntaxError("')' expected after keyword 'empty'");
3742 case TokenNameinclude:
3744 checkFileName(token);
3746 case TokenNameinclude_once:
3747 // T_INCLUDE_ONCE expr
3748 checkFileName(token);
3751 // T_EVAL '(' expr ')'
3753 if (token != TokenNameLPAREN) {
3754 throwSyntaxError("'(' expected after keyword 'eval'");
3758 if (token != TokenNameRPAREN) {
3759 throwSyntaxError("')' expected after keyword 'eval'");
3763 case TokenNamerequire:
3765 checkFileName(token);
3767 case TokenNamerequire_once:
3768 // T_REQUIRE_ONCE expr
3769 checkFileName(token);
3775 * Parse and check the include file name
3777 * @param includeToken
3779 private void checkFileName(int includeToken) {
3780 // <include-token> expr
3781 int start = scanner.getCurrentTokenStartPosition();
3782 boolean hasLPAREN = false;
3784 if (token == TokenNameLPAREN) {
3788 Expression expression = expr();
3790 if (token == TokenNameRPAREN) {
3793 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3796 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3798 if (scanner.compilationUnit != null) {
3799 IResource resource = scanner.compilationUnit.getResource();
3800 if (resource != null && resource instanceof IFile) {
3801 file = (IFile) resource;
3805 tokens = new char[1][];
3806 tokens[0] = currTokenSource;
3808 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3809 impt.declarationSourceEnd = impt.sourceEnd;
3810 impt.declarationEnd = impt.declarationSourceEnd;
3811 // endPosition is just before the ;
3812 impt.declarationSourceStart = start;
3813 includesList.add(impt);
3815 if (expression instanceof StringLiteral) {
3816 StringLiteral literal = (StringLiteral) expression;
3817 char[] includeName = literal.source();
3818 if (includeName.length == 0) {
3819 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3820 literal.sourceStart + 1);
3822 String includeNameString = new String(includeName);
3823 if (literal instanceof StringLiteralDQ) {
3824 if (includeNameString.indexOf('$') >= 0) {
3825 // assuming that the filename contains a variable => no filename check
3829 if (includeNameString.startsWith("http://")) {
3830 // assuming external include location
3834 // check the filename:
3835 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3836 // expression.toStringExpression());
3837 IProject project = file.getProject();
3838 if (project != null) {
3839 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3842 // SyntaxError: "File: << >> doesn't exist in project."
3843 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3844 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3845 compilationUnit.compilationResult);
3848 String filePath = path.toString();
3849 String ext = file.getRawLocation().getFileExtension();
3850 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3852 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3853 impt.setFile(PHPFileUtil.createFile(path, project));
3854 } catch (Exception e) {
3855 // the file is outside of the workspace
3863 private void isset_variables() {
3865 // | isset_variables ','
3866 if (token == TokenNameRPAREN) {
3867 throwSyntaxError("Variable expected after keyword 'isset'");
3870 variable(true, false);
3871 if (token == TokenNameCOMMA) {
3879 private boolean common_scalar() {
3883 // | T_CONSTANT_ENCAPSED_STRING
3890 case TokenNameIntegerLiteral:
3893 case TokenNameDoubleLiteral:
3896 case TokenNameStringDoubleQuote:
3899 case TokenNameStringSingleQuote:
3902 case TokenNameStringInterpolated:
3911 case TokenNameCLASS_C:
3914 case TokenNameMETHOD_C:
3917 case TokenNameFUNC_C:
3924 private void scalar() {
3927 // | T_STRING_VARNAME
3930 // | '"' encaps_list '"'
3931 // | '\'' encaps_list '\''
3932 // | T_START_HEREDOC encaps_list T_END_HEREDOC
3933 throwSyntaxError("Not yet implemented (scalar).");
3936 private void static_scalar() {
3937 // static_scalar: /* compile-time evaluated scalars */
3940 // | '+' static_scalar
3941 // | '-' static_scalar
3942 // | T_ARRAY '(' static_array_pair_list ')'
3943 // | static_class_constant
3944 if (common_scalar()) {
3948 case TokenNameIdentifier:
3950 // static_class_constant:
3951 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3952 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3954 if (token == TokenNameIdentifier) {
3957 throwSyntaxError("Identifier expected after '::' operator.");
3961 case TokenNameEncapsedString0:
3963 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3964 while (scanner.currentCharacter != '`') {
3965 if (scanner.currentCharacter == '\\') {
3966 scanner.currentPosition++;
3968 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3971 } catch (IndexOutOfBoundsException e) {
3972 throwSyntaxError("'`' expected at end of static string.");
3975 // case TokenNameEncapsedString1:
3977 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3978 // while (scanner.currentCharacter != '\'') {
3979 // if (scanner.currentCharacter == '\\') {
3980 // scanner.currentPosition++;
3982 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3985 // } catch (IndexOutOfBoundsException e) {
3986 // throwSyntaxError("'\'' expected at end of static string.");
3989 // case TokenNameEncapsedString2:
3991 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3992 // while (scanner.currentCharacter != '"') {
3993 // if (scanner.currentCharacter == '\\') {
3994 // scanner.currentPosition++;
3996 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3999 // } catch (IndexOutOfBoundsException e) {
4000 // throwSyntaxError("'\"' expected at end of static string.");
4003 case TokenNameStringSingleQuote:
4006 case TokenNameStringDoubleQuote:
4013 case TokenNameMINUS:
4017 case TokenNamearray:
4019 if (token != TokenNameLPAREN) {
4020 throwSyntaxError("'(' expected after keyword 'array'");
4023 if (token == TokenNameRPAREN) {
4027 non_empty_static_array_pair_list();
4028 if (token != TokenNameRPAREN) {
4029 throwSyntaxError("')' or ',' expected after keyword 'array'");
4033 // case TokenNamenull :
4036 // case TokenNamefalse :
4039 // case TokenNametrue :
4043 throwSyntaxError("Static scalar/constant expected.");
4047 private void non_empty_static_array_pair_list() {
4048 // non_empty_static_array_pair_list:
4049 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4051 // | non_empty_static_array_pair_list ',' static_scalar
4052 // | static_scalar T_DOUBLE_ARROW static_scalar
4056 if (token == TokenNameEQUAL_GREATER) {
4060 if (token != TokenNameCOMMA) {
4064 if (token == TokenNameRPAREN) {
4070 // public void reportSyntaxError() { //int act, int currentKind, int
4071 // // stateStackTop) {
4072 // /* remember current scanner position */
4073 // int startPos = scanner.startPosition;
4074 // int currentPos = scanner.currentPosition;
4076 // this.checkAndReportBracketAnomalies(problemReporter());
4077 // /* reset scanner where it was */
4078 // scanner.startPosition = startPos;
4079 // scanner.currentPosition = currentPos;
4082 public static final int RoundBracket = 0;
4084 public static final int SquareBracket = 1;
4086 public static final int CurlyBracket = 2;
4088 public static final int BracketKinds = 3;
4090 protected int[] nestedMethod; // the ptr is nestedType
4092 protected int nestedType, dimensions;
4094 // variable set stack
4095 final static int VariableStackIncrement = 10;
4097 HashMap fTypeVariables = null;
4099 HashMap fMethodVariables = null;
4101 ArrayList fStackUnassigned = new ArrayList();
4104 final static int AstStackIncrement = 100;
4106 protected int astPtr;
4108 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4110 protected int astLengthPtr;
4112 protected int[] astLengthStack;
4114 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4116 public CompilationUnitDeclaration compilationUnit; /*
4117 * the result from parse()
4120 protected ReferenceContext referenceContext;
4122 protected ProblemReporter problemReporter;
4124 protected CompilerOptions options;
4126 private ArrayList includesList;
4128 // protected CompilationResult compilationResult;
4130 * Returns this parser's problem reporter initialized with its reference
4131 * context. Also it is assumed that a problem is going to be reported, so
4132 * initializes the compilation result's line positions.
4134 public ProblemReporter problemReporter() {
4135 if (scanner.recordLineSeparator) {
4136 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4138 problemReporter.referenceContext = referenceContext;
4139 return problemReporter;
4143 * Reconsider the entire source looking for inconsistencies in {} () []
4145 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4146 // problemReporter) {
4147 // scanner.wasAcr = false;
4148 // boolean anomaliesDetected = false;
4150 // char[] source = scanner.source;
4151 // int[] leftCount = { 0, 0, 0 };
4152 // int[] rightCount = { 0, 0, 0 };
4153 // int[] depths = { 0, 0, 0 };
4154 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4156 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4157 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4159 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4161 // scanner.currentPosition = scanner.initialPosition; //starting
4163 // // (first-zero-based
4165 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4170 // // ---------Consume white space and handles
4171 // // startPosition---------
4172 // boolean isWhiteSpace;
4174 // scanner.startPosition = scanner.currentPosition;
4175 // // if (((scanner.currentCharacter =
4176 // // source[scanner.currentPosition++]) == '\\') &&
4177 // // (source[scanner.currentPosition] == 'u')) {
4178 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4180 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4181 // (scanner.currentCharacter == '\n'))) {
4182 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4183 // // only record line positions we have not
4185 // scanner.pushLineSeparator();
4188 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4190 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4191 // // -------consume token until } is found---------
4192 // switch (scanner.currentCharacter) {
4194 // int index = leftCount[CurlyBracket]++;
4195 // if (index == leftPositions[CurlyBracket].length) {
4196 // System.arraycopy(leftPositions[CurlyBracket], 0,
4197 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4198 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4199 // new int[index * 2]), 0, index);
4201 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4202 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4206 // int index = rightCount[CurlyBracket]++;
4207 // if (index == rightPositions[CurlyBracket].length) {
4208 // System.arraycopy(rightPositions[CurlyBracket], 0,
4209 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4210 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4211 // new int[index * 2]), 0, index);
4213 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4214 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4218 // int index = leftCount[RoundBracket]++;
4219 // if (index == leftPositions[RoundBracket].length) {
4220 // System.arraycopy(leftPositions[RoundBracket], 0,
4221 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4222 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4223 // new int[index * 2]), 0, index);
4225 // leftPositions[RoundBracket][index] = scanner.startPosition;
4226 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4230 // int index = rightCount[RoundBracket]++;
4231 // if (index == rightPositions[RoundBracket].length) {
4232 // System.arraycopy(rightPositions[RoundBracket], 0,
4233 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4234 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4235 // new int[index * 2]), 0, index);
4237 // rightPositions[RoundBracket][index] = scanner.startPosition;
4238 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4242 // int index = leftCount[SquareBracket]++;
4243 // if (index == leftPositions[SquareBracket].length) {
4244 // System.arraycopy(leftPositions[SquareBracket], 0,
4245 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4246 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4247 // new int[index * 2]), 0, index);
4249 // leftPositions[SquareBracket][index] = scanner.startPosition;
4250 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4254 // int index = rightCount[SquareBracket]++;
4255 // if (index == rightPositions[SquareBracket].length) {
4256 // System.arraycopy(rightPositions[SquareBracket], 0,
4257 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4258 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4259 // = new int[index * 2]), 0, index);
4261 // rightPositions[SquareBracket][index] = scanner.startPosition;
4262 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4266 // if (scanner.getNextChar('\\')) {
4267 // scanner.scanEscapeCharacter();
4268 // } else { // consume next character
4269 // scanner.unicodeAsBackSlash = false;
4270 // // if (((scanner.currentCharacter =
4271 // // source[scanner.currentPosition++]) ==
4273 // // (source[scanner.currentPosition] ==
4275 // // scanner.getNextUnicodeChar();
4277 // if (scanner.withoutUnicodePtr != 0) {
4278 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4279 // scanner.currentCharacter;
4283 // scanner.getNextChar('\'');
4287 // // consume next character
4288 // scanner.unicodeAsBackSlash = false;
4289 // // if (((scanner.currentCharacter =
4290 // // source[scanner.currentPosition++]) == '\\') &&
4291 // // (source[scanner.currentPosition] == 'u')) {
4292 // // scanner.getNextUnicodeChar();
4294 // if (scanner.withoutUnicodePtr != 0) {
4295 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4296 // scanner.currentCharacter;
4299 // while (scanner.currentCharacter != '"') {
4300 // if (scanner.currentCharacter == '\r') {
4301 // if (source[scanner.currentPosition] == '\n')
4302 // scanner.currentPosition++;
4303 // break; // the string cannot go further that
4306 // if (scanner.currentCharacter == '\n') {
4307 // break; // the string cannot go further that
4310 // if (scanner.currentCharacter == '\\') {
4311 // scanner.scanEscapeCharacter();
4313 // // consume next character
4314 // scanner.unicodeAsBackSlash = false;
4315 // // if (((scanner.currentCharacter =
4316 // // source[scanner.currentPosition++]) == '\\')
4317 // // && (source[scanner.currentPosition] == 'u'))
4319 // // scanner.getNextUnicodeChar();
4321 // if (scanner.withoutUnicodePtr != 0) {
4322 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4323 // scanner.currentCharacter;
4330 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4332 // //get the next char
4333 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4335 // && (source[scanner.currentPosition] == 'u')) {
4336 // //-------------unicode traitement
4338 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4339 // scanner.currentPosition++;
4340 // while (source[scanner.currentPosition] == 'u') {
4341 // scanner.currentPosition++;
4343 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4345 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4347 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4349 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4350 // || c4 < 0) { //error
4354 // scanner.currentCharacter = 'A';
4355 // } //something different from \n and \r
4357 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4360 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4362 // //get the next char
4363 // scanner.startPosition = scanner.currentPosition;
4364 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4366 // && (source[scanner.currentPosition] == 'u')) {
4367 // //-------------unicode traitement
4369 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4370 // scanner.currentPosition++;
4371 // while (source[scanner.currentPosition] == 'u') {
4372 // scanner.currentPosition++;
4374 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4376 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4378 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4380 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4381 // || c4 < 0) { //error
4385 // scanner.currentCharacter = 'A';
4386 // } //something different from \n
4389 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4393 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4394 // (scanner.currentCharacter == '\n'))) {
4395 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4396 // // only record line positions we
4397 // // have not recorded yet
4398 // scanner.pushLineSeparator();
4399 // if (this.scanner.taskTags != null) {
4400 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4402 // .getCurrentTokenEndPosition());
4408 // if (test > 0) { //traditional and annotation
4410 // boolean star = false;
4411 // // consume next character
4412 // scanner.unicodeAsBackSlash = false;
4413 // // if (((scanner.currentCharacter =
4414 // // source[scanner.currentPosition++]) ==
4416 // // (source[scanner.currentPosition] ==
4418 // // scanner.getNextUnicodeChar();
4420 // if (scanner.withoutUnicodePtr != 0) {
4421 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4422 // scanner.currentCharacter;
4425 // if (scanner.currentCharacter == '*') {
4428 // //get the next char
4429 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4431 // && (source[scanner.currentPosition] == 'u')) {
4432 // //-------------unicode traitement
4434 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4435 // scanner.currentPosition++;
4436 // while (source[scanner.currentPosition] == 'u') {
4437 // scanner.currentPosition++;
4439 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4441 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4443 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4445 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4446 // || c4 < 0) { //error
4450 // scanner.currentCharacter = 'A';
4451 // } //something different from * and /
4453 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4456 // //loop until end of comment */
4457 // while ((scanner.currentCharacter != '/') || (!star)) {
4458 // star = scanner.currentCharacter == '*';
4460 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4462 // && (source[scanner.currentPosition] == 'u')) {
4463 // //-------------unicode traitement
4465 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4466 // scanner.currentPosition++;
4467 // while (source[scanner.currentPosition] == 'u') {
4468 // scanner.currentPosition++;
4470 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4472 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4474 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4476 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4477 // || c4 < 0) { //error
4481 // scanner.currentCharacter = 'A';
4482 // } //something different from * and
4485 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4489 // if (this.scanner.taskTags != null) {
4490 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4491 // this.scanner.getCurrentTokenEndPosition());
4498 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4499 // scanner.scanIdentifierOrKeyword(false);
4502 // if (Character.isDigit(scanner.currentCharacter)) {
4503 // scanner.scanNumber(false);
4507 // //-----------------end switch while
4508 // // try--------------------
4509 // } catch (IndexOutOfBoundsException e) {
4510 // break; // read until EOF
4511 // } catch (InvalidInputException e) {
4512 // return false; // no clue
4515 // if (scanner.recordLineSeparator) {
4516 // compilationUnit.compilationResult.lineSeparatorPositions =
4517 // scanner.getLineEnds();
4519 // // check placement anomalies against other kinds of brackets
4520 // for (int kind = 0; kind < BracketKinds; kind++) {
4521 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4522 // int start = leftPositions[kind][leftIndex]; // deepest
4524 // // find matching closing bracket
4525 // int depth = leftDepths[kind][leftIndex];
4527 // for (int i = 0; i < rightCount[kind]; i++) {
4528 // int pos = rightPositions[kind][i];
4529 // // want matching bracket further in source with same
4531 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4536 // if (end < 0) { // did not find a good closing match
4537 // problemReporter.unmatchedBracket(start, referenceContext,
4538 // compilationUnit.compilationResult);
4541 // // check if even number of opening/closing other brackets
4542 // // in between this pair of brackets
4544 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4546 // for (int i = 0; i < leftCount[otherKind]; i++) {
4547 // int pos = leftPositions[otherKind][i];
4548 // if ((pos > start) && (pos < end))
4551 // for (int i = 0; i < rightCount[otherKind]; i++) {
4552 // int pos = rightPositions[otherKind][i];
4553 // if ((pos > start) && (pos < end))
4556 // if (balance != 0) {
4557 // problemReporter.unmatchedBracket(start, referenceContext,
4558 // compilationUnit.compilationResult); //bracket
4564 // // too many opening brackets ?
4565 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4566 // anomaliesDetected = true;
4567 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4568 // 1], referenceContext,
4569 // compilationUnit.compilationResult);
4571 // // too many closing brackets ?
4572 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4573 // anomaliesDetected = true;
4574 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4575 // compilationUnit.compilationResult);
4577 // if (anomaliesDetected)
4580 // return anomaliesDetected;
4581 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4582 // return anomaliesDetected;
4583 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4584 // return anomaliesDetected;
4587 protected void pushOnAstLengthStack(int pos) {
4589 astLengthStack[++astLengthPtr] = pos;
4590 } catch (IndexOutOfBoundsException e) {
4591 int oldStackLength = astLengthStack.length;
4592 int[] oldPos = astLengthStack;
4593 astLengthStack = new int[oldStackLength + StackIncrement];
4594 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4595 astLengthStack[astLengthPtr] = pos;
4599 protected void pushOnAstStack(ASTNode node) {
4601 * add a new obj on top of the ast stack
4604 astStack[++astPtr] = node;
4605 } catch (IndexOutOfBoundsException e) {
4606 int oldStackLength = astStack.length;
4607 ASTNode[] oldStack = astStack;
4608 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4609 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4610 astPtr = oldStackLength;
4611 astStack[astPtr] = node;
4614 astLengthStack[++astLengthPtr] = 1;
4615 } catch (IndexOutOfBoundsException e) {
4616 int oldStackLength = astLengthStack.length;
4617 int[] oldPos = astLengthStack;
4618 astLengthStack = new int[oldStackLength + AstStackIncrement];
4619 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4620 astLengthStack[astLengthPtr] = 1;
4624 protected void resetModifiers() {
4625 this.modifiers = AccDefault;
4626 this.modifiersSourceStart = -1; // <-- see comment into
4627 // modifiersFlag(int)
4628 this.scanner.commentPtr = -1;
4631 protected void consumePackageDeclarationName(IFile file) {
4632 // create a package name similar to java package names
4633 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4634 String filePath = file.getRawLocation().toString();
4635 String ext = file.getRawLocation().getFileExtension();
4636 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4637 ImportReference impt;
4639 if (filePath.startsWith(projectPath)) {
4640 tokens = CharOperation
4641 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4643 String name = file.getName();
4644 tokens = new char[1][];
4645 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4648 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4650 impt.declarationSourceStart = 0;
4651 impt.declarationSourceEnd = 0;
4652 impt.declarationEnd = 0;
4653 // endPosition is just before the ;
4657 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4658 "$_SESSION", "$_SERVER" };
4663 private void pushFunctionVariableSet() {
4664 HashSet set = new HashSet();
4665 if (fStackUnassigned.isEmpty()) {
4666 for (int i = 0; i < GLOBALS.length; i++) {
4667 set.add(GLOBALS[i]);
4670 fStackUnassigned.add(set);
4673 private void pushIfVariableSet() {
4674 if (!fStackUnassigned.isEmpty()) {
4675 HashSet set = new HashSet();
4676 fStackUnassigned.add(set);
4680 private HashSet removeIfVariableSet() {
4681 if (!fStackUnassigned.isEmpty()) {
4682 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4688 * Returns the <i>set of assigned variables </i> returns null if no Set is
4689 * defined at the current scanner position
4691 private HashSet peekVariableSet() {
4692 if (!fStackUnassigned.isEmpty()) {
4693 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4699 * add the current identifier source to the <i>set of assigned variables </i>
4703 private void addVariableSet(HashSet set) {
4705 set.add(new String(scanner.getCurrentTokenSource()));
4710 * add the current identifier source to the <i>set of assigned variables </i>
4713 private void addVariableSet() {
4714 HashSet set = peekVariableSet();
4716 set.add(new String(scanner.getCurrentTokenSource()));
4721 * add the current identifier source to the <i>set of assigned variables </i>
4724 private void addVariableSet(char[] token) {
4725 HashSet set = peekVariableSet();
4727 set.add(new String(token));
4732 * check if the current identifier source is in the <i>set of assigned
4733 * variables </i> Returns true, if no set is defined for the current scanner
4737 private boolean containsVariableSet() {
4738 return containsVariableSet(scanner.getCurrentTokenSource());
4741 private boolean containsVariableSet(char[] token) {
4743 if (!fStackUnassigned.isEmpty()) {
4745 String str = new String(token);
4746 for (int i = 0; i < fStackUnassigned.size(); i++) {
4747 set = (HashSet) fStackUnassigned.get(i);
4748 if (set.contains(str)) {