зеркало из https://github.com/mozilla/pjs.git
Replacing state flags in TokenStream by separated boolean values to simplify
code and to remove flags that were set/cleared but never queried.
This commit is contained in:
Родитель
860281245c
Коммит
6cda148128
|
@ -587,7 +587,7 @@ final class IRFactory
|
|||
*/
|
||||
Node createWith(Node obj, Node body, int lineno)
|
||||
{
|
||||
setRequiresActivation();
|
||||
parser.setRequiresActivation();
|
||||
Node result = new Node(Token.BLOCK, lineno);
|
||||
result.addChildToBack(new Node(Token.ENTERWITH, obj));
|
||||
Node bodyNode = new Node(Token.WITH, body, lineno);
|
||||
|
@ -791,7 +791,7 @@ final class IRFactory
|
|||
Node node = new Node(nodeType, child);
|
||||
if (type != Node.NON_SPECIALCALL) {
|
||||
// Calls to these functions require activation objects.
|
||||
setRequiresActivation();
|
||||
parser.setRequiresActivation();
|
||||
node.putIntProp(Node.SPECIALCALL_PROP, type);
|
||||
}
|
||||
return node;
|
||||
|
@ -1113,8 +1113,8 @@ final class IRFactory
|
|||
|
||||
private void checkActivationName(String name, int token)
|
||||
{
|
||||
boolean activation = false;
|
||||
if (parser.currentScriptOrFn.getType() == Token.FUNCTION) {
|
||||
if (parser.insideFunction()) {
|
||||
boolean activation = false;
|
||||
if ("arguments".equals(name)
|
||||
|| (parser.compilerEnv.activationNames != null
|
||||
&& parser.compilerEnv.activationNames.containsKey(name)))
|
||||
|
@ -1129,16 +1129,9 @@ final class IRFactory
|
|||
activation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activation) {
|
||||
((FunctionNode)parser.currentScriptOrFn).setRequiresActivation();
|
||||
}
|
||||
}
|
||||
|
||||
private void setRequiresActivation()
|
||||
{
|
||||
if (parser.currentScriptOrFn.getType() == Token.FUNCTION) {
|
||||
((FunctionNode)parser.currentScriptOrFn).setRequiresActivation();
|
||||
if (activation) {
|
||||
parser.setRequiresActivation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,9 +144,9 @@ public class Parser
|
|||
|
||||
try {
|
||||
for (;;) {
|
||||
ts.flags |= TokenStream.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
int tt = ts.getToken();
|
||||
ts.flags &= ~TokenStream.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
|
||||
if (tt <= Token.EOF) {
|
||||
break;
|
||||
|
@ -205,6 +205,18 @@ public class Parser
|
|||
return ts.eof();
|
||||
}
|
||||
|
||||
boolean insideFunction()
|
||||
{
|
||||
return nestingOfFunction != 0;
|
||||
}
|
||||
|
||||
void setRequiresActivation()
|
||||
{
|
||||
if (insideFunction()) {
|
||||
((FunctionNode)currentScriptOrFn).setRequiresActivation();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The C version of this function takes an argument list,
|
||||
* which doesn't seem to be needed for tree generation...
|
||||
|
@ -214,11 +226,7 @@ public class Parser
|
|||
private Node parseFunctionBody()
|
||||
throws IOException
|
||||
{
|
||||
int oldflags = ts.flags;
|
||||
ts.flags &= ~(TokenStream.TSF_RETURN_EXPR
|
||||
| TokenStream.TSF_RETURN_VOID);
|
||||
ts.flags |= TokenStream.TSF_FUNCTION;
|
||||
|
||||
++nestingOfFunction;
|
||||
Node pn = nf.createBlock(ts.getLineno());
|
||||
try {
|
||||
int tt;
|
||||
|
@ -235,10 +243,7 @@ public class Parser
|
|||
} catch (ParserException e) {
|
||||
this.ok = false;
|
||||
} finally {
|
||||
// also in finally block:
|
||||
// flushNewLines, clearPushback.
|
||||
|
||||
ts.flags = oldflags;
|
||||
--nestingOfFunction;
|
||||
}
|
||||
|
||||
return pn;
|
||||
|
@ -286,7 +291,7 @@ public class Parser
|
|||
decompiler.addToken(Token.ASSIGN);
|
||||
}
|
||||
|
||||
boolean nested = (currentScriptOrFn.type == Token.FUNCTION);
|
||||
boolean nested = insideFunction();
|
||||
|
||||
FunctionNode fnNode = nf.createFunction(name);
|
||||
if (nested) {
|
||||
|
@ -816,23 +821,19 @@ public class Parser
|
|||
|
||||
decompiler.addToken(Token.RETURN);
|
||||
|
||||
// bail if we're not in a (toplevel) function
|
||||
if ((ts.flags & ts.TSF_FUNCTION) == 0)
|
||||
if (!insideFunction())
|
||||
reportError("msg.bad.return");
|
||||
|
||||
/* This is ugly, but we don't want to require a semicolon. */
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
tt = ts.peekTokenSameLine();
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
|
||||
int lineno = ts.getLineno();
|
||||
if (tt != Token.EOF && tt != Token.EOL && tt != Token.SEMI && tt != Token.RC) {
|
||||
retExpr = expr(false);
|
||||
if (ts.getLineno() == lineno)
|
||||
checkWellTerminated();
|
||||
ts.flags |= ts.TSF_RETURN_EXPR;
|
||||
} else {
|
||||
ts.flags |= ts.TSF_RETURN_VOID;
|
||||
}
|
||||
|
||||
// XXX ASSERT pn
|
||||
|
@ -1186,9 +1187,9 @@ public class Parser
|
|||
{
|
||||
int tt;
|
||||
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
tt = ts.getToken();
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
|
||||
switch(tt) {
|
||||
case Token.VOID:
|
||||
|
@ -1253,9 +1254,9 @@ public class Parser
|
|||
throws IOException, ParserException
|
||||
{
|
||||
boolean matched;
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
matched = ts.matchToken(Token.RP);
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
if (!matched) {
|
||||
boolean first = true;
|
||||
do {
|
||||
|
@ -1278,9 +1279,9 @@ public class Parser
|
|||
Node pn;
|
||||
|
||||
/* Check for new expressions. */
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
tt = ts.peekToken();
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
if (tt == Token.NEW) {
|
||||
/* Eat the NEW token. */
|
||||
ts.getToken();
|
||||
|
@ -1360,9 +1361,9 @@ public class Parser
|
|||
|
||||
Node pn;
|
||||
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
tt = ts.getToken();
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
|
||||
switch(tt) {
|
||||
|
||||
|
@ -1376,9 +1377,9 @@ public class Parser
|
|||
decompiler.addToken(Token.LB);
|
||||
boolean after_lb_or_comma = true;
|
||||
for (;;) {
|
||||
ts.flags |= ts.TSF_REGEXP;
|
||||
ts.allowRegExp = true;
|
||||
tt = ts.peekToken();
|
||||
ts.flags &= ~ts.TSF_REGEXP;
|
||||
ts.allowRegExp = false;
|
||||
|
||||
if (tt == Token.COMMA) {
|
||||
ts.getToken();
|
||||
|
@ -1529,8 +1530,9 @@ public class Parser
|
|||
|
||||
private boolean ok; // Did the parse encounter an error?
|
||||
|
||||
ScriptOrFnNode currentScriptOrFn;
|
||||
private ScriptOrFnNode currentScriptOrFn;
|
||||
|
||||
private int nestingOfFunction;
|
||||
private int nestingOfWith;
|
||||
|
||||
private Decompiler decompiler;
|
||||
|
|
|
@ -53,20 +53,6 @@ import java.io.*;
|
|||
|
||||
public class TokenStream
|
||||
{
|
||||
/*
|
||||
* JSTokenStream flags, mirroring those in jsscan.h. These are used
|
||||
* by the parser to change/check the state of the scanner.
|
||||
*/
|
||||
|
||||
final static int
|
||||
TSF_NEWLINES = 1 << 0, // tokenize newlines
|
||||
TSF_FUNCTION = 1 << 1, // scanning inside function body
|
||||
TSF_RETURN_EXPR = 1 << 2, // function has 'return expr;'
|
||||
TSF_RETURN_VOID = 1 << 3, // function has 'return;'
|
||||
TSF_REGEXP = 1 << 4, // looking for a regular expression
|
||||
TSF_DIRTYLINE = 1 << 5; // stuff other than whitespace since
|
||||
// start of line
|
||||
|
||||
/*
|
||||
* For chars - because we need something out-of-range
|
||||
* to check. (And checking EOF by exception is annoying.)
|
||||
|
@ -83,7 +69,6 @@ public class TokenStream
|
|||
this.pushbackToken = Token.EOF;
|
||||
this.sourceName = sourceName;
|
||||
this.lineno = lineno;
|
||||
this.flags = 0;
|
||||
if (sourceReader != null) {
|
||||
if (sourceString != null) Kit.codeBug();
|
||||
this.sourceReader = sourceReader;
|
||||
|
@ -354,11 +339,11 @@ public class TokenStream
|
|||
}
|
||||
|
||||
public final int peekTokenSameLine() throws IOException {
|
||||
flags |= TSF_NEWLINES; // SCAN_NEWLINES from jsscan.h
|
||||
significantEol = true; // SCAN_NEWLINES from jsscan.h
|
||||
int result = getToken();
|
||||
this.pushbackToken = result;
|
||||
tokenno--;
|
||||
flags &= ~TSF_NEWLINES; // HIDE_NEWLINES from jsscan.h
|
||||
significantEol = false; // HIDE_NEWLINES from jsscan.h
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -370,7 +355,7 @@ public class TokenStream
|
|||
if (this.pushbackToken != Token.EOF) {
|
||||
int result = this.pushbackToken;
|
||||
this.pushbackToken = Token.EOF;
|
||||
if (result != Token.EOL || (flags & TSF_NEWLINES) != 0) {
|
||||
if (result != Token.EOL || significantEol) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -383,13 +368,13 @@ public class TokenStream
|
|||
if (c == EOF_CHAR) {
|
||||
return Token.EOF;
|
||||
} else if (c == '\n') {
|
||||
flags &= ~TSF_DIRTYLINE;
|
||||
if ((flags & TSF_NEWLINES) != 0) {
|
||||
dirtyLine = false;
|
||||
if (significantEol) {
|
||||
return Token.EOL;
|
||||
}
|
||||
} else if (!isJSSpace(c)) {
|
||||
if (c != '-') {
|
||||
flags |= TSF_DIRTYLINE;
|
||||
dirtyLine = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -839,7 +824,7 @@ public class TokenStream
|
|||
}
|
||||
|
||||
// is it a regexp?
|
||||
if ((flags & TSF_REGEXP) != 0) {
|
||||
if (allowRegExp) {
|
||||
stringBufferTop = 0;
|
||||
while ((c = getChar()) != '/') {
|
||||
if (c == '\n' || c == EOF_CHAR) {
|
||||
|
@ -914,7 +899,7 @@ public class TokenStream
|
|||
this.op = Token.SUB;
|
||||
c = Token.ASSIGNOP;
|
||||
} else if (matchChar('-')) {
|
||||
if (0 == (flags & TSF_DIRTYLINE)) {
|
||||
if (!dirtyLine) {
|
||||
// treat HTML end-comment after possible whitespace
|
||||
// after line start as comment-utill-eol
|
||||
if (matchChar('>')) {
|
||||
|
@ -926,7 +911,7 @@ public class TokenStream
|
|||
} else {
|
||||
c = Token.SUB;
|
||||
}
|
||||
flags |= TSF_DIRTYLINE;
|
||||
dirtyLine = true;
|
||||
return c;
|
||||
|
||||
default:
|
||||
|
@ -1155,11 +1140,13 @@ public class TokenStream
|
|||
return true;
|
||||
}
|
||||
|
||||
/* for TSF_REGEXP, etc.
|
||||
* should this be manipulated by gettor/settor functions?
|
||||
* should it be passed to getToken();
|
||||
*/
|
||||
int flags;
|
||||
// tokenize newlines
|
||||
private boolean significantEol;
|
||||
|
||||
// stuff other than whitespace since start of line
|
||||
private boolean dirtyLine;
|
||||
|
||||
boolean allowRegExp;
|
||||
String regExpFlags;
|
||||
|
||||
private String sourceName;
|
||||
|
|
Загрузка…
Ссылка в новой задаче