diff --git a/src/Type.cc b/src/Type.cc index e9b0949d13..34ad207842 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -96,6 +96,7 @@ BroType::BroType(TypeTag t, bool arg_base_type) case TYPE_LIST: case TYPE_FUNC: case TYPE_FILE: + case TYPE_OPAQUE: case TYPE_VECTOR: case TYPE_TYPE: internal_tag = TYPE_INTERNAL_OTHER; @@ -1262,6 +1263,42 @@ bool FileType::DoUnserialize(UnserialInfo* info) return yield != 0; } +OpaqueType::OpaqueType(const string& name) +: BroType(TYPE_OPAQUE), name(name) + { + } + +void OpaqueType::Describe(ODesc* d) const + { + if ( d->IsReadable() ) + d->AddSP("opaque of"); + else + d->Add(int(Tag())); + + d->Add(name.c_str()); + } + +// TODO: Serialization semantics not yet defined. +// +// IMPLEMENT_SERIAL(OpaqueType, SER_OPAQUE_TYPE); +// +// bool OpaqueType::DoSerialize(SerialInfo* info) const +// { +// DO_SERIALIZE(SER_OPAQUE_TYPE, BroType); +// return SERIALIZE(name); +// } +// +// bool OpaqueType::DoUnserialize(UnserialInfo* info) +// { +// DO_UNSERIALIZE(BroType); +// +// char const* n; +// if ( ! UNSERIALIZE_STR(&n, 0) ); +// return false; +// name = n; +// return true; +// } + EnumType::EnumType(const string& arg_name) : BroType(TYPE_ENUM) { @@ -1716,6 +1753,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init) case TYPE_FILE: return same_type(t1->YieldType(), t2->YieldType(), is_init); + case TYPE_OPAQUE: + // FIXME: Should we downcast here and compare the opaque type names? + return 1; + case TYPE_TYPE: return same_type(t1, t2, is_init); @@ -1805,6 +1846,7 @@ int is_assignable(BroType* t) case TYPE_VECTOR: case TYPE_FILE: + case TYPE_OPAQUE: case TYPE_TABLE: case TYPE_TYPE: return 1; diff --git a/src/Type.h b/src/Type.h index 8e2bb099d8..21b4bc2023 100644 --- a/src/Type.h +++ b/src/Type.h @@ -29,6 +29,7 @@ typedef enum { TYPE_LIST, TYPE_FUNC, TYPE_FILE, + TYPE_OPAQUE, TYPE_VECTOR, TYPE_TYPE, TYPE_ERROR @@ -499,6 +500,24 @@ protected: BroType* yield; }; +class OpaqueType : public BroType { +public: + OpaqueType(const string& name); + virtual ~OpaqueType() { }; + + const string& Name() { return name; } + + void Describe(ODesc* d) const; + +protected: + OpaqueType() { } + + // TODO: Serialization semantics not yet defined. + //DECLARE_SERIAL(OpaqueType) + + const string name; +}; + class EnumType : public BroType { public: EnumType(const string& arg_name); diff --git a/src/parse.y b/src/parse.y index b4eee1a56c..c442ffbd72 100644 --- a/src/parse.y +++ b/src/parse.y @@ -11,7 +11,7 @@ %token TOK_DOUBLE TOK_ELSE TOK_ENUM TOK_EVENT TOK_EXPORT TOK_FILE TOK_FOR %token TOK_FUNCTION TOK_GLOBAL TOK_HOOK TOK_ID TOK_IF TOK_INT %token TOK_INTERVAL TOK_LIST TOK_LOCAL TOK_MODULE -%token TOK_NEXT TOK_OF TOK_PATTERN TOK_PATTERN_TEXT +%token TOK_NEXT TOK_OF TOK_OPAQUE TOK_PATTERN TOK_PATTERN_TEXT %token TOK_PORT TOK_PRINT TOK_RECORD TOK_REDEF %token TOK_REMOVE_FROM TOK_RETURN TOK_SCHEDULE TOK_SET %token TOK_STRING TOK_SUBNET TOK_SWITCH TOK_TABLE @@ -890,6 +890,12 @@ type: $$ = new FileType(base_type(TYPE_STRING)); } + | TOK_OPAQUE TOK_OF TOK_ID + { + set_location(@1, @3); + $$ = new OpaqueType($3); + } + | resolve_id { if ( ! $1 || ! ($$ = $1->AsType()) ) diff --git a/src/scan.l b/src/scan.l index 4e1a66144e..b231e11d74 100644 --- a/src/scan.l +++ b/src/scan.l @@ -298,6 +298,7 @@ local return TOK_LOCAL; module return TOK_MODULE; next return TOK_NEXT; of return TOK_OF; +opaque return TOK_OPAQUE; pattern return TOK_PATTERN; port return TOK_PORT; print return TOK_PRINT;