diff --git a/smali/src/main/antlr3/org/jf/smali/smaliParser.g b/smali/src/main/antlr3/org/jf/smali/smaliParser.g index 0e16126a..d909f50f 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliParser.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliParser.g @@ -341,12 +341,12 @@ statements_and_directives registers_directive : ( - REGISTERS_DIRECTIVE regCount=integral_literal -> ^(I_REGISTERS[$REGISTERS_DIRECTIVE, "I_REGISTERS"] $regCount) - | LOCALS_DIRECTIVE regCount2=integral_literal -> ^(I_LOCALS[$LOCALS_DIRECTIVE, "I_LOCALS"] $regCount2) + directive=REGISTERS_DIRECTIVE regCount=integral_literal -> ^(I_REGISTERS[$REGISTERS_DIRECTIVE, "I_REGISTERS"] $regCount) + | directive=LOCALS_DIRECTIVE regCount2=integral_literal -> ^(I_LOCALS[$LOCALS_DIRECTIVE, "I_LOCALS"] $regCount2) ) { if ($statements_and_directives::hasRegistersDirective) { - throw new SemanticException(input, $registers_directive.tree, "There can only be a single .registers or .locals directive in a method"); + throw new SemanticException(input, $directive, "There can only be a single .registers or .locals directive in a method"); } $statements_and_directives::hasRegistersDirective=true; }; diff --git a/smali/src/main/java/org/jf/smali/SemanticException.java b/smali/src/main/java/org/jf/smali/SemanticException.java index fc67920d..73e4c9d8 100644 --- a/smali/src/main/java/org/jf/smali/SemanticException.java +++ b/smali/src/main/java/org/jf/smali/SemanticException.java @@ -28,8 +28,10 @@ package org.jf.smali; +import org.antlr.runtime.CommonToken; import org.antlr.runtime.IntStream; import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; import org.antlr.runtime.tree.CommonTree; public class SemanticException extends RecognitionException { @@ -56,6 +58,16 @@ public class SemanticException extends RecognitionException { this.errorMessage = String.format(errorMessage, messageArguments); } + SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { + super(); + this.input = input; + this.token = token; + this.index = ((CommonToken)token).getStartIndex(); + this.line = token.getLine(); + this.charPositionInLine = token.getCharPositionInLine(); + this.errorMessage = String.format(errorMessage, messageArguments); + } + public String getMessage() { return errorMessage; }