|
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 896-902
Link Here
|
| 896 |
public CompilationUnitDeclaration compilationUnit; /*the result from parse()*/ |
895 |
public CompilationUnitDeclaration compilationUnit; /*the result from parse()*/ |
| 897 |
|
896 |
|
| 898 |
protected RecoveredElement currentElement; |
897 |
protected RecoveredElement currentElement; |
| 899 |
public int currentToken; |
898 |
|
| 900 |
protected boolean diet = false; //tells the scanner to jump over some parts of the code/expressions like method bodies |
899 |
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...] |
900 |
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) |
901 |
protected int endPosition; //accurate only when used ! (the start position is pushed into intStack while the end the current one) |
|
Lines 987-994
Link Here
|
| 987 |
protected int nextTypeStart; |
986 |
protected int nextTypeStart; |
| 988 |
protected TypeDeclaration pendingRecoveredType; |
987 |
protected TypeDeclaration pendingRecoveredType; |
| 989 |
public RecoveryScanner recoveryScanner; |
988 |
public RecoveryScanner recoveryScanner; |
| 990 |
//scanner token |
989 |
|
| 991 |
public Scanner scanner; |
|
|
| 992 |
protected int[] stack = new int[StackIncrement]; |
990 |
protected int[] stack = new int[StackIncrement]; |
| 993 |
protected int stateStackTop; |
991 |
protected int stateStackTop; |
| 994 |
protected int synchronizedBlockSourceStart; |
992 |
protected int synchronizedBlockSourceStart; |
|
Lines 1004-1010
Link Here
|
| 1004 |
// used for recovery |
1002 |
// used for recovery |
| 1005 |
protected int lastJavadocEnd; |
1003 |
protected int lastJavadocEnd; |
| 1006 |
public org.eclipse.jdt.internal.compiler.ReadManager readManager; |
1004 |
public org.eclipse.jdt.internal.compiler.ReadManager readManager; |
| 1007 |
private int valueLambdaNestDepth = -1; |
1005 |
protected int valueLambdaNestDepth = -1; |
| 1008 |
private int stateStackLengthStack[] = new int[0]; |
1006 |
private int stateStackLengthStack[] = new int[0]; |
| 1009 |
protected boolean parsingJava8Plus; |
1007 |
protected boolean parsingJava8Plus; |
| 1010 |
protected int unstackedAct = ERROR_ACTION; |
1008 |
protected int unstackedAct = ERROR_ACTION; |
|
Lines 1013-1026
Link Here
|
| 1013 |
private boolean processingLambdaParameterList = false; |
1011 |
private boolean processingLambdaParameterList = false; |
| 1014 |
private boolean expectTypeAnnotation = false; |
1012 |
private boolean expectTypeAnnotation = false; |
| 1015 |
|
1013 |
|
| 1016 |
// resumeOnSyntaxError codes: |
1014 |
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 ! |
1015 |
// Caveat Emptor: For inheritance purposes and then only in very special needs. Only minimal state is initialized ! |
| 1025 |
} |
1016 |
} |
| 1026 |
public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) { |
1017 |
public Parser(ProblemReporter problemReporter, boolean optimizeStringLiterals) { |
|
Lines 2251-2257
Link Here
|
| 2251 |
pushOnAstStack(block); |
2242 |
pushOnAstStack(block); |
| 2252 |
} |
2243 |
} |
| 2253 |
protected void consumeBlockStatement() { |
2244 |
protected void consumeBlockStatement() { |
| 2254 |
// todo. |
2245 |
// for assist parsers. |
| 2255 |
} |
2246 |
} |
| 2256 |
protected void consumeBlockStatements() { |
2247 |
protected void consumeBlockStatements() { |
| 2257 |
// BlockStatements ::= BlockStatements BlockStatement |
2248 |
// BlockStatements ::= BlockStatements BlockStatement |
|
Lines 7855-7871
Link Here
|
| 7855 |
pushOnIntStack(0); // signal explicit this |
7846 |
pushOnIntStack(0); // signal explicit this |
| 7856 |
} |
7847 |
} |
| 7857 |
|
7848 |
|
|
|
7849 |
protected boolean isAssistParser() { |
| 7850 |
return false; |
| 7851 |
} |
| 7858 |
protected void consumeNestedLambda() { |
7852 |
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. |
7853 |
// NestedLambda ::= $empty - we get here just after the type+parenthesis elided singleton parameter or just before the '(' of the parameter list. |
| 7860 |
consumeNestedType(); |
7854 |
consumeNestedType(); |
| 7861 |
this.nestedMethod[this.nestedType] ++; |
7855 |
this.nestedMethod[this.nestedType] ++; |
| 7862 |
LambdaExpression lambda = new LambdaExpression(this.compilationUnit.compilationResult, this instanceof AssistParser); |
7856 |
LambdaExpression lambda = new LambdaExpression(this.compilationUnit.compilationResult, isAssistParser()); |
| 7863 |
pushOnAstStack(lambda); |
7857 |
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; |
7858 |
this.processingLambdaParameterList = true; |
| 7870 |
} |
7859 |
} |
| 7871 |
|
7860 |
|
|
Lines 7896-7911
Link Here
|
| 7896 |
} |
7885 |
} |
| 7897 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr]; |
7886 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr]; |
| 7898 |
lexp.setArguments(arguments); |
7887 |
lexp.setArguments(arguments); |
| 7899 |
lexp.setArrowPosition(arrowPosition); // '->' position |
7888 |
lexp.setArrowPosition(arrowPosition); |
| 7900 |
lexp.sourceEnd = this.intStack[this.intPtr--]; // ')' position or identifier position. |
7889 |
lexp.sourceEnd = this.intStack[this.intPtr--]; // ')' position or identifier position. |
| 7901 |
lexp.sourceStart = this.intStack[this.intPtr--]; // '(' position or identifier position. |
7890 |
lexp.sourceStart = this.intStack[this.intPtr--]; // '(' position or identifier position. |
| 7902 |
lexp.hasParentheses = (this.scanner.getSource()[lexp.sourceStart] == '('); |
7891 |
lexp.hasParentheses = (this.scanner.getSource()[lexp.sourceStart] == '('); |
| 7903 |
this.listLength = 0; // reset this.listLength after having read all parameters |
7892 |
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; |
7893 |
this.processingLambdaParameterList = false; |
|
|
7894 |
if (this.currentElement != null) { |
| 7895 |
this.lastCheckPoint = arrowPosition + 1; |
| 7896 |
} |
| 7909 |
} |
7897 |
} |
| 7910 |
protected void consumeLambdaExpression() { |
7898 |
protected void consumeLambdaExpression() { |
| 7911 |
|
7899 |
|
|
Lines 7919-7924
Link Here
|
| 7919 |
if (this.options.ignoreMethodBodies) { |
7907 |
if (this.options.ignoreMethodBodies) { |
| 7920 |
body = new Block(0); |
7908 |
body = new Block(0); |
| 7921 |
} |
7909 |
} |
|
|
7910 |
((Block) body).lambdaBody = true; // for consistency's sakes. |
| 7922 |
} |
7911 |
} |
| 7923 |
|
7912 |
|
| 7924 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr--]; |
7913 |
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr--]; |
|
Lines 7935-7944
Link Here
|
| 7935 |
} |
7924 |
} |
| 7936 |
pushOnExpressionStack(lexp); |
7925 |
pushOnExpressionStack(lexp); |
| 7937 |
if (this.currentElement != null) { |
7926 |
if (this.currentElement != null) { |
| 7938 |
if (this.currentElement.parseTree() == lexp && this.currentElement.parent != null) { |
7927 |
this.lastCheckPoint = body.sourceEnd + 1; |
| 7939 |
this.currentElement = this.currentElement.parent; |
|
|
| 7940 |
} |
| 7941 |
this.lastCheckPoint = lexp.sourceEnd + 1; |
| 7942 |
} |
7928 |
} |
| 7943 |
} |
7929 |
} |
| 7944 |
|
7930 |
|
|
Lines 7984-7992
Link Here
|
| 7984 |
pushOnIntStack(arg.declarationSourceEnd); |
7970 |
pushOnIntStack(arg.declarationSourceEnd); |
| 7985 |
} |
7971 |
} |
| 7986 |
pushOnAstStack(arg); |
7972 |
pushOnAstStack(arg); |
| 7987 |
/* if incomplete method header, this.listLength counter will not have been reset, |
7973 |
this.listLength++; // not relevant really. |
| 7988 |
indicating that some arguments are available on the stack */ |
|
|
| 7989 |
this.listLength++; |
| 7990 |
} |
7974 |
} |
| 7991 |
protected void consumeElidedLeftBraceAndReturn() { |
7975 |
protected void consumeElidedLeftBraceAndReturn() { |
| 7992 |
/* ElidedLeftBraceAndReturn ::= $empty |
7976 |
/* ElidedLeftBraceAndReturn ::= $empty |
|
Lines 10464-10470
Link Here
|
| 10464 |
this.referenceContext = null; |
10448 |
this.referenceContext = null; |
| 10465 |
this.endStatementPosition = 0; |
10449 |
this.endStatementPosition = 0; |
| 10466 |
this.valueLambdaNestDepth = -1; |
10450 |
this.valueLambdaNestDepth = -1; |
| 10467 |
|
10451 |
|
| 10468 |
//remove objects from stack too, while the same parser/compiler couple is |
10452 |
//remove objects from stack too, while the same parser/compiler couple is |
| 10469 |
//re-used between two compilations .... |
10453 |
//re-used between two compilations .... |
| 10470 |
|
10454 |
|
|
Lines 10797-10837
Link Here
|
| 10797 |
|
10781 |
|
| 10798 |
Though this code looks complex, we should exit early in most situations. |
10782 |
Though this code looks complex, we should exit early in most situations. |
| 10799 |
*/ |
10783 |
*/ |
| 10800 |
int lastAction = this.unstackedAct; |
10784 |
if (this.unstackedAct == ERROR_ACTION) { // automaton is not running. |
| 10801 |
if (lastAction == ERROR_ACTION) { // automaton is not running. |
|
|
| 10802 |
return false; |
10785 |
return false; |
| 10803 |
} |
10786 |
} |
| 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) { |
10787 |
if (token != TokenNameAT) { |
| 10809 |
token = token == TokenNameLPAREN ? TokenNameBeginLambda : TokenNameBeginTypeArguments; |
10788 |
token = token == TokenNameLPAREN ? TokenNameBeginLambda : TokenNameBeginTypeArguments; |
| 10810 |
} |
10789 |
} |
| 10811 |
|
10790 |
|
| 10812 |
// A rotated version of the automaton - cf. parse()'s for(;;) |
10791 |
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 |
} |
10792 |
} |
| 10836 |
/*main loop of the automat |
10793 |
/*main loop of the automat |
| 10837 |
When a rule is reduced, the method consumeRule(int) is called with the number |
10794 |
When a rule is reduced, the method consumeRule(int) is called with the number |
|
Lines 10852-10857
Link Here
|
| 10852 |
|
10809 |
|
| 10853 |
this.hasReportedError = false; |
10810 |
this.hasReportedError = false; |
| 10854 |
int act = START_STATE; |
10811 |
int act = START_STATE; |
|
|
10812 |
this.unstackedAct = ERROR_ACTION; |
| 10855 |
this.stateStackTop = -1; |
10813 |
this.stateStackTop = -1; |
| 10856 |
this.currentToken = getFirstToken(); |
10814 |
this.currentToken = getFirstToken(); |
| 10857 |
|
10815 |
|
|
Lines 10866-10873
Link Here
|
| 10866 |
stackLength); |
10824 |
stackLength); |
| 10867 |
} |
10825 |
} |
| 10868 |
this.stack[this.stateStackTop] = act; |
10826 |
this.stack[this.stateStackTop] = act; |
| 10869 |
|
10827 |
this.unstackedAct = act = tAction(act, this.currentToken); |
| 10870 |
act = tAction(act, this.currentToken); |
|
|
| 10871 |
if (act == ERROR_ACTION || this.restartRecovery) { |
10828 |
if (act == ERROR_ACTION || this.restartRecovery) { |
| 10872 |
if (DEBUG_AUTOMATON) { |
10829 |
if (DEBUG_AUTOMATON) { |
| 10873 |
if (this.restartRecovery) { |
10830 |
if (this.restartRecovery) { |
|
Lines 10879-10901
Link Here
|
| 10879 |
|
10836 |
|
| 10880 |
int errorPos = this.scanner.currentPosition - 1; |
10837 |
int errorPos = this.scanner.currentPosition - 1; |
| 10881 |
if (!this.hasReportedError) { |
10838 |
if (!this.hasReportedError) { |
| 10882 |
this.hasError = true; // looks incorrect for recovery case ? |
10839 |
this.hasError = true; |
| 10883 |
} |
10840 |
} |
| 10884 |
int previousToken = this.currentToken; |
10841 |
this.kurrentToken = this.currentToken; |
| 10885 |
switch (resumeOnSyntaxError()) { |
10842 |
switch (resumeOnSyntaxError()) { |
| 10886 |
case HALT: |
10843 |
case HALT: |
| 10887 |
act = ERROR_ACTION; |
10844 |
act = ERROR_ACTION; |
| 10888 |
break ProcessTerminals; |
10845 |
break ProcessTerminals; |
| 10889 |
case RESTART: |
10846 |
case RESTART: |
| 10890 |
if (act == ERROR_ACTION && previousToken != 0) this.lastErrorEndPosition = errorPos; |
10847 |
if (act == ERROR_ACTION && this.kurrentToken != 0) this.lastErrorEndPosition = errorPos; |
| 10891 |
act = START_STATE; |
10848 |
act = START_STATE; |
| 10892 |
this.stateStackTop = -1; |
10849 |
this.stateStackTop = -1; |
| 10893 |
this.currentToken = getFirstToken(); |
10850 |
this.currentToken = getFirstToken(); |
| 10894 |
continue ProcessTerminals; |
10851 |
continue ProcessTerminals; |
| 10895 |
case RESUME: |
10852 |
case RESUME: |
| 10896 |
break; // We presume the world is virgin so we can continue exactly from where we left off. |
10853 |
if (act == ERROR_ACTION) { |
| 10897 |
default: |
10854 |
act = this.stack[this.stateStackTop--]; |
| 10898 |
throw new IllegalStateException(); |
10855 |
continue ProcessTerminals; |
|
|
10856 |
} else { |
| 10857 |
this.currentToken = this.kurrentToken; // Gets trashed all over the place. |
| 10858 |
} |
| 10859 |
// FALL THROUGH. |
| 10899 |
} |
10860 |
} |
| 10900 |
} |
10861 |
} |
| 10901 |
if (act <= NUM_RULES) { |
10862 |
if (act <= NUM_RULES) { |
|
Lines 10914-10920
Link Here
|
| 10914 |
this.recordStringLiterals = oldValue; |
10875 |
this.recordStringLiterals = oldValue; |
| 10915 |
} |
10876 |
} |
| 10916 |
try { |
10877 |
try { |
| 10917 |
this.unstackedAct = act; |
|
|
| 10918 |
this.currentToken = this.scanner.getNextToken(); |
10878 |
this.currentToken = this.scanner.getNextToken(); |
| 10919 |
} catch(InvalidInputException e){ |
10879 |
} catch(InvalidInputException e){ |
| 10920 |
if (!this.hasReportedError){ |
10880 |
if (!this.hasReportedError){ |
|
Lines 10924-10936
Link Here
|
| 10924 |
this.lastCheckPoint = this.scanner.currentPosition; |
10884 |
this.lastCheckPoint = this.scanner.currentPosition; |
| 10925 |
this.currentToken = 0; |
10885 |
this.currentToken = 0; |
| 10926 |
this.restartRecovery = true; |
10886 |
this.restartRecovery = true; |
| 10927 |
} finally { |
10887 |
} |
| 10928 |
this.unstackedAct = ERROR_ACTION; |
|
|
| 10929 |
} |
| 10930 |
if(this.statementRecoveryActivated) { |
10888 |
if(this.statementRecoveryActivated) { |
| 10931 |
jumpOverType(); |
10889 |
jumpOverType(); |
| 10932 |
} |
10890 |
} |
| 10933 |
act -= ERROR_ACTION; |
10891 |
this.unstackedAct = act -= ERROR_ACTION; |
| 10934 |
|
10892 |
|
| 10935 |
if (DEBUG_AUTOMATON) { |
10893 |
if (DEBUG_AUTOMATON) { |
| 10936 |
System.out.print("Shift/Reduce - (" + name[terminal_index[this.currentToken]]+") "); //$NON-NLS-1$ //$NON-NLS-2$ |
10894 |
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; |
10904 |
this.recordStringLiterals = oldValue; |
| 10947 |
} |
10905 |
} |
| 10948 |
try{ |
10906 |
try{ |
| 10949 |
this.unstackedAct = act; |
|
|
| 10950 |
this.currentToken = this.scanner.getNextToken(); |
10907 |
this.currentToken = this.scanner.getNextToken(); |
| 10951 |
} catch(InvalidInputException e){ |
10908 |
} catch(InvalidInputException e){ |
| 10952 |
if (!this.hasReportedError){ |
10909 |
if (!this.hasReportedError){ |
|
Lines 10956-10963
Link Here
|
| 10956 |
this.lastCheckPoint = this.scanner.currentPosition; |
10913 |
this.lastCheckPoint = this.scanner.currentPosition; |
| 10957 |
this.currentToken = 0; |
10914 |
this.currentToken = 0; |
| 10958 |
this.restartRecovery = true; |
10915 |
this.restartRecovery = true; |
| 10959 |
} finally { |
|
|
| 10960 |
this.unstackedAct = ERROR_ACTION; |
| 10961 |
} |
10916 |
} |
| 10962 |
if(this.statementRecoveryActivated) { |
10917 |
if(this.statementRecoveryActivated) { |
| 10963 |
jumpOverType(); |
10918 |
jumpOverType(); |
|
Lines 10978-10985
Link Here
|
| 10978 |
} |
10933 |
} |
| 10979 |
|
10934 |
|
| 10980 |
this.stateStackTop -= (rhs[act] - 1); |
10935 |
this.stateStackTop -= (rhs[act] - 1); |
|
|
10936 |
this.unstackedAct = ntAction(this.stack[this.stateStackTop], lhs[act]); |
| 10981 |
consumeRule(act); |
10937 |
consumeRule(act); |
| 10982 |
act = ntAction(this.stack[this.stateStackTop], lhs[act]); |
10938 |
act = this.unstackedAct; |
| 10983 |
|
10939 |
|
| 10984 |
if (DEBUG_AUTOMATON) { |
10940 |
if (DEBUG_AUTOMATON) { |
| 10985 |
if (act <= NUM_RULES) { |
10941 |
if (act <= NUM_RULES) { |
|
Lines 10994-10999
Link Here
|
| 10994 |
} |
10950 |
} |
| 10995 |
} |
10951 |
} |
| 10996 |
} finally { |
10952 |
} finally { |
|
|
10953 |
this.unstackedAct = ERROR_ACTION; |
| 10997 |
this.scanner.setActiveParser(null); |
10954 |
this.scanner.setActiveParser(null); |
| 10998 |
} |
10955 |
} |
| 10999 |
|
10956 |
|
|
Lines 12164-12171
Link Here
|
| 12164 |
this.identifierPtr = -1; |
12121 |
this.identifierPtr = -1; |
| 12165 |
this.identifierLengthPtr = -1; |
12122 |
this.identifierLengthPtr = -1; |
| 12166 |
this.intPtr = -1; |
12123 |
this.intPtr = -1; |
|
|
12124 |
|
| 12167 |
this.nestedMethod[this.nestedType = 0] = 0; // need to reset for further reuse |
12125 |
this.nestedMethod[this.nestedType = 0] = 0; // need to reset for further reuse |
| 12168 |
this.variablesCounter[this.nestedType] = 0; |
12126 |
this.variablesCounter[this.nestedType] = 0; |
|
|
12127 |
|
| 12169 |
this.dimensions = 0 ; |
12128 |
this.dimensions = 0 ; |
| 12170 |
this.realBlockStack[this.realBlockPtr = 0] = 0; |
12129 |
this.realBlockStack[this.realBlockPtr = 0] = 0; |
| 12171 |
this.recoveredStaticInitializerStart = 0; |
12130 |
this.recoveredStaticInitializerStart = 0; |
|
Lines 12184-12190
Link Here
|
| 12184 |
* Move checkpoint location, reset internal stacks and |
12143 |
* Move checkpoint location, reset internal stacks and |
| 12185 |
* decide which grammar goal is activated. |
12144 |
* decide which grammar goal is activated. |
| 12186 |
*/ |
12145 |
*/ |
| 12187 |
protected boolean resumeAfterRecovery() { |
12146 |
protected int resumeAfterRecovery() { |
| 12188 |
if(!this.methodRecoveryActivated && !this.statementRecoveryActivated) { |
12147 |
if(!this.methodRecoveryActivated && !this.statementRecoveryActivated) { |
| 12189 |
|
12148 |
|
| 12190 |
// reset internal stacks |
12149 |
// reset internal stacks |
|
Lines 12193-12210
Link Here
|
| 12193 |
|
12152 |
|
| 12194 |
/* attempt to move checkpoint location */ |
12153 |
/* attempt to move checkpoint location */ |
| 12195 |
if (!moveRecoveryCheckpoint()) { |
12154 |
if (!moveRecoveryCheckpoint()) { |
| 12196 |
return false; |
12155 |
return HALT; |
| 12197 |
} |
12156 |
} |
| 12198 |
|
12157 |
|
| 12199 |
// only look for headers |
12158 |
// only look for headers |
| 12200 |
if (this.referenceContext instanceof CompilationUnitDeclaration){ |
12159 |
if (this.referenceContext instanceof CompilationUnitDeclaration){ |
| 12201 |
goForHeaders(); |
12160 |
goForHeaders(); |
| 12202 |
this.diet = true; // passed this point, will not consider method bodies |
12161 |
this.diet = true; // passed this point, will not consider method bodies |
| 12203 |
return true; |
12162 |
return RESTART; |
| 12204 |
} |
12163 |
} |
| 12205 |
|
12164 |
|
| 12206 |
// does not know how to restart |
12165 |
// does not know how to restart |
| 12207 |
return false; |
12166 |
return HALT; |
| 12208 |
} else if(!this.statementRecoveryActivated) { |
12167 |
} else if(!this.statementRecoveryActivated) { |
| 12209 |
|
12168 |
|
| 12210 |
// reset internal stacks |
12169 |
// reset internal stacks |
|
Lines 12213-12226
Link Here
|
| 12213 |
|
12172 |
|
| 12214 |
/* attempt to move checkpoint location */ |
12173 |
/* attempt to move checkpoint location */ |
| 12215 |
if (!moveRecoveryCheckpoint()) { |
12174 |
if (!moveRecoveryCheckpoint()) { |
| 12216 |
return false; |
12175 |
return HALT; |
| 12217 |
} |
12176 |
} |
| 12218 |
|
12177 |
|
| 12219 |
// only look for headers |
12178 |
// only look for headers |
| 12220 |
goForHeaders(); |
12179 |
goForHeaders(); |
| 12221 |
return true; |
12180 |
return RESTART; |
| 12222 |
} else { |
12181 |
} else { |
| 12223 |
return false; |
12182 |
return HALT; |
| 12224 |
} |
12183 |
} |
| 12225 |
} |
12184 |
} |
| 12226 |
protected int resumeOnSyntaxError() { |
12185 |
protected int resumeOnSyntaxError() { |
|
Lines 12260-12266
Link Here
|
| 12260 |
} |
12219 |
} |
| 12261 |
|
12220 |
|
| 12262 |
/* attempt to reset state in order to resume to parse loop */ |
12221 |
/* attempt to reset state in order to resume to parse loop */ |
| 12263 |
return resumeAfterRecovery() ? RESTART : HALT; |
12222 |
return resumeAfterRecovery(); |
| 12264 |
} |
12223 |
} |
| 12265 |
public void setMethodsFullRecovery(boolean enabled) { |
12224 |
public void setMethodsFullRecovery(boolean enabled) { |
| 12266 |
this.options.performMethodsFullRecovery = enabled; |
12225 |
this.options.performMethodsFullRecovery = enabled; |
|
Lines 12368-12371
Link Here
|
| 12368 |
exp.sourceEnd = this.intStack[this.intPtr--]; |
12327 |
exp.sourceEnd = this.intStack[this.intPtr--]; |
| 12369 |
exp.sourceStart = this.intStack[this.intPtr--]; |
12328 |
exp.sourceStart = this.intStack[this.intPtr--]; |
| 12370 |
} |
12329 |
} |
|
|
12330 |
public void copyState(CommitRollbackParser from) { |
| 12331 |
|
| 12332 |
Parser parser = (Parser) from; |
| 12333 |
|
| 12334 |
// Stack pointers. |
| 12335 |
|
| 12336 |
this.stateStackTop = parser.stateStackTop; |
| 12337 |
this.unstackedAct = parser.unstackedAct; |
| 12338 |
this.identifierPtr = parser.identifierPtr; |
| 12339 |
this.identifierLengthPtr = parser.identifierLengthPtr; |
| 12340 |
this.astPtr = parser.astPtr; |
| 12341 |
this.astLengthPtr = parser.astLengthPtr; |
| 12342 |
this.expressionPtr = parser.expressionPtr; |
| 12343 |
this.expressionLengthPtr = parser.expressionLengthPtr; |
| 12344 |
this.genericsPtr = parser.genericsPtr; |
| 12345 |
this.genericsLengthPtr = parser.genericsLengthPtr; |
| 12346 |
this.genericsIdentifiersLengthPtr = parser.genericsIdentifiersLengthPtr; |
| 12347 |
this.typeAnnotationPtr = parser.typeAnnotationPtr; |
| 12348 |
this.typeAnnotationLengthPtr = parser.typeAnnotationLengthPtr; |
| 12349 |
this.intPtr = parser.intPtr; |
| 12350 |
this.nestedType = parser.nestedType; |
| 12351 |
this.realBlockPtr = parser.realBlockPtr; |
| 12352 |
this.valueLambdaNestDepth = parser.valueLambdaNestDepth; |
| 12353 |
|
| 12354 |
// Stacks. |
| 12355 |
|
| 12356 |
int length; |
| 12357 |
System.arraycopy(parser.stack, 0, this.stack = new int [length = parser.stack.length], 0, length); |
| 12358 |
System.arraycopy(parser.identifierStack, 0, this.identifierStack = new char [length = parser.identifierStack.length][], 0, length); |
| 12359 |
System.arraycopy(parser.identifierLengthStack, 0, this.identifierLengthStack = new int [length = parser.identifierLengthStack.length], 0, length); |
| 12360 |
System.arraycopy(parser.identifierPositionStack, 0, this.identifierPositionStack = new long[length = parser.identifierPositionStack.length], 0, length); |
| 12361 |
System.arraycopy(parser.astStack, 0, this.astStack = new ASTNode [length = parser.astStack.length], 0, length); |
| 12362 |
System.arraycopy(parser.astLengthStack, 0, this.astLengthStack = new int [length = parser.astLengthStack.length], 0, length); |
| 12363 |
System.arraycopy(parser.expressionStack, 0, this.expressionStack = new Expression [length = parser.expressionStack.length], 0, length); |
| 12364 |
System.arraycopy(parser.expressionLengthStack, 0, this.expressionLengthStack = new int [length = parser.expressionLengthStack.length], 0, length); |
| 12365 |
System.arraycopy(parser.genericsStack, 0, this.genericsStack = new ASTNode [length = parser.genericsStack.length], 0, length); |
| 12366 |
System.arraycopy(parser.genericsLengthStack, 0, this.genericsLengthStack = new int [length = parser.genericsLengthStack.length], 0, length); |
| 12367 |
System.arraycopy(parser.genericsIdentifiersLengthStack, 0, this.genericsIdentifiersLengthStack = new int [length = parser.genericsIdentifiersLengthStack.length], 0, length); |
| 12368 |
System.arraycopy(parser.typeAnnotationStack, 0, this.typeAnnotationStack = new Annotation [length = parser.typeAnnotationStack.length], 0, length); |
| 12369 |
System.arraycopy(parser.typeAnnotationLengthStack, 0, this.typeAnnotationLengthStack = new int [length = parser.typeAnnotationLengthStack.length], 0, length); |
| 12370 |
System.arraycopy(parser.intStack, 0, this.intStack = new int [length = parser.intStack.length], 0, length); |
| 12371 |
System.arraycopy(parser.nestedMethod, 0, this.nestedMethod = new int [length = parser.nestedMethod.length], 0, length); |
| 12372 |
System.arraycopy(parser.realBlockStack, 0, this.realBlockStack = new int [length = parser.realBlockStack.length], 0, length); |
| 12373 |
System.arraycopy(parser.stateStackLengthStack, 0, this.stateStackLengthStack = new int [length = parser.stateStackLengthStack.length], 0, length); |
| 12374 |
System.arraycopy(parser.variablesCounter, 0, this.variablesCounter = new int [length = parser.variablesCounter.length], 0, length); |
| 12375 |
System.arraycopy(parser.stack, 0, this.stack = new int [length = parser.stack.length], 0, length); |
| 12376 |
System.arraycopy(parser.stack, 0, this.stack = new int [length = parser.stack.length], 0, length); |
| 12377 |
System.arraycopy(parser.stack, 0, this.stack = new int [length = parser.stack.length], 0, length); |
| 12378 |
|
| 12379 |
// Loose variables. |
| 12380 |
|
| 12381 |
this.listLength = parser.listLength; |
| 12382 |
this.listTypeParameterLength = parser.listTypeParameterLength; |
| 12383 |
this.dimensions = parser.dimensions; |
| 12384 |
this.recoveredStaticInitializerStart = parser.recoveredStaticInitializerStart; |
| 12385 |
|
| 12386 |
// Parser.resetStacks is not clearing the modifiers, but AssistParser.resumeAfterRecovery is - why ? (the former doesn't) |
| 12387 |
// this.modifiers = parser.modifiers; |
| 12388 |
// this.modifiersSourceStart = parser.modifiersSourceStart; |
| 12389 |
} |
| 12390 |
|
| 12391 |
public int automatonState() { |
| 12392 |
return this.stack[this.stateStackTop]; |
| 12393 |
} |
| 12394 |
public boolean automatonWillShift(int token, int lastAction) { |
| 12395 |
int stackTop = this.stateStackTop; // local copy of stack pointer |
| 12396 |
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. |
| 12397 |
int highWaterMark = stackTop; |
| 12398 |
// A rotated version of the automaton - cf. parse()'s for(;;) |
| 12399 |
for (;;) { |
| 12400 |
if (lastAction > ERROR_ACTION) { |
| 12401 |
lastAction -= ERROR_ACTION; /* shift-reduce on loop entry from above, reduce on loop back */ |
| 12402 |
do { /* reduce */ |
| 12403 |
stackTop -= rhs[lastAction] - 1; |
| 12404 |
if (stackTop < highWaterMark) { |
| 12405 |
stackTopState = this.stack[highWaterMark = stackTop]; |
| 12406 |
} // else stackTopState is upto date already. |
| 12407 |
lastAction = ntAction(stackTopState, lhs[lastAction]); |
| 12408 |
} while (lastAction <= NUM_RULES); |
| 12409 |
} |
| 12410 |
highWaterMark = ++stackTop; |
| 12411 |
stackTopState = lastAction; // "push" |
| 12412 |
lastAction = tAction(lastAction, token); // can be looked up from a precomputed cache. |
| 12413 |
if (lastAction <= NUM_RULES) { |
| 12414 |
stackTop --; |
| 12415 |
lastAction += ERROR_ACTION; |
| 12416 |
continue; |
| 12417 |
} |
| 12418 |
// Error => false, Shift, Shift/Reduce => true, Accept => impossible. |
| 12419 |
return lastAction != ERROR_ACTION; |
| 12420 |
} |
| 12421 |
} |
| 12371 |
} |
12422 |
} |