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
465 .getCurrentIdentifierSource()),
466 statement.sourceStart,
467 statement.sourceEnd, referenceContext,
468 compilationUnit.compilationResult);
471 if ((token == TokenNameRBRACE) || (token == TokenNamecase)
472 || (token == TokenNamedefault)
473 || (token == TokenNameelse)
474 || (token == TokenNameelseif)
475 || (token == TokenNameendif)
476 || (token == TokenNameendfor)
477 || (token == TokenNameendforeach)
478 || (token == TokenNameendwhile)
479 || (token == TokenNameendswitch)
480 || (token == TokenNameenddeclare)
481 || (token == TokenNameEOF) || (token == TokenNameERROR)) {
482 return createBlock(blockStart, blockStatements);
484 branchStatement = checkUnreachableStatements(statement);
485 } catch (SyntaxError sytaxErr1) {
486 // if an error occured,
487 // try to find keywords
488 // to parse the rest of the string
489 boolean tokenize = scanner.tokenizeStrings;
491 scanner.tokenizeStrings = true;
494 while (token != TokenNameEOF) {
495 if ((token == TokenNameRBRACE)
496 || (token == TokenNamecase)
497 || (token == TokenNamedefault)
498 || (token == TokenNameelse)
499 || (token == TokenNameelseif)
500 || (token == TokenNameendif)
501 || (token == TokenNameendfor)
502 || (token == TokenNameendforeach)
503 || (token == TokenNameendwhile)
504 || (token == TokenNameendswitch)
505 || (token == TokenNameenddeclare)
506 || (token == TokenNameEOF)
507 || (token == TokenNameERROR)) {
508 return createBlock(blockStart, blockStatements);
510 if (token == TokenNameif || token == TokenNameswitch
511 || token == TokenNamefor
512 || token == TokenNamewhile
513 || token == TokenNamedo
514 || token == TokenNameforeach
515 || token == TokenNamecontinue
516 || token == TokenNamebreak
517 || token == TokenNamereturn
518 || token == TokenNameexit
519 || token == TokenNameecho
520 || token == TokenNameECHO_INVISIBLE
521 || token == TokenNameglobal
522 || token == TokenNamestatic
523 || token == TokenNameunset
524 || token == TokenNamefunction
525 || token == TokenNamedeclare
526 || token == TokenNametry
527 || token == TokenNamecatch
528 || token == TokenNamethrow
529 || token == TokenNamefinal
530 || token == TokenNameabstract
531 || token == TokenNameclass
532 || token == TokenNameinterface) {
535 // System.out.println(scanner.toStringAction(token));
537 // System.out.println(scanner.toStringAction(token));
539 if (token == TokenNameEOF) {
543 scanner.tokenizeStrings = tokenize;
553 private boolean checkUnreachableStatements(Statement statement) {
554 if (statement instanceof ReturnStatement
555 || statement instanceof ContinueStatement
556 || statement instanceof BreakStatement) {
558 } else if (statement instanceof IfStatement
559 && ((IfStatement) statement).checkUnreachable) {
567 * @param blockStatements
570 private Block createBlock(int blockStart, ArrayList blockStatements) {
571 int blockEnd = scanner.getCurrentTokenEndPosition();
572 Block b = Block.EmptyWith(blockStart, blockEnd);
573 b.statements = new Statement[blockStatements.size()];
574 blockStatements.toArray(b.statements);
578 private void functionBody(MethodDeclaration methodDecl) {
579 // '{' [statement-list] '}'
580 if (token == TokenNameLBRACE) {
583 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
584 throwSyntaxError("'{' expected in compound-statement.");
586 if (token != TokenNameRBRACE) {
589 if (token == TokenNameRBRACE) {
590 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
593 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
594 throwSyntaxError("'}' expected in compound-statement.");
598 private Statement statement() {
599 Statement statement = null;
600 Expression expression;
601 int sourceStart = scanner.getCurrentTokenStartPosition();
603 if (token == TokenNameif) {
604 // T_IF '(' expr ')' statement elseif_list else_single
605 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
606 // new_else_single T_ENDIF ';'
608 if (token == TokenNameLPAREN) {
611 throwSyntaxError("'(' expected after 'if' keyword.");
614 if (token == TokenNameRPAREN) {
617 throwSyntaxError("')' expected after 'if' condition.");
619 // create basic IfStatement
620 IfStatement ifStatement = new IfStatement(expression, null, null,
622 if (token == TokenNameCOLON) {
624 ifStatementColon(ifStatement);
626 ifStatement(ifStatement);
629 } else if (token == TokenNameswitch) {
631 if (token == TokenNameLPAREN) {
634 throwSyntaxError("'(' expected after 'switch' keyword.");
637 if (token == TokenNameRPAREN) {
640 throwSyntaxError("')' expected after 'switch' condition.");
644 } else if (token == TokenNamefor) {
646 if (token == TokenNameLPAREN) {
649 throwSyntaxError("'(' expected after 'for' keyword.");
651 if (token == TokenNameSEMICOLON) {
655 if (token == TokenNameSEMICOLON) {
658 throwSyntaxError("';' expected after 'for'.");
661 if (token == TokenNameSEMICOLON) {
665 if (token == TokenNameSEMICOLON) {
668 throwSyntaxError("';' expected after 'for'.");
671 if (token == TokenNameRPAREN) {
675 if (token == TokenNameRPAREN) {
678 throwSyntaxError("')' expected after 'for'.");
683 } else if (token == TokenNamewhile) {
685 if (token == TokenNameLPAREN) {
688 throwSyntaxError("'(' expected after 'while' keyword.");
691 if (token == TokenNameRPAREN) {
694 throwSyntaxError("')' expected after 'while' condition.");
698 } else if (token == TokenNamedo) {
700 if (token == TokenNameLBRACE) {
702 if (token != TokenNameRBRACE) {
705 if (token == TokenNameRBRACE) {
708 throwSyntaxError("'}' expected after 'do' keyword.");
713 if (token == TokenNamewhile) {
715 if (token == TokenNameLPAREN) {
718 throwSyntaxError("'(' expected after 'while' keyword.");
721 if (token == TokenNameRPAREN) {
724 throwSyntaxError("')' expected after 'while' condition.");
727 throwSyntaxError("'while' expected after 'do' keyword.");
729 if (token == TokenNameSEMICOLON) {
732 if (token != TokenNameINLINE_HTML) {
733 throwSyntaxError("';' expected after do-while statement.");
738 } else if (token == TokenNameforeach) {
740 if (token == TokenNameLPAREN) {
743 throwSyntaxError("'(' expected after 'foreach' keyword.");
746 if (token == TokenNameas) {
749 throwSyntaxError("'as' expected after 'foreach' exxpression.");
753 foreach_optional_arg();
754 if (token == TokenNameEQUAL_GREATER) {
756 variable(false, false);
758 if (token == TokenNameRPAREN) {
761 throwSyntaxError("')' expected after 'foreach' expression.");
765 } else if (token == TokenNamebreak) {
768 if (token != TokenNameSEMICOLON) {
771 if (token == TokenNameSEMICOLON) {
772 sourceEnd = scanner.getCurrentTokenEndPosition();
775 if (token != TokenNameINLINE_HTML) {
776 throwSyntaxError("';' expected after 'break'.");
778 sourceEnd = scanner.getCurrentTokenEndPosition();
781 return new BreakStatement(null, sourceStart, sourceEnd);
782 } else if (token == TokenNamecontinue) {
785 if (token != TokenNameSEMICOLON) {
788 if (token == TokenNameSEMICOLON) {
789 sourceEnd = scanner.getCurrentTokenEndPosition();
792 if (token != TokenNameINLINE_HTML) {
793 throwSyntaxError("';' expected after 'continue'.");
795 sourceEnd = scanner.getCurrentTokenEndPosition();
798 return new ContinueStatement(null, sourceStart, sourceEnd);
799 } else if (token == TokenNamereturn) {
802 if (token != TokenNameSEMICOLON) {
805 if (token == TokenNameSEMICOLON) {
806 sourceEnd = scanner.getCurrentTokenEndPosition();
809 if (token != TokenNameINLINE_HTML) {
810 throwSyntaxError("';' expected after 'return'.");
812 sourceEnd = scanner.getCurrentTokenEndPosition();
815 return new ReturnStatement(expression, sourceStart, sourceEnd);
816 } else if (token == TokenNameecho) {
819 if (token == TokenNameSEMICOLON) {
822 if (token != TokenNameINLINE_HTML) {
823 throwSyntaxError("';' expected after 'echo' statement.");
828 } else if (token == TokenNameECHO_INVISIBLE) {
829 // 0-length token directly after PHP short tag <?=
832 if (token == TokenNameSEMICOLON) {
834 // if (token != TokenNameINLINE_HTML) {
835 // // TODO should this become a configurable warning?
836 // reportSyntaxError("Probably '?>' expected after PHP short tag
837 // expression (only the first expression will be echoed).");
840 if (token != TokenNameINLINE_HTML) {
841 throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
846 } else if (token == TokenNameINLINE_HTML) {
849 } else if (token == TokenNameglobal) {
852 if (token == TokenNameSEMICOLON) {
855 if (token != TokenNameINLINE_HTML) {
856 throwSyntaxError("';' expected after 'global' statement.");
861 } else if (token == TokenNameconst) {
862 // TODO make sure you clean this hack up ed_mann.
864 if (token == TokenNameIdentifier) {
866 if (token == TokenNameEQUAL) {
870 } else if (token == TokenNamestatic) {
873 if (token == TokenNameSEMICOLON) {
876 if (token != TokenNameINLINE_HTML) {
877 throwSyntaxError("';' expected after 'static' statement.");
882 } else if (token == TokenNameunset) {
884 if (token == TokenNameLPAREN) {
887 throwSyntaxError("'(' expected after 'unset' statement.");
890 if (token == TokenNameRPAREN) {
893 throwSyntaxError("')' expected after 'unset' statement.");
895 if (token == TokenNameSEMICOLON) {
898 if (token != TokenNameINLINE_HTML) {
899 throwSyntaxError("';' expected after 'unset' statement.");
904 } else if (token == TokenNamefunction) {
905 MethodDeclaration methodDecl = new MethodDeclaration(
906 this.compilationUnit.compilationResult);
907 methodDecl.declarationSourceStart = scanner
908 .getCurrentTokenStartPosition();
909 methodDecl.modifiers = AccDefault;
910 methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
913 functionDefinition(methodDecl);
915 sourceEnd = methodDecl.sourceEnd;
917 || methodDecl.declarationSourceStart > sourceEnd) {
918 sourceEnd = methodDecl.declarationSourceStart + 1;
920 methodDecl.declarationSourceEnd = sourceEnd;
921 methodDecl.sourceEnd = sourceEnd;
924 } else if (token == TokenNamedeclare) {
925 // T_DECLARE '(' declare_list ')' declare_statement
927 if (token != TokenNameLPAREN) {
928 throwSyntaxError("'(' expected in 'declare' statement.");
932 if (token != TokenNameRPAREN) {
933 throwSyntaxError("')' expected in 'declare' statement.");
938 } else if (token == TokenNametry) {
940 if (token != TokenNameLBRACE) {
941 throwSyntaxError("'{' expected in 'try' statement.");
945 if (token != TokenNameRBRACE) {
946 throwSyntaxError("'}' expected in 'try' statement.");
950 } else if (token == TokenNamecatch) {
952 if (token != TokenNameLPAREN) {
953 throwSyntaxError("'(' expected in 'catch' statement.");
956 fully_qualified_class_name();
957 if (token != TokenNameVariable) {
958 throwSyntaxError("Variable expected in 'catch' statement.");
962 if (token != TokenNameRPAREN) {
963 throwSyntaxError("')' expected in 'catch' statement.");
966 if (token != TokenNameLBRACE) {
967 throwSyntaxError("'{' expected in 'catch' statement.");
970 if (token != TokenNameRBRACE) {
972 if (token != TokenNameRBRACE) {
973 throwSyntaxError("'}' expected in 'catch' statement.");
977 additional_catches();
979 } else if (token == TokenNamethrow) {
982 if (token == TokenNameSEMICOLON) {
985 throwSyntaxError("';' expected after 'throw' exxpression.");
988 } else if (token == TokenNamefinal || token == TokenNameabstract
989 || token == TokenNameclass || token == TokenNameinterface) {
991 TypeDeclaration typeDecl = new TypeDeclaration(
992 this.compilationUnit.compilationResult);
993 typeDecl.declarationSourceStart = scanner
994 .getCurrentTokenStartPosition();
995 typeDecl.declarationSourceEnd = scanner
996 .getCurrentTokenEndPosition();
997 typeDecl.name = new char[] { ' ' };
998 // default super class
999 typeDecl.superclass = new SingleTypeReference(
1000 TypeConstants.OBJECT, 0);
1001 compilationUnit.types.add(typeDecl);
1002 pushOnAstStack(typeDecl);
1003 unticked_class_declaration_statement(typeDecl);
1011 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
1012 } else if (token == TokenNameLBRACE) {
1014 if (token != TokenNameRBRACE) {
1015 statement = statementList();
1017 if (token == TokenNameRBRACE) {
1021 throwSyntaxError("'}' expected.");
1024 if (token != TokenNameSEMICOLON) {
1027 if (token == TokenNameSEMICOLON) {
1031 if (token == TokenNameRBRACE) {
1032 reportSyntaxError("';' expected after expression (Found token: "
1033 + scanner.toStringAction(token) + ")");
1035 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
1036 throwSyntaxError("';' expected after expression (Found token: "
1037 + scanner.toStringAction(token) + ")");
1047 private void declare_statement() {
1049 // | ':' inner_statement_list T_ENDDECLARE ';'
1051 if (token == TokenNameCOLON) {
1053 // TODO: implement inner_statement_list();
1055 if (token != TokenNameenddeclare) {
1056 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
1059 if (token != TokenNameSEMICOLON) {
1060 throwSyntaxError("';' expected after 'enddeclare' keyword.");
1068 private void declare_list() {
1069 // T_STRING '=' static_scalar
1070 // | declare_list ',' T_STRING '=' static_scalar
1072 if (token != TokenNameIdentifier) {
1073 throwSyntaxError("Identifier expected in 'declare' list.");
1076 if (token != TokenNameEQUAL) {
1077 throwSyntaxError("'=' expected in 'declare' list.");
1081 if (token != TokenNameCOMMA) {
1088 private void additional_catches() {
1089 while (token == TokenNamecatch) {
1091 if (token != TokenNameLPAREN) {
1092 throwSyntaxError("'(' expected in 'catch' statement.");
1095 fully_qualified_class_name();
1096 if (token != TokenNameVariable) {
1097 throwSyntaxError("Variable expected in 'catch' statement.");
1101 if (token != TokenNameRPAREN) {
1102 throwSyntaxError("')' expected in 'catch' statement.");
1105 if (token != TokenNameLBRACE) {
1106 throwSyntaxError("'{' expected in 'catch' statement.");
1109 if (token != TokenNameRBRACE) {
1112 if (token != TokenNameRBRACE) {
1113 throwSyntaxError("'}' expected in 'catch' statement.");
1119 private void foreach_variable() {
1122 if (token == TokenNameAND) {
1128 private void foreach_optional_arg() {
1130 // | T_DOUBLE_ARROW foreach_variable
1131 if (token == TokenNameEQUAL_GREATER) {
1137 private void global_var_list() {
1139 // global_var_list ',' global_var
1141 HashSet set = peekVariableSet();
1144 if (token != TokenNameCOMMA) {
1151 private void global_var(HashSet set) {
1155 // | '$' '{' expr '}'
1156 if (token == TokenNameVariable) {
1157 if (fMethodVariables != null) {
1158 VariableInfo info = new VariableInfo(
1159 scanner.getCurrentTokenStartPosition(),
1160 VariableInfo.LEVEL_GLOBAL_VAR);
1161 fMethodVariables.put(
1162 new String(scanner.getCurrentIdentifierSource()), info);
1164 addVariableSet(set);
1166 } else if (token == TokenNameDOLLAR) {
1168 if (token == TokenNameLBRACE) {
1171 if (token != TokenNameRBRACE) {
1172 throwSyntaxError("'}' expected in global variable.");
1181 private void static_var_list() {
1183 // static_var_list ',' T_VARIABLE
1184 // | static_var_list ',' T_VARIABLE '=' static_scalar
1186 // | T_VARIABLE '=' static_scalar,
1187 HashSet set = peekVariableSet();
1189 if (token == TokenNameVariable) {
1190 if (fMethodVariables != null) {
1191 VariableInfo info = new VariableInfo(
1192 scanner.getCurrentTokenStartPosition(),
1193 VariableInfo.LEVEL_STATIC_VAR);
1194 fMethodVariables.put(
1195 new String(scanner.getCurrentIdentifierSource()),
1198 addVariableSet(set);
1200 if (token == TokenNameEQUAL) {
1204 if (token != TokenNameCOMMA) {
1214 private void unset_variables() {
1217 // | unset_variables ',' unset_variable
1221 variable(false, false);
1222 if (token != TokenNameCOMMA) {
1229 private final void initializeModifiers() {
1231 this.modifiersSourceStart = -1;
1234 private final void checkAndSetModifiers(int flag) {
1235 this.modifiers |= flag;
1236 if (this.modifiersSourceStart < 0)
1237 this.modifiersSourceStart = this.scanner.startPosition;
1240 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1241 initializeModifiers();
1242 if (token == TokenNameinterface) {
1243 // interface_entry T_STRING
1244 // interface_extends_list
1245 // '{' class_statement_list '}'
1246 checkAndSetModifiers(AccInterface);
1248 typeDecl.modifiers = this.modifiers;
1249 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1250 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1251 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1252 typeDecl.name = scanner.getCurrentIdentifierSource();
1253 if (token > TokenNameKEYWORD) {
1255 .phpKeywordWarning(new String[] { scanner
1256 .toStringAction(token) }, scanner
1257 .getCurrentTokenStartPosition(), scanner
1258 .getCurrentTokenEndPosition(),
1260 compilationUnit.compilationResult);
1261 // throwSyntaxError("Don't use a keyword for interface
1263 // + scanner.toStringAction(token) + "].",
1264 // typeDecl.sourceStart, typeDecl.sourceEnd);
1267 interface_extends_list(typeDecl);
1269 typeDecl.name = new char[] { ' ' };
1271 "Interface name expected after keyword 'interface'.",
1272 typeDecl.sourceStart, typeDecl.sourceEnd);
1276 // class_entry_type T_STRING extends_from
1278 // '{' class_statement_list'}'
1280 typeDecl.modifiers = this.modifiers;
1281 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1282 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1284 // identifier 'extends' identifier
1285 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1286 typeDecl.name = scanner.getCurrentIdentifierSource();
1287 if (token > TokenNameKEYWORD) {
1289 .phpKeywordWarning(new String[] { scanner
1290 .toStringAction(token) }, scanner
1291 .getCurrentTokenStartPosition(), scanner
1292 .getCurrentTokenEndPosition(),
1294 compilationUnit.compilationResult);
1295 // throwSyntaxError("Don't use a keyword for class
1297 // scanner.toStringAction(token) + "].",
1298 // typeDecl.sourceStart, typeDecl.sourceEnd);
1303 // | T_EXTENDS fully_qualified_class_name
1304 if (token == TokenNameextends) {
1305 class_extends_list(typeDecl);
1307 // if (token != TokenNameIdentifier) {
1308 // throwSyntaxError("Class name expected after keyword
1310 // scanner.getCurrentTokenStartPosition(), scanner
1311 // .getCurrentTokenEndPosition());
1314 implements_list(typeDecl);
1316 typeDecl.name = new char[] { ' ' };
1317 throwSyntaxError("Class name expected after keyword 'class'.",
1318 typeDecl.sourceStart, typeDecl.sourceEnd);
1322 // '{' class_statement_list '}'
1323 if (token == TokenNameLBRACE) {
1325 if (token != TokenNameRBRACE) {
1326 ArrayList list = new ArrayList();
1327 class_statement_list(list);
1328 typeDecl.fields = new FieldDeclaration[list.size()];
1329 for (int i = 0; i < list.size(); i++) {
1330 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1333 if (token == TokenNameRBRACE) {
1334 typeDecl.declarationSourceEnd = scanner
1335 .getCurrentTokenEndPosition();
1338 throwSyntaxError("'}' expected at end of class body.");
1341 throwSyntaxError("'{' expected at start of class body.");
1345 private void class_entry_type() {
1347 // | T_ABSTRACT T_CLASS
1348 // | T_FINAL T_CLASS
1349 if (token == TokenNameclass) {
1351 } else if (token == TokenNameabstract) {
1352 checkAndSetModifiers(AccAbstract);
1354 if (token != TokenNameclass) {
1355 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1358 } else if (token == TokenNamefinal) {
1359 checkAndSetModifiers(AccFinal);
1361 if (token != TokenNameclass) {
1362 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1366 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1370 // private void class_extends(TypeDeclaration typeDecl) {
1372 // // | T_EXTENDS interface_list
1373 // if (token == TokenNameextends) {
1376 // if (token == TokenNameIdentifier) {
1379 // throwSyntaxError("Class name expected after keyword 'extends'.");
1384 private void interface_extends_list(TypeDeclaration typeDecl) {
1386 // | T_EXTENDS interface_list
1387 if (token == TokenNameextends) {
1389 interface_list(typeDecl);
1393 private void class_extends_list(TypeDeclaration typeDecl) {
1395 // | T_EXTENDS interface_list
1396 if (token == TokenNameextends) {
1398 class_list(typeDecl);
1402 private void implements_list(TypeDeclaration typeDecl) {
1404 // | T_IMPLEMENTS interface_list
1405 if (token == TokenNameimplements) {
1407 interface_list(typeDecl);
1411 private void class_list(TypeDeclaration typeDecl) {
1413 // fully_qualified_class_name
1415 if (token == TokenNameIdentifier) {
1416 char[] ident = scanner.getCurrentIdentifierSource();
1417 // TODO make this code working better:
1418 // SingleTypeReference ref =
1419 // ParserUtil.getTypeReference(scanner,
1420 // includesList, ident);
1421 // if (ref != null) {
1422 // typeDecl.superclass = ref;
1426 throwSyntaxError("Classname expected after keyword 'extends'.");
1428 if (token == TokenNameCOMMA) {
1429 reportSyntaxError("No multiple inheritance allowed. Expected token 'implements' or '{'.");
1438 private void interface_list(TypeDeclaration typeDecl) {
1440 // fully_qualified_class_name
1441 // | interface_list ',' fully_qualified_class_name
1443 if (token == TokenNameIdentifier) {
1446 throwSyntaxError("Interfacename expected after keyword 'implements'.");
1448 if (token != TokenNameCOMMA) {
1455 // private void classBody(TypeDeclaration typeDecl) {
1456 // //'{' [class-element-list] '}'
1457 // if (token == TokenNameLBRACE) {
1459 // if (token != TokenNameRBRACE) {
1460 // class_statement_list();
1462 // if (token == TokenNameRBRACE) {
1463 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1466 // throwSyntaxError("'}' expected at end of class body.");
1469 // throwSyntaxError("'{' expected at start of class body.");
1472 private void class_statement_list(ArrayList list) {
1475 class_statement(list);
1476 if (token == TokenNamepublic || token == TokenNameprotected
1477 || token == TokenNameprivate
1478 || token == TokenNamestatic
1479 || token == TokenNameabstract
1480 || token == TokenNamefinal
1481 || token == TokenNamefunction || token == TokenNamevar
1482 || token == TokenNameconst) {
1485 if (token == TokenNameRBRACE) {
1488 throwSyntaxError("'}' at end of class statement.");
1489 } catch (SyntaxError sytaxErr1) {
1490 boolean tokenize = scanner.tokenizeStrings;
1492 scanner.tokenizeStrings = true;
1495 // if an error occured,
1496 // try to find keywords
1497 // to parse the rest of the string
1498 while (token != TokenNameEOF) {
1499 if (token == TokenNamepublic
1500 || token == TokenNameprotected
1501 || token == TokenNameprivate
1502 || token == TokenNamestatic
1503 || token == TokenNameabstract
1504 || token == TokenNamefinal
1505 || token == TokenNamefunction
1506 || token == TokenNamevar
1507 || token == TokenNameconst) {
1510 // System.out.println(scanner.toStringAction(token));
1513 if (token == TokenNameEOF) {
1517 scanner.tokenizeStrings = tokenize;
1523 private void class_statement(ArrayList list) {
1525 // variable_modifiers class_variable_declaration ';'
1526 // | class_constant_declaration ';'
1527 // | method_modifiers T_FUNCTION is_reference T_STRING
1528 // '(' parameter_list ')' method_body
1529 initializeModifiers();
1530 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1532 if (token == TokenNamevar) {
1533 checkAndSetModifiers(AccPublic);
1534 problemReporter.phpVarDeprecatedWarning(
1535 scanner.getCurrentTokenStartPosition(),
1536 scanner.getCurrentTokenEndPosition(), referenceContext,
1537 compilationUnit.compilationResult);
1539 class_variable_declaration(declarationSourceStart, list);
1540 } else if (token == TokenNameconst) {
1541 checkAndSetModifiers(AccFinal | AccPublic);
1542 class_constant_declaration(declarationSourceStart, list);
1543 if (token != TokenNameSEMICOLON) {
1544 throwSyntaxError("';' expected after class const declaration.");
1548 boolean hasModifiers = member_modifiers();
1549 if (token == TokenNamefunction) {
1550 if (!hasModifiers) {
1551 checkAndSetModifiers(AccPublic);
1553 MethodDeclaration methodDecl = new MethodDeclaration(
1554 this.compilationUnit.compilationResult);
1555 methodDecl.declarationSourceStart = scanner
1556 .getCurrentTokenStartPosition();
1557 methodDecl.modifiers = this.modifiers;
1558 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1561 functionDefinition(methodDecl);
1563 int sourceEnd = methodDecl.sourceEnd;
1565 || methodDecl.declarationSourceStart > sourceEnd) {
1566 sourceEnd = methodDecl.declarationSourceStart + 1;
1568 methodDecl.declarationSourceEnd = sourceEnd;
1569 methodDecl.sourceEnd = sourceEnd;
1572 if (!hasModifiers) {
1573 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1575 class_variable_declaration(declarationSourceStart, list);
1580 private void class_constant_declaration(int declarationSourceStart,
1582 // class_constant_declaration ',' T_STRING '=' static_scalar
1583 // | T_CONST T_STRING '=' static_scalar
1584 if (token != TokenNameconst) {
1585 throwSyntaxError("'const' keyword expected in class declaration.");
1590 if (token != TokenNameIdentifier) {
1591 throwSyntaxError("Identifier expected in class const declaration.");
1593 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1594 scanner.getCurrentIdentifierSource(),
1595 scanner.getCurrentTokenStartPosition(),
1596 scanner.getCurrentTokenEndPosition());
1597 fieldDeclaration.modifiers = this.modifiers;
1598 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1599 fieldDeclaration.declarationSourceEnd = scanner
1600 .getCurrentTokenEndPosition();
1601 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1602 // fieldDeclaration.type
1603 list.add(fieldDeclaration);
1605 if (token != TokenNameEQUAL) {
1606 throwSyntaxError("'=' expected in class const declaration.");
1610 if (token != TokenNameCOMMA) {
1611 break; // while(true)-loop
1617 // private void variable_modifiers() {
1618 // // variable_modifiers:
1619 // // non_empty_member_modifiers
1621 // initializeModifiers();
1622 // if (token == TokenNamevar) {
1623 // checkAndSetModifiers(AccPublic);
1624 // reportSyntaxError(
1625 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1627 // modifier for field declarations.",
1628 // scanner.getCurrentTokenStartPosition(), scanner
1629 // .getCurrentTokenEndPosition());
1632 // if (!member_modifiers()) {
1633 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1634 // field declarations.");
1638 // private void method_modifiers() {
1639 // //method_modifiers:
1641 // //| non_empty_member_modifiers
1642 // initializeModifiers();
1643 // if (!member_modifiers()) {
1644 // checkAndSetModifiers(AccPublic);
1647 private boolean member_modifiers() {
1654 boolean foundToken = false;
1656 if (token == TokenNamepublic) {
1657 checkAndSetModifiers(AccPublic);
1660 } else if (token == TokenNameprotected) {
1661 checkAndSetModifiers(AccProtected);
1664 } else if (token == TokenNameprivate) {
1665 checkAndSetModifiers(AccPrivate);
1668 } else if (token == TokenNamestatic) {
1669 checkAndSetModifiers(AccStatic);
1672 } else if (token == TokenNameabstract) {
1673 checkAndSetModifiers(AccAbstract);
1676 } else if (token == TokenNamefinal) {
1677 checkAndSetModifiers(AccFinal);
1687 private void class_variable_declaration(int declarationSourceStart,
1689 // class_variable_declaration:
1690 // class_variable_declaration ',' T_VARIABLE
1691 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1693 // | T_VARIABLE '=' static_scalar
1694 char[] classVariable;
1696 if (token == TokenNameVariable) {
1697 classVariable = scanner.getCurrentIdentifierSource();
1698 // indexManager.addIdentifierInformation('v', classVariable,
1701 FieldDeclaration fieldDeclaration = new FieldDeclaration(
1702 classVariable, scanner.getCurrentTokenStartPosition(),
1703 scanner.getCurrentTokenEndPosition());
1704 fieldDeclaration.modifiers = this.modifiers;
1705 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1706 fieldDeclaration.declarationSourceEnd = scanner
1707 .getCurrentTokenEndPosition();
1708 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1709 list.add(fieldDeclaration);
1710 if (fTypeVariables != null) {
1711 VariableInfo info = new VariableInfo(
1712 scanner.getCurrentTokenStartPosition(),
1713 VariableInfo.LEVEL_CLASS_UNIT);
1715 new String(scanner.getCurrentIdentifierSource()),
1719 if (token == TokenNameEQUAL) {
1724 // if (token == TokenNamethis) {
1725 // throwSyntaxError("'$this' not allowed after keyword 'public'
1726 // 'protected' 'private' 'var'.");
1728 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1730 if (token != TokenNameCOMMA) {
1735 if (token != TokenNameSEMICOLON) {
1736 throwSyntaxError("';' expected after field declaration.");
1741 private void functionDefinition(MethodDeclaration methodDecl) {
1742 boolean isAbstract = false;
1744 if (compilationUnit != null) {
1745 compilationUnit.types.add(methodDecl);
1748 ASTNode node = astStack[astPtr];
1749 if (node instanceof TypeDeclaration) {
1750 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1751 if (typeDecl.methods == null) {
1752 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1754 AbstractMethodDeclaration[] newMethods;
1758 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1759 0, typeDecl.methods.length);
1760 newMethods[typeDecl.methods.length] = methodDecl;
1761 typeDecl.methods = newMethods;
1763 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1765 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1771 pushFunctionVariableSet();
1772 functionDeclarator(methodDecl);
1773 if (token == TokenNameSEMICOLON) {
1775 methodDecl.sourceEnd = scanner
1776 .getCurrentTokenStartPosition() - 1;
1777 throwSyntaxError("Body declaration expected for method: "
1778 + new String(methodDecl.selector));
1783 functionBody(methodDecl);
1785 if (!fStackUnassigned.isEmpty()) {
1786 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1791 private void functionDeclarator(MethodDeclaration methodDecl) {
1792 // identifier '(' [parameter-list] ')'
1793 if (token == TokenNameAND) {
1796 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1797 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1798 if (Scanner.isIdentifierOrKeyword(token)) {
1799 methodDecl.selector = scanner.getCurrentIdentifierSource();
1800 if (token > TokenNameKEYWORD) {
1801 problemReporter.phpKeywordWarning(
1802 new String[] { scanner.toStringAction(token) },
1803 scanner.getCurrentTokenStartPosition(),
1804 scanner.getCurrentTokenEndPosition(), referenceContext,
1805 compilationUnit.compilationResult);
1808 if (token == TokenNameLPAREN) {
1811 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1812 throwSyntaxError("'(' expected in function declaration.");
1814 if (token != TokenNameRPAREN) {
1815 parameter_list(methodDecl);
1817 if (token != TokenNameRPAREN) {
1818 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1819 throwSyntaxError("')' expected in function declaration.");
1821 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1825 methodDecl.selector = "<undefined>".toCharArray();
1826 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1827 throwSyntaxError("Function name expected after keyword 'function'.");
1832 private void parameter_list(MethodDeclaration methodDecl) {
1833 // non_empty_parameter_list
1835 non_empty_parameter_list(methodDecl, true);
1838 private void non_empty_parameter_list(MethodDeclaration methodDecl,
1839 boolean empty_allowed) {
1840 // optional_class_type T_VARIABLE
1841 // | optional_class_type '&' T_VARIABLE
1842 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1843 // | optional_class_type T_VARIABLE '=' static_scalar
1844 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1845 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1846 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1848 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1850 char[] typeIdentifier = null;
1851 if (token == TokenNameIdentifier || token == TokenNamearray
1852 || token == TokenNameVariable || token == TokenNameAND) {
1853 HashSet set = peekVariableSet();
1855 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature
1858 typeIdentifier = scanner.getCurrentIdentifierSource();
1861 if (token == TokenNameAND) {
1864 if (token == TokenNameVariable) {
1865 if (fMethodVariables != null) {
1867 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1868 info = new VariableInfo(
1869 scanner.getCurrentTokenStartPosition(),
1870 VariableInfo.LEVEL_FUNCTION_DEFINITION);
1872 info = new VariableInfo(
1873 scanner.getCurrentTokenStartPosition(),
1874 VariableInfo.LEVEL_METHOD_DEFINITION);
1876 info.typeIdentifier = typeIdentifier;
1878 .put(new String(scanner
1879 .getCurrentIdentifierSource()), info);
1881 addVariableSet(set);
1883 if (token == TokenNameEQUAL) {
1888 throwSyntaxError("Variable expected in parameter list.");
1890 if (token != TokenNameCOMMA) {
1897 if (!empty_allowed) {
1898 throwSyntaxError("Identifier expected in parameter list.");
1902 private void optional_class_type() {
1907 // private void parameterDeclaration() {
1909 // //variable-reference
1910 // if (token == TokenNameAND) {
1912 // if (isVariable()) {
1915 // throwSyntaxError("Variable expected after reference operator '&'.");
1918 // //variable '=' constant
1919 // if (token == TokenNameVariable) {
1921 // if (token == TokenNameEQUAL) {
1927 // // if (token == TokenNamethis) {
1928 // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1929 // // declaration.");
1933 private void labeledStatementList() {
1934 if (token != TokenNamecase && token != TokenNamedefault) {
1935 throwSyntaxError("'case' or 'default' expected.");
1938 if (token == TokenNamecase) {
1940 expr(); // constant();
1941 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1943 if (token == TokenNameRBRACE) {
1944 // empty case; assumes that the '}' token belongs to the
1946 // switch statement - #1371992
1949 if (token == TokenNamecase || token == TokenNamedefault) {
1950 // empty case statement ?
1955 // else if (token == TokenNameSEMICOLON) {
1957 // "':' expected after 'case' keyword (Found token: " +
1958 // scanner.toStringAction(token) + ")",
1959 // scanner.getCurrentTokenStartPosition(),
1960 // scanner.getCurrentTokenEndPosition(),
1963 // if (token == TokenNamecase) { // empty case statement ?
1969 throwSyntaxError("':' character expected after 'case' constant (Found token: "
1970 + scanner.toStringAction(token) + ")");
1972 } else { // TokenNamedefault
1974 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1976 if (token == TokenNameRBRACE) {
1977 // empty default case; ; assumes that the '}' token
1979 // wrapping switch statement - #1371992
1982 if (token != TokenNamecase) {
1986 throwSyntaxError("':' character expected after 'default'.");
1989 } while (token == TokenNamecase || token == TokenNamedefault);
1992 private void ifStatementColon(IfStatement iState) {
1993 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1994 // new_else_single T_ENDIF ';'
1995 HashSet assignedVariableSet = null;
1997 Block b = inner_statement_list();
1998 iState.thenStatement = b;
1999 checkUnreachable(iState, b);
2001 assignedVariableSet = removeIfVariableSet();
2003 if (token == TokenNameelseif) {
2005 pushIfVariableSet();
2006 new_elseif_list(iState);
2008 HashSet set = removeIfVariableSet();
2009 if (assignedVariableSet != null && set != null) {
2010 assignedVariableSet.addAll(set);
2015 pushIfVariableSet();
2016 new_else_single(iState);
2018 HashSet set = removeIfVariableSet();
2019 if (assignedVariableSet != null) {
2020 HashSet topSet = peekVariableSet();
2021 if (topSet != null) {
2025 topSet.addAll(assignedVariableSet);
2029 if (token != TokenNameendif) {
2030 throwSyntaxError("'endif' expected.");
2033 if (token != TokenNameSEMICOLON && token != TokenNameINLINE_HTML) {
2034 reportSyntaxError("';' expected after if-statement.");
2035 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2037 iState.sourceEnd = scanner.getCurrentTokenEndPosition();
2042 private void ifStatement(IfStatement iState) {
2043 // T_IF '(' expr ')' statement elseif_list else_single
2044 HashSet assignedVariableSet = null;
2046 pushIfVariableSet();
2047 Statement s = statement();
2048 iState.thenStatement = s;
2049 checkUnreachable(iState, s);
2051 assignedVariableSet = removeIfVariableSet();
2054 if (token == TokenNameelseif) {
2056 pushIfVariableSet();
2057 elseif_list(iState);
2059 HashSet set = removeIfVariableSet();
2060 if (assignedVariableSet != null && set != null) {
2061 assignedVariableSet.addAll(set);
2066 pushIfVariableSet();
2067 else_single(iState);
2069 HashSet set = removeIfVariableSet();
2070 if (assignedVariableSet != null) {
2071 HashSet topSet = peekVariableSet();
2072 if (topSet != null) {
2076 topSet.addAll(assignedVariableSet);
2082 private void elseif_list(IfStatement iState) {
2084 // | elseif_list T_ELSEIF '(' expr ')' statement
2085 ArrayList conditionList = new ArrayList();
2086 ArrayList statementList = new ArrayList();
2089 while (token == TokenNameelseif) {
2091 if (token == TokenNameLPAREN) {
2094 throwSyntaxError("'(' expected after 'elseif' keyword.");
2097 conditionList.add(e);
2098 if (token == TokenNameRPAREN) {
2101 throwSyntaxError("')' expected after 'elseif' condition.");
2104 statementList.add(s);
2105 checkUnreachable(iState, s);
2107 iState.elseifConditions = new Expression[conditionList.size()];
2108 iState.elseifStatements = new Statement[statementList.size()];
2109 conditionList.toArray(iState.elseifConditions);
2110 statementList.toArray(iState.elseifStatements);
2113 private void new_elseif_list(IfStatement iState) {
2115 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
2116 ArrayList conditionList = new ArrayList();
2117 ArrayList statementList = new ArrayList();
2120 while (token == TokenNameelseif) {
2122 if (token == TokenNameLPAREN) {
2125 throwSyntaxError("'(' expected after 'elseif' keyword.");
2128 conditionList.add(e);
2129 if (token == TokenNameRPAREN) {
2132 throwSyntaxError("')' expected after 'elseif' condition.");
2134 if (token == TokenNameCOLON) {
2137 throwSyntaxError("':' expected after 'elseif' keyword.");
2139 b = inner_statement_list();
2140 statementList.add(b);
2141 checkUnreachable(iState, b);
2143 iState.elseifConditions = new Expression[conditionList.size()];
2144 iState.elseifStatements = new Statement[statementList.size()];
2145 conditionList.toArray(iState.elseifConditions);
2146 statementList.toArray(iState.elseifStatements);
2149 private void else_single(IfStatement iState) {
2152 if (token == TokenNameelse) {
2154 Statement s = statement();
2155 iState.elseStatement = s;
2156 checkUnreachable(iState, s);
2158 iState.checkUnreachable = false;
2160 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
2163 private void new_else_single(IfStatement iState) {
2165 // | T_ELSE ':' inner_statement_list
2166 if (token == TokenNameelse) {
2168 if (token == TokenNameCOLON) {
2171 throwSyntaxError("':' expected after 'else' keyword.");
2173 Block b = inner_statement_list();
2174 iState.elseStatement = b;
2175 checkUnreachable(iState, b);
2177 iState.checkUnreachable = false;
2181 private Block inner_statement_list() {
2182 // inner_statement_list inner_statement
2184 return statementList();
2191 private void checkUnreachable(IfStatement iState, Statement s) {
2192 if (s instanceof Block) {
2193 Block b = (Block) s;
2194 if (b.statements == null || b.statements.length == 0) {
2195 iState.checkUnreachable = false;
2197 int off = b.statements.length - 1;
2198 if (!(b.statements[off] instanceof ReturnStatement)
2199 && !(b.statements[off] instanceof ContinueStatement)
2200 && !(b.statements[off] instanceof BreakStatement)) {
2201 if (!(b.statements[off] instanceof IfStatement)
2202 || !((IfStatement) b.statements[off]).checkUnreachable) {
2203 iState.checkUnreachable = false;
2208 if (!(s instanceof ReturnStatement)
2209 && !(s instanceof ContinueStatement)
2210 && !(s instanceof BreakStatement)) {
2211 if (!(s instanceof IfStatement)
2212 || !((IfStatement) s).checkUnreachable) {
2213 iState.checkUnreachable = false;
2219 // private void elseifStatementList() {
2221 // elseifStatement();
2223 // case TokenNameelse:
2225 // if (token == TokenNameCOLON) {
2227 // if (token != TokenNameendif) {
2232 // if (token == TokenNameif) { //'else if'
2235 // throwSyntaxError("':' expected after 'else'.");
2239 // case TokenNameelseif:
2248 // private void elseifStatement() {
2249 // if (token == TokenNameLPAREN) {
2252 // if (token != TokenNameRPAREN) {
2253 // throwSyntaxError("')' expected in else-if-statement.");
2256 // if (token != TokenNameCOLON) {
2257 // throwSyntaxError("':' expected in else-if-statement.");
2260 // if (token != TokenNameendif) {
2266 private void switchStatement() {
2267 if (token == TokenNameCOLON) {
2268 // ':' [labeled-statement-list] 'endswitch' ';'
2270 labeledStatementList();
2271 if (token != TokenNameendswitch) {
2272 throwSyntaxError("'endswitch' expected.");
2275 if (token != TokenNameSEMICOLON && token != TokenNameINLINE_HTML) {
2276 throwSyntaxError("';' expected after switch-statement.");
2280 // '{' [labeled-statement-list] '}'
2281 if (token != TokenNameLBRACE) {
2282 throwSyntaxError("'{' expected in switch statement.");
2285 if (token != TokenNameRBRACE) {
2286 labeledStatementList();
2288 if (token != TokenNameRBRACE) {
2289 throwSyntaxError("'}' expected in switch statement.");
2295 private void forStatement() {
2296 if (token == TokenNameCOLON) {
2299 if (token != TokenNameendfor) {
2300 throwSyntaxError("'endfor' expected.");
2303 if (token != TokenNameSEMICOLON && token != TokenNameINLINE_HTML) {
2304 throwSyntaxError("';' expected after for-statement.");
2312 private void whileStatement() {
2313 // ':' statement-list 'endwhile' ';'
2314 if (token == TokenNameCOLON) {
2317 if (token != TokenNameendwhile) {
2318 throwSyntaxError("'endwhile' expected.");
2321 if (token != TokenNameSEMICOLON && token != TokenNameINLINE_HTML) {
2322 throwSyntaxError("';' expected after while-statement.");
2330 private void foreachStatement() {
2331 if (token == TokenNameCOLON) {
2334 if (token != TokenNameendforeach) {
2335 throwSyntaxError("'endforeach' expected.");
2338 if (token != TokenNameSEMICOLON && token != TokenNameINLINE_HTML) {
2339 throwSyntaxError("';' expected after foreach-statement.");
2347 // private void exitStatus() {
2348 // if (token == TokenNameLPAREN) {
2351 // throwSyntaxError("'(' expected in 'exit-status'.");
2353 // if (token != TokenNameRPAREN) {
2356 // if (token == TokenNameRPAREN) {
2359 // throwSyntaxError("')' expected after 'exit-status'.");
2362 private void expressionList() {
2365 if (token == TokenNameCOMMA) {
2373 private Expression expr() {
2375 // | expr_without_variable
2376 // if (token!=TokenNameEOF) {
2377 if (Scanner.TRACE) {
2378 System.out.println("TRACE: expr()");
2380 return expr_without_variable(true, null);
2384 private Expression expr_without_variable(boolean only_variable,
2385 UninitializedVariableHandler initHandler) {
2386 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2387 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2388 Expression expression = new Expression();
2389 expression.sourceStart = exprSourceStart;
2390 // default, may be overwritten
2391 expression.sourceEnd = exprSourceEnd;
2393 // internal_functions_in_yacc
2402 // | T_INC rw_variable
2403 // | T_DEC rw_variable
2404 // | T_INT_CAST expr
2405 // | T_DOUBLE_CAST expr
2406 // | T_STRING_CAST expr
2407 // | T_ARRAY_CAST expr
2408 // | T_OBJECT_CAST expr
2409 // | T_BOOL_CAST expr
2410 // | T_UNSET_CAST expr
2411 // | T_EXIT exit_expr
2413 // | T_ARRAY '(' array_pair_list ')'
2414 // | '`' encaps_list '`'
2415 // | T_LIST '(' assignment_list ')' '=' expr
2416 // | T_NEW class_name_reference ctor_arguments
2417 // | variable '=' expr
2418 // | variable '=' '&' variable
2419 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2420 // | variable T_PLUS_EQUAL expr
2421 // | variable T_MINUS_EQUAL expr
2422 // | variable T_MUL_EQUAL expr
2423 // | variable T_DIV_EQUAL expr
2424 // | variable T_CONCAT_EQUAL expr
2425 // | variable T_MOD_EQUAL expr
2426 // | variable T_AND_EQUAL expr
2427 // | variable T_OR_EQUAL expr
2428 // | variable T_XOR_EQUAL expr
2429 // | variable T_SL_EQUAL expr
2430 // | variable T_SR_EQUAL expr
2431 // | rw_variable T_INC
2432 // | rw_variable T_DEC
2433 // | expr T_BOOLEAN_OR expr
2434 // | expr T_BOOLEAN_AND expr
2435 // | expr T_LOGICAL_OR expr
2436 // | expr T_LOGICAL_AND expr
2437 // | expr T_LOGICAL_XOR expr
2449 // | expr T_IS_IDENTICAL expr
2450 // | expr T_IS_NOT_IDENTICAL expr
2451 // | expr T_IS_EQUAL expr
2452 // | expr T_IS_NOT_EQUAL expr
2454 // | expr T_IS_SMALLER_OR_EQUAL expr
2456 // | expr T_IS_GREATER_OR_EQUAL expr
2457 // | expr T_INSTANCEOF class_name_reference
2458 // | expr '?' expr ':' expr
2459 if (Scanner.TRACE) {
2460 System.out.println("TRACE: expr_without_variable() PART 1");
2463 case TokenNameisset:
2464 // T_ISSET '(' isset_variables ')'
2466 if (token != TokenNameLPAREN) {
2467 throwSyntaxError("'(' expected after keyword 'isset'");
2471 if (token != TokenNameRPAREN) {
2472 throwSyntaxError("')' expected after keyword 'isset'");
2476 case TokenNameempty:
2478 if (token != TokenNameLPAREN) {
2479 throwSyntaxError("'(' expected after keyword 'empty'");
2482 variable(true, false);
2483 if (token != TokenNameRPAREN) {
2484 throwSyntaxError("')' expected after keyword 'empty'");
2489 case TokenNameinclude:
2490 case TokenNameinclude_once:
2491 case TokenNamerequire:
2492 case TokenNamerequire_once:
2493 case TokenNameNamespace:
2494 case TokenNameconst:
2495 internal_functions_in_yacc();
2497 case TokenNameLPAREN:
2500 if (token == TokenNameRPAREN) {
2503 throwSyntaxError("')' expected in expression.");
2513 // | T_INT_CAST expr
2514 // | T_DOUBLE_CAST expr
2515 // | T_STRING_CAST expr
2516 // | T_ARRAY_CAST expr
2517 // | T_OBJECT_CAST expr
2518 // | T_BOOL_CAST expr
2519 // | T_UNSET_CAST expr
2520 case TokenNameclone:
2521 case TokenNameprint:
2524 case TokenNameMINUS:
2526 case TokenNameTWIDDLE:
2527 case TokenNameintCAST:
2528 case TokenNamedoubleCAST:
2529 case TokenNamestringCAST:
2530 case TokenNamearrayCAST:
2531 case TokenNameobjectCAST:
2532 case TokenNameboolCAST:
2533 case TokenNameunsetCAST:
2543 // | T_STRING_VARNAME
2545 // | T_START_HEREDOC encaps_list T_END_HEREDOC
2546 // | '`' encaps_list '`'
2548 // | '`' encaps_list '`'
2549 // case TokenNameEncapsedString0:
2550 // scanner.encapsedStringStack.push(new Character('`'));
2553 // if (token == TokenNameEncapsedString0) {
2556 // if (token != TokenNameEncapsedString0) {
2557 // throwSyntaxError("\'`\' expected at end of string" + "(Found
2559 // scanner.toStringAction(token) + " )");
2563 // scanner.encapsedStringStack.pop();
2567 // // | '\'' encaps_list '\''
2568 // case TokenNameEncapsedString1:
2569 // scanner.encapsedStringStack.push(new Character('\''));
2572 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2573 // if (token == TokenNameEncapsedString1) {
2575 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2576 // exprSourceStart, scanner
2577 // .getCurrentTokenEndPosition());
2580 // if (token != TokenNameEncapsedString1) {
2581 // throwSyntaxError("\'\'\' expected at end of string" + "(Found
2583 // + scanner.toStringAction(token) + " )");
2586 // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2587 // exprSourceStart, scanner
2588 // .getCurrentTokenEndPosition());
2592 // scanner.encapsedStringStack.pop();
2596 // //| '"' encaps_list '"'
2597 // case TokenNameEncapsedString2:
2598 // scanner.encapsedStringStack.push(new Character('"'));
2601 // exprSourceStart = scanner.getCurrentTokenStartPosition();
2602 // if (token == TokenNameEncapsedString2) {
2604 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2605 // exprSourceStart, scanner
2606 // .getCurrentTokenEndPosition());
2609 // if (token != TokenNameEncapsedString2) {
2610 // throwSyntaxError("'\"' expected at end of string" + "(Found
2612 // scanner.toStringAction(token) + " )");
2615 // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2616 // exprSourceStart, scanner
2617 // .getCurrentTokenEndPosition());
2621 // scanner.encapsedStringStack.pop();
2625 case TokenNameStringDoubleQuote:
2626 expression = new StringLiteralDQ(
2627 scanner.getCurrentStringLiteralSource(),
2628 scanner.getCurrentTokenStartPosition(),
2629 scanner.getCurrentTokenEndPosition());
2632 case TokenNameStringSingleQuote:
2633 expression = new StringLiteralSQ(
2634 scanner.getCurrentStringLiteralSource(),
2635 scanner.getCurrentTokenStartPosition(),
2636 scanner.getCurrentTokenEndPosition());
2639 case TokenNameIntegerLiteral:
2640 case TokenNameDoubleLiteral:
2641 case TokenNameStringInterpolated:
2644 case TokenNameCLASS_C:
2645 case TokenNameMETHOD_C:
2646 case TokenNameFUNC_C:
2649 case TokenNameHEREDOC:
2652 case TokenNamearray:
2653 // T_ARRAY '(' array_pair_list ')'
2655 if (token == TokenNameLPAREN) {
2657 if (token == TokenNameRPAREN) {
2662 if (token != TokenNameRPAREN) {
2663 throwSyntaxError("')' or ',' expected after keyword 'array'"
2665 + scanner.toStringAction(token) + ")");
2669 throwSyntaxError("'(' expected after keyword 'array'"
2670 + "(Found token: " + scanner.toStringAction(token)
2675 // | T_LIST '(' assignment_list ')' '=' expr
2677 if (token == TokenNameLPAREN) {
2680 if (token != TokenNameRPAREN) {
2681 throwSyntaxError("')' expected after 'list' keyword.");
2684 if (token != TokenNameEQUAL) {
2685 throwSyntaxError("'=' expected after 'list' keyword.");
2690 throwSyntaxError("'(' expected after 'list' keyword.");
2694 // | T_NEW class_name_reference ctor_arguments
2696 Expression typeRef = class_name_reference();
2698 if (typeRef != null) {
2699 expression = typeRef;
2702 // | T_INC rw_variable
2703 // | T_DEC rw_variable
2704 case TokenNamePLUS_PLUS:
2705 case TokenNameMINUS_MINUS:
2709 // | variable '=' expr
2710 // | variable '=' '&' variable
2711 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2712 // | variable T_PLUS_EQUAL expr
2713 // | variable T_MINUS_EQUAL expr
2714 // | variable T_MUL_EQUAL expr
2715 // | variable T_DIV_EQUAL expr
2716 // | variable T_CONCAT_EQUAL expr
2717 // | variable T_MOD_EQUAL expr
2718 // | variable T_AND_EQUAL expr
2719 // | variable T_OR_EQUAL expr
2720 // | variable T_XOR_EQUAL expr
2721 // | variable T_SL_EQUAL expr
2722 // | variable T_SR_EQUAL expr
2723 // | rw_variable T_INC
2724 // | rw_variable T_DEC
2725 case TokenNameIdentifier:
2726 case TokenNameVariable:
2727 case TokenNameDOLLAR:
2728 Expression lhs = null;
2729 boolean rememberedVar = false;
2730 if (token == TokenNameIdentifier) {
2731 lhs = identifier(true, true);
2736 lhs = variable(true, true);
2740 if (lhs != null && lhs instanceof FieldReference
2741 && token != TokenNameEQUAL
2742 && token != TokenNamePLUS_EQUAL
2743 && token != TokenNameMINUS_EQUAL
2744 && token != TokenNameMULTIPLY_EQUAL
2745 && token != TokenNameDIVIDE_EQUAL
2746 && token != TokenNameDOT_EQUAL
2747 && token != TokenNameREMAINDER_EQUAL
2748 && token != TokenNameAND_EQUAL
2749 && token != TokenNameOR_EQUAL
2750 && token != TokenNameXOR_EQUAL
2751 && token != TokenNameRIGHT_SHIFT_EQUAL
2752 && token != TokenNameLEFT_SHIFT_EQUAL) {
2753 FieldReference ref = (FieldReference) lhs;
2754 if (!containsVariableSet(ref.token)) {
2755 if (null == initHandler
2756 || initHandler.reportError()) {
2757 problemReporter.uninitializedLocalVariable(
2758 new String(ref.token), ref.sourceStart,
2759 ref.sourceEnd, referenceContext,
2760 compilationUnit.compilationResult);
2762 addVariableSet(ref.token);
2767 case TokenNameEQUAL:
2768 if (lhs != null && lhs instanceof FieldReference) {
2769 addVariableSet(((FieldReference) lhs).token);
2772 if (token == TokenNameAND) {
2774 if (token == TokenNamenew) {
2775 // | variable '=' '&' T_NEW class_name_reference
2778 SingleTypeReference classRef = class_name_reference();
2780 if (classRef != null) {
2782 && lhs instanceof FieldReference) {
2784 // $var = & new Object();
2785 if (fMethodVariables != null) {
2786 VariableInfo lhsInfo = new VariableInfo(
2787 ((FieldReference) lhs).sourceStart);
2788 lhsInfo.reference = classRef;
2789 lhsInfo.typeIdentifier = classRef.token;
2790 fMethodVariables.put(new String(
2791 ((FieldReference) lhs).token),
2793 rememberedVar = true;
2798 Expression rhs = variable(false, false);
2799 if (rhs != null && rhs instanceof FieldReference
2801 && lhs instanceof FieldReference) {
2804 if (fMethodVariables != null) {
2805 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
2806 .get(((FieldReference) rhs).token);
2808 && rhsInfo.reference != null) {
2809 VariableInfo lhsInfo = new VariableInfo(
2810 ((FieldReference) lhs).sourceStart);
2811 lhsInfo.reference = rhsInfo.reference;
2812 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2813 fMethodVariables.put(new String(
2814 ((FieldReference) lhs).token),
2816 rememberedVar = true;
2822 Expression rhs = expr();
2823 if (lhs != null && lhs instanceof FieldReference) {
2824 if (rhs != null && rhs instanceof FieldReference) {
2827 if (fMethodVariables != null) {
2828 VariableInfo rhsInfo = (VariableInfo) fMethodVariables
2829 .get(((FieldReference) rhs).token);
2831 && rhsInfo.reference != null) {
2832 VariableInfo lhsInfo = new VariableInfo(
2833 ((FieldReference) lhs).sourceStart);
2834 lhsInfo.reference = rhsInfo.reference;
2835 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2836 fMethodVariables.put(new String(
2837 ((FieldReference) lhs).token),
2839 rememberedVar = true;
2842 } else if (rhs != null
2843 && rhs instanceof SingleTypeReference) {
2845 // $var = new Object();
2846 if (fMethodVariables != null) {
2847 VariableInfo lhsInfo = new VariableInfo(
2848 ((FieldReference) lhs).sourceStart);
2849 lhsInfo.reference = (SingleTypeReference) rhs;
2850 lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2851 fMethodVariables.put(new String(
2852 ((FieldReference) lhs).token),
2854 rememberedVar = true;
2859 if (rememberedVar == false && lhs != null
2860 && lhs instanceof FieldReference) {
2861 if (fMethodVariables != null) {
2862 VariableInfo lhsInfo = new VariableInfo(
2863 ((FieldReference) lhs).sourceStart);
2864 fMethodVariables.put(new String(
2865 ((FieldReference) lhs).token), lhsInfo);
2869 case TokenNamePLUS_EQUAL:
2870 case TokenNameMINUS_EQUAL:
2871 case TokenNameMULTIPLY_EQUAL:
2872 case TokenNameDIVIDE_EQUAL:
2873 case TokenNameDOT_EQUAL:
2874 case TokenNameREMAINDER_EQUAL:
2875 case TokenNameAND_EQUAL:
2876 case TokenNameOR_EQUAL:
2877 case TokenNameXOR_EQUAL:
2878 case TokenNameRIGHT_SHIFT_EQUAL:
2879 case TokenNameLEFT_SHIFT_EQUAL:
2880 if (lhs != null && lhs instanceof FieldReference) {
2881 addVariableSet(((FieldReference) lhs).token);
2886 case TokenNamePLUS_PLUS:
2887 case TokenNameMINUS_MINUS:
2891 if (!only_variable) {
2892 throwSyntaxError("Variable expression not allowed (found token '"
2893 + scanner.toStringAction(token) + "').");
2901 if (token != TokenNameINLINE_HTML) {
2902 if (token > TokenNameKEYWORD) {
2906 // System.out.println(scanner.getCurrentTokenStartPosition());
2907 // System.out.println(scanner.getCurrentTokenEndPosition());
2909 throwSyntaxError("Error in expression (found token '"
2910 + scanner.toStringAction(token) + "').");
2915 if (Scanner.TRACE) {
2916 System.out.println("TRACE: expr_without_variable() PART 2");
2918 // | expr T_BOOLEAN_OR expr
2919 // | expr T_BOOLEAN_AND expr
2920 // | expr T_LOGICAL_OR expr
2921 // | expr T_LOGICAL_AND expr
2922 // | expr T_LOGICAL_XOR expr
2934 // | expr T_IS_IDENTICAL expr
2935 // | expr T_IS_NOT_IDENTICAL expr
2936 // | expr T_IS_EQUAL expr
2937 // | expr T_IS_NOT_EQUAL expr
2939 // | expr T_IS_SMALLER_OR_EQUAL expr
2941 // | expr T_IS_GREATER_OR_EQUAL expr
2944 case TokenNameOR_OR:
2946 expression = new OR_OR_Expression(expression, expr(), token);
2948 case TokenNameAND_AND:
2950 expression = new AND_AND_Expression(expression, expr(),
2953 case TokenNameEQUAL_EQUAL:
2955 expression = new EqualExpression(expression, expr(), token);
2965 case TokenNameMINUS:
2966 case TokenNameMULTIPLY:
2967 case TokenNameDIVIDE:
2968 case TokenNameREMAINDER:
2969 case TokenNameLEFT_SHIFT:
2970 case TokenNameRIGHT_SHIFT:
2971 case TokenNameEQUAL_EQUAL_EQUAL:
2972 case TokenNameNOT_EQUAL_EQUAL:
2973 case TokenNameNOT_EQUAL:
2975 case TokenNameLESS_EQUAL:
2976 case TokenNameGREATER:
2977 case TokenNameGREATER_EQUAL:
2979 expression = new BinaryExpression(expression, expr(), token);
2981 // | expr T_INSTANCEOF class_name_reference
2982 // | expr '?' expr ':' expr
2983 case TokenNameinstanceof:
2985 TypeReference classRef = class_name_reference();
2986 if (classRef != null) {
2987 expression = new InstanceOfExpression(expression,
2988 classRef, OperatorIds.INSTANCEOF);
2989 expression.sourceStart = exprSourceStart;
2990 expression.sourceEnd = scanner
2991 .getCurrentTokenEndPosition();
2994 case TokenNameQUESTION:
2996 Expression valueIfTrue = expr();
2997 if (token != TokenNameCOLON) {
2998 throwSyntaxError("':' expected in conditional expression.");
3001 Expression valueIfFalse = expr();
3003 expression = new ConditionalExpression(expression,
3004 valueIfTrue, valueIfFalse);
3010 } catch (SyntaxError e) {
3011 // try to find next token after expression with errors:
3012 if (token == TokenNameSEMICOLON) {
3016 if (token == TokenNameRBRACE || token == TokenNameRPAREN
3017 || token == TokenNameRBRACKET) {
3025 private SingleTypeReference class_name_reference() {
3026 // class_name_reference:
3028 // | dynamic_class_name_reference
3029 SingleTypeReference ref = null;
3030 if (Scanner.TRACE) {
3031 System.out.println("TRACE: class_name_reference()");
3033 if (token == TokenNameIdentifier) {
3034 ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(),
3035 scanner.getCurrentTokenStartPosition());
3036 int pos = scanner.currentPosition;
3038 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3039 // Not terminated by T_STRING, reduce to
3040 // dynamic_class_name_reference
3041 scanner.currentPosition = pos;
3042 token = TokenNameIdentifier;
3044 dynamic_class_name_reference();
3048 dynamic_class_name_reference();
3053 private void dynamic_class_name_reference() {
3054 // dynamic_class_name_reference:
3055 // base_variable T_OBJECT_OPERATOR object_property
3056 // dynamic_class_name_variable_properties
3058 if (Scanner.TRACE) {
3059 System.out.println("TRACE: dynamic_class_name_reference()");
3061 base_variable(true);
3062 if (token == TokenNameMINUS_GREATER) {
3065 dynamic_class_name_variable_properties();
3069 private void dynamic_class_name_variable_properties() {
3070 // dynamic_class_name_variable_properties:
3071 // dynamic_class_name_variable_properties
3072 // dynamic_class_name_variable_property
3074 if (Scanner.TRACE) {
3076 .println("TRACE: dynamic_class_name_variable_properties()");
3078 while (token == TokenNameMINUS_GREATER) {
3079 dynamic_class_name_variable_property();
3083 private void dynamic_class_name_variable_property() {
3084 // dynamic_class_name_variable_property:
3085 // T_OBJECT_OPERATOR object_property
3086 if (Scanner.TRACE) {
3087 System.out.println("TRACE: dynamic_class_name_variable_property()");
3089 if (token == TokenNameMINUS_GREATER) {
3095 private void ctor_arguments() {
3098 // | '(' function_call_parameter_list ')'
3099 if (token == TokenNameLPAREN) {
3101 if (token == TokenNameRPAREN) {
3105 non_empty_function_call_parameter_list();
3106 if (token != TokenNameRPAREN) {
3107 throwSyntaxError("')' expected in ctor_arguments.");
3113 private void assignment_list() {
3115 // assignment_list ',' assignment_list_element
3116 // | assignment_list_element
3118 assignment_list_element();
3119 if (token != TokenNameCOMMA) {
3126 private void assignment_list_element() {
3127 // assignment_list_element:
3129 // | T_LIST '(' assignment_list ')'
3131 if (token == TokenNameVariable) {
3132 variable(true, false);
3133 } else if (token == TokenNameDOLLAR) {
3134 variable(false, false);
3135 } else if (token == TokenNameIdentifier) {
3136 identifier(true, true);
3138 if (token == TokenNamelist) {
3140 if (token == TokenNameLPAREN) {
3143 if (token != TokenNameRPAREN) {
3144 throwSyntaxError("')' expected after 'list' keyword.");
3148 throwSyntaxError("'(' expected after 'list' keyword.");
3154 private void array_pair_list() {
3157 // | non_empty_array_pair_list possible_comma
3158 non_empty_array_pair_list();
3159 if (token == TokenNameCOMMA) {
3164 private void non_empty_array_pair_list() {
3165 // non_empty_array_pair_list:
3166 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
3167 // | non_empty_array_pair_list ',' expr
3168 // | expr T_DOUBLE_ARROW expr
3170 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
3171 // | non_empty_array_pair_list ',' '&' w_variable
3172 // | expr T_DOUBLE_ARROW '&' w_variable
3175 if (token == TokenNameAND) {
3177 variable(true, false);
3180 if (token == TokenNameAND) {
3182 variable(true, false);
3183 } else if (token == TokenNameEQUAL_GREATER) {
3185 if (token == TokenNameAND) {
3187 variable(true, false);
3193 if (token != TokenNameCOMMA) {
3197 if (token == TokenNameRPAREN) {
3203 // private void variableList() {
3206 // if (token == TokenNameCOMMA) {
3213 private Expression variable_without_objects(boolean lefthandside,
3214 boolean ignoreVar) {
3215 // variable_without_objects:
3216 // reference_variable
3217 // | simple_indirect_reference reference_variable
3218 if (Scanner.TRACE) {
3219 System.out.println("TRACE: variable_without_objects()");
3221 while (token == TokenNameDOLLAR) {
3224 return reference_variable(lefthandside, ignoreVar);
3227 private Expression function_call(boolean lefthandside, boolean ignoreVar) {
3229 // T_STRING '(' function_call_parameter_list ')'
3230 // | class_constant '(' function_call_parameter_list ')'
3231 // | static_member '(' function_call_parameter_list ')'
3232 // | variable_without_objects '(' function_call_parameter_list ')'
3233 char[] defineName = null;
3234 char[] ident = null;
3237 Expression ref = null;
3238 if (Scanner.TRACE) {
3239 System.out.println("TRACE: function_call()");
3241 if (token == TokenNameIdentifier) {
3242 ident = scanner.getCurrentIdentifierSource();
3244 startPos = scanner.getCurrentTokenStartPosition();
3245 endPos = scanner.getCurrentTokenEndPosition();
3248 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3252 if (token == TokenNameIdentifier) {
3257 variable_without_objects(true, false);
3262 ref = variable_without_objects(lefthandside, ignoreVar);
3264 if (token != TokenNameLPAREN) {
3265 if (defineName != null) {
3266 // does this identifier contain only uppercase characters?
3267 if (defineName.length == 3) {
3268 if (defineName[0] == 'd' && defineName[1] == 'i'
3269 && defineName[2] == 'e') {
3272 } else if (defineName.length == 4) {
3273 if (defineName[0] == 't' && defineName[1] == 'r'
3274 && defineName[2] == 'u' && defineName[3] == 'e') {
3276 } else if (defineName[0] == 'n' && defineName[1] == 'u'
3277 && defineName[2] == 'l' && defineName[3] == 'l') {
3280 } else if (defineName.length == 5) {
3281 if (defineName[0] == 'f' && defineName[1] == 'a'
3282 && defineName[2] == 'l' && defineName[3] == 's'
3283 && defineName[4] == 'e') {
3287 if (defineName != null) {
3288 for (int i = 0; i < defineName.length; i++) {
3289 if (Character.isLowerCase(defineName[i])) {
3290 problemReporter.phpUppercaseIdentifierWarning(
3291 startPos, endPos, referenceContext,
3292 compilationUnit.compilationResult);
3300 if (token == TokenNameRPAREN) {
3304 non_empty_function_call_parameter_list();
3305 if (token != TokenNameRPAREN) {
3306 String functionName;
3307 if (ident == null) {
3308 functionName = new String(" ");
3310 functionName = new String(ident);
3312 throwSyntaxError("')' expected in function call ("
3313 + functionName + ").");
3320 private void non_empty_function_call_parameter_list() {
3321 this.non_empty_function_call_parameter_list(null);
3324 // private void function_call_parameter_list() {
3325 // function_call_parameter_list:
3326 // non_empty_function_call_parameter_list { $$ = $1; }
3329 private void non_empty_function_call_parameter_list(String functionName) {
3330 // non_empty_function_call_parameter_list:
3331 // expr_without_variable
3334 // | non_empty_function_call_parameter_list ',' expr_without_variable
3335 // | non_empty_function_call_parameter_list ',' variable
3336 // | non_empty_function_call_parameter_list ',' '&' w_variable
3337 if (Scanner.TRACE) {
3339 .println("TRACE: non_empty_function_call_parameter_list()");
3341 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3342 initHandler.setFunctionName(functionName);
3344 initHandler.incrementArgumentCount();
3345 if (token == TokenNameAND) {
3349 // if (token == TokenNameIdentifier || token ==
3350 // TokenNameVariable
3351 // || token == TokenNameDOLLAR) {
3354 expr_without_variable(true, initHandler);
3357 if (token != TokenNameCOMMA) {
3364 private void fully_qualified_class_name() {
3365 if (token == TokenNameIdentifier) {
3368 throwSyntaxError("Class name expected.");
3372 private void static_member() {
3374 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3375 // variable_without_objects
3376 if (Scanner.TRACE) {
3377 System.out.println("TRACE: static_member()");
3379 fully_qualified_class_name();
3380 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3381 throwSyntaxError("'::' expected after class name (static_member).");
3384 variable_without_objects(false, false);
3387 private Expression base_variable_with_function_calls(boolean lefthandside,
3388 boolean ignoreVar) {
3389 // base_variable_with_function_calls:
3392 if (Scanner.TRACE) {
3393 System.out.println("TRACE: base_variable_with_function_calls()");
3395 return function_call(lefthandside, ignoreVar);
3398 private Expression base_variable(boolean lefthandside) {
3400 // reference_variable
3401 // | simple_indirect_reference reference_variable
3403 Expression ref = null;
3404 if (Scanner.TRACE) {
3405 System.out.println("TRACE: base_variable()");
3407 if (token == TokenNameIdentifier) {
3410 while (token == TokenNameDOLLAR) {
3413 reference_variable(lefthandside, false);
3418 // private void simple_indirect_reference() {
3419 // // simple_indirect_reference:
3421 // //| simple_indirect_reference '$'
3423 private Expression reference_variable(boolean lefthandside,
3424 boolean ignoreVar) {
3425 // reference_variable:
3426 // reference_variable '[' dim_offset ']'
3427 // | reference_variable '{' expr '}'
3428 // | compound_variable
3429 Expression ref = null;
3430 if (Scanner.TRACE) {
3431 System.out.println("TRACE: reference_variable()");
3433 ref = compound_variable(lefthandside, ignoreVar);
3435 if (token == TokenNameLBRACE) {
3439 if (token != TokenNameRBRACE) {
3440 throwSyntaxError("'}' expected in reference variable.");
3443 } else if (token == TokenNameLBRACKET) {
3444 // To remove "ref = null;" here, is probably better than the
3446 // commented in #1368081 - axelcl
3448 if (token != TokenNameRBRACKET) {
3451 if (token != TokenNameRBRACKET) {
3452 throwSyntaxError("']' expected in reference variable.");
3463 private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3464 // compound_variable:
3466 // | '$' '{' expr '}'
3467 if (Scanner.TRACE) {
3468 System.out.println("TRACE: compound_variable()");
3470 if (token == TokenNameVariable) {
3471 if (!lefthandside) {
3472 if (!containsVariableSet()) {
3473 // reportSyntaxError("The local variable " + new
3474 // String(scanner.getCurrentIdentifierSource())
3475 // + " may not have been initialized");
3476 problemReporter.uninitializedLocalVariable(new String(
3477 scanner.getCurrentIdentifierSource()), scanner
3478 .getCurrentTokenStartPosition(), scanner
3479 .getCurrentTokenEndPosition(), referenceContext,
3480 compilationUnit.compilationResult);
3487 FieldReference ref = new FieldReference(
3488 scanner.getCurrentIdentifierSource(),
3489 scanner.getCurrentTokenStartPosition());
3493 // because of simple_indirect_reference
3494 while (token == TokenNameDOLLAR) {
3497 if (token != TokenNameLBRACE) {
3498 reportSyntaxError("'{' expected after compound variable token '$'.");
3503 if (token != TokenNameRBRACE) {
3504 throwSyntaxError("'}' expected after compound variable token '$'.");
3509 } // private void dim_offset() { // // dim_offset: // // /* empty */
3514 private void object_property() {
3517 // | variable_without_objects
3518 if (Scanner.TRACE) {
3519 System.out.println("TRACE: object_property()");
3521 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3522 variable_without_objects(false, false);
3528 private void object_dim_list() {
3530 // object_dim_list '[' dim_offset ']'
3531 // | object_dim_list '{' expr '}'
3533 if (Scanner.TRACE) {
3534 System.out.println("TRACE: object_dim_list()");
3538 if (token == TokenNameLBRACE) {
3541 if (token != TokenNameRBRACE) {
3542 throwSyntaxError("'}' expected in object_dim_list.");
3545 } else if (token == TokenNameLBRACKET) {
3547 if (token == TokenNameRBRACKET) {
3552 if (token != TokenNameRBRACKET) {
3553 throwSyntaxError("']' expected in object_dim_list.");
3562 private void variable_name() {
3566 if (Scanner.TRACE) {
3567 System.out.println("TRACE: variable_name()");
3569 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3570 if (token > TokenNameKEYWORD) {
3571 // TODO show a warning "Keyword used as variable" ?
3575 if (token != TokenNameLBRACE) {
3576 throwSyntaxError("'{' expected in variable name.");
3580 if (token != TokenNameRBRACE) {
3581 throwSyntaxError("'}' expected in variable name.");
3587 private void r_variable() {
3588 variable(false, false);
3591 private void w_variable(boolean lefthandside) {
3592 variable(lefthandside, false);
3595 private void rw_variable() {
3596 variable(false, false);
3599 private Expression variable(boolean lefthandside, boolean ignoreVar) {
3601 // base_variable_with_function_calls T_OBJECT_OPERATOR
3602 // object_property method_or_not variable_properties
3603 // | base_variable_with_function_calls
3604 Expression ref = base_variable_with_function_calls(lefthandside,
3606 if (token == TokenNameMINUS_GREATER) {
3611 variable_properties();
3616 private void variable_properties() {
3617 // variable_properties:
3618 // variable_properties variable_property
3620 while (token == TokenNameMINUS_GREATER) {
3621 variable_property();
3625 private void variable_property() {
3626 // variable_property:
3627 // T_OBJECT_OPERATOR object_property method_or_not
3628 if (Scanner.TRACE) {
3629 System.out.println("TRACE: variable_property()");
3631 if (token == TokenNameMINUS_GREATER) {
3636 throwSyntaxError("'->' expected in variable_property.");
3640 private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3642 // base_variable_with_function_calls T_OBJECT_OPERATOR
3643 // object_property method_or_not variable_properties
3644 // | base_variable_with_function_calls
3646 // Expression ref = function_call(lefthandside, ignoreVar);
3649 // T_STRING '(' function_call_parameter_list ')'
3650 // | class_constant '(' function_call_parameter_list ')'
3651 // | static_member '(' function_call_parameter_list ')'
3652 // | variable_without_objects '(' function_call_parameter_list ')'
3653 char[] defineName = null;
3654 char[] ident = null;
3657 Expression ref = null;
3658 if (Scanner.TRACE) {
3659 System.out.println("TRACE: function_call()");
3661 if (token == TokenNameIdentifier) {
3662 ident = scanner.getCurrentIdentifierSource();
3664 startPos = scanner.getCurrentTokenStartPosition();
3665 endPos = scanner.getCurrentTokenEndPosition();
3668 if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL
3669 || token == TokenNameMINUS_EQUAL
3670 || token == TokenNameMULTIPLY_EQUAL
3671 || token == TokenNameDIVIDE_EQUAL
3672 || token == TokenNameDOT_EQUAL
3673 || token == TokenNameREMAINDER_EQUAL
3674 || token == TokenNameAND_EQUAL
3675 || token == TokenNameOR_EQUAL
3676 || token == TokenNameXOR_EQUAL
3677 || token == TokenNameRIGHT_SHIFT_EQUAL
3678 || token == TokenNameLEFT_SHIFT_EQUAL) {
3679 String error = "Assignment operator '"
3680 + scanner.toStringAction(token)
3681 + "' not allowed after identifier '"
3683 + "' (use 'define(...)' to define constants).";
3684 reportSyntaxError(error);
3688 case TokenNamePAAMAYIM_NEKUDOTAYIM:
3692 if (token == TokenNameIdentifier) {
3697 variable_without_objects(true, false);
3702 ref = variable_without_objects(lefthandside, ignoreVar);
3704 if (token != TokenNameLPAREN) {
3705 if (defineName != null) {
3706 // does this identifier contain only uppercase characters?
3707 if (defineName.length == 3) {
3708 if (defineName[0] == 'd' && defineName[1] == 'i'
3709 && defineName[2] == 'e') {
3712 } else if (defineName.length == 4) {
3713 if (defineName[0] == 't' && defineName[1] == 'r'
3714 && defineName[2] == 'u' && defineName[3] == 'e') {
3716 } else if (defineName[0] == 'n' && defineName[1] == 'u'
3717 && defineName[2] == 'l' && defineName[3] == 'l') {
3720 } else if (defineName.length == 5) {
3721 if (defineName[0] == 'f' && defineName[1] == 'a'
3722 && defineName[2] == 'l' && defineName[3] == 's'
3723 && defineName[4] == 'e') {
3727 if (defineName != null) {
3728 for (int i = 0; i < defineName.length; i++) {
3729 if (Character.isLowerCase(defineName[i])) {
3730 problemReporter.phpUppercaseIdentifierWarning(
3731 startPos, endPos, referenceContext,
3732 compilationUnit.compilationResult);
3738 // TODO is this ok ?
3740 // throwSyntaxError("'(' expected in function call.");
3744 if (token == TokenNameRPAREN) {
3748 String functionName;
3749 if (ident == null) {
3750 functionName = new String(" ");
3752 functionName = new String(ident);
3754 non_empty_function_call_parameter_list(functionName);
3755 if (token != TokenNameRPAREN) {
3756 throwSyntaxError("')' expected in function call ("
3757 + functionName + ").");
3762 if (token == TokenNameMINUS_GREATER) {
3767 variable_properties();
3772 private void method_or_not() {
3774 // '(' function_call_parameter_list ')'
3776 if (Scanner.TRACE) {
3777 System.out.println("TRACE: method_or_not()");
3779 if (token == TokenNameLPAREN) {
3781 if (token == TokenNameRPAREN) {
3785 non_empty_function_call_parameter_list();
3786 if (token != TokenNameRPAREN) {
3787 throwSyntaxError("')' expected in method_or_not.");
3793 private void exit_expr() {
3797 if (token != TokenNameLPAREN) {
3801 if (token == TokenNameRPAREN) {
3806 if (token != TokenNameRPAREN) {
3807 throwSyntaxError("')' expected after keyword 'exit'");
3812 // private void encaps_list() {
3813 // // encaps_list encaps_var
3814 // // | encaps_list T_STRING
3815 // // | encaps_list T_NUM_STRING
3816 // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3817 // // | encaps_list T_CHARACTER
3818 // // | encaps_list T_BAD_CHARACTER
3819 // // | encaps_list '['
3820 // // | encaps_list ']'
3821 // // | encaps_list '{'
3822 // // | encaps_list '}'
3823 // // | encaps_list T_OBJECT_OPERATOR
3827 // case TokenNameSTRING:
3830 // case TokenNameLBRACE:
3831 // // scanner.encapsedStringStack.pop();
3834 // case TokenNameRBRACE:
3835 // // scanner.encapsedStringStack.pop();
3838 // case TokenNameLBRACKET:
3839 // // scanner.encapsedStringStack.pop();
3842 // case TokenNameRBRACKET:
3843 // // scanner.encapsedStringStack.pop();
3846 // case TokenNameMINUS_GREATER:
3847 // // scanner.encapsedStringStack.pop();
3850 // case TokenNameVariable:
3851 // case TokenNameDOLLAR_LBRACE:
3852 // case TokenNameLBRACE_DOLLAR:
3856 // char encapsedChar = ((Character)
3857 // scanner.encapsedStringStack.peek()).charValue();
3858 // if (encapsedChar == '$') {
3859 // scanner.encapsedStringStack.pop();
3860 // encapsedChar = ((Character)
3861 // scanner.encapsedStringStack.peek()).charValue();
3862 // switch (encapsedChar) {
3864 // if (token == TokenNameEncapsedString0) {
3867 // token = TokenNameSTRING;
3870 // if (token == TokenNameEncapsedString1) {
3873 // token = TokenNameSTRING;
3876 // if (token == TokenNameEncapsedString2) {
3879 // token = TokenNameSTRING;
3888 // private void encaps_var() {
3890 // // | T_VARIABLE '[' encaps_var_offset ']'
3891 // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3892 // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3893 // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3894 // // | T_CURLY_OPEN variable '}'
3896 // case TokenNameVariable:
3898 // if (token == TokenNameLBRACKET) {
3900 // expr(); //encaps_var_offset();
3901 // if (token != TokenNameRBRACKET) {
3902 // throwSyntaxError("']' expected after variable.");
3904 // // scanner.encapsedStringStack.pop();
3907 // } else if (token == TokenNameMINUS_GREATER) {
3909 // if (token != TokenNameIdentifier) {
3910 // throwSyntaxError("Identifier expected after '->'.");
3912 // // scanner.encapsedStringStack.pop();
3916 // // // scanner.encapsedStringStack.pop();
3917 // // int tempToken = TokenNameSTRING;
3918 // // if (!scanner.encapsedStringStack.isEmpty()
3919 // // && (token == TokenNameEncapsedString0
3920 // // || token == TokenNameEncapsedString1
3921 // // || token == TokenNameEncapsedString2 || token ==
3922 // // TokenNameERROR)) {
3923 // // char encapsedChar = ((Character)
3924 // // scanner.encapsedStringStack.peek())
3926 // // switch (token) {
3927 // // case TokenNameEncapsedString0 :
3928 // // if (encapsedChar == '`') {
3929 // // tempToken = TokenNameEncapsedString0;
3932 // // case TokenNameEncapsedString1 :
3933 // // if (encapsedChar == '\'') {
3934 // // tempToken = TokenNameEncapsedString1;
3937 // // case TokenNameEncapsedString2 :
3938 // // if (encapsedChar == '"') {
3939 // // tempToken = TokenNameEncapsedString2;
3942 // // case TokenNameERROR :
3943 // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3944 // // scanner.currentPosition--;
3945 // // getNextToken();
3950 // // token = tempToken;
3953 // case TokenNameDOLLAR_LBRACE:
3955 // if (token == TokenNameDOLLAR_LBRACE) {
3957 // } else if (token == TokenNameIdentifier) {
3959 // if (token == TokenNameLBRACKET) {
3961 // // if (token == TokenNameRBRACKET) {
3962 // // getNextToken();
3965 // if (token != TokenNameRBRACKET) {
3966 // throwSyntaxError("']' expected after '${'.");
3974 // if (token != TokenNameRBRACE) {
3975 // throwSyntaxError("'}' expected.");
3979 // case TokenNameLBRACE_DOLLAR:
3981 // if (token == TokenNameLBRACE_DOLLAR) {
3983 // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3985 // if (token == TokenNameLBRACKET) {
3987 // // if (token == TokenNameRBRACKET) {
3988 // // getNextToken();
3991 // if (token != TokenNameRBRACKET) {
3992 // throwSyntaxError("']' expected.");
3996 // } else if (token == TokenNameMINUS_GREATER) {
3998 // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3999 // throwSyntaxError("String or Variable token expected.");
4002 // if (token == TokenNameLBRACKET) {
4004 // // if (token == TokenNameRBRACKET) {
4005 // // getNextToken();
4008 // if (token != TokenNameRBRACKET) {
4009 // throwSyntaxError("']' expected after '${'.");
4015 // // if (token != TokenNameRBRACE) {
4016 // // throwSyntaxError("'}' expected after '{$'.");
4018 // // // scanner.encapsedStringStack.pop();
4019 // // getNextToken();
4022 // if (token != TokenNameRBRACE) {
4023 // throwSyntaxError("'}' expected.");
4025 // // scanner.encapsedStringStack.pop();
4032 // private void encaps_var_offset() {
4034 // // | T_NUM_STRING
4037 // case TokenNameSTRING:
4040 // case TokenNameIntegerLiteral:
4043 // case TokenNameVariable:
4046 // case TokenNameIdentifier:
4050 // throwSyntaxError("Variable or String token expected.");
4055 private void internal_functions_in_yacc() {
4058 // case TokenNameisset:
4059 // // T_ISSET '(' isset_variables ')'
4061 // if (token != TokenNameLPAREN) {
4062 // throwSyntaxError("'(' expected after keyword 'isset'");
4065 // isset_variables();
4066 // if (token != TokenNameRPAREN) {
4067 // throwSyntaxError("')' expected after keyword 'isset'");
4071 // case TokenNameempty:
4072 // // T_EMPTY '(' variable ')'
4074 // if (token != TokenNameLPAREN) {
4075 // throwSyntaxError("'(' expected after keyword 'empty'");
4079 // if (token != TokenNameRPAREN) {
4080 // throwSyntaxError("')' expected after keyword 'empty'");
4084 case TokenNameinclude:
4086 checkFileName(token);
4088 case TokenNameinclude_once:
4089 // T_INCLUDE_ONCE expr
4090 checkFileName(token);
4093 // T_EVAL '(' expr ')'
4095 if (token != TokenNameLPAREN) {
4096 throwSyntaxError("'(' expected after keyword 'eval'");
4100 if (token != TokenNameRPAREN) {
4101 throwSyntaxError("')' expected after keyword 'eval'");
4105 case TokenNamerequire:
4107 checkFileName(token);
4109 case TokenNamerequire_once:
4110 // T_REQUIRE_ONCE expr
4111 checkFileName(token);
4113 case TokenNameNamespace:
4115 checkNameSpaceName();
4117 case TokenNameconst:
4125 * parse and check the namespace name
4128 * @param namespaceToken
4130 private void checkNameSpaceName() {
4133 if (token == TokenNameForwardSlash || token == TokenNameIdentifier) {
4139 if (token != TokenNameSEMICOLON) {
4140 throwSyntaxError("';' expected after keyword '"
4141 + scanner.toStringAction(TokenNameNamespace) + "'");
4147 * Parse and check the include file name
4149 * @param includeToken
4151 private void checkFileName(int includeToken) {
4152 // <include-token> expr
4153 int start = scanner.getCurrentTokenStartPosition();
4154 boolean hasLPAREN = false;
4156 if (token == TokenNameLPAREN) {
4160 Expression expression = expr();
4162 if (token == TokenNameRPAREN) {
4165 throwSyntaxError("')' expected for keyword '"
4166 + scanner.toStringAction(includeToken) + "'");
4169 char[] currTokenSource = scanner.getCurrentTokenSource(start);
4171 if (scanner.compilationUnit != null) {
4172 IResource resource = scanner.compilationUnit.getResource();
4173 if (resource != null && resource instanceof IFile) {
4174 file = (IFile) resource;
4178 tokens = new char[1][];
4179 tokens[0] = currTokenSource;
4181 ImportReference impt = new ImportReference(tokens, currTokenSource,
4182 start, scanner.getCurrentTokenEndPosition(), false);
4183 impt.declarationSourceEnd = impt.sourceEnd;
4184 impt.declarationEnd = impt.declarationSourceEnd;
4185 // endPosition is just before the ;
4186 impt.declarationSourceStart = start;
4187 includesList.add(impt);
4189 if (expression instanceof StringLiteral) {
4190 StringLiteral literal = (StringLiteral) expression;
4191 char[] includeName = literal.source();
4192 if (includeName.length == 0) {
4194 "Empty filename after keyword '"
4195 + scanner.toStringAction(includeToken) + "'",
4196 literal.sourceStart, literal.sourceStart + 1);
4198 String includeNameString = new String(includeName);
4199 if (literal instanceof StringLiteralDQ) {
4200 if (includeNameString.indexOf('$') >= 0) {
4201 // assuming that the filename contains a variable => no
4206 if (includeNameString.startsWith("http://")) {
4207 // assuming external include location
4211 // check the filename:
4212 // System.out.println(new
4213 // String(compilationUnit.getFileName())+" - "+
4214 // expression.toStringExpression());
4215 IProject project = file.getProject();
4216 if (project != null) {
4217 IPath path = PHPFileUtil.determineFilePath(
4218 includeNameString, file, project);
4221 // SyntaxError: "File: << >> doesn't exist in project."
4222 String[] args = { expression.toStringExpression(),
4223 project.getFullPath().toString() };
4224 problemReporter.phpIncludeNotExistWarning(args,
4225 literal.sourceStart, literal.sourceEnd,
4227 compilationUnit.compilationResult);
4230 String filePath = path.toString();
4231 String ext = file.getRawLocation()
4232 .getFileExtension();
4233 int fileExtensionLength = ext == null ? 0 : ext
4236 IFile f = PHPFileUtil.createFile(path, project);
4238 impt.tokens = CharOperation.splitOn('/',
4239 filePath.toCharArray(), 0,
4240 filePath.length() - fileExtensionLength);
4242 } catch (Exception e) {
4243 // the file is outside of the workspace
4251 private void isset_variables() {
4253 // | isset_variables ','
4254 if (token == TokenNameRPAREN) {
4255 throwSyntaxError("Variable expected after keyword 'isset'");
4258 variable(true, false);
4259 if (token == TokenNameCOMMA) {
4267 private boolean common_scalar() {
4271 // | T_CONSTANT_ENCAPSED_STRING
4278 case TokenNameIntegerLiteral:
4281 case TokenNameDoubleLiteral:
4284 case TokenNameStringDoubleQuote:
4287 case TokenNameStringSingleQuote:
4290 case TokenNameStringInterpolated:
4299 case TokenNameCLASS_C:
4302 case TokenNameMETHOD_C:
4305 case TokenNameFUNC_C:
4312 private void scalar() {
4315 // | T_STRING_VARNAME
4318 // | '"' encaps_list '"'
4319 // | '\'' encaps_list '\''
4320 // | T_START_HEREDOC encaps_list T_END_HEREDOC
4321 throwSyntaxError("Not yet implemented (scalar).");
4324 private void static_scalar() {
4325 // static_scalar: /* compile-time evaluated scalars */
4328 // | '+' static_scalar
4329 // | '-' static_scalar
4330 // | T_ARRAY '(' static_array_pair_list ')'
4331 // | static_class_constant
4332 if (common_scalar()) {
4336 case TokenNameIdentifier:
4338 // static_class_constant:
4339 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
4340 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
4342 if (token == TokenNameIdentifier) {
4345 throwSyntaxError("Identifier expected after '::' operator.");
4349 case TokenNameEncapsedString0:
4351 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4352 while (scanner.currentCharacter != '`') {
4353 if (scanner.currentCharacter == '\\') {
4354 scanner.currentPosition++;
4356 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4359 } catch (IndexOutOfBoundsException e) {
4360 throwSyntaxError("'`' expected at end of static string.");
4363 // case TokenNameEncapsedString1:
4365 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4366 // while (scanner.currentCharacter != '\'') {
4367 // if (scanner.currentCharacter == '\\') {
4368 // scanner.currentPosition++;
4370 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4373 // } catch (IndexOutOfBoundsException e) {
4374 // throwSyntaxError("'\'' expected at end of static string.");
4377 // case TokenNameEncapsedString2:
4379 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4380 // while (scanner.currentCharacter != '"') {
4381 // if (scanner.currentCharacter == '\\') {
4382 // scanner.currentPosition++;
4384 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4387 // } catch (IndexOutOfBoundsException e) {
4388 // throwSyntaxError("'\"' expected at end of static string.");
4391 case TokenNameStringSingleQuote:
4394 case TokenNameStringDoubleQuote:
4401 case TokenNameMINUS:
4405 case TokenNamearray:
4407 if (token != TokenNameLPAREN) {
4408 throwSyntaxError("'(' expected after keyword 'array'");
4411 if (token == TokenNameRPAREN) {
4415 non_empty_static_array_pair_list();
4416 if (token != TokenNameRPAREN) {
4417 throwSyntaxError("')' or ',' expected after keyword 'array'");
4421 // case TokenNamenull :
4424 // case TokenNamefalse :
4427 // case TokenNametrue :
4431 throwSyntaxError("Static scalar/constant expected.");
4435 private void non_empty_static_array_pair_list() {
4436 // non_empty_static_array_pair_list:
4437 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4439 // | non_empty_static_array_pair_list ',' static_scalar
4440 // | static_scalar T_DOUBLE_ARROW static_scalar
4444 if (token == TokenNameEQUAL_GREATER) {
4448 if (token != TokenNameCOMMA) {
4452 if (token == TokenNameRPAREN) {
4458 // public void reportSyntaxError() { //int act, int currentKind, int
4459 // // stateStackTop) {
4460 // /* remember current scanner position */
4461 // int startPos = scanner.startPosition;
4462 // int currentPos = scanner.currentPosition;
4464 // this.checkAndReportBracketAnomalies(problemReporter());
4465 // /* reset scanner where it was */
4466 // scanner.startPosition = startPos;
4467 // scanner.currentPosition = currentPos;
4470 public static final int RoundBracket = 0;
4472 public static final int SquareBracket = 1;
4474 public static final int CurlyBracket = 2;
4476 public static final int BracketKinds = 3;
4478 protected int[] nestedMethod; // the ptr is nestedType
4480 protected int nestedType, dimensions;
4482 // variable set stack
4483 final static int VariableStackIncrement = 10;
4485 HashMap fTypeVariables = null;
4487 HashMap fMethodVariables = null;
4489 ArrayList fStackUnassigned = new ArrayList();
4492 final static int AstStackIncrement = 100;
4494 protected int astPtr;
4496 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4498 protected int astLengthPtr;
4500 protected int[] astLengthStack;
4502 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4504 public CompilationUnitDeclaration compilationUnit; /*
4509 protected ReferenceContext referenceContext;
4511 protected ProblemReporter problemReporter;
4513 protected CompilerOptions options;
4515 private ArrayList includesList;
4517 // protected CompilationResult compilationResult;
4519 * Returns this parser's problem reporter initialized with its reference
4520 * context. Also it is assumed that a problem is going to be reported, so
4521 * initializes the compilation result's line positions.
4523 public ProblemReporter problemReporter() {
4524 if (scanner.recordLineSeparator) {
4525 compilationUnit.compilationResult.lineSeparatorPositions = scanner
4528 problemReporter.referenceContext = referenceContext;
4529 return problemReporter;
4533 * Reconsider the entire source looking for inconsistencies in {} () []
4535 // public boolean checkAndReportBracketAnomalies(ProblemReporter
4536 // problemReporter) {
4537 // scanner.wasAcr = false;
4538 // boolean anomaliesDetected = false;
4540 // char[] source = scanner.source;
4541 // int[] leftCount = { 0, 0, 0 };
4542 // int[] rightCount = { 0, 0, 0 };
4543 // int[] depths = { 0, 0, 0 };
4544 // int[][] leftPositions = new int[][] { new int[10], new int[10], new
4547 // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10]
4549 // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4551 // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4553 // scanner.currentPosition = scanner.initialPosition; //starting
4555 // // (first-zero-based
4557 // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4562 // // ---------Consume white space and handles
4563 // // startPosition---------
4564 // boolean isWhiteSpace;
4566 // scanner.startPosition = scanner.currentPosition;
4567 // // if (((scanner.currentCharacter =
4568 // // source[scanner.currentPosition++]) == '\\') &&
4569 // // (source[scanner.currentPosition] == 'u')) {
4570 // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4572 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4573 // (scanner.currentCharacter == '\n'))) {
4574 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4575 // // only record line positions we have not
4577 // scanner.pushLineSeparator();
4580 // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4582 // } while (isWhiteSpace && (scanner.currentPosition <
4583 // scanner.eofPosition));
4584 // // -------consume token until } is found---------
4585 // switch (scanner.currentCharacter) {
4587 // int index = leftCount[CurlyBracket]++;
4588 // if (index == leftPositions[CurlyBracket].length) {
4589 // System.arraycopy(leftPositions[CurlyBracket], 0,
4590 // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4591 // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4592 // new int[index * 2]), 0, index);
4594 // leftPositions[CurlyBracket][index] = scanner.startPosition;
4595 // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4599 // int index = rightCount[CurlyBracket]++;
4600 // if (index == rightPositions[CurlyBracket].length) {
4601 // System.arraycopy(rightPositions[CurlyBracket], 0,
4602 // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4603 // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket]
4605 // new int[index * 2]), 0, index);
4607 // rightPositions[CurlyBracket][index] = scanner.startPosition;
4608 // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4612 // int index = leftCount[RoundBracket]++;
4613 // if (index == leftPositions[RoundBracket].length) {
4614 // System.arraycopy(leftPositions[RoundBracket], 0,
4615 // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4616 // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4617 // new int[index * 2]), 0, index);
4619 // leftPositions[RoundBracket][index] = scanner.startPosition;
4620 // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4624 // int index = rightCount[RoundBracket]++;
4625 // if (index == rightPositions[RoundBracket].length) {
4626 // System.arraycopy(rightPositions[RoundBracket], 0,
4627 // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4628 // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket]
4630 // new int[index * 2]), 0, index);
4632 // rightPositions[RoundBracket][index] = scanner.startPosition;
4633 // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4637 // int index = leftCount[SquareBracket]++;
4638 // if (index == leftPositions[SquareBracket].length) {
4639 // System.arraycopy(leftPositions[SquareBracket], 0,
4640 // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4641 // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket]
4643 // new int[index * 2]), 0, index);
4645 // leftPositions[SquareBracket][index] = scanner.startPosition;
4646 // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4650 // int index = rightCount[SquareBracket]++;
4651 // if (index == rightPositions[SquareBracket].length) {
4652 // System.arraycopy(rightPositions[SquareBracket], 0,
4653 // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4654 // System.arraycopy(rightDepths[SquareBracket], 0,
4655 // (rightDepths[SquareBracket]
4656 // = new int[index * 2]), 0, index);
4658 // rightPositions[SquareBracket][index] = scanner.startPosition;
4659 // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4663 // if (scanner.getNextChar('\\')) {
4664 // scanner.scanEscapeCharacter();
4665 // } else { // consume next character
4666 // scanner.unicodeAsBackSlash = false;
4667 // // if (((scanner.currentCharacter =
4668 // // source[scanner.currentPosition++]) ==
4670 // // (source[scanner.currentPosition] ==
4672 // // scanner.getNextUnicodeChar();
4674 // if (scanner.withoutUnicodePtr != 0) {
4675 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4676 // scanner.currentCharacter;
4680 // scanner.getNextChar('\'');
4684 // // consume next character
4685 // scanner.unicodeAsBackSlash = false;
4686 // // if (((scanner.currentCharacter =
4687 // // source[scanner.currentPosition++]) == '\\') &&
4688 // // (source[scanner.currentPosition] == 'u')) {
4689 // // scanner.getNextUnicodeChar();
4691 // if (scanner.withoutUnicodePtr != 0) {
4692 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4693 // scanner.currentCharacter;
4696 // while (scanner.currentCharacter != '"') {
4697 // if (scanner.currentCharacter == '\r') {
4698 // if (source[scanner.currentPosition] == '\n')
4699 // scanner.currentPosition++;
4700 // break; // the string cannot go further that
4703 // if (scanner.currentCharacter == '\n') {
4704 // break; // the string cannot go further that
4707 // if (scanner.currentCharacter == '\\') {
4708 // scanner.scanEscapeCharacter();
4710 // // consume next character
4711 // scanner.unicodeAsBackSlash = false;
4712 // // if (((scanner.currentCharacter =
4713 // // source[scanner.currentPosition++]) == '\\')
4714 // // && (source[scanner.currentPosition] == 'u'))
4716 // // scanner.getNextUnicodeChar();
4718 // if (scanner.withoutUnicodePtr != 0) {
4719 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4720 // scanner.currentCharacter;
4727 // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4729 // //get the next char
4730 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4732 // && (source[scanner.currentPosition] == 'u')) {
4733 // //-------------unicode traitement
4735 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4736 // scanner.currentPosition++;
4737 // while (source[scanner.currentPosition] == 'u') {
4738 // scanner.currentPosition++;
4740 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4742 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4745 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4748 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4750 // || c4 < 0) { //error
4754 // scanner.currentCharacter = 'A';
4755 // } //something different from \n and \r
4757 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4760 // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4762 // //get the next char
4763 // scanner.startPosition = scanner.currentPosition;
4764 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4766 // && (source[scanner.currentPosition] == 'u')) {
4767 // //-------------unicode traitement
4769 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4770 // scanner.currentPosition++;
4771 // while (source[scanner.currentPosition] == 'u') {
4772 // scanner.currentPosition++;
4774 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4776 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4779 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4782 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4784 // || c4 < 0) { //error
4788 // scanner.currentCharacter = 'A';
4789 // } //something different from \n
4792 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4796 // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4797 // (scanner.currentCharacter == '\n'))) {
4798 // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4799 // // only record line positions we
4800 // // have not recorded yet
4801 // scanner.pushLineSeparator();
4802 // if (this.scanner.taskTags != null) {
4803 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4805 // .getCurrentTokenEndPosition());
4811 // if (test > 0) { //traditional and annotation
4813 // boolean star = false;
4814 // // consume next character
4815 // scanner.unicodeAsBackSlash = false;
4816 // // if (((scanner.currentCharacter =
4817 // // source[scanner.currentPosition++]) ==
4819 // // (source[scanner.currentPosition] ==
4821 // // scanner.getNextUnicodeChar();
4823 // if (scanner.withoutUnicodePtr != 0) {
4824 // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4825 // scanner.currentCharacter;
4828 // if (scanner.currentCharacter == '*') {
4831 // //get the next char
4832 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4834 // && (source[scanner.currentPosition] == 'u')) {
4835 // //-------------unicode traitement
4837 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4838 // scanner.currentPosition++;
4839 // while (source[scanner.currentPosition] == 'u') {
4840 // scanner.currentPosition++;
4842 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4844 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4847 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4850 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4852 // || c4 < 0) { //error
4856 // scanner.currentCharacter = 'A';
4857 // } //something different from * and /
4859 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4862 // //loop until end of comment */
4863 // while ((scanner.currentCharacter != '/') || (!star)) {
4864 // star = scanner.currentCharacter == '*';
4866 // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4868 // && (source[scanner.currentPosition] == 'u')) {
4869 // //-------------unicode traitement
4871 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4872 // scanner.currentPosition++;
4873 // while (source[scanner.currentPosition] == 'u') {
4874 // scanner.currentPosition++;
4876 // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4878 // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) >
4881 // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) >
4884 // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) >
4886 // || c4 < 0) { //error
4890 // scanner.currentCharacter = 'A';
4891 // } //something different from * and
4894 // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4898 // if (this.scanner.taskTags != null) {
4899 // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4900 // this.scanner.getCurrentTokenEndPosition());
4907 // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4908 // scanner.scanIdentifierOrKeyword(false);
4911 // if (Character.isDigit(scanner.currentCharacter)) {
4912 // scanner.scanNumber(false);
4916 // //-----------------end switch while
4917 // // try--------------------
4918 // } catch (IndexOutOfBoundsException e) {
4919 // break; // read until EOF
4920 // } catch (InvalidInputException e) {
4921 // return false; // no clue
4924 // if (scanner.recordLineSeparator) {
4925 // compilationUnit.compilationResult.lineSeparatorPositions =
4926 // scanner.getLineEnds();
4928 // // check placement anomalies against other kinds of brackets
4929 // for (int kind = 0; kind < BracketKinds; kind++) {
4930 // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4931 // int start = leftPositions[kind][leftIndex]; // deepest
4933 // // find matching closing bracket
4934 // int depth = leftDepths[kind][leftIndex];
4936 // for (int i = 0; i < rightCount[kind]; i++) {
4937 // int pos = rightPositions[kind][i];
4938 // // want matching bracket further in source with same
4940 // if ((pos > start) && (depth == rightDepths[kind][i])) {
4945 // if (end < 0) { // did not find a good closing match
4946 // problemReporter.unmatchedBracket(start, referenceContext,
4947 // compilationUnit.compilationResult);
4950 // // check if even number of opening/closing other brackets
4951 // // in between this pair of brackets
4953 // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4955 // for (int i = 0; i < leftCount[otherKind]; i++) {
4956 // int pos = leftPositions[otherKind][i];
4957 // if ((pos > start) && (pos < end))
4960 // for (int i = 0; i < rightCount[otherKind]; i++) {
4961 // int pos = rightPositions[otherKind][i];
4962 // if ((pos > start) && (pos < end))
4965 // if (balance != 0) {
4966 // problemReporter.unmatchedBracket(start, referenceContext,
4967 // compilationUnit.compilationResult); //bracket
4973 // // too many opening brackets ?
4974 // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4975 // anomaliesDetected = true;
4976 // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i
4978 // 1], referenceContext,
4979 // compilationUnit.compilationResult);
4981 // // too many closing brackets ?
4982 // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4983 // anomaliesDetected = true;
4984 // problemReporter.unmatchedBracket(rightPositions[kind][i],
4985 // referenceContext,
4986 // compilationUnit.compilationResult);
4988 // if (anomaliesDetected)
4991 // return anomaliesDetected;
4992 // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4993 // return anomaliesDetected;
4994 // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4995 // return anomaliesDetected;
4998 protected void pushOnAstLengthStack(int pos) {
5000 astLengthStack[++astLengthPtr] = pos;
5001 } catch (IndexOutOfBoundsException e) {
5002 int oldStackLength = astLengthStack.length;
5003 int[] oldPos = astLengthStack;
5004 astLengthStack = new int[oldStackLength + StackIncrement];
5005 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5006 astLengthStack[astLengthPtr] = pos;
5010 protected void pushOnAstStack(ASTNode node) {
5012 * add a new obj on top of the ast stack
5015 astStack[++astPtr] = node;
5016 } catch (IndexOutOfBoundsException e) {
5017 int oldStackLength = astStack.length;
5018 ASTNode[] oldStack = astStack;
5019 astStack = new ASTNode[oldStackLength + AstStackIncrement];
5020 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
5021 astPtr = oldStackLength;
5022 astStack[astPtr] = node;
5025 astLengthStack[++astLengthPtr] = 1;
5026 } catch (IndexOutOfBoundsException e) {
5027 int oldStackLength = astLengthStack.length;
5028 int[] oldPos = astLengthStack;
5029 astLengthStack = new int[oldStackLength + AstStackIncrement];
5030 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
5031 astLengthStack[astLengthPtr] = 1;
5035 protected void resetModifiers() {
5036 this.modifiers = AccDefault;
5037 this.modifiersSourceStart = -1; // <-- see comment into
5038 // modifiersFlag(int)
5039 this.scanner.commentPtr = -1;
5042 protected void consumePackageDeclarationName(IFile file) {
5043 // create a package name similar to java package names
5044 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject())
5046 String filePath = file.getFullPath().toString();
5048 String ext = file.getFileExtension();
5049 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
5050 ImportReference impt;
5052 if (filePath.startsWith(projectPath)) {
5053 tokens = CharOperation.splitOn('/', filePath.toCharArray(),
5054 projectPath.length() + 1, filePath.length()
5055 - fileExtensionLength);
5057 String name = file.getName();
5058 tokens = new char[1][];
5059 tokens[0] = name.substring(0, name.length() - fileExtensionLength)
5063 this.compilationUnit.currentPackage = impt = new ImportReference(
5064 tokens, new char[0], 0, 0, true);
5066 impt.declarationSourceStart = 0;
5067 impt.declarationSourceEnd = 0;
5068 impt.declarationEnd = 0;
5069 // endPosition is just before the ;
5073 public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV",
5074 "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST", "$_SESSION",
5080 private void pushFunctionVariableSet() {
5081 HashSet set = new HashSet();
5082 if (fStackUnassigned.isEmpty()) {
5083 for (int i = 0; i < GLOBALS.length; i++) {
5084 set.add(GLOBALS[i]);
5087 fStackUnassigned.add(set);
5090 private void pushIfVariableSet() {
5091 if (!fStackUnassigned.isEmpty()) {
5092 HashSet set = new HashSet();
5093 fStackUnassigned.add(set);
5097 private HashSet removeIfVariableSet() {
5098 if (!fStackUnassigned.isEmpty()) {
5099 return (HashSet) fStackUnassigned
5100 .remove(fStackUnassigned.size() - 1);
5106 * Returns the <i>set of assigned variables </i> returns null if no Set is
5107 * defined at the current scanner position
5109 private HashSet peekVariableSet() {
5110 if (!fStackUnassigned.isEmpty()) {
5111 return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
5117 * add the current identifier source to the <i>set of assigned variables
5122 private void addVariableSet(HashSet set) {
5124 set.add(new String(scanner.getCurrentTokenSource()));
5129 * add the current identifier source to the <i>set of assigned variables
5133 private void addVariableSet() {
5134 HashSet set = peekVariableSet();
5136 set.add(new String(scanner.getCurrentTokenSource()));
5141 * add the current identifier source to the <i>set of assigned variables
5145 private void addVariableSet(char[] token) {
5146 HashSet set = peekVariableSet();
5148 set.add(new String(token));
5153 * check if the current identifier source is in the <i>set of assigned
5154 * variables </i> Returns true, if no set is defined for the current scanner
5158 private boolean containsVariableSet() {
5159 return containsVariableSet(scanner.getCurrentTokenSource());
5162 private boolean containsVariableSet(char[] token) {
5164 if (!fStackUnassigned.isEmpty()) {
5166 String str = new String(token);
5167 for (int i = 0; i < fStackUnassigned.size(); i++) {
5168 set = (HashSet) fStackUnassigned.get(i);
5169 if (set.contains(str)) {