mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
fixes & enhancements to location information associated w/ AST nodes & ZAM optimization
This commit is contained in:
parent
7a283afe00
commit
e5bb63c662
14 changed files with 299 additions and 259 deletions
|
@ -348,10 +348,10 @@ ExprPtr Expr::AssignToTemporary(ExprPtr e, Reducer* c, StmtPtr& red_stmt) {
|
|||
auto result_tmp = c->GenTemporaryExpr(GetType(), e);
|
||||
|
||||
auto a_e = make_intrusive<AssignExpr>(result_tmp->MakeLvalue(), e, false, nullptr, nullptr, false);
|
||||
a_e->SetLocationInfo(GetLocationInfo());
|
||||
a_e->SetIsTemp();
|
||||
a_e->SetOriginal(ThisPtr());
|
||||
|
||||
auto a_e_s = make_intrusive<ExprStmt>(a_e);
|
||||
auto a_e_s = with_location_of(make_intrusive<ExprStmt>(a_e), this);
|
||||
red_stmt = MergeStmts(red_stmt, a_e_s);
|
||||
|
||||
// Important: our result is not result_tmp, but a duplicate of it.
|
||||
|
@ -366,7 +366,7 @@ ExprPtr Expr::TransformMe(ExprPtr new_me, Reducer* c, StmtPtr& red_stmt) {
|
|||
if ( new_me == this )
|
||||
return new_me;
|
||||
|
||||
new_me->SetOriginal(ThisPtr());
|
||||
new_me->SetLocationInfo(GetLocationInfo());
|
||||
|
||||
// Unlike for Stmt's, we assume that new_me has already
|
||||
// been reduced, so no need to do so further.
|
||||
|
@ -377,7 +377,7 @@ StmtPtr Expr::MergeStmts(StmtPtr s1, StmtPtr s2, StmtPtr s3) const {
|
|||
int nums = (s1 != nullptr) + (s2 != nullptr) + (s3 != nullptr);
|
||||
|
||||
if ( nums > 1 )
|
||||
return make_intrusive<StmtList>(s1, s2, s3);
|
||||
return with_location_of(make_intrusive<StmtList>(s1, s2, s3), this);
|
||||
else if ( s1 )
|
||||
return s1;
|
||||
else if ( s2 )
|
||||
|
@ -402,7 +402,11 @@ ValPtr Expr::MakeZero(TypeTag t) const {
|
|||
}
|
||||
}
|
||||
|
||||
ConstExprPtr Expr::MakeZeroExpr(TypeTag t) const { return make_intrusive<ConstExpr>(MakeZero(t)); }
|
||||
ConstExprPtr Expr::MakeZeroExpr(TypeTag t) const {
|
||||
auto z = make_intrusive<ConstExpr>(MakeZero(t));
|
||||
z->SetLocationInfo(GetLocationInfo());
|
||||
return z;
|
||||
}
|
||||
|
||||
ExprPtr NameExpr::Duplicate() { return SetSucc(new NameExpr(id, in_const_init)); }
|
||||
|
||||
|
@ -569,17 +573,15 @@ ExprPtr IncrExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
StmtPtr target_stmt;
|
||||
target = target->ReduceToSingleton(c, target_stmt);
|
||||
|
||||
auto incr_const = make_intrusive<ConstExpr>(val_mgr->Count(1));
|
||||
incr_const->SetOriginal(ThisPtr());
|
||||
auto incr_const = with_location_of(make_intrusive<ConstExpr>(val_mgr->Count(1)), this);
|
||||
|
||||
ExprPtr incr_expr;
|
||||
|
||||
if ( Tag() == EXPR_INCR )
|
||||
incr_expr = make_intrusive<AddExpr>(target, incr_const);
|
||||
incr_expr = with_location_of(make_intrusive<AddExpr>(target, incr_const), this);
|
||||
else
|
||||
incr_expr = make_intrusive<SubExpr>(target, incr_const);
|
||||
incr_expr = with_location_of(make_intrusive<SubExpr>(target, incr_const), this);
|
||||
|
||||
incr_expr->SetOriginal(ThisPtr());
|
||||
StmtPtr incr_stmt;
|
||||
auto incr_expr2 = incr_expr->Reduce(c, incr_stmt);
|
||||
|
||||
|
@ -594,21 +596,19 @@ ExprPtr IncrExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
auto dup1 = orig_target->GetOp1()->Duplicate();
|
||||
auto dup2 = orig_target->GetOp2()->Duplicate();
|
||||
auto index = dup2->AsListExprPtr();
|
||||
orig_target = make_intrusive<IndexExpr>(dup1, index);
|
||||
orig_target = with_location_of(make_intrusive<IndexExpr>(dup1, index), this);
|
||||
}
|
||||
|
||||
else if ( orig_target->Tag() == EXPR_FIELD ) {
|
||||
auto dup1 = orig_target->GetOp1()->Duplicate();
|
||||
auto field_name = orig_target->AsFieldExpr()->FieldName();
|
||||
orig_target = make_intrusive<FieldExpr>(dup1, field_name);
|
||||
orig_target = with_location_of(make_intrusive<FieldExpr>(dup1, field_name), this);
|
||||
}
|
||||
|
||||
else
|
||||
reporter->InternalError("confused in IncrExpr::Reduce");
|
||||
|
||||
auto assign = make_intrusive<AssignExpr>(orig_target, rhs, false, nullptr, nullptr, false);
|
||||
|
||||
orig_target->SetOriginal(ThisPtr());
|
||||
auto assign = with_location_of(make_intrusive<AssignExpr>(orig_target, rhs, false, nullptr, nullptr, false), this);
|
||||
|
||||
// First reduce it regularly, so it can transform into $= or
|
||||
// such as needed. Then reduce that to a singleton to provide
|
||||
|
@ -628,7 +628,7 @@ ExprPtr IncrExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
if ( target->Tag() == EXPR_NAME && IsIntegral(target->GetType()->Tag()) ) {
|
||||
ExprPtr incr_expr = Duplicate();
|
||||
red_stmt = make_intrusive<ExprStmt>(incr_expr)->Reduce(c);
|
||||
red_stmt = with_location_of(make_intrusive<ExprStmt>(incr_expr), this)->Reduce(c);
|
||||
|
||||
StmtPtr targ_red_stmt;
|
||||
auto targ_red = target->Reduce(c, targ_red_stmt);
|
||||
|
@ -719,9 +719,7 @@ ExprPtr AddExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
ExprPtr AddExpr::BuildSub(const ExprPtr& op1, const ExprPtr& op2) {
|
||||
auto rhs = op2->GetOp1();
|
||||
auto sub = make_intrusive<SubExpr>(op1, rhs);
|
||||
sub->SetOriginal(ThisPtr());
|
||||
return sub;
|
||||
return with_location_of(make_intrusive<SubExpr>(op1, rhs), this);
|
||||
}
|
||||
|
||||
ExprPtr AddToExpr::Duplicate() {
|
||||
|
@ -767,10 +765,8 @@ ExprPtr AddToExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
red_stmt = MergeStmts(red_stmt1, red_stmt2);
|
||||
|
||||
if ( tag == TYPE_VECTOR && (! IsVector(op2->GetType()->Tag()) || ! same_type(t, op2->GetType())) ) {
|
||||
auto append = make_intrusive<AppendToExpr>(op1->Duplicate(), op2);
|
||||
append->SetOriginal(ThisPtr());
|
||||
|
||||
auto append_stmt = make_intrusive<ExprStmt>(append);
|
||||
auto append = with_location_of(make_intrusive<AppendToExpr>(op1->Duplicate(), op2), this);
|
||||
auto append_stmt = with_location_of(make_intrusive<ExprStmt>(append), this);
|
||||
|
||||
red_stmt = MergeStmts(red_stmt, append_stmt);
|
||||
|
||||
|
@ -782,8 +778,9 @@ ExprPtr AddToExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
default: {
|
||||
auto rhs = op1->AsRefExprPtr()->GetOp1();
|
||||
auto do_incr = make_intrusive<AddExpr>(rhs->Duplicate(), op2);
|
||||
auto assign = make_intrusive<AssignExpr>(op1, do_incr, false, nullptr, nullptr, false);
|
||||
auto do_incr = with_location_of(make_intrusive<AddExpr>(rhs->Duplicate(), op2), this);
|
||||
auto assign =
|
||||
with_location_of(make_intrusive<AssignExpr>(op1, do_incr, false, nullptr, nullptr, false), this);
|
||||
|
||||
return assign->ReduceToSingleton(c, red_stmt);
|
||||
}
|
||||
|
@ -791,7 +788,7 @@ ExprPtr AddToExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
}
|
||||
|
||||
ExprPtr AddToExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
||||
auto at_stmt = make_intrusive<ExprStmt>(Duplicate());
|
||||
auto at_stmt = with_location_of(make_intrusive<ExprStmt>(Duplicate()), this);
|
||||
red_stmt = at_stmt->Reduce(c);
|
||||
return op1;
|
||||
}
|
||||
|
@ -814,8 +811,7 @@ ExprPtr SubExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
if ( op2->Tag() == EXPR_NEGATE ) {
|
||||
auto rhs = op2->GetOp1();
|
||||
auto add = make_intrusive<AddExpr>(op1, rhs);
|
||||
add->SetOriginal(ThisPtr());
|
||||
auto add = with_location_of(make_intrusive<AddExpr>(op1, rhs), this);
|
||||
return add->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -864,14 +860,14 @@ ExprPtr RemoveFromExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
}
|
||||
|
||||
auto lhs = op1->AsRefExprPtr()->GetOp1();
|
||||
auto do_decr = make_intrusive<SubExpr>(lhs->Duplicate(), op2);
|
||||
auto assign = make_intrusive<AssignExpr>(op1, do_decr, false, nullptr, nullptr, false);
|
||||
auto do_decr = with_location_of(make_intrusive<SubExpr>(lhs->Duplicate(), op2), this);
|
||||
auto assign = with_location_of(make_intrusive<AssignExpr>(op1, do_decr, false, nullptr, nullptr, false), this);
|
||||
|
||||
return assign->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
ExprPtr RemoveFromExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
||||
auto rf_stmt = make_intrusive<ExprStmt>(Duplicate());
|
||||
auto rf_stmt = with_location_of(make_intrusive<ExprStmt>(Duplicate()), this);
|
||||
red_stmt = rf_stmt->Reduce(c);
|
||||
return op1;
|
||||
}
|
||||
|
@ -970,13 +966,13 @@ static bool is_pattern_cascade(const ExprPtr& e, IDPtr& id, std::vector<ConstExp
|
|||
|
||||
// Given a set of pattern constants, returns a disjunction that
|
||||
// includes all of them.
|
||||
static ExprPtr build_disjunction(std::vector<ConstExprPtr>& patterns) {
|
||||
static ExprPtr build_disjunction(std::vector<ConstExprPtr>& patterns, const Obj* obj) {
|
||||
ASSERT(patterns.size() > 1);
|
||||
|
||||
ExprPtr e = patterns[0];
|
||||
|
||||
for ( auto& p : patterns )
|
||||
e = make_intrusive<BitExpr>(EXPR_OR, e, p);
|
||||
e = with_location_of(make_intrusive<BitExpr>(EXPR_OR, e, p), obj);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
@ -1005,9 +1001,9 @@ ExprPtr BoolExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
IDPtr common_id = nullptr;
|
||||
std::vector<ConstExprPtr> patterns;
|
||||
if ( tag == EXPR_OR_OR && is_pattern_cascade(ThisPtr(), common_id, patterns) ) {
|
||||
auto new_pat = build_disjunction(patterns);
|
||||
auto new_id = make_intrusive<NameExpr>(common_id);
|
||||
auto new_node = make_intrusive<InExpr>(new_pat, new_id);
|
||||
auto new_pat = build_disjunction(patterns, this);
|
||||
auto new_id = with_location_of(make_intrusive<NameExpr>(common_id), this);
|
||||
auto new_node = with_location_of(make_intrusive<InExpr>(new_pat, new_id), this);
|
||||
return new_node->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -1052,16 +1048,15 @@ ExprPtr BoolExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
}
|
||||
|
||||
auto else_val = is_and ? val_mgr->False() : val_mgr->True();
|
||||
ExprPtr else_e = make_intrusive<ConstExpr>(else_val);
|
||||
ExprPtr else_e = with_location_of(make_intrusive<ConstExpr>(else_val), this);
|
||||
|
||||
ExprPtr cond;
|
||||
if ( is_and )
|
||||
cond = make_intrusive<CondExpr>(op1, op2, else_e);
|
||||
cond = with_location_of(make_intrusive<CondExpr>(op1, op2, else_e), this);
|
||||
else
|
||||
cond = make_intrusive<CondExpr>(op1, else_e, op2);
|
||||
cond = with_location_of(make_intrusive<CondExpr>(op1, else_e, op2), this);
|
||||
|
||||
auto cond_red = cond->ReduceToSingleton(c, red_stmt);
|
||||
|
||||
return TransformMe(cond_red, c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -1118,8 +1113,7 @@ ExprPtr BitExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
auto n = op1->AsNameExpr();
|
||||
|
||||
if ( Tag() == EXPR_XOR ) {
|
||||
auto zero = make_intrusive<ConstExpr>(val_mgr->Count(0));
|
||||
zero->SetOriginal(ThisPtr());
|
||||
auto zero = with_location_of(make_intrusive<ConstExpr>(val_mgr->Count(0)), this);
|
||||
return zero->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -1141,8 +1135,7 @@ bool EqExpr::WillTransform(Reducer* c) const { return GetType()->Tag() == TYPE_B
|
|||
ExprPtr EqExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||
if ( GetType()->Tag() == TYPE_BOOL && same_singletons(op1, op2) ) {
|
||||
bool t = Tag() == EXPR_EQ;
|
||||
auto res = make_intrusive<ConstExpr>(val_mgr->Bool(t));
|
||||
res->SetOriginal(ThisPtr());
|
||||
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
||||
return res->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -1161,8 +1154,7 @@ ExprPtr RelExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
if ( GetType()->Tag() == TYPE_BOOL ) {
|
||||
if ( same_singletons(op1, op2) ) {
|
||||
bool t = Tag() == EXPR_GE || Tag() == EXPR_LE;
|
||||
auto res = make_intrusive<ConstExpr>(val_mgr->Bool(t));
|
||||
res->SetOriginal(ThisPtr());
|
||||
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
||||
return res->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -1248,7 +1240,7 @@ ExprPtr CondExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
return op1;
|
||||
|
||||
// Instead we have "var ? F : T".
|
||||
return make_intrusive<NotExpr>(op1);
|
||||
return TransformMe(make_intrusive<NotExpr>(op1), c, red_stmt);
|
||||
}
|
||||
|
||||
if ( c->Optimizing() )
|
||||
|
@ -1288,11 +1280,12 @@ StmtPtr CondExpr::ReduceToSingletons(Reducer* c) {
|
|||
|
||||
if ( red2_stmt || red3_stmt ) {
|
||||
if ( ! red2_stmt )
|
||||
red2_stmt = make_intrusive<NullStmt>();
|
||||
red2_stmt = with_location_of(make_intrusive<NullStmt>(), this);
|
||||
if ( ! red3_stmt )
|
||||
red3_stmt = make_intrusive<NullStmt>();
|
||||
red3_stmt = with_location_of(make_intrusive<NullStmt>(), this);
|
||||
|
||||
if_else = make_intrusive<IfStmt>(op1->Duplicate(), std::move(red2_stmt), std::move(red3_stmt));
|
||||
if_else = with_location_of(make_intrusive<IfStmt>(op1->Duplicate(), std::move(red2_stmt), std::move(red3_stmt)),
|
||||
this);
|
||||
}
|
||||
|
||||
return MergeStmts(red1_stmt, if_else);
|
||||
|
@ -1343,7 +1336,7 @@ StmtPtr RefExpr::ReduceToLHS(Reducer* c) {
|
|||
}
|
||||
|
||||
auto red_stmt1 = op->ReduceToSingletons(c);
|
||||
auto op_ref = make_intrusive<RefExpr>(op);
|
||||
auto op_ref = with_location_of(make_intrusive<RefExpr>(op), this);
|
||||
|
||||
StmtPtr red_stmt2;
|
||||
op = AssignToTemporary(op_ref, c, red_stmt2);
|
||||
|
@ -1428,9 +1421,9 @@ ExprPtr AssignExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
if ( val ) {
|
||||
// These are reduced to the assignment followed by
|
||||
// the assignment value.
|
||||
auto assign_val = make_intrusive<ConstExpr>(val);
|
||||
auto assign_val = with_location_of(make_intrusive<ConstExpr>(val), this);
|
||||
val = nullptr;
|
||||
red_stmt = make_intrusive<ExprStmt>(ThisPtr());
|
||||
red_stmt = with_location_of(make_intrusive<ExprStmt>(ThisPtr()), this);
|
||||
return assign_val;
|
||||
}
|
||||
|
||||
|
@ -1443,6 +1436,8 @@ ExprPtr AssignExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
StmtPtr rhs_reduce;
|
||||
|
||||
if ( lhs_is_any != rhs_is_any ) {
|
||||
auto op2_orig = op2;
|
||||
|
||||
ExprPtr red_rhs = op2->ReduceToSingleton(c, rhs_reduce);
|
||||
|
||||
if ( lhs_is_any ) {
|
||||
|
@ -1453,11 +1448,13 @@ ExprPtr AssignExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
}
|
||||
else
|
||||
op2 = make_intrusive<CoerceFromAnyExpr>(red_rhs, t1);
|
||||
|
||||
op2->SetLocationInfo(op2_orig->GetLocationInfo());
|
||||
}
|
||||
|
||||
if ( t1->Tag() == TYPE_VECTOR && t1->Yield()->Tag() != TYPE_ANY && t2->Yield() && t2->Yield()->Tag() == TYPE_ANY ) {
|
||||
ExprPtr red_rhs = op2->ReduceToSingleton(c, rhs_reduce);
|
||||
op2 = make_intrusive<CoerceFromAnyVecExpr>(red_rhs, t1);
|
||||
op2 = with_location_of(make_intrusive<CoerceFromAnyVecExpr>(red_rhs, t1), op2);
|
||||
}
|
||||
|
||||
auto lhs_ref = op1->AsRefExprPtr();
|
||||
|
@ -1511,10 +1508,12 @@ ExprPtr AssignExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
loop_over_list(lhs_list, i) {
|
||||
auto rhs_dup = rhs_e->Duplicate();
|
||||
auto rhs = make_intrusive<AnyIndexExpr>(rhs_dup, i);
|
||||
auto rhs = with_location_of(make_intrusive<AnyIndexExpr>(rhs_dup, i), this);
|
||||
auto lhs = lhs_list[i]->ThisPtr();
|
||||
lhs->SetLocationInfo(GetLocationInfo());
|
||||
auto assign = make_intrusive<AssignExpr>(lhs, rhs, false, nullptr, nullptr, false);
|
||||
auto assign_stmt = make_intrusive<ExprStmt>(assign);
|
||||
|
||||
auto assign_stmt = with_location_of(make_intrusive<ExprStmt>(assign), this);
|
||||
red_stmt = MergeStmts(red_stmt, assign_stmt);
|
||||
}
|
||||
|
||||
|
@ -1562,11 +1561,11 @@ ExprPtr AssignExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
|||
Internal("Confusion in AssignExpr::ReduceToSingleton");
|
||||
|
||||
ExprPtr assign_expr = Duplicate();
|
||||
auto ae_stmt = make_intrusive<ExprStmt>(assign_expr);
|
||||
auto ae_stmt = with_location_of(make_intrusive<ExprStmt>(assign_expr), this);
|
||||
red_stmt = ae_stmt->Reduce(c);
|
||||
|
||||
if ( val )
|
||||
return make_intrusive<ConstExpr>(val);
|
||||
return TransformMe(make_intrusive<ConstExpr>(val), c, red_stmt);
|
||||
|
||||
auto lhs = op1->AsRefExprPtr()->GetOp1();
|
||||
StmtPtr lhs_stmt;
|
||||
|
@ -1884,7 +1883,7 @@ ExprPtr ArithCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
if ( IsArithmetic(t->Tag()) || IsArithmetic(ct->Tag()) ) {
|
||||
if ( auto v = FoldSingleVal(cv, t) )
|
||||
return make_intrusive<ConstExpr>(v);
|
||||
return TransformMe(make_intrusive<ConstExpr>(v), c, red_stmt);
|
||||
// else there was a coercion error, fall through
|
||||
}
|
||||
}
|
||||
|
@ -1926,7 +1925,7 @@ ExprPtr RecordCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
if ( WillTransform(c) ) {
|
||||
auto rt = cast_intrusive<RecordType>(type);
|
||||
auto rc_op = op->AsRecordConstructorExpr();
|
||||
auto known_constr = make_intrusive<RecordConstructorExpr>(rt, rc_op->Op());
|
||||
auto known_constr = with_location_of(make_intrusive<RecordConstructorExpr>(rt, rc_op->Op()), this);
|
||||
auto red_e = known_constr->Reduce(c, red_stmt);
|
||||
return TransformMe(std::move(red_e), c, red_stmt);
|
||||
}
|
||||
|
@ -1960,7 +1959,7 @@ ExprPtr VectorCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
auto op1_list = op->GetOp1();
|
||||
ASSERT(op1_list->Tag() == EXPR_LIST);
|
||||
auto empty_list = cast_intrusive<ListExpr>(op1_list);
|
||||
auto new_me = make_intrusive<VectorConstructorExpr>(empty_list, type);
|
||||
auto new_me = with_location_of(make_intrusive<VectorConstructorExpr>(empty_list, type), this);
|
||||
auto red_e = new_me->Reduce(c, red_stmt);
|
||||
return TransformMe(std::move(red_e), c, red_stmt);
|
||||
}
|
||||
|
@ -2039,7 +2038,7 @@ bool InExpr::HasReducedOps(Reducer* c) const { return op1->HasReducedOps(c) && o
|
|||
|
||||
ExprPtr InExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||
if ( op2->Tag() == EXPR_SET_CONSTRUCTOR && op2->GetOp1()->AsListExpr()->HasConstantOps() )
|
||||
op2 = make_intrusive<ConstExpr>(op2->Eval(nullptr));
|
||||
op2 = with_location_of(make_intrusive<ConstExpr>(op2->Eval(nullptr)), this);
|
||||
|
||||
return BinaryExpr::Reduce(c, red_stmt);
|
||||
}
|
||||
|
@ -2290,9 +2289,9 @@ ExprPtr CastExpr::Duplicate() { return SetSucc(new CastExpr(op->Duplicate(), typ
|
|||
|
||||
ExprPtr IsExpr::Duplicate() { return SetSucc(new IsExpr(op->Duplicate(), t)); }
|
||||
|
||||
InlineExpr::InlineExpr(ListExprPtr arg_args, std::vector<IDPtr> arg_params, std ::vector<bool> arg_param_is_modified,
|
||||
StmtPtr arg_body, int _frame_offset, TypePtr ret_type)
|
||||
: Expr(EXPR_INLINE), args(std::move(arg_args)), body(std::move(arg_body)) {
|
||||
InlineExpr::InlineExpr(ScriptFuncPtr arg_sf, ListExprPtr arg_args, std::vector<IDPtr> arg_params,
|
||||
std ::vector<bool> arg_param_is_modified, StmtPtr arg_body, int _frame_offset, TypePtr ret_type)
|
||||
: Expr(EXPR_INLINE), sf(std::move(arg_sf)), args(std::move(arg_args)), body(std::move(arg_body)) {
|
||||
params = std::move(arg_params);
|
||||
param_is_modified = std::move(arg_param_is_modified);
|
||||
frame_offset = _frame_offset;
|
||||
|
@ -2335,7 +2334,7 @@ ValPtr InlineExpr::Eval(Frame* f) const {
|
|||
ExprPtr InlineExpr::Duplicate() {
|
||||
auto args_d = args->Duplicate()->AsListExprPtr();
|
||||
auto body_d = body->Duplicate();
|
||||
return SetSucc(new InlineExpr(args_d, params, param_is_modified, body_d, frame_offset, type));
|
||||
return SetSucc(new InlineExpr(sf, args_d, params, param_is_modified, body_d, frame_offset, type));
|
||||
}
|
||||
|
||||
bool InlineExpr::IsReduced(Reducer* c) const { return NonReduced(this); }
|
||||
|
@ -2349,18 +2348,20 @@ ExprPtr InlineExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
|
||||
auto args_list = args->Exprs();
|
||||
auto ret_val = c->PushInlineBlock(type);
|
||||
if ( ret_val )
|
||||
ret_val->SetLocationInfo(GetLocationInfo());
|
||||
|
||||
loop_over_list(args_list, i) {
|
||||
StmtPtr arg_red_stmt;
|
||||
auto red_i = args_list[i]->Reduce(c, arg_red_stmt);
|
||||
auto assign_stmt = c->GenParam(params[i], red_i, param_is_modified[i]);
|
||||
auto assign_stmt = with_location_of(c->GenParam(params[i], red_i, param_is_modified[i]), this);
|
||||
red_stmt = MergeStmts(red_stmt, arg_red_stmt, assign_stmt);
|
||||
}
|
||||
|
||||
body = body->Reduce(c);
|
||||
c->PopInlineBlock();
|
||||
|
||||
auto catch_ret = make_intrusive<CatchReturnStmt>(body, ret_val);
|
||||
auto catch_ret = with_location_of(make_intrusive<CatchReturnStmt>(sf, body, ret_val), this);
|
||||
|
||||
red_stmt = MergeStmts(red_stmt, catch_ret);
|
||||
|
||||
|
@ -2448,7 +2449,7 @@ ExprPtr AppendToExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
}
|
||||
|
||||
ExprPtr AppendToExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
||||
auto at_stmt = make_intrusive<ExprStmt>(Duplicate());
|
||||
auto at_stmt = with_location_of(make_intrusive<ExprStmt>(Duplicate()), this);
|
||||
red_stmt = at_stmt->Reduce(c);
|
||||
return op1->AsRefExprPtr()->GetOp1();
|
||||
}
|
||||
|
@ -2496,10 +2497,10 @@ ExprPtr IndexAssignExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
|||
StmtPtr op1_red_stmt;
|
||||
op1 = op1->Reduce(c, op1_red_stmt);
|
||||
|
||||
auto assign_stmt = make_intrusive<ExprStmt>(Duplicate());
|
||||
auto assign_stmt = with_location_of(make_intrusive<ExprStmt>(Duplicate()), this);
|
||||
|
||||
auto index = op2->AsListExprPtr();
|
||||
auto res = make_intrusive<IndexExpr>(GetOp1(), index, false);
|
||||
auto res = with_location_of(make_intrusive<IndexExpr>(GetOp1(), index, false), this);
|
||||
auto final_res = res->ReduceToSingleton(c, red_stmt);
|
||||
|
||||
red_stmt = MergeStmts(op1_red_stmt, assign_stmt, red_stmt);
|
||||
|
@ -2597,9 +2598,9 @@ ExprPtr FieldLHSAssignExpr::ReduceToSingleton(Reducer* c, StmtPtr& red_stmt) {
|
|||
StmtPtr op1_red_stmt;
|
||||
op1 = op1->Reduce(c, op1_red_stmt);
|
||||
|
||||
auto assign_stmt = make_intrusive<ExprStmt>(Duplicate());
|
||||
auto assign_stmt = with_location_of(make_intrusive<ExprStmt>(Duplicate()), this);
|
||||
|
||||
auto field_res = make_intrusive<FieldExpr>(op1, field_name);
|
||||
auto field_res = with_location_of(make_intrusive<FieldExpr>(op1, field_name), this);
|
||||
StmtPtr field_res_stmt;
|
||||
auto res = field_res->ReduceToSingleton(c, field_res_stmt);
|
||||
|
||||
|
|
|
@ -217,7 +217,9 @@ void Inliner::CoalesceEventHandlers() {
|
|||
|
||||
void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::Body>& bodies,
|
||||
const BodyInfo& body_to_info) {
|
||||
auto merged_body = make_intrusive<StmtList>();
|
||||
// We pattern the new (alternate) body off of the first body.
|
||||
auto& b0 = func->GetBodies()[0].stmts;
|
||||
auto merged_body = with_location_of(make_intrusive<StmtList>(), b0);
|
||||
auto oi = merged_body->GetOptInfo();
|
||||
|
||||
auto& params = func->GetType()->Params();
|
||||
|
@ -226,8 +228,6 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
|
|||
|
||||
PreInline(oi, init_frame_size);
|
||||
|
||||
// We pattern the new (alternate) body off of the first body.
|
||||
auto& b0 = func->GetBodies()[0].stmts;
|
||||
auto b0_info = body_to_info.find(b0.get());
|
||||
ASSERT(b0_info != body_to_info.end());
|
||||
auto& info0 = funcs[b0_info->second];
|
||||
|
@ -254,9 +254,9 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
|
|||
auto new_scope = pop_scope();
|
||||
|
||||
// Build up the calling arguments.
|
||||
auto args = make_intrusive<ListExpr>();
|
||||
auto args = with_location_of(make_intrusive<ListExpr>(), b0);
|
||||
for ( auto& p : param_ids )
|
||||
args->Append(make_intrusive<NameExpr>(p));
|
||||
args->Append(with_location_of(make_intrusive<NameExpr>(p), b0));
|
||||
|
||||
for ( auto& b : bodies ) {
|
||||
auto bp = b.stmts;
|
||||
|
@ -272,7 +272,8 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
|
|||
// changes other than the function's scope.
|
||||
return;
|
||||
|
||||
merged_body->Stmts().push_back(make_intrusive<ExprStmt>(ie));
|
||||
auto ie_s = with_location_of(make_intrusive<ExprStmt>(ie), bp);
|
||||
merged_body->Stmts().push_back(std::move(ie_s));
|
||||
}
|
||||
|
||||
auto inlined_func = make_intrusive<CoalescedScriptFunc>(merged_body, new_scope, func);
|
||||
|
@ -370,7 +371,7 @@ ExprPtr Inliner::CheckForInlining(CallExprPtr c) {
|
|||
auto ie = DoInline(func_vf, body, c->ArgsPtr(), scope, ia->second);
|
||||
|
||||
if ( ie ) {
|
||||
ie->SetOriginal(c);
|
||||
ie->SetLocationInfo(c->GetLocationInfo());
|
||||
did_inline.insert(func_vf.get());
|
||||
}
|
||||
|
||||
|
@ -438,7 +439,9 @@ ExprPtr Inliner::DoInline(ScriptFuncPtr sf, StmtPtr body, ListExprPtr args, Scop
|
|||
auto t = scope->GetReturnType();
|
||||
|
||||
ASSERT(params.size() == args->Exprs().size());
|
||||
return make_intrusive<InlineExpr>(args, params, param_is_modified, body_dup, curr_frame_size, t);
|
||||
return with_location_of(make_intrusive<InlineExpr>(sf, args, params, param_is_modified, body_dup, curr_frame_size,
|
||||
t),
|
||||
body);
|
||||
}
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
|
|
@ -38,13 +38,7 @@ StmtPtr Reducer::Reduce(StmtPtr s) {
|
|||
}
|
||||
|
||||
ExprPtr Reducer::GenTemporaryExpr(const TypePtr& t, ExprPtr rhs) {
|
||||
auto e = make_intrusive<NameExpr>(GenTemporary(t, rhs));
|
||||
e->SetLocationInfo(rhs->GetLocationInfo());
|
||||
|
||||
// No need to associate with current statement, since these
|
||||
// are not generated during optimization.
|
||||
|
||||
return e;
|
||||
return with_location_of(make_intrusive<NameExpr>(GenTemporary(t, rhs)), rhs);
|
||||
}
|
||||
|
||||
NameExprPtr Reducer::UpdateName(NameExprPtr n) {
|
||||
|
@ -117,6 +111,7 @@ bool Reducer::ID_IsReduced(const ID* id) const {
|
|||
|
||||
StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
|
||||
auto param = GenInlineBlockName(id);
|
||||
param->SetLocationInfo(rhs->GetLocationInfo());
|
||||
auto rhs_id = rhs->Tag() == EXPR_NAME ? rhs->AsNameExpr()->IdPtr() : nullptr;
|
||||
|
||||
if ( rhs_id && pf->Locals().count(rhs_id.get()) == 0 && ! rhs_id->IsConst() )
|
||||
|
@ -145,9 +140,10 @@ StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
|
|||
|
||||
param_temps.insert(param_id.get());
|
||||
param = make_intrusive<NameExpr>(param_id);
|
||||
param->SetLocationInfo(rhs->GetLocationInfo());
|
||||
}
|
||||
|
||||
auto assign = make_intrusive<AssignExpr>(param, rhs, false, nullptr, nullptr, false);
|
||||
auto assign = with_location_of(make_intrusive<AssignExpr>(param, rhs, false, nullptr, nullptr, false), rhs);
|
||||
return make_intrusive<ExprStmt>(assign);
|
||||
}
|
||||
|
||||
|
@ -209,9 +205,15 @@ ExprPtr Reducer::NewVarUsage(IDPtr var, const Expr* orig) {
|
|||
return var_usage;
|
||||
}
|
||||
|
||||
void Reducer::BindExprToCurrStmt(const ExprPtr& e) { e->GetOptInfo()->stmt_num = curr_stmt->GetOptInfo()->stmt_num; }
|
||||
void Reducer::BindExprToCurrStmt(const ExprPtr& e) {
|
||||
e->GetOptInfo()->stmt_num = curr_stmt->GetOptInfo()->stmt_num;
|
||||
e->SetLocationInfo(curr_stmt->GetLocationInfo());
|
||||
}
|
||||
|
||||
void Reducer::BindStmtToCurrStmt(const StmtPtr& s) { s->GetOptInfo()->stmt_num = curr_stmt->GetOptInfo()->stmt_num; }
|
||||
void Reducer::BindStmtToCurrStmt(const StmtPtr& s) {
|
||||
s->GetOptInfo()->stmt_num = curr_stmt->GetOptInfo()->stmt_num;
|
||||
s->SetLocationInfo(curr_stmt->GetLocationInfo());
|
||||
}
|
||||
|
||||
bool Reducer::SameOp(const Expr* op1, const Expr* op2) {
|
||||
if ( op1 == op2 )
|
||||
|
@ -597,6 +599,7 @@ ConstExprPtr Reducer::Fold(ExprPtr e) {
|
|||
}
|
||||
|
||||
void Reducer::FoldedTo(ExprPtr e, ConstExprPtr c) {
|
||||
c->SetLocationInfo(e->GetLocationInfo());
|
||||
om.AddObj(e.get());
|
||||
constant_exprs[e.get()] = std::move(c);
|
||||
folded_exprs.push_back(std::move(e));
|
||||
|
@ -638,14 +641,14 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
|
|||
// about it being assigned but not used (though
|
||||
// we can still omit the assignment).
|
||||
constant_vars.insert(id);
|
||||
return make_intrusive<ConstExpr>(is_const->ValuePtr());
|
||||
return with_location_of(make_intrusive<ConstExpr>(is_const->ValuePtr()), e);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
if ( tmp_var->Const() )
|
||||
return make_intrusive<ConstExpr>(tmp_var->Const()->ValuePtr());
|
||||
return with_location_of(make_intrusive<ConstExpr>(tmp_var->Const()->ValuePtr()), e);
|
||||
|
||||
auto alias = tmp_var->Alias();
|
||||
if ( alias ) {
|
||||
|
@ -667,7 +670,7 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
|
|||
return e;
|
||||
|
||||
auto c = rhs->AsConstExpr();
|
||||
return make_intrusive<ConstExpr>(c->ValuePtr());
|
||||
return with_location_of(make_intrusive<ConstExpr>(c->ValuePtr()), e);
|
||||
}
|
||||
|
||||
StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& succ_stmt) {
|
||||
|
@ -720,7 +723,7 @@ StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& suc
|
|||
|
||||
// Got it. Mark the original temporary as no longer relevant.
|
||||
lhs_tmp->Deactivate();
|
||||
auto merge_e = make_intrusive<AssignExpr>(a_lhs_deref, rhs, false, nullptr, nullptr, false);
|
||||
auto merge_e = with_location_of(make_intrusive<AssignExpr>(a_lhs_deref, rhs, false, nullptr, nullptr, false), lhs);
|
||||
auto merge_e_stmt = make_intrusive<ExprStmt>(merge_e);
|
||||
|
||||
// Update the associated stmt_num's. For strict correctness, we
|
||||
|
|
|
@ -23,11 +23,8 @@ StmtPtr Stmt::Reduce(Reducer* c) {
|
|||
if ( repl )
|
||||
return repl;
|
||||
|
||||
if ( c->ShouldOmitStmt(this) ) {
|
||||
auto null = make_intrusive<NullStmt>();
|
||||
null->SetOriginal(this_ptr);
|
||||
return null;
|
||||
}
|
||||
if ( c->ShouldOmitStmt(this) )
|
||||
return with_location_of(make_intrusive<NullStmt>(), this);
|
||||
|
||||
c->SetCurrStmt(this);
|
||||
|
||||
|
@ -39,7 +36,7 @@ StmtPtr Stmt::TransformMe(StmtPtr new_me, Reducer* c) {
|
|||
|
||||
// Set the original prior to reduction, to support "original chains"
|
||||
// to ultimately resolve back to the source statement.
|
||||
new_me->SetOriginal(ThisPtr());
|
||||
new_me->SetLocationInfo(GetLocationInfo());
|
||||
return new_me->Reduce(c);
|
||||
}
|
||||
|
||||
|
@ -62,8 +59,8 @@ StmtPtr ExprListStmt::DoReduce(Reducer* c) {
|
|||
if ( ! c->Optimizing() && IsReduced(c) )
|
||||
return ThisPtr();
|
||||
|
||||
auto new_l = make_intrusive<ListExpr>();
|
||||
auto s = make_intrusive<StmtList>();
|
||||
auto new_l = with_location_of(make_intrusive<ListExpr>(), this);
|
||||
auto s = with_location_of(make_intrusive<StmtList>(), this);
|
||||
|
||||
ExprPList& e = l->Exprs();
|
||||
for ( auto& expr : e ) {
|
||||
|
@ -97,9 +94,7 @@ StmtPtr ExprListStmt::DoReduce(Reducer* c) {
|
|||
StmtPtr PrintStmt::Duplicate() { return SetSucc(new PrintStmt(l->Duplicate()->AsListExprPtr())); }
|
||||
|
||||
StmtPtr PrintStmt::DoSubclassReduce(ListExprPtr singletons, Reducer* c) {
|
||||
auto new_me = make_intrusive<PrintStmt>(singletons);
|
||||
new_me->SetOriginal(ThisPtr());
|
||||
return new_me;
|
||||
return with_location_of(make_intrusive<PrintStmt>(singletons), this);
|
||||
}
|
||||
|
||||
StmtPtr ExprStmt::Duplicate() { return SetSucc(new ExprStmt(e ? e->Duplicate() : nullptr)); }
|
||||
|
@ -201,7 +196,7 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
|||
auto b = e->GetOp2();
|
||||
|
||||
auto s1_dup = s1 ? s1->Duplicate() : nullptr;
|
||||
s2 = make_intrusive<IfStmt>(b, s1_dup, s2);
|
||||
s2 = with_location_of(make_intrusive<IfStmt>(b, s1_dup, s2), s2);
|
||||
e = a;
|
||||
|
||||
auto res = DoReduce(c);
|
||||
|
@ -218,7 +213,7 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
|||
auto b = e->GetOp2();
|
||||
|
||||
auto s2_dup = s2 ? s2->Duplicate() : nullptr;
|
||||
s1 = make_intrusive<IfStmt>(b, s1, s2_dup);
|
||||
s1 = with_location_of(make_intrusive<IfStmt>(b, s1, s2_dup), s1);
|
||||
e = a;
|
||||
|
||||
auto res = DoReduce(c);
|
||||
|
@ -239,11 +234,13 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
|||
e = e->ReduceToConditional(c, cond_red_stmt);
|
||||
|
||||
if ( red_e_stmt && cond_red_stmt )
|
||||
red_e_stmt = make_intrusive<StmtList>(red_e_stmt, cond_red_stmt);
|
||||
red_e_stmt = with_location_of(make_intrusive<StmtList>(red_e_stmt, cond_red_stmt), this);
|
||||
else if ( cond_red_stmt )
|
||||
red_e_stmt = cond_red_stmt;
|
||||
}
|
||||
|
||||
StmtPtr sl;
|
||||
|
||||
if ( e->IsConst() ) {
|
||||
auto c_e = e->AsConstExprPtr();
|
||||
auto t = c_e->Value()->AsBool();
|
||||
|
@ -251,14 +248,14 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
|||
if ( c->Optimizing() )
|
||||
return t ? s1 : s2;
|
||||
|
||||
if ( t )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, s1), c);
|
||||
else
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, s2), c);
|
||||
sl = make_intrusive<StmtList>(red_e_stmt, t ? s1 : s2);
|
||||
}
|
||||
|
||||
if ( red_e_stmt )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, ThisPtr()), c);
|
||||
else if ( red_e_stmt )
|
||||
sl = make_intrusive<StmtList>(red_e_stmt, ThisPtr());
|
||||
|
||||
if ( sl )
|
||||
return TransformMe(sl, c);
|
||||
|
||||
return ThisPtr();
|
||||
}
|
||||
|
@ -339,9 +336,9 @@ bool SwitchStmt::IsReduced(Reducer* r) const {
|
|||
StmtPtr SwitchStmt::DoReduce(Reducer* rc) {
|
||||
if ( cases->length() == 0 )
|
||||
// Degenerate.
|
||||
return make_intrusive<NullStmt>();
|
||||
return TransformMe(make_intrusive<NullStmt>(), rc);
|
||||
|
||||
auto s = make_intrusive<StmtList>();
|
||||
auto s = with_location_of(make_intrusive<StmtList>(), this);
|
||||
StmtPtr red_e_stmt;
|
||||
|
||||
if ( rc->Optimizing() )
|
||||
|
@ -381,11 +378,8 @@ StmtPtr SwitchStmt::DoReduce(Reducer* rc) {
|
|||
c->UpdateBody(c->Body()->Reduce(rc));
|
||||
}
|
||||
|
||||
if ( ! s->Stmts().empty() ) {
|
||||
StmtPtr me = ThisPtr();
|
||||
auto pre_and_me = make_intrusive<StmtList>(s, me);
|
||||
return TransformMe(pre_and_me, rc);
|
||||
}
|
||||
if ( ! s->Stmts().empty() )
|
||||
return TransformMe(make_intrusive<StmtList>(s, ThisPtr()), rc);
|
||||
|
||||
return ThisPtr();
|
||||
}
|
||||
|
@ -429,10 +423,8 @@ StmtPtr AddDelStmt::DoReduce(Reducer* c) {
|
|||
|
||||
auto red_e_stmt = e->ReduceToSingletons(c);
|
||||
|
||||
if ( red_e_stmt ) {
|
||||
auto s = make_intrusive<StmtList>(red_e_stmt, ThisPtr());
|
||||
return TransformMe(s, c);
|
||||
}
|
||||
if ( red_e_stmt )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, ThisPtr()), c);
|
||||
|
||||
else
|
||||
return ThisPtr();
|
||||
|
@ -457,10 +449,8 @@ StmtPtr EventStmt::DoReduce(Reducer* c) {
|
|||
event_expr = ee_red->AsEventExprPtr();
|
||||
e = event_expr;
|
||||
|
||||
if ( red_e_stmt ) {
|
||||
auto s = make_intrusive<StmtList>(red_e_stmt, ThisPtr());
|
||||
return TransformMe(s, c);
|
||||
}
|
||||
if ( red_e_stmt )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, ThisPtr()), c);
|
||||
}
|
||||
|
||||
return ThisPtr();
|
||||
|
@ -490,7 +480,7 @@ StmtPtr WhileStmt::DoReduce(Reducer* c) {
|
|||
if ( ! c->IsPruning() ) {
|
||||
// See comment below for the particulars
|
||||
// of this constructor.
|
||||
stmt_loop_condition = make_intrusive<ExprStmt>(STMT_EXPR, loop_condition);
|
||||
stmt_loop_condition = with_location_of(make_intrusive<ExprStmt>(STMT_EXPR, loop_condition), this);
|
||||
return ThisPtr();
|
||||
}
|
||||
}
|
||||
|
@ -503,7 +493,7 @@ StmtPtr WhileStmt::DoReduce(Reducer* c) {
|
|||
// We use the more involved ExprStmt constructor here to bypass
|
||||
// its check for whether the expression is being ignored, since
|
||||
// we're not actually creating an ExprStmt for execution.
|
||||
stmt_loop_condition = make_intrusive<ExprStmt>(STMT_EXPR, loop_condition);
|
||||
stmt_loop_condition = with_location_of(make_intrusive<ExprStmt>(STMT_EXPR, loop_condition), this);
|
||||
|
||||
if ( loop_cond_pred_stmt )
|
||||
loop_cond_pred_stmt = loop_cond_pred_stmt->Reduce(c);
|
||||
|
@ -606,10 +596,8 @@ StmtPtr ReturnStmt::DoReduce(Reducer* c) {
|
|||
StmtPtr red_e_stmt;
|
||||
e = e->ReduceToSingleton(c, red_e_stmt);
|
||||
|
||||
if ( red_e_stmt ) {
|
||||
auto s = make_intrusive<StmtList>(red_e_stmt, ThisPtr());
|
||||
return TransformMe(s, c);
|
||||
}
|
||||
if ( red_e_stmt )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, ThisPtr()), c);
|
||||
}
|
||||
|
||||
return ThisPtr();
|
||||
|
@ -829,7 +817,7 @@ StmtPtr AssertStmt::Duplicate() { return SetSucc(new AssertStmt(cond->Duplicate(
|
|||
|
||||
bool AssertStmt::IsReduced(Reducer* c) const { return false; }
|
||||
|
||||
StmtPtr AssertStmt::DoReduce(Reducer* c) { return make_intrusive<NullStmt>(); }
|
||||
StmtPtr AssertStmt::DoReduce(Reducer* c) { return TransformMe(make_intrusive<NullStmt>(), c); }
|
||||
|
||||
bool WhenInfo::HasUnreducedIDs(Reducer* c) const {
|
||||
for ( auto& cp : *cl ) {
|
||||
|
@ -891,18 +879,17 @@ StmtPtr WhenStmt::DoReduce(Reducer* c) {
|
|||
auto new_e = e->ReduceToSingleton(c, red_e_stmt);
|
||||
wi->SetTimeoutExpr(new_e);
|
||||
|
||||
if ( red_e_stmt ) {
|
||||
auto s = make_intrusive<StmtList>(red_e_stmt, ThisPtr());
|
||||
return TransformMe(std::move(s), c);
|
||||
}
|
||||
if ( red_e_stmt )
|
||||
return TransformMe(make_intrusive<StmtList>(red_e_stmt, ThisPtr()), c);
|
||||
}
|
||||
|
||||
return ThisPtr();
|
||||
}
|
||||
|
||||
CatchReturnStmt::CatchReturnStmt(StmtPtr _block, NameExprPtr _ret_var) : Stmt(STMT_CATCH_RETURN) {
|
||||
block = _block;
|
||||
ret_var = _ret_var;
|
||||
CatchReturnStmt::CatchReturnStmt(ScriptFuncPtr _sf, StmtPtr _block, NameExprPtr _ret_var) : Stmt(STMT_CATCH_RETURN) {
|
||||
sf = std::move(_sf);
|
||||
block = std::move(_block);
|
||||
ret_var = std::move(_ret_var);
|
||||
}
|
||||
|
||||
ValPtr CatchReturnStmt::Exec(Frame* f, StmtFlowType& flow) {
|
||||
|
@ -929,7 +916,7 @@ bool CatchReturnStmt::IsPure() const {
|
|||
StmtPtr CatchReturnStmt::Duplicate() {
|
||||
auto rv_dup = ret_var->Duplicate();
|
||||
auto rv_dup_ptr = rv_dup->AsNameExprPtr();
|
||||
return SetSucc(new CatchReturnStmt(block->Duplicate(), rv_dup_ptr));
|
||||
return SetSucc(new CatchReturnStmt(sf, block->Duplicate(), rv_dup_ptr));
|
||||
}
|
||||
|
||||
StmtPtr CatchReturnStmt::DoReduce(Reducer* c) {
|
||||
|
@ -945,14 +932,14 @@ StmtPtr CatchReturnStmt::DoReduce(Reducer* c) {
|
|||
if ( ret_var )
|
||||
reporter->InternalError("inlining inconsistency: no return value");
|
||||
|
||||
return make_intrusive<NullStmt>();
|
||||
return TransformMe(make_intrusive<NullStmt>(), c);
|
||||
}
|
||||
|
||||
auto rv_dup = ret_var->Duplicate();
|
||||
auto ret_e_dup = ret_e->Duplicate();
|
||||
|
||||
auto assign = make_intrusive<AssignExpr>(rv_dup, ret_e_dup, false);
|
||||
assign_stmt = make_intrusive<ExprStmt>(assign);
|
||||
auto assign = with_location_of(make_intrusive<AssignExpr>(rv_dup, ret_e_dup, false), this);
|
||||
assign_stmt = with_location_of(make_intrusive<ExprStmt>(assign), this);
|
||||
|
||||
if ( ret_e_dup->Tag() == EXPR_CONST ) {
|
||||
auto ce = ret_e_dup->AsConstExpr();
|
||||
|
|
|
@ -87,7 +87,7 @@ bool UseDefs::RemoveUnused(int iter) {
|
|||
// with one that only includes the actually
|
||||
// used identifiers.
|
||||
|
||||
auto new_init = make_intrusive<InitStmt>(used_ids);
|
||||
auto new_init = with_location_of(make_intrusive<InitStmt>(used_ids), s);
|
||||
rc->AddStmtToReplace(s, std::move(new_init));
|
||||
}
|
||||
|
||||
|
|
|
@ -870,21 +870,30 @@ const ZAMStmt ZAMCompiler::AssignTableElem(const Expr* e) {
|
|||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::Call(const ExprStmt* e) {
|
||||
if ( IsZAM_BuiltIn(e->StmtExpr()) )
|
||||
return LastInst();
|
||||
auto c = cast_intrusive<CallExpr>(e->StmtExprPtr());
|
||||
|
||||
if ( IsZAM_BuiltIn(c.get()) ) {
|
||||
auto ret = LastInst();
|
||||
insts1.back()->call_expr = c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DoCall(e->StmtExpr()->AsCallExpr(), nullptr);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::AssignToCall(const ExprStmt* e) {
|
||||
if ( IsZAM_BuiltIn(e->StmtExpr()) )
|
||||
return LastInst();
|
||||
|
||||
auto assign = e->StmtExpr()->AsAssignExpr();
|
||||
auto n = assign->GetOp1()->AsRefExpr()->GetOp1()->AsNameExpr();
|
||||
auto call = assign->GetOp2()->AsCallExpr();
|
||||
auto call = cast_intrusive<CallExpr>(assign->GetOp2());
|
||||
|
||||
return DoCall(call, n);
|
||||
if ( IsZAM_BuiltIn(e->StmtExpr()) ) {
|
||||
auto ret = LastInst();
|
||||
insts1.back()->call_expr = call;
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto n = assign->GetOp1()->AsRefExpr()->GetOp1()->AsNameExpr();
|
||||
|
||||
return DoCall(call.get(), n);
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n) {
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace zeek::detail {
|
|||
|
||||
const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) {
|
||||
curr_stmt = const_cast<Stmt*>(s)->ThisPtr();
|
||||
ASSERT(curr_stmt->Tag() == STMT_NULL || curr_stmt->GetLocationInfo()->first_line != 0);
|
||||
|
||||
switch ( s->Tag() ) {
|
||||
case STMT_PRINT: return CompilePrint(static_cast<const PrintStmt*>(s));
|
||||
|
|
|
@ -195,7 +195,7 @@ void ZBody::SetInsts(vector<ZInstI*>& instsI) {
|
|||
auto& iI = *instsI[i];
|
||||
insts_copy[i] = iI;
|
||||
if ( iI.stmt ) {
|
||||
auto l = iI.stmt->Original()->GetLocationInfo();
|
||||
auto l = iI.stmt->GetLocationInfo();
|
||||
if ( l != &no_location )
|
||||
insts_copy[i].loc = std::make_shared<Location>(l->filename, l->first_line, l->last_line,
|
||||
l->first_column, l->last_column);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue