Move the totalMethodRegisters calculation back up to when the rule is matched, because the value is needed for subsequent rules

git-svn-id: https://smali.googlecode.com/svn/trunk@720 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-04-18 19:32:59 +00:00
parent 4d9801a89d
commit cafef597c9

View File

@ -487,7 +487,15 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
methodParameterRegisters++; methodParameterRegisters++;
} }
} }
registers_directive? ( registers_directive
{
if ($registers_directive.isLocalsDirective) {
totalMethodRegisters = $registers_directive.registers + methodParameterRegisters;
} else {
totalMethodRegisters = $registers_directive.registers;
}
}
)?
labels labels
packed_switch_declarations packed_switch_declarations
sparse_switch_declarations sparse_switch_declarations
@ -505,7 +513,7 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
DebugInfoItem debugInfoItem = $method::debugInfo.encodeDebugInfo(dexFile); DebugInfoItem debugInfoItem = $method::debugInfo.encodeDebugInfo(dexFile);
CodeItem codeItem; CodeItem codeItem;
boolean isAbstract = false; boolean isAbstract = false;
boolean isNative = false; boolean isNative = false;
@ -519,14 +527,14 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
if (!isAbstract && !isNative) { if (!isAbstract && !isNative) {
throw new SemanticException(input, $I_METHOD, "A non-abstract/non-native method must have at least 1 instruction"); throw new SemanticException(input, $I_METHOD, "A non-abstract/non-native method must have at least 1 instruction");
} }
String methodType; String methodType;
if (isAbstract) { if (isAbstract) {
methodType = "an abstract"; methodType = "an abstract";
} else { } else {
methodType = "a native"; methodType = "a native";
} }
if ($registers_directive.start != null) { if ($registers_directive.start != null) {
if ($registers_directive.isLocalsDirective) { if ($registers_directive.isLocalsDirective) {
throw new SemanticException(input, $registers_directive.start, "A .locals directive is not valid in \%s method", methodType); throw new SemanticException(input, $registers_directive.start, "A .locals directive is not valid in \%s method", methodType);
@ -543,10 +551,10 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
throw new SemanticException(input, $I_METHOD, "try/catch blocks cannot be present in \%s method", methodType); throw new SemanticException(input, $I_METHOD, "try/catch blocks cannot be present in \%s method", methodType);
} }
if (debugInfoItem != null) { if (debugInfoItem != null) {
throw new SemanticException(input, $I_METHOD, "debug directives cannot be present in \%s method", methodType); throw new SemanticException(input, $I_METHOD, "debug directives cannot be present in \%s method", methodType);
} }
codeItem = null; codeItem = null;
} else { } else {
if (isAbstract) { if (isAbstract) {
@ -555,17 +563,11 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
if (isNative) { if (isNative) {
throw new SemanticException(input, $I_METHOD, "A native method cannot have any instructions"); throw new SemanticException(input, $I_METHOD, "A native method cannot have any instructions");
} }
if ($registers_directive.start == null) { if ($registers_directive.start == null) {
throw new SemanticException(input, $I_METHOD, "A .registers or .locals directive must be present for a non-abstract/non-final method"); throw new SemanticException(input, $I_METHOD, "A .registers or .locals directive must be present for a non-abstract/non-final method");
} }
if ($registers_directive.isLocalsDirective) {
totalMethodRegisters = $registers_directive.registers + methodParameterRegisters;
} else {
totalMethodRegisters = $registers_directive.registers;
}
if (totalMethodRegisters < methodParameterRegisters) { if (totalMethodRegisters < methodParameterRegisters) {
throw new SemanticException(input, $registers_directive.start, "This method requires at least " + throw new SemanticException(input, $registers_directive.start, "This method requires at least " +
Integer.toString(methodParameterRegisters) + Integer.toString(methodParameterRegisters) +