More const preparation: allow type casts to follow qualification.
More const preparation: allow type casts to follow qualification.
1.1 --- a/src/Types.cpp Tue Dec 25 16:32:06 2012 -0800
1.2 +++ b/src/Types.cpp Tue Dec 25 17:02:07 2012 -0800
1.3 @@ -87,7 +87,7 @@
1.4 return NULL;
1.5 }
1.6
1.7 - Local<ArrayType> type(zone, ArrayType::cast(zone->allocate(MapKind_ArrayType, sizeof(ArrayType), Heap::Tenure_Old)));
1.8 + Local<ArrayType> type(zone, (ArrayType *)zone->allocate(MapKind_ArrayType, sizeof(ArrayType), Heap::Tenure_Old));
1.9 if (!type)
1.10 return NULL;
1.11
1.12 @@ -104,7 +104,7 @@
1.13 ArrayType *
1.14 ArrayType::NewExternal(Zone *zone, Handle<Type> contained)
1.15 {
1.16 - Local<ArrayType> type(zone, ArrayType::cast(zone->allocate(MapKind_ArrayType, sizeof(ArrayType), Heap::Tenure_Old)));
1.17 + Local<ArrayType> type(zone, (ArrayType *)zone->allocate(MapKind_ArrayType, sizeof(ArrayType), Heap::Tenure_Old));
1.18 if (!type)
1.19 return NULL;
1.20
1.21 @@ -120,7 +120,7 @@
1.22 ReferenceType *
1.23 ReferenceType::New(Zone *zone, Handle<Type> contained)
1.24 {
1.25 - Local<ReferenceType> type(zone, ReferenceType::cast(zone->allocate(MapKind_ReferenceType, sizeof(ReferenceType), Heap::Tenure_Old)));
1.26 + Local<ReferenceType> type(zone, (ReferenceType *)zone->allocate(MapKind_ReferenceType, sizeof(ReferenceType), Heap::Tenure_Old));
1.27 if (!type)
1.28 return NULL;
1.29
1.30 @@ -132,7 +132,7 @@
1.31 EnumType *
1.32 EnumType::New(Zone *zone, Handle<String> name)
1.33 {
1.34 - Local<EnumType> type(zone, EnumType::cast(zone->allocate(MapKind_EnumType, sizeof(EnumType), Heap::Tenure_Old)));
1.35 + Local<EnumType> type(zone, (EnumType *)zone->allocate(MapKind_EnumType, sizeof(EnumType), Heap::Tenure_Old));
1.36 if (!type)
1.37 return NULL;
1.38
1.39 @@ -144,7 +144,7 @@
1.40 StructType *
1.41 StructType::New(Zone *zone, Handle<String> name, Handle<FixedArray> fields)
1.42 {
1.43 - Local<StructType> type(zone, StructType::cast(zone->allocate(MapKind_StructType, sizeof(StructType), Heap::Tenure_Old)));
1.44 + Local<StructType> type(zone, (StructType *)zone->allocate(MapKind_StructType, sizeof(StructType), Heap::Tenure_Old));
1.45 if (!type)
1.46 return NULL;
1.47
1.48 @@ -193,7 +193,7 @@
1.49 FunctionType *
1.50 FunctionType::New(Zone *zone, Handle<String> name, TokenKind token)
1.51 {
1.52 - Local<FunctionType> type(zone, FunctionType::cast(zone->allocate(MapKind_FunctionType, sizeof(FunctionType), Heap::Tenure_Old)));
1.53 + Local<FunctionType> type(zone, (FunctionType *)zone->allocate(MapKind_FunctionType, sizeof(FunctionType), Heap::Tenure_Old));
1.54 if (!type)
1.55 return NULL;
1.56
2.1 --- a/src/Types.h Tue Dec 25 16:32:06 2012 -0800
2.2 +++ b/src/Types.h Tue Dec 25 17:02:07 2012 -0800
2.3 @@ -113,7 +113,11 @@
2.4 // int32, float, bool, or an enum.
2.5 UNCHECKED,
2.6
2.7 - // ------ Add traceable types below -------
2.8 + // Contains type qualifiers, and a back pointer to the actual
2.9 + // unqualified type.
2.10 + QUALTYPE,
2.11 +
2.12 + // ------ Add traceable types below (STRING FIRST!) -------
2.13
2.14 // An immutable type that is a primitive in terms of language
2.15 // semantics, but gets a special type here to make internal
2.16 @@ -133,11 +137,7 @@
2.17
2.18 // Structs are composite records that may contain primitives, arrays,
2.19 // functions, enums, and other structs.
2.20 - STRUCT,
2.21 -
2.22 - // Contains type qualifiers, and a back pointer to the actual
2.23 - // unqualified type.
2.24 - QUALTYPE
2.25 + STRUCT
2.26 };
2.27
2.28 void init(Kind kind);
2.29 @@ -236,6 +236,9 @@
2.30 return TypeQual_None;
2.31 return quals_;
2.32 }
2.33 + Type *unqualified() {
2.34 + return root_;
2.35 + }
2.36
2.37 // GC Descriptor.
2.38 static inline size_t offsetOfRoot() {
2.39 @@ -292,8 +295,11 @@
2.40 }
2.41 // End GC Descriptor.
2.42
2.43 - static ReferenceType *cast(Object *obj) {
2.44 - assert(!obj || obj->is(MapKind_ReferenceType));
2.45 + static ReferenceType *cast(Type *obj) {
2.46 + if (!obj)
2.47 + return NULL;
2.48 + obj = obj->unqualified();
2.49 + assert(obj->is(MapKind_ReferenceType));
2.50 return (ReferenceType *)obj;
2.51 }
2.52
2.53 @@ -358,8 +364,11 @@
2.54 }
2.55 // End GC Descriptor.
2.56
2.57 - static ArrayType *cast(Object *obj) {
2.58 - assert(!obj || obj->is(MapKind_ArrayType));
2.59 + static ArrayType *cast(Type *obj) {
2.60 + if (!obj)
2.61 + return NULL;
2.62 + obj = obj->unqualified();
2.63 + assert(obj->is(MapKind_ArrayType));
2.64 return (ArrayType *)obj;
2.65 }
2.66
2.67 @@ -406,8 +415,11 @@
2.68 }
2.69 // End GC Descriptor.
2.70
2.71 - static StructType *cast(Object *obj) {
2.72 - assert(!obj || obj->is(MapKind_StructType));
2.73 + static StructType *cast(Type *obj) {
2.74 + if (!obj)
2.75 + return NULL;
2.76 + obj = obj->unqualified();
2.77 + assert(obj->is(MapKind_StructType));
2.78 return (StructType *)obj;
2.79 }
2.80
2.81 @@ -478,8 +490,11 @@
2.82 }
2.83 // End GC Descriptor.
2.84
2.85 - static FunctionType *cast(Object *obj) {
2.86 - assert(!obj || obj->is(MapKind_FunctionType));
2.87 + static FunctionType *cast(Type *obj) {
2.88 + if (!obj)
2.89 + return NULL;
2.90 + obj = obj->unqualified();
2.91 + assert(obj->is(MapKind_FunctionType));
2.92 return (FunctionType *)obj;
2.93 }
2.94