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) {
755 if (scanner.phpExpressionTag) {
756 // start of <?= ... ?> block
759 if (token == TokenNameSEMICOLON) {
762 if (token != TokenNameINLINE_HTML) {
763 throwSyntaxError("Missing '?>' for open PHP expression block ('<?=').");
769 // } else if (token == TokenNameprint) {
772 // if (token == TokenNameSEMICOLON) {
775 // if (token != TokenNameStopPHP) {
776 // throwSyntaxError("';' expected after 'print' statement.");
781 } else if (token == TokenNameglobal) {
784 if (token == TokenNameSEMICOLON) {
787 if (token != TokenNameINLINE_HTML) {
788 throwSyntaxError("';' expected after 'global' statement.");
793 } else if (token == TokenNamestatic) {
796 if (token == TokenNameSEMICOLON) {
799 if (token != TokenNameINLINE_HTML) {
800 throwSyntaxError("';' expected after 'static' statement.");
805 } else if (token == TokenNameunset) {
807 if (token == TokenNameLPAREN) {
810 throwSyntaxError("'(' expected after 'unset' statement.");
813 if (token == TokenNameRPAREN) {
816 throwSyntaxError("')' expected after 'unset' statement.");
818 if (token == TokenNameSEMICOLON) {
821 if (token != TokenNameINLINE_HTML) {
822 throwSyntaxError("';' expected after 'unset' statement.");
827 } else if (token == TokenNamefunction) {
828 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
829 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
830 methodDecl.modifiers = AccDefault;
831 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
834 functionDefinition(methodDecl);
836 sourceEnd = methodDecl.sourceEnd;
837 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
838 sourceEnd = methodDecl.declarationSourceStart + 1;
840 methodDecl.declarationSourceEnd = sourceEnd;
841 methodDecl.sourceEnd = sourceEnd;
844 } else if (token == TokenNamedeclare) {
845 // T_DECLARE '(' declare_list ')' declare_statement
847 if (token != TokenNameLPAREN) {
848 throwSyntaxError("'(' expected in 'declare' statement.");
852 if (token != TokenNameRPAREN) {
853 throwSyntaxError("')' expected in 'declare' statement.");
858 } else if (token == TokenNametry) {
860 if (token != TokenNameLBRACE) {
861 throwSyntaxError("'{' expected in 'try' statement.");
865 if (token != TokenNameRBRACE) {
866 throwSyntaxError("'}' expected in 'try' statement.");
870 } else if (token == TokenNamecatch) {
872 if (token != TokenNameLPAREN) {
873 throwSyntaxError("'(' expected in 'catch' statement.");
876 fully_qualified_class_name();
877 if (token != TokenNameVariable) {
878 throwSyntaxError("Variable expected in 'catch' statement.");
882 if (token != TokenNameRPAREN) {
883 throwSyntaxError("')' expected in 'catch' statement.");
886 if (token != TokenNameLBRACE) {
887 throwSyntaxError("'{' expected in 'catch' statement.");
890 if (token != TokenNameRBRACE) {
892 if (token != TokenNameRBRACE) {
893 throwSyntaxError("'}' expected in 'catch' statement.");
897 additional_catches();
899 } else if (token == TokenNamethrow) {
902 if (token == TokenNameSEMICOLON) {
905 throwSyntaxError("';' expected after 'throw' exxpression.");
908 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
910 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
911 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
912 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
913 typeDecl.name = new char[] { ' ' };
914 // default super class
915 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
916 compilationUnit.types.add(typeDecl);
917 pushOnAstStack(typeDecl);
918 unticked_class_declaration_statement(typeDecl);
926 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
927 } else if (token == TokenNameLBRACE) {
929 if (token != TokenNameRBRACE) {
930 statement = statementList();
932 if (token == TokenNameRBRACE) {
936 throwSyntaxError("'}' expected.");
939 if (token != TokenNameSEMICOLON) {
942 if (token == TokenNameSEMICOLON) {
946 if (token == TokenNameRBRACE) {
947 reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
949 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
950 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
960 private void declare_statement() {
962 // | ':' inner_statement_list T_ENDDECLARE ';'
964 if (token == TokenNameCOLON) {
966 // TODO: implement inner_statement_list();
968 if (token != TokenNameenddeclare) {
969 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
972 if (token != TokenNameSEMICOLON) {
973 throwSyntaxError("';' expected after 'enddeclare' keyword.");
981 private void declare_list() {
982 // T_STRING '=' static_scalar
983 // | declare_list ',' T_STRING '=' static_scalar
985 if (token != TokenNameIdentifier) {
986 throwSyntaxError("Identifier expected in 'declare' list.");
989 if (token != TokenNameEQUAL) {
990 throwSyntaxError("'=' expected in 'declare' list.");
994 if (token != TokenNameCOMMA) {
1001 private void additional_catches() {
1002 while (token == TokenNamecatch) {
1004 if (token != TokenNameLPAREN) {
1005 throwSyntaxError("'(' expected in 'catch' statement.");
1008 fully_qualified_class_name();
1009 if (token != TokenNameVariable) {
1010 throwSyntaxError("Variable expected in 'catch' statement.");
1014 if (token != TokenNameRPAREN) {
1015 throwSyntaxError("')' expected in 'catch' statement.");
1018 if (token != TokenNameLBRACE) {
1019 throwSyntaxError("'{' expected in 'catch' statement.");
1022 if (token != TokenNameRBRACE) {
1025 if (token != TokenNameRBRACE) {
1026 throwSyntaxError("'}' expected in 'catch' statement.");
1032 private void foreach_variable() {
1035 if (token == TokenNameAND) {
1041 private void foreach_optional_arg() {
1043 // | T_DOUBLE_ARROW foreach_variable
1044 if (token == TokenNameEQUAL_GREATER) {
1050 private void global_var_list() {
1052 // global_var_list ',' global_var
1054 HashSet set = peekVariableSet();
1057 if (token != TokenNameCOMMA) {
1064 private void global_var(HashSet set) {
1068 // | '$' '{' expr '}'
1069 if (token == TokenNameVariable) {
1070 if (fMethodVariables != null) {
1071 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1072 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1074 addVariableSet(set);
1076 } else if (token == TokenNameDOLLAR) {
1078 if (token == TokenNameLBRACE) {
1081 if (token != TokenNameRBRACE) {
1082 throwSyntaxError("'}' expected in global variable.");
1091 private void static_var_list() {
1093 // static_var_list ',' T_VARIABLE
1094 // | static_var_list ',' T_VARIABLE '=' static_scalar
1096 // | T_VARIABLE '=' static_scalar,
1097 HashSet set = peekVariableSet();
1099 if (token == TokenNameVariable) {
1100 if (fMethodVariables != null) {
1101 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1102 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1104 addVariableSet(set);
1106 if (token == TokenNameEQUAL) {
1110 if (token != TokenNameCOMMA) {
1120 private void unset_variables() {
1123 // | unset_variables ',' unset_variable
1127 variable(false, false);
1128 if (token != TokenNameCOMMA) {
1135 private final void initializeModifiers() {
1137 this.modifiersSourceStart = -1;
1140 private final void checkAndSetModifiers(int flag) {
1141 this.modifiers |= flag;
1142 if (this.modifiersSourceStart < 0)
1143 this.modifiersSourceStart = this.scanner.startPosition;
1146 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1147 initializeModifiers();
1148 if (token == TokenNameinterface) {
1149 // interface_entry T_STRING
1150 // interface_extends_list
1151 // '{' class_statement_list '}'
1152 checkAndSetModifiers(AccInterface);
1154 typeDecl.modifiers = this.modifiers;
1155 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1156 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1157 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1158 typeDecl.name = scanner.getCurrentIdentifierSource();
1159 if (token > TokenNameKEYWORD) {
1160 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1161 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1162 // throwSyntaxError("Don't use a keyword for interface declaration ["
1163 // + scanner.toStringAction(token) + "].",
1164 // typeDecl.sourceStart, typeDecl.sourceEnd);
1167 interface_extends_list(typeDecl);
1169 typeDecl.name = new char[] { ' ' };
1170 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1174 // class_entry_type T_STRING extends_from
1176 // '{' class_statement_list'}'
1178 typeDecl.modifiers = this.modifiers;
1179 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1180 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1182 // identifier 'extends' identifier
1183 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1184 typeDecl.name = scanner.getCurrentIdentifierSource();
1185 if (token > TokenNameKEYWORD) {
1186 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1187 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1188 // throwSyntaxError("Don't use a keyword for class declaration [" +
1189 // scanner.toStringAction(token) + "].",
1190 // typeDecl.sourceStart, typeDecl.sourceEnd);
1195 // | T_EXTENDS fully_qualified_class_name
1196 if (token == TokenNameextends) {
1197 interface_extends_list(typeDecl);
1199 // if (token != TokenNameIdentifier) {
1200 // throwSyntaxError("Class name expected after keyword
1202 // scanner.getCurrentTokenStartPosition(), scanner
1203 // .getCurrentTokenEndPosition());
1206 implements_list(typeDecl);
1208 typeDecl.name = new char[] { ' ' };
1209 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1213 // '{' class_statement_list '}'
1214 if (token == TokenNameLBRACE) {
1216 if (token != TokenNameRBRACE) {
1217 ArrayList list = new ArrayList();
1218 class_statement_list(list);
1219 typeDecl.fields = new FieldDeclaration[list.size()];
1220 for (int i = 0; i < list.size(); i++) {
1221 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1224 if (token == TokenNameRBRACE) {
1225 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1228 throwSyntaxError("'}' expected at end of class body.");
1231 throwSyntaxError("'{' expected at start of class body.");
1235 private void class_entry_type() {
1237 // | T_ABSTRACT T_CLASS
1238 // | T_FINAL T_CLASS
1239 if (token == TokenNameclass) {
1241 } else if (token == TokenNameabstract) {
1242 checkAndSetModifiers(AccAbstract);
1244 if (token != TokenNameclass) {
1245 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1248 } else if (token == TokenNamefinal) {
1249 checkAndSetModifiers(AccFinal);
1251 if (token != TokenNameclass) {
1252 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1256 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1260 // private void class_extends(TypeDeclaration typeDecl) {
1262 // // | T_EXTENDS interface_list
1263 // if (token == TokenNameextends) {
1266 // if (token == TokenNameIdentifier) {
1269 // throwSyntaxError("Class name expected after keyword 'extends'.");
1274 private void interface_extends_list(TypeDeclaration typeDecl) {
1276 // | T_EXTENDS interface_list
1277 if (token == TokenNameextends) {
1283 private void implements_list(TypeDeclaration typeDecl) {
1285 // | T_IMPLEMENTS interface_list
1286 if (token == TokenNameimplements) {
1292 private void interface_list() {
1294 // fully_qualified_class_name
1295 // | interface_list ',' fully_qualified_class_name
1297 if (token == TokenNameIdentifier) {
1300 throwSyntaxError("Interface name expected after keyword 'implements'.");
1302 if (token != TokenNameCOMMA) {
1309 // private void classBody(TypeDeclaration typeDecl) {
1310 // //'{' [class-element-list] '}'
1311 // if (token == TokenNameLBRACE) {
1313 // if (token != TokenNameRBRACE) {
1314 // class_statement_list();
1316 // if (token == TokenNameRBRACE) {
1317 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1320 // throwSyntaxError("'}' expected at end of class body.");
1323 // throwSyntaxError("'{' expected at start of class body.");
1326 private void class_statement_list(ArrayList list) {
1329 class_statement(list);
1330 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1331 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1332 || token == TokenNameconst) {
1335 if (token == TokenNameRBRACE) {
1338 throwSyntaxError("'}' at end of class statement.");
1339 } catch (SyntaxError sytaxErr1) {
1340 boolean tokenize = scanner.tokenizeStrings;
1342 scanner.tokenizeStrings = true;
1345 // if an error occured,
1346 // try to find keywords
1347 // to parse the rest of the string
1348 while (token != TokenNameEOF) {
1349 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1350 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1351 || token == TokenNameconst) {
1354 // System.out.println(scanner.toStringAction(token));
1357 if (token == TokenNameEOF) {
1361 scanner.tokenizeStrings = tokenize;
1367 private void class_statement(ArrayList list) {
1369 // variable_modifiers class_variable_declaration ';'
1370 // | class_constant_declaration ';'
1371 // | method_modifiers T_FUNCTION is_reference T_STRING
1372 // '(' parameter_list ')' method_body
1373 initializeModifiers();
1374 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1376 if (token == TokenNamevar) {
1377 checkAndSetModifiers(AccPublic);
1378 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1379 referenceContext, compilationUnit.compilationResult);
1381 class_variable_declaration(declarationSourceStart, list);
1382 } else if (token == TokenNameconst) {
1383 checkAndSetModifiers(AccFinal | AccPublic);
1384 class_constant_declaration(declarationSourceStart, list);
1385 if (token != TokenNameSEMICOLON) {
1386 throwSyntaxError("';' expected after class const declaration.");
1390 boolean hasModifiers = member_modifiers();
1391 if (token == TokenNamefunction) {
1392 if (!hasModifiers) {
1393 checkAndSetModifiers(AccPublic);
1395 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1396 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1397 methodDecl.modifiers = this.modifiers;
1398 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1401 functionDefinition(methodDecl);
1403 int sourceEnd = methodDecl.sourceEnd;
1404 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1405 sourceEnd = methodDecl.declarationSourceStart + 1;
1407 methodDecl.declarationSourceEnd = sourceEnd;
1408 methodDecl.sourceEnd = sourceEnd;
1411 if (!hasModifiers) {
1412 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1414 class_variable_declaration(declarationSourceStart, list);
1419 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1420 // class_constant_declaration ',' T_STRING '=' static_scalar
1421 // | T_CONST T_STRING '=' static_scalar
1422 if (token != TokenNameconst) {
1423 throwSyntaxError("'const' keyword expected in class declaration.");
1428 if (token != TokenNameIdentifier) {
1429 throwSyntaxError("Identifier expected in class const declaration.");
1431 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1432 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1433 fieldDeclaration.modifiers = this.modifiers;
1434 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1435 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1436 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1437 // fieldDeclaration.type
1438 list.add(fieldDeclaration);
1440 if (token != TokenNameEQUAL) {
1441 throwSyntaxError("'=' expected in class const declaration.");
1445 if (token != TokenNameCOMMA) {
1446 break; // while(true)-loop
1452 // private void variable_modifiers() {
1453 // // variable_modifiers:
1454 // // non_empty_member_modifiers
1456 // initializeModifiers();
1457 // if (token == TokenNamevar) {
1458 // checkAndSetModifiers(AccPublic);
1459 // reportSyntaxError(
1460 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1462 // modifier for field declarations.",
1463 // scanner.getCurrentTokenStartPosition(), scanner
1464 // .getCurrentTokenEndPosition());
1467 // if (!member_modifiers()) {
1468 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1469 // field declarations.");
1473 // private void method_modifiers() {
1474 // //method_modifiers:
1476 // //| non_empty_member_modifiers
1477 // initializeModifiers();
1478 // if (!member_modifiers()) {
1479 // checkAndSetModifiers(AccPublic);
1482 private boolean member_modifiers() {
1489 boolean foundToken = false;
1491 if (token == TokenNamepublic) {
1492 checkAndSetModifiers(AccPublic);
1495 } else if (token == TokenNameprotected) {
1496 checkAndSetModifiers(AccProtected);
1499 } else if (token == TokenNameprivate) {
1500 checkAndSetModifiers(AccPrivate);
1503 } else if (token == TokenNamestatic) {
1504 checkAndSetModifiers(AccStatic);
1507 } else if (token == TokenNameabstract) {
1508 checkAndSetModifiers(AccAbstract);
1511 } else if (token == TokenNamefinal) {
1512 checkAndSetModifiers(AccFinal);
1522 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1523 // class_variable_declaration:
1524 // class_variable_declaration ',' T_VARIABLE
1525 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1527 // | T_VARIABLE '=' static_scalar
1528 char[] classVariable;
1530 if (token == TokenNameVariable) {
1531 classVariable = scanner.getCurrentIdentifierSource();
1532 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1534 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1535 .getCurrentTokenEndPosition());
1536 fieldDeclaration.modifiers = this.modifiers;
1537 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1538 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1539 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1540 list.add(fieldDeclaration);
1541 if (fTypeVariables != null) {
1542 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1543 fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1546 if (token == TokenNameEQUAL) {
1551 // if (token == TokenNamethis) {
1552 // throwSyntaxError("'$this' not allowed after keyword 'public'
1553 // 'protected' 'private' 'var'.");
1555 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1557 if (token != TokenNameCOMMA) {
1562 if (token != TokenNameSEMICOLON) {
1563 throwSyntaxError("';' expected after field declaration.");
1568 private void functionDefinition(MethodDeclaration methodDecl) {
1569 boolean isAbstract = false;
1571 if (compilationUnit != null) {
1572 compilationUnit.types.add(methodDecl);
1575 ASTNode node = astStack[astPtr];
1576 if (node instanceof TypeDeclaration) {
1577 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1578 if (typeDecl.methods == null) {
1579 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1581 AbstractMethodDeclaration[] newMethods;
1582 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1583 typeDecl.methods.length);
1584 newMethods[typeDecl.methods.length] = methodDecl;
1585 typeDecl.methods = newMethods;
1587 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1589 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1595 pushFunctionVariableSet();
1596 functionDeclarator(methodDecl);
1597 if (token == TokenNameSEMICOLON) {
1599 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1600 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1605 functionBody(methodDecl);
1607 if (!fStackUnassigned.isEmpty()) {
1608 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1613 private void functionDeclarator(MethodDeclaration methodDecl) {
1614 // identifier '(' [parameter-list] ')'
1615 if (token == TokenNameAND) {
1618 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1619 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1620 if (Scanner.isIdentifierOrKeyword(token)) {
1621 methodDecl.selector = scanner.getCurrentIdentifierSource();
1622 if (token > TokenNameKEYWORD) {
1623 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1624 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1627 if (token == TokenNameLPAREN) {
1630 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1631 throwSyntaxError("'(' expected in function declaration.");
1633 if (token != TokenNameRPAREN) {
1634 parameter_list(methodDecl);
1636 if (token != TokenNameRPAREN) {
1637 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1638 throwSyntaxError("')' expected in function declaration.");
1640 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1644 methodDecl.selector = "<undefined>".toCharArray();
1645 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1646 throwSyntaxError("Function name expected after keyword 'function'.");
1651 private void parameter_list(MethodDeclaration methodDecl) {
1652 // non_empty_parameter_list
1654 non_empty_parameter_list(methodDecl, true);
1657 private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1658 // optional_class_type T_VARIABLE
1659 // | optional_class_type '&' T_VARIABLE
1660 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1661 // | optional_class_type T_VARIABLE '=' static_scalar
1662 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1663 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1664 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1666 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1668 char[] typeIdentifier = null;
1669 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1670 HashSet set = peekVariableSet();
1672 if (token == TokenNameIdentifier) {
1673 typeIdentifier = scanner.getCurrentIdentifierSource();
1676 if (token == TokenNameAND) {
1679 if (token == TokenNameVariable) {
1680 if (fMethodVariables != null) {
1682 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1683 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1685 info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1687 info.typeIdentifier = typeIdentifier;
1688 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1690 addVariableSet(set);
1692 if (token == TokenNameEQUAL) {
1697 throwSyntaxError("Variable expected in parameter list.");
1699 if (token != TokenNameCOMMA) {
1706 if (!empty_allowed) {
1707 throwSyntaxError("Identifier expected in parameter list.");
1711 private void optional_class_type() {
1716 // private void parameterDeclaration() {
1718 // //variable-reference
1719 // if (token == TokenNameAND) {
1721 // if (isVariable()) {
1724 // throwSyntaxError("Variable expected after reference operator '&'.");
1727 // //variable '=' constant
1728 // if (token == TokenNameVariable) {
1730 // if (token == TokenNameEQUAL) {
1736 // // if (token == TokenNamethis) {
1737 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1738 // // declaration.");
1742 private void labeledStatementList() {
1743 if (token != TokenNamecase && token != TokenNamedefault) {
1744 throwSyntaxError("'case' or 'default' expected.");
1747 if (token == TokenNamecase) {
1749 expr(); // constant();
1750 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1752 if (token == TokenNamecase || token == TokenNamedefault) {
1753 // empty case statement ?
1758 // else if (token == TokenNameSEMICOLON) {
1760 // "':' expected after 'case' keyword (Found token: " +
1761 // scanner.toStringAction(token) + ")",
1762 // scanner.getCurrentTokenStartPosition(),
1763 // scanner.getCurrentTokenEndPosition(),
1766 // if (token == TokenNamecase) { // empty case statement ?
1772 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1774 } else { // TokenNamedefault
1776 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1778 if (token == TokenNameRBRACE) {
1779 // empty default case
1782 if (token != TokenNamecase) {
1786 throwSyntaxError("':' character expected after 'default'.");
1789 } while (token == TokenNamecase || token == TokenNamedefault);
1792 private void ifStatementColon(IfStatement iState) {
1793 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1794 // new_else_single T_ENDIF ';'
1795 HashSet assignedVariableSet = null;
1797 Block b = inner_statement_list();
1798 iState.thenStatement = b;
1799 checkUnreachable(iState, b);
1801 assignedVariableSet = removeIfVariableSet();
1803 if (token == TokenNameelseif) {
1805 pushIfVariableSet();
1806 new_elseif_list(iState);
1808 HashSet set = removeIfVariableSet();
1809 if (assignedVariableSet != null && set != null) {
1810 assignedVariableSet.addAll(set);
1815 pushIfVariableSet();
1816 new_else_single(iState);
1818 HashSet set = removeIfVariableSet();
1819 if (assignedVariableSet != null) {
1820 HashSet topSet = peekVariableSet();
1821 if (topSet != null) {
1825 topSet.addAll(assignedVariableSet);
1829 if (token != TokenNameendif) {
1830 throwSyntaxError("'endif' expected.");
1833 if (token != TokenNameSEMICOLON) {
1834 reportSyntaxError("';' expected after if-statement.");
1835 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1837 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1842 private void ifStatement(IfStatement iState) {
1843 // T_IF '(' expr ')' statement elseif_list else_single
1844 HashSet assignedVariableSet = null;
1846 pushIfVariableSet();
1847 Statement s = statement();
1848 iState.thenStatement = s;
1849 checkUnreachable(iState, s);
1851 assignedVariableSet = removeIfVariableSet();
1854 if (token == TokenNameelseif) {
1856 pushIfVariableSet();
1857 elseif_list(iState);
1859 HashSet set = removeIfVariableSet();
1860 if (assignedVariableSet != null && set != null) {
1861 assignedVariableSet.addAll(set);
1866 pushIfVariableSet();
1867 else_single(iState);
1869 HashSet set = removeIfVariableSet();
1870 if (assignedVariableSet != null) {
1871 HashSet topSet = peekVariableSet();
1872 if (topSet != null) {
1876 topSet.addAll(assignedVariableSet);
1882 private void elseif_list(IfStatement iState) {
1884 // | elseif_list T_ELSEIF '(' expr ')' statement
1885 ArrayList conditionList = new ArrayList();
1886 ArrayList statementList = new ArrayList();
1889 while (token == TokenNameelseif) {
1891 if (token == TokenNameLPAREN) {
1894 throwSyntaxError("'(' expected after 'elseif' keyword.");
1897 conditionList.add(e);
1898 if (token == TokenNameRPAREN) {
1901 throwSyntaxError("')' expected after 'elseif' condition.");
1904 statementList.add(s);
1905 checkUnreachable(iState, s);
1907 iState.elseifConditions = new Expression[conditionList.size()];
1908 iState.elseifStatements = new Statement[statementList.size()];
1909 conditionList.toArray(iState.elseifConditions);
1910 statementList.toArray(iState.elseifStatements);
1913 private void new_elseif_list(IfStatement iState) {
1915 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1916 ArrayList conditionList = new ArrayList();
1917 ArrayList statementList = new ArrayList();
1920 while (token == TokenNameelseif) {
1922 if (token == TokenNameLPAREN) {
1925 throwSyntaxError("'(' expected after 'elseif' keyword.");
1928 conditionList.add(e);
1929 if (token == TokenNameRPAREN) {
1932 throwSyntaxError("')' expected after 'elseif' condition.");
1934 if (token == TokenNameCOLON) {
1937 throwSyntaxError("':' expected after 'elseif' keyword.");
1939 b = inner_statement_list();
1940 statementList.add(b);
1941 checkUnreachable(iState, b);
1943 iState.elseifConditions = new Expression[conditionList.size()];
1944 iState.elseifStatements = new Statement[statementList.size()];
1945 conditionList.toArray(iState.elseifConditions);
1946 statementList.toArray(iState.elseifStatements);
1949 private void else_single(IfStatement iState) {
1952 if (token == TokenNameelse) {
1954 Statement s = statement();
1955 iState.elseStatement = s;
1956 checkUnreachable(iState, s);
1958 iState.checkUnreachable = false;
1960 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1963 private void new_else_single(IfStatement iState) {
1965 // | T_ELSE ':' inner_statement_list
1966 if (token == TokenNameelse) {
1968 if (token == TokenNameCOLON) {
1971 throwSyntaxError("':' expected after 'else' keyword.");
1973 Block b = inner_statement_list();
1974 iState.elseStatement = b;
1975 checkUnreachable(iState, b);
1977 iState.checkUnreachable = false;
1981 private Block inner_statement_list() {
1982 // inner_statement_list inner_statement
1984 return statementList();
1991 private void checkUnreachable(IfStatement iState, Statement s) {
1992 if (s instanceof Block) {
1993 Block b = (Block) s;
1994 if (b.statements == null || b.statements.length == 0) {
1995 iState.checkUnreachable = false;
1997 int off = b.statements.length - 1;
1998 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
1999 && !(b.statements[off] instanceof BreakStatement)) {
2000 if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2001 iState.checkUnreachable = false;
2006 if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2007 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2008 iState.checkUnreachable = false;
2014 // private void elseifStatementList() {
2016 // elseifStatement();
2018 // case TokenNameelse:
2020 // if (token == TokenNameCOLON) {
2022 // if (token != TokenNameendif) {
2027 // if (token == TokenNameif) { //'else if'
2030 // throwSyntaxError("':' expected after 'else'.");
2034 // case TokenNameelseif:
2043 // private void elseifStatement() {
2044 // if (token == TokenNameLPAREN) {
2047 // if (token != TokenNameRPAREN) {
2048 // throwSyntaxError("')' expected in else-if-statement.");
2051 // if (token != TokenNameCOLON) {
2052 // throwSyntaxError("':' expected in else-if-statement.");
2055 // if (token != TokenNameendif) {
2061 private void switchStatement() {
2062 if (token == TokenNameCOLON) {
2063 // ':' [labeled-statement-list] 'endswitch' ';'
2065 labeledStatementList();
2066 if (token != TokenNameendswitch) {
2067 throwSyntaxError("'endswitch' expected.");
2070 if (token != TokenNameSEMICOLON) {
2071 throwSyntaxError("';' expected after switch-statement.");
2075 // '{' [labeled-statement-list] '}'
2076 if (token != TokenNameLBRACE) {
2077 throwSyntaxError("'{' expected in switch statement.");
2080 if (token != TokenNameRBRACE) {
2081 labeledStatementList();
2083 if (token != TokenNameRBRACE) {
2084 throwSyntaxError("'}' expected in switch statement.");
2090 private void forStatement() {
2091 if (token == TokenNameCOLON) {
2094 if (token != TokenNameendfor) {
2095 throwSyntaxError("'endfor' expected.");
2098 if (token != TokenNameSEMICOLON) {
2099 throwSyntaxError("';' expected after for-statement.");
2107 private void whileStatement() {
2108 // ':' statement-list 'endwhile' ';'
2109 if (token == TokenNameCOLON) {
2112 if (token != TokenNameendwhile) {
2113 throwSyntaxError("'endwhile' expected.");
2116 if (token != TokenNameSEMICOLON) {
2117 throwSyntaxError("';' expected after while-statement.");
2125 private void foreachStatement() {
2126 if (token == TokenNameCOLON) {
2129 if (token != TokenNameendforeach) {
2130 throwSyntaxError("'endforeach' expected.");
2133 if (token != TokenNameSEMICOLON) {
2134 throwSyntaxError("';' expected after foreach-statement.");
2142 // private void exitStatus() {
2143 // if (token == TokenNameLPAREN) {
2146 // throwSyntaxError("'(' expected in 'exit-status'.");
2148 // if (token != TokenNameRPAREN) {
2151 // if (token == TokenNameRPAREN) {
2154 // throwSyntaxError("')' expected after 'exit-status'.");
2157 private void expressionList() {
2160 if (token == TokenNameCOMMA) {
2168 private Expression expr() {
2170 // | expr_without_variable
2171 // if (token!=TokenNameEOF) {
2172 if (Scanner.TRACE) {
2173 System.out.println("TRACE: expr()");
2175 return expr_without_variable(true);
2179 private Expression expr_without_variable(boolean only_variable) {
2180 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2181 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2182 Expression expression = new Expression();
2183 expression.sourceStart = exprSourceStart;
2184 // default, may be overwritten
2185 expression.sourceEnd = exprSourceEnd;
2187 // internal_functions_in_yacc
2196 // | T_INC rw_variable
2197 // | T_DEC rw_variable
2198 // | T_INT_CAST expr
2199 // | T_DOUBLE_CAST expr
2200 // | T_STRING_CAST expr
2201 // | T_ARRAY_CAST expr
2202 // | T_OBJECT_CAST expr
2203 // | T_BOOL_CAST expr
2204 // | T_UNSET_CAST expr
2205 // | T_EXIT exit_expr
2207 // | T_ARRAY '(' array_pair_list ')'
2208 // | '`' encaps_list '`'
2209 // | T_LIST '(' assignment_list ')' '=' expr
2210 // | T_NEW class_name_reference ctor_arguments
2211 // | variable '=' expr
2212 // | variable '=' '&' variable
2213 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2214 // | variable T_PLUS_EQUAL expr
2215 // | variable T_MINUS_EQUAL expr
2216 // | variable T_MUL_EQUAL expr
2217 // | variable T_DIV_EQUAL expr
2218 // | variable T_CONCAT_EQUAL expr
2219 // | variable T_MOD_EQUAL expr
2220 // | variable T_AND_EQUAL expr
2221 // | variable T_OR_EQUAL expr
2222 // | variable T_XOR_EQUAL expr
2223 // | variable T_SL_EQUAL expr
2224 // | variable T_SR_EQUAL expr
2225 // | rw_variable T_INC
2226 // | rw_variable T_DEC
2227 // | expr T_BOOLEAN_OR expr
2228 // | expr T_BOOLEAN_AND expr
2229 // | expr T_LOGICAL_OR expr
2230 // | expr T_LOGICAL_AND expr
2231 // | expr T_LOGICAL_XOR expr
2243 // | expr T_IS_IDENTICAL expr
2244 // | expr T_IS_NOT_IDENTICAL expr
2245 // | expr T_IS_EQUAL expr
2246 // | expr T_IS_NOT_EQUAL expr
2248 // | expr T_IS_SMALLER_OR_EQUAL expr
2250 // | expr T_IS_GREATER_OR_EQUAL expr
2251 // | expr T_INSTANCEOF class_name_reference
2252 // | expr '?' expr ':' expr
2253 if (Scanner.TRACE) {
2254 System.out.println("TRACE: expr_without_variable() PART 1");
2257 case TokenNameisset:
2258 // T_ISSET '(' isset_variables ')'
2260 if (token != TokenNameLPAREN) {
2261 throwSyntaxError("'(' expected after keyword 'isset'");
2265 if (token != TokenNameRPAREN) {
2266 throwSyntaxError("')' expected after keyword 'isset'");
2270 case TokenNameempty:
2272 if (token != TokenNameLPAREN) {
2273 throwSyntaxError("'(' expected after keyword 'empty'");
2276 variable(true, false);
2277 if (token != TokenNameRPAREN) {
2278 throwSyntaxError("')' expected after keyword 'empty'");
2283 case TokenNameinclude:
2284 case TokenNameinclude_once:
2285 case TokenNamerequire:
2286 case TokenNamerequire_once:
2287 internal_functions_in_yacc();
2290 case TokenNameLPAREN:
2293 if (token == TokenNameRPAREN) {
2296 throwSyntaxError("')' expected in expression.");
2306 // | T_INT_CAST expr
2307 // | T_DOUBLE_CAST expr
2308 // | T_STRING_CAST expr
2309 // | T_ARRAY_CAST expr
2310 // | T_OBJECT_CAST expr
2311 // | T_BOOL_CAST expr
2312 // | T_UNSET_CAST expr
2313 case TokenNameclone:
2314 case TokenNameprint:
2317 case TokenNameMINUS:
2319 case TokenNameTWIDDLE:
2320 case TokenNameintCAST:
2321 case TokenNamedoubleCAST:
2322 case TokenNamestringCAST:
2323 case TokenNamearrayCAST:
2324 case TokenNameobjectCAST:
2325 case TokenNameboolCAST:
2326 case TokenNameunsetCAST:
2336 // | T_STRING_VARNAME
2338 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2339 // | '`' encaps_list '`'
2341 // | '`' encaps_list '`'
2342 // case TokenNameEncapsedString0:
2343 // scanner.encapsedStringStack.push(new Character('`'));
2346 // if (token == TokenNameEncapsedString0) {
2349 // if (token != TokenNameEncapsedString0) {
2350 // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2351 // scanner.toStringAction(token) + " )");
2355 // scanner.encapsedStringStack.pop();
2359 // // | '\'' encaps_list '\''
2360 // case TokenNameEncapsedString1:
2361 // scanner.encapsedStringStack.push(new Character('\''));
2364 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2365 // if (token == TokenNameEncapsedString1) {
2367 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2368 // exprSourceStart, scanner
2369 // .getCurrentTokenEndPosition());
2372 // if (token != TokenNameEncapsedString1) {
2373 // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2374 // + scanner.toStringAction(token) + " )");
2377 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2378 // exprSourceStart, scanner
2379 // .getCurrentTokenEndPosition());
2383 // scanner.encapsedStringStack.pop();
2387 // //| '"' encaps_list '"'
2388 // case TokenNameEncapsedString2:
2389 // scanner.encapsedStringStack.push(new Character('"'));
2392 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2393 // if (token == TokenNameEncapsedString2) {
2395 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2396 // exprSourceStart, scanner
2397 // .getCurrentTokenEndPosition());
2400 // if (token != TokenNameEncapsedString2) {
2401 // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2402 // scanner.toStringAction(token) + " )");
2405 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2406 // exprSourceStart, scanner
2407 // .getCurrentTokenEndPosition());
2411 // scanner.encapsedStringStack.pop();
2415 case TokenNameStringDoubleQuote:
2416 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2417 .getCurrentTokenEndPosition());
2420 case TokenNameStringSingleQuote:
2421 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2422 .getCurrentTokenEndPosition());
2425 case TokenNameIntegerLiteral:
2426 case TokenNameDoubleLiteral:
2427 case TokenNameStringInterpolated:
2430 case TokenNameCLASS_C:
2431 case TokenNameMETHOD_C:
2432 case TokenNameFUNC_C:
2435 case TokenNameHEREDOC:
2438 case TokenNamearray:
2439 // T_ARRAY '(' array_pair_list ')'
2441 if (token == TokenNameLPAREN) {
2443 if (token == TokenNameRPAREN) {
2448 if (token != TokenNameRPAREN) {
2449 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2453 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2457 // | T_LIST '(' assignment_list ')' '=' expr
2459 if (token == TokenNameLPAREN) {
2462 if (token != TokenNameRPAREN) {
2463 throwSyntaxError("')' expected after 'list' keyword.");
2466 if (token != TokenNameEQUAL) {
2467 throwSyntaxError("'=' expected after 'list' keyword.");
2472 throwSyntaxError("'(' expected after 'list' keyword.");
2476 // | T_NEW class_name_reference ctor_arguments
2478 Expression typeRef = class_name_reference();
2480 if (typeRef != null) {
2481 expression = typeRef;
2484 // | T_INC rw_variable
2485 // | T_DEC rw_variable
2486 case TokenNamePLUS_PLUS:
2487 case TokenNameMINUS_MINUS:
2491 // | variable '=' expr
2492 // | variable '=' '&' variable
2493 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2494 // | variable T_PLUS_EQUAL expr
2495 // | variable T_MINUS_EQUAL expr
2496 // | variable T_MUL_EQUAL expr
2497 // | variable T_DIV_EQUAL expr
2498 // | variable T_CONCAT_EQUAL expr
2499 // | variable T_MOD_EQUAL expr
2500 // | variable T_AND_EQUAL expr
2501 // | variable T_OR_EQUAL expr
2502 // | variable T_XOR_EQUAL expr
2503 // | variable T_SL_EQUAL expr
2504 // | variable T_SR_EQUAL expr
2505 // | rw_variable T_INC
2506 // | rw_variable T_DEC
2507 case TokenNameIdentifier:
2508 case TokenNameVariable:
2509 case TokenNameDOLLAR:
2510 Expression lhs = null;
2511 boolean rememberedVar = false;
2512 if (token == TokenNameIdentifier) {
2513 lhs = identifier(true, true);
2518 lhs = variable(true, true);
2522 if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2523 && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2524 && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2525 && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2526 && token != TokenNameLEFT_SHIFT_EQUAL) {
2527 FieldReference ref = (FieldReference) lhs;
2528 if (!containsVariableSet(ref.token)) {
2529 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart(), ref.sourceEnd(),
2530 referenceContext, compilationUnit.compilationResult);
2531 addVariableSet(ref.token);
2536 case TokenNameEQUAL:
2537 if (lhs != null && lhs instanceof FieldReference) {
2538 addVariableSet(((FieldReference) lhs).token);
2541 if (token == TokenNameAND) {
2543 if (token == TokenNamenew) {
2544 // | variable '=' '&' T_NEW class_name_reference
2547 SingleTypeReference classRef = class_name_reference();
2549 if (classRef != null) {
2550 if (lhs != null && lhs instanceof FieldReference) {
2552 // $var = & new Object();
2553 if (fMethodVariables != null) {
2554 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2555 lhsInfo.reference = classRef;
2556 lhsInfo.typeIdentifier = classRef.token;
2557 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2558 rememberedVar = true;
2563 Expression rhs = variable(false, false);
2564 if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2567 if (fMethodVariables != null) {
2568 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2569 if (rhsInfo != null && rhsInfo.reference != null) {
2570 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2571 lhsInfo.reference = rhsInfo.reference;
2572 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2573 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2574 rememberedVar = true;
2580 Expression rhs = expr();
2581 if (lhs != null && lhs instanceof FieldReference) {
2582 if (rhs != null && rhs instanceof FieldReference) {
2585 if (fMethodVariables != null) {
2586 VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2587 if (rhsInfo != null && rhsInfo.reference != null) {
2588 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2589 lhsInfo.reference = rhsInfo.reference;
2590 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2591 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2592 rememberedVar = true;
2595 } else if (rhs != null && rhs instanceof SingleTypeReference) {
2597 // $var = new Object();
2598 if (fMethodVariables != null) {
2599 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2600 lhsInfo.reference = (SingleTypeReference) rhs;
2601 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2602 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2603 rememberedVar = true;
2608 if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2609 if (fMethodVariables != null) {
2610 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart());
2611 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2615 case TokenNamePLUS_EQUAL:
2616 case TokenNameMINUS_EQUAL:
2617 case TokenNameMULTIPLY_EQUAL:
2618 case TokenNameDIVIDE_EQUAL:
2619 case TokenNameDOT_EQUAL:
2620 case TokenNameREMAINDER_EQUAL:
2621 case TokenNameAND_EQUAL:
2622 case TokenNameOR_EQUAL:
2623 case TokenNameXOR_EQUAL:
2624 case TokenNameRIGHT_SHIFT_EQUAL:
2625 case TokenNameLEFT_SHIFT_EQUAL:
2626 if (lhs != null && lhs instanceof FieldReference) {
2627 addVariableSet(((FieldReference) lhs).token);
2632 case TokenNamePLUS_PLUS:
2633 case TokenNameMINUS_MINUS:
2637 if (!only_variable) {
2638 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2646 if (token != TokenNameINLINE_HTML) {
2647 if (token > TokenNameKEYWORD) {
2651 // System.out.println(scanner.getCurrentTokenStartPosition());
2652 // System.out.println(scanner.getCurrentTokenEndPosition());
2654 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2659 if (Scanner.TRACE) {
2660 System.out.println("TRACE: expr_without_variable() PART 2");
2662 // | expr T_BOOLEAN_OR expr
2663 // | expr T_BOOLEAN_AND expr
2664 // | expr T_LOGICAL_OR expr
2665 // | expr T_LOGICAL_AND expr
2666 // | expr T_LOGICAL_XOR expr
2678 // | expr T_IS_IDENTICAL expr
2679 // | expr T_IS_NOT_IDENTICAL expr
2680 // | expr T_IS_EQUAL expr
2681 // | expr T_IS_NOT_EQUAL expr
2683 // | expr T_IS_SMALLER_OR_EQUAL expr
2685 // | expr T_IS_GREATER_OR_EQUAL expr
2688 case TokenNameOR_OR:
2690 expression = new OR_OR_Expression(expression, expr(), token);
2692 case TokenNameAND_AND:
2694 expression = new AND_AND_Expression(expression, expr(), token);
2696 case TokenNameEQUAL_EQUAL:
2698 expression = new EqualExpression(expression, expr(), token);
2708 case TokenNameMINUS:
2709 case TokenNameMULTIPLY:
2710 case TokenNameDIVIDE:
2711 case TokenNameREMAINDER:
2712 case TokenNameLEFT_SHIFT:
2713 case TokenNameRIGHT_SHIFT:
2714 case TokenNameEQUAL_EQUAL_EQUAL:
2715 case TokenNameNOT_EQUAL_EQUAL:
2716 case TokenNameNOT_EQUAL:
2718 case TokenNameLESS_EQUAL:
2719 case TokenNameGREATER:
2720 case TokenNameGREATER_EQUAL:
2722 expression = new BinaryExpression(expression, expr(), token);
2724 // | expr T_INSTANCEOF class_name_reference
2725 // | expr '?' expr ':' expr
2726 case TokenNameinstanceof:
2728 TypeReference classRef = class_name_reference();
2729 if (classRef != null) {
2730 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2731 expression.sourceStart = exprSourceStart;
2732 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2735 case TokenNameQUESTION:
2737 Expression valueIfTrue = expr();
2738 if (token != TokenNameCOLON) {
2739 throwSyntaxError("':' expected in conditional expression.");
2742 Expression valueIfFalse = expr();
2744 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2750 } catch (SyntaxError e) {
2751 // try to find next token after expression with errors:
2752 if (token == TokenNameSEMICOLON) {
2756 if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2764 private SingleTypeReference class_name_reference() {
2765 // class_name_reference:
2767 // | dynamic_class_name_reference
2768 SingleTypeReference ref = null;
2769 if (Scanner.TRACE) {
2770 System.out.println("TRACE: class_name_reference()");
2772 if (token == TokenNameIdentifier) {
2773 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2777 dynamic_class_name_reference();
2782 private void dynamic_class_name_reference() {
2783 // dynamic_class_name_reference:
2784 // base_variable T_OBJECT_OPERATOR object_property
2785 // dynamic_class_name_variable_properties
2787 if (Scanner.TRACE) {
2788 System.out.println("TRACE: dynamic_class_name_reference()");
2791 if (token == TokenNameMINUS_GREATER) {
2794 dynamic_class_name_variable_properties();
2798 private void dynamic_class_name_variable_properties() {
2799 // dynamic_class_name_variable_properties:
2800 // dynamic_class_name_variable_properties
2801 // dynamic_class_name_variable_property
2803 if (Scanner.TRACE) {
2804 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2806 while (token == TokenNameMINUS_GREATER) {
2807 dynamic_class_name_variable_property();
2811 private void dynamic_class_name_variable_property() {
2812 // dynamic_class_name_variable_property:
2813 // T_OBJECT_OPERATOR object_property
2814 if (Scanner.TRACE) {
2815 System.out.println("TRACE: dynamic_class_name_variable_property()");
2817 if (token == TokenNameMINUS_GREATER) {
2823 private void ctor_arguments() {
2826 // | '(' function_call_parameter_list ')'
2827 if (token == TokenNameLPAREN) {
2829 if (token == TokenNameRPAREN) {
2833 non_empty_function_call_parameter_list();
2834 if (token != TokenNameRPAREN) {
2835 throwSyntaxError("')' expected in ctor_arguments.");
2841 private void assignment_list() {
2843 // assignment_list ',' assignment_list_element
2844 // | assignment_list_element
2846 assignment_list_element();
2847 if (token != TokenNameCOMMA) {
2854 private void assignment_list_element() {
2855 // assignment_list_element:
2857 // | T_LIST '(' assignment_list ')'
2859 if (token == TokenNameVariable) {
2860 variable(true, false);
2861 } else if (token == TokenNameDOLLAR) {
2862 variable(false, false);
2864 if (token == TokenNamelist) {
2866 if (token == TokenNameLPAREN) {
2869 if (token != TokenNameRPAREN) {
2870 throwSyntaxError("')' expected after 'list' keyword.");
2874 throwSyntaxError("'(' expected after 'list' keyword.");
2880 private void array_pair_list() {
2883 // | non_empty_array_pair_list possible_comma
2884 non_empty_array_pair_list();
2885 if (token == TokenNameCOMMA) {
2890 private void non_empty_array_pair_list() {
2891 // non_empty_array_pair_list:
2892 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2893 // | non_empty_array_pair_list ',' expr
2894 // | expr T_DOUBLE_ARROW expr
2896 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2897 // | non_empty_array_pair_list ',' '&' w_variable
2898 // | expr T_DOUBLE_ARROW '&' w_variable
2901 if (token == TokenNameAND) {
2903 variable(true, false);
2906 if (token == TokenNameAND) {
2908 variable(true, false);
2909 } else if (token == TokenNameEQUAL_GREATER) {
2911 if (token == TokenNameAND) {
2913 variable(true, false);
2919 if (token != TokenNameCOMMA) {
2923 if (token == TokenNameRPAREN) {
2929 // private void variableList() {
2932 // if (token == TokenNameCOMMA) {
2939 private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2940 // variable_without_objects:
2941 // reference_variable
2942 // | simple_indirect_reference reference_variable
2943 if (Scanner.TRACE) {
2944 System.out.println("TRACE: variable_without_objects()");
2946 while (token == TokenNameDOLLAR) {
2949 return reference_variable(lefthandside, ignoreVar);
2952 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2954 // T_STRING '(' function_call_parameter_list ')'
2955 // | class_constant '(' function_call_parameter_list ')'
2956 // | static_member '(' function_call_parameter_list ')'
2957 // | variable_without_objects '(' function_call_parameter_list ')'
2958 char[] defineName = null;
2959 char[] ident = null;
2962 Expression ref = null;
2963 if (Scanner.TRACE) {
2964 System.out.println("TRACE: function_call()");
2966 if (token == TokenNameIdentifier) {
2967 ident = scanner.getCurrentIdentifierSource();
2969 startPos = scanner.getCurrentTokenStartPosition();
2970 endPos = scanner.getCurrentTokenEndPosition();
2973 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2977 if (token == TokenNameIdentifier) {
2982 variable_without_objects(true, false);
2987 ref = variable_without_objects(lefthandside, ignoreVar);
2989 if (token != TokenNameLPAREN) {
2990 if (defineName != null) {
2991 // does this identifier contain only uppercase characters?
2992 if (defineName.length == 3) {
2993 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2996 } else if (defineName.length == 4) {
2997 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2999 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3002 } else if (defineName.length == 5) {
3003 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3007 if (defineName != null) {
3008 for (int i = 0; i < defineName.length; i++) {
3009 if (Character.isLowerCase(defineName[i])) {
3010 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3018 if (token == TokenNameRPAREN) {
3022 non_empty_function_call_parameter_list();
3023 if (token != TokenNameRPAREN) {
3024 String functionName;
3025 if (ident == null) {
3026 functionName = new String(" ");
3028 functionName = new String(ident);
3030 throwSyntaxError("')' expected in function call (" + functionName + ").");
3037 // private void function_call_parameter_list() {
3038 // function_call_parameter_list:
3039 // non_empty_function_call_parameter_list { $$ = $1; }
3042 private void non_empty_function_call_parameter_list() {
3043 // non_empty_function_call_parameter_list:
3044 // expr_without_variable
3047 // | non_empty_function_call_parameter_list ',' expr_without_variable
3048 // | non_empty_function_call_parameter_list ',' variable
3049 // | non_empty_function_call_parameter_list ',' '&' w_variable
3050 if (Scanner.TRACE) {
3051 System.out.println("TRACE: non_empty_function_call_parameter_list()");
3054 if (token == TokenNameAND) {
3058 // if (token == TokenNameIdentifier || token ==
3059 // TokenNameVariable
3060 // || token == TokenNameDOLLAR) {
3063 expr_without_variable(true);
3066 if (token != TokenNameCOMMA) {
3073 private void fully_qualified_class_name() {
3074 if (token == TokenNameIdentifier) {
3077 throwSyntaxError("Class name expected.");
3081 private void static_member() {
3083 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3084 // variable_without_objects
3085 if (Scanner.TRACE) {
3086 System.out.println("TRACE: static_member()");
3088 fully_qualified_class_name();
3089 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3090 throwSyntaxError("'::' expected after class name (static_member).");
3093 variable_without_objects(false, false);
3096 private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3097 // base_variable_with_function_calls:
3100 if (Scanner.TRACE) {
3101 System.out.println("TRACE: base_variable_with_function_calls()");
3103 return function_call(lefthandside, ignoreVar);
3106 private Expression base_variable() {
3108 // reference_variable
3109 // | simple_indirect_reference reference_variable
3111 Expression ref = null;
3112 if (Scanner.TRACE) {
3113 System.out.println("TRACE: base_variable()");
3115 if (token == TokenNameIdentifier) {
3118 while (token == TokenNameDOLLAR) {
3121 reference_variable(false, false);
3126 // private void simple_indirect_reference() {
3127 // // simple_indirect_reference:
3129 // //| simple_indirect_reference '$'
3131 private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3132 // reference_variable:
3133 // reference_variable '[' dim_offset ']'
3134 // | reference_variable '{' expr '}'
3135 // | compound_variable
3136 Expression ref = null;
3137 if (Scanner.TRACE) {
3138 System.out.println("TRACE: reference_variable()");
3140 ref = compound_variable(lefthandside, ignoreVar);
3142 if (token == TokenNameLBRACE) {
3146 if (token != TokenNameRBRACE) {
3147 throwSyntaxError("'}' expected in reference variable.");
3150 } else if (token == TokenNameLBRACKET) {
3151 if (ref != null && ref instanceof FieldReference) {
3152 FieldReference fref = (FieldReference) ref;
3153 addVariableSet(fref.token);
3157 if (token != TokenNameRBRACKET) {
3160 if (token != TokenNameRBRACKET) {
3161 throwSyntaxError("']' expected in reference variable.");
3172 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3173 // compound_variable:
3175 // | '$' '{' expr '}'
3176 if (Scanner.TRACE) {
3177 System.out.println("TRACE: compound_variable()");
3179 if (token == TokenNameVariable) {
3180 if (!lefthandside) {
3181 if (!containsVariableSet()) {
3182 // reportSyntaxError("The local variable " + new
3183 // String(scanner.getCurrentIdentifierSource())
3184 // + " may not have been initialized");
3185 problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3186 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3187 compilationUnit.compilationResult);
3194 FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3198 // because of simple_indirect_reference
3199 while (token == TokenNameDOLLAR) {
3202 if (token != TokenNameLBRACE) {
3203 reportSyntaxError("'{' expected after compound variable token '$'.");
3208 if (token != TokenNameRBRACE) {
3209 throwSyntaxError("'}' expected after compound variable token '$'.");
3214 } // private void dim_offset() { // // dim_offset: // // /* empty */
3219 private void object_property() {
3222 // | variable_without_objects
3223 if (Scanner.TRACE) {
3224 System.out.println("TRACE: object_property()");
3226 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3227 variable_without_objects(false, false);
3233 private void object_dim_list() {
3235 // object_dim_list '[' dim_offset ']'
3236 // | object_dim_list '{' expr '}'
3238 if (Scanner.TRACE) {
3239 System.out.println("TRACE: object_dim_list()");
3243 if (token == TokenNameLBRACE) {
3246 if (token != TokenNameRBRACE) {
3247 throwSyntaxError("'}' expected in object_dim_list.");
3250 } else if (token == TokenNameLBRACKET) {
3252 if (token == TokenNameRBRACKET) {
3257 if (token != TokenNameRBRACKET) {
3258 throwSyntaxError("']' expected in object_dim_list.");
3267 private void variable_name() {
3271 if (Scanner.TRACE) {
3272 System.out.println("TRACE: variable_name()");
3274 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3275 if (token > TokenNameKEYWORD) {
3276 // TODO show a warning "Keyword used as variable" ?
3280 if (token != TokenNameLBRACE) {
3281 throwSyntaxError("'{' expected in variable name.");
3285 if (token != TokenNameRBRACE) {
3286 throwSyntaxError("'}' expected in variable name.");
3292 private void r_variable() {
3293 variable(false, false);
3296 private void w_variable(boolean lefthandside) {
3297 variable(lefthandside, false);
3300 private void rw_variable() {
3301 variable(false, false);
3304 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3306 // base_variable_with_function_calls T_OBJECT_OPERATOR
3307 // object_property method_or_not variable_properties
3308 // | base_variable_with_function_calls
3309 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3310 if (token == TokenNameMINUS_GREATER) {
3315 variable_properties();
3320 private void variable_properties() {
3321 // variable_properties:
3322 // variable_properties variable_property
3324 while (token == TokenNameMINUS_GREATER) {
3325 variable_property();
3329 private void variable_property() {
3330 // variable_property:
3331 // T_OBJECT_OPERATOR object_property method_or_not
3332 if (Scanner.TRACE) {
3333 System.out.println("TRACE: variable_property()");
3335 if (token == TokenNameMINUS_GREATER) {
3340 throwSyntaxError("'->' expected in variable_property.");
3344 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3346 // base_variable_with_function_calls T_OBJECT_OPERATOR
3347 // object_property method_or_not variable_properties
3348 // | base_variable_with_function_calls
3350 // Expression ref = function_call(lefthandside, ignoreVar);
3353 // T_STRING '(' function_call_parameter_list ')'
3354 // | class_constant '(' function_call_parameter_list ')'
3355 // | static_member '(' function_call_parameter_list ')'
3356 // | variable_without_objects '(' function_call_parameter_list ')'
3357 char[] defineName = null;
3358 char[] ident = null;
3361 Expression ref = null;
3362 if (Scanner.TRACE) {
3363 System.out.println("TRACE: function_call()");
3365 if (token == TokenNameIdentifier) {
3366 ident = scanner.getCurrentIdentifierSource();
3368 startPos = scanner.getCurrentTokenStartPosition();
3369 endPos = scanner.getCurrentTokenEndPosition();
3372 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3373 || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3374 || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3375 || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3376 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3377 + new String(ident) + "' (use 'define(...)' to define constants).";
3378 reportSyntaxError(error);
3382 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3386 if (token == TokenNameIdentifier) {
3391 variable_without_objects(true, false);
3396 ref = variable_without_objects(lefthandside, ignoreVar);
3398 if (token != TokenNameLPAREN) {
3399 if (defineName != null) {
3400 // does this identifier contain only uppercase characters?
3401 if (defineName.length == 3) {
3402 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3405 } else if (defineName.length == 4) {
3406 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3408 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3411 } else if (defineName.length == 5) {
3412 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3416 if (defineName != null) {
3417 for (int i = 0; i < defineName.length; i++) {
3418 if (Character.isLowerCase(defineName[i])) {
3419 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3425 // TODO is this ok ?
3427 // throwSyntaxError("'(' expected in function call.");
3431 if (token == TokenNameRPAREN) {
3435 non_empty_function_call_parameter_list();
3436 if (token != TokenNameRPAREN) {
3437 String functionName;
3438 if (ident == null) {
3439 functionName = new String(" ");
3441 functionName = new String(ident);
3443 throwSyntaxError("')' expected in function call (" + functionName + ").");
3448 if (token == TokenNameMINUS_GREATER) {
3453 variable_properties();
3458 private void method_or_not() {
3460 // '(' function_call_parameter_list ')'
3462 if (Scanner.TRACE) {
3463 System.out.println("TRACE: method_or_not()");
3465 if (token == TokenNameLPAREN) {
3467 if (token == TokenNameRPAREN) {
3471 non_empty_function_call_parameter_list();
3472 if (token != TokenNameRPAREN) {
3473 throwSyntaxError("')' expected in method_or_not.");
3479 private void exit_expr() {
3483 if (token != TokenNameLPAREN) {
3487 if (token == TokenNameRPAREN) {
3492 if (token != TokenNameRPAREN) {
3493 throwSyntaxError("')' expected after keyword 'exit'");
3498 // private void encaps_list() {
3499 // // encaps_list encaps_var
3500 // // | encaps_list T_STRING
3501 // // | encaps_list T_NUM_STRING
3502 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3503 // // | encaps_list T_CHARACTER
3504 // // | encaps_list T_BAD_CHARACTER
3505 // // | encaps_list '['
3506 // // | encaps_list ']'
3507 // // | encaps_list '{'
3508 // // | encaps_list '}'
3509 // // | encaps_list T_OBJECT_OPERATOR
3513 // case TokenNameSTRING:
3516 // case TokenNameLBRACE:
3517 // // scanner.encapsedStringStack.pop();
3520 // case TokenNameRBRACE:
3521 // // scanner.encapsedStringStack.pop();
3524 // case TokenNameLBRACKET:
3525 // // scanner.encapsedStringStack.pop();
3528 // case TokenNameRBRACKET:
3529 // // scanner.encapsedStringStack.pop();
3532 // case TokenNameMINUS_GREATER:
3533 // // scanner.encapsedStringStack.pop();
3536 // case TokenNameVariable:
3537 // case TokenNameDOLLAR_LBRACE:
3538 // case TokenNameLBRACE_DOLLAR:
3542 // char encapsedChar = ((Character)
3543 // scanner.encapsedStringStack.peek()).charValue();
3544 // if (encapsedChar == '$') {
3545 // scanner.encapsedStringStack.pop();
3546 // encapsedChar = ((Character)
3547 // scanner.encapsedStringStack.peek()).charValue();
3548 // switch (encapsedChar) {
3550 // if (token == TokenNameEncapsedString0) {
3553 // token = TokenNameSTRING;
3556 // if (token == TokenNameEncapsedString1) {
3559 // token = TokenNameSTRING;
3562 // if (token == TokenNameEncapsedString2) {
3565 // token = TokenNameSTRING;
3574 // private void encaps_var() {
3576 // // | T_VARIABLE '[' encaps_var_offset ']'
3577 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3578 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3579 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3580 // // | T_CURLY_OPEN variable '}'
3582 // case TokenNameVariable:
3584 // if (token == TokenNameLBRACKET) {
3586 // expr(); //encaps_var_offset();
3587 // if (token != TokenNameRBRACKET) {
3588 // throwSyntaxError("']' expected after variable.");
3590 // // scanner.encapsedStringStack.pop();
3593 // } else if (token == TokenNameMINUS_GREATER) {
3595 // if (token != TokenNameIdentifier) {
3596 // throwSyntaxError("Identifier expected after '->'.");
3598 // // scanner.encapsedStringStack.pop();
3602 // // // scanner.encapsedStringStack.pop();
3603 // // int tempToken = TokenNameSTRING;
3604 // // if (!scanner.encapsedStringStack.isEmpty()
3605 // // && (token == TokenNameEncapsedString0
3606 // // || token == TokenNameEncapsedString1
3607 // // || token == TokenNameEncapsedString2 || token ==
3608 // // TokenNameERROR)) {
3609 // // char encapsedChar = ((Character)
3610 // // scanner.encapsedStringStack.peek())
3612 // // switch (token) {
3613 // // case TokenNameEncapsedString0 :
3614 // // if (encapsedChar == '`') {
3615 // // tempToken = TokenNameEncapsedString0;
3618 // // case TokenNameEncapsedString1 :
3619 // // if (encapsedChar == '\'') {
3620 // // tempToken = TokenNameEncapsedString1;
3623 // // case TokenNameEncapsedString2 :
3624 // // if (encapsedChar == '"') {
3625 // // tempToken = TokenNameEncapsedString2;
3628 // // case TokenNameERROR :
3629 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3630 // // scanner.currentPosition--;
3631 // // getNextToken();
3636 // // token = tempToken;
3639 // case TokenNameDOLLAR_LBRACE:
3641 // if (token == TokenNameDOLLAR_LBRACE) {
3643 // } else if (token == TokenNameIdentifier) {
3645 // if (token == TokenNameLBRACKET) {
3647 // // if (token == TokenNameRBRACKET) {
3648 // // getNextToken();
3651 // if (token != TokenNameRBRACKET) {
3652 // throwSyntaxError("']' expected after '${'.");
3660 // if (token != TokenNameRBRACE) {
3661 // throwSyntaxError("'}' expected.");
3665 // case TokenNameLBRACE_DOLLAR:
3667 // if (token == TokenNameLBRACE_DOLLAR) {
3669 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3671 // if (token == TokenNameLBRACKET) {
3673 // // if (token == TokenNameRBRACKET) {
3674 // // getNextToken();
3677 // if (token != TokenNameRBRACKET) {
3678 // throwSyntaxError("']' expected.");
3682 // } else if (token == TokenNameMINUS_GREATER) {
3684 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3685 // throwSyntaxError("String or Variable token expected.");
3688 // if (token == TokenNameLBRACKET) {
3690 // // if (token == TokenNameRBRACKET) {
3691 // // getNextToken();
3694 // if (token != TokenNameRBRACKET) {
3695 // throwSyntaxError("']' expected after '${'.");
3701 // // if (token != TokenNameRBRACE) {
3702 // // throwSyntaxError("'}' expected after '{$'.");
3704 // // // scanner.encapsedStringStack.pop();
3705 // // getNextToken();
3708 // if (token != TokenNameRBRACE) {
3709 // throwSyntaxError("'}' expected.");
3711 // // scanner.encapsedStringStack.pop();
3718 // private void encaps_var_offset() {
3720 // // | T_NUM_STRING
3723 // case TokenNameSTRING:
3726 // case TokenNameIntegerLiteral:
3729 // case TokenNameVariable:
3732 // case TokenNameIdentifier:
3736 // throwSyntaxError("Variable or String token expected.");
3741 private void internal_functions_in_yacc() {
3744 // case TokenNameisset:
3745 // // T_ISSET '(' isset_variables ')'
3747 // if (token != TokenNameLPAREN) {
3748 // throwSyntaxError("'(' expected after keyword 'isset'");
3751 // isset_variables();
3752 // if (token != TokenNameRPAREN) {
3753 // throwSyntaxError("')' expected after keyword 'isset'");
3757 // case TokenNameempty:
3758 // // T_EMPTY '(' variable ')'
3760 // if (token != TokenNameLPAREN) {
3761 // throwSyntaxError("'(' expected after keyword 'empty'");
3765 // if (token != TokenNameRPAREN) {
3766 // throwSyntaxError("')' expected after keyword 'empty'");
3770 case TokenNameinclude:
3772 checkFileName(token);
3774 case TokenNameinclude_once:
3775 // T_INCLUDE_ONCE expr
3776 checkFileName(token);
3779 // T_EVAL '(' expr ')'
3781 if (token != TokenNameLPAREN) {
3782 throwSyntaxError("'(' expected after keyword 'eval'");
3786 if (token != TokenNameRPAREN) {
3787 throwSyntaxError("')' expected after keyword 'eval'");
3791 case TokenNamerequire:
3793 checkFileName(token);
3795 case TokenNamerequire_once:
3796 // T_REQUIRE_ONCE expr
3797 checkFileName(token);
3803 * Parse and check the include file name
3805 * @param includeToken
3807 private void checkFileName(int includeToken) {
3808 // <include-token> expr
3809 int start = scanner.getCurrentTokenStartPosition();
3810 boolean hasLPAREN = false;
3812 if (token == TokenNameLPAREN) {
3816 Expression expression = expr();
3818 if (token == TokenNameRPAREN) {
3821 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3824 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3826 if (scanner.compilationUnit != null) {
3827 IResource resource = scanner.compilationUnit.getResource();
3828 if (resource != null && resource instanceof IFile) {
3829 file = (IFile) resource;
3833 tokens = new char[1][];
3834 tokens[0] = currTokenSource;
3836 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3837 impt.declarationSourceEnd = impt.sourceEnd;
3838 impt.declarationEnd = impt.declarationSourceEnd;
3839 // endPosition is just before the ;
3840 impt.declarationSourceStart = start;
3841 includesList.add(impt);
3843 if (expression instanceof StringLiteral) {
3844 StringLiteral literal = (StringLiteral) expression;
3845 char[] includeName = literal.source();
3846 if (includeName.length == 0) {
3847 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3848 literal.sourceStart + 1);
3850 String includeNameString = new String(includeName);
3851 if (literal instanceof StringLiteralDQ) {
3852 if (includeNameString.indexOf('$') >= 0) {
3853 // assuming that the filename contains a variable => no filename check
3857 if (includeNameString.startsWith("http://")) {
3858 // assuming external include location
3862 // check the filename:
3863 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3864 // expression.toStringExpression());
3865 IProject project = file.getProject();
3866 if (project != null) {
3867 IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3870 // SyntaxError: "File: << >> doesn't exist in project."
3871 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3872 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3873 compilationUnit.compilationResult);
3876 String filePath = path.toString();
3877 String ext = file.getRawLocation().getFileExtension();
3878 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3880 impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3881 impt.setFile(PHPFileUtil.createFile(path, project));
3882 } catch (Exception e) {
3883 // the file is outside of the workspace
3891 private void isset_variables() {
3893 // | isset_variables ','
3894 if (token == TokenNameRPAREN) {
3895 throwSyntaxError("Variable expected after keyword 'isset'");
3898 variable(true, false);
3899 if (token == TokenNameCOMMA) {
3907 private boolean common_scalar() {
3911 // | T_CONSTANT_ENCAPSED_STRING
3918 case TokenNameIntegerLiteral:
3921 case TokenNameDoubleLiteral:
3924 case TokenNameStringDoubleQuote:
3927 case TokenNameStringSingleQuote:
3930 case TokenNameStringInterpolated:
3939 case TokenNameCLASS_C:
3942 case TokenNameMETHOD_C:
3945 case TokenNameFUNC_C:
3952 private void scalar() {
3955 // | T_STRING_VARNAME
3958 // | '"' encaps_list '"'
3959 // | '\'' encaps_list '\''
3960 // | T_START_HEREDOC encaps_list T_END_HEREDOC
3961 throwSyntaxError("Not yet implemented (scalar).");
3964 private void static_scalar() {
3965 // static_scalar: /* compile-time evaluated scalars */
3968 // | '+' static_scalar
3969 // | '-' static_scalar
3970 // | T_ARRAY '(' static_array_pair_list ')'
3971 // | static_class_constant
3972 if (common_scalar()) {
3976 case TokenNameIdentifier:
3978 // static_class_constant:
3979 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3980 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3982 if (token == TokenNameIdentifier) {
3985 throwSyntaxError("Identifier expected after '::' operator.");
3989 case TokenNameEncapsedString0:
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 TokenNameEncapsedString1:
4005 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4006 // while (scanner.currentCharacter != '\'') {
4007 // if (scanner.currentCharacter == '\\') {
4008 // scanner.currentPosition++;
4010 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4013 // } catch (IndexOutOfBoundsException e) {
4014 // throwSyntaxError("'\'' expected at end of static string.");
4017 // case TokenNameEncapsedString2:
4019 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4020 // while (scanner.currentCharacter != '"') {
4021 // if (scanner.currentCharacter == '\\') {
4022 // scanner.currentPosition++;
4024 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4027 // } catch (IndexOutOfBoundsException e) {
4028 // throwSyntaxError("'\"' expected at end of static string.");
4031 case TokenNameStringSingleQuote:
4034 case TokenNameStringDoubleQuote:
4041 case TokenNameMINUS:
4045 case TokenNamearray:
4047 if (token != TokenNameLPAREN) {
4048 throwSyntaxError("'(' expected after keyword 'array'");
4051 if (token == TokenNameRPAREN) {
4055 non_empty_static_array_pair_list();
4056 if (token != TokenNameRPAREN) {
4057 throwSyntaxError("')' or ',' expected after keyword 'array'");
4061 // case TokenNamenull :
4064 // case TokenNamefalse :
4067 // case TokenNametrue :
4071 throwSyntaxError("Static scalar/constant expected.");
4075 private void non_empty_static_array_pair_list() {
4076 // non_empty_static_array_pair_list:
4077 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4079 // | non_empty_static_array_pair_list ',' static_scalar
4080 // | static_scalar T_DOUBLE_ARROW static_scalar
4084 if (token == TokenNameEQUAL_GREATER) {
4088 if (token != TokenNameCOMMA) {
4092 if (token == TokenNameRPAREN) {
4098 // public void reportSyntaxError() { //int act, int currentKind, int
4099 // // stateStackTop) {
4100 // /* remember current scanner position */
4101 // int startPos = scanner.startPosition;
4102 // int currentPos = scanner.currentPosition;
4104 // this.checkAndReportBracketAnomalies(problemReporter());
4105 // /* reset scanner where it was */
4106 // scanner.startPosition = startPos;
4107 // scanner.currentPosition = currentPos;
4110 public static final int RoundBracket = 0;
4112 public static final int SquareBracket = 1;
4114 public static final int CurlyBracket = 2;
4116 public static final int BracketKinds = 3;
4118 protected int[] nestedMethod; // the ptr is nestedType
4120 protected int nestedType, dimensions;
4122 // variable set stack
4123 final static int VariableStackIncrement = 10;
4125 HashMap fTypeVariables = null;
4127 HashMap fMethodVariables = null;
4129 ArrayList fStackUnassigned = new ArrayList();
4132 final static int AstStackIncrement = 100;
4134 protected int astPtr;
4136 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4138 protected int astLengthPtr;
4140 protected int[] astLengthStack;
4142 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4144 public CompilationUnitDeclaration compilationUnit; /*
4145 * the result from parse()
4148 protected ReferenceContext referenceContext;
4150 protected ProblemReporter problemReporter;
4152 protected CompilerOptions options;
4154 private ArrayList includesList;
4156 // protected CompilationResult compilationResult;
4158 * Returns this parser's problem reporter initialized with its reference
4159 * context. Also it is assumed that a problem is going to be reported, so
4160 * initializes the compilation result's line positions.
4162 public ProblemReporter problemReporter() {
4163 if (scanner.recordLineSeparator) {
4164 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4166 problemReporter.referenceContext = referenceContext;
4167 return problemReporter;
4171 * Reconsider the entire source looking for inconsistencies in {} () []
4173 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4174 // problemReporter) {
4175 // scanner.wasAcr = false;
4176 // boolean anomaliesDetected = false;
4178 // char[] source = scanner.source;
4179 // int[] leftCount = { 0, 0, 0 };
4180 // int[] rightCount = { 0, 0, 0 };
4181 // int[] depths = { 0, 0, 0 };
4182 // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4184 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4185 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4187 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4189 // scanner.currentPosition = scanner.initialPosition; //starting
4191 // // (first-zero-based
4193 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4198 // // ---------Consume white space and handles
4199 // // startPosition---------
4200 // boolean isWhiteSpace;
4202 // scanner.startPosition = scanner.currentPosition;
4203 // // if (((scanner.currentCharacter =
4204 // // source[scanner.currentPosition++]) == '\\') &&
4205 // // (source[scanner.currentPosition] == 'u')) {
4206 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4208 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4209 // (scanner.currentCharacter == '\n'))) {
4210 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4211 // // only record line positions we have not
4213 // scanner.pushLineSeparator();
4216 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4218 // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4219 // // -------consume token until } is found---------
4220 // switch (scanner.currentCharacter) {
4222 // int index = leftCount[CurlyBracket]++;
4223 // if (index == leftPositions[CurlyBracket].length) {
4224 // System.arraycopy(leftPositions[CurlyBracket], 0,
4225 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4226 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4227 // new int[index * 2]), 0, index);
4229 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4230 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4234 // int index = rightCount[CurlyBracket]++;
4235 // if (index == rightPositions[CurlyBracket].length) {
4236 // System.arraycopy(rightPositions[CurlyBracket], 0,
4237 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4238 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4239 // new int[index * 2]), 0, index);
4241 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4242 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4246 // int index = leftCount[RoundBracket]++;
4247 // if (index == leftPositions[RoundBracket].length) {
4248 // System.arraycopy(leftPositions[RoundBracket], 0,
4249 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4250 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4251 // new int[index * 2]), 0, index);
4253 // leftPositions[RoundBracket][index] = scanner.startPosition;
4254 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4258 // int index = rightCount[RoundBracket]++;
4259 // if (index == rightPositions[RoundBracket].length) {
4260 // System.arraycopy(rightPositions[RoundBracket], 0,
4261 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4262 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4263 // new int[index * 2]), 0, index);
4265 // rightPositions[RoundBracket][index] = scanner.startPosition;
4266 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4270 // int index = leftCount[SquareBracket]++;
4271 // if (index == leftPositions[SquareBracket].length) {
4272 // System.arraycopy(leftPositions[SquareBracket], 0,
4273 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4274 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4275 // new int[index * 2]), 0, index);
4277 // leftPositions[SquareBracket][index] = scanner.startPosition;
4278 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4282 // int index = rightCount[SquareBracket]++;
4283 // if (index == rightPositions[SquareBracket].length) {
4284 // System.arraycopy(rightPositions[SquareBracket], 0,
4285 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4286 // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4287 // = new int[index * 2]), 0, index);
4289 // rightPositions[SquareBracket][index] = scanner.startPosition;
4290 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4294 // if (scanner.getNextChar('\\')) {
4295 // scanner.scanEscapeCharacter();
4296 // } else { // consume next character
4297 // scanner.unicodeAsBackSlash = false;
4298 // // if (((scanner.currentCharacter =
4299 // // source[scanner.currentPosition++]) ==
4301 // // (source[scanner.currentPosition] ==
4303 // // scanner.getNextUnicodeChar();
4305 // if (scanner.withoutUnicodePtr != 0) {
4306 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4307 // scanner.currentCharacter;
4311 // scanner.getNextChar('\'');
4315 // // consume next character
4316 // scanner.unicodeAsBackSlash = false;
4317 // // if (((scanner.currentCharacter =
4318 // // source[scanner.currentPosition++]) == '\\') &&
4319 // // (source[scanner.currentPosition] == 'u')) {
4320 // // scanner.getNextUnicodeChar();
4322 // if (scanner.withoutUnicodePtr != 0) {
4323 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4324 // scanner.currentCharacter;
4327 // while (scanner.currentCharacter != '"') {
4328 // if (scanner.currentCharacter == '\r') {
4329 // if (source[scanner.currentPosition] == '\n')
4330 // scanner.currentPosition++;
4331 // break; // the string cannot go further that
4334 // if (scanner.currentCharacter == '\n') {
4335 // break; // the string cannot go further that
4338 // if (scanner.currentCharacter == '\\') {
4339 // scanner.scanEscapeCharacter();
4341 // // consume next character
4342 // scanner.unicodeAsBackSlash = false;
4343 // // if (((scanner.currentCharacter =
4344 // // source[scanner.currentPosition++]) == '\\')
4345 // // && (source[scanner.currentPosition] == 'u'))
4347 // // scanner.getNextUnicodeChar();
4349 // if (scanner.withoutUnicodePtr != 0) {
4350 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4351 // scanner.currentCharacter;
4358 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4360 // //get the next char
4361 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4363 // && (source[scanner.currentPosition] == 'u')) {
4364 // //-------------unicode traitement
4366 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4367 // scanner.currentPosition++;
4368 // while (source[scanner.currentPosition] == 'u') {
4369 // scanner.currentPosition++;
4371 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4373 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4375 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4377 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4378 // || c4 < 0) { //error
4382 // scanner.currentCharacter = 'A';
4383 // } //something different from \n and \r
4385 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4388 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4390 // //get the next char
4391 // scanner.startPosition = scanner.currentPosition;
4392 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4394 // && (source[scanner.currentPosition] == 'u')) {
4395 // //-------------unicode traitement
4397 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4398 // scanner.currentPosition++;
4399 // while (source[scanner.currentPosition] == 'u') {
4400 // scanner.currentPosition++;
4402 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4404 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4406 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4408 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4409 // || c4 < 0) { //error
4413 // scanner.currentCharacter = 'A';
4414 // } //something different from \n
4417 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4421 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4422 // (scanner.currentCharacter == '\n'))) {
4423 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4424 // // only record line positions we
4425 // // have not recorded yet
4426 // scanner.pushLineSeparator();
4427 // if (this.scanner.taskTags != null) {
4428 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4430 // .getCurrentTokenEndPosition());
4436 // if (test > 0) { //traditional and annotation
4438 // boolean star = false;
4439 // // consume next character
4440 // scanner.unicodeAsBackSlash = false;
4441 // // if (((scanner.currentCharacter =
4442 // // source[scanner.currentPosition++]) ==
4444 // // (source[scanner.currentPosition] ==
4446 // // scanner.getNextUnicodeChar();
4448 // if (scanner.withoutUnicodePtr != 0) {
4449 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4450 // scanner.currentCharacter;
4453 // if (scanner.currentCharacter == '*') {
4456 // //get the next char
4457 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4459 // && (source[scanner.currentPosition] == 'u')) {
4460 // //-------------unicode traitement
4462 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4463 // scanner.currentPosition++;
4464 // while (source[scanner.currentPosition] == 'u') {
4465 // scanner.currentPosition++;
4467 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4469 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4471 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4473 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4474 // || c4 < 0) { //error
4478 // scanner.currentCharacter = 'A';
4479 // } //something different from * and /
4481 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4484 // //loop until end of comment */
4485 // while ((scanner.currentCharacter != '/') || (!star)) {
4486 // star = scanner.currentCharacter == '*';
4488 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4490 // && (source[scanner.currentPosition] == 'u')) {
4491 // //-------------unicode traitement
4493 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4494 // scanner.currentPosition++;
4495 // while (source[scanner.currentPosition] == 'u') {
4496 // scanner.currentPosition++;
4498 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4500 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4502 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4504 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4505 // || c4 < 0) { //error
4509 // scanner.currentCharacter = 'A';
4510 // } //something different from * and
4513 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4517 // if (this.scanner.taskTags != null) {
4518 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4519 // this.scanner.getCurrentTokenEndPosition());
4526 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4527 // scanner.scanIdentifierOrKeyword(false);
4530 // if (Character.isDigit(scanner.currentCharacter)) {
4531 // scanner.scanNumber(false);
4535 // //-----------------end switch while
4536 // // try--------------------
4537 // } catch (IndexOutOfBoundsException e) {
4538 // break; // read until EOF
4539 // } catch (InvalidInputException e) {
4540 // return false; // no clue
4543 // if (scanner.recordLineSeparator) {
4544 // compilationUnit.compilationResult.lineSeparatorPositions =
4545 // scanner.getLineEnds();
4547 // // check placement anomalies against other kinds of brackets
4548 // for (int kind = 0; kind < BracketKinds; kind++) {
4549 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4550 // int start = leftPositions[kind][leftIndex]; // deepest
4552 // // find matching closing bracket
4553 // int depth = leftDepths[kind][leftIndex];
4555 // for (int i = 0; i < rightCount[kind]; i++) {
4556 // int pos = rightPositions[kind][i];
4557 // // want matching bracket further in source with same
4559 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4564 // if (end < 0) { // did not find a good closing match
4565 // problemReporter.unmatchedBracket(start, referenceContext,
4566 // compilationUnit.compilationResult);
4569 // // check if even number of opening/closing other brackets
4570 // // in between this pair of brackets
4572 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4574 // for (int i = 0; i < leftCount[otherKind]; i++) {
4575 // int pos = leftPositions[otherKind][i];
4576 // if ((pos > start) && (pos < end))
4579 // for (int i = 0; i < rightCount[otherKind]; i++) {
4580 // int pos = rightPositions[otherKind][i];
4581 // if ((pos > start) && (pos < end))
4584 // if (balance != 0) {
4585 // problemReporter.unmatchedBracket(start, referenceContext,
4586 // compilationUnit.compilationResult); //bracket
4592 // // too many opening brackets ?
4593 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4594 // anomaliesDetected = true;
4595 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4596 // 1], referenceContext,
4597 // compilationUnit.compilationResult);
4599 // // too many closing brackets ?
4600 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4601 // anomaliesDetected = true;
4602 // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4603 // compilationUnit.compilationResult);
4605 // if (anomaliesDetected)
4608 // return anomaliesDetected;
4609 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4610 // return anomaliesDetected;
4611 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4612 // return anomaliesDetected;
4615 protected void pushOnAstLengthStack(int pos) {
4617 astLengthStack[++astLengthPtr] = pos;
4618 } catch (IndexOutOfBoundsException e) {
4619 int oldStackLength = astLengthStack.length;
4620 int[] oldPos = astLengthStack;
4621 astLengthStack = new int[oldStackLength + StackIncrement];
4622 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4623 astLengthStack[astLengthPtr] = pos;
4627 protected void pushOnAstStack(ASTNode node) {
4629 * add a new obj on top of the ast stack
4632 astStack[++astPtr] = node;
4633 } catch (IndexOutOfBoundsException e) {
4634 int oldStackLength = astStack.length;
4635 ASTNode[] oldStack = astStack;
4636 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4637 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4638 astPtr = oldStackLength;
4639 astStack[astPtr] = node;
4642 astLengthStack[++astLengthPtr] = 1;
4643 } catch (IndexOutOfBoundsException e) {
4644 int oldStackLength = astLengthStack.length;
4645 int[] oldPos = astLengthStack;
4646 astLengthStack = new int[oldStackLength + AstStackIncrement];
4647 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4648 astLengthStack[astLengthPtr] = 1;
4652 protected void resetModifiers() {
4653 this.modifiers = AccDefault;
4654 this.modifiersSourceStart = -1; // <-- see comment into
4655 // modifiersFlag(int)
4656 this.scanner.commentPtr = -1;
4659 protected void consumePackageDeclarationName(IFile file) {
4660 // create a package name similar to java package names
4661 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4662 String filePath = file.getRawLocation().toString();
4663 String ext = file.getRawLocation().getFileExtension();
4664 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4665 ImportReference impt;
4667 if (filePath.startsWith(projectPath)) {
4668 tokens = CharOperation
4669 .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4671 String name = file.getName();
4672 tokens = new char[1][];
4673 tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4676 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4678 impt.declarationSourceStart = 0;
4679 impt.declarationSourceEnd = 0;
4680 impt.declarationEnd = 0;
4681 // endPosition is just before the ;
4685 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4686 "$_SESSION", "$_SERVER" };
4691 private void pushFunctionVariableSet() {
4692 HashSet set = new HashSet();
4693 if (fStackUnassigned.isEmpty()) {
4694 for (int i = 0; i < GLOBALS.length; i++) {
4695 set.add(GLOBALS[i]);
4698 fStackUnassigned.add(set);
4701 private void pushIfVariableSet() {
4702 if (!fStackUnassigned.isEmpty()) {
4703 HashSet set = new HashSet();
4704 fStackUnassigned.add(set);
4708 private HashSet removeIfVariableSet() {
4709 if (!fStackUnassigned.isEmpty()) {
4710 return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4716 * Returns the <i>set of assigned variables </i> returns null if no Set is
4717 * defined at the current scanner position
4719 private HashSet peekVariableSet() {
4720 if (!fStackUnassigned.isEmpty()) {
4721 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4727 * add the current identifier source to the <i>set of assigned variables </i>
4731 private void addVariableSet(HashSet set) {
4733 set.add(new String(scanner.getCurrentTokenSource()));
4738 * add the current identifier source to the <i>set of assigned variables </i>
4741 private void addVariableSet() {
4742 HashSet set = peekVariableSet();
4744 set.add(new String(scanner.getCurrentTokenSource()));
4749 * add the current identifier source to the <i>set of assigned variables </i>
4752 private void addVariableSet(char[] token) {
4753 HashSet set = peekVariableSet();
4755 set.add(new String(token));
4760 * check if the current identifier source is in the <i>set of assigned
4761 * variables </i> Returns true, if no set is defined for the current scanner
4765 private boolean containsVariableSet() {
4766 return containsVariableSet(scanner.getCurrentTokenSource());
4769 private boolean containsVariableSet(char[] token) {
4771 if (!fStackUnassigned.isEmpty()) {
4773 String str = new String(token);
4774 for (int i = 0; i < fStackUnassigned.size(); i++) {
4775 set = (HashSet) fStackUnassigned.get(i);
4776 if (set.contains(str)) {