1.1 --- a/src/Types.h Sat Dec 22 19:48:43 2012 -0800
1.2 +++ b/src/Types.h Sat Dec 22 23:18:57 2012 -0800
1.3 @@ -104,7 +104,6 @@
1.4 static Type *NewVoid(Zone *zone);
1.5 static Type *NewUnchecked(Zone *zone);
1.6 static Type *NewPrimitive(Zone *zone, PrimitiveType type);
1.7 - static Type *NewEnum(Zone *zone, Handle<String> name);
1.8
1.9 static bool Compare(Type *left, Type *right);
1.10
1.11 @@ -114,7 +113,8 @@
1.12 obj->is(MapKind_FunctionType) ||
1.13 obj->is(MapKind_StructType) ||
1.14 obj->is(MapKind_ArrayType) ||
1.15 - obj->is(MapKind_ReferenceType));
1.16 + obj->is(MapKind_ReferenceType) ||
1.17 + obj->is(MapKind_EnumType));
1.18 return (Type *)obj;
1.19 }
1.20
1.21 @@ -185,25 +185,35 @@
1.22 return kind() == ENUM;
1.23 }
1.24
1.25 - String *name() {
1.26 - assert(isEnum() || isStruct());
1.27 - return name_;
1.28 - }
1.29 -
1.30 - // GC Descriptor.
1.31 - static inline size_t offsetOfName() {
1.32 - return OFFSETOF(Type, name_);
1.33 - }
1.34 - // End GC Descriptor.
1.35 -
1.36 protected:
1.37 Kind kind_;
1.38 PrimitiveType primitive_;
1.39
1.40 // Primitives, arrays, and references.
1.41 bool const_;
1.42 +};
1.43
1.44 - // Enums and structs only.
1.45 +class EnumType : public Type
1.46 +{
1.47 + public:
1.48 + static EnumType *New(Zone *Zone, Handle<String> name);
1.49 +
1.50 + String *name() {
1.51 + return name_;
1.52 + }
1.53 +
1.54 + // GC Descriptor.
1.55 + static inline size_t offsetOfName() {
1.56 + return OFFSETOF(EnumType, name_);
1.57 + }
1.58 + // End GC Descriptor.
1.59 +
1.60 + static EnumType *cast(Object *obj) {
1.61 + assert(!obj || obj->is(MapKind_EnumType));
1.62 + return (EnumType *)obj;
1.63 + }
1.64 +
1.65 + private:
1.66 Barriered<String> name_;
1.67 };
1.68
1.69 @@ -325,6 +335,10 @@
1.70 newMap_ = map;
1.71 }
1.72
1.73 + String *name() {
1.74 + return name_;
1.75 + }
1.76 +
1.77 // GC Descriptor.
1.78 static inline size_t offsetOfFields() {
1.79 return OFFSETOF(StructType, fields_);
1.80 @@ -332,6 +346,9 @@
1.81 static inline size_t offsetOfNewMap() {
1.82 return OFFSETOF(StructType, newMap_);
1.83 }
1.84 + static inline size_t offsetOfName() {
1.85 + return OFFSETOF(StructType, name_);
1.86 + }
1.87 // End GC Descriptor.
1.88
1.89 static StructType *cast(Object *obj) {
1.90 @@ -343,12 +360,13 @@
1.91 // Structs only.
1.92 Barriered<FixedArray> fields_;
1.93 Barriered<StructMap> newMap_;
1.94 + Barriered<String> name_;
1.95 };
1.96
1.97 class FunctionType : public Type
1.98 {
1.99 public:
1.100 - static FunctionType *New(Zone *zone, TokenKind kind);
1.101 + static FunctionType *New(Zone *zone, Handle<String> name, TokenKind kind);
1.102
1.103 Type *parameterAt(size_t i) {
1.104 return Type::cast(parameters()->at(i));
1.105 @@ -386,6 +404,9 @@
1.106 TokenKind token() {
1.107 return token_;
1.108 }
1.109 + String *name() {
1.110 + return name_;
1.111 + }
1.112
1.113 // GC Descriptor.
1.114 static inline size_t offsetOfReturnType() {
1.115 @@ -397,6 +418,9 @@
1.116 static inline size_t offsetOfDefaults() {
1.117 return OFFSETOF(FunctionType, defaults_);
1.118 }
1.119 + static inline size_t offsetOfName() {
1.120 + return OFFSETOF(FunctionType, name_);
1.121 + }
1.122 // End GC Descriptor.
1.123
1.124 static FunctionType *cast(Object *obj) {
1.125 @@ -409,6 +433,7 @@
1.126 Barriered<Type> returnType_;
1.127 Barriered<FixedArray> parameters_;
1.128 Barriered<FixedArray> defaults_;
1.129 + Barriered<String> name_;
1.130 TokenKind token_;
1.131 bool variadicNative_;
1.132 };