Lines 58-63
Link Here
|
58 |
public static short check_table[] = null; |
58 |
public static short check_table[] = null; |
59 |
public static final int CurlyBracket = 2; |
59 |
public static final int CurlyBracket = 2; |
60 |
private static final boolean DEBUG = false; |
60 |
private static final boolean DEBUG = false; |
|
|
61 |
private static final boolean DEBUG_AUTOMATON = false; |
61 |
private static final String EOF_TOKEN = "$eof" ; //$NON-NLS-1$ |
62 |
private static final String EOF_TOKEN = "$eof" ; //$NON-NLS-1$ |
62 |
private static final String ERROR_TOKEN = "$error" ; //$NON-NLS-1$ |
63 |
private static final String ERROR_TOKEN = "$error" ; //$NON-NLS-1$ |
63 |
//expression stack |
64 |
//expression stack |
Lines 189-194
Link Here
|
189 |
protected TypeDeclaration[] recoveredTypes; |
190 |
protected TypeDeclaration[] recoveredTypes; |
190 |
protected int recoveredTypePtr; |
191 |
protected int recoveredTypePtr; |
191 |
protected int nextTypeStart; |
192 |
protected int nextTypeStart; |
|
|
193 |
protected TypeDeclaration pendingRecoveredType; |
192 |
|
194 |
|
193 |
public RecoveryScanner recoveryScanner; |
195 |
public RecoveryScanner recoveryScanner; |
194 |
|
196 |
|
Lines 1052-1057
Link Here
|
1052 |
} |
1054 |
} |
1053 |
} |
1055 |
} |
1054 |
} |
1056 |
} |
|
|
1057 |
|
1058 |
if (this.statementRecoveryActivated) { |
1059 |
if (this.pendingRecoveredType != null && |
1060 |
this.scanner.startPosition - 1 <= this.pendingRecoveredType.declarationSourceEnd) { |
1061 |
// Add the pending type to the AST if this type isn't already added in the AST. |
1062 |
element = element.add(this.pendingRecoveredType, 0); |
1063 |
this.lastCheckPoint = this.pendingRecoveredType.declarationSourceEnd + 1; |
1064 |
this.pendingRecoveredType = null; |
1065 |
} |
1066 |
} |
1055 |
return element; |
1067 |
return element; |
1056 |
} |
1068 |
} |
1057 |
|
1069 |
|
Lines 1487-1492
Link Here
|
1487 |
this.expressionStack[this.expressionPtr] , |
1499 |
this.expressionStack[this.expressionPtr] , |
1488 |
this.expressionStack[this.expressionPtr+1], |
1500 |
this.expressionStack[this.expressionPtr+1], |
1489 |
this.scanner.startPosition - 1); |
1501 |
this.scanner.startPosition - 1); |
|
|
1502 |
|
1503 |
if (this.pendingRecoveredType != null) { |
1504 |
// Used only in statements recovery. |
1505 |
// This is not a real assignment but a placeholder for an existing anonymous type. |
1506 |
// The assignment must be replace by the anonymous type. |
1507 |
if (this.pendingRecoveredType.allocation != null && |
1508 |
this.scanner.startPosition - 1 <= this.pendingRecoveredType.declarationSourceEnd) { |
1509 |
this.expressionStack[this.expressionPtr] = this.pendingRecoveredType.allocation; |
1510 |
this.pendingRecoveredType = null; |
1511 |
return; |
1512 |
} |
1513 |
this.pendingRecoveredType = null; |
1514 |
} |
1490 |
} |
1515 |
} |
1491 |
protected void consumeAssignmentOperator(int pos) { |
1516 |
protected void consumeAssignmentOperator(int pos) { |
1492 |
// AssignmentOperator ::= '=' |
1517 |
// AssignmentOperator ::= '=' |
Lines 6630-6635
Link Here
|
6630 |
// break pushs a position on this.intStack in case there is no label |
6655 |
// break pushs a position on this.intStack in case there is no label |
6631 |
|
6656 |
|
6632 |
pushOnAstStack(new BreakStatement(null, this.intStack[this.intPtr--], this.endPosition)); |
6657 |
pushOnAstStack(new BreakStatement(null, this.intStack[this.intPtr--], this.endPosition)); |
|
|
6658 |
|
6659 |
if (this.pendingRecoveredType != null) { |
6660 |
// Used only in statements recovery. |
6661 |
// This is not a real break statement but a placeholder for an existing local type. |
6662 |
// The break statement must be replace by the local type. |
6663 |
if (this.pendingRecoveredType.allocation == null && |
6664 |
this.endPosition <= this.pendingRecoveredType.declarationSourceEnd) { |
6665 |
this.astStack[this.astPtr] = this.pendingRecoveredType; |
6666 |
this.pendingRecoveredType = null; |
6667 |
return; |
6668 |
} |
6669 |
this.pendingRecoveredType = null; |
6670 |
} |
6633 |
} |
6671 |
} |
6634 |
protected void consumeStatementBreakWithLabel() { |
6672 |
protected void consumeStatementBreakWithLabel() { |
6635 |
// BreakStatement ::= 'break' Identifier ';' |
6673 |
// BreakStatement ::= 'break' Identifier ';' |
Lines 8582-8625
Link Here
|
8582 |
} |
8620 |
} |
8583 |
private void jumpOverType(){ |
8621 |
private void jumpOverType(){ |
8584 |
if (this.recoveredTypes != null && this.nextTypeStart > -1 && this.nextTypeStart < this.scanner.currentPosition) { |
8622 |
if (this.recoveredTypes != null && this.nextTypeStart > -1 && this.nextTypeStart < this.scanner.currentPosition) { |
|
|
8623 |
|
8624 |
if (DEBUG_AUTOMATON) { |
8625 |
System.out.println("Jump -"); //$NON-NLS-1$ |
8626 |
} |
8627 |
|
8585 |
TypeDeclaration typeDeclaration = this.recoveredTypes[this.recoveredTypePtr]; |
8628 |
TypeDeclaration typeDeclaration = this.recoveredTypes[this.recoveredTypePtr]; |
8586 |
boolean isAnonymous = typeDeclaration.allocation != null; |
8629 |
boolean isAnonymous = typeDeclaration.allocation != null; |
8587 |
|
8630 |
|
8588 |
int end = this.scanner.eofPosition; |
8631 |
int end = this.scanner.eofPosition; |
8589 |
this.scanner.resetTo(typeDeclaration.declarationSourceEnd + 1, end - 1); |
8632 |
this.scanner.resetTo(typeDeclaration.declarationSourceEnd + 1, end - 1); |
8590 |
if(!isAnonymous) { |
8633 |
if(!isAnonymous) { |
8591 |
pushOnAstStack(typeDeclaration); |
8634 |
((RecoveryScanner)this.scanner).setPendingTokens(new int[]{TokenNameSEMICOLON, TokenNamebreak}); |
8592 |
if(this.astLengthPtr > 0) { |
|
|
8593 |
concatNodeLists(); |
8594 |
} |
8595 |
|
8596 |
if(this.currentElement != null) { |
8597 |
this.currentElement = this.currentElement.add(typeDeclaration, 0); |
8598 |
} |
8599 |
|
8600 |
try { |
8601 |
this.currentToken = this.scanner.getNextToken(); |
8602 |
} catch(InvalidInputException e){ |
8603 |
if (!this.hasReportedError){ |
8604 |
this.problemReporter().scannerError(this, e.getMessage()); |
8605 |
this.hasReportedError = true; |
8606 |
} |
8607 |
this.lastCheckPoint = this.scanner.currentPosition; |
8608 |
} |
8609 |
} else { |
8635 |
} else { |
8610 |
if(this.astPtr > -1 && this.astStack[this.astPtr] instanceof TypeDeclaration) { |
8636 |
((RecoveryScanner)this.scanner).setPendingTokens(new int[]{TokenNameIdentifier, TokenNameEQUAL, TokenNameIdentifier}); |
8611 |
this.astStack[astPtr] = typeDeclaration; |
8637 |
} |
8612 |
this.expressionStack[this.expressionPtr] = typeDeclaration.allocation; |
8638 |
|
8613 |
} |
8639 |
this.pendingRecoveredType = typeDeclaration; |
8614 |
this.currentToken = TokenNameRBRACE; |
8640 |
|
|
|
8641 |
try { |
8642 |
this.currentToken = this.scanner.getNextToken(); |
8643 |
} catch(InvalidInputException e){ |
8644 |
// it's impossible because we added pending tokens before |
8615 |
} |
8645 |
} |
8616 |
|
8646 |
|
8617 |
if(++this.recoveredTypePtr < this.recoveredTypes.length) { |
8647 |
if(++this.recoveredTypePtr < this.recoveredTypes.length) { |
8618 |
TypeDeclaration nextTypeDeclaration = this.recoveredTypes[this.recoveredTypePtr]; |
8648 |
TypeDeclaration nextTypeDeclaration = this.recoveredTypes[this.recoveredTypePtr]; |
8619 |
this.nextTypeStart = |
8649 |
this.nextTypeStart = |
8620 |
nextTypeDeclaration.allocation == null |
8650 |
nextTypeDeclaration.allocation == null |
8621 |
? nextTypeDeclaration.declarationSourceStart |
8651 |
? nextTypeDeclaration.declarationSourceStart |
8622 |
: nextTypeDeclaration.bodyStart; |
8652 |
: nextTypeDeclaration.allocation.sourceStart; |
8623 |
} else { |
8653 |
} else { |
8624 |
this.nextTypeStart = Integer.MAX_VALUE; |
8654 |
this.nextTypeStart = Integer.MAX_VALUE; |
8625 |
} |
8655 |
} |
Lines 8831-8838
Link Here
|
8831 |
// name[symbol_index[currentKind]] |
8861 |
// name[symbol_index[currentKind]] |
8832 |
protected void parse() { |
8862 |
protected void parse() { |
8833 |
if (DEBUG) System.out.println("-- ENTER INSIDE PARSE METHOD --"); //$NON-NLS-1$ |
8863 |
if (DEBUG) System.out.println("-- ENTER INSIDE PARSE METHOD --"); //$NON-NLS-1$ |
|
|
8864 |
|
8865 |
if (DEBUG_AUTOMATON) { |
8866 |
System.out.println("- Start --------------------------------"); //$NON-NLS-1$ |
8867 |
} |
8868 |
|
8834 |
boolean isDietParse = this.diet; |
8869 |
boolean isDietParse = this.diet; |
8835 |
boolean jumpOverTypeAfterReduce = false; |
|
|
8836 |
int oldFirstToken = getFirstToken(); |
8870 |
int oldFirstToken = getFirstToken(); |
8837 |
this.hasError = false; |
8871 |
this.hasError = false; |
8838 |
|
8872 |
|
Lines 8852-8857
Link Here
|
8852 |
|
8886 |
|
8853 |
act = tAction(act, this.currentToken); |
8887 |
act = tAction(act, this.currentToken); |
8854 |
if (act == ERROR_ACTION || this.restartRecovery) { |
8888 |
if (act == ERROR_ACTION || this.restartRecovery) { |
|
|
8889 |
|
8890 |
if (DEBUG_AUTOMATON) { |
8891 |
if (this.restartRecovery) { |
8892 |
System.out.println("Restart - "); //$NON-NLS-1$ |
8893 |
} else { |
8894 |
System.out.println("Error - "); //$NON-NLS-1$ |
8895 |
} |
8896 |
} |
8897 |
|
8855 |
int errorPos = this.scanner.currentPosition; |
8898 |
int errorPos = this.scanner.currentPosition; |
8856 |
if (!this.hasReportedError) { |
8899 |
if (!this.hasReportedError) { |
8857 |
this.hasError = true; |
8900 |
this.hasError = true; |
Lines 8868-8874
Link Here
|
8868 |
} |
8911 |
} |
8869 |
if (act <= NUM_RULES) { |
8912 |
if (act <= NUM_RULES) { |
8870 |
this.stateStackTop--; |
8913 |
this.stateStackTop--; |
8871 |
|
8914 |
|
|
|
8915 |
if (DEBUG_AUTOMATON) { |
8916 |
System.out.print("Reduce - "); //$NON-NLS-1$ |
8917 |
} |
8918 |
|
8872 |
} else if (act > ERROR_ACTION) { /* shift-reduce */ |
8919 |
} else if (act > ERROR_ACTION) { /* shift-reduce */ |
8873 |
consumeToken(this.currentToken); |
8920 |
consumeToken(this.currentToken); |
8874 |
if (this.currentElement != null) this.recoveryTokenCheck(); |
8921 |
if (this.currentElement != null) this.recoveryTokenCheck(); |
Lines 8883-8892
Link Here
|
8883 |
this.restartRecovery = true; |
8930 |
this.restartRecovery = true; |
8884 |
} |
8931 |
} |
8885 |
if(this.statementRecoveryActivated) { |
8932 |
if(this.statementRecoveryActivated) { |
8886 |
jumpOverTypeAfterReduce = true; |
8933 |
this.jumpOverType(); |
8887 |
} |
8934 |
} |
8888 |
act -= ERROR_ACTION; |
8935 |
act -= ERROR_ACTION; |
8889 |
|
8936 |
|
|
|
8937 |
if (DEBUG_AUTOMATON) { |
8938 |
System.out.print("Shift/Reduce - (" + name[terminal_index[this.currentToken]]+") "); //$NON-NLS-1$ //$NON-NLS-2$ |
8939 |
} |
8940 |
|
8890 |
} else { |
8941 |
} else { |
8891 |
if (act < ACCEPT_ACTION) { /* shift */ |
8942 |
if (act < ACCEPT_ACTION) { /* shift */ |
8892 |
consumeToken(this.currentToken); |
8943 |
consumeToken(this.currentToken); |
Lines 8904-8909
Link Here
|
8904 |
if(this.statementRecoveryActivated) { |
8955 |
if(this.statementRecoveryActivated) { |
8905 |
this.jumpOverType(); |
8956 |
this.jumpOverType(); |
8906 |
} |
8957 |
} |
|
|
8958 |
if (DEBUG_AUTOMATON) { |
8959 |
System.out.println("Shift - (" + name[terminal_index[this.currentToken]]+")"); //$NON-NLS-1$ //$NON-NLS-2$ |
8960 |
} |
8907 |
continue ProcessTerminals; |
8961 |
continue ProcessTerminals; |
8908 |
} |
8962 |
} |
8909 |
break ProcessTerminals; |
8963 |
break ProcessTerminals; |
Lines 8911-8927
Link Here
|
8911 |
|
8965 |
|
8912 |
// ProcessNonTerminals : |
8966 |
// ProcessNonTerminals : |
8913 |
do { /* reduce */ |
8967 |
do { /* reduce */ |
|
|
8968 |
|
8969 |
if (DEBUG_AUTOMATON) { |
8970 |
System.out.println(name[non_terminal_index[lhs[act]]]); |
8971 |
} |
8972 |
|
8914 |
consumeRule(act); |
8973 |
consumeRule(act); |
8915 |
this.stateStackTop -= (rhs[act] - 1); |
8974 |
this.stateStackTop -= (rhs[act] - 1); |
8916 |
act = ntAction(this.stack[this.stateStackTop], lhs[act]); |
8975 |
act = ntAction(this.stack[this.stateStackTop], lhs[act]); |
8917 |
if(this.statementRecoveryActivated && act > NUM_RULES) { |
8976 |
|
8918 |
if(jumpOverTypeAfterReduce) { |
8977 |
if (DEBUG_AUTOMATON && act <= NUM_RULES) { |
8919 |
this.jumpOverType(); |
8978 |
System.out.print(" - "); //$NON-NLS-1$ |
8920 |
jumpOverTypeAfterReduce = false; |
|
|
8921 |
} |
8922 |
} |
8979 |
} |
|
|
8980 |
|
8923 |
} while (act <= NUM_RULES); |
8981 |
} while (act <= NUM_RULES); |
|
|
8982 |
|
8983 |
if (DEBUG_AUTOMATON) { |
8984 |
System.out.println("----------------------------------------"); //$NON-NLS-1$ |
8985 |
} |
8986 |
} |
8987 |
|
8988 |
if (DEBUG_AUTOMATON) { |
8989 |
System.out.println("- End ----------------------------------"); //$NON-NLS-1$ |
8924 |
} |
8990 |
} |
|
|
8991 |
|
8925 |
endParse(act); |
8992 |
endParse(act); |
8926 |
// record all nls tags in the corresponding compilation unit |
8993 |
// record all nls tags in the corresponding compilation unit |
8927 |
final NLSTag[] tags = this.scanner.getNLSTags(); |
8994 |
final NLSTag[] tags = this.scanner.getNLSTags(); |
Lines 9367-9379
Link Here
|
9367 |
this.referenceContext = rc; |
9434 |
this.referenceContext = rc; |
9368 |
this.compilationUnit = unit; |
9435 |
this.compilationUnit = unit; |
9369 |
|
9436 |
|
|
|
9437 |
this.pendingRecoveredType = null; |
9438 |
|
9370 |
if(types != null && types.length > 0) { |
9439 |
if(types != null && types.length > 0) { |
9371 |
this.recoveredTypes = types; |
9440 |
this.recoveredTypes = types; |
9372 |
this.recoveredTypePtr = 0; |
9441 |
this.recoveredTypePtr = 0; |
9373 |
this.nextTypeStart = |
9442 |
this.nextTypeStart = |
9374 |
this.recoveredTypes[0].allocation == null |
9443 |
this.recoveredTypes[0].allocation == null |
9375 |
? this.recoveredTypes[0].declarationSourceStart |
9444 |
? this.recoveredTypes[0].declarationSourceStart |
9376 |
: this.recoveredTypes[0].bodyStart; |
9445 |
: this.recoveredTypes[0].allocation.sourceStart; |
9377 |
} else { |
9446 |
} else { |
9378 |
this.recoveredTypes = null; |
9447 |
this.recoveredTypes = null; |
9379 |
this.recoveredTypePtr = -1; |
9448 |
this.recoveredTypePtr = -1; |
Lines 9976-9981
Link Here
|
9976 |
// Reset javadoc before restart parsing after recovery |
10045 |
// Reset javadoc before restart parsing after recovery |
9977 |
this.javadoc = null; |
10046 |
this.javadoc = null; |
9978 |
|
10047 |
|
|
|
10048 |
// do not investigate deeper in statement recovery |
10049 |
if (this.statementRecoveryActivated) return false; |
10050 |
|
9979 |
// build some recovered elements |
10051 |
// build some recovered elements |
9980 |
this.currentElement = buildInitialRecoveryState(); |
10052 |
this.currentElement = buildInitialRecoveryState(); |
9981 |
} |
10053 |
} |