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,
61 ParserBasicInformation {
62 protected final static int StackIncrement = 255;
64 protected int stateStackTop;
66 // protected int[] stack = new int[StackIncrement];
68 public int firstToken; // handle for multiple parsing goals
70 public int lastAct; // handle for multiple parsing goals
72 // protected RecoveredElement currentElement;
74 public static boolean VERBOSE_RECOVERY = false;
76 protected boolean diet = false; // tells the scanner to jump over some
79 * the PHP token scanner
81 public Scanner scanner;
85 protected int modifiers;
87 protected int modifiersSourceStart;
89 protected Parser(ProblemReporter problemReporter) {
90 this.problemReporter = problemReporter;
91 this.options = problemReporter.options;
92 this.token = TokenNameEOF;
93 this.initializeScanner();
96 public void setFileToParse(IFile fileToParse) {
97 this.token = TokenNameEOF;
98 this.initializeScanner();
102 * ClassDeclaration Constructor.
106 * Description of Parameter
109 public Parser(IFile fileToParse) {
110 // if (keywordMap == null) {
111 // keywordMap = new HashMap();
112 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
113 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
116 // this.currentPHPString = 0;
117 // PHPParserSuperclass.fileToParse = fileToParse;
118 // this.phpList = null;
119 this.includesList = null;
121 this.token = TokenNameEOF;
123 // this.rowCount = 1;
124 // this.columnCount = 0;
125 // this.phpEnd = false;
127 this.initializeScanner();
130 public void initializeScanner() {
131 this.scanner = new Scanner(
133 false /* whitespace */,
134 this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */,
135 false, false, this.options.taskTags/* taskTags */,
136 this.options.taskPriorites/* taskPriorities */, true/* isTaskCaseSensitive */);
140 * Create marker for the parse error
142 // private void setMarker(String message, int charStart, int charEnd, int
144 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
147 * This method will throw the SyntaxError. It will add the good lines and
148 * columns to the Error
152 * @throws SyntaxError
155 private void throwSyntaxError(String error) {
156 int problemStartPosition = scanner.getCurrentTokenStartPosition();
157 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
158 if (scanner.source.length <= problemEndPosition
159 && problemEndPosition > 0) {
160 problemEndPosition = scanner.source.length - 1;
161 if (problemStartPosition > 0
162 && problemStartPosition >= problemEndPosition
163 && problemEndPosition > 0) {
164 problemStartPosition = problemEndPosition - 1;
167 throwSyntaxError(error, problemStartPosition, problemEndPosition);
171 * This method will throw the SyntaxError. It will add the good lines and
172 * columns to the Error
176 * @throws SyntaxError
179 // private void throwSyntaxError(String error, int startRow) {
180 // throw new SyntaxError(startRow, 0, " ", error);
182 private void throwSyntaxError(String error, int problemStartPosition,
183 int problemEndPosition) {
184 if (referenceContext != null) {
185 problemReporter.phpParsingError(new String[] { error },
186 problemStartPosition, problemEndPosition, referenceContext,
187 compilationUnit.compilationResult);
189 throw new SyntaxError(1, 0, " ", error);
192 private void reportSyntaxError(String error) {
193 int problemStartPosition = scanner.getCurrentTokenStartPosition();
194 int problemEndPosition = scanner.getCurrentTokenEndPosition();
195 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
198 private void reportSyntaxError(String error, int problemStartPosition,
199 int problemEndPosition) {
200 if (referenceContext != null) {
201 problemReporter.phpParsingError(new String[] { error },
202 problemStartPosition, problemEndPosition, referenceContext,
203 compilationUnit.compilationResult);
207 // private void reportSyntaxWarning(String error, int problemStartPosition,
208 // int problemEndPosition) {
209 // if (referenceContext != null) {
210 // problemReporter.phpParsingWarning(new String[] { error },
211 // problemStartPosition, problemEndPosition, referenceContext,
212 // compilationUnit.compilationResult);
217 * gets the next token from input
219 private void getNextToken() {
221 token = scanner.getNextToken();
223 int currentEndPosition = scanner.getCurrentTokenEndPosition();
224 int currentStartPosition = scanner
225 .getCurrentTokenStartPosition();
226 System.out.print(currentStartPosition + ","
227 + currentEndPosition + ": ");
228 System.out.println(scanner.toStringAction(token));
230 } catch (InvalidInputException e) {
231 token = TokenNameERROR;
232 String detailedMessage = e.getMessage();
234 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
235 throwSyntaxError("Unterminated string.");
236 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
237 throwSyntaxError("Unterminated commment.");
243 public void init(String s) {
245 this.token = TokenNameEOF;
246 this.includesList = new ArrayList();
248 // this.rowCount = 1;
249 // this.columnCount = 0;
250 // this.phpEnd = false;
251 // this.phpMode = false;
252 /* scanner initialization */
253 scanner.setSource(s.toCharArray());
254 scanner.setPHPMode(false);
258 protected void initialize(boolean phpMode) {
259 initialize(phpMode, null);
262 protected void initialize(boolean phpMode,
263 IdentifierIndexManager indexManager) {
264 compilationUnit = null;
265 referenceContext = null;
266 this.includesList = new ArrayList();
267 // this.indexManager = indexManager;
269 this.token = TokenNameEOF;
271 // this.rowCount = 1;
272 // this.columnCount = 0;
273 // this.phpEnd = false;
274 // this.phpMode = phpMode;
275 scanner.setPHPMode(phpMode);
280 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
283 public void parse(String s) {
288 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
291 public void parse(String s, HashMap variables) {
292 fMethodVariables = variables;
293 fStackUnassigned = new ArrayList();
299 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
302 protected void parse() {
303 if (scanner.compilationUnit != null) {
304 IResource resource = scanner.compilationUnit.getResource();
305 if (resource != null && resource instanceof IFile) {
306 // set the package name
307 consumePackageDeclarationName((IFile) resource);
313 if (token != TokenNameEOF && token != TokenNameERROR) {
316 if (token != TokenNameEOF) {
317 if (token == TokenNameERROR) {
318 throwSyntaxError("Scanner error (Found unknown token: "
319 + scanner.toStringAction(token) + ")");
321 if (token == TokenNameRPAREN) {
322 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
324 if (token == TokenNameRBRACE) {
325 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
327 if (token == TokenNameRBRACKET) {
328 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
330 if (token == TokenNameLPAREN) {
331 throwSyntaxError("Read character '('; end-of-file not reached.");
333 if (token == TokenNameLBRACE) {
334 throwSyntaxError("Read character '{'; end-of-file not reached.");
336 if (token == TokenNameLBRACKET) {
337 throwSyntaxError("Read character '['; end-of-file not reached.");
339 throwSyntaxError("End-of-file not reached.");
342 } catch (SyntaxError syntaxError) {
343 // syntaxError.printStackTrace();
352 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
355 public void parseFunction(String s, HashMap variables) {
357 scanner.phpMode = true;
358 parseFunction(variables);
362 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
365 protected void parseFunction(HashMap variables) {
367 boolean hasModifiers = member_modifiers();
368 if (token == TokenNamefunction) {
370 checkAndSetModifiers(AccPublic);
372 this.fMethodVariables = variables;
374 MethodDeclaration methodDecl = new MethodDeclaration(null);
375 methodDecl.declarationSourceStart = scanner
376 .getCurrentTokenStartPosition();
377 methodDecl.modifiers = this.modifiers;
378 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
381 functionDefinition(methodDecl);
382 } catch (SyntaxError sytaxErr1) {
385 int sourceEnd = methodDecl.sourceEnd;
387 || methodDecl.declarationSourceStart > sourceEnd) {
388 sourceEnd = methodDecl.declarationSourceStart + 1;
390 methodDecl.sourceEnd = sourceEnd;
391 methodDecl.declarationSourceEnd = sourceEnd;
396 protected CompilationUnitDeclaration endParse(int act) {
400 // if (currentElement != null) {
401 // currentElement.topElement().updateParseTree();
402 // if (VERBOSE_RECOVERY) {
403 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
404 // System.out.println("--------------------------"); //$NON-NLS-1$
405 // System.out.println(compilationUnit);
406 // System.out.println("----------------------------------");
410 if (diet & VERBOSE_RECOVERY) {
411 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
412 System.out.println("--------------------------"); //$NON-NLS-1$
413 System.out.println(compilationUnit);
414 System.out.println("----------------------------------"); //$NON-NLS-1$
417 if (scanner.recordLineSeparator) {
418 compilationUnit.compilationResult.lineSeparatorPositions = scanner
421 if (scanner.taskTags != null) {
422 for (int i = 0; i < scanner.foundTaskCount; i++) {
423 problemReporter().task(
424 new String(scanner.foundTaskTags[i]),
425 new String(scanner.foundTaskMessages[i]),
426 scanner.foundTaskPriorities[i] == null ? null
427 : new String(scanner.foundTaskPriorities[i]),
428 scanner.foundTaskPositions[i][0],
429 scanner.foundTaskPositions[i][1]);
432 compilationUnit.imports = new ImportReference[includesList.size()];
433 for (int i = 0; i < includesList.size(); i++) {
434 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
436 return compilationUnit;
439 private Block statementList() {
440 boolean branchStatement = false;
442 int blockStart = scanner.getCurrentTokenStartPosition();
443 ArrayList blockStatements = new ArrayList();
446 statement = statement();
447 blockStatements.add(statement);
448 if (token == TokenNameEOF) {
451 if (branchStatement && statement != null) {
452 // reportSyntaxError("Unreachable code",
453 // statement.sourceStart,
454 // statement.sourceEnd);
455 if (!(statement instanceof BreakStatement)) {
457 * don't give an error for break statement following
458 * return statement Technically it's unreachable code,
459 * but in switch-case it's recommended to avoid
460 * accidental fall-through later when editing the code
462 problemReporter.unreachableCode(new String(scanner
463 .getCurrentIdentifierSource()),
464 statement.sourceStart, statement.sourceEnd,
466 compilationUnit.compilationResult);
469 if ((token == TokenNameRBRACE) || (token == TokenNamecase)
470 || (token == TokenNamedefault)
471 || (token == TokenNameelse)
472 || (token == TokenNameelseif)
473 || (token == TokenNameendif)
474 || (token == TokenNameendfor)
475 || (token == TokenNameendforeach)
476 || (token == TokenNameendwhile)
477 || (token == TokenNameendswitch)
478 || (token == TokenNameenddeclare)
479 || (token == TokenNameEOF) || (token == TokenNameERROR)) {
480 return createBlock(blockStart, blockStatements);
482 branchStatement = checkUnreachableStatements(statement);
483 } catch (SyntaxError sytaxErr1) {
484 // if an error occured,
485 // try to find keywords
486 // to parse the rest of the string
487 boolean tokenize = scanner.tokenizeStrings;
489 scanner.tokenizeStrings = true;
492 while (token != TokenNameEOF) {
493 if ((token == TokenNameRBRACE)
494 || (token == TokenNamecase)
495 || (token == TokenNamedefault)
496 || (token == TokenNameelse)
497 || (token == TokenNameelseif)
498 || (token == TokenNameendif)
499 || (token == TokenNameendfor)
500 || (token == TokenNameendforeach)
501 || (token == TokenNameendwhile)
502 || (token == TokenNameendswitch)
503 || (token == TokenNameenddeclare)
504 || (token == TokenNameEOF)
505 || (token == TokenNameERROR)) {
506 return createBlock(blockStart, blockStatements);
508 if (token == TokenNameif || token == TokenNameswitch
509 || token == TokenNamefor
510 || token == TokenNamewhile
511 || token == TokenNamedo
512 || token == TokenNameforeach
513 || token == TokenNamecontinue
514 || token == TokenNamebreak
515 || token == TokenNamereturn
516 || token == TokenNameexit
517 || token == TokenNameecho
518 || token == TokenNameECHO_INVISIBLE
519 || token == TokenNameglobal
520 || token == TokenNamestatic
521 || token == TokenNameunset
522 || token == TokenNamefunction
523 || token == TokenNamedeclare
524 || token == TokenNametry
525 || token == TokenNamecatch
526 || token == TokenNamethrow
527 || token == TokenNamefinal
528 || token == TokenNameabstract
529 || token == TokenNameclass
530 || token == TokenNameinterface) {
533 // System.out.println(scanner.toStringAction(token));
535 // System.out.println(scanner.toStringAction(token));
537 if (token == TokenNameEOF) {
541 scanner.tokenizeStrings = tokenize;
551 private boolean checkUnreachableStatements(Statement statement) {
552 if (statement instanceof ReturnStatement
553 || statement instanceof ContinueStatement
554 || statement instanceof BreakStatement) {
556 } else if (statement instanceof IfStatement
557 && ((IfStatement) statement).checkUnreachable) {
565 * @param blockStatements
568 private Block createBlock(int blockStart, ArrayList blockStatements) {
569 int blockEnd = scanner.getCurrentTokenEndPosition();
570 Block b = Block.EmptyWith(blockStart, blockEnd);
571 b.statements = new Statement[blockStatements.size()];
572 blockStatements.toArray(b.statements);
576 private void functionBody(MethodDeclaration methodDecl) {
577 // '{' [statement-list] '}'
578 if (token == TokenNameLBRACE) {
581 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
582 throwSyntaxError("'{' expected in compound-statement.");
584 if (token != TokenNameRBRACE) {
587 if (token == TokenNameRBRACE) {
588 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
591 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
592 throwSyntaxError("'}' expected in compound-statement.");
596 private Statement statement() {
597 Statement statement = null;
598 Expression expression;
599 int sourceStart = scanner.getCurrentTokenStartPosition();
601 if (token == TokenNameif) {
602 // T_IF '(' expr ')' statement elseif_list else_single
603 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
604 // new_else_single T_ENDIF ';'
606 if (token == TokenNameLPAREN) {
609 throwSyntaxError("'(' expected after 'if' keyword.");
612 if (token == TokenNameRPAREN) {
615 throwSyntaxError("')' expected after 'if' condition.");
617 // create basic IfStatement
618 IfStatement ifStatement = new IfStatement(expression, null, null,
620 if (token == TokenNameCOLON) {
622 ifStatementColon(ifStatement);
624 ifStatement(ifStatement);
627 } else if (token == TokenNameswitch) {
629 if (token == TokenNameLPAREN) {
632 throwSyntaxError("'(' expected after 'switch' keyword.");
635 if (token == TokenNameRPAREN) {
638 throwSyntaxError("')' expected after 'switch' condition.");
642 } else if (token == TokenNamefor) {
644 if (token == TokenNameLPAREN) {
647 throwSyntaxError("'(' expected after 'for' keyword.");
649 if (token == TokenNameSEMICOLON) {
653 if (token == TokenNameSEMICOLON) {
656 throwSyntaxError("';' expected after 'for'.");
659 if (token == TokenNameSEMICOLON) {
663 if (token == TokenNameSEMICOLON) {
666 throwSyntaxError("';' expected after 'for'.");
669 if (token == TokenNameRPAREN) {
673 if (token == TokenNameRPAREN) {
676 throwSyntaxError("')' expected after 'for'.");
681 } else if (token == TokenNamewhile) {
683 if (token == TokenNameLPAREN) {
686 throwSyntaxError("'(' expected after 'while' keyword.");
689 if (token == TokenNameRPAREN) {
692 throwSyntaxError("')' expected after 'while' condition.");
696 } else if (token == TokenNamedo) {
698 if (token == TokenNameLBRACE) {
700 if (token != TokenNameRBRACE) {
703 if (token == TokenNameRBRACE) {
706 throwSyntaxError("'}' expected after 'do' keyword.");
711 if (token == TokenNamewhile) {
713 if (token == TokenNameLPAREN) {
716 throwSyntaxError("'(' expected after 'while' keyword.");
719 if (token == TokenNameRPAREN) {
722 throwSyntaxError("')' expected after 'while' condition.");
725 throwSyntaxError("'while' expected after 'do' keyword.");
727 if (token == TokenNameSEMICOLON) {
730 if (token != TokenNameINLINE_HTML) {
731 throwSyntaxError("';' expected after do-while statement.");
736 } else if (token == TokenNameforeach) {
738 if (token == TokenNameLPAREN) {
741 throwSyntaxError("'(' expected after 'foreach' keyword.");
744 if (token == TokenNameas) {
747 throwSyntaxError("'as' expected after 'foreach' exxpression.");
751 foreach_optional_arg();
752 if (token == TokenNameEQUAL_GREATER) {
754 variable(false, false);
756 if (token == TokenNameRPAREN) {
759 throwSyntaxError("')' expected after 'foreach' expression.");
763 } else if (token == TokenNamebreak) {
766 if (token != TokenNameSEMICOLON) {
769 if (token == TokenNameSEMICOLON) {
770 sourceEnd = scanner.getCurrentTokenEndPosition();
773 if (token != TokenNameINLINE_HTML) {
774 throwSyntaxError("';' expected after 'break'.");
776 sourceEnd = scanner.getCurrentTokenEndPosition();
779 return new BreakStatement(null, sourceStart, sourceEnd);
780 } else if (token == TokenNamecontinue) {
783 if (token != TokenNameSEMICOLON) {
786 if (token == TokenNameSEMICOLON) {
787 sourceEnd = scanner.getCurrentTokenEndPosition();
790 if (token != TokenNameINLINE_HTML) {
791 throwSyntaxError("';' expected after 'continue'.");
793 sourceEnd = scanner.getCurrentTokenEndPosition();
796 return new ContinueStatement(null, sourceStart, sourceEnd);
797 } else if (token == TokenNamereturn) {
800 if (token != TokenNameSEMICOLON) {
803 if (token == TokenNameSEMICOLON) {
804 sourceEnd = scanner.getCurrentTokenEndPosition();
807 if (token != TokenNameINLINE_HTML) {
808 throwSyntaxError("';' expected after 'return'.");
810 sourceEnd = scanner.getCurrentTokenEndPosition();
813 return new ReturnStatement(expression, sourceStart, sourceEnd);
814 } else if (token == TokenNameecho) {
817 if (token == TokenNameSEMICOLON) {
820 if (token != TokenNameINLINE_HTML) {
821 throwSyntaxError("';' expected after 'echo' statement.");
826 } else if (token == TokenNameECHO_INVISIBLE) {
827 // 0-length token directly after PHP short tag <?=
830 if (token == TokenNameSEMICOLON) {
832 // if (token != TokenNameINLINE_HTML) {
833 // // TODO should this become a configurable warning?
834 // reportSyntaxError("Probably '?>' expected after PHP short tag
835 // expression (only the first expression will be echoed).");
838 if (token != TokenNameINLINE_HTML) {
839 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
844 } else if (token == TokenNameINLINE_HTML) {
847 } else if (token == TokenNameglobal) {
850 if (token == TokenNameSEMICOLON) {
853 if (token != TokenNameINLINE_HTML) {
854 throwSyntaxError("';' expected after 'global' statement.");
859 } else if (token == TokenNamestatic) {
862 if (token == TokenNameSEMICOLON) {
865 if (token != TokenNameINLINE_HTML) {
866 throwSyntaxError("';' expected after 'static' statement.");
871 } else if (token == TokenNameunset) {
873 if (token == TokenNameLPAREN) {
876 throwSyntaxError("'(' expected after 'unset' statement.");
879 if (token == TokenNameRPAREN) {
882 throwSyntaxError("')' expected after 'unset' statement.");
884 if (token == TokenNameSEMICOLON) {
887 if (token != TokenNameINLINE_HTML) {
888 throwSyntaxError("';' expected after 'unset' statement.");
893 } else if (token == TokenNamefunction) {
894 MethodDeclaration methodDecl = new MethodDeclaration(
895 this.compilationUnit.compilationResult);
896 methodDecl.declarationSourceStart = scanner
897 .getCurrentTokenStartPosition();
898 methodDecl.modifiers = AccDefault;
899 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
902 functionDefinition(methodDecl);
904 sourceEnd = methodDecl.sourceEnd;
906 || methodDecl.declarationSourceStart > sourceEnd) {
907 sourceEnd = methodDecl.declarationSourceStart + 1;
909 methodDecl.declarationSourceEnd = sourceEnd;
910 methodDecl.sourceEnd = sourceEnd;
913 } else if (token == TokenNamedeclare) {
914 // T_DECLARE '(' declare_list ')' declare_statement
916 if (token != TokenNameLPAREN) {
917 throwSyntaxError("'(' expected in 'declare' statement.");
921 if (token != TokenNameRPAREN) {
922 throwSyntaxError("')' expected in 'declare' statement.");
927 } else if (token == TokenNametry) {
929 if (token != TokenNameLBRACE) {
930 throwSyntaxError("'{' expected in 'try' statement.");
934 if (token != TokenNameRBRACE) {
935 throwSyntaxError("'}' expected in 'try' statement.");
939 } else if (token == TokenNamecatch) {
941 if (token != TokenNameLPAREN) {
942 throwSyntaxError("'(' expected in 'catch' statement.");
945 fully_qualified_class_name();
946 if (token != TokenNameVariable) {
947 throwSyntaxError("Variable expected in 'catch' statement.");
951 if (token != TokenNameRPAREN) {
952 throwSyntaxError("')' expected in 'catch' statement.");
955 if (token != TokenNameLBRACE) {
956 throwSyntaxError("'{' expected in 'catch' statement.");
959 if (token != TokenNameRBRACE) {
961 if (token != TokenNameRBRACE) {
962 throwSyntaxError("'}' expected in 'catch' statement.");
966 additional_catches();
968 } else if (token == TokenNamethrow) {
971 if (token == TokenNameSEMICOLON) {
974 throwSyntaxError("';' expected after 'throw' exxpression.");
977 } else if (token == TokenNamefinal || token == TokenNameabstract
978 || token == TokenNameclass || token == TokenNameinterface) {
980 TypeDeclaration typeDecl = new TypeDeclaration(
981 this.compilationUnit.compilationResult);
982 typeDecl.declarationSourceStart = scanner
983 .getCurrentTokenStartPosition();
984 typeDecl.declarationSourceEnd = scanner
985 .getCurrentTokenEndPosition();
986 typeDecl.name = new char[] { ' ' };
987 // default super class
988 typeDecl.superclass = new SingleTypeReference(
989 TypeConstants.OBJECT, 0);
990 compilationUnit.types.add(typeDecl);
991 pushOnAstStack(typeDecl);
992 unticked_class_declaration_statement(typeDecl);
1000 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
1001 } else if (token == TokenNameLBRACE) {
1003 if (token != TokenNameRBRACE) {
1004 statement = statementList();
1006 if (token == TokenNameRBRACE) {
1010 throwSyntaxError("'}' expected.");
1013 if (token != TokenNameSEMICOLON) {
1016 if (token == TokenNameSEMICOLON) {
1020 if (token == TokenNameRBRACE) {
1021 reportSyntaxError("';' expected after expression (Found token: "
1022 + scanner.toStringAction(token) + ")");
1024 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
1025 throwSyntaxError("';' expected after expression (Found token: "
1026 + scanner.toStringAction(token) + ")");
1036 private void declare_statement() {
1038 // | ':' inner_statement_list T_ENDDECLARE ';'
1040 if (token == TokenNameCOLON) {
1042 // TODO: implement inner_statement_list();
1044 if (token != TokenNameenddeclare) {
1045 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1048 if (token != TokenNameSEMICOLON) {
1049 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1057 private void declare_list() {
1058 // T_STRING '=' static_scalar
1059 // | declare_list ',' T_STRING '=' static_scalar
1061 if (token != TokenNameIdentifier) {
1062 throwSyntaxError("Identifier expected in 'declare' list.");
1065 if (token != TokenNameEQUAL) {
1066 throwSyntaxError("'=' expected in 'declare' list.");
1070 if (token != TokenNameCOMMA) {
1077 private void additional_catches() {
1078 while (token == TokenNamecatch) {
1080 if (token != TokenNameLPAREN) {
1081 throwSyntaxError("'(' expected in 'catch' statement.");
1084 fully_qualified_class_name();
1085 if (token != TokenNameVariable) {
1086 throwSyntaxError("Variable expected in 'catch' statement.");
1090 if (token != TokenNameRPAREN) {
1091 throwSyntaxError("')' expected in 'catch' statement.");
1094 if (token != TokenNameLBRACE) {
1095 throwSyntaxError("'{' expected in 'catch' statement.");
1098 if (token != TokenNameRBRACE) {
1101 if (token != TokenNameRBRACE) {
1102 throwSyntaxError("'}' expected in 'catch' statement.");
1108 private void foreach_variable() {
1111 if (token == TokenNameAND) {
1117 private void foreach_optional_arg() {
1119 // | T_DOUBLE_ARROW foreach_variable
1120 if (token == TokenNameEQUAL_GREATER) {
1126 private void global_var_list() {
1128 // global_var_list ',' global_var
1130 HashSet set = peekVariableSet();
1133 if (token != TokenNameCOMMA) {
1140 private void global_var(HashSet set) {
1144 // | '$' '{' expr '}'
1145 if (token == TokenNameVariable) {
1146 if (fMethodVariables != null) {
1147 VariableInfo info = new VariableInfo(scanner
1148 .getCurrentTokenStartPosition(),
1149 VariableInfo.LEVEL_GLOBAL_VAR);
1150 fMethodVariables.put(new String(scanner
1151 .getCurrentIdentifierSource()), info);
1153 addVariableSet(set);
1155 } else if (token == TokenNameDOLLAR) {
1157 if (token == TokenNameLBRACE) {
1160 if (token != TokenNameRBRACE) {
1161 throwSyntaxError("'}' expected in global variable.");
1170 private void static_var_list() {
1172 // static_var_list ',' T_VARIABLE
1173 // | static_var_list ',' T_VARIABLE '=' static_scalar
1175 // | T_VARIABLE '=' static_scalar,
1176 HashSet set = peekVariableSet();
1178 if (token == TokenNameVariable) {
1179 if (fMethodVariables != null) {
1180 VariableInfo info = new VariableInfo(scanner
1181 .getCurrentTokenStartPosition(),
1182 VariableInfo.LEVEL_STATIC_VAR);
1183 fMethodVariables.put(new String(scanner
1184 .getCurrentIdentifierSource()), info);
1186 addVariableSet(set);
1188 if (token == TokenNameEQUAL) {
1192 if (token != TokenNameCOMMA) {
1202 private void unset_variables() {
1205 // | unset_variables ',' unset_variable
1209 variable(false, false);
1210 if (token != TokenNameCOMMA) {
1217 private final void initializeModifiers() {
1219 this.modifiersSourceStart = -1;
1222 private final void checkAndSetModifiers(int flag) {
1223 this.modifiers |= flag;
1224 if (this.modifiersSourceStart < 0)
1225 this.modifiersSourceStart = this.scanner.startPosition;
1228 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1229 initializeModifiers();
1230 if (token == TokenNameinterface) {
1231 // interface_entry T_STRING
1232 // interface_extends_list
1233 // '{' class_statement_list '}'
1234 checkAndSetModifiers(AccInterface);
1236 typeDecl.modifiers = this.modifiers;
1237 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1238 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1239 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1240 typeDecl.name = scanner.getCurrentIdentifierSource();
1241 if (token > TokenNameKEYWORD) {
1242 problemReporter.phpKeywordWarning(new String[] { scanner
1243 .toStringAction(token) }, scanner
1244 .getCurrentTokenStartPosition(), scanner
1245 .getCurrentTokenEndPosition(), referenceContext,
1246 compilationUnit.compilationResult);
1247 // throwSyntaxError("Don't use a keyword for interface
1249 // + scanner.toStringAction(token) + "].",
1250 // typeDecl.sourceStart, typeDecl.sourceEnd);
1253 interface_extends_list(typeDecl);
1255 typeDecl.name = new char[] { ' ' };
1257 "Interface name expected after keyword 'interface'.",
1258 typeDecl.sourceStart, typeDecl.sourceEnd);
1262 // class_entry_type T_STRING extends_from
1264 // '{' class_statement_list'}'
1266 typeDecl.modifiers = this.modifiers;
1267 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1268 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1270 // identifier 'extends' identifier
1271 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1272 typeDecl.name = scanner.getCurrentIdentifierSource();
1273 if (token > TokenNameKEYWORD) {
1274 problemReporter.phpKeywordWarning(new String[] { scanner
1275 .toStringAction(token) }, scanner
1276 .getCurrentTokenStartPosition(), scanner
1277 .getCurrentTokenEndPosition(), referenceContext,
1278 compilationUnit.compilationResult);
1279 // throwSyntaxError("Don't use a keyword for class
1281 // scanner.toStringAction(token) + "].",
1282 // typeDecl.sourceStart, typeDecl.sourceEnd);
1287 // | T_EXTENDS fully_qualified_class_name
1288 if (token == TokenNameextends) {
1289 class_extends_list(typeDecl);
1291 // if (token != TokenNameIdentifier) {
1292 // throwSyntaxError("Class name expected after keyword
1294 // scanner.getCurrentTokenStartPosition(), scanner
1295 // .getCurrentTokenEndPosition());
1298 implements_list(typeDecl);
1300 typeDecl.name = new char[] { ' ' };
1301 throwSyntaxError("Class name expected after keyword 'class'.",
1302 typeDecl.sourceStart, typeDecl.sourceEnd);
1306 // '{' class_statement_list '}'
1307 if (token == TokenNameLBRACE) {
1309 if (token != TokenNameRBRACE) {
1310 ArrayList list = new ArrayList();
1311 class_statement_list(list);
1312 typeDecl.fields = new FieldDeclaration[list.size()];
1313 for (int i = 0; i < list.size(); i++) {
1314 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1317 if (token == TokenNameRBRACE) {
1318 typeDecl.declarationSourceEnd = scanner
1319 .getCurrentTokenEndPosition();
1322 throwSyntaxError("'}' expected at end of class body.");
1325 throwSyntaxError("'{' expected at start of class body.");
1329 private void class_entry_type() {
1331 // | T_ABSTRACT T_CLASS
1332 // | T_FINAL T_CLASS
1333 if (token == TokenNameclass) {
1335 } else if (token == TokenNameabstract) {
1336 checkAndSetModifiers(AccAbstract);
1338 if (token != TokenNameclass) {
1339 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1342 } else if (token == TokenNamefinal) {
1343 checkAndSetModifiers(AccFinal);
1345 if (token != TokenNameclass) {
1346 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1350 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1354 // private void class_extends(TypeDeclaration typeDecl) {
1356 // // | T_EXTENDS interface_list
1357 // if (token == TokenNameextends) {
1360 // if (token == TokenNameIdentifier) {
1363 // throwSyntaxError("Class name expected after keyword 'extends'.");
1368 private void interface_extends_list(TypeDeclaration typeDecl) {
1370 // | T_EXTENDS interface_list
1371 if (token == TokenNameextends) {
1373 interface_list(typeDecl);
1377 private void class_extends_list(TypeDeclaration typeDecl) {
1379 // | T_EXTENDS interface_list
1380 if (token == TokenNameextends) {
1382 class_list(typeDecl);
1386 private void implements_list(TypeDeclaration typeDecl) {
1388 // | T_IMPLEMENTS interface_list
1389 if (token == TokenNameimplements) {
1391 interface_list(typeDecl);
1395 private void class_list(TypeDeclaration typeDecl) {
1397 // fully_qualified_class_name
1399 if (token == TokenNameIdentifier) {
1400 char[] ident = scanner.getCurrentIdentifierSource();
1401 // TODO make this code working better:
1402 // SingleTypeReference ref =
1403 // ParserUtil.getTypeReference(scanner,
1404 // includesList, ident);
1405 // if (ref != null) {
1406 // typeDecl.superclass = ref;
1410 throwSyntaxError("Classname expected after keyword 'extends'.");
1412 if (token == TokenNameCOMMA) {
1413 reportSyntaxError("No multiple inheritance allowed. Expected token 'implements' or '{'.");
1422 private void interface_list(TypeDeclaration typeDecl) {
1424 // fully_qualified_class_name
1425 // | interface_list ',' fully_qualified_class_name
1427 if (token == TokenNameIdentifier) {
1430 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1432 if (token != TokenNameCOMMA) {
1439 // private void classBody(TypeDeclaration typeDecl) {
1440 // //'{' [class-element-list] '}'
1441 // if (token == TokenNameLBRACE) {
1443 // if (token != TokenNameRBRACE) {
1444 // class_statement_list();
1446 // if (token == TokenNameRBRACE) {
1447 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1450 // throwSyntaxError("'}' expected at end of class body.");
1453 // throwSyntaxError("'{' expected at start of class body.");
1456 private void class_statement_list(ArrayList list) {
1459 class_statement(list);
1460 if (token == TokenNamepublic || token == TokenNameprotected
1461 || token == TokenNameprivate
1462 || token == TokenNamestatic
1463 || token == TokenNameabstract
1464 || token == TokenNamefinal
1465 || token == TokenNamefunction || token == TokenNamevar
1466 || token == TokenNameconst) {
1469 if (token == TokenNameRBRACE) {
1472 throwSyntaxError("'}' at end of class statement.");
1473 } catch (SyntaxError sytaxErr1) {
1474 boolean tokenize = scanner.tokenizeStrings;
1476 scanner.tokenizeStrings = true;
1479 // if an error occured,
1480 // try to find keywords
1481 // to parse the rest of the string
1482 while (token != TokenNameEOF) {
1483 if (token == TokenNamepublic
1484 || token == TokenNameprotected
1485 || token == TokenNameprivate
1486 || token == TokenNamestatic
1487 || token == TokenNameabstract
1488 || token == TokenNamefinal
1489 || token == TokenNamefunction
1490 || token == TokenNamevar
1491 || token == TokenNameconst) {
1494 // System.out.println(scanner.toStringAction(token));
1497 if (token == TokenNameEOF) {
1501 scanner.tokenizeStrings = tokenize;
1507 private void class_statement(ArrayList list) {
1509 // variable_modifiers class_variable_declaration ';'
1510 // | class_constant_declaration ';'
1511 // | method_modifiers T_FUNCTION is_reference T_STRING
1512 // '(' parameter_list ')' method_body
1513 initializeModifiers();
1514 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1516 if (token == TokenNamevar) {
1517 checkAndSetModifiers(AccPublic);
1518 problemReporter.phpVarDeprecatedWarning(scanner
1519 .getCurrentTokenStartPosition(), scanner
1520 .getCurrentTokenEndPosition(), referenceContext,
1521 compilationUnit.compilationResult);
1523 class_variable_declaration(declarationSourceStart, list);
1524 } else if (token == TokenNameconst) {
1525 checkAndSetModifiers(AccFinal | AccPublic);
1526 class_constant_declaration(declarationSourceStart, list);
1527 if (token != TokenNameSEMICOLON) {
1528 throwSyntaxError("';' expected after class const declaration.");
1532 boolean hasModifiers = member_modifiers();
1533 if (token == TokenNamefunction) {
1534 if (!hasModifiers) {
1535 checkAndSetModifiers(AccPublic);
1537 MethodDeclaration methodDecl = new MethodDeclaration(
1538 this.compilationUnit.compilationResult);
1539 methodDecl.declarationSourceStart = scanner
1540 .getCurrentTokenStartPosition();
1541 methodDecl.modifiers = this.modifiers;
1542 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1545 functionDefinition(methodDecl);
1547 int sourceEnd = methodDecl.sourceEnd;
1549 || methodDecl.declarationSourceStart > sourceEnd) {
1550 sourceEnd = methodDecl.declarationSourceStart + 1;
1552 methodDecl.declarationSourceEnd = sourceEnd;
1553 methodDecl.sourceEnd = sourceEnd;
1556 if (!hasModifiers) {
1557 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1559 class_variable_declaration(declarationSourceStart, list);
1564 private void class_constant_declaration(int declarationSourceStart,
1566 // class_constant_declaration ',' T_STRING '=' static_scalar
1567 // | T_CONST T_STRING '=' static_scalar
1568 if (token != TokenNameconst) {
1569 throwSyntaxError("'const' keyword expected in class declaration.");
1574 if (token != TokenNameIdentifier) {
1575 throwSyntaxError("Identifier expected in class const declaration.");
1577 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner
1578 .getCurrentIdentifierSource(), scanner
1579 .getCurrentTokenStartPosition(), scanner
1580 .getCurrentTokenEndPosition());
1581 fieldDeclaration.modifiers = this.modifiers;
1582 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1583 fieldDeclaration.declarationSourceEnd = scanner
1584 .getCurrentTokenEndPosition();
1585 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1586 // fieldDeclaration.type
1587 list.add(fieldDeclaration);
1589 if (token != TokenNameEQUAL) {
1590 throwSyntaxError("'=' expected in class const declaration.");
1594 if (token != TokenNameCOMMA) {
1595 break; // while(true)-loop
1601 // private void variable_modifiers() {
1602 // // variable_modifiers:
1603 // // non_empty_member_modifiers
1605 // initializeModifiers();
1606 // if (token == TokenNamevar) {
1607 // checkAndSetModifiers(AccPublic);
1608 // reportSyntaxError(
1609 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1611 // modifier for field declarations.",
1612 // scanner.getCurrentTokenStartPosition(), scanner
1613 // .getCurrentTokenEndPosition());
1616 // if (!member_modifiers()) {
1617 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1618 // field declarations.");
1622 // private void method_modifiers() {
1623 // //method_modifiers:
1625 // //| non_empty_member_modifiers
1626 // initializeModifiers();
1627 // if (!member_modifiers()) {
1628 // checkAndSetModifiers(AccPublic);
1631 private boolean member_modifiers() {
1638 boolean foundToken = false;
1640 if (token == TokenNamepublic) {
1641 checkAndSetModifiers(AccPublic);
1644 } else if (token == TokenNameprotected) {
1645 checkAndSetModifiers(AccProtected);
1648 } else if (token == TokenNameprivate) {
1649 checkAndSetModifiers(AccPrivate);
1652 } else if (token == TokenNamestatic) {
1653 checkAndSetModifiers(AccStatic);
1656 } else if (token == TokenNameabstract) {
1657 checkAndSetModifiers(AccAbstract);
1660 } else if (token == TokenNamefinal) {
1661 checkAndSetModifiers(AccFinal);
1671 private void class_variable_declaration(int declarationSourceStart,
1673 // class_variable_declaration:
1674 // class_variable_declaration ',' T_VARIABLE
1675 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1677 // | T_VARIABLE '=' static_scalar
1678 char[] classVariable;
1680 if (token == TokenNameVariable) {
1681 classVariable = scanner.getCurrentIdentifierSource();
1682 // indexManager.addIdentifierInformation('v', classVariable,
1685 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1686 classVariable, scanner.getCurrentTokenStartPosition(),
1687 scanner.getCurrentTokenEndPosition());
1688 fieldDeclaration.modifiers = this.modifiers;
1689 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1690 fieldDeclaration.declarationSourceEnd = scanner
1691 .getCurrentTokenEndPosition();
1692 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1693 list.add(fieldDeclaration);
1694 if (fTypeVariables != null) {
1695 VariableInfo info = new VariableInfo(scanner
1696 .getCurrentTokenStartPosition(),
1697 VariableInfo.LEVEL_CLASS_UNIT);
1698 fTypeVariables.put(new String(scanner
1699 .getCurrentIdentifierSource()), info);
1702 if (token == TokenNameEQUAL) {
1707 // if (token == TokenNamethis) {
1708 // throwSyntaxError("'$this' not allowed after keyword 'public'
1709 // 'protected' 'private' 'var'.");
1711 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1713 if (token != TokenNameCOMMA) {
1718 if (token != TokenNameSEMICOLON) {
1719 throwSyntaxError("';' expected after field declaration.");
1724 private void functionDefinition(MethodDeclaration methodDecl) {
1725 boolean isAbstract = false;
1727 if (compilationUnit != null) {
1728 compilationUnit.types.add(methodDecl);
1731 ASTNode node = astStack[astPtr];
1732 if (node instanceof TypeDeclaration) {
1733 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1734 if (typeDecl.methods == null) {
1735 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1737 AbstractMethodDeclaration[] newMethods;
1742 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1743 0, typeDecl.methods.length);
1744 newMethods[typeDecl.methods.length] = methodDecl;
1745 typeDecl.methods = newMethods;
1747 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1749 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1755 pushFunctionVariableSet();
1756 functionDeclarator(methodDecl);
1757 if (token == TokenNameSEMICOLON) {
1759 methodDecl.sourceEnd = scanner
1760 .getCurrentTokenStartPosition() - 1;
1761 throwSyntaxError("Body declaration expected for method: "
1762 + new String(methodDecl.selector));
1767 functionBody(methodDecl);
1769 if (!fStackUnassigned.isEmpty()) {
1770 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1775 private void functionDeclarator(MethodDeclaration methodDecl) {
1776 // identifier '(' [parameter-list] ')'
1777 if (token == TokenNameAND) {
1780 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1781 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1782 if (Scanner.isIdentifierOrKeyword(token)) {
1783 methodDecl.selector = scanner.getCurrentIdentifierSource();
1784 if (token > TokenNameKEYWORD) {
1785 problemReporter.phpKeywordWarning(new String[] { scanner
1786 .toStringAction(token) }, scanner
1787 .getCurrentTokenStartPosition(), scanner
1788 .getCurrentTokenEndPosition(), referenceContext,
1789 compilationUnit.compilationResult);
1792 if (token == TokenNameLPAREN) {
1795 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1796 throwSyntaxError("'(' expected in function declaration.");
1798 if (token != TokenNameRPAREN) {
1799 parameter_list(methodDecl);
1801 if (token != TokenNameRPAREN) {
1802 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1803 throwSyntaxError("')' expected in function declaration.");
1805 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1809 methodDecl.selector = "<undefined>".toCharArray();
1810 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1811 throwSyntaxError("Function name expected after keyword 'function'.");
1816 private void parameter_list(MethodDeclaration methodDecl) {
1817 // non_empty_parameter_list
1819 non_empty_parameter_list(methodDecl, true);
1822 private void non_empty_parameter_list(MethodDeclaration methodDecl,
1823 boolean empty_allowed) {
1824 // optional_class_type T_VARIABLE
1825 // | optional_class_type '&' T_VARIABLE
1826 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1827 // | optional_class_type T_VARIABLE '=' static_scalar
1828 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1829 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1830 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1832 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1834 char[] typeIdentifier = null;
1835 if (token == TokenNameIdentifier || token == TokenNamearray
1836 || token == TokenNameVariable || token == TokenNameAND) {
1837 HashSet set = peekVariableSet();
1839 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature
1842 typeIdentifier = scanner.getCurrentIdentifierSource();
1845 if (token == TokenNameAND) {
1848 if (token == TokenNameVariable) {
1849 if (fMethodVariables != null) {
1851 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1852 info = new VariableInfo(scanner
1853 .getCurrentTokenStartPosition(),
1854 VariableInfo.LEVEL_FUNCTION_DEFINITION);
1856 info = new VariableInfo(scanner
1857 .getCurrentTokenStartPosition(),
1858 VariableInfo.LEVEL_METHOD_DEFINITION);
1860 info.typeIdentifier = typeIdentifier;
1861 fMethodVariables.put(new String(scanner
1862 .getCurrentIdentifierSource()), info);
1864 addVariableSet(set);
1866 if (token == TokenNameEQUAL) {
1871 throwSyntaxError("Variable expected in parameter list.");
1873 if (token != TokenNameCOMMA) {
1880 if (!empty_allowed) {
1881 throwSyntaxError("Identifier expected in parameter list.");
1885 private void optional_class_type() {
1890 // private void parameterDeclaration() {
1892 // //variable-reference
1893 // if (token == TokenNameAND) {
1895 // if (isVariable()) {
1898 // throwSyntaxError("Variable expected after reference operator '&'.");
1901 // //variable '=' constant
1902 // if (token == TokenNameVariable) {
1904 // if (token == TokenNameEQUAL) {
1910 // // if (token == TokenNamethis) {
1911 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1912 // // declaration.");
1916 private void labeledStatementList() {
1917 if (token != TokenNamecase && token != TokenNamedefault) {
1918 throwSyntaxError("'case' or 'default' expected.");
1921 if (token == TokenNamecase) {
1923 expr(); // constant();
1924 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1926 if (token == TokenNameRBRACE) {
1927 // empty case; assumes that the '}' token belongs to the
1929 // switch statement - #1371992
1932 if (token == TokenNamecase || token == TokenNamedefault) {
1933 // empty case statement ?
1938 // else if (token == TokenNameSEMICOLON) {
1940 // "':' expected after 'case' keyword (Found token: " +
1941 // scanner.toStringAction(token) + ")",
1942 // scanner.getCurrentTokenStartPosition(),
1943 // scanner.getCurrentTokenEndPosition(),
1946 // if (token == TokenNamecase) { // empty case statement ?
1952 throwSyntaxError("':' character expected after 'case' constant (Found token: "
1953 + scanner.toStringAction(token) + ")");
1955 } else { // TokenNamedefault
1957 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1959 if (token == TokenNameRBRACE) {
1960 // empty default case; ; assumes that the '}' token
1962 // wrapping switch statement - #1371992
1965 if (token != TokenNamecase) {
1969 throwSyntaxError("':' character expected after 'default'.");
1972 } while (token == TokenNamecase || token == TokenNamedefault);
1975 private void ifStatementColon(IfStatement iState) {
1976 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1977 // new_else_single T_ENDIF ';'
1978 HashSet assignedVariableSet = null;
1980 Block b = inner_statement_list();
1981 iState.thenStatement = b;
1982 checkUnreachable(iState, b);
1984 assignedVariableSet = removeIfVariableSet();
1986 if (token == TokenNameelseif) {
1988 pushIfVariableSet();
1989 new_elseif_list(iState);
1991 HashSet set = removeIfVariableSet();
1992 if (assignedVariableSet != null && set != null) {
1993 assignedVariableSet.addAll(set);
1998 pushIfVariableSet();
1999 new_else_single(iState);
2001 HashSet set = removeIfVariableSet();
2002 if (assignedVariableSet != null) {
2003 HashSet topSet = peekVariableSet();
2004 if (topSet != null) {
2008 topSet.addAll(assignedVariableSet);
2012 if (token != TokenNameendif) {
2013 throwSyntaxError("'endif' expected.");
2016 if (token != TokenNameSEMICOLON) {
2017 reportSyntaxError("';' expected after if-statement.");
2018 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2020 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
2025 private void ifStatement(IfStatement iState) {
2026 // T_IF '(' expr ')' statement elseif_list else_single
2027 HashSet assignedVariableSet = null;
2029 pushIfVariableSet();
2030 Statement s = statement();
2031 iState.thenStatement = s;
2032 checkUnreachable(iState, s);
2034 assignedVariableSet = removeIfVariableSet();
2037 if (token == TokenNameelseif) {
2039 pushIfVariableSet();
2040 elseif_list(iState);
2042 HashSet set = removeIfVariableSet();
2043 if (assignedVariableSet != null && set != null) {
2044 assignedVariableSet.addAll(set);
2049 pushIfVariableSet();
2050 else_single(iState);
2052 HashSet set = removeIfVariableSet();
2053 if (assignedVariableSet != null) {
2054 HashSet topSet = peekVariableSet();
2055 if (topSet != null) {
2059 topSet.addAll(assignedVariableSet);
2065 private void elseif_list(IfStatement iState) {
2067 // | elseif_list T_ELSEIF '(' expr ')' statement
2068 ArrayList conditionList = new ArrayList();
2069 ArrayList statementList = new ArrayList();
2072 while (token == TokenNameelseif) {
2074 if (token == TokenNameLPAREN) {
2077 throwSyntaxError("'(' expected after 'elseif' keyword.");
2080 conditionList.add(e);
2081 if (token == TokenNameRPAREN) {
2084 throwSyntaxError("')' expected after 'elseif' condition.");
2087 statementList.add(s);
2088 checkUnreachable(iState, s);
2090 iState.elseifConditions = new Expression[conditionList.size()];
2091 iState.elseifStatements = new Statement[statementList.size()];
2092 conditionList.toArray(iState.elseifConditions);
2093 statementList.toArray(iState.elseifStatements);
2096 private void new_elseif_list(IfStatement iState) {
2098 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
2099 ArrayList conditionList = new ArrayList();
2100 ArrayList statementList = new ArrayList();
2103 while (token == TokenNameelseif) {
2105 if (token == TokenNameLPAREN) {
2108 throwSyntaxError("'(' expected after 'elseif' keyword.");
2111 conditionList.add(e);
2112 if (token == TokenNameRPAREN) {
2115 throwSyntaxError("')' expected after 'elseif' condition.");
2117 if (token == TokenNameCOLON) {
2120 throwSyntaxError("':' expected after 'elseif' keyword.");
2122 b = inner_statement_list();
2123 statementList.add(b);
2124 checkUnreachable(iState, b);
2126 iState.elseifConditions = new Expression[conditionList.size()];
2127 iState.elseifStatements = new Statement[statementList.size()];
2128 conditionList.toArray(iState.elseifConditions);
2129 statementList.toArray(iState.elseifStatements);
2132 private void else_single(IfStatement iState) {
2135 if (token == TokenNameelse) {
2137 Statement s = statement();
2138 iState.elseStatement = s;
2139 checkUnreachable(iState, s);
2141 iState.checkUnreachable = false;
2143 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2146 private void new_else_single(IfStatement iState) {
2148 // | T_ELSE ':' inner_statement_list
2149 if (token == TokenNameelse) {
2151 if (token == TokenNameCOLON) {
2154 throwSyntaxError("':' expected after 'else' keyword.");
2156 Block b = inner_statement_list();
2157 iState.elseStatement = b;
2158 checkUnreachable(iState, b);
2160 iState.checkUnreachable = false;
2164 private Block inner_statement_list() {
2165 // inner_statement_list inner_statement
2167 return statementList();
2174 private void checkUnreachable(IfStatement iState, Statement s) {
2175 if (s instanceof Block) {
2176 Block b = (Block) s;
2177 if (b.statements == null || b.statements.length == 0) {
2178 iState.checkUnreachable = false;
2180 int off = b.statements.length - 1;
2181 if (!(b.statements[off] instanceof ReturnStatement)
2182 && !(b.statements[off] instanceof ContinueStatement)
2183 && !(b.statements[off] instanceof BreakStatement)) {
2184 if (!(b.statements[off] instanceof IfStatement)
2185 || !((IfStatement) b.statements[off]).checkUnreachable) {
2186 iState.checkUnreachable = false;
2191 if (!(s instanceof ReturnStatement)
2192 && !(s instanceof ContinueStatement)
2193 && !(s instanceof BreakStatement)) {
2194 if (!(s instanceof IfStatement)
2195 || !((IfStatement) s).checkUnreachable) {
2196 iState.checkUnreachable = false;
2202 // private void elseifStatementList() {
2204 // elseifStatement();
2206 // case TokenNameelse:
2208 // if (token == TokenNameCOLON) {
2210 // if (token != TokenNameendif) {
2215 // if (token == TokenNameif) { //'else if'
2218 // throwSyntaxError("':' expected after 'else'.");
2222 // case TokenNameelseif:
2231 // private void elseifStatement() {
2232 // if (token == TokenNameLPAREN) {
2235 // if (token != TokenNameRPAREN) {
2236 // throwSyntaxError("')' expected in else-if-statement.");
2239 // if (token != TokenNameCOLON) {
2240 // throwSyntaxError("':' expected in else-if-statement.");
2243 // if (token != TokenNameendif) {
2249 private void switchStatement() {
2250 if (token == TokenNameCOLON) {
2251 // ':' [labeled-statement-list] 'endswitch' ';'
2253 labeledStatementList();
2254 if (token != TokenNameendswitch) {
2255 throwSyntaxError("'endswitch' expected.");
2258 if (token != TokenNameSEMICOLON) {
2259 throwSyntaxError("';' expected after switch-statement.");
2263 // '{' [labeled-statement-list] '}'
2264 if (token != TokenNameLBRACE) {
2265 throwSyntaxError("'{' expected in switch statement.");
2268 if (token != TokenNameRBRACE) {
2269 labeledStatementList();
2271 if (token != TokenNameRBRACE) {
2272 throwSyntaxError("'}' expected in switch statement.");
2278 private void forStatement() {
2279 if (token == TokenNameCOLON) {
2282 if (token != TokenNameendfor) {
2283 throwSyntaxError("'endfor' expected.");
2286 if (token != TokenNameSEMICOLON) {
2287 throwSyntaxError("';' expected after for-statement.");
2295 private void whileStatement() {
2296 // ':' statement-list 'endwhile' ';'
2297 if (token == TokenNameCOLON) {
2300 if (token != TokenNameendwhile) {
2301 throwSyntaxError("'endwhile' expected.");
2304 if (token != TokenNameSEMICOLON) {
2305 throwSyntaxError("';' expected after while-statement.");
2313 private void foreachStatement() {
2314 if (token == TokenNameCOLON) {
2317 if (token != TokenNameendforeach) {
2318 throwSyntaxError("'endforeach' expected.");
2321 if (token != TokenNameSEMICOLON) {
2322 throwSyntaxError("';' expected after foreach-statement.");
2330 // private void exitStatus() {
2331 // if (token == TokenNameLPAREN) {
2334 // throwSyntaxError("'(' expected in 'exit-status'.");
2336 // if (token != TokenNameRPAREN) {
2339 // if (token == TokenNameRPAREN) {
2342 // throwSyntaxError("')' expected after 'exit-status'.");
2345 private void expressionList() {
2348 if (token == TokenNameCOMMA) {
2356 private Expression expr() {
2358 // | expr_without_variable
2359 // if (token!=TokenNameEOF) {
2360 if (Scanner.TRACE) {
2361 System.out.println("TRACE: expr()");
2363 return expr_without_variable(true, null);
2367 private Expression expr_without_variable(boolean only_variable,
2368 UninitializedVariableHandler initHandler) {
2369 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2370 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2371 Expression expression = new Expression();
2372 expression.sourceStart = exprSourceStart;
2373 // default, may be overwritten
2374 expression.sourceEnd = exprSourceEnd;
2376 // internal_functions_in_yacc
2385 // | T_INC rw_variable
2386 // | T_DEC rw_variable
2387 // | T_INT_CAST expr
2388 // | T_DOUBLE_CAST expr
2389 // | T_STRING_CAST expr
2390 // | T_ARRAY_CAST expr
2391 // | T_OBJECT_CAST expr
2392 // | T_BOOL_CAST expr
2393 // | T_UNSET_CAST expr
2394 // | T_EXIT exit_expr
2396 // | T_ARRAY '(' array_pair_list ')'
2397 // | '`' encaps_list '`'
2398 // | T_LIST '(' assignment_list ')' '=' expr
2399 // | T_NEW class_name_reference ctor_arguments
2400 // | variable '=' expr
2401 // | variable '=' '&' variable
2402 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2403 // | variable T_PLUS_EQUAL expr
2404 // | variable T_MINUS_EQUAL expr
2405 // | variable T_MUL_EQUAL expr
2406 // | variable T_DIV_EQUAL expr
2407 // | variable T_CONCAT_EQUAL expr
2408 // | variable T_MOD_EQUAL expr
2409 // | variable T_AND_EQUAL expr
2410 // | variable T_OR_EQUAL expr
2411 // | variable T_XOR_EQUAL expr
2412 // | variable T_SL_EQUAL expr
2413 // | variable T_SR_EQUAL expr
2414 // | rw_variable T_INC
2415 // | rw_variable T_DEC
2416 // | expr T_BOOLEAN_OR expr
2417 // | expr T_BOOLEAN_AND expr
2418 // | expr T_LOGICAL_OR expr
2419 // | expr T_LOGICAL_AND expr
2420 // | expr T_LOGICAL_XOR expr
2432 // | expr T_IS_IDENTICAL expr
2433 // | expr T_IS_NOT_IDENTICAL expr
2434 // | expr T_IS_EQUAL expr
2435 // | expr T_IS_NOT_EQUAL expr
2437 // | expr T_IS_SMALLER_OR_EQUAL expr
2439 // | expr T_IS_GREATER_OR_EQUAL expr
2440 // | expr T_INSTANCEOF class_name_reference
2441 // | expr '?' expr ':' expr
2442 if (Scanner.TRACE) {
2443 System.out.println("TRACE: expr_without_variable() PART 1");
2446 case TokenNameisset:
2447 // T_ISSET '(' isset_variables ')'
2449 if (token != TokenNameLPAREN) {
2450 throwSyntaxError("'(' expected after keyword 'isset'");
2454 if (token != TokenNameRPAREN) {
2455 throwSyntaxError("')' expected after keyword 'isset'");
2459 case TokenNameempty:
2461 if (token != TokenNameLPAREN) {
2462 throwSyntaxError("'(' expected after keyword 'empty'");
2465 variable(true, false);
2466 if (token != TokenNameRPAREN) {
2467 throwSyntaxError("')' expected after keyword 'empty'");
2472 case TokenNameinclude:
2473 case TokenNameinclude_once:
2474 case TokenNamerequire:
2475 case TokenNamerequire_once:
2476 internal_functions_in_yacc();
2479 case TokenNameLPAREN:
2482 if (token == TokenNameRPAREN) {
2485 throwSyntaxError("')' expected in expression.");
2495 // | T_INT_CAST expr
2496 // | T_DOUBLE_CAST expr
2497 // | T_STRING_CAST expr
2498 // | T_ARRAY_CAST expr
2499 // | T_OBJECT_CAST expr
2500 // | T_BOOL_CAST expr
2501 // | T_UNSET_CAST expr
2502 case TokenNameclone:
2503 case TokenNameprint:
2506 case TokenNameMINUS:
2508 case TokenNameTWIDDLE:
2509 case TokenNameintCAST:
2510 case TokenNamedoubleCAST:
2511 case TokenNamestringCAST:
2512 case TokenNamearrayCAST:
2513 case TokenNameobjectCAST:
2514 case TokenNameboolCAST:
2515 case TokenNameunsetCAST:
2525 // | T_STRING_VARNAME
2527 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2528 // | '`' encaps_list '`'
2530 // | '`' encaps_list '`'
2531 // case TokenNameEncapsedString0:
2532 // scanner.encapsedStringStack.push(new Character('`'));
2535 // if (token == TokenNameEncapsedString0) {
2538 // if (token != TokenNameEncapsedString0) {
2539 // throwSyntaxError("\'`\' expected at end of string" + "(Found
2541 // scanner.toStringAction(token) + " )");
2545 // scanner.encapsedStringStack.pop();
2549 // // | '\'' encaps_list '\''
2550 // case TokenNameEncapsedString1:
2551 // scanner.encapsedStringStack.push(new Character('\''));
2554 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2555 // if (token == TokenNameEncapsedString1) {
2557 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2558 // exprSourceStart, scanner
2559 // .getCurrentTokenEndPosition());
2562 // if (token != TokenNameEncapsedString1) {
2563 // throwSyntaxError("\'\'\' expected at end of string" + "(Found
2565 // + scanner.toStringAction(token) + " )");
2568 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2569 // exprSourceStart, scanner
2570 // .getCurrentTokenEndPosition());
2574 // scanner.encapsedStringStack.pop();
2578 // //| '"' encaps_list '"'
2579 // case TokenNameEncapsedString2:
2580 // scanner.encapsedStringStack.push(new Character('"'));
2583 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2584 // if (token == TokenNameEncapsedString2) {
2586 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2587 // exprSourceStart, scanner
2588 // .getCurrentTokenEndPosition());
2591 // if (token != TokenNameEncapsedString2) {
2592 // throwSyntaxError("'\"' expected at end of string" + "(Found
2594 // scanner.toStringAction(token) + " )");
2597 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2598 // exprSourceStart, scanner
2599 // .getCurrentTokenEndPosition());
2603 // scanner.encapsedStringStack.pop();
2607 case TokenNameStringDoubleQuote:
2608 expression = new StringLiteralDQ(scanner
2609 .getCurrentStringLiteralSource(), scanner
2610 .getCurrentTokenStartPosition(), scanner
2611 .getCurrentTokenEndPosition());
2614 case TokenNameStringSingleQuote:
2615 expression = new StringLiteralSQ(scanner
2616 .getCurrentStringLiteralSource(), scanner
2617 .getCurrentTokenStartPosition(), scanner
2618 .getCurrentTokenEndPosition());
2621 case TokenNameIntegerLiteral:
2622 case TokenNameDoubleLiteral:
2623 case TokenNameStringInterpolated:
2626 case TokenNameCLASS_C:
2627 case TokenNameMETHOD_C:
2628 case TokenNameFUNC_C:
2631 case TokenNameHEREDOC:
2634 case TokenNamearray:
2635 // T_ARRAY '(' array_pair_list ')'
2637 if (token == TokenNameLPAREN) {
2639 if (token == TokenNameRPAREN) {
2644 if (token != TokenNameRPAREN) {
2645 throwSyntaxError("')' or ',' expected after keyword 'array'"
2647 + scanner.toStringAction(token) + ")");
2651 throwSyntaxError("'(' expected after keyword 'array'"
2652 + "(Found token: " + scanner.toStringAction(token)
2657 // | T_LIST '(' assignment_list ')' '=' expr
2659 if (token == TokenNameLPAREN) {
2662 if (token != TokenNameRPAREN) {
2663 throwSyntaxError("')' expected after 'list' keyword.");
2666 if (token != TokenNameEQUAL) {
2667 throwSyntaxError("'=' expected after 'list' keyword.");
2672 throwSyntaxError("'(' expected after 'list' keyword.");
2676 // | T_NEW class_name_reference ctor_arguments
2678 Expression typeRef = class_name_reference();
2680 if (typeRef != null) {
2681 expression = typeRef;
2684 // | T_INC rw_variable
2685 // | T_DEC rw_variable
2686 case TokenNamePLUS_PLUS:
2687 case TokenNameMINUS_MINUS:
2691 // | variable '=' expr
2692 // | variable '=' '&' variable
2693 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2694 // | variable T_PLUS_EQUAL expr
2695 // | variable T_MINUS_EQUAL expr
2696 // | variable T_MUL_EQUAL expr
2697 // | variable T_DIV_EQUAL expr
2698 // | variable T_CONCAT_EQUAL expr
2699 // | variable T_MOD_EQUAL expr
2700 // | variable T_AND_EQUAL expr
2701 // | variable T_OR_EQUAL expr
2702 // | variable T_XOR_EQUAL expr
2703 // | variable T_SL_EQUAL expr
2704 // | variable T_SR_EQUAL expr
2705 // | rw_variable T_INC
2706 // | rw_variable T_DEC
2707 case TokenNameIdentifier:
2708 case TokenNameVariable:
2709 case TokenNameDOLLAR:
2710 Expression lhs = null;
2711 boolean rememberedVar = false;
2712 if (token == TokenNameIdentifier) {
2713 lhs = identifier(true, true);
2718 lhs = variable(true, true);
2722 if (lhs != null && lhs instanceof FieldReference
2723 && token != TokenNameEQUAL
2724 && token != TokenNamePLUS_EQUAL
2725 && token != TokenNameMINUS_EQUAL
2726 && token != TokenNameMULTIPLY_EQUAL
2727 && token != TokenNameDIVIDE_EQUAL
2728 && token != TokenNameDOT_EQUAL
2729 && token != TokenNameREMAINDER_EQUAL
2730 && token != TokenNameAND_EQUAL
2731 && token != TokenNameOR_EQUAL
2732 && token != TokenNameXOR_EQUAL
2733 && token != TokenNameRIGHT_SHIFT_EQUAL
2734 && token != TokenNameLEFT_SHIFT_EQUAL) {
2735 FieldReference ref = (FieldReference) lhs;
2736 if (!containsVariableSet(ref.token)) {
2737 if (null == initHandler
2738 || initHandler.reportError()) {
2739 problemReporter.uninitializedLocalVariable(
2740 new String(ref.token), ref.sourceStart,
2741 ref.sourceEnd, referenceContext,
2742 compilationUnit.compilationResult);
2744 addVariableSet(ref.token);
2749 case TokenNameEQUAL:
2750 if (lhs != null && lhs instanceof FieldReference) {
2751 addVariableSet(((FieldReference) lhs).token);
2754 if (token == TokenNameAND) {
2756 if (token == TokenNamenew) {
2757 // | variable '=' '&' T_NEW class_name_reference
2760 SingleTypeReference classRef = class_name_reference();
2762 if (classRef != null) {
2764 && lhs instanceof FieldReference) {
2766 // $var = & new Object();
2767 if (fMethodVariables != null) {
2768 VariableInfo lhsInfo = new VariableInfo(
2769 ((FieldReference) lhs).sourceStart);
2770 lhsInfo.reference = classRef;
2771 lhsInfo.typeIdentifier = classRef.token;
2772 fMethodVariables.put(new String(
2773 ((FieldReference) lhs).token),
2775 rememberedVar = true;
2780 Expression rhs = variable(false, false);
2781 if (rhs != null && rhs instanceof FieldReference
2783 && lhs instanceof FieldReference) {
2786 if (fMethodVariables != null) {
2787 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
2788 .get(((FieldReference) rhs).token);
2790 && rhsInfo.reference != null) {
2791 VariableInfo lhsInfo = new VariableInfo(
2792 ((FieldReference) lhs).sourceStart);
2793 lhsInfo.reference = rhsInfo.reference;
2794 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2795 fMethodVariables.put(new String(
2796 ((FieldReference) lhs).token),
2798 rememberedVar = true;
2804 Expression rhs = expr();
2805 if (lhs != null && lhs instanceof FieldReference) {
2806 if (rhs != null && rhs instanceof FieldReference) {
2809 if (fMethodVariables != null) {
2810 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
2811 .get(((FieldReference) rhs).token);
2813 && rhsInfo.reference != null) {
2814 VariableInfo lhsInfo = new VariableInfo(
2815 ((FieldReference) lhs).sourceStart);
2816 lhsInfo.reference = rhsInfo.reference;
2817 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2818 fMethodVariables.put(new String(
2819 ((FieldReference) lhs).token),
2821 rememberedVar = true;
2824 } else if (rhs != null
2825 && rhs instanceof SingleTypeReference) {
2827 // $var = new Object();
2828 if (fMethodVariables != null) {
2829 VariableInfo lhsInfo = new VariableInfo(
2830 ((FieldReference) lhs).sourceStart);
2831 lhsInfo.reference = (SingleTypeReference) rhs;
2832 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2833 fMethodVariables.put(new String(
2834 ((FieldReference) lhs).token),
2836 rememberedVar = true;
2841 if (rememberedVar == false && lhs != null
2842 && lhs instanceof FieldReference) {
2843 if (fMethodVariables != null) {
2844 VariableInfo lhsInfo = new VariableInfo(
2845 ((FieldReference) lhs).sourceStart);
2846 fMethodVariables.put(new String(
2847 ((FieldReference) lhs).token), lhsInfo);
2851 case TokenNamePLUS_EQUAL:
2852 case TokenNameMINUS_EQUAL:
2853 case TokenNameMULTIPLY_EQUAL:
2854 case TokenNameDIVIDE_EQUAL:
2855 case TokenNameDOT_EQUAL:
2856 case TokenNameREMAINDER_EQUAL:
2857 case TokenNameAND_EQUAL:
2858 case TokenNameOR_EQUAL:
2859 case TokenNameXOR_EQUAL:
2860 case TokenNameRIGHT_SHIFT_EQUAL:
2861 case TokenNameLEFT_SHIFT_EQUAL:
2862 if (lhs != null && lhs instanceof FieldReference) {
2863 addVariableSet(((FieldReference) lhs).token);
2868 case TokenNamePLUS_PLUS:
2869 case TokenNameMINUS_MINUS:
2873 if (!only_variable) {
2874 throwSyntaxError("Variable expression not allowed (found token '"
2875 + scanner.toStringAction(token) + "').");
2883 if (token != TokenNameINLINE_HTML) {
2884 if (token > TokenNameKEYWORD) {
2888 // System.out.println(scanner.getCurrentTokenStartPosition());
2889 // System.out.println(scanner.getCurrentTokenEndPosition());
2891 throwSyntaxError("Error in expression (found token '"
2892 + scanner.toStringAction(token) + "').");
2897 if (Scanner.TRACE) {
2898 System.out.println("TRACE: expr_without_variable() PART 2");
2900 // | expr T_BOOLEAN_OR expr
2901 // | expr T_BOOLEAN_AND expr
2902 // | expr T_LOGICAL_OR expr
2903 // | expr T_LOGICAL_AND expr
2904 // | expr T_LOGICAL_XOR expr
2916 // | expr T_IS_IDENTICAL expr
2917 // | expr T_IS_NOT_IDENTICAL expr
2918 // | expr T_IS_EQUAL expr
2919 // | expr T_IS_NOT_EQUAL expr
2921 // | expr T_IS_SMALLER_OR_EQUAL expr
2923 // | expr T_IS_GREATER_OR_EQUAL expr
2926 case TokenNameOR_OR:
2928 expression = new OR_OR_Expression(expression, expr(), token);
2930 case TokenNameAND_AND:
2932 expression = new AND_AND_Expression(expression, expr(),
2935 case TokenNameEQUAL_EQUAL:
2937 expression = new EqualExpression(expression, expr(), token);
2947 case TokenNameMINUS:
2948 case TokenNameMULTIPLY:
2949 case TokenNameDIVIDE:
2950 case TokenNameREMAINDER:
2951 case TokenNameLEFT_SHIFT:
2952 case TokenNameRIGHT_SHIFT:
2953 case TokenNameEQUAL_EQUAL_EQUAL:
2954 case TokenNameNOT_EQUAL_EQUAL:
2955 case TokenNameNOT_EQUAL:
2957 case TokenNameLESS_EQUAL:
2958 case TokenNameGREATER:
2959 case TokenNameGREATER_EQUAL:
2961 expression = new BinaryExpression(expression, expr(), token);
2963 // | expr T_INSTANCEOF class_name_reference
2964 // | expr '?' expr ':' expr
2965 case TokenNameinstanceof:
2967 TypeReference classRef = class_name_reference();
2968 if (classRef != null) {
2969 expression = new InstanceOfExpression(expression,
2970 classRef, OperatorIds.INSTANCEOF);
2971 expression.sourceStart = exprSourceStart;
2972 expression.sourceEnd = scanner
2973 .getCurrentTokenEndPosition();
2976 case TokenNameQUESTION:
2978 Expression valueIfTrue = expr();
2979 if (token != TokenNameCOLON) {
2980 throwSyntaxError("':' expected in conditional expression.");
2983 Expression valueIfFalse = expr();
2985 expression = new ConditionalExpression(expression,
2986 valueIfTrue, valueIfFalse);
2992 } catch (SyntaxError e) {
2993 // try to find next token after expression with errors:
2994 if (token == TokenNameSEMICOLON) {
2998 if (token == TokenNameRBRACE || token == TokenNameRPAREN
2999 || token == TokenNameRBRACKET) {
3007 private SingleTypeReference class_name_reference() {
3008 // class_name_reference:
3010 // | dynamic_class_name_reference
3011 SingleTypeReference ref = null;
3012 if (Scanner.TRACE) {
3013 System.out.println("TRACE: class_name_reference()");
3015 if (token == TokenNameIdentifier) {
3016 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3017 scanner.getCurrentTokenStartPosition());
3021 dynamic_class_name_reference();
3026 private void dynamic_class_name_reference() {
3027 // dynamic_class_name_reference:
3028 // base_variable T_OBJECT_OPERATOR object_property
3029 // dynamic_class_name_variable_properties
3031 if (Scanner.TRACE) {
3032 System.out.println("TRACE: dynamic_class_name_reference()");
3034 base_variable(true);
3035 if (token == TokenNameMINUS_GREATER) {
3038 dynamic_class_name_variable_properties();
3042 private void dynamic_class_name_variable_properties() {
3043 // dynamic_class_name_variable_properties:
3044 // dynamic_class_name_variable_properties
3045 // dynamic_class_name_variable_property
3047 if (Scanner.TRACE) {
3049 .println("TRACE: dynamic_class_name_variable_properties()");
3051 while (token == TokenNameMINUS_GREATER) {
3052 dynamic_class_name_variable_property();
3056 private void dynamic_class_name_variable_property() {
3057 // dynamic_class_name_variable_property:
3058 // T_OBJECT_OPERATOR object_property
3059 if (Scanner.TRACE) {
3060 System.out.println("TRACE: dynamic_class_name_variable_property()");
3062 if (token == TokenNameMINUS_GREATER) {
3068 private void ctor_arguments() {
3071 // | '(' function_call_parameter_list ')'
3072 if (token == TokenNameLPAREN) {
3074 if (token == TokenNameRPAREN) {
3078 non_empty_function_call_parameter_list();
3079 if (token != TokenNameRPAREN) {
3080 throwSyntaxError("')' expected in ctor_arguments.");
3086 private void assignment_list() {
3088 // assignment_list ',' assignment_list_element
3089 // | assignment_list_element
3091 assignment_list_element();
3092 if (token != TokenNameCOMMA) {
3099 private void assignment_list_element() {
3100 // assignment_list_element:
3102 // | T_LIST '(' assignment_list ')'
3104 if (token == TokenNameVariable) {
3105 variable(true, false);
3106 } else if (token == TokenNameDOLLAR) {
3107 variable(false, false);
3108 } else if (token == TokenNameIdentifier) {
3109 identifier(true, true);
3111 if (token == TokenNamelist) {
3113 if (token == TokenNameLPAREN) {
3116 if (token != TokenNameRPAREN) {
3117 throwSyntaxError("')' expected after 'list' keyword.");
3121 throwSyntaxError("'(' expected after 'list' keyword.");
3127 private void array_pair_list() {
3130 // | non_empty_array_pair_list possible_comma
3131 non_empty_array_pair_list();
3132 if (token == TokenNameCOMMA) {
3137 private void non_empty_array_pair_list() {
3138 // non_empty_array_pair_list:
3139 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3140 // | non_empty_array_pair_list ',' expr
3141 // | expr T_DOUBLE_ARROW expr
3143 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3144 // | non_empty_array_pair_list ',' '&' w_variable
3145 // | expr T_DOUBLE_ARROW '&' w_variable
3148 if (token == TokenNameAND) {
3150 variable(true, false);
3153 if (token == TokenNameAND) {
3155 variable(true, false);
3156 } else if (token == TokenNameEQUAL_GREATER) {
3158 if (token == TokenNameAND) {
3160 variable(true, false);
3166 if (token != TokenNameCOMMA) {
3170 if (token == TokenNameRPAREN) {
3176 // private void variableList() {
3179 // if (token == TokenNameCOMMA) {
3186 private Expression variable_without_objects(boolean lefthandside,
3187 boolean ignoreVar) {
3188 // variable_without_objects:
3189 // reference_variable
3190 // | simple_indirect_reference reference_variable
3191 if (Scanner.TRACE) {
3192 System.out.println("TRACE: variable_without_objects()");
3194 while (token == TokenNameDOLLAR) {
3197 return reference_variable(lefthandside, ignoreVar);
3200 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3202 // T_STRING '(' function_call_parameter_list ')'
3203 // | class_constant '(' function_call_parameter_list ')'
3204 // | static_member '(' function_call_parameter_list ')'
3205 // | variable_without_objects '(' function_call_parameter_list ')'
3206 char[] defineName = null;
3207 char[] ident = null;
3210 Expression ref = null;
3211 if (Scanner.TRACE) {
3212 System.out.println("TRACE: function_call()");
3214 if (token == TokenNameIdentifier) {
3215 ident = scanner.getCurrentIdentifierSource();
3217 startPos = scanner.getCurrentTokenStartPosition();
3218 endPos = scanner.getCurrentTokenEndPosition();
3221 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3225 if (token == TokenNameIdentifier) {
3230 variable_without_objects(true, false);
3235 ref = variable_without_objects(lefthandside, ignoreVar);
3237 if (token != TokenNameLPAREN) {
3238 if (defineName != null) {
3239 // does this identifier contain only uppercase characters?
3240 if (defineName.length == 3) {
3241 if (defineName[0] == 'd' && defineName[1] == 'i'
3242 && defineName[2] == 'e') {
3245 } else if (defineName.length == 4) {
3246 if (defineName[0] == 't' && defineName[1] == 'r'
3247 && defineName[2] == 'u' && defineName[3] == 'e') {
3249 } else if (defineName[0] == 'n' && defineName[1] == 'u'
3250 && defineName[2] == 'l' && defineName[3] == 'l') {
3253 } else if (defineName.length == 5) {
3254 if (defineName[0] == 'f' && defineName[1] == 'a'
3255 && defineName[2] == 'l' && defineName[3] == 's'
3256 && defineName[4] == 'e') {
3260 if (defineName != null) {
3261 for (int i = 0; i < defineName.length; i++) {
3262 if (Character.isLowerCase(defineName[i])) {
3263 problemReporter.phpUppercaseIdentifierWarning(
3264 startPos, endPos, referenceContext,
3265 compilationUnit.compilationResult);
3273 if (token == TokenNameRPAREN) {
3277 non_empty_function_call_parameter_list();
3278 if (token != TokenNameRPAREN) {
3279 String functionName;
3280 if (ident == null) {
3281 functionName = new String(" ");
3283 functionName = new String(ident);
3285 throwSyntaxError("')' expected in function call ("
3286 + functionName + ").");
3293 private void non_empty_function_call_parameter_list() {
3294 this.non_empty_function_call_parameter_list(null);
3297 // private void function_call_parameter_list() {
3298 // function_call_parameter_list:
3299 // non_empty_function_call_parameter_list { $$ = $1; }
3302 private void non_empty_function_call_parameter_list(String functionName) {
3303 // non_empty_function_call_parameter_list:
3304 // expr_without_variable
3307 // | non_empty_function_call_parameter_list ',' expr_without_variable
3308 // | non_empty_function_call_parameter_list ',' variable
3309 // | non_empty_function_call_parameter_list ',' '&' w_variable
3310 if (Scanner.TRACE) {
3312 .println("TRACE: non_empty_function_call_parameter_list()");
3314 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3315 initHandler.setFunctionName(functionName);
3317 initHandler.incrementArgumentCount();
3318 if (token == TokenNameAND) {
3322 // if (token == TokenNameIdentifier || token ==
3323 // TokenNameVariable
3324 // || token == TokenNameDOLLAR) {
3327 expr_without_variable(true, initHandler);
3330 if (token != TokenNameCOMMA) {
3337 private void fully_qualified_class_name() {
3338 if (token == TokenNameIdentifier) {
3341 throwSyntaxError("Class name expected.");
3345 private void static_member() {
3347 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3348 // variable_without_objects
3349 if (Scanner.TRACE) {
3350 System.out.println("TRACE: static_member()");
3352 fully_qualified_class_name();
3353 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3354 throwSyntaxError("'::' expected after class name (static_member).");
3357 variable_without_objects(false, false);
3360 private Expression base_variable_with_function_calls(boolean lefthandside,
3361 boolean ignoreVar) {
3362 // base_variable_with_function_calls:
3365 if (Scanner.TRACE) {
3366 System.out.println("TRACE: base_variable_with_function_calls()");
3368 return function_call(lefthandside, ignoreVar);
3371 private Expression base_variable(boolean lefthandside) {
3373 // reference_variable
3374 // | simple_indirect_reference reference_variable
3376 Expression ref = null;
3377 if (Scanner.TRACE) {
3378 System.out.println("TRACE: base_variable()");
3380 if (token == TokenNameIdentifier) {
3383 while (token == TokenNameDOLLAR) {
3386 reference_variable(lefthandside, false);
3391 // private void simple_indirect_reference() {
3392 // // simple_indirect_reference:
3394 // //| simple_indirect_reference '$'
3396 private Expression reference_variable(boolean lefthandside,
3397 boolean ignoreVar) {
3398 // reference_variable:
3399 // reference_variable '[' dim_offset ']'
3400 // | reference_variable '{' expr '}'
3401 // | compound_variable
3402 Expression ref = null;
3403 if (Scanner.TRACE) {
3404 System.out.println("TRACE: reference_variable()");
3406 ref = compound_variable(lefthandside, ignoreVar);
3408 if (token == TokenNameLBRACE) {
3412 if (token != TokenNameRBRACE) {
3413 throwSyntaxError("'}' expected in reference variable.");
3416 } else if (token == TokenNameLBRACKET) {
3417 // To remove "ref = null;" here, is probably better than the
3419 // commented in #1368081 - axelcl
3421 if (token != TokenNameRBRACKET) {
3424 if (token != TokenNameRBRACKET) {
3425 throwSyntaxError("']' expected in reference variable.");
3436 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3437 // compound_variable:
3439 // | '$' '{' expr '}'
3440 if (Scanner.TRACE) {
3441 System.out.println("TRACE: compound_variable()");
3443 if (token == TokenNameVariable) {
3444 if (!lefthandside) {
3445 if (!containsVariableSet()) {
3446 // reportSyntaxError("The local variable " + new
3447 // String(scanner.getCurrentIdentifierSource())
3448 // + " may not have been initialized");
3449 problemReporter.uninitializedLocalVariable(new String(
3450 scanner.getCurrentIdentifierSource()), scanner
3451 .getCurrentTokenStartPosition(), scanner
3452 .getCurrentTokenEndPosition(), referenceContext,
3453 compilationUnit.compilationResult);
3460 FieldReference ref = new FieldReference(scanner
3461 .getCurrentIdentifierSource(), scanner
3462 .getCurrentTokenStartPosition());
3466 // because of simple_indirect_reference
3467 while (token == TokenNameDOLLAR) {
3470 if (token != TokenNameLBRACE) {
3471 reportSyntaxError("'{' expected after compound variable token '$'.");
3476 if (token != TokenNameRBRACE) {
3477 throwSyntaxError("'}' expected after compound variable token '$'.");
3482 } // private void dim_offset() { // // dim_offset: // // /* empty */
3487 private void object_property() {
3490 // | variable_without_objects
3491 if (Scanner.TRACE) {
3492 System.out.println("TRACE: object_property()");
3494 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3495 variable_without_objects(false, false);
3501 private void object_dim_list() {
3503 // object_dim_list '[' dim_offset ']'
3504 // | object_dim_list '{' expr '}'
3506 if (Scanner.TRACE) {
3507 System.out.println("TRACE: object_dim_list()");
3511 if (token == TokenNameLBRACE) {
3514 if (token != TokenNameRBRACE) {
3515 throwSyntaxError("'}' expected in object_dim_list.");
3518 } else if (token == TokenNameLBRACKET) {
3520 if (token == TokenNameRBRACKET) {
3525 if (token != TokenNameRBRACKET) {
3526 throwSyntaxError("']' expected in object_dim_list.");
3535 private void variable_name() {
3539 if (Scanner.TRACE) {
3540 System.out.println("TRACE: variable_name()");
3542 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3543 if (token > TokenNameKEYWORD) {
3544 // TODO show a warning "Keyword used as variable" ?
3548 if (token != TokenNameLBRACE) {
3549 throwSyntaxError("'{' expected in variable name.");
3553 if (token != TokenNameRBRACE) {
3554 throwSyntaxError("'}' expected in variable name.");
3560 private void r_variable() {
3561 variable(false, false);
3564 private void w_variable(boolean lefthandside) {
3565 variable(lefthandside, false);
3568 private void rw_variable() {
3569 variable(false, false);
3572 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3574 // base_variable_with_function_calls T_OBJECT_OPERATOR
3575 // object_property method_or_not variable_properties
3576 // | base_variable_with_function_calls
3577 Expression ref = base_variable_with_function_calls(lefthandside,
3579 if (token == TokenNameMINUS_GREATER) {
3584 variable_properties();
3589 private void variable_properties() {
3590 // variable_properties:
3591 // variable_properties variable_property
3593 while (token == TokenNameMINUS_GREATER) {
3594 variable_property();
3598 private void variable_property() {
3599 // variable_property:
3600 // T_OBJECT_OPERATOR object_property method_or_not
3601 if (Scanner.TRACE) {
3602 System.out.println("TRACE: variable_property()");
3604 if (token == TokenNameMINUS_GREATER) {
3609 throwSyntaxError("'->' expected in variable_property.");
3613 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3615 // base_variable_with_function_calls T_OBJECT_OPERATOR
3616 // object_property method_or_not variable_properties
3617 // | base_variable_with_function_calls
3619 // Expression ref = function_call(lefthandside, ignoreVar);
3622 // T_STRING '(' function_call_parameter_list ')'
3623 // | class_constant '(' function_call_parameter_list ')'
3624 // | static_member '(' function_call_parameter_list ')'
3625 // | variable_without_objects '(' function_call_parameter_list ')'
3626 char[] defineName = null;
3627 char[] ident = null;
3630 Expression ref = null;
3631 if (Scanner.TRACE) {
3632 System.out.println("TRACE: function_call()");
3634 if (token == TokenNameIdentifier) {
3635 ident = scanner.getCurrentIdentifierSource();
3637 startPos = scanner.getCurrentTokenStartPosition();
3638 endPos = scanner.getCurrentTokenEndPosition();
3641 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL
3642 || token == TokenNameMINUS_EQUAL
3643 || token == TokenNameMULTIPLY_EQUAL
3644 || token == TokenNameDIVIDE_EQUAL
3645 || token == TokenNameDOT_EQUAL
3646 || token == TokenNameREMAINDER_EQUAL
3647 || token == TokenNameAND_EQUAL
3648 || token == TokenNameOR_EQUAL
3649 || token == TokenNameXOR_EQUAL
3650 || token == TokenNameRIGHT_SHIFT_EQUAL
3651 || token == TokenNameLEFT_SHIFT_EQUAL) {
3652 String error = "Assignment operator '"
3653 + scanner.toStringAction(token)
3654 + "' not allowed after identifier '"
3656 + "' (use 'define(...)' to define constants).";
3657 reportSyntaxError(error);
3661 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3665 if (token == TokenNameIdentifier) {
3670 variable_without_objects(true, false);
3675 ref = variable_without_objects(lefthandside, ignoreVar);
3677 if (token != TokenNameLPAREN) {
3678 if (defineName != null) {
3679 // does this identifier contain only uppercase characters?
3680 if (defineName.length == 3) {
3681 if (defineName[0] == 'd' && defineName[1] == 'i'
3682 && defineName[2] == 'e') {
3685 } else if (defineName.length == 4) {
3686 if (defineName[0] == 't' && defineName[1] == 'r'
3687 && defineName[2] == 'u' && defineName[3] == 'e') {
3689 } else if (defineName[0] == 'n' && defineName[1] == 'u'
3690 && defineName[2] == 'l' && defineName[3] == 'l') {
3693 } else if (defineName.length == 5) {
3694 if (defineName[0] == 'f' && defineName[1] == 'a'
3695 && defineName[2] == 'l' && defineName[3] == 's'
3696 && defineName[4] == 'e') {
3700 if (defineName != null) {
3701 for (int i = 0; i < defineName.length; i++) {
3702 if (Character.isLowerCase(defineName[i])) {
3703 problemReporter.phpUppercaseIdentifierWarning(
3704 startPos, endPos, referenceContext,
3705 compilationUnit.compilationResult);
3711 // TODO is this ok ?
3713 // throwSyntaxError("'(' expected in function call.");
3717 if (token == TokenNameRPAREN) {
3721 String functionName;
3722 if (ident == null) {
3723 functionName = new String(" ");
3725 functionName = new String(ident);
3727 non_empty_function_call_parameter_list(functionName);
3728 if (token != TokenNameRPAREN) {
3729 throwSyntaxError("')' expected in function call ("
3730 + functionName + ").");
3735 if (token == TokenNameMINUS_GREATER) {
3740 variable_properties();
3745 private void method_or_not() {
3747 // '(' function_call_parameter_list ')'
3749 if (Scanner.TRACE) {
3750 System.out.println("TRACE: method_or_not()");
3752 if (token == TokenNameLPAREN) {
3754 if (token == TokenNameRPAREN) {
3758 non_empty_function_call_parameter_list();
3759 if (token != TokenNameRPAREN) {
3760 throwSyntaxError("')' expected in method_or_not.");
3766 private void exit_expr() {
3770 if (token != TokenNameLPAREN) {
3774 if (token == TokenNameRPAREN) {
3779 if (token != TokenNameRPAREN) {
3780 throwSyntaxError("')' expected after keyword 'exit'");
3785 // private void encaps_list() {
3786 // // encaps_list encaps_var
3787 // // | encaps_list T_STRING
3788 // // | encaps_list T_NUM_STRING
3789 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3790 // // | encaps_list T_CHARACTER
3791 // // | encaps_list T_BAD_CHARACTER
3792 // // | encaps_list '['
3793 // // | encaps_list ']'
3794 // // | encaps_list '{'
3795 // // | encaps_list '}'
3796 // // | encaps_list T_OBJECT_OPERATOR
3800 // case TokenNameSTRING:
3803 // case TokenNameLBRACE:
3804 // // scanner.encapsedStringStack.pop();
3807 // case TokenNameRBRACE:
3808 // // scanner.encapsedStringStack.pop();
3811 // case TokenNameLBRACKET:
3812 // // scanner.encapsedStringStack.pop();
3815 // case TokenNameRBRACKET:
3816 // // scanner.encapsedStringStack.pop();
3819 // case TokenNameMINUS_GREATER:
3820 // // scanner.encapsedStringStack.pop();
3823 // case TokenNameVariable:
3824 // case TokenNameDOLLAR_LBRACE:
3825 // case TokenNameLBRACE_DOLLAR:
3829 // char encapsedChar = ((Character)
3830 // scanner.encapsedStringStack.peek()).charValue();
3831 // if (encapsedChar == '$') {
3832 // scanner.encapsedStringStack.pop();
3833 // encapsedChar = ((Character)
3834 // scanner.encapsedStringStack.peek()).charValue();
3835 // switch (encapsedChar) {
3837 // if (token == TokenNameEncapsedString0) {
3840 // token = TokenNameSTRING;
3843 // if (token == TokenNameEncapsedString1) {
3846 // token = TokenNameSTRING;
3849 // if (token == TokenNameEncapsedString2) {
3852 // token = TokenNameSTRING;
3861 // private void encaps_var() {
3863 // // | T_VARIABLE '[' encaps_var_offset ']'
3864 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3865 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3866 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3867 // // | T_CURLY_OPEN variable '}'
3869 // case TokenNameVariable:
3871 // if (token == TokenNameLBRACKET) {
3873 // expr(); //encaps_var_offset();
3874 // if (token != TokenNameRBRACKET) {
3875 // throwSyntaxError("']' expected after variable.");
3877 // // scanner.encapsedStringStack.pop();
3880 // } else if (token == TokenNameMINUS_GREATER) {
3882 // if (token != TokenNameIdentifier) {
3883 // throwSyntaxError("Identifier expected after '->'.");
3885 // // scanner.encapsedStringStack.pop();
3889 // // // scanner.encapsedStringStack.pop();
3890 // // int tempToken = TokenNameSTRING;
3891 // // if (!scanner.encapsedStringStack.isEmpty()
3892 // // && (token == TokenNameEncapsedString0
3893 // // || token == TokenNameEncapsedString1
3894 // // || token == TokenNameEncapsedString2 || token ==
3895 // // TokenNameERROR)) {
3896 // // char encapsedChar = ((Character)
3897 // // scanner.encapsedStringStack.peek())
3899 // // switch (token) {
3900 // // case TokenNameEncapsedString0 :
3901 // // if (encapsedChar == '`') {
3902 // // tempToken = TokenNameEncapsedString0;
3905 // // case TokenNameEncapsedString1 :
3906 // // if (encapsedChar == '\'') {
3907 // // tempToken = TokenNameEncapsedString1;
3910 // // case TokenNameEncapsedString2 :
3911 // // if (encapsedChar == '"') {
3912 // // tempToken = TokenNameEncapsedString2;
3915 // // case TokenNameERROR :
3916 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3917 // // scanner.currentPosition--;
3918 // // getNextToken();
3923 // // token = tempToken;
3926 // case TokenNameDOLLAR_LBRACE:
3928 // if (token == TokenNameDOLLAR_LBRACE) {
3930 // } else if (token == TokenNameIdentifier) {
3932 // if (token == TokenNameLBRACKET) {
3934 // // if (token == TokenNameRBRACKET) {
3935 // // getNextToken();
3938 // if (token != TokenNameRBRACKET) {
3939 // throwSyntaxError("']' expected after '${'.");
3947 // if (token != TokenNameRBRACE) {
3948 // throwSyntaxError("'}' expected.");
3952 // case TokenNameLBRACE_DOLLAR:
3954 // if (token == TokenNameLBRACE_DOLLAR) {
3956 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3958 // if (token == TokenNameLBRACKET) {
3960 // // if (token == TokenNameRBRACKET) {
3961 // // getNextToken();
3964 // if (token != TokenNameRBRACKET) {
3965 // throwSyntaxError("']' expected.");
3969 // } else if (token == TokenNameMINUS_GREATER) {
3971 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3972 // throwSyntaxError("String or Variable token expected.");
3975 // if (token == TokenNameLBRACKET) {
3977 // // if (token == TokenNameRBRACKET) {
3978 // // getNextToken();
3981 // if (token != TokenNameRBRACKET) {
3982 // throwSyntaxError("']' expected after '${'.");
3988 // // if (token != TokenNameRBRACE) {
3989 // // throwSyntaxError("'}' expected after '{$'.");
3991 // // // scanner.encapsedStringStack.pop();
3992 // // getNextToken();
3995 // if (token != TokenNameRBRACE) {
3996 // throwSyntaxError("'}' expected.");
3998 // // scanner.encapsedStringStack.pop();
4005 // private void encaps_var_offset() {
4007 // // | T_NUM_STRING
4010 // case TokenNameSTRING:
4013 // case TokenNameIntegerLiteral:
4016 // case TokenNameVariable:
4019 // case TokenNameIdentifier:
4023 // throwSyntaxError("Variable or String token expected.");
4028 private void internal_functions_in_yacc() {
4031 // case TokenNameisset:
4032 // // T_ISSET '(' isset_variables ')'
4034 // if (token != TokenNameLPAREN) {
4035 // throwSyntaxError("'(' expected after keyword 'isset'");
4038 // isset_variables();
4039 // if (token != TokenNameRPAREN) {
4040 // throwSyntaxError("')' expected after keyword 'isset'");
4044 // case TokenNameempty:
4045 // // T_EMPTY '(' variable ')'
4047 // if (token != TokenNameLPAREN) {
4048 // throwSyntaxError("'(' expected after keyword 'empty'");
4052 // if (token != TokenNameRPAREN) {
4053 // throwSyntaxError("')' expected after keyword 'empty'");
4057 case TokenNameinclude:
4059 checkFileName(token);
4061 case TokenNameinclude_once:
4062 // T_INCLUDE_ONCE expr
4063 checkFileName(token);
4066 // T_EVAL '(' expr ')'
4068 if (token != TokenNameLPAREN) {
4069 throwSyntaxError("'(' expected after keyword 'eval'");
4073 if (token != TokenNameRPAREN) {
4074 throwSyntaxError("')' expected after keyword 'eval'");
4078 case TokenNamerequire:
4080 checkFileName(token);
4082 case TokenNamerequire_once:
4083 // T_REQUIRE_ONCE expr
4084 checkFileName(token);
4090 * Parse and check the include file name
4092 * @param includeToken
4094 private void checkFileName(int includeToken) {
4095 // <include-token> expr
4096 int start = scanner.getCurrentTokenStartPosition();
4097 boolean hasLPAREN = false;
4099 if (token == TokenNameLPAREN) {
4103 Expression expression = expr();
4105 if (token == TokenNameRPAREN) {
4108 throwSyntaxError("')' expected for keyword '"
4109 + scanner.toStringAction(includeToken) + "'");
4112 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4114 if (scanner.compilationUnit != null) {
4115 IResource resource = scanner.compilationUnit.getResource();
4116 if (resource != null && resource instanceof IFile) {
4117 file = (IFile) resource;
4121 tokens = new char[1][];
4122 tokens[0] = currTokenSource;
4124 ImportReference impt = new ImportReference(tokens, currTokenSource,
4125 start, scanner.getCurrentTokenEndPosition(), false);
4126 impt.declarationSourceEnd = impt.sourceEnd;
4127 impt.declarationEnd = impt.declarationSourceEnd;
4128 // endPosition is just before the ;
4129 impt.declarationSourceStart = start;
4130 includesList.add(impt);
4132 if (expression instanceof StringLiteral) {
4133 StringLiteral literal = (StringLiteral) expression;
4134 char[] includeName = literal.source();
4135 if (includeName.length == 0) {
4136 reportSyntaxError("Empty filename after keyword '"
4137 + scanner.toStringAction(includeToken) + "'",
4138 literal.sourceStart, literal.sourceStart + 1);
4140 String includeNameString = new String(includeName);
4141 if (literal instanceof StringLiteralDQ) {
4142 if (includeNameString.indexOf('$') >= 0) {
4143 // assuming that the filename contains a variable => no
4148 if (includeNameString.startsWith("http://")) {
4149 // assuming external include location
4153 // check the filename:
4154 // System.out.println(new
4155 // String(compilationUnit.getFileName())+" - "+
4156 // expression.toStringExpression());
4157 IProject project = file.getProject();
4158 if (project != null) {
4159 IPath path = PHPFileUtil.determineFilePath(
4160 includeNameString, file, project);
4163 // SyntaxError: "File: << >> doesn't exist in project."
4164 String[] args = { expression.toStringExpression(),
4165 project.getLocation().toString() };
4166 problemReporter.phpIncludeNotExistWarning(args,
4167 literal.sourceStart, literal.sourceEnd,
4169 compilationUnit.compilationResult);
4172 String filePath = path.toString();
4173 String ext = file.getRawLocation()
4174 .getFileExtension();
4175 int fileExtensionLength = ext == null ? 0 : ext
4178 IFile f = PHPFileUtil.createFile(path, project);
4180 impt.tokens = CharOperation.splitOn('/', filePath
4181 .toCharArray(), 0, filePath.length()
4182 - fileExtensionLength);
4184 } catch (Exception e) {
4185 // the file is outside of the workspace
4193 private void isset_variables() {
4195 // | isset_variables ','
4196 if (token == TokenNameRPAREN) {
4197 throwSyntaxError("Variable expected after keyword 'isset'");
4200 variable(true, false);
4201 if (token == TokenNameCOMMA) {
4209 private boolean common_scalar() {
4213 // | T_CONSTANT_ENCAPSED_STRING
4220 case TokenNameIntegerLiteral:
4223 case TokenNameDoubleLiteral:
4226 case TokenNameStringDoubleQuote:
4229 case TokenNameStringSingleQuote:
4232 case TokenNameStringInterpolated:
4241 case TokenNameCLASS_C:
4244 case TokenNameMETHOD_C:
4247 case TokenNameFUNC_C:
4254 private void scalar() {
4257 // | T_STRING_VARNAME
4260 // | '"' encaps_list '"'
4261 // | '\'' encaps_list '\''
4262 // | T_START_HEREDOC encaps_list T_END_HEREDOC
4263 throwSyntaxError("Not yet implemented (scalar).");
4266 private void static_scalar() {
4267 // static_scalar: /* compile-time evaluated scalars */
4270 // | '+' static_scalar
4271 // | '-' static_scalar
4272 // | T_ARRAY '(' static_array_pair_list ')'
4273 // | static_class_constant
4274 if (common_scalar()) {
4278 case TokenNameIdentifier:
4280 // static_class_constant:
4281 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4282 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
4284 if (token == TokenNameIdentifier) {
4287 throwSyntaxError("Identifier expected after '::' operator.");
4291 case TokenNameEncapsedString0:
4293 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4294 while (scanner.currentCharacter != '`') {
4295 if (scanner.currentCharacter == '\\') {
4296 scanner.currentPosition++;
4298 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4301 } catch (IndexOutOfBoundsException e) {
4302 throwSyntaxError("'`' expected at end of static string.");
4305 // case TokenNameEncapsedString1:
4307 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4308 // while (scanner.currentCharacter != '\'') {
4309 // if (scanner.currentCharacter == '\\') {
4310 // scanner.currentPosition++;
4312 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4315 // } catch (IndexOutOfBoundsException e) {
4316 // throwSyntaxError("'\'' expected at end of static string.");
4319 // case TokenNameEncapsedString2:
4321 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4322 // while (scanner.currentCharacter != '"') {
4323 // if (scanner.currentCharacter == '\\') {
4324 // scanner.currentPosition++;
4326 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4329 // } catch (IndexOutOfBoundsException e) {
4330 // throwSyntaxError("'\"' expected at end of static string.");
4333 case TokenNameStringSingleQuote:
4336 case TokenNameStringDoubleQuote:
4343 case TokenNameMINUS:
4347 case TokenNamearray:
4349 if (token != TokenNameLPAREN) {
4350 throwSyntaxError("'(' expected after keyword 'array'");
4353 if (token == TokenNameRPAREN) {
4357 non_empty_static_array_pair_list();
4358 if (token != TokenNameRPAREN) {
4359 throwSyntaxError("')' or ',' expected after keyword 'array'");
4363 // case TokenNamenull :
4366 // case TokenNamefalse :
4369 // case TokenNametrue :
4373 throwSyntaxError("Static scalar/constant expected.");
4377 private void non_empty_static_array_pair_list() {
4378 // non_empty_static_array_pair_list:
4379 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4381 // | non_empty_static_array_pair_list ',' static_scalar
4382 // | static_scalar T_DOUBLE_ARROW static_scalar
4386 if (token == TokenNameEQUAL_GREATER) {
4390 if (token != TokenNameCOMMA) {
4394 if (token == TokenNameRPAREN) {
4400 // public void reportSyntaxError() { //int act, int currentKind, int
4401 // // stateStackTop) {
4402 // /* remember current scanner position */
4403 // int startPos = scanner.startPosition;
4404 // int currentPos = scanner.currentPosition;
4406 // this.checkAndReportBracketAnomalies(problemReporter());
4407 // /* reset scanner where it was */
4408 // scanner.startPosition = startPos;
4409 // scanner.currentPosition = currentPos;
4412 public static final int RoundBracket = 0;
4414 public static final int SquareBracket = 1;
4416 public static final int CurlyBracket = 2;
4418 public static final int BracketKinds = 3;
4420 protected int[] nestedMethod; // the ptr is nestedType
4422 protected int nestedType, dimensions;
4424 // variable set stack
4425 final static int VariableStackIncrement = 10;
4427 HashMap fTypeVariables = null;
4429 HashMap fMethodVariables = null;
4431 ArrayList fStackUnassigned = new ArrayList();
4434 final static int AstStackIncrement = 100;
4436 protected int astPtr;
4438 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4440 protected int astLengthPtr;
4442 protected int[] astLengthStack;
4444 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4446 public CompilationUnitDeclaration compilationUnit; /*
4451 protected ReferenceContext referenceContext;
4453 protected ProblemReporter problemReporter;
4455 protected CompilerOptions options;
4457 private ArrayList includesList;
4459 // protected CompilationResult compilationResult;
4461 * Returns this parser's problem reporter initialized with its reference
4462 * context. Also it is assumed that a problem is going to be reported, so
4463 * initializes the compilation result's line positions.
4465 public ProblemReporter problemReporter() {
4466 if (scanner.recordLineSeparator) {
4467 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4470 problemReporter.referenceContext = referenceContext;
4471 return problemReporter;
4475 * Reconsider the entire source looking for inconsistencies in {} () []
4477 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4478 // problemReporter) {
4479 // scanner.wasAcr = false;
4480 // boolean anomaliesDetected = false;
4482 // char[] source = scanner.source;
4483 // int[] leftCount = { 0, 0, 0 };
4484 // int[] rightCount = { 0, 0, 0 };
4485 // int[] depths = { 0, 0, 0 };
4486 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4489 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4491 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4493 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4495 // scanner.currentPosition = scanner.initialPosition; //starting
4497 // // (first-zero-based
4499 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4504 // // ---------Consume white space and handles
4505 // // startPosition---------
4506 // boolean isWhiteSpace;
4508 // scanner.startPosition = scanner.currentPosition;
4509 // // if (((scanner.currentCharacter =
4510 // // source[scanner.currentPosition++]) == '\\') &&
4511 // // (source[scanner.currentPosition] == 'u')) {
4512 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4514 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4515 // (scanner.currentCharacter == '\n'))) {
4516 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4517 // // only record line positions we have not
4519 // scanner.pushLineSeparator();
4522 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4524 // } while (isWhiteSpace && (scanner.currentPosition <
4525 // scanner.eofPosition));
4526 // // -------consume token until } is found---------
4527 // switch (scanner.currentCharacter) {
4529 // int index = leftCount[CurlyBracket]++;
4530 // if (index == leftPositions[CurlyBracket].length) {
4531 // System.arraycopy(leftPositions[CurlyBracket], 0,
4532 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4533 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4534 // new int[index * 2]), 0, index);
4536 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4537 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4541 // int index = rightCount[CurlyBracket]++;
4542 // if (index == rightPositions[CurlyBracket].length) {
4543 // System.arraycopy(rightPositions[CurlyBracket], 0,
4544 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4545 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
4547 // new int[index * 2]), 0, index);
4549 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4550 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4554 // int index = leftCount[RoundBracket]++;
4555 // if (index == leftPositions[RoundBracket].length) {
4556 // System.arraycopy(leftPositions[RoundBracket], 0,
4557 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4558 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4559 // new int[index * 2]), 0, index);
4561 // leftPositions[RoundBracket][index] = scanner.startPosition;
4562 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4566 // int index = rightCount[RoundBracket]++;
4567 // if (index == rightPositions[RoundBracket].length) {
4568 // System.arraycopy(rightPositions[RoundBracket], 0,
4569 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4570 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
4572 // new int[index * 2]), 0, index);
4574 // rightPositions[RoundBracket][index] = scanner.startPosition;
4575 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4579 // int index = leftCount[SquareBracket]++;
4580 // if (index == leftPositions[SquareBracket].length) {
4581 // System.arraycopy(leftPositions[SquareBracket], 0,
4582 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4583 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
4585 // new int[index * 2]), 0, index);
4587 // leftPositions[SquareBracket][index] = scanner.startPosition;
4588 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4592 // int index = rightCount[SquareBracket]++;
4593 // if (index == rightPositions[SquareBracket].length) {
4594 // System.arraycopy(rightPositions[SquareBracket], 0,
4595 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4596 // System.arraycopy(rightDepths[SquareBracket], 0,
4597 // (rightDepths[SquareBracket]
4598 // = new int[index * 2]), 0, index);
4600 // rightPositions[SquareBracket][index] = scanner.startPosition;
4601 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4605 // if (scanner.getNextChar('\\')) {
4606 // scanner.scanEscapeCharacter();
4607 // } else { // consume next character
4608 // scanner.unicodeAsBackSlash = false;
4609 // // if (((scanner.currentCharacter =
4610 // // source[scanner.currentPosition++]) ==
4612 // // (source[scanner.currentPosition] ==
4614 // // scanner.getNextUnicodeChar();
4616 // if (scanner.withoutUnicodePtr != 0) {
4617 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4618 // scanner.currentCharacter;
4622 // scanner.getNextChar('\'');
4626 // // consume next character
4627 // scanner.unicodeAsBackSlash = false;
4628 // // if (((scanner.currentCharacter =
4629 // // source[scanner.currentPosition++]) == '\\') &&
4630 // // (source[scanner.currentPosition] == 'u')) {
4631 // // scanner.getNextUnicodeChar();
4633 // if (scanner.withoutUnicodePtr != 0) {
4634 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4635 // scanner.currentCharacter;
4638 // while (scanner.currentCharacter != '"') {
4639 // if (scanner.currentCharacter == '\r') {
4640 // if (source[scanner.currentPosition] == '\n')
4641 // scanner.currentPosition++;
4642 // break; // the string cannot go further that
4645 // if (scanner.currentCharacter == '\n') {
4646 // break; // the string cannot go further that
4649 // if (scanner.currentCharacter == '\\') {
4650 // scanner.scanEscapeCharacter();
4652 // // consume next character
4653 // scanner.unicodeAsBackSlash = false;
4654 // // if (((scanner.currentCharacter =
4655 // // source[scanner.currentPosition++]) == '\\')
4656 // // && (source[scanner.currentPosition] == 'u'))
4658 // // scanner.getNextUnicodeChar();
4660 // if (scanner.withoutUnicodePtr != 0) {
4661 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4662 // scanner.currentCharacter;
4669 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4671 // //get the next char
4672 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4674 // && (source[scanner.currentPosition] == 'u')) {
4675 // //-------------unicode traitement
4677 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4678 // scanner.currentPosition++;
4679 // while (source[scanner.currentPosition] == 'u') {
4680 // scanner.currentPosition++;
4682 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4684 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4687 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4690 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4692 // || c4 < 0) { //error
4696 // scanner.currentCharacter = 'A';
4697 // } //something different from \n and \r
4699 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4702 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4704 // //get the next char
4705 // scanner.startPosition = scanner.currentPosition;
4706 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4708 // && (source[scanner.currentPosition] == 'u')) {
4709 // //-------------unicode traitement
4711 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4712 // scanner.currentPosition++;
4713 // while (source[scanner.currentPosition] == 'u') {
4714 // scanner.currentPosition++;
4716 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4718 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4721 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4724 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4726 // || c4 < 0) { //error
4730 // scanner.currentCharacter = 'A';
4731 // } //something different from \n
4734 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4738 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4739 // (scanner.currentCharacter == '\n'))) {
4740 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4741 // // only record line positions we
4742 // // have not recorded yet
4743 // scanner.pushLineSeparator();
4744 // if (this.scanner.taskTags != null) {
4745 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4747 // .getCurrentTokenEndPosition());
4753 // if (test > 0) { //traditional and annotation
4755 // boolean star = false;
4756 // // consume next character
4757 // scanner.unicodeAsBackSlash = false;
4758 // // if (((scanner.currentCharacter =
4759 // // source[scanner.currentPosition++]) ==
4761 // // (source[scanner.currentPosition] ==
4763 // // scanner.getNextUnicodeChar();
4765 // if (scanner.withoutUnicodePtr != 0) {
4766 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4767 // scanner.currentCharacter;
4770 // if (scanner.currentCharacter == '*') {
4773 // //get the next char
4774 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4776 // && (source[scanner.currentPosition] == 'u')) {
4777 // //-------------unicode traitement
4779 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4780 // scanner.currentPosition++;
4781 // while (source[scanner.currentPosition] == 'u') {
4782 // scanner.currentPosition++;
4784 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4786 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4789 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4792 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4794 // || c4 < 0) { //error
4798 // scanner.currentCharacter = 'A';
4799 // } //something different from * and /
4801 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4804 // //loop until end of comment */
4805 // while ((scanner.currentCharacter != '/') || (!star)) {
4806 // star = scanner.currentCharacter == '*';
4808 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4810 // && (source[scanner.currentPosition] == 'u')) {
4811 // //-------------unicode traitement
4813 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4814 // scanner.currentPosition++;
4815 // while (source[scanner.currentPosition] == 'u') {
4816 // scanner.currentPosition++;
4818 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4820 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4823 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4826 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4828 // || c4 < 0) { //error
4832 // scanner.currentCharacter = 'A';
4833 // } //something different from * and
4836 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4840 // if (this.scanner.taskTags != null) {
4841 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4842 // this.scanner.getCurrentTokenEndPosition());
4849 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4850 // scanner.scanIdentifierOrKeyword(false);
4853 // if (Character.isDigit(scanner.currentCharacter)) {
4854 // scanner.scanNumber(false);
4858 // //-----------------end switch while
4859 // // try--------------------
4860 // } catch (IndexOutOfBoundsException e) {
4861 // break; // read until EOF
4862 // } catch (InvalidInputException e) {
4863 // return false; // no clue
4866 // if (scanner.recordLineSeparator) {
4867 // compilationUnit.compilationResult.lineSeparatorPositions =
4868 // scanner.getLineEnds();
4870 // // check placement anomalies against other kinds of brackets
4871 // for (int kind = 0; kind < BracketKinds; kind++) {
4872 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4873 // int start = leftPositions[kind][leftIndex]; // deepest
4875 // // find matching closing bracket
4876 // int depth = leftDepths[kind][leftIndex];
4878 // for (int i = 0; i < rightCount[kind]; i++) {
4879 // int pos = rightPositions[kind][i];
4880 // // want matching bracket further in source with same
4882 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4887 // if (end < 0) { // did not find a good closing match
4888 // problemReporter.unmatchedBracket(start, referenceContext,
4889 // compilationUnit.compilationResult);
4892 // // check if even number of opening/closing other brackets
4893 // // in between this pair of brackets
4895 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4897 // for (int i = 0; i < leftCount[otherKind]; i++) {
4898 // int pos = leftPositions[otherKind][i];
4899 // if ((pos > start) && (pos < end))
4902 // for (int i = 0; i < rightCount[otherKind]; i++) {
4903 // int pos = rightPositions[otherKind][i];
4904 // if ((pos > start) && (pos < end))
4907 // if (balance != 0) {
4908 // problemReporter.unmatchedBracket(start, referenceContext,
4909 // compilationUnit.compilationResult); //bracket
4915 // // too many opening brackets ?
4916 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4917 // anomaliesDetected = true;
4918 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
4920 // 1], referenceContext,
4921 // compilationUnit.compilationResult);
4923 // // too many closing brackets ?
4924 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4925 // anomaliesDetected = true;
4926 // problemReporter.unmatchedBracket(rightPositions[kind][i],
4927 // referenceContext,
4928 // compilationUnit.compilationResult);
4930 // if (anomaliesDetected)
4933 // return anomaliesDetected;
4934 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4935 // return anomaliesDetected;
4936 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4937 // return anomaliesDetected;
4940 protected void pushOnAstLengthStack(int pos) {
4942 astLengthStack[++astLengthPtr] = pos;
4943 } catch (IndexOutOfBoundsException e) {
4944 int oldStackLength = astLengthStack.length;
4945 int[] oldPos = astLengthStack;
4946 astLengthStack = new int[oldStackLength + StackIncrement];
4947 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4948 astLengthStack[astLengthPtr] = pos;
4952 protected void pushOnAstStack(ASTNode node) {
4954 * add a new obj on top of the ast stack
4957 astStack[++astPtr] = node;
4958 } catch (IndexOutOfBoundsException e) {
4959 int oldStackLength = astStack.length;
4960 ASTNode[] oldStack = astStack;
4961 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4962 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4963 astPtr = oldStackLength;
4964 astStack[astPtr] = node;
4967 astLengthStack[++astLengthPtr] = 1;
4968 } catch (IndexOutOfBoundsException e) {
4969 int oldStackLength = astLengthStack.length;
4970 int[] oldPos = astLengthStack;
4971 astLengthStack = new int[oldStackLength + AstStackIncrement];
4972 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4973 astLengthStack[astLengthPtr] = 1;
4977 protected void resetModifiers() {
4978 this.modifiers = AccDefault;
4979 this.modifiersSourceStart = -1; // <-- see comment into
4980 // modifiersFlag(int)
4981 this.scanner.commentPtr = -1;
4984 protected void consumePackageDeclarationName(IFile file) {
4985 // create a package name similar to java package names
4986 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
4988 String filePath = file.getRawLocation().toString();
4989 String ext = file.getRawLocation().getFileExtension();
4990 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4991 ImportReference impt;
4993 if (filePath.startsWith(projectPath)) {
4994 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
4995 projectPath.length() + 1, filePath.length()
4996 - fileExtensionLength);
4998 String name = file.getName();
4999 tokens = new char[1][];
5000 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5004 this.compilationUnit.currentPackage = impt = new ImportReference(
5005 tokens, new char[0], 0, 0, true);
5007 impt.declarationSourceStart = 0;
5008 impt.declarationSourceEnd = 0;
5009 impt.declarationEnd = 0;
5010 // endPosition is just before the ;
5014 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5015 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5021 private void pushFunctionVariableSet() {
5022 HashSet set = new HashSet();
5023 if (fStackUnassigned.isEmpty()) {
5024 for (int i = 0; i < GLOBALS.length; i++) {
5025 set.add(GLOBALS[i]);
5028 fStackUnassigned.add(set);
5031 private void pushIfVariableSet() {
5032 if (!fStackUnassigned.isEmpty()) {
5033 HashSet set = new HashSet();
5034 fStackUnassigned.add(set);
5038 private HashSet removeIfVariableSet() {
5039 if (!fStackUnassigned.isEmpty()) {
5040 return (HashSet) fStackUnassigned
5041 .remove(fStackUnassigned.size() - 1);
5047 * Returns the <i>set of assigned variables </i> returns null if no Set is
5048 * defined at the current scanner position
5050 private HashSet peekVariableSet() {
5051 if (!fStackUnassigned.isEmpty()) {
5052 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5058 * add the current identifier source to the <i>set of assigned variables
5063 private void addVariableSet(HashSet set) {
5065 set.add(new String(scanner.getCurrentTokenSource()));
5070 * add the current identifier source to the <i>set of assigned variables
5074 private void addVariableSet() {
5075 HashSet set = peekVariableSet();
5077 set.add(new String(scanner.getCurrentTokenSource()));
5082 * add the current identifier source to the <i>set of assigned variables
5086 private void addVariableSet(char[] token) {
5087 HashSet set = peekVariableSet();
5089 set.add(new String(token));
5094 * check if the current identifier source is in the <i>set of assigned
5095 * variables </i> Returns true, if no set is defined for the current scanner
5099 private boolean containsVariableSet() {
5100 return containsVariableSet(scanner.getCurrentTokenSource());
5103 private boolean containsVariableSet(char[] token) {
5105 if (!fStackUnassigned.isEmpty()) {
5107 String str = new String(token);
5108 for (int i = 0; i < fStackUnassigned.size(); i++) {
5109 set = (HashSet) fStackUnassigned.get(i);
5110 if (set.contains(str)) {