mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
fixes for ZAM compilation of switch statements
This commit is contained in:
parent
51eec61272
commit
b9949560c6
3 changed files with 57 additions and 33 deletions
|
@ -320,13 +320,20 @@ IntrusivePtr<Case> Case::Duplicate()
|
|||
return make_intrusive<Case>(new_exprs, nullptr, s->Duplicate());
|
||||
}
|
||||
|
||||
IDPList* new_type_cases = nullptr;
|
||||
|
||||
if ( type_cases )
|
||||
{
|
||||
new_type_cases = new IDPList();
|
||||
|
||||
for ( auto tc : *type_cases )
|
||||
{
|
||||
zeek::Ref(tc);
|
||||
new_type_cases->append(tc);
|
||||
}
|
||||
}
|
||||
|
||||
return make_intrusive<Case>(nullptr, type_cases, s->Duplicate());
|
||||
return make_intrusive<Case>(nullptr, new_type_cases, s->Duplicate());
|
||||
}
|
||||
|
||||
StmtPtr SwitchStmt::Duplicate()
|
||||
|
@ -354,6 +361,9 @@ bool SwitchStmt::IsReduced(Reducer* r) const
|
|||
if ( ! e->IsReduced(r) )
|
||||
return NonReduced(e.get());
|
||||
|
||||
if ( cases->length() == 0 )
|
||||
return false;
|
||||
|
||||
for ( const auto& c : *cases )
|
||||
{
|
||||
if ( c->ExprCases() && ! c->ExprCases()->IsReduced(r) )
|
||||
|
@ -371,6 +381,10 @@ bool SwitchStmt::IsReduced(Reducer* r) const
|
|||
|
||||
StmtPtr SwitchStmt::DoReduce(Reducer* rc)
|
||||
{
|
||||
if ( cases->length() == 0 )
|
||||
// Degenerate.
|
||||
return make_intrusive<NullStmt>();
|
||||
|
||||
auto s = make_intrusive<StmtList>();
|
||||
StmtPtr red_e_stmt;
|
||||
|
||||
|
@ -388,7 +402,8 @@ StmtPtr SwitchStmt::DoReduce(Reducer* rc)
|
|||
for ( auto& i : case_label_type_list )
|
||||
{
|
||||
IDPtr idp = {NewRef{}, i.first};
|
||||
i.first = rc->UpdateID(idp).release();
|
||||
if ( idp->Name() )
|
||||
i.first = rc->UpdateID(idp).release();
|
||||
}
|
||||
|
||||
for ( const auto& c : *cases )
|
||||
|
@ -405,7 +420,11 @@ StmtPtr SwitchStmt::DoReduce(Reducer* rc)
|
|||
|
||||
auto c_t = c->TypeCases();
|
||||
if ( c_t )
|
||||
rc->UpdateIDs(c_t);
|
||||
{
|
||||
for ( auto& c_t_i : *c_t )
|
||||
if ( c_t_i->Name() )
|
||||
c_t_i = rc->UpdateID({NewRef{}, c_t_i}).release();
|
||||
}
|
||||
|
||||
c->UpdateBody(c->Body()->Reduce(rc));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue