|
Lines 45-51
Link Here
|
| 45 |
|
45 |
|
| 46 |
import org.eclipse.jdt.core.compiler.CharOperation; |
46 |
import org.eclipse.jdt.core.compiler.CharOperation; |
| 47 |
import org.eclipse.jdt.core.compiler.InvalidInputException; |
47 |
import org.eclipse.jdt.core.compiler.InvalidInputException; |
| 48 |
import org.eclipse.jdt.internal.codeassist.impl.AssistParser; |
|
|
| 49 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
48 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
| 50 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
49 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
| 51 |
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression; |
50 |
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression; |
|
Lines 159-165
Link Here
|
| 159 |
import org.eclipse.jdt.internal.compiler.util.Messages; |
158 |
import org.eclipse.jdt.internal.compiler.util.Messages; |
| 160 |
import org.eclipse.jdt.internal.compiler.util.Util; |
159 |
import org.eclipse.jdt.internal.compiler.util.Util; |
| 161 |
|
160 |
|
| 162 |
public class Parser implements ConflictedParser, ParserBasicInformation, TerminalTokens, OperatorIds, TypeIds { |
161 |
public class Parser extends CommitRollbackParser implements ConflictedParser, OperatorIds, TypeIds { |
| 163 |
|
162 |
|
| 164 |
protected static final int THIS_CALL = ExplicitConstructorCall.This; |
163 |
protected static final int THIS_CALL = ExplicitConstructorCall.This; |
| 165 |
protected static final int SUPER_CALL = ExplicitConstructorCall.Super; |
164 |
protected static final int SUPER_CALL = ExplicitConstructorCall.Super; |
|
Lines 168-176
Link Here
|
| 168 |
|
167 |
|
| 169 |
public static char asb[] = null; |
168 |
public static char asb[] = null; |
| 170 |
public static char asr[] = null; |
169 |
public static char asr[] = null; |
| 171 |
//ast stack |
|
|
| 172 |
protected final static int AstStackIncrement = 100; |
| 173 |
public static char base_action[] = null; |
| 174 |
public static final int BracketKinds = 3; |
170 |
public static final int BracketKinds = 3; |
| 175 |
|
171 |
|
| 176 |
public static short check_table[] = null; |
172 |
public static short check_table[] = null; |
|
Lines 179-193
Link Here
|
| 179 |
private static final boolean DEBUG_AUTOMATON = false; |
175 |
private static final boolean DEBUG_AUTOMATON = false; |
| 180 |
private static final String EOF_TOKEN = "$eof" ; //$NON-NLS-1$ |
176 |
private static final String EOF_TOKEN = "$eof" ; //$NON-NLS-1$ |
| 181 |
private static final String ERROR_TOKEN = "$error" ; //$NON-NLS-1$ |
177 |
private static final String ERROR_TOKEN = "$error" ; //$NON-NLS-1$ |
| 182 |
//expression stack |
|
|
| 183 |
protected final static int ExpressionStackIncrement = 100; |
| 184 |
|
| 185 |
protected final static int GenericsStackIncrement = 10; |
| 186 |
|
| 187 |
private final static String FILEPREFIX = "parser"; //$NON-NLS-1$ |
178 |
private final static String FILEPREFIX = "parser"; //$NON-NLS-1$ |
| 188 |
public static char in_symb[] = null; |
179 |
public static char in_symb[] = null; |
| 189 |
private static final String INVALID_CHARACTER = "Invalid Character" ; //$NON-NLS-1$ |
180 |
private static final String INVALID_CHARACTER = "Invalid Character" ; //$NON-NLS-1$ |
| 190 |
public static char lhs[] = null; |
|
|
| 191 |
|
181 |
|
| 192 |
public static String name[] = null; |
182 |
public static String name[] = null; |
| 193 |
public static char nasb[] = null; |
183 |
public static char nasb[] = null; |
|
Lines 197-203
Link Here
|
| 197 |
|
187 |
|
| 198 |
public static String readableName[] = null; |
188 |
public static String readableName[] = null; |
| 199 |
|
189 |
|
| 200 |
public static byte rhs[] = null; |
|
|
| 201 |
|
190 |
|
| 202 |
public static int[] reverse_index = null; |
191 |
public static int[] reverse_index = null; |
| 203 |
public static char[] recovery_templates_index = null; |
192 |
public static char[] recovery_templates_index = null; |
|
Lines 219-229
Link Here
|
| 219 |
public static char scope_suffix[] = null; |
208 |
public static char scope_suffix[] = null; |
| 220 |
public static final int SquareBracket = 1; |
209 |
public static final int SquareBracket = 1; |
| 221 |
|
210 |
|
| 222 |
//internal data for the automat |
|
|
| 223 |
protected final static int StackIncrement = 255; |
| 224 |
|
| 225 |
public static char term_action[] = null; |
| 226 |
public static byte term_check[] = null; |
| 227 |
|
211 |
|
| 228 |
public static char terminal_index[] = null; |
212 |
public static char terminal_index[] = null; |
| 229 |
|
213 |
|
|
Lines 737-745
Link Here
|
| 737 |
public static int nasi(int state) { |
721 |
public static int nasi(int state) { |
| 738 |
return nasb[original_state(state)]; |
722 |
return nasb[original_state(state)]; |
| 739 |
} |
723 |
} |
| 740 |
public static int ntAction(int state, int sym) { |
|
|
| 741 |
return base_action[state + sym]; |
| 742 |
} |
| 743 |
protected static int original_state(int state) { |
724 |
protected static int original_state(int state) { |
| 744 |
return -base_check(state); |
725 |
return -base_check(state); |
| 745 |
} |
726 |
} |
|
Lines 885-949
Link Here
|
| 885 |
} |
866 |
} |
| 886 |
return chars; |
867 |
return chars; |
| 887 |
} |
868 |
} |
| 888 |
public static int tAction(int state, int sym) { |
|
|
| 889 |
return term_action[term_check[base_action[state]+sym] == sym ? base_action[state] + sym : base_action[state]]; |
| 890 |
} |
| 891 |
protected int astLengthPtr; |
| 892 |
|
| 893 |
protected int[] astLengthStack; |
| 894 |
protected int astPtr; |
| 895 |
protected ASTNode[] astStack = new ASTNode[AstStackIncrement]; |
| 896 |
public CompilationUnitDeclaration compilationUnit; /*the result from parse()*/ |
869 |
public CompilationUnitDeclaration compilationUnit; /*the result from parse()*/ |
| 897 |
|
870 |
|
| 898 |
protected RecoveredElement currentElement; |
871 |
protected RecoveredElement currentElement; |
| 899 |
public int currentToken; |
872 |
|
| 900 |
protected boolean diet = false; //tells the scanner to jump over some parts of the code/expressions like method bodies |
873 |
protected boolean diet = false; //tells the scanner to jump over some parts of the code/expressions like method bodies |
| 901 |
protected int dietInt = 0; // if > 0 force the none-diet-parsing mode (even if diet if requested) [field parsing with anonymous inner classes...] |
874 |
protected int dietInt = 0; // if > 0 force the none-diet-parsing mode (even if diet if requested) [field parsing with anonymous inner classes...] |
| 902 |
protected int endPosition; //accurate only when used ! (the start position is pushed into intStack while the end the current one) |
875 |
protected int endPosition; //accurate only when used ! (the start position is pushed into intStack while the end the current one) |
| 903 |
protected int endStatementPosition; |
876 |
protected int endStatementPosition; |
| 904 |
protected int expressionLengthPtr; |
|
|
| 905 |
protected int[] expressionLengthStack; |
| 906 |
protected int expressionPtr; |
| 907 |
protected Expression[] expressionStack = new Expression[ExpressionStackIncrement]; |
| 908 |
public int firstToken ; // handle for multiple parsing goals |
877 |
public int firstToken ; // handle for multiple parsing goals |
| 909 |
|
878 |
|
| 910 |
/* jsr308 -- Type annotation management, we now maintain type annotations in a separate stack |
|
|
| 911 |
as otherwise they get interspersed with other expressions and some of the code is not prepared |
| 912 |
to handle such interleaving and will look ugly if changed. |
| 913 |
|
| 914 |
See consumeArrayCreationExpressionWithoutInitializer for example. |
| 915 |
|
| 916 |
Where SE8 annotations occur in a place SE5 annotations are legal, the SE8 annotations end up in |
| 917 |
the expression stack as we have no way of distinguishing between the two. |
| 918 |
*/ |
| 919 |
protected int typeAnnotationPtr; |
| 920 |
protected int typeAnnotationLengthPtr; |
| 921 |
protected Annotation [] typeAnnotationStack = new Annotation[TypeAnnotationStackIncrement]; |
| 922 |
protected int [] typeAnnotationLengthStack; |
| 923 |
// annotation stack |
| 924 |
protected final static int TypeAnnotationStackIncrement = 100; |
| 925 |
|
| 926 |
// generics management |
| 927 |
protected int genericsIdentifiersLengthPtr; |
| 928 |
protected int[] genericsIdentifiersLengthStack = new int[GenericsStackIncrement]; |
| 929 |
protected int genericsLengthPtr; |
| 930 |
protected int[] genericsLengthStack = new int[GenericsStackIncrement]; |
| 931 |
protected int genericsPtr; |
| 932 |
protected ASTNode[] genericsStack = new ASTNode[GenericsStackIncrement]; |
| 933 |
protected boolean hasError; |
879 |
protected boolean hasError; |
| 934 |
protected boolean hasReportedError; |
880 |
protected boolean hasReportedError; |
| 935 |
//identifiers stacks |
|
|
| 936 |
protected int identifierLengthPtr; |
| 937 |
protected int[] identifierLengthStack; |
| 938 |
protected long[] identifierPositionStack; |
| 939 |
protected int identifierPtr; |
| 940 |
protected char[][] identifierStack; |
| 941 |
protected boolean ignoreNextOpeningBrace; |
881 |
protected boolean ignoreNextOpeningBrace; |
| 942 |
|
882 |
|
| 943 |
//positions , dimensions , .... (int stacks) |
|
|
| 944 |
protected int intPtr; |
| 945 |
|
| 946 |
protected int[] intStack; |
| 947 |
public int lastAct ; //handle for multiple parsing goals |
883 |
public int lastAct ; //handle for multiple parsing goals |
| 948 |
//error recovery management |
884 |
//error recovery management |
| 949 |
protected int lastCheckPoint; |
885 |
protected int lastCheckPoint; |
|
Lines 951-968
Link Here
|
| 951 |
protected int lastErrorEndPositionBeforeRecovery = -1; |
887 |
protected int lastErrorEndPositionBeforeRecovery = -1; |
| 952 |
protected int lastIgnoredToken, nextIgnoredToken; |
888 |
protected int lastIgnoredToken, nextIgnoredToken; |
| 953 |
|
889 |
|
| 954 |
protected int listLength; // for recovering some incomplete list (interfaces, throws or parameters) |
|
|
| 955 |
|
| 956 |
protected int listTypeParameterLength; // for recovering some incomplete list (type parameters) |
| 957 |
protected int lParenPos,rParenPos; //accurate only when used ! |
890 |
protected int lParenPos,rParenPos; //accurate only when used ! |
| 958 |
protected int modifiers; |
|
|
| 959 |
protected int modifiersSourceStart; |
| 960 |
protected int[] nestedMethod; //the ptr is nestedType |
| 961 |
|
| 962 |
protected int nestedType, dimensions; |
| 963 |
ASTNode [] noAstNodes = new ASTNode[AstStackIncrement]; |
| 964 |
|
| 965 |
Expression [] noExpressions = new Expression[ExpressionStackIncrement]; |
| 966 |
//modifiers dimensions nestedType etc....... |
891 |
//modifiers dimensions nestedType etc....... |
| 967 |
protected boolean optimizeStringLiterals =true; |
892 |
protected boolean optimizeStringLiterals =true; |
| 968 |
protected CompilerOptions options; |
893 |
protected CompilerOptions options; |
|
Lines 970-979
Link Here
|
| 970 |
protected ProblemReporter problemReporter; |
895 |
protected ProblemReporter problemReporter; |
| 971 |
|
896 |
|
| 972 |
protected int rBraceStart, rBraceEnd, rBraceSuccessorStart; //accurate only when used ! |
897 |
protected int rBraceStart, rBraceEnd, rBraceSuccessorStart; //accurate only when used ! |
| 973 |
protected int realBlockPtr; |
|
|
| 974 |
protected int[] realBlockStack; |
| 975 |
protected int recoveredStaticInitializerStart; |
| 976 |
public ReferenceContext referenceContext; |
| 977 |
public boolean reportOnlyOneSyntaxError = false; |
898 |
public boolean reportOnlyOneSyntaxError = false; |
| 978 |
public boolean reportSyntaxErrorIsRequired = true; |
899 |
public boolean reportSyntaxErrorIsRequired = true; |
| 979 |
protected boolean restartRecovery; |
900 |
protected boolean restartRecovery; |
|
Lines 988-999
Link Here
|
| 988 |
protected TypeDeclaration pendingRecoveredType; |
909 |
protected TypeDeclaration pendingRecoveredType; |
| 989 |
public RecoveryScanner recoveryScanner; |
910 |
public RecoveryScanner recoveryScanner; |
| 990 |
//scanner token |
911 |
//scanner token |
| 991 |
public Scanner scanner; |
|
|
| 992 |
protected int[] stack = new int[StackIncrement]; |
| 993 |
protected int stateStackTop; |
| 994 |
protected int synchronizedBlockSourceStart; |
912 |
protected int synchronizedBlockSourceStart; |
| 995 |
|
|
|
| 996 |
protected int[] variablesCounter; |
| 997 |
|
913 |
|
| 998 |
protected boolean checkExternalizeStrings; |
914 |
protected boolean checkExternalizeStrings; |
| 999 |
|
915 |
|
|
Lines 1004-1026
Link Here
|
| 1004 |
// used for recovery |
920 |
// used for recovery |
| 1005 |
protected int lastJavadocEnd; |
921 |
protected int lastJavadocEnd; |
| 1006 |
public org.eclipse.jdt.internal.compiler.ReadManager readManager; |
922 |
public org.eclipse.jdt.internal.compiler.ReadManager readManager; |
| 1007 |
private int valueLambdaNestDepth = -1; |
923 |
private boolean parsingJava8Plus; |
| 1008 |
private int stateStackLengthStack[] = new int[0]; |
|
|
| 1009 |
protected boolean parsingJava8Plus; |
| 1010 |
protected int unstackedAct = ERROR_ACTION; |
| 1011 |
private boolean haltOnSyntaxError = false; |
924 |
private boolean haltOnSyntaxError = false; |
| 1012 |
private boolean tolerateDefaultClassMethods = false; |
925 |
private boolean tolerateDefaultClassMethods = false; |
| 1013 |
private boolean processingLambdaParameterList = false; |
926 |
private boolean processingLambdaParameterList = false; |
| 1014 |
private boolean expectTypeAnnotation = false; |
927 |
private boolean expectTypeAnnotation = false; |
| 1015 |
|
928 |
|
| 1016 |
// resumeOnSyntaxError codes: |
929 |
public Parser () { |
| 1017 |
|
|
|
| 1018 |
protected static final int HALT = 0; // halt and throw up hands. |
| 1019 |
protected static final int RESTART = 1; // stacks reset, alternate goal from check point. |
| 1020 |
protected static final int RESUME = 2; // stacks untouched, just continue from where left off. |
| 1021 |
|
| 1022 |
|
| 1023 |
protected Parser () { |
| 1024 |
// Caveat Emptor: For inheritance purposes and then only in very special needs. Only minimal state is initialized ! |
930 |
// Caveat Emptor: For inheritance purposes and then only in very special needs. Only minimal state is initialized ! |
| 1025 |
} |
931 |
} |
| 1026 |
public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) { |
932 |
public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) { |
|
Lines 2251-2257
Link Here
|
| 2251 |
pushOnAstStack(block); |
2157 |
pushOnAstStack(block); |
| 2252 |
} |
2158 |
} |
| 2253 |
protected void consumeBlockStatement() { |
2159 |
protected void consumeBlockStatement() { |
| 2254 |
// todo. |
2160 |
// for assist parsers. |
| 2255 |
} |
2161 |
} |
| 2256 |
protected void consumeBlockStatements() { |
2162 |
protected void consumeBlockStatements() { |
| 2257 |
// BlockStatements ::= BlockStatements BlockStatement |
2163 |
// BlockStatements ::= BlockStatements BlockStatement |
|
Lines 7855-7871
Link Here
|
| 7855 |
pushOnIntStack(0); // signal explicit this |
7761 |
pushOnIntStack(0); // signal explicit this |
| 7856 |
} |
7762 |
} |
| 7857 |
|
7763 |
|
|
|
7764 |
protected boolean isAssistParser() { |
| 7765 |
return false; |
| 7766 |
} |
| 7858 |
protected void consumeNestedLambda() { |
7767 |
protected void consumeNestedLambda() { |
| 7859 |
// NestedLambda ::= $empty - we get here just after the type+parenthesis elided singleton parameter or just before the '(' of the parameter list. |
7768 |
// NestedLambda ::= $empty - we get here just after the type+parenthesis elided singleton parameter or just before the '(' of the parameter list. |
| 7860 |
consumeNestedType(); |
7769 |
consumeNestedType(); |
| 7861 |
this.nestedMethod[this.nestedType] ++; |
7770 |
this.nestedMethod[this.nestedType] ++; |
| 7862 |
LambdaExpression lambda = new LambdaExpression(this.compilationUnit.compilationResult, this instanceof AssistParser); |
7771 |
LambdaExpression lambda = new LambdaExpression(this.compilationUnit.compilationResult, isAssistParser()); |
| 7863 |
pushOnAstStack(lambda); |
7772 |
pushOnAstStack(lambda); |
| 7864 |
if (this.currentElement != null) { |
|
|
| 7865 |
this.currentElement = this.currentElement.add(lambda, 0); |
| 7866 |
this.lastCheckPoint = this.scanner.currentPosition; |
| 7867 |
this.lastIgnoredToken = -1; |
| 7868 |
} |
| 7869 |
this.processingLambdaParameterList = true; |
7773 |
this.processingLambdaParameterList = true; |
| 7870 |
} |
7774 |
} |
| 7871 |
|
7775 |
|
|
Lines 7896-7911
Link Here
|
| 7896 |
} |
7800 |
} |
| 7897 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr]; |
7801 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr]; |
| 7898 |
lexp.setArguments(arguments); |
7802 |
lexp.setArguments(arguments); |
| 7899 |
lexp.setArrowPosition(arrowPosition); // '->' position |
7803 |
lexp.setArrowPosition(arrowPosition); |
| 7900 |
lexp.sourceEnd = this.intStack[this.intPtr--]; // ')' position or identifier position. |
7804 |
lexp.sourceEnd = this.intStack[this.intPtr--]; // ')' position or identifier position. |
| 7901 |
lexp.sourceStart = this.intStack[this.intPtr--]; // '(' position or identifier position. |
7805 |
lexp.sourceStart = this.intStack[this.intPtr--]; // '(' position or identifier position. |
| 7902 |
lexp.hasParentheses = (this.scanner.getSource()[lexp.sourceStart] == '('); |
7806 |
lexp.hasParentheses = (this.scanner.getSource()[lexp.sourceStart] == '('); |
| 7903 |
this.listLength = 0; // reset this.listLength after having read all parameters |
7807 |
this.listLength -= arguments == null ? 0 : arguments.length; // not necessary really. |
| 7904 |
if (this.currentElement != null) { |
|
|
| 7905 |
this.lastCheckPoint = lexp.sourceEnd + 1; |
| 7906 |
this.lastIgnoredToken = -1; |
| 7907 |
} |
| 7908 |
this.processingLambdaParameterList = false; |
7808 |
this.processingLambdaParameterList = false; |
|
|
7809 |
if (this.currentElement != null) { |
| 7810 |
this.lastCheckPoint = arrowPosition + 1; |
| 7811 |
// this.ignoreNextOpeningBrace = true; |
| 7812 |
// this.currentElement.bracketBalance++; |
| 7813 |
} |
| 7909 |
} |
7814 |
} |
| 7910 |
protected void consumeLambdaExpression() { |
7815 |
protected void consumeLambdaExpression() { |
| 7911 |
|
7816 |
|
|
Lines 7919-7924
Link Here
|
| 7919 |
if (this.options.ignoreMethodBodies) { |
7824 |
if (this.options.ignoreMethodBodies) { |
| 7920 |
body = new Block(0); |
7825 |
body = new Block(0); |
| 7921 |
} |
7826 |
} |
|
|
7827 |
((Block) body).lambdaBody = true; // for consistency's sakes. |
| 7922 |
} |
7828 |
} |
| 7923 |
|
7829 |
|
| 7924 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr--]; |
7830 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr--]; |
|
Lines 7935-7944
Link Here
|
| 7935 |
} |
7841 |
} |
| 7936 |
pushOnExpressionStack(lexp); |
7842 |
pushOnExpressionStack(lexp); |
| 7937 |
if (this.currentElement != null) { |
7843 |
if (this.currentElement != null) { |
| 7938 |
if (this.currentElement.parseTree() == lexp && this.currentElement.parent != null) { |
7844 |
this.lastCheckPoint = body.sourceEnd + 1; |
| 7939 |
this.currentElement = this.currentElement.parent; |
7845 |
// if (body instanceof Expression) |
| 7940 |
} |
7846 |
// this.currentElement.bracketBalance --; |
| 7941 |
this.lastCheckPoint = lexp.sourceEnd + 1; |
|
|
| 7942 |
} |
7847 |
} |
| 7943 |
} |
7848 |
} |
| 7944 |
|
7849 |
|
|
Lines 7984-7992
Link Here
|
| 7984 |
pushOnIntStack(arg.declarationSourceEnd); |
7889 |
pushOnIntStack(arg.declarationSourceEnd); |
| 7985 |
} |
7890 |
} |
| 7986 |
pushOnAstStack(arg); |
7891 |
pushOnAstStack(arg); |
| 7987 |
/* if incomplete method header, this.listLength counter will not have been reset, |
7892 |
this.listLength++; // not relevant really. |
| 7988 |
indicating that some arguments are available on the stack */ |
|
|
| 7989 |
this.listLength++; |
| 7990 |
} |
7893 |
} |
| 7991 |
protected void consumeElidedLeftBraceAndReturn() { |
7894 |
protected void consumeElidedLeftBraceAndReturn() { |
| 7992 |
/* ElidedLeftBraceAndReturn ::= $empty |
7895 |
/* ElidedLeftBraceAndReturn ::= $empty |
|
Lines 8740-8765
Link Here
|
| 8740 |
optimizedConcatNodeLists(); |
8643 |
optimizedConcatNodeLists(); |
| 8741 |
} |
8644 |
} |
| 8742 |
protected void consumeToken(int type) { |
8645 |
protected void consumeToken(int type) { |
| 8743 |
/* remember the last consumed value */ |
|
|
| 8744 |
/* try to minimize the number of build values */ |
| 8745 |
// // clear the commentPtr of the scanner in case we read something different from a modifier |
| 8746 |
// switch(type) { |
| 8747 |
// case TokenNameabstract : |
| 8748 |
// case TokenNamestrictfp : |
| 8749 |
// case TokenNamefinal : |
| 8750 |
// case TokenNamenative : |
| 8751 |
// case TokenNameprivate : |
| 8752 |
// case TokenNameprotected : |
| 8753 |
// case TokenNamepublic : |
| 8754 |
// case TokenNametransient : |
| 8755 |
// case TokenNamevolatile : |
| 8756 |
// case TokenNamestatic : |
| 8757 |
// case TokenNamesynchronized : |
| 8758 |
// break; |
| 8759 |
// default: |
| 8760 |
// this.scanner.commentPtr = -1; |
| 8761 |
// } |
| 8762 |
//System.out.println(this.scanner.toStringAction(type)); |
| 8763 |
switch (type) { |
8646 |
switch (type) { |
| 8764 |
case TokenNameARROW: |
8647 |
case TokenNameARROW: |
| 8765 |
consumeLambdaHeader(); |
8648 |
consumeLambdaHeader(); |
|
Lines 10464-10487
Link Here
|
| 10464 |
this.referenceContext = null; |
10347 |
this.referenceContext = null; |
| 10465 |
this.endStatementPosition = 0; |
10348 |
this.endStatementPosition = 0; |
| 10466 |
this.valueLambdaNestDepth = -1; |
10349 |
this.valueLambdaNestDepth = -1; |
| 10467 |
|
10350 |
|
| 10468 |
//remove objects from stack too, while the same parser/compiler couple is |
|
|
| 10469 |
//re-used between two compilations .... |
| 10470 |
|
| 10471 |
int astLength = this.astStack.length; |
10351 |
int astLength = this.astStack.length; |
| 10472 |
if (this.noAstNodes.length < astLength){ |
10352 |
for (int i = 0; i < astLength; i++) |
| 10473 |
this.noAstNodes = new ASTNode[astLength]; |
10353 |
this.astStack[i] = null; |
| 10474 |
//System.out.println("Resized AST stacks : "+ astLength); |
|
|
| 10475 |
|
| 10476 |
} |
| 10477 |
System.arraycopy(this.noAstNodes, 0, this.astStack, 0, astLength); |
| 10478 |
|
10354 |
|
| 10479 |
int expressionLength = this.expressionStack.length; |
10355 |
int expressionLength = this.expressionStack.length; |
| 10480 |
if (this.noExpressions.length < expressionLength){ |
10356 |
for (int i = 0; i < expressionLength; i++) |
| 10481 |
this.noExpressions = new Expression[expressionLength]; |
10357 |
this.expressionStack[i] = null; |
| 10482 |
//System.out.println("Resized EXPR stacks : "+ expressionLength); |
|
|
| 10483 |
} |
| 10484 |
System.arraycopy(this.noExpressions, 0, this.expressionStack, 0, expressionLength); |
| 10485 |
|
10358 |
|
| 10486 |
// reset this.scanner state |
10359 |
// reset this.scanner state |
| 10487 |
this.scanner.commentPtr = -1; |
10360 |
this.scanner.commentPtr = -1; |
|
Lines 10797-10837
Link Here
|
| 10797 |
|
10670 |
|
| 10798 |
Though this code looks complex, we should exit early in most situations. |
10671 |
Though this code looks complex, we should exit early in most situations. |
| 10799 |
*/ |
10672 |
*/ |
| 10800 |
int lastAction = this.unstackedAct; |
10673 |
if (this.unstackedAct == ERROR_ACTION) { // automaton is not running. |
| 10801 |
if (lastAction == ERROR_ACTION) { // automaton is not running. |
|
|
| 10802 |
return false; |
10674 |
return false; |
| 10803 |
} |
10675 |
} |
| 10804 |
int stackTop = this.stateStackTop; // local copy of stack pointer |
|
|
| 10805 |
int stackTopState = this.stack[stackTop]; // single cell non write through "alternate stack" - the automaton's stack pointer either stays fixed during this manoeuvre or monotonically decreases. |
| 10806 |
int highWaterMark = stackTop; |
| 10807 |
|
| 10808 |
if (token != TokenNameAT) { |
10676 |
if (token != TokenNameAT) { |
| 10809 |
token = token == TokenNameLPAREN ? TokenNameBeginLambda : TokenNameBeginTypeArguments; |
10677 |
token = token == TokenNameLPAREN ? TokenNameBeginLambda : TokenNameBeginTypeArguments; |
| 10810 |
} |
10678 |
} |
| 10811 |
|
10679 |
|
| 10812 |
// A rotated version of the automaton - cf. parse()'s for(;;) |
10680 |
return automatonWillShift(token, this.unstackedAct); |
| 10813 |
for (;;) { |
|
|
| 10814 |
if (lastAction > ERROR_ACTION) { |
| 10815 |
lastAction -= ERROR_ACTION; /* shift-reduce on loop entry from above, reduce on loop back */ |
| 10816 |
do { /* reduce */ |
| 10817 |
stackTop -= rhs[lastAction] - 1; |
| 10818 |
if (stackTop < highWaterMark) { |
| 10819 |
stackTopState = this.stack[highWaterMark = stackTop]; |
| 10820 |
} // else stackTopState is upto date already. |
| 10821 |
lastAction = ntAction(stackTopState, lhs[lastAction]); |
| 10822 |
} while (lastAction <= NUM_RULES); |
| 10823 |
} |
| 10824 |
highWaterMark = ++stackTop; |
| 10825 |
stackTopState = lastAction; // "push" |
| 10826 |
lastAction = tAction(lastAction, token); // can be looked up from a precomputed cache. |
| 10827 |
if (lastAction <= NUM_RULES) { |
| 10828 |
stackTop --; |
| 10829 |
lastAction += ERROR_ACTION; |
| 10830 |
continue; |
| 10831 |
} |
| 10832 |
// Error => false, Shift, Shift/Reduce => true, Accept => impossible. |
| 10833 |
return lastAction != ERROR_ACTION; |
| 10834 |
} |
| 10835 |
} |
10681 |
} |
| 10836 |
/*main loop of the automat |
10682 |
/*main loop of the automat |
| 10837 |
When a rule is reduced, the method consumeRule(int) is called with the number |
10683 |
When a rule is reduced, the method consumeRule(int) is called with the number |
|
Lines 10852-10857
Link Here
|
| 10852 |
|
10698 |
|
| 10853 |
this.hasReportedError = false; |
10699 |
this.hasReportedError = false; |
| 10854 |
int act = START_STATE; |
10700 |
int act = START_STATE; |
|
|
10701 |
this.unstackedAct = ERROR_ACTION; |
| 10855 |
this.stateStackTop = -1; |
10702 |
this.stateStackTop = -1; |
| 10856 |
this.currentToken = getFirstToken(); |
10703 |
this.currentToken = getFirstToken(); |
| 10857 |
|
10704 |
|
|
Lines 10866-10873
Link Here
|
| 10866 |
stackLength); |
10713 |
stackLength); |
| 10867 |
} |
10714 |
} |
| 10868 |
this.stack[this.stateStackTop] = act; |
10715 |
this.stack[this.stateStackTop] = act; |
| 10869 |
|
10716 |
this.unstackedAct = act = tAction(act, this.currentToken); |
| 10870 |
act = tAction(act, this.currentToken); |
|
|
| 10871 |
if (act == ERROR_ACTION || this.restartRecovery) { |
10717 |
if (act == ERROR_ACTION || this.restartRecovery) { |
| 10872 |
if (DEBUG_AUTOMATON) { |
10718 |
if (DEBUG_AUTOMATON) { |
| 10873 |
if (this.restartRecovery) { |
10719 |
if (this.restartRecovery) { |
|
Lines 10879-10901
Link Here
|
| 10879 |
|
10725 |
|
| 10880 |
int errorPos = this.scanner.currentPosition - 1; |
10726 |
int errorPos = this.scanner.currentPosition - 1; |
| 10881 |
if (!this.hasReportedError) { |
10727 |
if (!this.hasReportedError) { |
| 10882 |
this.hasError = true; // looks incorrect for recovery case ? |
10728 |
this.hasError = true; |
| 10883 |
} |
10729 |
} |
| 10884 |
int previousToken = this.currentToken; |
10730 |
this.kurrentToken = this.currentToken; |
| 10885 |
switch (resumeOnSyntaxError()) { |
10731 |
switch (resumeOnErrorOrTriggeredRecovery(act == ERROR_ACTION)) { |
| 10886 |
case HALT: |
10732 |
case HALT: |
| 10887 |
act = ERROR_ACTION; |
10733 |
act = ERROR_ACTION; |
| 10888 |
break ProcessTerminals; |
10734 |
break ProcessTerminals; |
| 10889 |
case RESTART: |
10735 |
case RESTART: |
| 10890 |
if (act == ERROR_ACTION && previousToken != 0) this.lastErrorEndPosition = errorPos; |
10736 |
if (act == ERROR_ACTION && this.kurrentToken != 0) this.lastErrorEndPosition = errorPos; |
| 10891 |
act = START_STATE; |
10737 |
act = START_STATE; |
| 10892 |
this.stateStackTop = -1; |
10738 |
this.stateStackTop = -1; |
| 10893 |
this.currentToken = getFirstToken(); |
10739 |
this.currentToken = getFirstToken(); |
| 10894 |
continue ProcessTerminals; |
10740 |
continue ProcessTerminals; |
| 10895 |
case RESUME: |
10741 |
case RESUME: |
| 10896 |
break; // We presume the world is virgin so we can continue exactly from where we left off. |
10742 |
if (act == ERROR_ACTION) { |
| 10897 |
default: |
10743 |
act = this.stack[this.stateStackTop--]; |
| 10898 |
throw new IllegalStateException(); |
10744 |
continue ProcessTerminals; |
|
|
10745 |
} else { |
| 10746 |
this.currentToken = this.kurrentToken; // Gets trashed all over the place. |
| 10747 |
} |
| 10748 |
// FALL THROUGH. |
| 10899 |
} |
10749 |
} |
| 10900 |
} |
10750 |
} |
| 10901 |
if (act <= NUM_RULES) { |
10751 |
if (act <= NUM_RULES) { |
|
Lines 10914-10920
Link Here
|
| 10914 |
this.recordStringLiterals = oldValue; |
10764 |
this.recordStringLiterals = oldValue; |
| 10915 |
} |
10765 |
} |
| 10916 |
try { |
10766 |
try { |
| 10917 |
this.unstackedAct = act; |
|
|
| 10918 |
this.currentToken = this.scanner.getNextToken(); |
10767 |
this.currentToken = this.scanner.getNextToken(); |
| 10919 |
} catch(InvalidInputException e){ |
10768 |
} catch(InvalidInputException e){ |
| 10920 |
if (!this.hasReportedError){ |
10769 |
if (!this.hasReportedError){ |
|
Lines 10924-10936
Link Here
|
| 10924 |
this.lastCheckPoint = this.scanner.currentPosition; |
10773 |
this.lastCheckPoint = this.scanner.currentPosition; |
| 10925 |
this.currentToken = 0; |
10774 |
this.currentToken = 0; |
| 10926 |
this.restartRecovery = true; |
10775 |
this.restartRecovery = true; |
| 10927 |
} finally { |
10776 |
} |
| 10928 |
this.unstackedAct = ERROR_ACTION; |
|
|
| 10929 |
} |
| 10930 |
if(this.statementRecoveryActivated) { |
10777 |
if(this.statementRecoveryActivated) { |
| 10931 |
jumpOverType(); |
10778 |
jumpOverType(); |
| 10932 |
} |
10779 |
} |
| 10933 |
act -= ERROR_ACTION; |
10780 |
this.unstackedAct = act -= ERROR_ACTION; |
| 10934 |
|
10781 |
|
| 10935 |
if (DEBUG_AUTOMATON) { |
10782 |
if (DEBUG_AUTOMATON) { |
| 10936 |
System.out.print("Shift/Reduce - (" + name[terminal_index[this.currentToken]]+") "); //$NON-NLS-1$ //$NON-NLS-2$ |
10783 |
System.out.print("Shift/Reduce - (" + name[terminal_index[this.currentToken]]+") "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
Lines 10946-10952
Link Here
|
| 10946 |
this.recordStringLiterals = oldValue; |
10793 |
this.recordStringLiterals = oldValue; |
| 10947 |
} |
10794 |
} |
| 10948 |
try{ |
10795 |
try{ |
| 10949 |
this.unstackedAct = act; |
|
|
| 10950 |
this.currentToken = this.scanner.getNextToken(); |
10796 |
this.currentToken = this.scanner.getNextToken(); |
| 10951 |
} catch(InvalidInputException e){ |
10797 |
} catch(InvalidInputException e){ |
| 10952 |
if (!this.hasReportedError){ |
10798 |
if (!this.hasReportedError){ |
|
Lines 10956-10963
Link Here
|
| 10956 |
this.lastCheckPoint = this.scanner.currentPosition; |
10802 |
this.lastCheckPoint = this.scanner.currentPosition; |
| 10957 |
this.currentToken = 0; |
10803 |
this.currentToken = 0; |
| 10958 |
this.restartRecovery = true; |
10804 |
this.restartRecovery = true; |
| 10959 |
} finally { |
|
|
| 10960 |
this.unstackedAct = ERROR_ACTION; |
| 10961 |
} |
10805 |
} |
| 10962 |
if(this.statementRecoveryActivated) { |
10806 |
if(this.statementRecoveryActivated) { |
| 10963 |
jumpOverType(); |
10807 |
jumpOverType(); |
|
Lines 10978-10985
Link Here
|
| 10978 |
} |
10822 |
} |
| 10979 |
|
10823 |
|
| 10980 |
this.stateStackTop -= (rhs[act] - 1); |
10824 |
this.stateStackTop -= (rhs[act] - 1); |
|
|
10825 |
this.unstackedAct = ntAction(this.stack[this.stateStackTop], lhs[act]); |
| 10981 |
consumeRule(act); |
10826 |
consumeRule(act); |
| 10982 |
act = ntAction(this.stack[this.stateStackTop], lhs[act]); |
10827 |
act = this.unstackedAct; |
| 10983 |
|
10828 |
|
| 10984 |
if (DEBUG_AUTOMATON) { |
10829 |
if (DEBUG_AUTOMATON) { |
| 10985 |
if (act <= NUM_RULES) { |
10830 |
if (act <= NUM_RULES) { |
|
Lines 10994-10999
Link Here
|
| 10994 |
} |
10839 |
} |
| 10995 |
} |
10840 |
} |
| 10996 |
} finally { |
10841 |
} finally { |
|
|
10842 |
this.unstackedAct = ERROR_ACTION; |
| 10997 |
this.scanner.setActiveParser(null); |
10843 |
this.scanner.setActiveParser(null); |
| 10998 |
} |
10844 |
} |
| 10999 |
|
10845 |
|
|
Lines 11993-11998
Link Here
|
| 11993 |
} |
11839 |
} |
| 11994 |
} |
11840 |
} |
| 11995 |
|
11841 |
|
|
|
11842 |
public boolean requireExtendedRecovery() { |
| 11843 |
return false; // for assist parsers. |
| 11844 |
} |
| 11845 |
|
| 11846 |
public void startRecovery() { |
| 11847 |
this.restartRecovery = true; |
| 11848 |
} |
| 11849 |
|
| 11996 |
public void recoveryExitFromVariable() { |
11850 |
public void recoveryExitFromVariable() { |
| 11997 |
if(this.currentElement != null && this.currentElement.parent != null) { |
11851 |
if(this.currentElement != null && this.currentElement.parent != null) { |
| 11998 |
if(this.currentElement instanceof RecoveredLocalVariable) { |
11852 |
if(this.currentElement instanceof RecoveredLocalVariable) { |
|
Lines 12152-12190
Link Here
|
| 12152 |
} |
12006 |
} |
| 12153 |
/* |
12007 |
/* |
| 12154 |
* Reset context so as to resume to regular parse loop |
12008 |
* Reset context so as to resume to regular parse loop |
| 12155 |
*/ |
|
|
| 12156 |
protected void resetStacks() { |
| 12157 |
|
| 12158 |
this.astPtr = -1; |
| 12159 |
this.astLengthPtr = -1; |
| 12160 |
this.expressionPtr = -1; |
| 12161 |
this.expressionLengthPtr = -1; |
| 12162 |
this.typeAnnotationLengthPtr = -1; |
| 12163 |
this.typeAnnotationPtr = -1; |
| 12164 |
this.identifierPtr = -1; |
| 12165 |
this.identifierLengthPtr = -1; |
| 12166 |
this.intPtr = -1; |
| 12167 |
this.nestedMethod[this.nestedType = 0] = 0; // need to reset for further reuse |
| 12168 |
this.variablesCounter[this.nestedType] = 0; |
| 12169 |
this.dimensions = 0 ; |
| 12170 |
this.realBlockStack[this.realBlockPtr = 0] = 0; |
| 12171 |
this.recoveredStaticInitializerStart = 0; |
| 12172 |
this.listLength = 0; |
| 12173 |
this.listTypeParameterLength = 0; |
| 12174 |
|
| 12175 |
this.genericsIdentifiersLengthPtr = -1; |
| 12176 |
this.genericsLengthPtr = -1; |
| 12177 |
this.genericsPtr = -1; |
| 12178 |
this.valueLambdaNestDepth = -1; |
| 12179 |
} |
| 12180 |
/* |
| 12181 |
* Reset context so as to resume to regular parse loop |
| 12182 |
* If unable to reset for resuming, answers false. |
12009 |
* If unable to reset for resuming, answers false. |
| 12183 |
* |
12010 |
* |
| 12184 |
* Move checkpoint location, reset internal stacks and |
12011 |
* Move checkpoint location, reset internal stacks and |
| 12185 |
* decide which grammar goal is activated. |
12012 |
* decide which grammar goal is activated. |
| 12186 |
*/ |
12013 |
*/ |
| 12187 |
protected boolean resumeAfterRecovery() { |
12014 |
protected int resumeAfterRecovery(boolean errorRecovery) { |
| 12188 |
if(!this.methodRecoveryActivated && !this.statementRecoveryActivated) { |
12015 |
if(!this.methodRecoveryActivated && !this.statementRecoveryActivated) { |
| 12189 |
|
12016 |
|
| 12190 |
// reset internal stacks |
12017 |
// reset internal stacks |
|
Lines 12193-12210
Link Here
|
| 12193 |
|
12020 |
|
| 12194 |
/* attempt to move checkpoint location */ |
12021 |
/* attempt to move checkpoint location */ |
| 12195 |
if (!moveRecoveryCheckpoint()) { |
12022 |
if (!moveRecoveryCheckpoint()) { |
| 12196 |
return false; |
12023 |
return HALT; |
| 12197 |
} |
12024 |
} |
| 12198 |
|
12025 |
|
| 12199 |
// only look for headers |
12026 |
// only look for headers |
| 12200 |
if (this.referenceContext instanceof CompilationUnitDeclaration){ |
12027 |
if (this.referenceContext instanceof CompilationUnitDeclaration){ |
| 12201 |
goForHeaders(); |
12028 |
goForHeaders(); |
| 12202 |
this.diet = true; // passed this point, will not consider method bodies |
12029 |
this.diet = true; // passed this point, will not consider method bodies |
| 12203 |
return true; |
12030 |
return RESTART; |
| 12204 |
} |
12031 |
} |
| 12205 |
|
12032 |
|
| 12206 |
// does not know how to restart |
12033 |
// does not know how to restart |
| 12207 |
return false; |
12034 |
return HALT; |
| 12208 |
} else if(!this.statementRecoveryActivated) { |
12035 |
} else if(!this.statementRecoveryActivated) { |
| 12209 |
|
12036 |
|
| 12210 |
// reset internal stacks |
12037 |
// reset internal stacks |
|
Lines 12213-12229
Link Here
|
| 12213 |
|
12040 |
|
| 12214 |
/* attempt to move checkpoint location */ |
12041 |
/* attempt to move checkpoint location */ |
| 12215 |
if (!moveRecoveryCheckpoint()) { |
12042 |
if (!moveRecoveryCheckpoint()) { |
| 12216 |
return false; |
12043 |
return HALT; |
| 12217 |
} |
12044 |
} |
| 12218 |
|
12045 |
|
| 12219 |
// only look for headers |
12046 |
// only look for headers |
| 12220 |
goForHeaders(); |
12047 |
goForHeaders(); |
| 12221 |
return true; |
12048 |
return RESTART; |
| 12222 |
} else { |
12049 |
} else { |
| 12223 |
return false; |
12050 |
return HALT; |
| 12224 |
} |
12051 |
} |
| 12225 |
} |
12052 |
} |
| 12226 |
protected int resumeOnSyntaxError() { |
12053 |
protected int resumeOnErrorOrTriggeredRecovery(boolean errorRecovery) { |
| 12227 |
if (this.haltOnSyntaxError) |
12054 |
if (this.haltOnSyntaxError) |
| 12228 |
return HALT; |
12055 |
return HALT; |
| 12229 |
/* request recovery initialization */ |
12056 |
/* request recovery initialization */ |
|
Lines 12260-12266
Link Here
|
| 12260 |
} |
12087 |
} |
| 12261 |
|
12088 |
|
| 12262 |
/* attempt to reset state in order to resume to parse loop */ |
12089 |
/* attempt to reset state in order to resume to parse loop */ |
| 12263 |
return resumeAfterRecovery() ? RESTART : HALT; |
12090 |
return resumeAfterRecovery(errorRecovery); |
| 12264 |
} |
12091 |
} |
| 12265 |
public void setMethodsFullRecovery(boolean enabled) { |
12092 |
public void setMethodsFullRecovery(boolean enabled) { |
| 12266 |
this.options.performMethodsFullRecovery = enabled; |
12093 |
this.options.performMethodsFullRecovery = enabled; |