Commit 23c27d2d authored by Marius Wachtler's avatar Marius Wachtler

Let nodeName() create a new unique name instead of returning the name for the passed node

parent 2f22f89e
...@@ -292,7 +292,7 @@ private: ...@@ -292,7 +292,7 @@ private:
if (exc_handlers.size() == 0) if (exc_handlers.size() == 0)
return call; return call;
auto name = nodeName(e); auto name = nodeName();
pushAssign(name, call); pushAssign(name, call);
return makeLoad(name, e); return makeLoad(name, e);
} }
...@@ -307,7 +307,7 @@ private: ...@@ -307,7 +307,7 @@ private:
template <typename ResultASTType, typename CompType> AST_expr* remapComprehension(CompType* node) { template <typename ResultASTType, typename CompType> AST_expr* remapComprehension(CompType* node) {
assert(curblock); assert(curblock);
InternedString rtn_name = nodeName(node); InternedString rtn_name = nodeName();
pushAssign(rtn_name, new ResultASTType()); pushAssign(rtn_name, new ResultASTType());
std::vector<CFGBlock*> exit_blocks; std::vector<CFGBlock*> exit_blocks;
...@@ -324,7 +324,7 @@ private: ...@@ -324,7 +324,7 @@ private:
AST_expr* remapped_iter = remapExpr(c->iter); AST_expr* remapped_iter = remapExpr(c->iter);
AST_LangPrimitive* iter_call = new AST_LangPrimitive(AST_LangPrimitive::GET_ITER); AST_LangPrimitive* iter_call = new AST_LangPrimitive(AST_LangPrimitive::GET_ITER);
iter_call->args.push_back(remapped_iter); iter_call->args.push_back(remapped_iter);
InternedString iter_name = nodeName(node, "lc_iter", i); InternedString iter_name = nodeName("lc_iter", i);
pushAssign(iter_name, iter_call); pushAssign(iter_name, iter_call);
AST_expr* next_attr = makeLoadAttribute(makeLoad(iter_name, node), internString("next"), true); AST_expr* next_attr = makeLoadAttribute(makeLoad(iter_name, node), internString("next"), true);
...@@ -357,7 +357,7 @@ private: ...@@ -357,7 +357,7 @@ private:
push_back(br); push_back(br);
curblock = body_block; curblock = body_block;
InternedString next_name(nodeName(next_attr)); InternedString next_name(nodeName());
pushAssign(next_name, makeCall(next_attr)); pushAssign(next_name, makeCall(next_attr));
pushAssign(c->target, makeLoad(next_name, node)); pushAssign(c->target, makeLoad(next_name, node));
...@@ -583,7 +583,7 @@ private: ...@@ -583,7 +583,7 @@ private:
push_back(assign); push_back(assign);
for (int i = 0; i < elts->size(); i++) { for (int i = 0; i < elts->size(); i++) {
InternedString tmp_name = nodeName(target, "", i); InternedString tmp_name = nodeName("", i);
new_target->elts.push_back(makeName(tmp_name, AST_TYPE::Store, target->lineno)); new_target->elts.push_back(makeName(tmp_name, AST_TYPE::Store, target->lineno));
pushAssign((*elts)[i], makeLoad(tmp_name, target)); pushAssign((*elts)[i], makeLoad(tmp_name, target));
...@@ -607,13 +607,11 @@ private: ...@@ -607,13 +607,11 @@ private:
return stmt; return stmt;
} }
InternedString nodeName(AST* node) { return createUniqueName("#"); } InternedString nodeName() { return createUniqueName("#"); }
InternedString nodeName(AST* node, const std::string& suffix) { InternedString nodeName(llvm::StringRef suffix) { return createUniqueName(llvm::Twine("#") + suffix + "_"); }
return createUniqueName(llvm::Twine("#") + suffix + "_");
}
InternedString nodeName(AST* node, const std::string& suffix, int idx) { InternedString nodeName(llvm::StringRef suffix, int idx) {
return createUniqueName(llvm::Twine("#") + suffix + "_" + llvm::Twine(idx) + "_"); return createUniqueName(llvm::Twine("#") + suffix + "_" + llvm::Twine(idx) + "_");
} }
...@@ -683,7 +681,7 @@ private: ...@@ -683,7 +681,7 @@ private:
AST_expr* remapBoolOp(AST_BoolOp* node) { AST_expr* remapBoolOp(AST_BoolOp* node) {
assert(curblock); assert(curblock);
InternedString name = nodeName(node); InternedString name = nodeName();
CFGBlock* starting_block = curblock; CFGBlock* starting_block = curblock;
CFGBlock* exit_block = cfg->addDeferredBlock(); CFGBlock* exit_block = cfg->addDeferredBlock();
...@@ -787,7 +785,7 @@ private: ...@@ -787,7 +785,7 @@ private:
} }
return rtn; return rtn;
} else { } else {
InternedString name = nodeName(node); InternedString name = nodeName();
CFGBlock* exit_block = cfg->addDeferredBlock(); CFGBlock* exit_block = cfg->addDeferredBlock();
AST_expr* left = remapExpr(node->left); AST_expr* left = remapExpr(node->left);
...@@ -926,7 +924,7 @@ private: ...@@ -926,7 +924,7 @@ private:
insert_point->push_back(makeExpr(y)); insert_point->push_back(makeExpr(y));
}); });
InternedString func_var_name = nodeName(func->function_def); InternedString func_var_name = nodeName();
pushAssign(func_var_name, func); pushAssign(func_var_name, func);
return makeCall(makeLoad(func_var_name, node), first); return makeCall(makeLoad(func_var_name, node), first);
...@@ -968,7 +966,7 @@ private: ...@@ -968,7 +966,7 @@ private:
rtn->value = makeName(rtn_name, AST_TYPE::Load, node->lineno); rtn->value = makeName(rtn_name, AST_TYPE::Load, node->lineno);
func->function_def->body.push_back(rtn); func->function_def->body.push_back(rtn);
InternedString func_var_name = nodeName(func->function_def); InternedString func_var_name = nodeName();
pushAssign(func_var_name, func); pushAssign(func_var_name, func);
return makeCall(makeName(func_var_name, AST_TYPE::Load, node->lineno), first); return makeCall(makeName(func_var_name, AST_TYPE::Load, node->lineno), first);
...@@ -977,7 +975,7 @@ private: ...@@ -977,7 +975,7 @@ private:
AST_expr* remapIfExp(AST_IfExp* node) { AST_expr* remapIfExp(AST_IfExp* node) {
assert(curblock); assert(curblock);
InternedString rtn_name = nodeName(node); InternedString rtn_name = nodeName();
CFGBlock* iftrue = cfg->addDeferredBlock(); CFGBlock* iftrue = cfg->addDeferredBlock();
CFGBlock* iffalse = cfg->addDeferredBlock(); CFGBlock* iffalse = cfg->addDeferredBlock();
CFGBlock* exit_block = cfg->addDeferredBlock(); CFGBlock* exit_block = cfg->addDeferredBlock();
...@@ -1130,7 +1128,7 @@ private: ...@@ -1130,7 +1128,7 @@ private:
rtn->col_offset = node->col_offset; rtn->col_offset = node->col_offset;
rtn->value = remapExpr(node->value); rtn->value = remapExpr(node->value);
InternedString node_name(nodeName(rtn)); InternedString node_name(nodeName());
pushAssign(node_name, rtn); pushAssign(node_name, rtn);
push_back(makeExpr(new AST_LangPrimitive(AST_LangPrimitive::UNCACHE_EXC_INFO))); push_back(makeExpr(new AST_LangPrimitive(AST_LangPrimitive::UNCACHE_EXC_INFO)));
...@@ -1236,7 +1234,7 @@ private: ...@@ -1236,7 +1234,7 @@ private:
// this is the part that actually generates temporaries & assigns to them. // this is the part that actually generates temporaries & assigns to them.
if (wrap_with_assign && (rtn->type != AST_TYPE::Name || ast_cast<AST_Name>(rtn)->id.str()[0] != '#')) { if (wrap_with_assign && (rtn->type != AST_TYPE::Name || ast_cast<AST_Name>(rtn)->id.str()[0] != '#')) {
InternedString name = nodeName(node); InternedString name = nodeName();
pushAssign(name, rtn); pushAssign(name, rtn);
return makeLoad(name, node); return makeLoad(name, node);
} else { } else {
...@@ -1419,7 +1417,7 @@ public: ...@@ -1419,7 +1417,7 @@ public:
scoping_analysis->registerScopeReplacement(node, def); scoping_analysis->registerScopeReplacement(node, def);
auto tmp = nodeName(node); auto tmp = nodeName();
pushAssign(tmp, new AST_MakeClass(def)); pushAssign(tmp, new AST_MakeClass(def));
// is this name mangling correct? // is this name mangling correct?
pushAssign(source->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno)); pushAssign(source->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno));
...@@ -1439,7 +1437,7 @@ public: ...@@ -1439,7 +1437,7 @@ public:
scoping_analysis->registerScopeReplacement(node, def); scoping_analysis->registerScopeReplacement(node, def);
auto tmp = nodeName(node); auto tmp = nodeName();
pushAssign(tmp, new AST_MakeFunction(def)); pushAssign(tmp, new AST_MakeFunction(def));
// is this name mangling correct? // is this name mangling correct?
pushAssign(source->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno)); pushAssign(source->mangleName(def->name), makeName(tmp, AST_TYPE::Load, node->lineno));
...@@ -1482,7 +1480,7 @@ public: ...@@ -1482,7 +1480,7 @@ public:
import->args.push_back(new AST_LangPrimitive(AST_LangPrimitive::NONE)); import->args.push_back(new AST_LangPrimitive(AST_LangPrimitive::NONE));
import->args.push_back(new AST_Str(a->name.str())); import->args.push_back(new AST_Str(a->name.str()));
InternedString tmpname = nodeName(a); InternedString tmpname = nodeName();
pushAssign(tmpname, import); pushAssign(tmpname, import);
if (a->asname.str().size() == 0) { if (a->asname.str().size() == 0) {
...@@ -1538,7 +1536,7 @@ public: ...@@ -1538,7 +1536,7 @@ public:
} }
import->args.push_back(new AST_Str(node->module.str())); import->args.push_back(new AST_Str(node->module.str()));
InternedString tmp_module_name = nodeName(node); InternedString tmp_module_name = nodeName();
pushAssign(tmp_module_name, import); pushAssign(tmp_module_name, import);
for (AST_alias* a : node->names) { for (AST_alias* a : node->names) {
...@@ -1562,7 +1560,7 @@ public: ...@@ -1562,7 +1560,7 @@ public:
import_from->args.push_back(makeLoad(tmp_module_name, node)); import_from->args.push_back(makeLoad(tmp_module_name, node));
import_from->args.push_back(new AST_Str(a->name.str())); import_from->args.push_back(new AST_Str(a->name.str()));
InternedString tmp_import_name = nodeName(a); InternedString tmp_import_name = nodeName();
pushAssign(tmp_import_name, import_from); pushAssign(tmp_import_name, import_from);
pushAssign(a->asname.str().size() ? a->asname : a->name, makeLoad(tmp_import_name, node)); pushAssign(a->asname.str().size() ? a->asname : a->name, makeLoad(tmp_import_name, node));
} }
...@@ -1654,7 +1652,7 @@ public: ...@@ -1654,7 +1652,7 @@ public:
case AST_TYPE::Name: { case AST_TYPE::Name: {
AST_Name* n = ast_cast<AST_Name>(node->target); AST_Name* n = ast_cast<AST_Name>(node->target);
assert(n->ctx_type == AST_TYPE::Store); assert(n->ctx_type == AST_TYPE::Store);
InternedString n_name(nodeName(n)); InternedString n_name(nodeName());
pushAssign(n_name, makeLoad(n->id, node)); pushAssign(n_name, makeLoad(n->id, node));
remapped_target = n; remapped_target = n;
remapped_lhs = makeLoad(n_name, node); remapped_lhs = makeLoad(n_name, node);
...@@ -1715,7 +1713,7 @@ public: ...@@ -1715,7 +1713,7 @@ public:
binop->col_offset = node->col_offset; binop->col_offset = node->col_offset;
binop->lineno = node->lineno; binop->lineno = node->lineno;
InternedString node_name(nodeName(node)); InternedString node_name(nodeName());
pushAssign(node_name, binop); pushAssign(node_name, binop);
pushAssign(remapped_target, makeLoad(node_name, node)); pushAssign(remapped_target, makeLoad(node_name, node));
return true; return true;
...@@ -2029,7 +2027,7 @@ public: ...@@ -2029,7 +2027,7 @@ public:
pushLoopContinuation(test_block, end_block); pushLoopContinuation(test_block, end_block);
curblock = loop_block; curblock = loop_block;
InternedString next_name(nodeName(next_attr)); InternedString next_name(nodeName());
pushAssign(next_name, makeCall(next_attr)); pushAssign(next_name, makeCall(next_attr));
pushAssign(node->target, makeLoad(next_name, node)); pushAssign(node->target, makeLoad(next_name, node));
...@@ -2125,9 +2123,9 @@ public: ...@@ -2125,9 +2123,9 @@ public:
assert(node->handlers.size() > 0); assert(node->handlers.size() > 0);
CFGBlock* exc_handler_block = cfg->addDeferredBlock(); CFGBlock* exc_handler_block = cfg->addDeferredBlock();
InternedString exc_type_name = nodeName(node, "type"); InternedString exc_type_name = nodeName("type");
InternedString exc_value_name = nodeName(node, "value"); InternedString exc_value_name = nodeName("value");
InternedString exc_traceback_name = nodeName(node, "traceback"); InternedString exc_traceback_name = nodeName("traceback");
exc_handlers.push_back({ exc_handler_block, exc_type_name, exc_value_name, exc_traceback_name }); exc_handlers.push_back({ exc_handler_block, exc_type_name, exc_value_name, exc_traceback_name });
for (AST_stmt* subnode : node->body) { for (AST_stmt* subnode : node->body) {
...@@ -2240,10 +2238,10 @@ public: ...@@ -2240,10 +2238,10 @@ public:
assert(curblock); assert(curblock);
CFGBlock* exc_handler_block = cfg->addDeferredBlock(); CFGBlock* exc_handler_block = cfg->addDeferredBlock();
InternedString exc_type_name = nodeName(node, "type"); InternedString exc_type_name = nodeName("type");
InternedString exc_value_name = nodeName(node, "value"); InternedString exc_value_name = nodeName("value");
InternedString exc_traceback_name = nodeName(node, "traceback"); InternedString exc_traceback_name = nodeName("traceback");
InternedString exc_why_name = nodeName(node, "why"); InternedString exc_why_name = nodeName("why");
exc_handlers.push_back({ exc_handler_block, exc_type_name, exc_value_name, exc_traceback_name }); exc_handlers.push_back({ exc_handler_block, exc_type_name, exc_value_name, exc_traceback_name });
CFGBlock* finally_block = cfg->addDeferredBlock(); CFGBlock* finally_block = cfg->addDeferredBlock();
...@@ -2332,12 +2330,12 @@ public: ...@@ -2332,12 +2330,12 @@ public:
// just translate this into AST_Try{Except,Finally} nodes and recursively visit those. (If there are other // just translate this into AST_Try{Except,Finally} nodes and recursively visit those. (If there are other
// reasons, I've forgotten them.) // reasons, I've forgotten them.)
assert(curblock); assert(curblock);
InternedString ctxmgrname = nodeName(node, "ctxmgr"); InternedString ctxmgrname = nodeName("ctxmgr");
InternedString exitname = nodeName(node, "exit"); InternedString exitname = nodeName("exit");
InternedString whyname = nodeName(node, "why"); InternedString whyname = nodeName("why");
InternedString exc_type_name = nodeName(node, "exc_type"); InternedString exc_type_name = nodeName("exc_type");
InternedString exc_value_name = nodeName(node, "exc_value"); InternedString exc_value_name = nodeName("exc_value");
InternedString exc_traceback_name = nodeName(node, "exc_traceback"); InternedString exc_traceback_name = nodeName("exc_traceback");
InternedString nonename = internString("None"); InternedString nonename = internString("None");
CFGBlock* exit_block = cfg->addDeferredBlock(); CFGBlock* exit_block = cfg->addDeferredBlock();
exit_block->info = "with_exit"; exit_block->info = "with_exit";
...@@ -2392,7 +2390,7 @@ public: ...@@ -2392,7 +2390,7 @@ public:
curblock = exc_block; curblock = exc_block;
// call the context-manager's exit method // call the context-manager's exit method
InternedString suppressname = nodeName(node, "suppress"); InternedString suppressname = nodeName("suppress");
pushAssign(suppressname, makeCall(makeLoad(exitname, node), makeLoad(exc_type_name, node), pushAssign(suppressname, makeCall(makeLoad(exitname, node), makeLoad(exc_type_name, node),
makeLoad(exc_value_name, node), makeLoad(exc_traceback_name, node))); makeLoad(exc_value_name, node), makeLoad(exc_traceback_name, node)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment