From 3abee993dbd8d8217caaf44159e115873420bfd9 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Fri, 6 Mar 2015 19:27:46 -0800 Subject: [PATCH] Improve error recovery when missing an .end packed-switch --- smalidea/src/main/antlr3/smalideaParser.g | 10 ++++- smalidea/testData/InvalidInstruction.smalidea | 7 ++++ smalidea/testData/InvalidInstruction.txt | 38 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g index ea3369d4..d22288d1 100644 --- a/smalidea/src/main/antlr3/smalideaParser.g +++ b/smalidea/src/main/antlr3/smalideaParser.g @@ -1320,7 +1320,15 @@ insn_packed_switch_directive : PACKED_SWITCH_DIRECTIVE fixed_32bit_literal packed_switch_element* - END_PACKED_SWITCH_DIRECTIVE; + end_packed_switch_directive; + +end_packed_switch_directive + : END_PACKED_SWITCH_DIRECTIVE; + catch [RecognitionException re] { + Marker errorMarker = mark(); + recover(input, re); + reportError(errorMarker, re, false); + } packed_switch_element @init { Marker marker = mark(); } diff --git a/smalidea/testData/InvalidInstruction.smalidea b/smalidea/testData/InvalidInstruction.smalidea index 98552503..44c52f02 100644 --- a/smalidea/testData/InvalidInstruction.smalidea +++ b/smalidea/testData/InvalidInstruction.smalidea @@ -13,4 +13,11 @@ invoke-virtual {v1, v2} .blah Lblah;->blah()V 1 2 .blah +.end method + +.method blah4()V + .packed-switch 1 + :blah + :blah2 + .blah .end method \ No newline at end of file diff --git a/smalidea/testData/InvalidInstruction.txt b/smalidea/testData/InvalidInstruction.txt index 197c68c4..dd4696ec 100644 --- a/smalidea/testData/InvalidInstruction.txt +++ b/smalidea/testData/InvalidInstruction.txt @@ -140,4 +140,42 @@ smali.FILE PsiErrorElement:mismatched input '.blah' expecting END_ARRAY_DATA_DIRECTIVE PsiElement(BAD_CHARACTER)('.blah') PsiWhiteSpace('\n') + PsiElement(END_METHOD_DIRECTIVE)('.end method') + PsiWhiteSpace('\n\n') + SmaliMethod(METHOD) + SmaliThrowsList(THROWS_LIST) + + PsiElement(METHOD_DIRECTIVE)('.method') + PsiWhiteSpace(' ') + SmaliModifierList(MODIFIER_LIST) + + PsiElement(MEMBER_NAME) + PsiElement(SIMPLE_NAME)('blah4') + SmaliMethodPrototype(METHOD_PROTOTYPE) + PsiElement(OPEN_PAREN)('(') + SmaliMethodParamList(METHOD_PARAM_LIST) + + PsiElement(CLOSE_PAREN)(')') + PsiElement(VOID_TYPE) + PsiElement(VOID_TYPE)('V') + PsiWhiteSpace('\n ') + PsiElement(INSTRUCTION) + PsiElement(PACKED_SWITCH_DIRECTIVE)('.packed-switch') + PsiWhiteSpace(' ') + PsiElement(LITERAL) + PsiElement(POSITIVE_INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + PsiElement(PACKED_SWITCH_ELEMENT) + PsiElement(LABEL_REFERENCE) + PsiElement(COLON)(':') + PsiElement(SIMPLE_NAME)('blah') + PsiWhiteSpace('\n ') + PsiElement(PACKED_SWITCH_ELEMENT) + PsiElement(LABEL_REFERENCE) + PsiElement(COLON)(':') + PsiElement(SIMPLE_NAME)('blah2') + PsiWhiteSpace('\n ') + PsiErrorElement:mismatched input '.blah' expecting END_PACKED_SWITCH_DIRECTIVE + PsiElement(BAD_CHARACTER)('.blah') + PsiWhiteSpace('\n') PsiElement(END_METHOD_DIRECTIVE)('.end method') \ No newline at end of file