зеркало из https://github.com/mozilla/gecko-dev.git
When parsing function parameters, collect all parameters names into array instead of generating a separated syntax subtree for them.
This commit is contained in:
Родитель
d32dddbf0c
Коммит
cb81ad7f8d
|
@ -40,8 +40,8 @@ import java.util.*;
|
|||
|
||||
public class FunctionNode extends Node {
|
||||
|
||||
public FunctionNode(String name, Node left, Node right) {
|
||||
super(TokenStream.FUNCTION, left, right);
|
||||
public FunctionNode(String name, Node statements) {
|
||||
super(TokenStream.FUNCTION, statements);
|
||||
functionName = name;
|
||||
itsVariableTable = new VariableTable();
|
||||
}
|
||||
|
@ -102,4 +102,5 @@ public class FunctionNode extends Node {
|
|||
protected boolean itsCheckThis;
|
||||
protected int itsFunctionType;
|
||||
private String functionName;
|
||||
ObjArray argNames;
|
||||
}
|
||||
|
|
|
@ -201,21 +201,22 @@ public class IRFactory {
|
|||
return new Node(TokenStream.BLOCK, lineno);
|
||||
}
|
||||
|
||||
public Object createFunctionNode(String name, Object args,
|
||||
Object statements)
|
||||
public Object createFunctionNode(String name, Object statements)
|
||||
{
|
||||
if (name == null)
|
||||
name = "";
|
||||
return new FunctionNode(name, (Node) args, (Node) statements);
|
||||
return new FunctionNode(name, (Node) statements);
|
||||
}
|
||||
|
||||
public Object createFunction(String name, Object args, Object statements,
|
||||
public Object createFunction(String name, ObjArray argNames,
|
||||
Object statements,
|
||||
String sourceName, int baseLineno,
|
||||
int endLineno, Object source,
|
||||
boolean isExpr)
|
||||
{
|
||||
FunctionNode f = (FunctionNode) createFunctionNode(name, args,
|
||||
statements);
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
FunctionNode f = (FunctionNode) createFunctionNode(name, statements);
|
||||
f.argNames = argNames;
|
||||
f.setFunctionType(isExpr ? FunctionNode.FUNCTION_EXPRESSION
|
||||
: FunctionNode.FUNCTION_STATEMENT);
|
||||
f.putProp(Node.SOURCENAME_PROP, sourceName);
|
||||
|
|
|
@ -548,14 +548,11 @@ public class NodeTransformer {
|
|||
|
||||
protected void addParameters(FunctionNode fnNode) {
|
||||
VariableTable vars = fnNode.getVariableTable();
|
||||
Node args = fnNode.getFirstChild();
|
||||
if (args.getType() == TokenStream.LP && vars.getParameterCount() == 0)
|
||||
{
|
||||
if (vars.getParameterCount() == 0) {
|
||||
ObjArray argNames = fnNode.argNames;
|
||||
// Add parameters
|
||||
for (Node cursor = args.getFirstChild(); cursor != null;
|
||||
cursor = cursor.getNext())
|
||||
{
|
||||
String arg = cursor.getString();
|
||||
for (int i = 0, N = argNames.size(); i != N; ++i) {
|
||||
String arg = (String)argNames.get(i);
|
||||
vars.addParameter(arg, createVariableObject(arg, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ class Parser {
|
|||
// function to parent source
|
||||
int savedSourceTop = sourceTop;
|
||||
int savedFunctionNumber = functionNumber;
|
||||
Object args;
|
||||
ObjArray args = new ObjArray();
|
||||
Object body;
|
||||
String source;
|
||||
try {
|
||||
|
@ -246,7 +246,6 @@ class Parser {
|
|||
sourceAdd((char) ts.FUNCTION);
|
||||
if (name != null) { sourceAddString(ts.NAME, name); }
|
||||
sourceAdd((char) ts.LP);
|
||||
args = nf.createLeaf(ts.LP);
|
||||
|
||||
if (!ts.matchToken(ts.RP)) {
|
||||
boolean first = true;
|
||||
|
@ -256,8 +255,7 @@ class Parser {
|
|||
first = false;
|
||||
mustMatchToken(ts, ts.NAME, "msg.no.parm");
|
||||
String s = ts.getString();
|
||||
nf.addChildToBack(args, nf.createName(s));
|
||||
|
||||
args.add(s);
|
||||
sourceAddString(ts.NAME, s);
|
||||
} while (ts.matchToken(ts.COMMA));
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ import java.util.*;
|
|||
|
||||
public class OptFunctionNode extends FunctionNode {
|
||||
|
||||
public OptFunctionNode(String name, Node left, Node right,
|
||||
public OptFunctionNode(String name, Node statements,
|
||||
ClassNameHelper nameHelper)
|
||||
{
|
||||
super(name, left, right);
|
||||
super(name, statements);
|
||||
OptClassNameHelper nh = (OptClassNameHelper) nameHelper;
|
||||
itsClassName = nh.getJavaScriptClassName(name, false);
|
||||
}
|
||||
|
|
|
@ -51,15 +51,9 @@ public class OptIRFactory extends IRFactory {
|
|||
this.nameHelper = nameHelper;
|
||||
}
|
||||
|
||||
public Object createFunctionNode(String name, Object args,
|
||||
Object statements)
|
||||
public Object createFunctionNode(String name, Object statements)
|
||||
{
|
||||
if (name == null)
|
||||
name = "";
|
||||
OptFunctionNode result = new OptFunctionNode(name, (Node) args,
|
||||
(Node) statements,
|
||||
nameHelper);
|
||||
return result;
|
||||
return new OptFunctionNode(name, (Node)statements, nameHelper);
|
||||
}
|
||||
|
||||
private ClassNameHelper nameHelper;
|
||||
|
|
Загрузка…
Ссылка в новой задаче