- changed the comment char from ; to #

- updated the tests and examples to use the new comment style
- changed the lexer error messages to include the source file path

git-svn-id: https://smali.googlecode.com/svn/trunk@83 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-04 05:54:34 +00:00
parent e53f5ae41b
commit 1834b365d6
12 changed files with 62 additions and 55 deletions

View File

@ -2,11 +2,11 @@
.super Ljava/lang/Object; .super Ljava/lang/Object;
;expected output: #expected output:
;@ClassAnnotation() #@ClassAnnotation()
;@MethodAnnotation() #@MethodAnnotation()
;@FieldAnnotation() #@FieldAnnotation()
;@ParameterAnnotation() #@ParameterAnnotation()
.method public static main([Ljava/lang/String;)V .method public static main([Ljava/lang/String;)V

View File

@ -38,9 +38,9 @@
.method public abstract methodValue()Ljava/lang/reflect/Method; .method public abstract methodValue()Ljava/lang/reflect/Method;
.end method .end method
;dalvik doesn't seem to like field values #dalvik doesn't seem to like field values
;.method public abstract fieldValue()Ljava/lang/reflect/Field; #.method public abstract fieldValue()Ljava/lang/reflect/Field;
;.end method #.end method
.method public abstract enumValue()LEnum; .method public abstract enumValue()LEnum;
.end method .end method

View File

@ -1,8 +1,8 @@
.class public LMain; .class public LMain;
.super Ljava/lang/Object; .super Ljava/lang/Object;
;expected output: #expected output:
;@AnnotationWithValues(booleanValue=false, byteValue=1, charValue=2, doubleValue=7.0, enumValue=12, floatValue=6.0, intValue=4, longValue=5, methodValue=public static void 10.11(), shortValue=3, stringValue=8, subAnnotationValue=@SubAnnotation(stringValue=9), typeValue=class 10) #@AnnotationWithValues(booleanValue=false, byteValue=1, charValue=2, doubleValue=7.0, enumValue=12, floatValue=6.0, intValue=4, longValue=5, methodValue=public static void 10.11(), shortValue=3, stringValue=8, subAnnotationValue=@SubAnnotation(stringValue=9), typeValue=class 10)
.method public static main([Ljava/lang/String;)V .method public static main([Ljava/lang/String;)V

View File

@ -1,8 +1,8 @@
.class public final enum LEnum; .class public final enum LEnum;
.super Ljava/lang/Enum; .super Ljava/lang/Enum;
;This class is an example of how to define an enum. You have #This class is an example of how to define an enum. You have
;to do all of the work that java normally takes care of #to do all of the work that java normally takes care of
.field private static final synthetic $VALUES:[LEnum; .field private static final synthetic $VALUES:[LEnum;
@ -12,37 +12,37 @@
.method static constructor <clinit>()V .method static constructor <clinit>()V
.registers 4 .registers 4
;create an instance of this class for the VALUE1 value #create an instance of this class for the VALUE1 value
new-instance v0, LEnum; new-instance v0, LEnum;
const-string v1, "VALUE1" const-string v1, "VALUE1"
const/4 v2, 0 const/4 v2, 0
invoke-direct {v0, v1, v2}, LEnum;-><init>(Ljava/lang/String;I)V invoke-direct {v0, v1, v2}, LEnum;-><init>(Ljava/lang/String;I)V
;and store it in VALUE1 #and store it in VALUE1
sput-object v0, LEnum;->VALUE1:LEnum; sput-object v0, LEnum;->VALUE1:LEnum;
;create an instance of this class for the VALUE2 value #create an instance of this class for the VALUE2 value
new-instance v0, LEnum; new-instance v0, LEnum;
const-string v1, "VALUE2" const-string v1, "VALUE2"
const/4 v3, 1 const/4 v3, 1
invoke-direct {v0, v1, v3}, LEnum;-><init>(Ljava/lang/String;I)V invoke-direct {v0, v1, v3}, LEnum;-><init>(Ljava/lang/String;I)V
;and store it in VALUE2 #and store it in VALUE2
sput-object v0, LEnum;->VALUE2:LEnum; sput-object v0, LEnum;->VALUE2:LEnum;
;create an array of Enums, for the $VALUES member #create an array of Enums, for the $VALUES member
const/4 v0, 2 const/4 v0, 2
new-array v0, v0, [LEnum; new-array v0, v0, [LEnum;
;add VALUE1 to the array #add VALUE1 to the array
sget-object v1, LEnum;->VALUE1:LEnum; sget-object v1, LEnum;->VALUE1:LEnum;
aput-object v1, v0, v2 aput-object v1, v0, v2
;add VALUE2 to the array #add VALUE2 to the array
sget-object v1, LEnum;->VALUE2:LEnum; sget-object v1, LEnum;->VALUE2:LEnum;
aput-object v1, v0, v3 aput-object v1, v0, v3
;and store the array in $VALUES #and store the array in $VALUES
sput-object v0, LEnum;->$VALUES:[LEnum; sput-object v0, LEnum;->$VALUES:[LEnum;
return-void return-void

View File

@ -1,12 +1,12 @@
.class public LHelloWorld; .class public LHelloWorld;
;Ye olde hello world application #Ye olde hello world application
;To assemble and run this on a phone or emulator: #To assemble and run this on a phone or emulator:
; #
;java -jar smali.jar --dex HelloWorld.smali #java -jar smali.jar --dex HelloWorld.smali
;zip HelloWorld.zip classes.dex #zip HelloWorld.zip classes.dex
;adb push HelloWorld.zip /data/local #adb push HelloWorld.zip /data/local
;adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld #adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
.super Ljava/lang/Object; .super Ljava/lang/Object;

View File

@ -1,8 +1,8 @@
.class public LMain; .class public LMain;
.super Ljava/lang/Object; .super Ljava/lang/Object;
;expected output (using the dalvik's default stack size) #expected output (using the dalvik's default stack size)
;@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=java.lang.StackOverflowError)))))))))))))))))))))))))))))) #@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=@RecursiveAnnotation(value=java.lang.StackOverflowError))))))))))))))))))))))))))))))
.method public static main([Ljava/lang/String;)V .method public static main([Ljava/lang/String;)V
.registers 3 .registers 3

View File

@ -2,9 +2,9 @@
.super Ljava/lang/Object; .super Ljava/lang/Object;
.implements Ljava/lang/annotation/Annotation; .implements Ljava/lang/annotation/Annotation;
;this is a recursive annotation that has a default value of itself. #this is a recursive annotation that has a default value of itself.
;Trying to print .toString() on an instance of this annotation #Trying to print .toString() on an instance of this annotation
;will cause a stack overflow #will cause a stack overflow
.method public abstract value()LRecursiveAnnotation; .method public abstract value()LRecursiveAnnotation;
.end method .end method

View File

@ -153,7 +153,6 @@ import java.util.ArrayDeque;
} }
catch (RecognitionException re) { catch (RecognitionException re) {
reportError(re); reportError(re);
// match() routine has already called recover()
} }
} }
} }
@ -176,6 +175,10 @@ import java.util.ArrayDeque;
token.setChannel(channel); token.setChannel(channel);
tokens.add(token); tokens.add(token);
} }
public String getErrorHeader(RecognitionException e) {
return getSourceName()+"["+ e.line+","+e.charPositionInLine+"]";
}
} }
@ -1413,12 +1416,12 @@ WHITE_SPACE
fragment LINE_COMMENT_EMIT fragment LINE_COMMENT_EMIT
: LINE_COMMENT2 {emit($LINE_COMMENT2, LINE_COMMENT, Token.HIDDEN_CHANNEL);}; : LINE_COMMENT2 {emit($LINE_COMMENT2, LINE_COMMENT, Token.HIDDEN_CHANNEL);};
fragment LINE_COMMENT2 fragment LINE_COMMENT2
: ';' ~('\n'|'\r')* ('\r\n' | '\r' | '\n'); : '#' ~('\n'|'\r')* ('\r\n' | '\r' | '\n');
LINE_COMMENT LINE_COMMENT
: (';' ~('\n'|'\r')* ('\r\n' | '\r' | '\n') : ('#' ~('\n'|'\r')* ('\r\n' | '\r' | '\n')
| ';' ~('\n'|'\r')*) | '#' ~('\n'|'\r')*)
{$channel = HIDDEN;}; {$channel = HIDDEN;};
fragment EQUAL_EMIT fragment EQUAL_EMIT

