Pass Decompiler object as an argument for Parser.parse instead of creating an instance there for better flexibility.

This commit is contained in:
igor%mir2.org 2003-08-08 15:42:19 +00:00
parent 6d6c104572
commit 5523fffb09
2 changed files with 7 additions and 14 deletions

View File

@ -854,8 +854,9 @@ public class Context {
Interpreter compiler = new Interpreter();
IRFactory irf = compiler.createIRFactory(this, ts);
Parser p = createParser();
Decompiler decompiler = new Decompiler();
try {
p.parse(ts, irf);
p.parse(ts, irf, decompiler);
} catch (IOException ioe) {
errorseen = true;
} catch (EvaluatorException ee) {
@ -1926,7 +1927,8 @@ public class Context {
errorCount = 0;
IRFactory irf = compiler.createIRFactory(this, ts);
ScriptOrFnNode tree = p.parse(ts, irf);
Decompiler decompiler = new Decompiler();
ScriptOrFnNode tree = p.parse(ts, irf, decompiler);
if (tree == null)
return null;

View File

@ -95,10 +95,11 @@ class Parser {
* parse failure will result in a call to the current Context's
* ErrorReporter.)
*/
public ScriptOrFnNode parse(TokenStream ts, IRFactory nf)
public ScriptOrFnNode parse(TokenStream ts, IRFactory nf,
Decompiler decompiler)
throws IOException
{
this.decompiler = new Decompiler();
this.decompiler = decompiler;
decompiler.startScript();
this.nf = nf;
@ -1398,16 +1399,6 @@ class Parser {
return null; // should never reach here
}
static String decompile(Object encodedSourcesTree,
int indent, boolean justbody)
{
final int INDENT_GAP = 4;
final int CASE_GAP = 2; // less how much for case labels
return Decompiler.decompile(encodedSourcesTree,
justbody, indent, INDENT_GAP, CASE_GAP);
}
private IRFactory nf;
private int languageVersion = Context.VERSION_DEFAULT;
private boolean allowMemberExprAsFunctionName = false;