diff -r 2b8512340180 -r bbb498ccb4ac src/Types.h --- a/src/Types.h Sat Dec 22 19:48:43 2012 -0800 +++ b/src/Types.h Sat Dec 22 23:18:57 2012 -0800 @@ -104,7 +104,6 @@ static Type *NewVoid(Zone *zone); static Type *NewUnchecked(Zone *zone); static Type *NewPrimitive(Zone *zone, PrimitiveType type); - static Type *NewEnum(Zone *zone, Handle name); static bool Compare(Type *left, Type *right); @@ -114,7 +113,8 @@ obj->is(MapKind_FunctionType) || obj->is(MapKind_StructType) || obj->is(MapKind_ArrayType) || - obj->is(MapKind_ReferenceType)); + obj->is(MapKind_ReferenceType) || + obj->is(MapKind_EnumType)); return (Type *)obj; } @@ -185,25 +185,35 @@ return kind() == ENUM; } - String *name() { - assert(isEnum() || isStruct()); - return name_; - } - - // GC Descriptor. - static inline size_t offsetOfName() { - return OFFSETOF(Type, name_); - } - // End GC Descriptor. - protected: Kind kind_; PrimitiveType primitive_; // Primitives, arrays, and references. bool const_; +}; - // Enums and structs only. +class EnumType : public Type +{ + public: + static EnumType *New(Zone *Zone, Handle name); + + String *name() { + return name_; + } + + // GC Descriptor. + static inline size_t offsetOfName() { + return OFFSETOF(EnumType, name_); + } + // End GC Descriptor. + + static EnumType *cast(Object *obj) { + assert(!obj || obj->is(MapKind_EnumType)); + return (EnumType *)obj; + } + + private: Barriered name_; }; @@ -325,6 +335,10 @@ newMap_ = map; } + String *name() { + return name_; + } + // GC Descriptor. static inline size_t offsetOfFields() { return OFFSETOF(StructType, fields_); @@ -332,6 +346,9 @@ static inline size_t offsetOfNewMap() { return OFFSETOF(StructType, newMap_); } + static inline size_t offsetOfName() { + return OFFSETOF(StructType, name_); + } // End GC Descriptor. static StructType *cast(Object *obj) { @@ -343,12 +360,13 @@ // Structs only. Barriered fields_; Barriered newMap_; + Barriered name_; }; class FunctionType : public Type { public: - static FunctionType *New(Zone *zone, TokenKind kind); + static FunctionType *New(Zone *zone, Handle name, TokenKind kind); Type *parameterAt(size_t i) { return Type::cast(parameters()->at(i)); @@ -386,6 +404,9 @@ TokenKind token() { return token_; } + String *name() { + return name_; + } // GC Descriptor. static inline size_t offsetOfReturnType() { @@ -397,6 +418,9 @@ static inline size_t offsetOfDefaults() { return OFFSETOF(FunctionType, defaults_); } + static inline size_t offsetOfName() { + return OFFSETOF(FunctionType, name_); + } // End GC Descriptor. static FunctionType *cast(Object *obj) { @@ -409,6 +433,7 @@ Barriered returnType_; Barriered parameters_; Barriered defaults_; + Barriered name_; TokenKind token_; bool variadicNative_; };