Parsing changes: for regular expression literals construct a tree node with regular expression number during parsing instead of generating a special subtree that is converted to such node during tree transformation.

This commit is contained in:
igor%mir2.org 2003-02-20 13:11:21 +00:00
parent 406437f686
commit a8e6f7c025
3 changed files with 6 additions and 21 deletions

View File

@ -665,13 +665,10 @@ public class IRFactory {
/**
* Regular expressions
*/
public Object createRegExp(String string, String flags) {
return flags.length() == 0
? new Node(TokenStream.REGEXP,
Node.newString(string))
: new Node(TokenStream.REGEXP,
Node.newString(string),
Node.newString(flags));
public Object createRegExp(int regexpIndex) {
Node n = new Node(TokenStream.REGEXP);
n.putIntProp(Node.REGEXP_PROP, regexpIndex);
return n;
}
/**

View File

@ -340,19 +340,6 @@ public class NodeTransformer {
node.setType(inFunction ? TokenStream.POP : TokenStream.POPV);
break;
case TokenStream.REGEXP:
{
Node left = node.getFirstChild();
Node right = node.getLastChild();
String string = left.getString();
String flags = (left != right) ? right.getString() : null;
int index = tree.addRegexp(string, flags);
Node n = new Node(TokenStream.REGEXP);
iter.replaceCurrent(n);
n.putIntProp(Node.REGEXP_PROP, index);
break;
}
case TokenStream.VAR:
{
Node result = new Node(TokenStream.BLOCK);

View File

@ -1399,7 +1399,8 @@ class Parser {
ts.regExpFlags = null;
String re = ts.getString();
sourceAddString(ts.REGEXP, '/' + re + '/' + flags);
return nf.createRegExp(re, flags);
int index = currentScriptOrFn.addRegexp(re, flags);
return nf.createRegExp(index);
}
case TokenStream.PRIMARY: