mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
reduction of Stmt subclasses - compiles but does not yet link
This commit is contained in:
parent
10e80dfcd3
commit
7a9694a2a4
4 changed files with 1059 additions and 66 deletions
109
src/Stmt.cc
109
src/Stmt.cc
|
@ -32,6 +32,8 @@ const char* stmt_name(StmtTag t)
|
|||
"for", "next", "break", "return", "add", "delete",
|
||||
"list", "bodylist",
|
||||
"<init>", "fallthrough", "while",
|
||||
"catch-return",
|
||||
"check-any-length",
|
||||
"null",
|
||||
};
|
||||
|
||||
|
@ -94,6 +96,18 @@ const SwitchStmt* Stmt::AsSwitchStmt() const
|
|||
return (const SwitchStmt*) this;
|
||||
}
|
||||
|
||||
const ExprStmt* Stmt::AsExprStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_EXPR, "Stmt::AsExprStmt", stmt_name)
|
||||
return (const ExprStmt*) this;
|
||||
}
|
||||
|
||||
const ReturnStmt* Stmt::AsReturnStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_RETURN, "Stmt::AsReturnStmt", stmt_name)
|
||||
return (const ReturnStmt*) this;
|
||||
}
|
||||
|
||||
bool Stmt::SetLocationInfo(const Location* start, const Location* end)
|
||||
{
|
||||
if ( ! Obj::SetLocationInfo(start, end) )
|
||||
|
@ -354,6 +368,11 @@ ExprStmt::ExprStmt(StmtTag t, ExprPtr arg_e) : Stmt(t), e(std::move(arg_e))
|
|||
|
||||
ExprStmt::~ExprStmt() = default;
|
||||
|
||||
ExprPtr ExprStmt::StmtExprPtr() const
|
||||
{
|
||||
return e;
|
||||
}
|
||||
|
||||
ValPtr ExprStmt::Exec(Frame* f, StmtFlowType& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -961,17 +980,37 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
AddStmt::AddStmt(ExprPtr arg_e) : ExprStmt(STMT_ADD, std::move(arg_e))
|
||||
|
||||
AddDelStmt::AddDelStmt(StmtTag t, ExprPtr arg_e)
|
||||
: ExprStmt(t, std::move(arg_e))
|
||||
{
|
||||
}
|
||||
|
||||
bool AddDelStmt::IsPure() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TraversalCode AddDelStmt::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
TraversalCode tc = cb->PreStmt(this);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
// Argument is stored in base class's "e" field.
|
||||
tc = e->Traverse(cb);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
tc = cb->PostStmt(this);
|
||||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
|
||||
AddStmt::AddStmt(ExprPtr arg_e) : AddDelStmt(STMT_ADD, std::move(arg_e))
|
||||
{
|
||||
if ( ! e->CanAdd() )
|
||||
Error("illegal add statement");
|
||||
}
|
||||
|
||||
bool AddStmt::IsPure() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ValPtr AddStmt::Exec(Frame* f, StmtFlowType& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -981,20 +1020,7 @@ ValPtr AddStmt::Exec(Frame* f, StmtFlowType& flow) const
|
|||
}
|
||||
|
||||
|
||||
TraversalCode AddStmt::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
TraversalCode tc = cb->PreStmt(this);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
// Argument is stored in base class's "e" field.
|
||||
tc = e->Traverse(cb);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
tc = cb->PostStmt(this);
|
||||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
DelStmt::DelStmt(ExprPtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e))
|
||||
DelStmt::DelStmt(ExprPtr arg_e) : AddDelStmt(STMT_DELETE, std::move(arg_e))
|
||||
{
|
||||
if ( e->IsError() )
|
||||
return;
|
||||
|
@ -1003,11 +1029,6 @@ DelStmt::DelStmt(ExprPtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e))
|
|||
Error("illegal delete statement");
|
||||
}
|
||||
|
||||
bool DelStmt::IsPure() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ValPtr DelStmt::Exec(Frame* f, StmtFlowType& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -1016,18 +1037,6 @@ ValPtr DelStmt::Exec(Frame* f, StmtFlowType& flow) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
TraversalCode DelStmt::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
TraversalCode tc = cb->PreStmt(this);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
// Argument is stored in base class's "e" field.
|
||||
tc = e->Traverse(cb);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
tc = cb->PostStmt(this);
|
||||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
EventStmt::EventStmt(EventExprPtr arg_e)
|
||||
: ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
|
||||
|
@ -1060,10 +1069,10 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
WhileStmt::WhileStmt(ExprPtr arg_loop_condition,
|
||||
StmtPtr arg_body)
|
||||
WhileStmt::WhileStmt(ExprPtr arg_loop_condition, StmtPtr arg_body)
|
||||
: Stmt(STMT_WHILE),
|
||||
loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body))
|
||||
loop_condition(std::move(arg_loop_condition)),
|
||||
body(std::move(arg_body))
|
||||
{
|
||||
if ( ! loop_condition->IsError() &&
|
||||
! IsBool(loop_condition->GetType()->Tag()) )
|
||||
|
@ -1119,6 +1128,9 @@ ValPtr WhileStmt::Exec(Frame* f, StmtFlowType& flow) const
|
|||
|
||||
for ( ; ; )
|
||||
{
|
||||
if ( loop_cond_pred_stmt )
|
||||
loop_cond_pred_stmt->Exec(f, flow);
|
||||
|
||||
auto cond = loop_condition->Eval(f);
|
||||
|
||||
if ( ! cond )
|
||||
|
@ -1568,12 +1580,15 @@ void ReturnStmt::StmtDescribe(ODesc* d) const
|
|||
|
||||
StmtList::StmtList() : Stmt(STMT_LIST)
|
||||
{
|
||||
stmts = new StmtPList;
|
||||
}
|
||||
|
||||
StmtList::~StmtList()
|
||||
{
|
||||
for ( const auto& stmt : stmts )
|
||||
for ( const auto& stmt : Stmts() )
|
||||
Unref(stmt);
|
||||
|
||||
delete stmts;
|
||||
}
|
||||
|
||||
ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) const
|
||||
|
@ -1581,7 +1596,7 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) const
|
|||
RegisterAccess();
|
||||
flow = FLOW_NEXT;
|
||||
|
||||
for ( const auto& stmt : stmts )
|
||||
for ( const auto& stmt : Stmts() )
|
||||
{
|
||||
f->SetNextStmt(stmt);
|
||||
|
||||
|
@ -1604,7 +1619,7 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) const
|
|||
|
||||
bool StmtList::IsPure() const
|
||||
{
|
||||
for ( const auto& stmt : stmts )
|
||||
for ( const auto& stmt : Stmts() )
|
||||
if ( ! stmt->IsPure() )
|
||||
return false;
|
||||
return true;
|
||||
|
@ -1615,10 +1630,10 @@ void StmtList::StmtDescribe(ODesc* d) const
|
|||
if ( ! d->IsReadable() )
|
||||
{
|
||||
AddTag(d);
|
||||
d->AddCount(stmts.length());
|
||||
d->AddCount(stmts->length());
|
||||
}
|
||||
|
||||
if ( stmts.length() == 0 )
|
||||
if ( stmts->length() == 0 )
|
||||
DescribeDone(d);
|
||||
|
||||
else
|
||||
|
@ -1629,7 +1644,7 @@ void StmtList::StmtDescribe(ODesc* d) const
|
|||
d->NL();
|
||||
}
|
||||
|
||||
for ( const auto& stmt : stmts )
|
||||
for ( const auto& stmt : Stmts() )
|
||||
{
|
||||
stmt->Describe(d);
|
||||
d->NL();
|
||||
|
@ -1645,7 +1660,7 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const
|
|||
TraversalCode tc = cb->PreStmt(this);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
||||
for ( const auto& stmt : stmts )
|
||||
for ( const auto& stmt : Stmts() )
|
||||
{
|
||||
tc = stmt->Traverse(cb);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue