Improve how method parameter lists are lexed

This commit is contained in:
Ben Gruver 2014-02-17 14:22:57 -08:00 committed by Connor Tumbleson
parent e1742d8547
commit b66bf0500b
6 changed files with 119 additions and 22 deletions

View File

@ -129,8 +129,10 @@ tokens {
OPEN_BRACE;
OPEN_PAREN;
PACKED_SWITCH_DIRECTIVE;
PARAM_LIST;
PARAM_LIST_OR_ID;
PARAM_LIST_END;
PARAM_LIST_START;
PARAM_LIST_OR_ID_END;
PARAM_LIST_OR_ID_START;
PARAMETER_DIRECTIVE;
POSITIVE_INTEGER_LITERAL;
PRIMITIVE_TYPE;
@ -530,6 +532,9 @@ registers_directive
$statements_and_directives::hasRegistersDirective=true;
};
param_list_or_id
: PARAM_LIST_OR_ID_START PRIMITIVE_TYPE+ PARAM_LIST_OR_ID_END;
/*identifiers are much more general than most languages. Any of the below can either be
the indicated type OR an identifier, depending on the context*/
simple_name
@ -543,7 +548,7 @@ simple_name
| BOOL_LITERAL -> SIMPLE_NAME[$BOOL_LITERAL]
| NULL_LITERAL -> SIMPLE_NAME[$NULL_LITERAL]
| REGISTER -> SIMPLE_NAME[$REGISTER]
| PARAM_LIST_OR_ID -> SIMPLE_NAME[$PARAM_LIST_OR_ID]
| param_list_or_id -> { adaptor.create(SIMPLE_NAME, $param_list_or_id.text) }
| PRIMITIVE_TYPE -> SIMPLE_NAME[$PRIMITIVE_TYPE]
| VOID_TYPE -> SIMPLE_NAME[$VOID_TYPE]
| ANNOTATION_VISIBILITY -> SIMPLE_NAME[$ANNOTATION_VISIBILITY]
@ -582,8 +587,8 @@ method_prototype
-> ^(I_METHOD_PROTOTYPE[$start, "I_METHOD_PROTOTYPE"] ^(I_METHOD_RETURN_TYPE type_descriptor) param_list?);
param_list
: PARAM_LIST -> { parseParamList((CommonToken)$PARAM_LIST) }
| PARAM_LIST_OR_ID -> { parseParamList((CommonToken)$PARAM_LIST_OR_ID) }
: PARAM_LIST_START nonvoid_type_descriptor* PARAM_LIST_END -> nonvoid_type_descriptor*
| PARAM_LIST_OR_ID_START PRIMITIVE_TYPE* PARAM_LIST_OR_ID_END -> PRIMITIVE_TYPE*
| nonvoid_type_descriptor*;
type_descriptor

View File

@ -465,10 +465,10 @@ method returns[BuilderMethod ret]
};
method_prototype returns[List<String> parameters, String returnType]
: ^(I_METHOD_PROTOTYPE ^(I_METHOD_RETURN_TYPE type_descriptor) field_type_list)
: ^(I_METHOD_PROTOTYPE ^(I_METHOD_RETURN_TYPE type_descriptor) method_type_list)
{
$returnType = $type_descriptor.type;
$parameters = $field_type_list.types;
$parameters = $method_type_list.types;
};
method_name_and_prototype returns[String name, List<SmaliMethodParameter> parameters, String returnType]
@ -488,7 +488,7 @@ method_name_and_prototype returns[String name, List<SmaliMethodParameter> parame
$returnType = $method_prototype.returnType;
};
field_type_list returns[List<String> types]
method_type_list returns[List<String> types]
@init
{
$types = Lists.newArrayList();

View File

@ -222,6 +222,8 @@ ArrayDescriptor = "[" + ({PrimitiveType} | {ClassDescriptor})
Type = {PrimitiveType} | {ClassDescriptor} | {ArrayDescriptor}
%state PARAM_LIST_OR_ID
%state PARAM_LIST
%state STRING
%state CHAR
@ -289,6 +291,20 @@ Type = {PrimitiveType} | {ClassDescriptor} | {ArrayDescriptor}
' { beginStringOrChar(CHAR); sb.append('\''); }
}
<PARAM_LIST_OR_ID> {
{PrimitiveType} { return newToken(PRIMITIVE_TYPE); }
[^] { yypushback(1); yybegin(YYINITIAL); return newToken(PARAM_LIST_OR_ID_END); }
<<EOF>> { yybegin(YYINITIAL); return newToken(PARAM_LIST_OR_ID_END); }
}
<PARAM_LIST> {
{PrimitiveType} { return newToken(PRIMITIVE_TYPE); }
{ClassDescriptor} { return newToken(CLASS_DESCRIPTOR); }
{ArrayDescriptor} { return newToken(ARRAY_DESCRIPTOR); }
[^] { yypushback(1); yybegin(YYINITIAL); return newToken(PARAM_LIST_END); }
<<EOF>> { yybegin(YYINITIAL); return newToken(PARAM_LIST_END); }
}
<STRING> {
"\"" { sb.append('"'); return endStringOrChar(STRING_LITERAL); }
@ -587,8 +603,19 @@ Type = {PrimitiveType} | {ClassDescriptor} | {ArrayDescriptor}
V { return newToken(VOID_TYPE); }
{ClassDescriptor} { return newToken(CLASS_DESCRIPTOR); }
{ArrayDescriptor} { return newToken(ARRAY_DESCRIPTOR); }
{PrimitiveType} {PrimitiveType}+ { return newToken(PARAM_LIST_OR_ID); }
{Type} {Type}+ { return newToken(PARAM_LIST); }
{PrimitiveType} {PrimitiveType}+ {
yypushback(yylength());
yybegin(PARAM_LIST_OR_ID);
return newToken(PARAM_LIST_OR_ID_START);
}
{Type} {Type}+ {
yypushback(yylength());
yybegin(PARAM_LIST);
return newToken(PARAM_LIST_START);
}
{SimpleName} { return newToken(SIMPLE_NAME); }
"<" {SimpleName} ">" { return newToken(MEMBER_NAME); }
}

View File

@ -552,7 +552,13 @@ METHOD_DIRECTIVE(".method")
ACCESS_SPEC("public")
SIMPLE_NAME("setCallForwardingOption")
OPEN_PAREN("(")
PARAM_LIST("IILjava/lang/String;ILandroid/os/Message;")
PARAM_LIST_START("")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("Ljava/lang/String;")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("Landroid/os/Message;")
PARAM_LIST_END("")
CLOSE_PAREN(")")
VOID_TYPE("V")
REGISTERS_DIRECTIVE(".registers")
@ -697,7 +703,12 @@ CLASS_DESCRIPTOR("Lcom/android/internal/telephony/gsm/GSMPhone$MyHandler;")
ARROW("->")
SIMPLE_NAME("obtainMessage")
OPEN_PAREN("(")
PARAM_LIST("IIILjava/lang/Object;")
PARAM_LIST_START("")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("Ljava/lang/Object;")
PARAM_LIST_END("")
CLOSE_PAREN(")")
CLASS_DESCRIPTOR("Landroid/os/Message;")
INSTRUCTION_FORMAT11x("move-result-object")
@ -749,7 +760,14 @@ CLASS_DESCRIPTOR("Lcom/android/internal/telephony/CommandsInterface;")
ARROW("->")
SIMPLE_NAME("setCallForward")
OPEN_PAREN("(")
PARAM_LIST("IIILjava/lang/String;ILandroid/os/Message;")
PARAM_LIST_START("")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("Ljava/lang/String;")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("Landroid/os/Message;")
PARAM_LIST_END("")
CLOSE_PAREN(")")
VOID_TYPE("V")
LINE_DIRECTIVE(".line")

View File

@ -47,4 +47,6 @@ L[Ljava/lang/String;
[java/lang/String;
[;
<linit>
<linit>
III

View File

@ -24,13 +24,52 @@ ARRAY_DESCRIPTOR("[D")
ARRAY_DESCRIPTOR("[Ljava/lang/String;")
ARRAY_DESCRIPTOR("[LI/I/I;")
PARAM_LIST_OR_ID("IIIII")
PARAM_LIST_OR_ID("ZBSCIJFD")
PARAM_LIST("ILa;[La;[I")
PARAM_LIST("Ljava/lang/String;Ljava/lang/String;")
PARAM_LIST("[I[I[I")
PARAM_LIST("[I[Z")
PARAM_LIST("[I[Ljava/lang/String;")
PARAM_LIST_OR_ID_START("")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PARAM_LIST_OR_ID_END("")
PARAM_LIST_OR_ID_START("")
PRIMITIVE_TYPE("Z")
PRIMITIVE_TYPE("B")
PRIMITIVE_TYPE("S")
PRIMITIVE_TYPE("C")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("J")
PRIMITIVE_TYPE("F")
PRIMITIVE_TYPE("D")
PARAM_LIST_OR_ID_END("")
PARAM_LIST_START("")
PRIMITIVE_TYPE("I")
CLASS_DESCRIPTOR("La;")
ARRAY_DESCRIPTOR("[La;")
ARRAY_DESCRIPTOR("[I")
PARAM_LIST_END("")
PARAM_LIST_START("")
CLASS_DESCRIPTOR("Ljava/lang/String;")
CLASS_DESCRIPTOR("Ljava/lang/String;")
PARAM_LIST_END("")
PARAM_LIST_START("")
ARRAY_DESCRIPTOR("[I")
ARRAY_DESCRIPTOR("[I")
ARRAY_DESCRIPTOR("[I")
PARAM_LIST_END("")
PARAM_LIST_START("")
ARRAY_DESCRIPTOR("[I")
ARRAY_DESCRIPTOR("[Z")
PARAM_LIST_END("")
PARAM_LIST_START("")
ARRAY_DESCRIPTOR("[I")
ARRAY_DESCRIPTOR("[Ljava/lang/String;")
PARAM_LIST_END("")
MEMBER_NAME("<init>")
MEMBER_NAME("<clinit>")
@ -47,4 +86,10 @@ INVALID_TOKEN("[") VOID_TYPE("V")
INVALID_TOKEN("[") SIMPLE_NAME("java") INVALID_TOKEN("/") SIMPLE_NAME("lang") INVALID_TOKEN("/") SIMPLE_NAME("String") INVALID_TOKEN(";")
INVALID_TOKEN("[") INVALID_TOKEN(";")
MEMBER_NAME("<linit>")
MEMBER_NAME("<linit>")
PARAM_LIST_OR_ID_START("")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PRIMITIVE_TYPE("I")
PARAM_LIST_OR_ID_END("")