View File

@ -168,6 +168,8 @@ public class smali
private static void assembleSmaliFile(File smaliFile, DexFile dexFile) private static void assembleSmaliFile(File smaliFile, DexFile dexFile)
throws Exception { throws Exception {
ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile)); ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile));
input.name = smaliFile.getAbsolutePath();
smaliLexer lexer = new smaliLexer(input); smaliLexer lexer = new smaliLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer); CommonTokenStream tokens = new CommonTokenStream(lexer);

View File

@ -2,7 +2,7 @@
.super Ljava/lang/Object; .super Ljava/lang/Object;
.source "FieldTest.smali" .source "FieldTest.smali"
;this class tests that fields of various types are working #this class tests that fields of various types are working
.method public constructor <init>()V .method public constructor <init>()V
.registers 4 .registers 4
@ -37,10 +37,10 @@
const-string v0, "privateStringFieldValue" const-string v0, "privateStringFieldValue"
iput-object v0, v3, LFieldTest;->privateStringField:Ljava/lang/String; iput-object v0, v3, LFieldTest;->privateStringField:Ljava/lang/String;
const-string v0, "publicStaticStringFieldValue"; const-string v0, "publicStaticStringFieldValue"
sput-object v0, LFieldTest;->publicStaticStringField:Ljava/lang/String; sput-object v0, LFieldTest;->publicStaticStringField:Ljava/lang/String;
const-string v0, "privateStaticStringFieldValue"; const-string v0, "privateStaticStringFieldValue"
sput-object v0, LFieldTest;->privateStaticStringField:Ljava/lang/String; sput-object v0, LFieldTest;->privateStaticStringField:Ljava/lang/String;
return-void return-void

