Activate support for getting token names if debugging interpreter icode, not only when debugging parsing trees. Not to depend in TokenStream on Interpreter, printICode debug flag is moved to Context, as with printTrees definition.

Fixing debug printing of icode which are not defined in TokenStream


git-svn-id: svn://10.0.0.236/trunk@116731 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
igor%mir2.org
2002-03-17 03:34:43 +00:00
parent a959425539
commit 1a044d7dfe
3 changed files with 25 additions and 8 deletions

View File

@@ -1839,6 +1839,7 @@ public class Context {
// debug flags
static final boolean printTrees = false;
static final boolean printICode = false;
/**
* Compile a script.

View File

@@ -46,8 +46,6 @@ import org.mozilla.javascript.debug.*;
public class Interpreter extends LabelTable {
public static final boolean printICode = false;
// Additional interpreter-specific codes
static final int
// To indicating a line number change in icodes.
@@ -148,7 +146,7 @@ public class Interpreter extends LabelTable {
generateICodeFromTree(tree, varTable, activationNeeded, securityDomain);
itsData.itsNestedFunctions = itsNestedFunctions;
itsData.itsRegExpLiterals = regExpLiterals;
if (printICode) dumpICode(itsData);
if (Context.printICode) dumpICode(itsData);
String[] argNames = itsVariableTable.getAllNames();
short argCount = (short)itsVariableTable.getParameterCount();
@@ -207,7 +205,7 @@ public class Interpreter extends LabelTable {
itsData.itsSource = (String)theFunction.getProp(Node.SOURCE_PROP);
itsData.itsNestedFunctions = itsNestedFunctions;
itsData.itsRegExpLiterals = regExpLiterals;
if (printICode) dumpICode(itsData);
if (Context.printICode) dumpICode(itsData);
String[] argNames = itsVariableTable.getAllNames();
short argCount = (short)itsVariableTable.getParameterCount();
@@ -1174,7 +1172,7 @@ public class Interpreter extends LabelTable {
static PrintWriter out;
static {
if (printICode) {
if (Context.printICode) {
try {
out = new PrintWriter(new FileOutputStream("icode.txt"));
out.close();
@@ -1184,8 +1182,26 @@ public class Interpreter extends LabelTable {
}
}
private static String icodeToName(int icode) {
if (Context.printICode) {
if (icode <= TokenStream.LAST_TOKEN) {
return TokenStream.tokenToName(icode);
}else {
switch (icode) {
case LINE_ICODE: return "line";
case SOURCEFILE_ICODE: return "sourcefile";
case BREAKPOINT_ICODE: return "breakpoint";
case SHORTNUMBER_ICODE: return "shortnumber";
case INTNUMBER_ICODE: return "intnumber";
}
}
return "<UNKNOWN ICODE: "+icode+">";
}
return "";
}
private static void dumpICode(InterpreterData theData) {
if (printICode) {
if (Context.printICode) {
try {
int iCodeLength = theData.itsICodeTop;
byte iCode[] = theData.itsICode;
@@ -1199,7 +1215,7 @@ public class Interpreter extends LabelTable {
for (int pc = 0; pc < iCodeLength; ) {
out.print("[" + pc + "] ");
int token = iCode[pc] & 0xff;
String tname = TokenStream.tokenToName(token);
String tname = icodeToName(token);
++pc;
switch (token) {
case TokenStream.SCOPE :

View File

@@ -254,7 +254,7 @@ public class TokenStream {
public static String tokenToName(int token) {
if (Context.printTrees) {
if (Context.printTrees || Context.printICode) {
switch (token) {
case ERROR: return "error";
case EOF: return "eof";