mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/enum-names-with-strings'
* origin/topic/awelzel/enum-names-with-strings: enum_names: Support naming types with a string
This commit is contained in:
commit
5aa7d80e88
6 changed files with 56 additions and 7 deletions
8
CHANGES
8
CHANGES
|
@ -1,3 +1,11 @@
|
||||||
|
5.2.0-dev.142 | 2022-10-25 12:37:16 +0200
|
||||||
|
|
||||||
|
* enum_names: Support naming types with a string (Arne Welzel, Corelight)
|
||||||
|
|
||||||
|
Add support to enum_names() to transparently lookup the type if a string
|
||||||
|
is provided. This is similar in how record_fields() behaves when being
|
||||||
|
passed a string.
|
||||||
|
|
||||||
5.2.0-dev.140 | 2022-10-25 12:34:39 +0200
|
5.2.0-dev.140 | 2022-10-25 12:34:39 +0200
|
||||||
|
|
||||||
* scripts: Migrate table iteration to blank identifiers (Arne Welzel, Corelight)
|
* scripts: Migrate table iteration to blank identifiers (Arne Welzel, Corelight)
|
||||||
|
|
3
NEWS
3
NEWS
|
@ -77,6 +77,9 @@ Changed Functionality
|
||||||
will be raised once only. Further, analyzer confirmations are not raised
|
will be raised once only. Further, analyzer confirmations are not raised
|
||||||
after a violation.
|
after a violation.
|
||||||
|
|
||||||
|
- The parameter given to ``enum_names()`` can now be a string naming the
|
||||||
|
enum type, rather than the type itself.
|
||||||
|
|
||||||
Deprecated Functionality
|
Deprecated Functionality
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
5.2.0-dev.140
|
5.2.0-dev.142
|
||||||
|
|
18
src/zeek.bif
18
src/zeek.bif
|
@ -1938,20 +1938,26 @@ function type_aliases%(x: any%): string_set
|
||||||
|
|
||||||
## Returns all value names associated with an enum type.
|
## Returns all value names associated with an enum type.
|
||||||
##
|
##
|
||||||
## et: An enum type.
|
## et: An enum type or a string naming one.
|
||||||
##
|
##
|
||||||
## Returns: All enum value names associated with enum type *et*.
|
## Returns: All enum value names associated with enum type *et*.
|
||||||
## If *et* is not an enum type, an empty set is returned.
|
## If *et* is not an enum type or does not name one, an empty set is returned.
|
||||||
function enum_names%(et: any%): string_set
|
function enum_names%(et: any%): string_set
|
||||||
%{
|
%{
|
||||||
auto rval = make_intrusive<zeek::TableVal>(zeek::id::string_set);
|
auto rval = make_intrusive<zeek::TableVal>(zeek::id::string_set);
|
||||||
|
|
||||||
if ( et->GetType()->Tag() != TYPE_TYPE )
|
zeek::TypePtr t = zeek::Type::nil;
|
||||||
return rval;
|
|
||||||
|
|
||||||
const auto& t = et->GetType()->AsTypeType()->GetType();
|
if ( et->GetType()->Tag() == TYPE_STRING )
|
||||||
|
{
|
||||||
|
const auto& id = zeek::detail::global_scope()->Find(et->AsStringVal()->ToStdString());
|
||||||
|
if ( id && id->IsType() )
|
||||||
|
t = id->GetType();
|
||||||
|
}
|
||||||
|
else if ( et->GetType()->Tag() == TYPE_TYPE )
|
||||||
|
t = et->GetType()->AsTypeType()->GetType();
|
||||||
|
|
||||||
if ( t->Tag() != TYPE_ENUM )
|
if ( ! t || t->Tag() != TYPE_ENUM )
|
||||||
return rval;
|
return rval;
|
||||||
|
|
||||||
auto enum_type = t->AsEnumType();
|
auto enum_type = t->AsEnumType();
|
||||||
|
|
|
@ -1,4 +1,20 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
with types
|
||||||
|
{
|
||||||
|
Monochrome::WHITE,
|
||||||
|
Monochrome::BLACK
|
||||||
|
}
|
||||||
|
{
|
||||||
|
RED,
|
||||||
|
GREEN,
|
||||||
|
PURPLE,
|
||||||
|
BLUE
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Monochrome::WHITE,
|
||||||
|
Monochrome::BLACK
|
||||||
|
}
|
||||||
|
with strings
|
||||||
{
|
{
|
||||||
RED,
|
RED,
|
||||||
GREEN,
|
GREEN,
|
||||||
|
@ -11,3 +27,7 @@ GREEN,
|
||||||
PURPLE,
|
PURPLE,
|
||||||
BLUE
|
BLUE
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
Monochrome::WHITE,
|
||||||
|
Monochrome::BLACK
|
||||||
|
}
|
||||||
|
|
|
@ -6,5 +6,17 @@ type ColorAlias: Color;
|
||||||
|
|
||||||
redef enum Color += { PURPLE };
|
redef enum Color += { PURPLE };
|
||||||
|
|
||||||
|
module Monochrome;
|
||||||
|
|
||||||
|
type Color: enum { WHITE, BLACK };
|
||||||
|
|
||||||
|
|
||||||
|
print "with types";
|
||||||
print enum_names(Color);
|
print enum_names(Color);
|
||||||
print enum_names(ColorAlias);
|
print enum_names(ColorAlias);
|
||||||
|
print enum_names(Monochrome::Color);
|
||||||
|
|
||||||
|
print "with strings";
|
||||||
|
print enum_names("Color");
|
||||||
|
print enum_names("ColorAlias");
|
||||||
|
print enum_names("Monochrome::Color");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue