Commit 403fb36a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Remove AST_Unreachable

parent dc7a6171
...@@ -297,7 +297,6 @@ public: ...@@ -297,7 +297,6 @@ public:
virtual bool visit_print(AST_Print* node) { return true; } virtual bool visit_print(AST_Print* node) { return true; }
virtual bool visit_raise(AST_Raise* node) { return true; } virtual bool visit_raise(AST_Raise* node) { return true; }
virtual bool visit_return(AST_Return* node) { return true; } virtual bool visit_return(AST_Return* node) { return true; }
virtual bool visit_unreachable(AST_Unreachable* node) { return true; }
virtual bool visit_classdef(AST_ClassDef* node) { virtual bool visit_classdef(AST_ClassDef* node) {
_doSet(node->name); _doSet(node->name);
......
...@@ -594,8 +594,6 @@ private: ...@@ -594,8 +594,6 @@ private:
} }
} }
void visit_unreachable(AST_Unreachable* node) override {}
public: public:
static void propagate(CFGBlock* block, const TypeMap& starting, TypeMap& ending, ExprTypeMap& expr_types, static void propagate(CFGBlock* block, const TypeMap& starting, TypeMap& ending, ExprTypeMap& expr_types,
TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation, TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation,
......
...@@ -2178,10 +2178,6 @@ private: ...@@ -2178,10 +2178,6 @@ private:
case AST_TYPE::Raise: case AST_TYPE::Raise:
doRaise(ast_cast<AST_Raise>(node), unw_info); doRaise(ast_cast<AST_Raise>(node), unw_info);
break; break;
case AST_TYPE::Unreachable:
emitter.getBuilder()->CreateUnreachable();
endBlock(FINISHED);
break;
default: default:
printf("Unhandled stmt type at " __FILE__ ":" STRINGIFY(__LINE__) ": %d\n", node->type); printf("Unhandled stmt type at " __FILE__ ":" STRINGIFY(__LINE__) ": %d\n", node->type);
exit(1); exit(1);
......
...@@ -61,7 +61,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstBoolOpType type) { ...@@ -61,7 +61,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstBoolOpType type) {
break; break;
} }
assert("Unknown AstBoolOpType" && false); assert("Unknown AstBoolOpType" && false);
return AST_TYPE::Unreachable; abort();
} }
AST_TYPE::AST_TYPE readItem(pypa::AstBinOpType type) { AST_TYPE::AST_TYPE readItem(pypa::AstBinOpType type) {
...@@ -94,7 +94,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstBinOpType type) { ...@@ -94,7 +94,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstBinOpType type) {
break; break;
} }
assert("Unknown AstBinOpType" && false); assert("Unknown AstBinOpType" && false);
return AST_TYPE::Unreachable; abort();
} }
AST_TYPE::AST_TYPE readItem(pypa::AstUnaryOpType type) { AST_TYPE::AST_TYPE readItem(pypa::AstUnaryOpType type) {
...@@ -111,7 +111,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstUnaryOpType type) { ...@@ -111,7 +111,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstUnaryOpType type) {
break; break;
} }
assert("Unknown AstUnaryOpType" && false); assert("Unknown AstUnaryOpType" && false);
return AST_TYPE::Unreachable; abort();
} }
...@@ -162,7 +162,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstCompareOpType type) { ...@@ -162,7 +162,7 @@ AST_TYPE::AST_TYPE readItem(pypa::AstCompareOpType type) {
break; break;
} }
assert("Unknown AstCompareOpType" && false); assert("Unknown AstCompareOpType" && false);
return AST_TYPE::Unreachable; abort();
} }
std::string readName(pypa::AstExpression& e) { std::string readName(pypa::AstExpression& e) {
......
...@@ -869,16 +869,6 @@ void* AST_UnaryOp::accept_expr(ExprVisitor* v) { ...@@ -869,16 +869,6 @@ void* AST_UnaryOp::accept_expr(ExprVisitor* v) {
return v->visit_unaryop(this); return v->visit_unaryop(this);
} }
void AST_Unreachable::accept(ASTVisitor* v) {
bool skip = v->visit_unreachable(this);
if (skip)
return;
}
void AST_Unreachable::accept_stmt(StmtVisitor* v) {
v->visit_unreachable(this);
}
void AST_While::accept(ASTVisitor* v) { void AST_While::accept(ASTVisitor* v) {
bool skip = v->visit_while(this); bool skip = v->visit_while(this);
if (skip) if (skip)
...@@ -1726,11 +1716,6 @@ bool PrintVisitor::visit_unaryop(AST_UnaryOp* node) { ...@@ -1726,11 +1716,6 @@ bool PrintVisitor::visit_unaryop(AST_UnaryOp* node) {
return true; return true;
} }
bool PrintVisitor::visit_unreachable(AST_Unreachable* node) {
printf("<unreachable>");
return true;
}
bool PrintVisitor::visit_while(AST_While* node) { bool PrintVisitor::visit_while(AST_While* node) {
printf("while "); printf("while ");
node->test->accept(this); node->test->accept(this);
...@@ -2025,10 +2010,6 @@ public: ...@@ -2025,10 +2010,6 @@ public:
output->push_back(node); output->push_back(node);
return false; return false;
} }
virtual bool visit_unreachable(AST_Unreachable* node) {
output->push_back(node);
return false;
}
virtual bool visit_while(AST_While* node) { virtual bool visit_while(AST_While* node) {
output->push_back(node); output->push_back(node);
return false; return false;
......
...@@ -125,7 +125,6 @@ enum AST_TYPE { ...@@ -125,7 +125,6 @@ enum AST_TYPE {
AugBinOp = 203, AugBinOp = 203,
Invoke = 204, Invoke = 204,
LangPrimitive = 205, LangPrimitive = 205,
Unreachable = 206,
// These aren't real AST types, but since we use AST types to represent binexp types // These aren't real AST types, but since we use AST types to represent binexp types
// and divmod+truediv are essentially types of binops, we add them here (at least for now): // and divmod+truediv are essentially types of binops, we add them here (at least for now):
...@@ -989,16 +988,6 @@ public: ...@@ -989,16 +988,6 @@ public:
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::LangPrimitive; static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::LangPrimitive;
}; };
class AST_Unreachable : public AST_stmt {
public:
virtual void accept(ASTVisitor* v);
virtual void accept_stmt(StmtVisitor* v);
AST_Unreachable() : AST_stmt(AST_TYPE::Unreachable) {}
static const AST_TYPE::AST_TYPE TYPE = AST_TYPE::Unreachable;
};
template <typename T> T* ast_cast(AST* node) { template <typename T> T* ast_cast(AST* node) {
assert(node->type == T::TYPE); assert(node->type == T::TYPE);
return static_cast<T*>(node); return static_cast<T*>(node);
...@@ -1066,7 +1055,6 @@ public: ...@@ -1066,7 +1055,6 @@ public:
virtual bool visit_tryfinally(AST_TryFinally* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_tryfinally(AST_TryFinally* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_tuple(AST_Tuple* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_tuple(AST_Tuple* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_unaryop(AST_UnaryOp* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_unaryop(AST_UnaryOp* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_unreachable(AST_Unreachable* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); }
virtual bool visit_yield(AST_Yield* node) { RELEASE_ASSERT(0, ""); } virtual bool visit_yield(AST_Yield* node) { RELEASE_ASSERT(0, ""); }
...@@ -1135,7 +1123,6 @@ public: ...@@ -1135,7 +1123,6 @@ public:
virtual bool visit_tryfinally(AST_TryFinally* node) { return false; } virtual bool visit_tryfinally(AST_TryFinally* node) { return false; }
virtual bool visit_tuple(AST_Tuple* node) { return false; } virtual bool visit_tuple(AST_Tuple* node) { return false; }
virtual bool visit_unaryop(AST_UnaryOp* node) { return false; } virtual bool visit_unaryop(AST_UnaryOp* node) { return false; }
virtual bool visit_unreachable(AST_Unreachable* node) { return false; }
virtual bool visit_while(AST_While* node) { return false; } virtual bool visit_while(AST_While* node) { return false; }
virtual bool visit_with(AST_With* node) { return false; } virtual bool visit_with(AST_With* node) { return false; }
virtual bool visit_yield(AST_Yield* node) { return false; } virtual bool visit_yield(AST_Yield* node) { return false; }
...@@ -1206,7 +1193,6 @@ public: ...@@ -1206,7 +1193,6 @@ public:
virtual void visit_return(AST_Return* node) { RELEASE_ASSERT(0, ""); } virtual void visit_return(AST_Return* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_tryexcept(AST_TryExcept* node) { RELEASE_ASSERT(0, ""); } virtual void visit_tryexcept(AST_TryExcept* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_tryfinally(AST_TryFinally* node) { RELEASE_ASSERT(0, ""); } virtual void visit_tryfinally(AST_TryFinally* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_unreachable(AST_Unreachable* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); } virtual void visit_while(AST_While* node) { RELEASE_ASSERT(0, ""); }
virtual void visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); } virtual void visit_with(AST_With* node) { RELEASE_ASSERT(0, ""); }
...@@ -1279,7 +1265,6 @@ public: ...@@ -1279,7 +1265,6 @@ public:
virtual bool visit_tryexcept(AST_TryExcept* node); virtual bool visit_tryexcept(AST_TryExcept* node);
virtual bool visit_tryfinally(AST_TryFinally* node); virtual bool visit_tryfinally(AST_TryFinally* node);
virtual bool visit_unaryop(AST_UnaryOp* node); virtual bool visit_unaryop(AST_UnaryOp* node);
virtual bool visit_unreachable(AST_Unreachable* node);
virtual bool visit_while(AST_While* node); virtual bool visit_while(AST_While* node);
virtual bool visit_with(AST_With* node); virtual bool visit_with(AST_With* node);
virtual bool visit_yield(AST_Yield* node); virtual bool visit_yield(AST_Yield* node);
......
...@@ -1821,7 +1821,6 @@ public: ...@@ -1821,7 +1821,6 @@ public:
if (!curblock) if (!curblock)
return true; return true;
curblock->push_back(new AST_Unreachable());
curblock = NULL; curblock = NULL;
return true; return true;
...@@ -1928,7 +1927,6 @@ public: ...@@ -1928,7 +1927,6 @@ public:
raise->arg1 = makeName(exc_value_name, AST_TYPE::Load, node->lineno); raise->arg1 = makeName(exc_value_name, AST_TYPE::Load, node->lineno);
raise->arg2 = makeName(exc_traceback_name, AST_TYPE::Load, node->lineno); raise->arg2 = makeName(exc_traceback_name, AST_TYPE::Load, node->lineno);
push_back(raise); push_back(raise);
curblock->push_back(new AST_Unreachable());
curblock = NULL; curblock = NULL;
} }
} }
...@@ -2009,7 +2007,6 @@ public: ...@@ -2009,7 +2007,6 @@ public:
raise->arg1 = makeName(exc_value_name, AST_TYPE::Load, node->lineno); raise->arg1 = makeName(exc_value_name, AST_TYPE::Load, node->lineno);
raise->arg2 = makeName(exc_traceback_name, AST_TYPE::Load, node->lineno); raise->arg2 = makeName(exc_traceback_name, AST_TYPE::Load, node->lineno);
push_back(raise); push_back(raise);
curblock->push_back(new AST_Unreachable());
curblock = noexc; curblock = noexc;
} }
...@@ -2236,7 +2233,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) { ...@@ -2236,7 +2233,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if (b->successors.size() == 0) { if (b->successors.size() == 0) {
AST_stmt* terminator = b->body.back(); AST_stmt* terminator = b->body.back();
assert(terminator->type == AST_TYPE::Return || terminator->type == AST_TYPE::Raise assert(terminator->type == AST_TYPE::Return || terminator->type == AST_TYPE::Raise
|| terminator->type == AST_TYPE::Unreachable); || terminator->type == AST_TYPE::Raise);
} }
if (b->predecessors.size() == 0) if (b->predecessors.size() == 0)
...@@ -2297,6 +2294,8 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) { ...@@ -2297,6 +2294,8 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
no_dups = false; no_dups = false;
} }
} }
if (!no_dups)
rtn->print();
assert(no_dups); assert(no_dups);
// TODO make sure the result of Invoke nodes are not used on the exceptional path // TODO make sure the result of Invoke nodes are not used on the exceptional path
......
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