Some more fixes to the closure extractor; now only a single test fails.

This commit is contained in:
Max Schaefer 2012-02-08 11:01:51 -05:00
parent 00b51cd14c
commit aa00b04c00
2 changed files with 13 additions and 13 deletions

View File

@ -442,7 +442,7 @@ public abstract class TestCorrelatedPairExtraction {
"function write(p, v) { this[p] = v; }",
"function extend(dest, src) {\n" +
" for(var p in src)\n" +
" if(foo(p)) (function _forin_body_0(p) { write.call(dest, p, src[p]); })(p);\n" +
" (function _forin_body_0(p) { if(foo(p)) write.call(dest, p, src[p]); })(p);\n" +
"}\n" +
"function write(p, v) { this[p] = v; }");
}
@ -476,9 +476,9 @@ public abstract class TestCorrelatedPairExtraction {
"function extend(dest, src) {\n" +
" var x, y;\n" +
" for(var name in src) {\n" +
" (function _forin_body_0(name) { { x = dest[name];\n" +
" (function _forin_body_0(name) { x = dest[name];\n" +
" y = src[name];\n" +
" dest[name] = join(x,y); } })(name);\n" +
" dest[name] = join(x,y); })(name);\n" +
" }\n" +
"}");
}
@ -497,7 +497,7 @@ public abstract class TestCorrelatedPairExtraction {
" var results = {};\n" +
" for (var i = 0, l = keys.length; i < l; i++){\n" +
" var k = keys[i];\n" +
" if (k in object) (function _forin_body_0(k) { results[k] = object[k]; })(k);\n" +
" (function _forin_body_0(k) { if (k in object) results[k] = object[k]; })(k);\n" +
" }\n" +
" return results;\n" +
"}");

View File

@ -449,7 +449,7 @@ public class ClosureExtractor extends CAstRewriterExt {
CAstNode node_to_extract = root.getChild(context.getStart());
if(node_to_extract.getKind() == CAstNode.EMPTY)
extractingEmpty = true;
fun_body_stmts.add(wrapInBlockExpr(node_to_extract));
fun_body_stmts.add(wrapIn(BLOCK_STMT, node_to_extract));
}
}
}
@ -533,7 +533,7 @@ public class ClosureExtractor extends CAstRewriterExt {
if(context.isOutermost()) {
CAstNode return_fixup = createReturnFixup(context, entity);
if(fixup != null)
fixup = Ast.makeNode(BLOCK_EXPR, return_fixup, fixup);
fixup = Ast.makeNode(BLOCK_STMT, return_fixup, fixup);
else
fixup = return_fixup;
} else {
@ -548,9 +548,9 @@ public class ClosureExtractor extends CAstRewriterExt {
// if(re$) <check>;
fixup = Ast.makeNode(IF_STMT,
addExnFlow(makeVarRef("re$"), JavaScriptTypes.ReferenceError, entity, context),
Ast.makeNode(LOCAL_SCOPE, wrapInBlockExpr(fixup == null ? Ast.makeNode(EMPTY) : fixup)));
Ast.makeNode(LOCAL_SCOPE, wrapIn(BLOCK_STMT, fixup == null ? Ast.makeNode(EMPTY) : fixup)));
stmts.add(Ast.makeNode(BLOCK_EXPR, decl, fixup));
stmts.add(Ast.makeNode(BLOCK_STMT, decl, fixup));
} else {
stmts.add(call);
}
@ -564,7 +564,7 @@ public class ClosureExtractor extends CAstRewriterExt {
}
if(extractingLocalScope || extractingEmpty) {
CAstNode newNode = Ast.makeNode(LOCAL_SCOPE, wrapInBlockExpr(stmts.toArray(new CAstNode[0])));
CAstNode newNode = Ast.makeNode(LOCAL_SCOPE, wrapIn(BLOCK_STMT, stmts.toArray(new CAstNode[0])));
stmts = Collections.singletonList(newNode);
}
@ -617,12 +617,12 @@ public class ClosureExtractor extends CAstRewriterExt {
addExnFlow(makeVarRef("re$"), JavaScriptTypes.ReferenceError, entity, context),
Ast.makeConstant("type")), JavaScriptTypes.TypeError, entity, context),
Ast.makeConstant("goto")),
Ast.makeNode(LOCAL_SCOPE, Ast.makeNode(BLOCK_EXPR, fixup)));
Ast.makeNode(LOCAL_SCOPE, wrapIn(BLOCK_STMT, fixup)));
}
// wrap given nodes into a BLOCK_EXPR unless there is only a single node which is itself a BLOCK_EXPR
private CAstNode wrapInBlockExpr(CAstNode... nodes) {
return nodes.length == 1 && nodes[0].getKind() == BLOCK_EXPR ? nodes[0] : Ast.makeNode(BLOCK_EXPR, nodes);
// wrap given nodes into a node of the given kind, unless there is only a single node which is itself of the same kind
private CAstNode wrapIn(int kind, CAstNode... nodes) {
return nodes.length == 1 && nodes[0].getKind() == kind ? nodes[0] : Ast.makeNode(kind, nodes);
}
// helper functions for adding exceptional CFG edges