mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
IndexType: Add IsPatternIndex(), like IsSubNetIndex()
This commit is contained in:
parent
074f51fc96
commit
c8bab6a0ec
5 changed files with 16 additions and 9 deletions
|
@ -2383,11 +2383,10 @@ IndexExpr::IndexExpr(ExprPtr arg_op1, ListExprPtr arg_op2, bool arg_is_slice, bo
|
|||
return;
|
||||
|
||||
if ( op1->GetType()->Tag() == TYPE_TABLE ) { // Check for a table[pattern] being indexed by a string
|
||||
auto table_type = op1->GetType()->AsTableType();
|
||||
auto& it = table_type->GetIndexTypes();
|
||||
auto& rhs_type = op2->GetType()->AsTypeList()->GetTypes();
|
||||
if ( it.size() == 1 && it[0]->Tag() == TYPE_PATTERN && table_type->Yield() && rhs_type.size() == 1 &&
|
||||
rhs_type[0]->Tag() == TYPE_STRING ) {
|
||||
const auto& table_type = op1->GetType()->AsTableType();
|
||||
const auto& rhs_type = op2->GetType()->AsTypeList()->GetTypes();
|
||||
if ( table_type->IsPatternIndex() && table_type->Yield() && rhs_type.size() == 1 &&
|
||||
IsString(rhs_type[0]->Tag()) ) {
|
||||
is_pattern_table = true;
|
||||
SetType(make_intrusive<VectorType>(op1->GetType()->Yield()));
|
||||
return;
|
||||
|
|
|
@ -389,6 +389,13 @@ bool IndexType::IsSubNetIndex() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IndexType::IsPatternIndex() const {
|
||||
const auto& types = indices->GetTypes();
|
||||
if ( types.size() == 1 && types[0]->Tag() == TYPE_PATTERN )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
detail::TraversalCode IndexType::Traverse(detail::TraversalCallback* cb) const {
|
||||
auto tc = cb->PreType(this);
|
||||
HANDLE_TC_TYPE_PRE(tc);
|
||||
|
|
|
@ -356,6 +356,9 @@ public:
|
|||
// Returns true if this table is solely indexed by subnet.
|
||||
bool IsSubNetIndex() const;
|
||||
|
||||
// Returns true if this table has a single index of type pattern.
|
||||
bool IsPatternIndex() const;
|
||||
|
||||
detail::TraversalCode Traverse(detail::TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1547,8 +1547,7 @@ void TableVal::Init(TableTypePtr t, bool ordered) {
|
|||
else
|
||||
subnets = nullptr;
|
||||
|
||||
auto& it = table_type->GetIndexTypes();
|
||||
if ( it.size() == 1 && it[0]->Tag() == TYPE_PATTERN && table_type->Yield() )
|
||||
if ( table_type->IsPatternIndex() && table_type->Yield() )
|
||||
pattern_matcher = new TablePatternMatcher(this, table_type->Yield());
|
||||
|
||||
table_hash = new detail::CompositeHash(table_type->GetIndices());
|
||||
|
|
|
@ -391,8 +391,7 @@ string CPPCompile::GenIndexExpr(const Expr* e, GenType gt) {
|
|||
auto ind_expr = e->GetOp2()->AsListExpr()->Exprs()[0];
|
||||
auto is_pat_str_ind = false;
|
||||
|
||||
auto& indices = aggr_t->AsTableType()->GetIndices()->GetTypes();
|
||||
if ( indices.size() == 1 && indices[0]->Tag() == TYPE_PATTERN && ind_expr->GetType()->Tag() == TYPE_STRING )
|
||||
if ( aggr_t->AsTableType()->IsPatternIndex() && ind_expr->GetType()->Tag() == TYPE_STRING )
|
||||
is_pat_str_ind = true;
|
||||
|
||||
if ( inside_when ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue