Fix for EnumVal's returning their underlying value

Change EnumVal()->AsEnum() to zeek_int_t.
This commit is contained in:
Vern Paxson 2023-03-08 09:49:59 +01:00 committed by Arne Welzel
parent 802d24cad7
commit b7f7d32bf7
5 changed files with 14 additions and 10 deletions

View file

@ -155,7 +155,7 @@ public:
UNDERLYING_ACCESSOR_DECL(detail::IntValImplementation, zeek_int_t, AsInt) UNDERLYING_ACCESSOR_DECL(detail::IntValImplementation, zeek_int_t, AsInt)
UNDERLYING_ACCESSOR_DECL(BoolVal, bool, AsBool) UNDERLYING_ACCESSOR_DECL(BoolVal, bool, AsBool)
UNDERLYING_ACCESSOR_DECL(EnumVal, int, AsEnum) UNDERLYING_ACCESSOR_DECL(EnumVal, zeek_int_t, AsEnum)
UNDERLYING_ACCESSOR_DECL(detail::UnsignedValImplementation, zeek_uint_t, AsCount) UNDERLYING_ACCESSOR_DECL(detail::UnsignedValImplementation, zeek_uint_t, AsCount)
UNDERLYING_ACCESSOR_DECL(detail::DoubleValImplementation, double, AsDouble) UNDERLYING_ACCESSOR_DECL(detail::DoubleValImplementation, double, AsDouble)
UNDERLYING_ACCESSOR_DECL(TimeVal, double, AsTime) UNDERLYING_ACCESSOR_DECL(TimeVal, double, AsTime)
@ -1476,7 +1476,7 @@ protected:
friend class Val; friend class Val;
friend class EnumType; friend class EnumType;
friend EnumValPtr make_enum__CPP(TypePtr t, int i); friend EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i);
template <class T, class... Ts> friend IntrusivePtr<T> make_intrusive(Ts&&... args); template <class T, class... Ts> friend IntrusivePtr<T> make_intrusive(Ts&&... args);
@ -1700,7 +1700,7 @@ private:
UNDERLYING_ACCESSOR_DEF(detail::IntValImplementation, zeek_int_t, AsInt) UNDERLYING_ACCESSOR_DEF(detail::IntValImplementation, zeek_int_t, AsInt)
UNDERLYING_ACCESSOR_DEF(BoolVal, bool, AsBool) UNDERLYING_ACCESSOR_DEF(BoolVal, bool, AsBool)
UNDERLYING_ACCESSOR_DEF(EnumVal, int, AsEnum) UNDERLYING_ACCESSOR_DEF(EnumVal, zeek_int_t, AsEnum)
UNDERLYING_ACCESSOR_DEF(detail::UnsignedValImplementation, zeek_uint_t, AsCount) UNDERLYING_ACCESSOR_DEF(detail::UnsignedValImplementation, zeek_uint_t, AsCount)
UNDERLYING_ACCESSOR_DEF(detail::DoubleValImplementation, double, AsDouble) UNDERLYING_ACCESSOR_DEF(detail::DoubleValImplementation, double, AsDouble)
UNDERLYING_ACCESSOR_DEF(TimeVal, double, AsTime) UNDERLYING_ACCESSOR_DEF(TimeVal, double, AsTime)

View file

@ -729,7 +729,8 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer,
if ( ! stream_id ) if ( ! stream_id )
{ {
reporter->Error("Failed to remotely log: stream %d doesn't have name", stream->AsEnum()); reporter->Error("Failed to remotely log: stream %" PRId64 " doesn't have name",
stream->AsEnum());
return false; return false;
} }
@ -737,7 +738,8 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer,
if ( ! writer_id ) if ( ! writer_id )
{ {
reporter->Error("Failed to remotely log: writer %d doesn't have name", writer->AsEnum()); reporter->Error("Failed to remotely log: writer %" PRId64 " doesn't have name",
writer->AsEnum());
return false; return false;
} }
@ -784,7 +786,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int
if ( ! stream_id ) if ( ! stream_id )
{ {
reporter->Error("Failed to remotely log: stream %d doesn't have name", stream->AsEnum()); reporter->Error("Failed to remotely log: stream %" PRId64 " doesn't have name",
stream->AsEnum());
return false; return false;
} }
@ -792,7 +795,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int
if ( ! writer_id ) if ( ! writer_id )
{ {
reporter->Error("Failed to remotely log: writer %d doesn't have name", writer->AsEnum()); reporter->Error("Failed to remotely log: writer %" PRId64 " doesn't have name",
writer->AsEnum());
return false; return false;
} }

View file

@ -1336,7 +1336,7 @@ string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev)
if ( ! et->HasRedefs() ) if ( ! et->HasRedefs() )
// Can use direct access. // Can use direct access.
return Fmt(v); return std::to_string(v);
// Need to dynamically map the access. // Need to dynamically map the access.
int mapping_slot; int mapping_slot;

View file

@ -257,7 +257,7 @@ EnumTypePtr get_enum_type__CPP(const string& enum_type_name)
return make_intrusive<EnumType>(enum_type_name); return make_intrusive<EnumType>(enum_type_name);
} }
EnumValPtr make_enum__CPP(TypePtr t, int i) EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i)
{ {
auto et = cast_intrusive<EnumType>(move(t)); auto et = cast_intrusive<EnumType>(move(t));
return make_intrusive<EnumVal>(et, i); return make_intrusive<EnumVal>(et, i);

View file

@ -84,7 +84,7 @@ extern EnumTypePtr get_enum_type__CPP(const std::string& enum_type_name);
// Returns an enum value corresponding to the given low-level value 'i' // Returns an enum value corresponding to the given low-level value 'i'
// in the context of the given enum type 't'. // in the context of the given enum type 't'.
extern EnumValPtr make_enum__CPP(TypePtr t, int i); extern EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i);
} // namespace zeek::detail } // namespace zeek::detail
} // namespace zeek } // namespace zeek