mirror of
https://github.com/revanced/smali.git
synced 2025-05-05 09:04:25 +02:00
Don't generate verbose parser errors by default, but add a smali parameter to enable them
git-svn-id: https://smali.googlecode.com/svn/trunk@723 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
9f69ec12ea
commit
86df593d85
@ -135,14 +135,23 @@ import org.jf.dexlib.Code.Format.*;
|
|||||||
|
|
||||||
|
|
||||||
@members {
|
@members {
|
||||||
|
private boolean verboseErrors = false;
|
||||||
|
|
||||||
|
public void setVerboseErrors(boolean verboseErrors) {
|
||||||
|
this.verboseErrors = verboseErrors;
|
||||||
|
}
|
||||||
|
|
||||||
public String getErrorMessage(RecognitionException e,
|
public String getErrorMessage(RecognitionException e,
|
||||||
String[] tokenNames)
|
String[] tokenNames) {
|
||||||
{
|
if (!verboseErrors) {
|
||||||
|
return super.getErrorMessage(e, tokenNames);
|
||||||
|
}
|
||||||
|
|
||||||
List stack = getRuleInvocationStack(e, this.getClass().getName());
|
List stack = getRuleInvocationStack(e, this.getClass().getName());
|
||||||
String msg = null;
|
String msg = null;
|
||||||
if ( e instanceof NoViableAltException ) {
|
if ( e instanceof NoViableAltException ) {
|
||||||
NoViableAltException nvae = (NoViableAltException)e;
|
NoViableAltException nvae = (NoViableAltException)e;
|
||||||
msg = " no viable alt; token="+e.token+
|
msg = " no viable alt; token="+getTokenErrorDisplay(e.token)+
|
||||||
" (decision="+nvae.decisionNumber+
|
" (decision="+nvae.decisionNumber+
|
||||||
" state "+nvae.stateNumber+")"+
|
" state "+nvae.stateNumber+")"+
|
||||||
" decision=<<"+nvae.grammarDecisionDescription+">>";
|
" decision=<<"+nvae.grammarDecisionDescription+">>";
|
||||||
@ -154,7 +163,38 @@ import org.jf.dexlib.Code.Format.*;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getTokenErrorDisplay(Token t) {
|
public String getTokenErrorDisplay(Token t) {
|
||||||
return t.toString();
|
if (!verboseErrors) {
|
||||||
|
String s = t.getText();
|
||||||
|
if ( s==null ) {
|
||||||
|
if ( t.getType()==Token.EOF ) {
|
||||||
|
s = "<EOF>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
s = "<"+tokenNames[t.getType()]+">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s = s.replaceAll("\n","\\\\n");
|
||||||
|
s = s.replaceAll("\r","\\\\r");
|
||||||
|
s = s.replaceAll("\t","\\\\t");
|
||||||
|
return "'"+s+"'";
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonToken ct = (CommonToken)t;
|
||||||
|
|
||||||
|
String channelStr = "";
|
||||||
|
if (t.getChannel()>0) {
|
||||||
|
channelStr=",channel="+t.getChannel();
|
||||||
|
}
|
||||||
|
String txt = t.getText();
|
||||||
|
if ( txt!=null ) {
|
||||||
|
txt = txt.replaceAll("\n","\\\\n");
|
||||||
|
txt = txt.replaceAll("\r","\\\\r");
|
||||||
|
txt = txt.replaceAll("\t","\\\\t");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
txt = "<no text>";
|
||||||
|
}
|
||||||
|
return "[@"+t.getTokenIndex()+","+ct.getStartIndex()+":"+ct.getStopIndex()+"='"+txt+"',<"+tokenNames[t.getType()]+">"+channelStr+","+t.getLine()+":"+t.getCharPositionInLine()+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getErrorHeader(RecognitionException e) {
|
public String getErrorHeader(RecognitionException e) {
|
||||||
|
@ -97,6 +97,7 @@ public class main {
|
|||||||
boolean sort = false;
|
boolean sort = false;
|
||||||
boolean fixStringConst = true;
|
boolean fixStringConst = true;
|
||||||
boolean fixGoto = true;
|
boolean fixGoto = true;
|
||||||
|
boolean verboseErrors = false;
|
||||||
|
|
||||||
String outputDexFile = "out.dex";
|
String outputDexFile = "out.dex";
|
||||||
String dumpFileName = null;
|
String dumpFileName = null;
|
||||||
@ -137,6 +138,9 @@ public class main {
|
|||||||
case 'G':
|
case 'G':
|
||||||
fixGoto = false;
|
fixGoto = false;
|
||||||
break;
|
break;
|
||||||
|
case 'V':
|
||||||
|
verboseErrors = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
@ -169,7 +173,7 @@ public class main {
|
|||||||
boolean errors = false;
|
boolean errors = false;
|
||||||
|
|
||||||
for (File file: filesToProcess) {
|
for (File file: filesToProcess) {
|
||||||
if (!assembleSmaliFile(file, dexFile)) {
|
if (!assembleSmaliFile(file, dexFile, verboseErrors)) {
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +249,7 @@ public class main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean assembleSmaliFile(File smaliFile, DexFile dexFile)
|
private static boolean assembleSmaliFile(File smaliFile, DexFile dexFile, boolean verboseErrors)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile), "UTF8");
|
ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(smaliFile), "UTF8");
|
||||||
input.name = smaliFile.getAbsolutePath();
|
input.name = smaliFile.getAbsolutePath();
|
||||||
@ -254,6 +258,7 @@ public class main {
|
|||||||
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
smaliParser parser = new smaliParser(tokens);
|
smaliParser parser = new smaliParser(tokens);
|
||||||
|
parser.setVerboseErrors(verboseErrors);
|
||||||
|
|
||||||
smaliParser.smali_file_return result = parser.smali_file();
|
smaliParser.smali_file_return result = parser.smali_file();
|
||||||
|
|
||||||
@ -346,6 +351,10 @@ public class main {
|
|||||||
.withDescription("Don't replace goto type instructions with a larger version where appropriate")
|
.withDescription("Don't replace goto type instructions with a larger version where appropriate")
|
||||||
.create("G");
|
.create("G");
|
||||||
|
|
||||||
|
Option verboseErrorsOption = OptionBuilder.withLongOpt("verbose-errors")
|
||||||
|
.withDescription("Generate verbose error messages")
|
||||||
|
.create("V");
|
||||||
|
|
||||||
basicOptions.addOption(versionOption);
|
basicOptions.addOption(versionOption);
|
||||||
basicOptions.addOption(helpOption);
|
basicOptions.addOption(helpOption);
|
||||||
basicOptions.addOption(outputOption);
|
basicOptions.addOption(outputOption);
|
||||||
@ -354,6 +363,7 @@ public class main {
|
|||||||
debugOptions.addOption(sortOption);
|
debugOptions.addOption(sortOption);
|
||||||
debugOptions.addOption(noFixStringConstOption);
|
debugOptions.addOption(noFixStringConstOption);
|
||||||
debugOptions.addOption(noFixGotoOption);
|
debugOptions.addOption(noFixGotoOption);
|
||||||
|
debugOptions.addOption(verboseErrorsOption);
|
||||||
|
|
||||||
for (Object option: basicOptions.getOptions()) {
|
for (Object option: basicOptions.getOptions()) {
|
||||||
options.addOption((Option)option);
|
options.addOption((Option)option);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user