mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
type/id/zeekygen: Add EnumVal to enum identifiers
Provide a direct way to go from a zeek🆔:ID value to EnumVal without
needing to go through the type.
This commit is contained in:
parent
f0ccd5c7f8
commit
18597ea49c
2 changed files with 11 additions and 1 deletions
|
@ -481,6 +481,10 @@ void ID::DescribeReST(ODesc* d, bool roles_only) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( val && type && type->Tag() != TYPE_FUNC && type->InternalType() != TYPE_INTERNAL_VOID &&
|
if ( val && type && type->Tag() != TYPE_FUNC && type->InternalType() != TYPE_INTERNAL_VOID &&
|
||||||
|
// Do not include a default value for enum const identifiers,
|
||||||
|
// as their value can't be changed.
|
||||||
|
! IsEnumConst() &&
|
||||||
|
|
||||||
// Values within Version module are likely to include a
|
// Values within Version module are likely to include a
|
||||||
// constantly-changing version number and be a frequent
|
// constantly-changing version number and be a frequent
|
||||||
// source of error/desynchronization, so don't include them.
|
// source of error/desynchronization, so don't include them.
|
||||||
|
|
|
@ -1567,7 +1567,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek
|
||||||
if ( deprecation )
|
if ( deprecation )
|
||||||
id->MakeDeprecated({NewRef{}, deprecation});
|
id->MakeDeprecated({NewRef{}, deprecation});
|
||||||
|
|
||||||
detail::zeekygen_mgr->Identifier(std::move(id), from_redef);
|
detail::zeekygen_mgr->Identifier(id, from_redef);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We allow double-definitions if matching exactly. This is so that
|
// We allow double-definitions if matching exactly. This is so that
|
||||||
|
@ -1591,6 +1591,12 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek
|
||||||
if ( vals.find(val) == vals.end() )
|
if ( vals.find(val) == vals.end() )
|
||||||
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
|
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
|
||||||
|
|
||||||
|
if ( ! id->HasVal() )
|
||||||
|
id->SetVal(vals[val]);
|
||||||
|
else if ( id->GetVal()->AsEnum() != val )
|
||||||
|
reporter->InternalError("inconsistent enum integer value for '%s' (old %" PRId64 " new %" PRId64 ")",
|
||||||
|
fullname.c_str(), id->GetVal()->AsEnum(), val);
|
||||||
|
|
||||||
const auto& types = Type::Aliases(GetName());
|
const auto& types = Type::Aliases(GetName());
|
||||||
|
|
||||||
for ( const auto& t : types )
|
for ( const auto& t : types )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue