Fix an NPE when generating the error message for the case of multiple .locals or .registers directives in a method

git-svn-id: https://smali.googlecode.com/svn/trunk@722 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-04-18 19:33:07 +00:00
parent af7330e5d5
commit 9f69ec12ea
2 changed files with 15 additions and 3 deletions

View File

@ -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;
};

View File

@ -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;
}