View File

@ -21,6 +21,8 @@
const-wide/16 v2, 12 const-wide/16 v2, 12
#the real test is that dalvik loaded and verified this class. This is
#mostly just to make sure that the method was actually called
invoke-static {v0, v1, v2, v3}, Lorg/junit/Assert;->assertEquals(JJ)V invoke-static {v0, v1, v2, v3}, Lorg/junit/Assert;->assertEquals(JJ)V
return-void return-void
@ -50,9 +52,9 @@ Label13:
const v1, 13 const v1, 13
return v1 return v1
;this nop de-aligns the following packed-switch data #this nop de-aligns the following packed-switch data
;smali should generate another nop before the packed-switch #smali should generate another nop before the packed-switch
;data to force alignment #data to force alignment
nop nop
PackedSwitch: PackedSwitch:

View File

@ -1,19 +1,19 @@
.class public LAllTests; .class public LAllTests;
.super Ljava/lang/Object; .super Ljava/lang/Object;
;This class is a wrapper for all the classes in the junit-tests directory #This class is a wrapper for all the classes in the junit-tests directory
; #
;To run the tests, you need to use dx on the junit jar and push that to the #To run the tests, you need to use dx on the junit jar and push that to the
;device/emulator, and then zip up the classes.dex containing this class #device/emulator, and then zip up the classes.dex containing this class
;and all of the tests and push that to the device/emulator. #and all of the tests and push that to the device/emulator.
; #
;dx --dex --output=classes.dex junit-4.6.jar #dx --dex --output=classes.dex junit-4.6.jar
;zip junit-4.6.zip classes.dex #zip junit-4.6.zip classes.dex
;adb push junit-4.6.zip /data/local #adb push junit-4.6.zip /data/local
;java -jar smali.jar --dex --output=classes.dex . #java -jar smali.jar --dex --output=classes.dex .
;zip smali-junit-tests.zip classes.dex #zip smali-junit-tests.zip classes.dex
;adb push smali-junit-tests.zip /data/local #adb push smali-junit-tests.zip /data/local
;adb shell dalvikvm -cp /data/local/junit-4.6.zip:/data/local/smali-junit-tests.zip org.junit.runner.JUnitCore AllTests #adb shell dalvikvm -cp /data/local/junit-4.6.zip:/data/local/smali-junit-tests.zip org.junit.runner.JUnitCore AllTests
.annotation runtime Lorg/junit/runner/RunWith; .annotation runtime Lorg/junit/runner/RunWith;
value = Lorg/junit/runners/Suite; value = Lorg/junit/runners/Suite;