mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
323
src/Stmt.cc
323
src/Stmt.cc
|
@ -1,42 +1,55 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
#include "zeek/Stmt.h"
|
||||
|
||||
#include "zeek/CompHash.h"
|
||||
#include "zeek/Expr.h"
|
||||
#include "zeek/Event.h"
|
||||
#include "zeek/Frame.h"
|
||||
#include "zeek/File.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/NetVar.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Var.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Debug.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Event.h"
|
||||
#include "zeek/Expr.h"
|
||||
#include "zeek/File.h"
|
||||
#include "zeek/Frame.h"
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
#include "zeek/NetVar.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Traverse.h"
|
||||
#include "zeek/Trigger.h"
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
#include "zeek/Var.h"
|
||||
#include "zeek/logging/Manager.h"
|
||||
#include "zeek/script_opt/StmtOptInfo.h"
|
||||
|
||||
#include "zeek/logging/logging.bif.h"
|
||||
#include "zeek/script_opt/StmtOptInfo.h"
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
namespace zeek::detail
|
||||
{
|
||||
|
||||
const char* stmt_name(StmtTag t)
|
||||
{
|
||||
static const char* stmt_names[int(NUM_STMTS)] = {
|
||||
"alarm", // Does no longer exist, but kept for keeping enums consistent.
|
||||
"print", "event", "expr", "if", "when", "switch",
|
||||
"for", "next", "break", "return", "add", "delete",
|
||||
"list", "bodylist",
|
||||
"<init>", "fallthrough", "while",
|
||||
"print",
|
||||
"event",
|
||||
"expr",
|
||||
"if",
|
||||
"when",
|
||||
"switch",
|
||||
"for",
|
||||
"next",
|
||||
"break",
|
||||
"return",
|
||||
"add",
|
||||
"delete",
|
||||
"list",
|
||||
"bodylist",
|
||||
"<init>",
|
||||
"fallthrough",
|
||||
"while",
|
||||
"catch-return",
|
||||
"check-any-length",
|
||||
"compiled-C++",
|
||||
"ZAM", "ZAM-resumption",
|
||||
"ZAM",
|
||||
"ZAM-resumption",
|
||||
"null",
|
||||
};
|
||||
|
||||
|
@ -63,79 +76,79 @@ Stmt::~Stmt()
|
|||
StmtList* Stmt::AsStmtList()
|
||||
{
|
||||
CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name)
|
||||
return (StmtList*) this;
|
||||
return (StmtList*)this;
|
||||
}
|
||||
|
||||
const StmtList* Stmt::AsStmtList() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name)
|
||||
return (const StmtList*) this;
|
||||
return (const StmtList*)this;
|
||||
}
|
||||
|
||||
ForStmt* Stmt::AsForStmt()
|
||||
{
|
||||
CHECK_TAG(tag, STMT_FOR, "Stmt::AsForStmt", stmt_name)
|
||||
return (ForStmt*) this;
|
||||
return (ForStmt*)this;
|
||||
}
|
||||
|
||||
const ForStmt* Stmt::AsForStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_FOR, "Stmt::AsForStmt", stmt_name)
|
||||
return (const ForStmt*) this;
|
||||
return (const ForStmt*)this;
|
||||
}
|
||||
|
||||
const InitStmt* Stmt::AsInitStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_INIT, "Stmt::AsInitStmt", stmt_name)
|
||||
return (const InitStmt*) this;
|
||||
return (const InitStmt*)this;
|
||||
}
|
||||
|
||||
const IfStmt* Stmt::AsIfStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_IF, "Stmt::AsIfStmt", stmt_name)
|
||||
return (const IfStmt*) this;
|
||||
return (const IfStmt*)this;
|
||||
}
|
||||
|
||||
const WhileStmt* Stmt::AsWhileStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_WHILE, "Stmt::AsWhileStmt", stmt_name)
|
||||
return (const WhileStmt*) this;
|
||||
return (const WhileStmt*)this;
|
||||
}
|
||||
|
||||
const WhenStmt* Stmt::AsWhenStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_WHEN, "Stmt::AsWhenStmt", stmt_name)
|
||||
return (const WhenStmt*) this;
|
||||
return (const WhenStmt*)this;
|
||||
}
|
||||
|
||||
const SwitchStmt* Stmt::AsSwitchStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_SWITCH, "Stmt::AsSwitchStmt", stmt_name)
|
||||
return (const SwitchStmt*) this;
|
||||
return (const SwitchStmt*)this;
|
||||
}
|
||||
|
||||
const ExprStmt* Stmt::AsExprStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_EXPR, "Stmt::AsExprStmt", stmt_name)
|
||||
return (const ExprStmt*) this;
|
||||
return (const ExprStmt*)this;
|
||||
}
|
||||
|
||||
const PrintStmt* Stmt::AsPrintStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_PRINT, "Stmt::AsPrintStmt", stmt_name)
|
||||
return (const PrintStmt*) this;
|
||||
return (const PrintStmt*)this;
|
||||
}
|
||||
|
||||
const CatchReturnStmt* Stmt::AsCatchReturnStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_CATCH_RETURN, "Stmt::AsCatchReturnStmt", stmt_name)
|
||||
return (const CatchReturnStmt*) this;
|
||||
return (const CatchReturnStmt*)this;
|
||||
}
|
||||
|
||||
const ReturnStmt* Stmt::AsReturnStmt() const
|
||||
{
|
||||
CHECK_TAG(tag, STMT_RETURN, "Stmt::AsReturnStmt", stmt_name)
|
||||
return (const ReturnStmt*) this;
|
||||
return (const ReturnStmt*)this;
|
||||
}
|
||||
|
||||
bool Stmt::SetLocationInfo(const Location* start, const Location* end)
|
||||
|
@ -225,8 +238,7 @@ void Stmt::AccessStats(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
ExprListStmt::ExprListStmt(StmtTag t, ListExprPtr arg_l)
|
||||
: Stmt(t), l(std::move(arg_l))
|
||||
ExprListStmt::ExprListStmt(StmtTag t, ListExprPtr arg_l) : Stmt(t), l(std::move(arg_l))
|
||||
{
|
||||
const ExprPList& e = l->Exprs();
|
||||
for ( const auto& expr : e )
|
||||
|
@ -308,8 +320,7 @@ static void print_log(const std::vector<ValPtr>& vals)
|
|||
log_mgr->Write(plval.get(), record.get());
|
||||
}
|
||||
|
||||
ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
|
||||
StmtFlowType& /* flow */)
|
||||
ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals, StmtFlowType& /* flow */)
|
||||
{
|
||||
RegisterAccess();
|
||||
do_print_stmt(vals);
|
||||
|
@ -333,31 +344,31 @@ void do_print_stmt(const std::vector<ValPtr>& vals)
|
|||
++offset;
|
||||
}
|
||||
|
||||
static auto print_log_type = static_cast<BifEnum::Log::PrintLogType>(
|
||||
id::find_val("Log::print_to_log")->AsEnum());
|
||||
static auto print_log_type =
|
||||
static_cast<BifEnum::Log::PrintLogType>(id::find_val("Log::print_to_log")->AsEnum());
|
||||
|
||||
switch ( print_log_type ) {
|
||||
case BifEnum::Log::REDIRECT_NONE:
|
||||
break;
|
||||
case BifEnum::Log::REDIRECT_ALL:
|
||||
switch ( print_log_type )
|
||||
{
|
||||
print_log(vals);
|
||||
return;
|
||||
case BifEnum::Log::REDIRECT_NONE:
|
||||
break;
|
||||
case BifEnum::Log::REDIRECT_ALL:
|
||||
{
|
||||
print_log(vals);
|
||||
return;
|
||||
}
|
||||
case BifEnum::Log::REDIRECT_STDOUT:
|
||||
if ( f->FileHandle() == stdout )
|
||||
{
|
||||
// Should catch even printing to a "manually opened" stdout file,
|
||||
// like "/dev/stdout" or "-".
|
||||
print_log(vals);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
reporter->InternalError("unknown Log::PrintLogType value: %d", print_log_type);
|
||||
break;
|
||||
}
|
||||
case BifEnum::Log::REDIRECT_STDOUT:
|
||||
if ( f->FileHandle() == stdout )
|
||||
{
|
||||
// Should catch even printing to a "manually opened" stdout file,
|
||||
// like "/dev/stdout" or "-".
|
||||
print_log(vals);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
reporter->InternalError("unknown Log::PrintLogType value: %d",
|
||||
print_log_type);
|
||||
break;
|
||||
}
|
||||
|
||||
DescStyle style = f->IsRawOutput() ? RAW_STYLE : STANDARD_STYLE;
|
||||
|
||||
|
@ -463,11 +474,8 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IfStmt::IfStmt(ExprPtr test,
|
||||
StmtPtr arg_s1,
|
||||
StmtPtr arg_s2)
|
||||
: ExprStmt(STMT_IF, std::move(test)),
|
||||
s1(std::move(arg_s1)), s2(std::move(arg_s2))
|
||||
IfStmt::IfStmt(ExprPtr test, StmtPtr arg_s1, StmtPtr arg_s2)
|
||||
: ExprStmt(STMT_IF, std::move(test)), s1(std::move(arg_s1)), s2(std::move(arg_s2))
|
||||
{
|
||||
if ( ! e->IsError() && ! IsBool(e->GetType()->Tag()) )
|
||||
e->Error("conditional in test must be boolean");
|
||||
|
@ -564,7 +572,8 @@ static StmtTag get_last_stmt_tag(const Stmt* stmt)
|
|||
return get_last_stmt_tag(stmts->Stmts()[len - 1]);
|
||||
}
|
||||
|
||||
class FallthroughFinder : public TraversalCallback {
|
||||
class FallthroughFinder : public TraversalCallback
|
||||
{
|
||||
TraversalCode PreStmt(const Stmt* stmt) override
|
||||
{
|
||||
if ( stmt->Tag() == STMT_SWITCH )
|
||||
|
@ -579,12 +588,10 @@ class FallthroughFinder : public TraversalCallback {
|
|||
reporter->PopLocation();
|
||||
return TC_CONTINUE;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Case::Case(ListExprPtr arg_expr_cases, IDPList* arg_type_cases,
|
||||
StmtPtr arg_s)
|
||||
: expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases),
|
||||
s(std::move(arg_s))
|
||||
Case::Case(ListExprPtr arg_expr_cases, IDPList* arg_type_cases, StmtPtr arg_s)
|
||||
: expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases), s(std::move(arg_s))
|
||||
{
|
||||
StmtTag t = get_last_stmt_tag(Body());
|
||||
|
||||
|
@ -706,7 +713,7 @@ TraversalCode Case::Traverse(TraversalCallback* cb) const
|
|||
|
||||
static void int_del_func(void* v)
|
||||
{
|
||||
delete (int*) v;
|
||||
delete (int*)v;
|
||||
}
|
||||
|
||||
void SwitchStmt::Init()
|
||||
|
@ -719,8 +726,7 @@ void SwitchStmt::Init()
|
|||
}
|
||||
|
||||
SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
|
||||
: ExprStmt(STMT_SWITCH, std::move(index)),
|
||||
cases(arg_cases), default_case_idx(-1)
|
||||
: ExprStmt(STMT_SWITCH, std::move(index)), cases(arg_cases), default_case_idx(-1)
|
||||
{
|
||||
Init();
|
||||
|
||||
|
@ -754,43 +760,44 @@ SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
|
|||
{
|
||||
Expr* expr = exprs[j];
|
||||
|
||||
switch ( expr->Tag() ) {
|
||||
// Simplify trivial unary plus/minus expressions on consts.
|
||||
case EXPR_NEGATE:
|
||||
switch ( expr->Tag() )
|
||||
{
|
||||
NegExpr* ne = (NegExpr*)(expr);
|
||||
// Simplify trivial unary plus/minus expressions on consts.
|
||||
case EXPR_NEGATE:
|
||||
{
|
||||
NegExpr* ne = (NegExpr*)(expr);
|
||||
|
||||
if ( ne->Op()->IsConst() )
|
||||
Unref(exprs.replace(j, new ConstExpr(ne->Eval(nullptr))));
|
||||
if ( ne->Op()->IsConst() )
|
||||
Unref(exprs.replace(j, new ConstExpr(ne->Eval(nullptr))));
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_POSITIVE:
|
||||
{
|
||||
PosExpr* pe = (PosExpr*)(expr);
|
||||
|
||||
if ( pe->Op()->IsConst() )
|
||||
Unref(exprs.replace(j, new ConstExpr(pe->Eval(nullptr))));
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_NAME:
|
||||
{
|
||||
NameExpr* ne = (NameExpr*)(expr);
|
||||
|
||||
if ( ne->Id()->IsConst() )
|
||||
{
|
||||
auto v = ne->Eval(nullptr);
|
||||
|
||||
if ( v )
|
||||
Unref(exprs.replace(j, new ConstExpr(std::move(v))));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_POSITIVE:
|
||||
{
|
||||
PosExpr* pe = (PosExpr*)(expr);
|
||||
|
||||
if ( pe->Op()->IsConst() )
|
||||
Unref(exprs.replace(j, new ConstExpr(pe->Eval(nullptr))));
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_NAME:
|
||||
{
|
||||
NameExpr* ne = (NameExpr*)(expr);
|
||||
|
||||
if ( ne->Id()->IsConst() )
|
||||
{
|
||||
auto v = ne->Eval(nullptr);
|
||||
|
||||
if ( v )
|
||||
Unref(exprs.replace(j, new ConstExpr(std::move(v))));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! exprs[j]->IsConst() )
|
||||
|
@ -811,7 +818,7 @@ SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
|
|||
{
|
||||
const auto& ct = t->GetType();
|
||||
|
||||
if ( ! can_cast_value_to_type(e->GetType().get(), ct.get()) )
|
||||
if ( ! can_cast_value_to_type(e->GetType().get(), ct.get()) )
|
||||
{
|
||||
c->Error("cannot cast switch expression to case type");
|
||||
continue;
|
||||
|
@ -836,7 +843,6 @@ SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
|
|||
|
||||
if ( have_exprs && have_types )
|
||||
Error("cannot mix cases with expressions and types");
|
||||
|
||||
}
|
||||
|
||||
SwitchStmt::~SwitchStmt()
|
||||
|
@ -856,8 +862,7 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
|
|||
{
|
||||
reporter->PushLocation(e->GetLocationInfo());
|
||||
reporter->InternalError("switch expression type mismatch (%s/%s)",
|
||||
type_name(v->GetType()->Tag()),
|
||||
type_name(e->GetType()->Tag()));
|
||||
type_name(v->GetType()->Tag()), type_name(e->GetType()->Tag()));
|
||||
}
|
||||
|
||||
int* label_idx = case_label_hash_map.Lookup(hk.get());
|
||||
|
@ -898,8 +903,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
|
|||
{
|
||||
reporter->PushLocation(e->GetLocationInfo());
|
||||
reporter->Error("switch expression type mismatch (%s/%s)",
|
||||
type_name(v->GetType()->Tag()),
|
||||
type_name(e->GetType()->Tag()));
|
||||
type_name(v->GetType()->Tag()), type_name(e->GetType()->Tag()));
|
||||
return std::make_pair(-1, nullptr);
|
||||
}
|
||||
|
||||
|
@ -951,7 +955,7 @@ ValPtr SwitchStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow)
|
|||
flow = FLOW_NEXT;
|
||||
rval = c->Body()->Exec(f, flow);
|
||||
|
||||
if ( flow == FLOW_BREAK || flow == FLOW_RETURN )
|
||||
if ( flow == FLOW_BREAK || flow == FLOW_RETURN )
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1012,11 +1016,7 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
|
||||
AddDelStmt::AddDelStmt(StmtTag t, ExprPtr arg_e)
|
||||
: ExprStmt(t, std::move(arg_e))
|
||||
{
|
||||
}
|
||||
AddDelStmt::AddDelStmt(StmtTag t, ExprPtr arg_e) : ExprStmt(t, std::move(arg_e)) { }
|
||||
|
||||
bool AddDelStmt::IsPure() const
|
||||
{
|
||||
|
@ -1036,7 +1036,6 @@ TraversalCode AddDelStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
|
||||
AddStmt::AddStmt(ExprPtr arg_e) : AddDelStmt(STMT_ADD, std::move(arg_e))
|
||||
{
|
||||
if ( ! e->CanAdd() )
|
||||
|
@ -1051,7 +1050,6 @@ ValPtr AddStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
DelStmt::DelStmt(ExprPtr arg_e) : AddDelStmt(STMT_DELETE, std::move(arg_e))
|
||||
{
|
||||
if ( e->IsError() )
|
||||
|
@ -1069,9 +1067,7 @@ ValPtr DelStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
EventStmt::EventStmt(EventExprPtr arg_e)
|
||||
: ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
|
||||
EventStmt::EventStmt(EventExprPtr arg_e) : ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1102,12 +1098,9 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
|
|||
}
|
||||
|
||||
WhileStmt::WhileStmt(ExprPtr arg_loop_condition, StmtPtr arg_body)
|
||||
: Stmt(STMT_WHILE),
|
||||
loop_condition(std::move(arg_loop_condition)),
|
||||
body(std::move(arg_body))
|
||||
: Stmt(STMT_WHILE), loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body))
|
||||
{
|
||||
if ( ! loop_condition->IsError() &&
|
||||
! IsBool(loop_condition->GetType()->Tag()) )
|
||||
if ( ! loop_condition->IsError() && ! IsBool(loop_condition->GetType()->Tag()) )
|
||||
loop_condition->Error("while conditional must be boolean");
|
||||
}
|
||||
|
||||
|
@ -1174,7 +1167,7 @@ ValPtr WhileStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
flow = FLOW_NEXT;
|
||||
ValPtr rval;
|
||||
|
||||
for ( ; ; )
|
||||
for ( ;; )
|
||||
{
|
||||
if ( loop_cond_pred_stmt )
|
||||
loop_cond_pred_stmt->Exec(f, flow);
|
||||
|
@ -1230,8 +1223,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
|
|||
|
||||
else
|
||||
{
|
||||
add_local({NewRef{}, lv}, ind_type, INIT_NONE,
|
||||
nullptr, nullptr, VAR_REGULAR);
|
||||
add_local({NewRef{}, lv}, ind_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1247,8 +1239,8 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
|
|||
const auto& t = (*loop_vars)[0]->GetType();
|
||||
|
||||
if ( ! t )
|
||||
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT),
|
||||
INIT_NONE, nullptr, nullptr, VAR_REGULAR);
|
||||
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT), INIT_NONE, nullptr,
|
||||
nullptr, VAR_REGULAR);
|
||||
|
||||
else if ( ! IsIntegral(t->Tag()) )
|
||||
{
|
||||
|
@ -1268,9 +1260,8 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
|
|||
const auto& t = (*loop_vars)[0]->GetType();
|
||||
|
||||
if ( ! t )
|
||||
add_local({NewRef{}, (*loop_vars)[0]},
|
||||
base_type(TYPE_STRING),
|
||||
INIT_NONE, nullptr, nullptr, VAR_REGULAR);
|
||||
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), INIT_NONE, nullptr,
|
||||
nullptr, VAR_REGULAR);
|
||||
|
||||
else if ( t->Tag() != TYPE_STRING )
|
||||
{
|
||||
|
@ -1282,8 +1273,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
|
|||
e->Error("target to iterate over must be a table, set, vector, or string");
|
||||
}
|
||||
|
||||
ForStmt::ForStmt(IDPList* arg_loop_vars,
|
||||
ExprPtr loop_expr, IDPtr val_var)
|
||||
ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr, IDPtr val_var)
|
||||
: ForStmt(arg_loop_vars, std::move(loop_expr))
|
||||
{
|
||||
value_var = std::move(val_var);
|
||||
|
@ -1372,7 +1362,7 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow)
|
|||
|
||||
for ( int i = 0; i < sval->Len(); ++i )
|
||||
{
|
||||
auto sv = make_intrusive<StringVal>(1, (const char*) sval->Bytes() + i);
|
||||
auto sv = make_intrusive<StringVal>(1, (const char*)sval->Bytes() + i);
|
||||
f->SetElement((*loop_vars)[0], std::move(sv));
|
||||
flow = FLOW_NEXT;
|
||||
ret = body->Exec(f, flow);
|
||||
|
@ -1386,10 +1376,10 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow)
|
|||
e->Error("Invalid type in for-loop execution");
|
||||
|
||||
if ( flow == FLOW_LOOP )
|
||||
flow = FLOW_NEXT; // last iteration exited with a "next"
|
||||
flow = FLOW_NEXT; // last iteration exited with a "next"
|
||||
|
||||
if ( flow == FLOW_BREAK )
|
||||
flow = FLOW_NEXT; // we've now finished the "break"
|
||||
flow = FLOW_NEXT; // we've now finished the "break"
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1537,8 +1527,7 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
ReturnStmt::ReturnStmt(ExprPtr arg_e)
|
||||
: ExprStmt(STMT_RETURN, std::move(arg_e))
|
||||
ReturnStmt::ReturnStmt(ExprPtr arg_e) : ExprStmt(STMT_RETURN, std::move(arg_e))
|
||||
{
|
||||
auto s = current_scope();
|
||||
|
||||
|
@ -1721,20 +1710,20 @@ ValPtr InitStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
|
||||
ValPtr v;
|
||||
|
||||
switch ( t->Tag() ) {
|
||||
case TYPE_RECORD:
|
||||
v = make_intrusive<RecordVal>(cast_intrusive<RecordType>(t));
|
||||
break;
|
||||
case TYPE_VECTOR:
|
||||
v = make_intrusive<VectorVal>(cast_intrusive<VectorType>(t));
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
v = make_intrusive<TableVal>(cast_intrusive<TableType>(t),
|
||||
aggr->GetAttrs());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch ( t->Tag() )
|
||||
{
|
||||
case TYPE_RECORD:
|
||||
v = make_intrusive<RecordVal>(cast_intrusive<RecordType>(t));
|
||||
break;
|
||||
case TYPE_VECTOR:
|
||||
v = make_intrusive<VectorVal>(cast_intrusive<VectorType>(t));
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
v = make_intrusive<TableVal>(cast_intrusive<TableType>(t), aggr->GetAttrs());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
f->SetElement(aggr, std::move(v));
|
||||
}
|
||||
|
@ -1804,11 +1793,9 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
WhenStmt::WhenStmt(ExprPtr arg_cond,
|
||||
StmtPtr arg_s1, StmtPtr arg_s2,
|
||||
ExprPtr arg_timeout, bool arg_is_return)
|
||||
: Stmt(STMT_WHEN),
|
||||
cond(std::move(arg_cond)), s1(std::move(arg_s1)), s2(std::move(arg_s2)),
|
||||
WhenStmt::WhenStmt(ExprPtr arg_cond, StmtPtr arg_s1, StmtPtr arg_s2, ExprPtr arg_timeout,
|
||||
bool arg_is_return)
|
||||
: Stmt(STMT_WHEN), cond(std::move(arg_cond)), s1(std::move(arg_s1)), s2(std::move(arg_s2)),
|
||||
timeout(std::move(arg_timeout)), is_return(arg_is_return)
|
||||
{
|
||||
assert(cond);
|
||||
|
@ -1836,11 +1823,9 @@ ValPtr WhenStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
flow = FLOW_NEXT;
|
||||
|
||||
// The new trigger object will take care of its own deletion.
|
||||
new trigger::Trigger(IntrusivePtr{cond}.release(),
|
||||
IntrusivePtr{s1}.release(),
|
||||
IntrusivePtr{s2}.release(),
|
||||
IntrusivePtr{timeout}.release(),
|
||||
f, is_return, location);
|
||||
new trigger::Trigger(IntrusivePtr{cond}.release(), IntrusivePtr{s1}.release(),
|
||||
IntrusivePtr{s2}.release(), IntrusivePtr{timeout}.release(), f, is_return,
|
||||
location);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1907,4 +1892,4 @@ TraversalCode WhenStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
} // namespace zeek::detail
|
||||
} // namespace zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue