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;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
23 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
44 import org.eclipse.core.resources.IFile;
45 import org.eclipse.core.resources.IProject;
46 import org.eclipse.core.resources.IResource;
48 public class Parser //extends PHPParserSuperclass
49 implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
50 //internal data for the automat
51 protected final static int StackIncrement = 255;
53 protected int stateStackTop;
55 protected int[] stack = new int[StackIncrement];
57 public int firstToken; // handle for multiple parsing goals
59 public int lastAct; //handle for multiple parsing goals
61 protected RecoveredElement currentElement;
63 public static boolean VERBOSE_RECOVERY = false;
65 protected boolean diet = false; //tells the scanner to jump over some
67 // parts of the code/expressions like
70 public Scanner scanner;
72 private ArrayList phpList;
74 private int currentPHPString;
76 private boolean phpEnd;
78 // private static HashMap keywordMap = null;
86 // row counter for syntax errors:
88 // column counter for syntax errors:
92 // // current identifier
98 private String stringValue;
100 /** Contains the current expression. */
101 // private StringBuffer expression;
102 //private boolean phpMode;
103 protected int modifiers;
105 protected int modifiersSourceStart;
107 // protected IdentifierIndexManager indexManager;
109 protected Parser(ProblemReporter problemReporter) {
110 this.problemReporter = problemReporter;
111 this.options = problemReporter.options;
112 this.currentPHPString = 0;
113 // PHPParserSuperclass.fileToParse = fileToParse;
115 // this.indexManager = null;
117 this.token = TokenNameEOF;
119 // this.rowCount = 1;
120 // this.columnCount = 0;
123 this.initializeScanner();
126 public void setFileToParse(IFile fileToParse) {
127 this.currentPHPString = 0;
128 // PHPParserSuperclass.fileToParse = fileToParse;
130 // this.indexManager = null;
132 this.token = TokenNameEOF;
134 this.initializeScanner();
138 * ClassDeclaration Constructor.
142 * Description of Parameter
145 public Parser(IFile fileToParse) {
146 // if (keywordMap == null) {
147 // keywordMap = new HashMap();
148 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
149 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
152 this.currentPHPString = 0;
153 // PHPParserSuperclass.fileToParse = fileToParse;
155 this.includesList = null;
157 this.token = TokenNameEOF;
159 // this.rowCount = 1;
160 // this.columnCount = 0;
163 this.initializeScanner();
166 public void initializeScanner() {
167 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
168 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
169 this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */);
173 * Create marker for the parse error
175 // private void setMarker(String message, int charStart, int charEnd, int
177 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
180 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
184 * @throws SyntaxError
187 private void throwSyntaxError(String error) {
188 int problemStartPosition = scanner.getCurrentTokenStartPosition();
189 int problemEndPosition = scanner.getCurrentTokenEndPosition();
190 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
194 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
198 * @throws SyntaxError
201 // private void throwSyntaxError(String error, int startRow) {
202 // throw new SyntaxError(startRow, 0, " ", error);
204 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
205 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
206 compilationUnit.compilationResult);
207 throw new SyntaxError(1, 0, " ", error);
210 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
211 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
212 compilationUnit.compilationResult);
215 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
216 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
217 compilationUnit.compilationResult);
221 * gets the next token from input
223 private void getNextToken() {
225 token = scanner.getNextToken();
227 int currentEndPosition = scanner.getCurrentTokenEndPosition();
228 int currentStartPosition = scanner.getCurrentTokenStartPosition();
229 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
230 System.out.println(scanner.toStringAction(token));
232 } catch (InvalidInputException e) {
233 token = TokenNameERROR;
234 String detailedMessage = e.getMessage();
236 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
237 throwSyntaxError("Unterminated string.");
238 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
239 throwSyntaxError("Unterminated commment.");
245 public void init(String s) {
247 this.token = TokenNameEOF;
249 // this.rowCount = 1;
250 // this.columnCount = 0;
252 // this.phpMode = false;
253 /* scanner initialization */
254 scanner.setSource(s.toCharArray());
255 scanner.setPHPMode(false);
258 protected void initialize(boolean phpMode) {
259 initialize(phpMode, null);
262 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
263 compilationUnit = null;
264 referenceContext = null;
265 includesList = new ArrayList();
266 // this.indexManager = indexManager;
268 this.token = TokenNameEOF;
270 // this.rowCount = 1;
271 // this.columnCount = 0;
273 // this.phpMode = phpMode;
274 scanner.setPHPMode(phpMode);
278 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
280 public void parse(String s) {
286 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
288 protected void parse() {
292 if (token != TokenNameEOF && token != TokenNameERROR) {
295 if (token != TokenNameEOF) {
296 if (token == TokenNameERROR) {
297 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
299 if (token == TokenNameRPAREN) {
300 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
302 if (token == TokenNameRBRACE) {
303 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
305 if (token == TokenNameRBRACKET) {
306 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
308 if (token == TokenNameLPAREN) {
309 throwSyntaxError("Read character '('; end-of-file not reached.");
311 if (token == TokenNameLBRACE) {
312 throwSyntaxError("Read character '{'; end-of-file not reached.");
314 if (token == TokenNameLBRACKET) {
315 throwSyntaxError("Read character '['; end-of-file not reached.");
317 throwSyntaxError("End-of-file not reached.");
320 } catch (SyntaxError sytaxErr1) {
321 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
323 // setMarker(sytaxErr1.getMessage(),
324 // scanner.getCurrentTokenStartPosition(),
325 // scanner.getCurrentTokenEndPosition(), ERROR);
327 // if an error occured,
328 // try to find keywords 'class' or 'function'
329 // to parse the rest of the string
330 while (token != TokenNameEOF && token != TokenNameERROR) {
331 if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
336 if (token == TokenNameEOF || token == TokenNameERROR) {
339 } catch (SyntaxError sytaxErr2) {
340 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
342 // setMarker(sytaxErr2.getMessage(),
343 // scanner.getCurrentTokenStartPosition(),
344 // scanner.getCurrentTokenEndPosition(), ERROR);
353 protected CompilationUnitDeclaration endParse(int act) {
357 if (currentElement != null) {
358 currentElement.topElement().updateParseTree();
359 if (VERBOSE_RECOVERY) {
360 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
361 System.out.println("--------------------------"); //$NON-NLS-1$
362 System.out.println(compilationUnit);
363 System.out.println("----------------------------------"); //$NON-NLS-1$
366 if (diet & VERBOSE_RECOVERY) {
367 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
368 System.out.println("--------------------------"); //$NON-NLS-1$
369 System.out.println(compilationUnit);
370 System.out.println("----------------------------------"); //$NON-NLS-1$
373 if (scanner.recordLineSeparator) {
374 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
376 if (scanner.taskTags != null) {
377 for (int i = 0; i < scanner.foundTaskCount; i++) {
378 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
379 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
380 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
383 compilationUnit.imports = new ImportReference[includesList.size()];
384 for (int i = 0; i < includesList.size(); i++) {
385 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
387 return compilationUnit;
390 // public PHPOutlineInfo parseInfo(Object parent, String s) {
391 // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
392 // // Stack stack = new Stack();
393 // // stack.push(outlineInfo.getDeclarations());
395 // this.token = TokenNameEOF;
396 // // this.chIndx = 0;
397 // // this.rowCount = 1;
398 // // this.columnCount = 0;
399 // this.phpEnd = false;
400 // this.phpMode = false;
401 // scanner.setSource(s.toCharArray());
402 // scanner.setPHPMode(false);
405 // parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
407 // return outlineInfo;
409 private boolean isVariable() {
410 return token == TokenNameVariable; // || token == TokenNamethis;
413 // private void parseDeclarations(PHPOutlineInfo outlineInfo,
414 // OutlineableWithChildren current, boolean goBack) {
416 // // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
417 // PHPSegmentWithChildren temp;
419 // IPreferenceStore store =
420 // PHPeclipsePlugin.getDefault().getPreferenceStore();
422 // while (token != TokenNameEOF && token != TokenNameERROR) {
423 // if (token == TokenNameVariable) {
424 // ident = scanner.getCurrentIdentifierSource();
425 // outlineInfo.addVariable(new String(ident));
427 // } else if (token == TokenNamevar) {
429 // if (token == TokenNameVariable
430 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
431 // ident = scanner.getCurrentIdentifierSource();
432 // //substring(1) added because PHPVarDeclaration doesn't
433 // // need the $ anymore
434 // String variableName = new String(ident).substring(1);
435 // outlineInfo.addVariable(variableName);
437 // if (token != TokenNameSEMICOLON) {
439 // ident = scanner.getCurrentTokenSource();
440 // if (token > TokenNameKEYWORD) {
441 // current.add(new PHPVarDeclaration(current, variableName,
442 // // chIndx - ident.length,
443 // scanner.getCurrentTokenStartPosition(), new String(ident)));
446 // case TokenNameVariable :
447 // case TokenNamethis :
448 // current.add(new PHPVarDeclaration(current, variableName,
451 // scanner.getCurrentTokenStartPosition(), new String(
454 // case TokenNameIdentifier :
455 // current.add(new PHPVarDeclaration(current, variableName,
458 // scanner.getCurrentTokenStartPosition(), new String(
461 // case TokenNameDoubleLiteral :
462 // current.add(new PHPVarDeclaration(current, variableName
466 // scanner.getCurrentTokenStartPosition(), new String(
469 // case TokenNameIntegerLiteral :
470 // current.add(new PHPVarDeclaration(current, variableName,
473 // scanner.getCurrentTokenStartPosition(), new String(
476 // case TokenNameStringInterpolated :
477 // case TokenNameStringLiteral :
478 // current.add(new PHPVarDeclaration(current, variableName,
481 // scanner.getCurrentTokenStartPosition(), new String(
484 // case TokenNameStringConstant :
485 // current.add(new PHPVarDeclaration(current, variableName,
488 // scanner.getCurrentTokenStartPosition(), new String(
492 // current.add(new PHPVarDeclaration(current, variableName,
495 // scanner.getCurrentTokenStartPosition()));
500 // ident = scanner.getCurrentIdentifierSource();
501 // current.add(new PHPVarDeclaration(current, variableName,
502 // // chIndx - ident.length
503 // scanner.getCurrentTokenStartPosition()));
506 // } else if (token == TokenNamefunction) {
508 // if (token == TokenNameAND) {
511 // if (token == TokenNameIdentifier
512 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
513 // ident = scanner.getCurrentIdentifierSource();
514 // outlineInfo.addVariable(new String(ident));
515 // temp = new PHPFunctionDeclaration(current, new String(ident),
516 // // chIndx - ident.length
517 // scanner.getCurrentTokenStartPosition());
518 // current.add(temp);
520 // parseDeclarations(outlineInfo, temp, true);
522 // } else if (token == TokenNameclass) {
524 // if (token == TokenNameIdentifier
525 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
526 // ident = scanner.getCurrentIdentifierSource();
527 // outlineInfo.addVariable(new String(ident));
528 // temp = new PHPClassDeclaration(current, new String(ident),
529 // // chIndx - ident.len
530 // scanner.getCurrentTokenStartPosition());
531 // current.add(temp);
532 // // stack.push(temp);
534 // //skip tokens for classname, extends and others until
535 // // we have the opening '{'
536 // while (token != TokenNameLBRACE && token != TokenNameEOF
537 // && token != TokenNameERROR) {
540 // parseDeclarations(outlineInfo, temp, true);
543 // } else if ((token == TokenNameLBRACE)
544 // || (token == TokenNameDOLLAR_LBRACE)) {
547 // } else if (token == TokenNameRBRACE) {
550 // if (counter == 0 && goBack) {
553 // } else if (token == TokenNamerequire || token == TokenNamerequire_once
554 // || token == TokenNameinclude || token == TokenNameinclude_once) {
555 // ident = scanner.getCurrentTokenSource();
557 // int startPosition = scanner.getCurrentTokenStartPosition();
559 // char[] expr = scanner.getCurrentTokenSource(startPosition);
560 // outlineInfo.addVariable(new String(ident));
561 // current.add(new PHPReqIncDeclaration(current, new String(ident),
562 // // chIndx - ident.length,
563 // startPosition, new String(expr)));
569 // } catch (SyntaxError sytaxErr) {
571 // // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
572 // // setMarker(sytaxErr.getMessage(),
573 // // scanner.getCurrentTokenStartPosition(),
574 // // scanner.getCurrentTokenEndPosition(), ERROR);
575 // // } catch (CoreException e) {
579 private void statementList() {
581 statement(TokenNameEOF);
582 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
583 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
584 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
585 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
591 private void functionBody(MethodDeclaration methodDecl) {
592 // '{' [statement-list] '}'
593 if (token == TokenNameLBRACE) {
596 throwSyntaxError("'{' expected in compound-statement.");
598 if (token != TokenNameRBRACE) {
601 if (token == TokenNameRBRACE) {
602 methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
605 throwSyntaxError("'}' expected in compound-statement.");
609 private Statement statement(int previousToken) {
610 Statement statement = null;
611 Expression expression;
612 int sourceStart = scanner.getCurrentTokenStartPosition();
613 if (token == TokenNameif) {
615 if (token == TokenNameLPAREN) {
618 throwSyntaxError("'(' expected after 'if' keyword.");
621 if (token == TokenNameRPAREN) {
624 throwSyntaxError("')' expected after 'if' condition.");
627 return new IfStatement(expression, statement, sourceStart, scanner.getCurrentTokenEndPosition());
628 } else if (token == TokenNameswitch) {
630 if (token == TokenNameLPAREN) {
633 throwSyntaxError("'(' expected after 'switch' keyword.");
636 if (token == TokenNameRPAREN) {
639 throwSyntaxError("')' expected after 'switch' condition.");
643 } else if (token == TokenNamefor) {
645 if (token == TokenNameLPAREN) {
648 throwSyntaxError("'(' expected after 'for' keyword.");
650 if (token == TokenNameSEMICOLON) {
654 if (token == TokenNameSEMICOLON) {
657 throwSyntaxError("';' expected after 'for'.");
660 if (token == TokenNameSEMICOLON) {
664 if (token == TokenNameSEMICOLON) {
667 throwSyntaxError("';' expected after 'for'.");
670 if (token == TokenNameRPAREN) {
674 if (token == TokenNameRPAREN) {
677 throwSyntaxError("')' expected after 'for'.");
682 } else if (token == TokenNamewhile) {
684 if (token == TokenNameLPAREN) {
687 throwSyntaxError("'(' expected after 'while' keyword.");
690 if (token == TokenNameRPAREN) {
693 throwSyntaxError("')' expected after 'while' condition.");
697 } else if (token == TokenNamedo) {
699 if (token == TokenNameLBRACE) {
701 if (token != TokenNameRBRACE) {
704 if (token == TokenNameRBRACE) {
707 throwSyntaxError("'}' expected after 'do' keyword.");
710 statement(TokenNameEOF);
712 if (token == TokenNamewhile) {
714 if (token == TokenNameLPAREN) {
717 throwSyntaxError("'(' expected after 'while' keyword.");
720 if (token == TokenNameRPAREN) {
723 throwSyntaxError("')' expected after 'while' condition.");
726 throwSyntaxError("'while' expected after 'do' keyword.");
728 if (token == TokenNameSEMICOLON) {
731 if (token != TokenNameINLINE_HTML) {
732 throwSyntaxError("';' expected after do-while statement.");
737 } else if (token == TokenNameforeach) {
739 if (token == TokenNameLPAREN) {
742 throwSyntaxError("'(' expected after 'foreach' keyword.");
745 if (token == TokenNameas) {
748 throwSyntaxError("'as' expected after 'foreach' exxpression.");
752 foreach_optional_arg();
753 if (token == TokenNameEQUAL_GREATER) {
757 if (token == TokenNameRPAREN) {
760 throwSyntaxError("')' expected after 'foreach' expression.");
764 } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
766 if (token != TokenNameSEMICOLON) {
769 if (token == TokenNameSEMICOLON) {
772 if (token != TokenNameINLINE_HTML) {
773 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
778 } else if (token == TokenNameecho) {
781 if (token == TokenNameSEMICOLON) {
784 if (token != TokenNameINLINE_HTML) {
785 throwSyntaxError("';' expected after 'echo' statement.");
790 } else if (token == TokenNameINLINE_HTML) {
793 // } else if (token == TokenNameprint) {
796 // if (token == TokenNameSEMICOLON) {
799 // if (token != TokenNameStopPHP) {
800 // throwSyntaxError("';' expected after 'print' statement.");
805 } else if (token == TokenNameglobal) {
808 if (token == TokenNameSEMICOLON) {
811 if (token != TokenNameINLINE_HTML) {
812 throwSyntaxError("';' expected after 'global' statement.");
817 } else if (token == TokenNamestatic) {
820 if (token == TokenNameSEMICOLON) {
823 if (token != TokenNameINLINE_HTML) {
824 throwSyntaxError("';' expected after 'static' statement.");
829 } else if (token == TokenNameunset) {
831 if (token == TokenNameLPAREN) {
834 throwSyntaxError("'(' expected after 'unset' statement.");
837 if (token == TokenNameRPAREN) {
840 throwSyntaxError("')' expected after 'unset' statement.");
842 if (token == TokenNameSEMICOLON) {
845 if (token != TokenNameINLINE_HTML) {
846 throwSyntaxError("';' expected after 'unset' statement.");
851 } else if (token == TokenNamefunction) {
852 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
853 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
854 methodDecl.modifiers = AccDefault;
856 functionDefinition(methodDecl);
858 } else if (token == TokenNamedeclare) {
859 //T_DECLARE '(' declare_list ')' declare_statement
861 if (token != TokenNameLPAREN) {
862 throwSyntaxError("'(' expected in 'declare' statement.");
866 if (token != TokenNameRPAREN) {
867 throwSyntaxError("')' expected in 'declare' statement.");
872 } else if (token == TokenNametry) {
874 if (token != TokenNameLBRACE) {
875 throwSyntaxError("'{' expected in 'try' statement.");
879 if (token != TokenNameRBRACE) {
880 throwSyntaxError("'}' expected in 'try' statement.");
884 } else if (token == TokenNamecatch) {
886 if (token != TokenNameLPAREN) {
887 throwSyntaxError("'(' expected in 'catch' statement.");
890 fully_qualified_class_name();
891 if (token != TokenNameVariable) {
892 throwSyntaxError("Variable expected in 'catch' statement.");
895 if (token != TokenNameRPAREN) {
896 throwSyntaxError("')' expected in 'catch' statement.");
899 if (token != TokenNameLBRACE) {
900 throwSyntaxError("'{' expected in 'catch' statement.");
903 if (token != TokenNameRBRACE) {
905 if (token != TokenNameRBRACE) {
906 throwSyntaxError("'}' expected in 'catch' statement.");
910 additional_catches();
912 } else if (token == TokenNamethrow) {
915 if (token == TokenNameSEMICOLON) {
918 throwSyntaxError("';' expected after 'throw' exxpression.");
921 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
922 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
923 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
924 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
925 typeDecl.name = new char[] { ' ' };
926 // default super class
927 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
928 compilationUnit.types.add(typeDecl);
930 pushOnAstStack(typeDecl);
931 unticked_class_declaration_statement(typeDecl);
932 // classBody(typeDecl);
939 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
940 } else if (token == TokenNameLBRACE) {
942 if (token != TokenNameRBRACE) {
945 if (token == TokenNameRBRACE) {
949 throwSyntaxError("'}' expected.");
952 if (token != TokenNameSEMICOLON) {
955 if (token == TokenNameSEMICOLON) {
959 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
960 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
969 private void declare_statement() {
971 //| ':' inner_statement_list T_ENDDECLARE ';'
973 if (token == TokenNameCOLON) {
975 // TODO: implement inner_statement_list();
977 if (token != TokenNameenddeclare) {
978 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
981 if (token != TokenNameSEMICOLON) {
982 throwSyntaxError("';' expected after 'enddeclare' keyword.");
986 statement(TokenNameRPAREN);
990 private void declare_list() {
991 // T_STRING '=' static_scalar
992 //| declare_list ',' T_STRING '=' static_scalar
994 if (token != TokenNameIdentifier) {
995 throwSyntaxError("Identifier expected in 'declare' list.");
998 if (token != TokenNameEQUAL) {
999 throwSyntaxError("'=' expected in 'declare' list.");
1003 if (token != TokenNameCOMMA) {
1010 private void additional_catches() {
1011 while (token == TokenNamecatch) {
1013 if (token != TokenNameLPAREN) {
1014 throwSyntaxError("'(' expected in 'catch' statement.");
1017 fully_qualified_class_name();
1018 if (token != TokenNameVariable) {
1019 throwSyntaxError("Variable expected in 'catch' statement.");
1022 if (token != TokenNameRPAREN) {
1023 throwSyntaxError("')' expected in 'catch' statement.");
1026 if (token != TokenNameLBRACE) {
1027 throwSyntaxError("'{' expected in 'catch' statement.");
1030 if (token != TokenNameRBRACE) {
1033 if (token != TokenNameRBRACE) {
1034 throwSyntaxError("'}' expected in 'catch' statement.");
1040 private void foreach_variable() {
1043 if (token == TokenNameAND) {
1049 private void foreach_optional_arg() {
1051 //| T_DOUBLE_ARROW foreach_variable
1052 if (token == TokenNameEQUAL_GREATER) {
1058 private void global_var_list() {
1060 // global_var_list ',' global_var
1064 if (token != TokenNameCOMMA) {
1071 private void global_var() {
1075 //| '$' '{' expr '}'
1076 if (token == TokenNameVariable) {
1078 } else if (token == TokenNameDOLLAR) {
1080 if (token == TokenNameLPAREN) {
1083 if (token != TokenNameLPAREN) {
1084 throwSyntaxError("')' expected in global variable.");
1093 private void static_var_list() {
1095 // static_var_list ',' T_VARIABLE
1096 //| static_var_list ',' T_VARIABLE '=' static_scalar
1098 //| T_VARIABLE '=' static_scalar
1100 if (token == TokenNameVariable) {
1102 if (token == TokenNameEQUAL) {
1106 if (token != TokenNameCOMMA) {
1116 private void unset_variables() {
1119 // | unset_variables ',' unset_variable
1124 if (token != TokenNameCOMMA) {
1131 private final void initializeModifiers() {
1133 this.modifiersSourceStart = -1;
1136 private final void checkAndSetModifiers(int flag) {
1137 this.modifiers |= flag;
1138 if (this.modifiersSourceStart < 0)
1139 this.modifiersSourceStart = this.scanner.startPosition;
1142 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1143 initializeModifiers();
1144 if (token == TokenNameinterface) {
1145 // interface_entry T_STRING
1146 // interface_extends_list
1147 // '{' class_statement_list '}'
1148 checkAndSetModifiers(AccInterface);
1150 typeDecl.modifiers = this.modifiers;
1151 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1152 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1153 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1154 typeDecl.name = scanner.getCurrentIdentifierSource();
1155 if (token > TokenNameKEYWORD) {
1156 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1157 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1158 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1159 // typeDecl.sourceStart, typeDecl.sourceEnd);
1162 interface_extends_list();
1164 typeDecl.name = new char[] { ' ' };
1165 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1169 // class_entry_type T_STRING extends_from
1171 // '{' class_statement_list'}'
1173 typeDecl.modifiers = this.modifiers;
1174 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1175 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1177 //identifier 'extends' identifier
1178 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1179 typeDecl.name = scanner.getCurrentIdentifierSource();
1180 if (token > TokenNameKEYWORD) {
1181 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1182 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1183 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1184 // typeDecl.sourceStart, typeDecl.sourceEnd);
1189 // | T_EXTENDS fully_qualified_class_name
1190 if (token == TokenNameextends) {
1191 interface_extends_list();
1193 // if (token != TokenNameIdentifier) {
1194 // throwSyntaxError("Class name expected after keyword
1196 // scanner.getCurrentTokenStartPosition(), scanner
1197 // .getCurrentTokenEndPosition());
1202 typeDecl.name = new char[] { ' ' };
1203 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1207 // '{' class_statement_list '}'
1208 if (token == TokenNameLBRACE) {
1210 if (token != TokenNameRBRACE) {
1211 ArrayList list = new ArrayList();
1212 class_statement_list(list);
1213 typeDecl.fields = new FieldDeclaration[list.size()];
1214 for (int i = 0; i < list.size(); i++) {
1215 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1218 if (token == TokenNameRBRACE) {
1219 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1222 throwSyntaxError("'}' expected at end of class body.");
1225 throwSyntaxError("'{' expected at start of class body.");
1229 private void class_entry_type() {
1231 // | T_ABSTRACT T_CLASS
1232 // | T_FINAL T_CLASS
1233 if (token == TokenNameclass) {
1235 } else if (token == TokenNameabstract) {
1236 checkAndSetModifiers(AccAbstract);
1238 if (token != TokenNameclass) {
1239 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1242 } else if (token == TokenNamefinal) {
1243 checkAndSetModifiers(AccFinal);
1245 if (token != TokenNameclass) {
1246 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1250 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1254 private void interface_extends_list() {
1256 // | T_EXTENDS interface_list
1257 if (token == TokenNameextends) {
1263 private void implements_list() {
1265 // | T_IMPLEMENTS interface_list
1266 if (token == TokenNameimplements) {
1272 private void interface_list() {
1274 // fully_qualified_class_name
1275 //| interface_list ',' fully_qualified_class_name
1277 if (token == TokenNameIdentifier) {
1280 throwSyntaxError("Interface name expected after keyword 'implements'.");
1282 if (token != TokenNameCOMMA) {
1289 // private void classBody(TypeDeclaration typeDecl) {
1290 // //'{' [class-element-list] '}'
1291 // if (token == TokenNameLBRACE) {
1293 // if (token != TokenNameRBRACE) {
1294 // class_statement_list();
1296 // if (token == TokenNameRBRACE) {
1297 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1300 // throwSyntaxError("'}' expected at end of class body.");
1303 // throwSyntaxError("'{' expected at start of class body.");
1306 private void class_statement_list(ArrayList list) {
1308 class_statement(list);
1309 } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1310 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1311 || token == TokenNameconst);
1314 private void class_statement(ArrayList list) {
1316 // variable_modifiers class_variable_declaration ';'
1317 // | class_constant_declaration ';'
1318 // | method_modifiers T_FUNCTION is_reference T_STRING
1319 // '(' parameter_list ')' method_body
1320 initializeModifiers();
1321 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1323 if (token == TokenNamevar) {
1324 checkAndSetModifiers(AccPublic);
1325 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1326 referenceContext, compilationUnit.compilationResult);
1328 class_variable_declaration(declarationSourceStart, list);
1329 } else if (token == TokenNameconst) {
1330 checkAndSetModifiers(AccFinal | AccPublic);
1331 class_constant_declaration(declarationSourceStart, list);
1332 if (token != TokenNameSEMICOLON) {
1333 throwSyntaxError("';' expected after class const declaration.");
1337 boolean hasModifiers = member_modifiers();
1338 if (token == TokenNamefunction) {
1339 if (!hasModifiers) {
1340 checkAndSetModifiers(AccPublic);
1342 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1343 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1344 methodDecl.modifiers = this.modifiers;
1346 functionDefinition(methodDecl);
1348 if (!hasModifiers) {
1349 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1351 class_variable_declaration(declarationSourceStart, list);
1356 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1357 // class_constant_declaration ',' T_STRING '=' static_scalar
1358 // | T_CONST T_STRING '=' static_scalar
1359 if (token != TokenNameconst) {
1360 throwSyntaxError("'const' keyword expected in class declaration.");
1365 if (token != TokenNameIdentifier) {
1366 throwSyntaxError("Identifier expected in class const declaration.");
1368 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1369 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1370 fieldDeclaration.modifiers = this.modifiers;
1371 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1372 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1373 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1374 // fieldDeclaration.type
1375 list.add(fieldDeclaration);
1377 if (token != TokenNameEQUAL) {
1378 throwSyntaxError("'=' expected in class const declaration.");
1382 if (token != TokenNameCOMMA) {
1383 break; // while(true)-loop
1389 // private void variable_modifiers() {
1390 // // variable_modifiers:
1391 // // non_empty_member_modifiers
1393 // initializeModifiers();
1394 // if (token == TokenNamevar) {
1395 // checkAndSetModifiers(AccPublic);
1396 // reportSyntaxError(
1397 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1399 // modifier for field declarations.",
1400 // scanner.getCurrentTokenStartPosition(), scanner
1401 // .getCurrentTokenEndPosition());
1404 // if (!member_modifiers()) {
1405 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1406 // field declarations.");
1410 // private void method_modifiers() {
1411 // //method_modifiers:
1413 // //| non_empty_member_modifiers
1414 // initializeModifiers();
1415 // if (!member_modifiers()) {
1416 // checkAndSetModifiers(AccPublic);
1419 private boolean member_modifiers() {
1426 boolean foundToken = false;
1428 if (token == TokenNamepublic) {
1429 checkAndSetModifiers(AccPublic);
1432 } else if (token == TokenNameprotected) {
1433 checkAndSetModifiers(AccProtected);
1436 } else if (token == TokenNameprivate) {
1437 checkAndSetModifiers(AccPrivate);
1440 } else if (token == TokenNamestatic) {
1441 checkAndSetModifiers(AccStatic);
1444 } else if (token == TokenNameabstract) {
1445 checkAndSetModifiers(AccAbstract);
1448 } else if (token == TokenNamefinal) {
1449 checkAndSetModifiers(AccFinal);
1459 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1460 // class_variable_declaration:
1461 // class_variable_declaration ',' T_VARIABLE
1462 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1464 // | T_VARIABLE '=' static_scalar
1465 char[] classVariable;
1467 if (token == TokenNameVariable) {
1468 classVariable = scanner.getCurrentIdentifierSource();
1469 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1470 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1471 .getCurrentTokenEndPosition());
1472 fieldDeclaration.modifiers = this.modifiers;
1473 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1474 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1475 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1476 // fieldDeclaration.type
1477 list.add(fieldDeclaration);
1479 if (token == TokenNameEQUAL) {
1484 // if (token == TokenNamethis) {
1485 // throwSyntaxError("'$this' not allowed after keyword 'public'
1486 // 'protected' 'private' 'var'.");
1488 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1490 if (token != TokenNameCOMMA) {
1495 if (token != TokenNameSEMICOLON) {
1496 throwSyntaxError("';' expected after field declaration.");
1501 private void functionDefinition(MethodDeclaration methodDecl) {
1502 boolean isAbstract = false;
1504 compilationUnit.types.add(methodDecl);
1506 ASTNode node = astStack[astPtr];
1507 if (node instanceof TypeDeclaration) {
1508 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1509 if (typeDecl.methods == null) {
1510 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1512 AbstractMethodDeclaration[] newMethods;
1513 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
1514 typeDecl.methods.length);
1515 newMethods[0] = methodDecl;
1516 typeDecl.methods = newMethods;
1518 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1520 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1525 functionDeclarator(methodDecl);
1526 if (token == TokenNameSEMICOLON) {
1528 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1533 functionBody(methodDecl);
1536 private void functionDeclarator(MethodDeclaration methodDecl) {
1537 //identifier '(' [parameter-list] ')'
1538 if (token == TokenNameAND) {
1541 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1542 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1543 if (Scanner.isIdentifierOrKeyword(token)) {
1544 methodDecl.selector = scanner.getCurrentIdentifierSource();
1545 if (token > TokenNameKEYWORD) {
1546 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1547 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1548 // reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
1549 // scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1552 if (token == TokenNameLPAREN) {
1555 throwSyntaxError("'(' expected in function declaration.");
1557 if (token != TokenNameRPAREN) {
1560 if (token != TokenNameRPAREN) {
1561 throwSyntaxError("')' expected in function declaration.");
1563 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1567 methodDecl.selector = "<undefined>".toCharArray();
1568 throwSyntaxError("Function name expected after keyword 'function'.");
1573 private void parameter_list() {
1574 // non_empty_parameter_list
1576 non_empty_parameter_list(true);
1579 private void non_empty_parameter_list(boolean empty_allowed) {
1580 // optional_class_type T_VARIABLE
1581 // | optional_class_type '&' T_VARIABLE
1582 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1583 // | optional_class_type T_VARIABLE '=' static_scalar
1584 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1585 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1586 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1588 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1590 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1592 if (token == TokenNameIdentifier) {
1595 if (token == TokenNameAND) {
1598 if (token == TokenNameVariable) {
1600 if (token == TokenNameEQUAL) {
1605 throwSyntaxError("Variable expected in parameter list.");
1607 if (token != TokenNameCOMMA) {
1614 if (!empty_allowed) {
1615 throwSyntaxError("Identifier expected in parameter list.");
1619 private void optional_class_type() {
1624 private void parameterDeclaration() {
1626 //variable-reference
1627 if (token == TokenNameAND) {
1632 throwSyntaxError("Variable expected after reference operator '&'.");
1635 //variable '=' constant
1636 if (token == TokenNameVariable) {
1638 if (token == TokenNameEQUAL) {
1644 // if (token == TokenNamethis) {
1645 // throwSyntaxError("Reserved word '$this' not allowed in parameter
1650 private void labeledStatementList() {
1651 if (token != TokenNamecase && token != TokenNamedefault) {
1652 throwSyntaxError("'case' or 'default' expected.");
1655 if (token == TokenNamecase) {
1657 expr(); //constant();
1658 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1660 if (token == TokenNamecase || token == TokenNamedefault) {
1661 // empty case statement ?
1666 // else if (token == TokenNameSEMICOLON) {
1668 // "':' expected after 'case' keyword (Found token: " +
1669 // scanner.toStringAction(token) + ")",
1670 // scanner.getCurrentTokenStartPosition(),
1671 // scanner.getCurrentTokenEndPosition(),
1674 // if (token == TokenNamecase) { // empty case statement ?
1680 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1682 } else { // TokenNamedefault
1684 if (token == TokenNameCOLON) {
1686 if (token == TokenNameRBRACE) {
1687 // empty default case
1690 if (token != TokenNamecase) {
1694 throwSyntaxError("':' character expected after 'default'.");
1697 } while (token == TokenNamecase || token == TokenNamedefault);
1700 // public void labeledStatement() {
1701 // if (token == TokenNamecase) {
1704 // if (token == TokenNameDDOT) {
1708 // throwSyntaxError("':' character after 'case' constant expected.");
1711 // } else if (token == TokenNamedefault) {
1713 // if (token == TokenNameDDOT) {
1717 // throwSyntaxError("':' character after 'default' expected.");
1722 // public void expressionStatement() {
1724 // private void inclusionStatement() {
1726 // public void compoundStatement() {
1728 // public void selectionStatement() {
1731 // public void iterationStatement() {
1734 // public void jumpStatement() {
1737 // public void outputStatement() {
1740 // public void scopeStatement() {
1743 // public void flowStatement() {
1746 // public void definitionStatement() {
1748 private void ifStatement() {
1749 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1750 if (token == TokenNameCOLON) {
1752 if (token != TokenNameendif) {
1757 if (token == TokenNameCOLON) {
1759 if (token != TokenNameendif) {
1763 if (token == TokenNameif) { //'else if'
1765 elseifStatementList();
1767 throwSyntaxError("':' expected after 'else'.");
1771 case TokenNameelseif:
1773 elseifStatementList();
1777 if (token != TokenNameendif) {
1778 throwSyntaxError("'endif' expected.");
1781 if (token != TokenNameSEMICOLON) {
1782 throwSyntaxError("';' expected after if-statement.");
1786 // statement [else-statement]
1787 statement(TokenNameEOF);
1788 if (token == TokenNameelseif) {
1790 if (token == TokenNameLPAREN) {
1793 throwSyntaxError("'(' expected after 'elseif' keyword.");
1796 if (token == TokenNameRPAREN) {
1799 throwSyntaxError("')' expected after 'elseif' condition.");
1802 } else if (token == TokenNameelse) {
1804 statement(TokenNameEOF);
1809 private void elseifStatementList() {
1815 if (token == TokenNameCOLON) {
1817 if (token != TokenNameendif) {
1822 if (token == TokenNameif) { //'else if'
1825 throwSyntaxError("':' expected after 'else'.");
1829 case TokenNameelseif:
1838 private void elseifStatement() {
1839 if (token == TokenNameLPAREN) {
1842 if (token != TokenNameRPAREN) {
1843 throwSyntaxError("')' expected in else-if-statement.");
1846 if (token != TokenNameCOLON) {
1847 throwSyntaxError("':' expected in else-if-statement.");
1850 if (token != TokenNameendif) {
1856 private void switchStatement() {
1857 if (token == TokenNameCOLON) {
1858 // ':' [labeled-statement-list] 'endswitch' ';'
1860 labeledStatementList();
1861 if (token != TokenNameendswitch) {
1862 throwSyntaxError("'endswitch' expected.");
1865 if (token != TokenNameSEMICOLON) {
1866 throwSyntaxError("';' expected after switch-statement.");
1870 // '{' [labeled-statement-list] '}'
1871 if (token != TokenNameLBRACE) {
1872 throwSyntaxError("'{' expected in switch statement.");
1875 if (token != TokenNameRBRACE) {
1876 labeledStatementList();
1878 if (token != TokenNameRBRACE) {
1879 throwSyntaxError("'}' expected in switch statement.");
1885 private void forStatement() {
1886 if (token == TokenNameCOLON) {
1889 if (token != TokenNameendfor) {
1890 throwSyntaxError("'endfor' expected.");
1893 if (token != TokenNameSEMICOLON) {
1894 throwSyntaxError("';' expected after for-statement.");
1898 statement(TokenNameEOF);
1902 private void whileStatement() {
1903 // ':' statement-list 'endwhile' ';'
1904 if (token == TokenNameCOLON) {
1907 if (token != TokenNameendwhile) {
1908 throwSyntaxError("'endwhile' expected.");
1911 if (token != TokenNameSEMICOLON) {
1912 throwSyntaxError("';' expected after while-statement.");
1916 statement(TokenNameEOF);
1920 private void foreachStatement() {
1921 if (token == TokenNameCOLON) {
1924 if (token != TokenNameendforeach) {
1925 throwSyntaxError("'endforeach' expected.");
1928 if (token != TokenNameSEMICOLON) {
1929 throwSyntaxError("';' expected after foreach-statement.");
1933 statement(TokenNameEOF);
1937 // private void exitStatus() {
1938 // if (token == TokenNameLPAREN) {
1941 // throwSyntaxError("'(' expected in 'exit-status'.");
1943 // if (token != TokenNameRPAREN) {
1946 // if (token == TokenNameRPAREN) {
1949 // throwSyntaxError("')' expected after 'exit-status'.");
1952 private void expressionList() {
1955 if (token == TokenNameCOMMA) {
1963 private Expression expr() {
1965 // | expr_without_variable
1966 // if (token!=TokenNameEOF) {
1967 if (Scanner.TRACE) {
1968 System.out.println("TRACE: expr()");
1970 return expr_without_variable(true);
1974 private Expression expr_without_variable(boolean only_variable) {
1975 int exprSourceStart = scanner.getCurrentTokenStartPosition();
1976 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
1977 Expression expression = new Expression();
1978 expression.sourceStart = exprSourceStart;
1979 // default, may be overwritten
1980 expression.sourceEnd = exprSourceEnd;
1981 // internal_functions_in_yacc
1990 // | T_INC rw_variable
1991 // | T_DEC rw_variable
1992 // | T_INT_CAST expr
1993 // | T_DOUBLE_CAST expr
1994 // | T_STRING_CAST expr
1995 // | T_ARRAY_CAST expr
1996 // | T_OBJECT_CAST expr
1997 // | T_BOOL_CAST expr
1998 // | T_UNSET_CAST expr
1999 // | T_EXIT exit_expr
2001 // | T_ARRAY '(' array_pair_list ')'
2002 // | '`' encaps_list '`'
2003 // | T_LIST '(' assignment_list ')' '=' expr
2004 // | T_NEW class_name_reference ctor_arguments
2005 // | variable '=' expr
2006 // | variable '=' '&' variable
2007 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2008 // | variable T_PLUS_EQUAL expr
2009 // | variable T_MINUS_EQUAL expr
2010 // | variable T_MUL_EQUAL expr
2011 // | variable T_DIV_EQUAL expr
2012 // | variable T_CONCAT_EQUAL expr
2013 // | variable T_MOD_EQUAL expr
2014 // | variable T_AND_EQUAL expr
2015 // | variable T_OR_EQUAL expr
2016 // | variable T_XOR_EQUAL expr
2017 // | variable T_SL_EQUAL expr
2018 // | variable T_SR_EQUAL expr
2019 // | rw_variable T_INC
2020 // | rw_variable T_DEC
2021 // | expr T_BOOLEAN_OR expr
2022 // | expr T_BOOLEAN_AND expr
2023 // | expr T_LOGICAL_OR expr
2024 // | expr T_LOGICAL_AND expr
2025 // | expr T_LOGICAL_XOR expr
2037 // | expr T_IS_IDENTICAL expr
2038 // | expr T_IS_NOT_IDENTICAL expr
2039 // | expr T_IS_EQUAL expr
2040 // | expr T_IS_NOT_EQUAL expr
2042 // | expr T_IS_SMALLER_OR_EQUAL expr
2044 // | expr T_IS_GREATER_OR_EQUAL expr
2045 // | expr T_INSTANCEOF class_name_reference
2046 // | expr '?' expr ':' expr
2047 if (Scanner.TRACE) {
2048 System.out.println("TRACE: expr_without_variable() PART 1");
2051 case TokenNameisset:
2052 case TokenNameempty:
2054 case TokenNameinclude:
2055 case TokenNameinclude_once:
2056 case TokenNamerequire:
2057 case TokenNamerequire_once:
2058 internal_functions_in_yacc();
2061 case TokenNameLPAREN:
2064 if (token == TokenNameRPAREN) {
2067 throwSyntaxError("')' expected in expression.");
2077 // | T_INT_CAST expr
2078 // | T_DOUBLE_CAST expr
2079 // | T_STRING_CAST expr
2080 // | T_ARRAY_CAST expr
2081 // | T_OBJECT_CAST expr
2082 // | T_BOOL_CAST expr
2083 // | T_UNSET_CAST expr
2084 case TokenNameclone:
2085 case TokenNameprint:
2088 case TokenNameMINUS:
2090 case TokenNameTWIDDLE:
2091 case TokenNameintCAST:
2092 case TokenNamedoubleCAST:
2093 case TokenNamestringCAST:
2094 case TokenNamearrayCAST:
2095 case TokenNameobjectCAST:
2096 case TokenNameboolCAST:
2097 case TokenNameunsetCAST:
2107 //| T_STRING_VARNAME
2109 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2110 // | '`' encaps_list '`'
2112 // | '`' encaps_list '`'
2113 case TokenNameEncapsedString0:
2114 scanner.encapsedStringStack.push(new Character('`'));
2117 if (token == TokenNameEncapsedString0) {
2120 if (token != TokenNameEncapsedString0) {
2121 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2125 scanner.encapsedStringStack.pop();
2129 // | '\'' encaps_list '\''
2130 case TokenNameEncapsedString1:
2131 scanner.encapsedStringStack.push(new Character('\''));
2134 exprSourceStart = scanner.getCurrentTokenStartPosition();
2135 if (token == TokenNameEncapsedString1) {
2136 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2137 .getCurrentTokenEndPosition());
2140 if (token != TokenNameEncapsedString1) {
2141 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2143 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2144 .getCurrentTokenEndPosition());
2148 scanner.encapsedStringStack.pop();
2152 //| '"' encaps_list '"'
2153 case TokenNameEncapsedString2:
2154 scanner.encapsedStringStack.push(new Character('"'));
2157 exprSourceStart = scanner.getCurrentTokenStartPosition();
2158 if (token == TokenNameEncapsedString2) {
2159 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2160 .getCurrentTokenEndPosition());
2163 if (token != TokenNameEncapsedString2) {
2164 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2166 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2167 .getCurrentTokenEndPosition());
2171 scanner.encapsedStringStack.pop();
2175 case TokenNameStringDoubleQuote:
2176 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2177 .getCurrentTokenEndPosition());
2180 case TokenNameStringSingleQuote:
2181 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2182 .getCurrentTokenEndPosition());
2185 case TokenNameIntegerLiteral:
2186 case TokenNameDoubleLiteral:
2187 case TokenNameStringInterpolated:
2190 case TokenNameCLASS_C:
2191 case TokenNameMETHOD_C:
2192 case TokenNameFUNC_C:
2195 case TokenNameHEREDOC:
2198 case TokenNamearray:
2199 // T_ARRAY '(' array_pair_list ')'
2201 if (token == TokenNameLPAREN) {
2203 if (token == TokenNameRPAREN) {
2208 if (token != TokenNameRPAREN) {
2209 throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2213 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2217 // | T_LIST '(' assignment_list ')' '=' expr
2219 if (token == TokenNameLPAREN) {
2222 if (token != TokenNameRPAREN) {
2223 throwSyntaxError("')' expected after 'list' keyword.");
2226 if (token != TokenNameEQUAL) {
2227 throwSyntaxError("'=' expected after 'list' keyword.");
2232 throwSyntaxError("'(' expected after 'list' keyword.");
2236 // | T_NEW class_name_reference ctor_arguments
2238 class_name_reference();
2241 // | T_INC rw_variable
2242 // | T_DEC rw_variable
2243 case TokenNamePLUS_PLUS:
2244 case TokenNameMINUS_MINUS:
2248 // | variable '=' expr
2249 // | variable '=' '&' variable
2250 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2251 // | variable T_PLUS_EQUAL expr
2252 // | variable T_MINUS_EQUAL expr
2253 // | variable T_MUL_EQUAL expr
2254 // | variable T_DIV_EQUAL expr
2255 // | variable T_CONCAT_EQUAL expr
2256 // | variable T_MOD_EQUAL expr
2257 // | variable T_AND_EQUAL expr
2258 // | variable T_OR_EQUAL expr
2259 // | variable T_XOR_EQUAL expr
2260 // | variable T_SL_EQUAL expr
2261 // | variable T_SR_EQUAL expr
2262 // | rw_variable T_INC
2263 // | rw_variable T_DEC
2264 case TokenNameIdentifier:
2265 case TokenNameVariable:
2266 case TokenNameDOLLAR:
2269 case TokenNameEQUAL:
2271 if (token == TokenNameAND) {
2273 if (token == TokenNamenew) {
2274 // | variable '=' '&' T_NEW class_name_reference
2277 class_name_reference();
2286 case TokenNamePLUS_EQUAL:
2287 case TokenNameMINUS_EQUAL:
2288 case TokenNameMULTIPLY_EQUAL:
2289 case TokenNameDIVIDE_EQUAL:
2290 case TokenNameDOT_EQUAL:
2291 case TokenNameREMAINDER_EQUAL:
2292 case TokenNameAND_EQUAL:
2293 case TokenNameOR_EQUAL:
2294 case TokenNameXOR_EQUAL:
2295 case TokenNameRIGHT_SHIFT_EQUAL:
2296 case TokenNameLEFT_SHIFT_EQUAL:
2300 case TokenNamePLUS_PLUS:
2301 case TokenNameMINUS_MINUS:
2305 if (!only_variable) {
2306 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2311 if (token != TokenNameINLINE_HTML) {
2312 if (token > TokenNameKEYWORD) {
2316 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2321 if (Scanner.TRACE) {
2322 System.out.println("TRACE: expr_without_variable() PART 2");
2324 // | expr T_BOOLEAN_OR expr
2325 // | expr T_BOOLEAN_AND expr
2326 // | expr T_LOGICAL_OR expr
2327 // | expr T_LOGICAL_AND expr
2328 // | expr T_LOGICAL_XOR expr
2340 // | expr T_IS_IDENTICAL expr
2341 // | expr T_IS_NOT_IDENTICAL expr
2342 // | expr T_IS_EQUAL expr
2343 // | expr T_IS_NOT_EQUAL expr
2345 // | expr T_IS_SMALLER_OR_EQUAL expr
2347 // | expr T_IS_GREATER_OR_EQUAL expr
2350 case TokenNameOR_OR:
2352 expression = new OR_OR_Expression(expression, expr(), token);
2354 case TokenNameAND_AND:
2356 expression = new AND_AND_Expression(expression, expr(), token);
2358 case TokenNameEQUAL_EQUAL:
2360 expression = new EqualExpression(expression, expr(), token);
2370 case TokenNameMINUS:
2371 case TokenNameMULTIPLY:
2372 case TokenNameDIVIDE:
2373 case TokenNameREMAINDER:
2374 case TokenNameLEFT_SHIFT:
2375 case TokenNameRIGHT_SHIFT:
2376 case TokenNameEQUAL_EQUAL_EQUAL:
2377 case TokenNameNOT_EQUAL_EQUAL:
2378 case TokenNameNOT_EQUAL:
2380 case TokenNameLESS_EQUAL:
2381 case TokenNameGREATER:
2382 case TokenNameGREATER_EQUAL:
2384 expression = new BinaryExpression(expression, expr(), token);
2386 // | expr T_INSTANCEOF class_name_reference
2387 // | expr '?' expr ':' expr
2388 case TokenNameinstanceof:
2390 class_name_reference();
2391 // TODO use InstanceofExpression
2392 expression = new Expression();
2393 expression.sourceStart = exprSourceStart;
2394 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2396 case TokenNameQUESTION:
2398 Expression valueIfTrue = expr();
2399 if (token != TokenNameCOLON) {
2400 throwSyntaxError("':' expected in conditional expression.");
2403 Expression valueIfFalse = expr();
2405 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2413 private void class_name_reference() {
2414 // class_name_reference:
2416 //| dynamic_class_name_reference
2417 if (Scanner.TRACE) {
2418 System.out.println("TRACE: class_name_reference()");
2420 if (token == TokenNameIdentifier) {
2423 dynamic_class_name_reference();
2427 private void dynamic_class_name_reference() {
2428 //dynamic_class_name_reference:
2429 // base_variable T_OBJECT_OPERATOR object_property
2430 // dynamic_class_name_variable_properties
2432 if (Scanner.TRACE) {
2433 System.out.println("TRACE: dynamic_class_name_reference()");
2436 if (token == TokenNameMINUS_GREATER) {
2439 dynamic_class_name_variable_properties();
2443 private void dynamic_class_name_variable_properties() {
2444 // dynamic_class_name_variable_properties:
2445 // dynamic_class_name_variable_properties
2446 // dynamic_class_name_variable_property
2448 if (Scanner.TRACE) {
2449 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2451 while (token == TokenNameMINUS_GREATER) {
2452 dynamic_class_name_variable_property();
2456 private void dynamic_class_name_variable_property() {
2457 // dynamic_class_name_variable_property:
2458 // T_OBJECT_OPERATOR object_property
2459 if (Scanner.TRACE) {
2460 System.out.println("TRACE: dynamic_class_name_variable_property()");
2462 if (token == TokenNameMINUS_GREATER) {
2468 private void ctor_arguments() {
2471 //| '(' function_call_parameter_list ')'
2472 if (token == TokenNameLPAREN) {
2474 if (token == TokenNameRPAREN) {
2478 non_empty_function_call_parameter_list();
2479 if (token != TokenNameRPAREN) {
2480 throwSyntaxError("')' expected in ctor_arguments.");
2486 private void assignment_list() {
2488 // assignment_list ',' assignment_list_element
2489 //| assignment_list_element
2491 assignment_list_element();
2492 if (token != TokenNameCOMMA) {
2499 private void assignment_list_element() {
2500 //assignment_list_element:
2502 //| T_LIST '(' assignment_list ')'
2504 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2507 if (token == TokenNamelist) {
2509 if (token == TokenNameLPAREN) {
2512 if (token != TokenNameRPAREN) {
2513 throwSyntaxError("')' expected after 'list' keyword.");
2517 throwSyntaxError("'(' expected after 'list' keyword.");
2523 private void array_pair_list() {
2526 //| non_empty_array_pair_list possible_comma
2527 non_empty_array_pair_list();
2528 if (token == TokenNameCOMMA) {
2533 private void non_empty_array_pair_list() {
2534 //non_empty_array_pair_list:
2535 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2536 //| non_empty_array_pair_list ',' expr
2537 //| expr T_DOUBLE_ARROW expr
2539 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2540 //| non_empty_array_pair_list ',' '&' w_variable
2541 //| expr T_DOUBLE_ARROW '&' w_variable
2544 if (token == TokenNameAND) {
2549 if (token == TokenNameAND) {
2552 } else if (token == TokenNameEQUAL_GREATER) {
2554 if (token == TokenNameAND) {
2562 if (token != TokenNameCOMMA) {
2566 if (token == TokenNameRPAREN) {
2572 // private void variableList() {
2575 // if (token == TokenNameCOMMA) {
2582 private void variable_without_objects() {
2583 // variable_without_objects:
2584 // reference_variable
2585 // | simple_indirect_reference reference_variable
2586 if (Scanner.TRACE) {
2587 System.out.println("TRACE: variable_without_objects()");
2589 while (token == TokenNameDOLLAR) {
2592 reference_variable();
2595 private void function_call() {
2597 // T_STRING '(' function_call_parameter_list ')'
2598 //| class_constant '(' function_call_parameter_list ')'
2599 //| static_member '(' function_call_parameter_list ')'
2600 //| variable_without_objects '(' function_call_parameter_list ')'
2601 char[] defineName = null;
2602 char[] ident = null;
2605 if (Scanner.TRACE) {
2606 System.out.println("TRACE: function_call()");
2608 if (token == TokenNameIdentifier) {
2609 ident = scanner.getCurrentIdentifierSource();
2611 startPos = scanner.getCurrentTokenStartPosition();
2612 endPos = scanner.getCurrentTokenEndPosition();
2615 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2619 if (token == TokenNameIdentifier) {
2624 variable_without_objects();
2629 variable_without_objects();
2631 if (token != TokenNameLPAREN) {
2632 if (defineName != null) {
2633 // does this identifier contain only uppercase characters?
2634 if (defineName.length == 3) {
2635 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2638 } else if (defineName.length == 4) {
2639 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2641 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2644 } else if (defineName.length == 5) {
2645 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2649 if (defineName != null) {
2650 for (int i = 0; i < defineName.length; i++) {
2651 if (Character.isLowerCase(defineName[i])) {
2652 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2658 // TODO is this ok ?
2660 // throwSyntaxError("'(' expected in function call.");
2663 if (token == TokenNameRPAREN) {
2667 non_empty_function_call_parameter_list();
2668 if (token != TokenNameRPAREN) {
2669 String functionName;
2670 if (ident == null) {
2671 functionName = new String(" ");
2673 functionName = new String(ident);
2675 throwSyntaxError("')' expected in function call (" + functionName + ").");
2680 // private void function_call_parameter_list() {
2681 // function_call_parameter_list:
2682 // non_empty_function_call_parameter_list { $$ = $1; }
2685 private void non_empty_function_call_parameter_list() {
2686 //non_empty_function_call_parameter_list:
2687 // expr_without_variable
2690 // | non_empty_function_call_parameter_list ',' expr_without_variable
2691 // | non_empty_function_call_parameter_list ',' variable
2692 // | non_empty_function_call_parameter_list ',' '&' w_variable
2693 if (Scanner.TRACE) {
2694 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2697 if (token == TokenNameAND) {
2701 // if (token == TokenNameIdentifier || token ==
2702 // TokenNameVariable
2703 // || token == TokenNameDOLLAR) {
2706 expr_without_variable(true);
2709 if (token != TokenNameCOMMA) {
2716 private void fully_qualified_class_name() {
2717 if (token == TokenNameIdentifier) {
2720 throwSyntaxError("Class name expected.");
2724 private void static_member() {
2726 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2727 // variable_without_objects
2728 if (Scanner.TRACE) {
2729 System.out.println("TRACE: static_member()");
2731 fully_qualified_class_name();
2732 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2733 throwSyntaxError("'::' expected after class name (static_member).");
2736 variable_without_objects();
2739 private void base_variable_with_function_calls() {
2740 // base_variable_with_function_calls:
2743 boolean functionCall = false;
2744 if (Scanner.TRACE) {
2745 System.out.println("TRACE: base_variable_with_function_calls()");
2747 // if (token == TokenNameIdentifier) {
2748 // functionCall = true;
2749 // } else if (token == TokenNameVariable) {
2750 // int tempToken = token;
2751 // int tempPosition = scanner.currentPosition;
2753 // if (token == TokenNameLPAREN) {
2754 // functionCall = true;
2756 // token = tempToken;
2757 // scanner.currentPosition = tempPosition;
2758 // scanner.phpMode = true;
2760 // if (functionCall) {
2767 private void base_variable() {
2769 // reference_variable
2770 // | simple_indirect_reference reference_variable
2772 if (Scanner.TRACE) {
2773 System.out.println("TRACE: base_variable()");
2775 if (token == TokenNameIdentifier) {
2778 while (token == TokenNameDOLLAR) {
2781 reference_variable();
2785 // private void simple_indirect_reference() {
2786 // // simple_indirect_reference:
2788 // //| simple_indirect_reference '$'
2790 private void reference_variable() {
2791 // reference_variable:
2792 // reference_variable '[' dim_offset ']'
2793 // | reference_variable '{' expr '}'
2794 // | compound_variable
2795 if (Scanner.TRACE) {
2796 System.out.println("TRACE: reference_variable()");
2798 compound_variable();
2800 if (token == TokenNameLBRACE) {
2803 if (token != TokenNameRBRACE) {
2804 throwSyntaxError("'}' expected in reference variable.");
2807 } else if (token == TokenNameLBRACKET) {
2809 if (token != TokenNameRBRACKET) {
2812 if (token != TokenNameRBRACKET) {
2813 throwSyntaxError("']' expected in reference variable.");
2823 private void compound_variable() {
2824 // compound_variable:
2826 // | '$' '{' expr '}'
2827 if (Scanner.TRACE) {
2828 System.out.println("TRACE: compound_variable()");
2830 if (token == TokenNameVariable) {
2833 // because of simple_indirect_reference
2834 while (token == TokenNameDOLLAR) {
2837 if (token != TokenNameLBRACE) {
2838 throwSyntaxError("'{' expected after compound variable token '$'.");
2842 if (token != TokenNameRBRACE) {
2843 throwSyntaxError("'}' expected after compound variable token '$'.");
2849 // private void dim_offset() {
2855 private void object_property() {
2858 //| variable_without_objects
2859 if (Scanner.TRACE) {
2860 System.out.println("TRACE: object_property()");
2862 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2863 variable_without_objects();
2869 private void object_dim_list() {
2871 // object_dim_list '[' dim_offset ']'
2872 //| object_dim_list '{' expr '}'
2874 if (Scanner.TRACE) {
2875 System.out.println("TRACE: object_dim_list()");
2879 if (token == TokenNameLBRACE) {
2882 if (token != TokenNameRBRACE) {
2883 throwSyntaxError("'}' expected in object_dim_list.");
2886 } else if (token == TokenNameLBRACKET) {
2888 if (token == TokenNameRBRACKET) {
2893 if (token != TokenNameRBRACKET) {
2894 throwSyntaxError("']' expected in object_dim_list.");
2903 private void variable_name() {
2907 if (Scanner.TRACE) {
2908 System.out.println("TRACE: variable_name()");
2910 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2911 if (token > TokenNameKEYWORD) {
2912 // TODO show a warning "Keyword used as variable" ?
2916 if (token != TokenNameLBRACE) {
2917 throwSyntaxError("'{' expected in variable name.");
2921 if (token != TokenNameRBRACE) {
2922 throwSyntaxError("'}' expected in variable name.");
2928 private void r_variable() {
2932 private void w_variable() {
2936 private void rw_variable() {
2940 private void variable() {
2942 // base_variable_with_function_calls T_OBJECT_OPERATOR
2943 // object_property method_or_not variable_properties
2944 // | base_variable_with_function_calls
2945 base_variable_with_function_calls();
2946 if (token == TokenNameMINUS_GREATER) {
2950 variable_properties();
2952 // if (token == TokenNameDOLLAR_LBRACE) {
2956 // if (token != TokenNameRBRACE) {
2957 // throwSyntaxError("'}' expected after indirect variable token '${'.");
2961 // if (token == TokenNameVariable) {
2963 // if (token == TokenNameLBRACKET) {
2966 // if (token != TokenNameRBRACKET) {
2967 // throwSyntaxError("']' expected in variable-list.");
2970 // } else if (token == TokenNameEQUAL) {
2975 // throwSyntaxError("$-variable expected in variable-list.");
2980 private void variable_properties() {
2981 // variable_properties:
2982 // variable_properties variable_property
2984 while (token == TokenNameMINUS_GREATER) {
2985 variable_property();
2989 private void variable_property() {
2990 // variable_property:
2991 // T_OBJECT_OPERATOR object_property method_or_not
2992 if (Scanner.TRACE) {
2993 System.out.println("TRACE: variable_property()");
2995 if (token == TokenNameMINUS_GREATER) {
3000 throwSyntaxError("'->' expected in variable_property.");
3004 private void method_or_not() {
3006 // '(' function_call_parameter_list ')'
3008 if (Scanner.TRACE) {
3009 System.out.println("TRACE: method_or_not()");
3011 if (token == TokenNameLPAREN) {
3013 if (token == TokenNameRPAREN) {
3017 non_empty_function_call_parameter_list();
3018 if (token != TokenNameRPAREN) {
3019 throwSyntaxError("')' expected in method_or_not.");
3025 private void exit_expr() {
3029 if (token != TokenNameLPAREN) {
3033 if (token == TokenNameRPAREN) {
3038 if (token != TokenNameRPAREN) {
3039 throwSyntaxError("')' expected after keyword 'exit'");
3044 private void encaps_list() {
3045 // encaps_list encaps_var
3046 // | encaps_list T_STRING
3047 // | encaps_list T_NUM_STRING
3048 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3049 // | encaps_list T_CHARACTER
3050 // | encaps_list T_BAD_CHARACTER
3051 // | encaps_list '['
3052 // | encaps_list ']'
3053 // | encaps_list '{'
3054 // | encaps_list '}'
3055 // | encaps_list T_OBJECT_OPERATOR
3059 case TokenNameSTRING:
3062 case TokenNameLBRACE:
3063 // scanner.encapsedStringStack.pop();
3066 case TokenNameRBRACE:
3067 // scanner.encapsedStringStack.pop();
3070 case TokenNameLBRACKET:
3071 // scanner.encapsedStringStack.pop();
3074 case TokenNameRBRACKET:
3075 // scanner.encapsedStringStack.pop();
3078 case TokenNameMINUS_GREATER:
3079 // scanner.encapsedStringStack.pop();
3082 case TokenNameVariable:
3083 case TokenNameDOLLAR_LBRACE:
3084 case TokenNameLBRACE_DOLLAR:
3088 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3089 if (encapsedChar == '$') {
3090 scanner.encapsedStringStack.pop();
3091 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3092 switch (encapsedChar) {
3094 if (token == TokenNameEncapsedString0) {
3097 token = TokenNameSTRING;
3100 if (token == TokenNameEncapsedString1) {
3103 token = TokenNameSTRING;
3106 if (token == TokenNameEncapsedString2) {
3109 token = TokenNameSTRING;
3118 private void encaps_var() {
3120 // | T_VARIABLE '[' encaps_var_offset ']'
3121 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3122 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3123 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3124 // | T_CURLY_OPEN variable '}'
3126 case TokenNameVariable:
3128 if (token == TokenNameLBRACKET) {
3130 expr(); //encaps_var_offset();
3131 if (token != TokenNameRBRACKET) {
3132 throwSyntaxError("']' expected after variable.");
3134 // scanner.encapsedStringStack.pop();
3137 } else if (token == TokenNameMINUS_GREATER) {
3139 if (token != TokenNameIdentifier) {
3140 throwSyntaxError("Identifier expected after '->'.");
3142 // scanner.encapsedStringStack.pop();
3146 // // scanner.encapsedStringStack.pop();
3147 // int tempToken = TokenNameSTRING;
3148 // if (!scanner.encapsedStringStack.isEmpty()
3149 // && (token == TokenNameEncapsedString0
3150 // || token == TokenNameEncapsedString1
3151 // || token == TokenNameEncapsedString2 || token ==
3152 // TokenNameERROR)) {
3153 // char encapsedChar = ((Character)
3154 // scanner.encapsedStringStack.peek())
3157 // case TokenNameEncapsedString0 :
3158 // if (encapsedChar == '`') {
3159 // tempToken = TokenNameEncapsedString0;
3162 // case TokenNameEncapsedString1 :
3163 // if (encapsedChar == '\'') {
3164 // tempToken = TokenNameEncapsedString1;
3167 // case TokenNameEncapsedString2 :
3168 // if (encapsedChar == '"') {
3169 // tempToken = TokenNameEncapsedString2;
3172 // case TokenNameERROR :
3173 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3174 // scanner.currentPosition--;
3180 // token = tempToken;
3183 case TokenNameDOLLAR_LBRACE:
3185 if (token == TokenNameDOLLAR_LBRACE) {
3187 } else if (token == TokenNameIdentifier) {
3189 if (token == TokenNameLBRACKET) {
3191 // if (token == TokenNameRBRACKET) {
3195 if (token != TokenNameRBRACKET) {
3196 throwSyntaxError("']' expected after '${'.");
3204 if (token != TokenNameRBRACE) {
3205 throwSyntaxError("'}' expected.");
3209 case TokenNameLBRACE_DOLLAR:
3211 if (token == TokenNameLBRACE_DOLLAR) {
3213 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3215 if (token == TokenNameLBRACKET) {
3217 // if (token == TokenNameRBRACKET) {
3221 if (token != TokenNameRBRACKET) {
3222 throwSyntaxError("']' expected.");
3226 } else if (token == TokenNameMINUS_GREATER) {
3228 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3229 throwSyntaxError("String or Variable token expected.");
3232 if (token == TokenNameLBRACKET) {
3234 // if (token == TokenNameRBRACKET) {
3238 if (token != TokenNameRBRACKET) {
3239 throwSyntaxError("']' expected after '${'.");
3245 // if (token != TokenNameRBRACE) {
3246 // throwSyntaxError("'}' expected after '{$'.");
3248 // // scanner.encapsedStringStack.pop();
3252 if (token != TokenNameRBRACE) {
3253 throwSyntaxError("'}' expected.");
3255 // scanner.encapsedStringStack.pop();
3262 private void encaps_var_offset() {
3267 case TokenNameSTRING:
3270 case TokenNameIntegerLiteral:
3273 case TokenNameVariable:
3276 case TokenNameIdentifier:
3280 throwSyntaxError("Variable or String token expected.");
3285 private void internal_functions_in_yacc() {
3287 ImportReference impt = null;
3289 case TokenNameisset:
3290 // T_ISSET '(' isset_variables ')'
3292 if (token != TokenNameLPAREN) {
3293 throwSyntaxError("'(' expected after keyword 'isset'");
3297 if (token != TokenNameRPAREN) {
3298 throwSyntaxError("')' expected after keyword 'isset'");
3302 case TokenNameempty:
3303 // T_EMPTY '(' variable ')'
3305 if (token != TokenNameLPAREN) {
3306 throwSyntaxError("'(' expected after keyword 'empty'");
3310 if (token != TokenNameRPAREN) {
3311 throwSyntaxError("')' expected after keyword 'empty'");
3315 case TokenNameinclude:
3317 checkFileName(token, impt);
3319 case TokenNameinclude_once:
3320 // T_INCLUDE_ONCE expr
3321 checkFileName(token, impt);
3324 // T_EVAL '(' expr ')'
3326 if (token != TokenNameLPAREN) {
3327 throwSyntaxError("'(' expected after keyword 'eval'");
3331 if (token != TokenNameRPAREN) {
3332 throwSyntaxError("')' expected after keyword 'eval'");
3336 case TokenNamerequire:
3338 checkFileName(token, impt);
3340 case TokenNamerequire_once:
3341 // T_REQUIRE_ONCE expr
3342 checkFileName(token, impt);
3347 private void checkFileName(int includeToken, ImportReference impt) {
3348 //<include-token> expr
3349 int start = scanner.getCurrentTokenStartPosition();
3350 boolean hasLPAREN = false;
3352 if (token == TokenNameLPAREN) {
3356 Expression expression = expr();
3358 if (token == TokenNameRPAREN) {
3361 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3364 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3365 impt.declarationSourceEnd = impt.sourceEnd;
3366 impt.declarationEnd = impt.declarationSourceEnd;
3367 //endPosition is just before the ;
3368 impt.declarationSourceStart = start;
3369 includesList.add(impt);
3371 if (expression instanceof StringLiteral) {
3372 StringLiteral literal = (StringLiteral) expression;
3373 char[] includeName = literal.source();
3374 if (includeName.length == 0) {
3375 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3376 literal.sourceStart + 1);
3378 String includeNameString = new String(includeName);
3379 if (literal instanceof StringLiteralDQ) {
3380 if (includeNameString.indexOf('$') >= 0) {
3381 // assuming that the filename contains a variable => no filename check
3385 if (includeNameString.startsWith("http://")) {
3386 // assuming external include location
3389 if (scanner.compilationUnit != null) {
3390 IResource resource = scanner.compilationUnit.getResource();
3391 // java.io.File f = new java.io.File(new String(compilationUnit.getFileName()));
3392 // System.out.println(expression.toStringExpression());
3394 if (resource != null && resource instanceof IFile) {
3395 // check the filename:
3396 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3397 IProject project = resource.getProject();
3398 if (project != null) {
3399 if (PHPFileUtil.determineFilePath(includeNameString, resource, project) == null) {
3400 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3401 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3402 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3403 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3404 compilationUnit.compilationResult);
3412 private void isset_variables() {
3414 // | isset_variables ','
3415 if (token == TokenNameRPAREN) {
3416 throwSyntaxError("Variable expected after keyword 'isset'");
3420 if (token == TokenNameCOMMA) {
3428 private boolean common_scalar() {
3432 // | T_CONSTANT_ENCAPSED_STRING
3439 case TokenNameIntegerLiteral:
3442 case TokenNameDoubleLiteral:
3445 case TokenNameStringDoubleQuote:
3448 case TokenNameStringSingleQuote:
3451 case TokenNameStringInterpolated:
3460 case TokenNameCLASS_C:
3463 case TokenNameMETHOD_C:
3466 case TokenNameFUNC_C:
3473 private void scalar() {
3476 //| T_STRING_VARNAME
3479 //| '"' encaps_list '"'
3480 //| '\'' encaps_list '\''
3481 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3482 throwSyntaxError("Not yet implemented (scalar).");
3485 private void static_scalar() {
3486 // static_scalar: /* compile-time evaluated scalars */
3489 // | '+' static_scalar
3490 // | '-' static_scalar
3491 // | T_ARRAY '(' static_array_pair_list ')'
3492 // | static_class_constant
3493 if (common_scalar()) {
3497 case TokenNameIdentifier:
3499 // static_class_constant:
3500 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3501 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3503 if (token == TokenNameIdentifier) {
3506 throwSyntaxError("Identifier expected after '::' operator.");
3510 case TokenNameEncapsedString0:
3512 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3513 while (scanner.currentCharacter != '`') {
3514 if (scanner.currentCharacter == '\\') {
3515 scanner.currentPosition++;
3517 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3520 } catch (IndexOutOfBoundsException e) {
3521 throwSyntaxError("'`' expected at end of static string.");
3524 case TokenNameEncapsedString1:
3526 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3527 while (scanner.currentCharacter != '\'') {
3528 if (scanner.currentCharacter == '\\') {
3529 scanner.currentPosition++;
3531 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3534 } catch (IndexOutOfBoundsException e) {
3535 throwSyntaxError("'\'' expected at end of static string.");
3538 case TokenNameEncapsedString2:
3540 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3541 while (scanner.currentCharacter != '"') {
3542 if (scanner.currentCharacter == '\\') {
3543 scanner.currentPosition++;
3545 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3548 } catch (IndexOutOfBoundsException e) {
3549 throwSyntaxError("'\"' expected at end of static string.");
3556 case TokenNameMINUS:
3560 case TokenNamearray:
3562 if (token != TokenNameLPAREN) {
3563 throwSyntaxError("'(' expected after keyword 'array'");
3566 if (token == TokenNameRPAREN) {
3570 non_empty_static_array_pair_list();
3571 if (token != TokenNameRPAREN) {
3572 throwSyntaxError("')' expected after keyword 'array'");
3576 // case TokenNamenull :
3579 // case TokenNamefalse :
3582 // case TokenNametrue :
3586 throwSyntaxError("Static scalar/constant expected.");
3590 private void non_empty_static_array_pair_list() {
3591 // non_empty_static_array_pair_list:
3592 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3594 //| non_empty_static_array_pair_list ',' static_scalar
3595 //| static_scalar T_DOUBLE_ARROW static_scalar
3599 if (token == TokenNameEQUAL_GREATER) {
3603 if (token != TokenNameCOMMA) {
3607 if (token == TokenNameRPAREN) {
3613 public void reportSyntaxError() { //int act, int currentKind, int
3615 /* remember current scanner position */
3616 int startPos = scanner.startPosition;
3617 int currentPos = scanner.currentPosition;
3618 // String[] expectings;
3619 // String tokenName = name[symbol_index[currentKind]];
3620 //fetch all "accurate" possible terminals that could recover the error
3621 // int start, end = start = asi(stack[stateStackTop]);
3622 // while (asr[end] != 0)
3624 // int length = end - start;
3625 // expectings = new String[length];
3626 // if (length != 0) {
3627 // char[] indexes = new char[length];
3628 // System.arraycopy(asr, start, indexes, 0, length);
3629 // for (int i = 0; i < length; i++) {
3630 // expectings[i] = name[symbol_index[indexes[i]]];
3633 //if the pb is an EOF, try to tell the user that they are some
3634 // if (tokenName.equals(UNEXPECTED_EOF)) {
3635 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3636 // char[] tokenSource;
3638 // tokenSource = this.scanner.getCurrentTokenSource();
3639 // } catch (Exception e) {
3640 // tokenSource = new char[] {};
3642 // problemReporter().parseError(
3643 // this.scanner.startPosition,
3644 // this.scanner.currentPosition - 1,
3649 // } else { //the next test is HEAVILY grammar DEPENDENT.
3650 // if ((length == 14)
3651 // && (expectings[0] == "=") //$NON-NLS-1$
3652 // && (expectings[1] == "*=") //$NON-NLS-1$
3653 // && (expressionPtr > -1)) {
3654 // switch(currentKind) {
3655 // case TokenNameSEMICOLON:
3656 // case TokenNamePLUS:
3657 // case TokenNameMINUS:
3658 // case TokenNameDIVIDE:
3659 // case TokenNameREMAINDER:
3660 // case TokenNameMULTIPLY:
3661 // case TokenNameLEFT_SHIFT:
3662 // case TokenNameRIGHT_SHIFT:
3663 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3664 // case TokenNameLESS:
3665 // case TokenNameGREATER:
3666 // case TokenNameLESS_EQUAL:
3667 // case TokenNameGREATER_EQUAL:
3668 // case TokenNameEQUAL_EQUAL:
3669 // case TokenNameNOT_EQUAL:
3670 // case TokenNameXOR:
3671 // case TokenNameAND:
3672 // case TokenNameOR:
3673 // case TokenNameOR_OR:
3674 // case TokenNameAND_AND:
3675 // // the ; is not the expected token ==> it ends a statement when an
3676 // expression is not ended
3677 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3679 // case TokenNameRBRACE :
3680 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3683 // char[] tokenSource;
3685 // tokenSource = this.scanner.getCurrentTokenSource();
3686 // } catch (Exception e) {
3687 // tokenSource = new char[] {};
3689 // problemReporter().parseError(
3690 // this.scanner.startPosition,
3691 // this.scanner.currentPosition - 1,
3695 // this.checkAndReportBracketAnomalies(problemReporter());
3700 tokenSource = this.scanner.getCurrentTokenSource();
3701 } catch (Exception e) {
3702 tokenSource = new char[] {};
3704 // problemReporter().parseError(
3705 // this.scanner.startPosition,
3706 // this.scanner.currentPosition - 1,
3710 this.checkAndReportBracketAnomalies(problemReporter());
3713 /* reset scanner where it was */
3714 scanner.startPosition = startPos;
3715 scanner.currentPosition = currentPos;
3718 public static final int RoundBracket = 0;
3720 public static final int SquareBracket = 1;
3722 public static final int CurlyBracket = 2;
3724 public static final int BracketKinds = 3;
3726 protected int[] nestedMethod; //the ptr is nestedType
3728 protected int nestedType, dimensions;
3731 final static int AstStackIncrement = 100;
3733 protected int astPtr;
3735 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
3737 protected int astLengthPtr;
3739 protected int[] astLengthStack;
3741 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
3743 public CompilationUnitDeclaration compilationUnit; /*
3744 * the result from parse()
3747 protected ReferenceContext referenceContext;
3749 protected ProblemReporter problemReporter;
3751 protected CompilerOptions options;
3753 private ArrayList includesList;
3755 // protected CompilationResult compilationResult;
3757 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
3758 * reported, so initializes the compilation result's line positions.
3760 public ProblemReporter problemReporter() {
3761 if (scanner.recordLineSeparator) {
3762 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
3764 problemReporter.referenceContext = referenceContext;
3765 return problemReporter;
3769 * Reconsider the entire source looking for inconsistencies in {} () []
3771 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3772 scanner.wasAcr = false;
3773 boolean anomaliesDetected = false;
3775 char[] source = scanner.source;
3776 int[] leftCount = { 0, 0, 0 };
3777 int[] rightCount = { 0, 0, 0 };
3778 int[] depths = { 0, 0, 0 };
3779 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
3780 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
3781 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
3782 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
3783 scanner.currentPosition = scanner.initialPosition; //starting
3785 // (first-zero-based
3787 while (scanner.currentPosition < scanner.eofPosition) { //loop for
3792 // ---------Consume white space and handles
3793 // startPosition---------
3794 boolean isWhiteSpace;
3796 scanner.startPosition = scanner.currentPosition;
3797 // if (((scanner.currentCharacter =
3798 // source[scanner.currentPosition++]) == '\\') &&
3799 // (source[scanner.currentPosition] == 'u')) {
3800 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3802 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3803 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3804 // only record line positions we have not
3806 scanner.pushLineSeparator();
3809 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3811 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
3812 // -------consume token until } is found---------
3813 switch (scanner.currentCharacter) {
3815 int index = leftCount[CurlyBracket]++;
3816 if (index == leftPositions[CurlyBracket].length) {
3817 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
3818 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
3820 leftPositions[CurlyBracket][index] = scanner.startPosition;
3821 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3825 int index = rightCount[CurlyBracket]++;
3826 if (index == rightPositions[CurlyBracket].length) {
3827 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
3828 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
3830 rightPositions[CurlyBracket][index] = scanner.startPosition;
3831 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3835 int index = leftCount[RoundBracket]++;
3836 if (index == leftPositions[RoundBracket].length) {
3837 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
3838 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
3840 leftPositions[RoundBracket][index] = scanner.startPosition;
3841 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3845 int index = rightCount[RoundBracket]++;
3846 if (index == rightPositions[RoundBracket].length) {
3847 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
3848 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
3850 rightPositions[RoundBracket][index] = scanner.startPosition;
3851 rightDepths[RoundBracket][index] = --depths[RoundBracket];
3855 int index = leftCount[SquareBracket]++;
3856 if (index == leftPositions[SquareBracket].length) {
3857 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
3858 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
3860 leftPositions[SquareBracket][index] = scanner.startPosition;
3861 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3865 int index = rightCount[SquareBracket]++;
3866 if (index == rightPositions[SquareBracket].length) {
3867 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
3868 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
3870 rightPositions[SquareBracket][index] = scanner.startPosition;
3871 rightDepths[SquareBracket][index] = --depths[SquareBracket];
3875 if (scanner.getNextChar('\\')) {
3876 scanner.scanEscapeCharacter();
3877 } else { // consume next character
3878 scanner.unicodeAsBackSlash = false;
3879 // if (((scanner.currentCharacter =
3880 // source[scanner.currentPosition++]) ==
3882 // (source[scanner.currentPosition] ==
3884 // scanner.getNextUnicodeChar();
3886 if (scanner.withoutUnicodePtr != 0) {
3887 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3891 scanner.getNextChar('\'');
3895 // consume next character
3896 scanner.unicodeAsBackSlash = false;
3897 // if (((scanner.currentCharacter =
3898 // source[scanner.currentPosition++]) == '\\') &&
3899 // (source[scanner.currentPosition] == 'u')) {
3900 // scanner.getNextUnicodeChar();
3902 if (scanner.withoutUnicodePtr != 0) {
3903 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3906 while (scanner.currentCharacter != '"') {
3907 if (scanner.currentCharacter == '\r') {
3908 if (source[scanner.currentPosition] == '\n')
3909 scanner.currentPosition++;
3910 break; // the string cannot go further that
3913 if (scanner.currentCharacter == '\n') {
3914 break; // the string cannot go further that
3917 if (scanner.currentCharacter == '\\') {
3918 scanner.scanEscapeCharacter();
3920 // consume next character
3921 scanner.unicodeAsBackSlash = false;
3922 // if (((scanner.currentCharacter =
3923 // source[scanner.currentPosition++]) == '\\')
3924 // && (source[scanner.currentPosition] == 'u'))
3926 // scanner.getNextUnicodeChar();
3928 if (scanner.withoutUnicodePtr != 0) {
3929 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3936 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3939 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3940 && (source[scanner.currentPosition] == 'u')) {
3941 //-------------unicode traitement
3943 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3944 scanner.currentPosition++;
3945 while (source[scanner.currentPosition] == 'u') {
3946 scanner.currentPosition++;
3948 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3949 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3950 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3951 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3955 scanner.currentCharacter = 'A';
3956 } //something different from \n and \r
3958 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3961 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
3963 scanner.startPosition = scanner.currentPosition;
3964 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3965 && (source[scanner.currentPosition] == 'u')) {
3966 //-------------unicode traitement
3968 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3969 scanner.currentPosition++;
3970 while (source[scanner.currentPosition] == 'u') {
3971 scanner.currentPosition++;
3973 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3974 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3975 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3976 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3980 scanner.currentCharacter = 'A';
3981 } //something different from \n
3984 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3988 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3989 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3990 // only record line positions we
3991 // have not recorded yet
3992 scanner.pushLineSeparator();
3993 if (this.scanner.taskTags != null) {
3994 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
3995 .getCurrentTokenEndPosition());
4001 if (test > 0) { //traditional and annotation
4003 boolean star = false;
4004 // consume next character
4005 scanner.unicodeAsBackSlash = false;
4006 // if (((scanner.currentCharacter =
4007 // source[scanner.currentPosition++]) ==
4009 // (source[scanner.currentPosition] ==
4011 // scanner.getNextUnicodeChar();
4013 if (scanner.withoutUnicodePtr != 0) {
4014 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4017 if (scanner.currentCharacter == '*') {
4021 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4022 && (source[scanner.currentPosition] == 'u')) {
4023 //-------------unicode traitement
4025 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4026 scanner.currentPosition++;
4027 while (source[scanner.currentPosition] == 'u') {
4028 scanner.currentPosition++;
4030 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4031 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4032 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4033 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4037 scanner.currentCharacter = 'A';
4038 } //something different from * and /
4040 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4043 //loop until end of comment */
4044 while ((scanner.currentCharacter != '/') || (!star)) {
4045 star = scanner.currentCharacter == '*';
4047 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4048 && (source[scanner.currentPosition] == 'u')) {
4049 //-------------unicode traitement
4051 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4052 scanner.currentPosition++;
4053 while (source[scanner.currentPosition] == 'u') {
4054 scanner.currentPosition++;
4056 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4057 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4058 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4059 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4063 scanner.currentCharacter = 'A';
4064 } //something different from * and
4067 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4071 if (this.scanner.taskTags != null) {
4072 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4079 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4080 scanner.scanIdentifierOrKeyword(false);
4083 if (Character.isDigit(scanner.currentCharacter)) {
4084 scanner.scanNumber(false);
4088 //-----------------end switch while
4089 // try--------------------
4090 } catch (IndexOutOfBoundsException e) {
4091 break; // read until EOF
4092 } catch (InvalidInputException e) {
4093 return false; // no clue
4096 if (scanner.recordLineSeparator) {
4097 // compilationUnit.compilationResult.lineSeparatorPositions =
4098 // scanner.getLineEnds();
4100 // check placement anomalies against other kinds of brackets
4101 for (int kind = 0; kind < BracketKinds; kind++) {
4102 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4103 int start = leftPositions[kind][leftIndex]; // deepest
4105 // find matching closing bracket
4106 int depth = leftDepths[kind][leftIndex];
4108 for (int i = 0; i < rightCount[kind]; i++) {
4109 int pos = rightPositions[kind][i];
4110 // want matching bracket further in source with same
4112 if ((pos > start) && (depth == rightDepths[kind][i])) {
4117 if (end < 0) { // did not find a good closing match
4118 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4121 // check if even number of opening/closing other brackets
4122 // in between this pair of brackets
4124 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4125 for (int i = 0; i < leftCount[otherKind]; i++) {
4126 int pos = leftPositions[otherKind][i];
4127 if ((pos > start) && (pos < end))
4130 for (int i = 0; i < rightCount[otherKind]; i++) {
4131 int pos = rightPositions[otherKind][i];
4132 if ((pos > start) && (pos < end))
4136 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4142 // too many opening brackets ?
4143 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4144 anomaliesDetected = true;
4145 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4146 compilationUnit.compilationResult);
4148 // too many closing brackets ?
4149 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4150 anomaliesDetected = true;
4151 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4153 if (anomaliesDetected)
4156 return anomaliesDetected;
4157 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4158 return anomaliesDetected;
4159 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4160 return anomaliesDetected;
4164 protected void pushOnAstLengthStack(int pos) {
4166 astLengthStack[++astLengthPtr] = pos;
4167 } catch (IndexOutOfBoundsException e) {
4168 int oldStackLength = astLengthStack.length;
4169 int[] oldPos = astLengthStack;
4170 astLengthStack = new int[oldStackLength + StackIncrement];
4171 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4172 astLengthStack[astLengthPtr] = pos;
4176 protected void pushOnAstStack(ASTNode node) {
4178 * add a new obj on top of the ast stack
4181 astStack[++astPtr] = node;
4182 } catch (IndexOutOfBoundsException e) {
4183 int oldStackLength = astStack.length;
4184 ASTNode[] oldStack = astStack;
4185 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4186 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4187 astPtr = oldStackLength;
4188 astStack[astPtr] = node;
4191 astLengthStack[++astLengthPtr] = 1;
4192 } catch (IndexOutOfBoundsException e) {
4193 int oldStackLength = astLengthStack.length;
4194 int[] oldPos = astLengthStack;
4195 astLengthStack = new int[oldStackLength + AstStackIncrement];
4196 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4197 astLengthStack[astLengthPtr] = 1;
4201 protected void resetModifiers() {
4202 this.modifiers = AccDefault;
4203 this.modifiersSourceStart = -1; // <-- see comment into
4204 // modifiersFlag(int)
4205 this.scanner.commentPtr = -1;