mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Type: move code from BroType::BroType() to constexpr functions
Prepare to inline the constructor, which will one day be `constexpr` (requires moving the `std::string name` field somewhere else).
This commit is contained in:
parent
411d048d24
commit
5b8bd26c72
2 changed files with 61 additions and 61 deletions
63
src/Type.cc
63
src/Type.cc
|
@ -63,68 +63,9 @@ const char* type_name(TypeTag t)
|
||||||
BroType::BroType(TypeTag t, bool arg_base_type)
|
BroType::BroType(TypeTag t, bool arg_base_type)
|
||||||
{
|
{
|
||||||
tag = t;
|
tag = t;
|
||||||
is_network_order = 0;
|
is_network_order = ::is_network_order(t);
|
||||||
base_type = arg_base_type;
|
base_type = arg_base_type;
|
||||||
|
internal_tag = to_internal_type_tag(tag);
|
||||||
switch ( tag ) {
|
|
||||||
case TYPE_VOID:
|
|
||||||
internal_tag = TYPE_INTERNAL_VOID;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_BOOL:
|
|
||||||
case TYPE_INT:
|
|
||||||
case TYPE_ENUM:
|
|
||||||
internal_tag = TYPE_INTERNAL_INT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_COUNT:
|
|
||||||
case TYPE_COUNTER:
|
|
||||||
internal_tag = TYPE_INTERNAL_UNSIGNED;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_PORT:
|
|
||||||
internal_tag = TYPE_INTERNAL_UNSIGNED;
|
|
||||||
is_network_order = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_DOUBLE:
|
|
||||||
case TYPE_TIME:
|
|
||||||
case TYPE_INTERVAL:
|
|
||||||
internal_tag = TYPE_INTERNAL_DOUBLE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_STRING:
|
|
||||||
internal_tag = TYPE_INTERNAL_STRING;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_ADDR:
|
|
||||||
internal_tag = TYPE_INTERNAL_ADDR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_SUBNET:
|
|
||||||
internal_tag = TYPE_INTERNAL_SUBNET;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_PATTERN:
|
|
||||||
case TYPE_TIMER:
|
|
||||||
case TYPE_ANY:
|
|
||||||
case TYPE_TABLE:
|
|
||||||
case TYPE_UNION:
|
|
||||||
case TYPE_RECORD:
|
|
||||||
case TYPE_LIST:
|
|
||||||
case TYPE_FUNC:
|
|
||||||
case TYPE_FILE:
|
|
||||||
case TYPE_OPAQUE:
|
|
||||||
case TYPE_VECTOR:
|
|
||||||
case TYPE_TYPE:
|
|
||||||
internal_tag = TYPE_INTERNAL_OTHER;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPE_ERROR:
|
|
||||||
internal_tag = TYPE_INTERNAL_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BroType* BroType::ShallowClone()
|
BroType* BroType::ShallowClone()
|
||||||
|
|
59
src/Type.h
59
src/Type.h
|
@ -44,6 +44,11 @@ typedef enum {
|
||||||
#define NUM_TYPES (int(TYPE_ERROR) + 1)
|
#define NUM_TYPES (int(TYPE_ERROR) + 1)
|
||||||
} TypeTag;
|
} TypeTag;
|
||||||
|
|
||||||
|
constexpr bool is_network_order(TypeTag tag) noexcept
|
||||||
|
{
|
||||||
|
return tag == TYPE_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FUNC_FLAVOR_FUNCTION,
|
FUNC_FLAVOR_FUNCTION,
|
||||||
FUNC_FLAVOR_EVENT,
|
FUNC_FLAVOR_EVENT,
|
||||||
|
@ -57,6 +62,60 @@ typedef enum {
|
||||||
TYPE_INTERNAL_OTHER, TYPE_INTERNAL_ERROR
|
TYPE_INTERNAL_OTHER, TYPE_INTERNAL_ERROR
|
||||||
} InternalTypeTag;
|
} InternalTypeTag;
|
||||||
|
|
||||||
|
constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept
|
||||||
|
{
|
||||||
|
switch ( tag ) {
|
||||||
|
case TYPE_VOID:
|
||||||
|
return TYPE_INTERNAL_VOID;
|
||||||
|
|
||||||
|
case TYPE_BOOL:
|
||||||
|
case TYPE_INT:
|
||||||
|
case TYPE_ENUM:
|
||||||
|
return TYPE_INTERNAL_INT;
|
||||||
|
|
||||||
|
case TYPE_COUNT:
|
||||||
|
case TYPE_COUNTER:
|
||||||
|
return TYPE_INTERNAL_UNSIGNED;
|
||||||
|
|
||||||
|
case TYPE_PORT:
|
||||||
|
return TYPE_INTERNAL_UNSIGNED;
|
||||||
|
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
case TYPE_TIME:
|
||||||
|
case TYPE_INTERVAL:
|
||||||
|
return TYPE_INTERNAL_DOUBLE;
|
||||||
|
|
||||||
|
case TYPE_STRING:
|
||||||
|
return TYPE_INTERNAL_STRING;
|
||||||
|
|
||||||
|
case TYPE_ADDR:
|
||||||
|
return TYPE_INTERNAL_ADDR;
|
||||||
|
|
||||||
|
case TYPE_SUBNET:
|
||||||
|
return TYPE_INTERNAL_SUBNET;
|
||||||
|
|
||||||
|
case TYPE_PATTERN:
|
||||||
|
case TYPE_TIMER:
|
||||||
|
case TYPE_ANY:
|
||||||
|
case TYPE_TABLE:
|
||||||
|
case TYPE_UNION:
|
||||||
|
case TYPE_RECORD:
|
||||||
|
case TYPE_LIST:
|
||||||
|
case TYPE_FUNC:
|
||||||
|
case TYPE_FILE:
|
||||||
|
case TYPE_OPAQUE:
|
||||||
|
case TYPE_VECTOR:
|
||||||
|
case TYPE_TYPE:
|
||||||
|
return TYPE_INTERNAL_OTHER;
|
||||||
|
|
||||||
|
case TYPE_ERROR:
|
||||||
|
return TYPE_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this should be unreachable */
|
||||||
|
return TYPE_INTERNAL_VOID;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the name of the type.
|
// Returns the name of the type.
|
||||||
extern const char* type_name(TypeTag t);
|
extern const char* type_name(TypeTag t);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue