Add support for reporting of the source file name from the lexer, to be used for error messages

git-svn-id: https://smali.googlecode.com/svn/trunk@755 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-06-13 20:34:29 +00:00
parent 9ac6fa5048
commit 1c42f47ada
2 changed files with 14 additions and 2 deletions

View File

@ -276,6 +276,7 @@ public class main {
InputStreamReader reader = new InputStreamReader(fis, "UTF-8"); InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
lexer = new smaliFlexLexer(reader); lexer = new smaliFlexLexer(reader);
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource)lexer); tokens = new CommonTokenStream((TokenSource)lexer);
} }

View File

@ -1,7 +1,8 @@
package org.jf.smali; package org.jf.smali;
import java.io.*;
import org.antlr.runtime.*; import org.antlr.runtime.*;
import org.jf.util.*;
import static org.jf.smali.smaliParser.*; import static org.jf.smali.smaliParser.*;
%% %%
@ -25,6 +26,8 @@ import static org.jf.smali.smaliParser.*;
private int lexerErrors = 0; private int lexerErrors = 0;
private File sourceFile;
public Token nextToken() { public Token nextToken() {
try { try {
Token token = yylex(); Token token = yylex();
@ -55,8 +58,16 @@ import static org.jf.smali.smaliParser.*;
return this.yycolumn; return this.yycolumn;
} }
public void setSourceFile(File sourceFile) {
this.sourceFile = sourceFile;
}
public String getSourceName() { public String getSourceName() {
return ""; try {
return PathUtil.getRelativeFile(new File("."), sourceFile).getPath();
} catch (IOException ex) {
return sourceFile.getAbsolutePath();
}
} }
public int getNumberOfSyntaxErrors() { public int getNumberOfSyntaxErrors() {