Improve error recovery when missing an .end sparse-switch

This commit is contained in:
Ben Gruver 2015-03-06 19:32:21 -08:00
parent 3abee993db
commit 698b799e4f
3 changed files with 72 additions and 1 deletions

View File

@ -1342,7 +1342,15 @@ packed_switch_element
insn_sparse_switch_directive
: SPARSE_SWITCH_DIRECTIVE
sparse_switch_element*
END_SPARSE_SWITCH_DIRECTIVE;
end_sparse_switch_directive;
end_sparse_switch_directive
: END_SPARSE_SWITCH_DIRECTIVE;
catch [RecognitionException re] {
Marker errorMarker = mark();
recover(input, re);
reportError(errorMarker, re, false);
}
sparse_switch_element
@init { Marker marker = mark(); }

View File

@ -20,4 +20,12 @@ invoke-virtual {v1, v2} .blah Lblah;->blah()V
:blah
:blah2
.blah
.end method
.method blah5()V
.sparse-switch
1 -> :blah
3 -> :blah2
5 -> :blah3
.blah
.end method

View File

@ -178,4 +178,59 @@ smali.FILE
PsiErrorElement:mismatched input '.blah' expecting END_PACKED_SWITCH_DIRECTIVE
PsiElement(BAD_CHARACTER)('.blah')
PsiWhiteSpace('\n')
PsiElement(END_METHOD_DIRECTIVE)('.end method')
PsiWhiteSpace('\n\n')
SmaliMethod(METHOD)
SmaliThrowsList(THROWS_LIST)
<empty list>
PsiElement(METHOD_DIRECTIVE)('.method')
PsiWhiteSpace(' ')
SmaliModifierList(MODIFIER_LIST)
<empty list>
PsiElement(MEMBER_NAME)
PsiElement(SIMPLE_NAME)('blah5')
SmaliMethodPrototype(METHOD_PROTOTYPE)
PsiElement(OPEN_PAREN)('(')
SmaliMethodParamList(METHOD_PARAM_LIST)
<empty list>
PsiElement(CLOSE_PAREN)(')')
PsiElement(VOID_TYPE)
PsiElement(VOID_TYPE)('V')
PsiWhiteSpace('\n ')
PsiElement(INSTRUCTION)
PsiElement(SPARSE_SWITCH_DIRECTIVE)('.sparse-switch')
PsiWhiteSpace('\n ')
PsiElement(SPARSE_SWITCH_ELEMENT)
PsiElement(LITERAL)
PsiElement(POSITIVE_INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
PsiElement(ARROW)('->')
PsiWhiteSpace(' ')
PsiElement(LABEL_REFERENCE)
PsiElement(COLON)(':')
PsiElement(SIMPLE_NAME)('blah')
PsiWhiteSpace('\n ')
PsiElement(SPARSE_SWITCH_ELEMENT)
PsiElement(LITERAL)
PsiElement(POSITIVE_INTEGER_LITERAL)('3')
PsiWhiteSpace(' ')
PsiElement(ARROW)('->')
PsiWhiteSpace(' ')
PsiElement(LABEL_REFERENCE)
PsiElement(COLON)(':')
PsiElement(SIMPLE_NAME)('blah2')
PsiWhiteSpace('\n ')
PsiElement(SPARSE_SWITCH_ELEMENT)
PsiElement(LITERAL)
PsiElement(POSITIVE_INTEGER_LITERAL)('5')
PsiWhiteSpace(' ')
PsiElement(ARROW)('->')
PsiWhiteSpace(' ')
PsiElement(LABEL_REFERENCE)
PsiElement(COLON)(':')
PsiElement(SIMPLE_NAME)('blah3')
PsiWhiteSpace('\n ')
PsiErrorElement:mismatched input '.blah' expecting END_SPARSE_SWITCH_DIRECTIVE
PsiElement(BAD_CHARACTER)('.blah')
PsiWhiteSpace('\n')
PsiElement(END_METHOD_DIRECTIVE)('.end method')