mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
make "switch" internals accessible to ZAM; tidying of same
This commit is contained in:
parent
c662f8fbe8
commit
c81a331944
2 changed files with 20 additions and 9 deletions
11
src/Stmt.cc
11
src/Stmt.cc
|
@ -710,7 +710,7 @@ void SwitchStmt::Init()
|
|||
t->Append(e->GetType());
|
||||
comp_hash = new CompositeHash(std::move(t));
|
||||
|
||||
case_label_value_map.SetDeleteFunc(int_del_func);
|
||||
case_label_hash_map.SetDeleteFunc(int_del_func);
|
||||
}
|
||||
|
||||
SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
|
||||
|
@ -855,12 +855,13 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
|
|||
type_name(e->GetType()->Tag()));
|
||||
}
|
||||
|
||||
int* label_idx = case_label_value_map.Lookup(hk.get());
|
||||
int* label_idx = case_label_hash_map.Lookup(hk.get());
|
||||
|
||||
if ( label_idx )
|
||||
return false;
|
||||
|
||||
case_label_value_map.Insert(hk.get(), new int(idx));
|
||||
case_label_value_map[v] = idx;
|
||||
case_label_hash_map.Insert(hk.get(), new int(idx));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -884,7 +885,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
|
|||
ID* label_id = nullptr;
|
||||
|
||||
// Find matching expression cases.
|
||||
if ( case_label_value_map.Length() )
|
||||
if ( case_label_hash_map.Length() )
|
||||
{
|
||||
auto hk = comp_hash->MakeHashKey(*v, true);
|
||||
|
||||
|
@ -897,7 +898,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
|
|||
return std::make_pair(-1, nullptr);
|
||||
}
|
||||
|
||||
if ( auto i = case_label_value_map.Lookup(hk.get()) )
|
||||
if ( auto i = case_label_hash_map.Lookup(hk.get()) )
|
||||
label_idx = *i;
|
||||
}
|
||||
|
||||
|
|
18
src/Stmt.h
18
src/Stmt.h
|
@ -183,15 +183,24 @@ public:
|
|||
bool NoFlowAfter(bool ignore_break) const override;
|
||||
|
||||
protected:
|
||||
friend class ZAMCompiler;
|
||||
|
||||
int DefaultCaseIndex() const { return default_case_idx; }
|
||||
const auto& ValueMap() const { return case_label_value_map; }
|
||||
const std::vector<std::pair<ID*, int>>* TypeMap() const
|
||||
{ return &case_label_type_list; }
|
||||
const CompositeHash* CompHash() const { return comp_hash; }
|
||||
|
||||
ValPtr DoExec(Frame* f, Val* v, StmtFlowType& flow) override;
|
||||
bool IsPure() const override;
|
||||
|
||||
// Initialize composite hash and case label map.
|
||||
void Init();
|
||||
|
||||
// Adds an entry in case_label_value_map for the given value to associate it
|
||||
// with the given index in the cases list. If the entry already exists,
|
||||
// returns false, else returns true.
|
||||
// Adds entries in case_label_value_map and case_label_hash_map
|
||||
// for the given value to associate it with the given index in
|
||||
// the cases list. If the entry already exists, returns false,
|
||||
// else returns true.
|
||||
bool AddCaseLabelValueMapping(const Val* v, int idx);
|
||||
|
||||
// Adds an entry in case_label_type_map for the given type (w/ ID) to
|
||||
|
@ -208,7 +217,8 @@ protected:
|
|||
case_list* cases;
|
||||
int default_case_idx;
|
||||
CompositeHash* comp_hash;
|
||||
PDict<int> case_label_value_map;
|
||||
std::unordered_map<const Val*, int> case_label_value_map;
|
||||
PDict<int> case_label_hash_map;
|
||||
std::vector<std::pair<ID*, int>> case_label_type_list;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue