Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: src/types.h

Issue 132493002: [Sheriff] Revert "Templatise type representation" and "Fix Mac warnings". (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/type-info.cc ('k') | src/types.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types.h
diff --git a/src/types.h b/src/types.h
index 0e659a0cb2bb18e330d05e6eac7c060797acc7f9..1dc79dd6b33566759cd87f8df4d54d8da25a951f 100644
--- a/src/types.h
+++ b/src/types.h
@@ -131,72 +131,44 @@ namespace internal {
V(Detectable, kAllocated - kUndetectable)
-// struct Config {
-// typedef Base;
-// typedef Unioned;
-// typedef Region;
-// template<class> struct Handle { typedef type; } // No template typedefs...
-// static Handle<Type>::type handle(Type* type); // !is_bitset(type)
-// static bool is_bitset(Type* type);
-// static bool is_class(Type* type);
-// static bool is_constant(Type* type);
-// static bool is_union(Type* type);
-// static int as_bitset(Type* type);
-// static i::Handle<i::Map> as_class(Type* type);
-// static i::Handle<i::Object> as_constant(Type* type);
-// static Handle<Unioned>::type as_union(Type* type);
-// static Type* from_bitset(int bitset);
-// static Handle<Type>::type from_bitset(int bitset, Region* region);
-// static Handle<Type>::type from_class(i::Handle<i::Map> map, Region* region)
-// static Handle<Type>::type from_constant(
-// i::Handle<i::Object> value, Region* region);
-// static Handle<Type>::type from_union(Handle<Unioned>::T unioned);
-// static Handle<Unioned>::type union_create(int size, Region* region);
-// static Handle<Type>::type union_get(Handle<Unioned>::T unioned, int i);
-// }
-template<class Config>
-class TypeImpl : public Config::Base {
+class Type : public Object {
public:
- typedef typename Config::template Handle<TypeImpl>::type TypeHandle;
- typedef typename Config::Region Region;
-
- #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
- static TypeImpl* type() { return Config::from_bitset(k##type); } \
- static TypeHandle type(Region* region) { \
- return Config::from_bitset(k##type, region); \
- }
+ #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
+ static Type* type() { return from_bitset(k##type); }
BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
#undef DEFINE_TYPE_CONSTRUCTOR
- static TypeHandle Class(i::Handle<i::Map> map, Region* region) {
- return Config::from_class(map, region);
+ static Type* Class(Handle<i::Map> map) { return from_handle(map); }
+ static Type* Constant(Handle<i::HeapObject> value) {
+ return Constant(value, value->GetIsolate());
}
- static TypeHandle Constant(i::Handle<i::Object> value, Region* region) {
- return Config::from_constant(value, region);
+ static Type* Constant(Handle<i::Object> value, Isolate* isolate) {
+ return from_handle(isolate->factory()->NewBox(value));
}
- static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
- static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg);
+ static Type* Union(Handle<Type> type1, Handle<Type> type2);
+ static Type* Intersect(Handle<Type> type1, Handle<Type> type2);
+ static Type* Optional(Handle<Type> type); // type \/ Undefined
- static TypeHandle Of(i::Handle<i::Object> value, Region* region) {
- return Config::from_bitset(LubBitset(*value), region);
+ static Type* Of(Handle<i::Object> value) {
+ return from_bitset(LubBitset(*value));
}
- bool Is(TypeImpl* that) { return this == that || this->SlowIs(that); }
- bool Is(TypeHandle that) { return this->Is(*that); }
- bool Maybe(TypeImpl* that);
- bool Maybe(TypeHandle that) { return this->Maybe(*that); }
+ bool Is(Type* that) { return this == that || SlowIs(that); }
+ bool Is(Handle<Type> that) { return this->Is(*that); }
+ bool Maybe(Type* that);
+ bool Maybe(Handle<Type> that) { return this->Maybe(*that); }
// State-dependent versions of Of and Is that consider subtyping between
// a constant and its map class.
- static TypeHandle OfCurrently(i::Handle<i::Object> value, Region* region);
- bool IsCurrently(TypeImpl* that);
- bool IsCurrently(TypeHandle that) { return this->IsCurrently(*that); }
+ static Type* OfCurrently(Handle<i::Object> value);
+ bool IsCurrently(Type* that);
+ bool IsCurrently(Handle<Type> that) { return this->IsCurrently(*that); }
- bool IsClass() { return Config::is_class(this); }
- bool IsConstant() { return Config::is_constant(this); }
- i::Handle<i::Map> AsClass() { return Config::as_class(this); }
- i::Handle<i::Object> AsConstant() { return Config::as_constant(this); }
+ bool IsClass() { return is_class(); }
+ bool IsConstant() { return is_constant(); }
+ Handle<i::Map> AsClass() { return as_class(); }
+ Handle<i::Object> AsConstant() { return as_constant(); }
int NumClasses();
int NumConstants();
@@ -205,36 +177,37 @@ class TypeImpl : public Config::Base {
class Iterator {
public:
bool Done() const { return index_ < 0; }
- i::Handle<T> Current();
+ Handle<T> Current();
void Advance();
private:
- template<class> friend class TypeImpl;
+ friend class Type;
Iterator() : index_(-1) {}
- explicit Iterator(TypeHandle type) : type_(type), index_(-1) {
+ explicit Iterator(Handle<Type> type) : type_(type), index_(-1) {
Advance();
}
- inline bool matches(TypeHandle type);
- inline TypeHandle get_type();
+ inline bool matches(Handle<Type> type);
+ inline Handle<Type> get_type();
- TypeHandle type_;
+ Handle<Type> type_;
int index_;
};
Iterator<i::Map> Classes() {
- if (this->IsBitset()) return Iterator<i::Map>();
- return Iterator<i::Map>(Config::handle(this));
+ if (this->is_bitset()) return Iterator<i::Map>();
+ return Iterator<i::Map>(this->handle());
}
Iterator<i::Object> Constants() {
- if (this->IsBitset()) return Iterator<i::Object>();
- return Iterator<i::Object>(Config::handle(this));
+ if (this->is_bitset()) return Iterator<i::Object>();
+ return Iterator<i::Object>(this->handle());
}
- static TypeImpl* cast(i::Object* object) {
- TypeImpl* t = static_cast<Type*>(object);
- ASSERT(t->IsBitset() || t->IsClass() || t->IsConstant() || t->IsUnion());
+ static Type* cast(i::Object* object) {
+ Type* t = static_cast<Type*>(object);
+ ASSERT(t->is_bitset() || t->is_class() ||
+ t->is_constant() || t->is_union());
return t;
}
@@ -244,14 +217,11 @@ class TypeImpl : public Config::Base {
#endif
private:
- template<class> friend class Iterator;
-
// A union is a fixed array containing types. Invariants:
// - its length is at least 2
// - at most one field is a bitset, and it must go into index 0
// - no field is a union
- typedef typename Config::Unioned Unioned;
- typedef typename Config::template Handle<Unioned>::type UnionedHandle;
+ typedef FixedArray Unioned;
enum {
#define DECLARE_TYPE(type, value) k##type = (value),
@@ -260,14 +230,40 @@ class TypeImpl : public Config::Base {
kUnusedEOL = 0
};
- bool IsNone() { return this == None(); }
- bool IsAny() { return this == Any(); }
- bool IsBitset() { return Config::is_bitset(this); }
- bool IsUnion() { return Config::is_union(this); }
- int AsBitset() { return Config::as_bitset(this); }
- UnionedHandle AsUnion() { return Config::as_union(this); }
+ bool is_none() { return this == None(); }
+ bool is_bitset() { return this->IsSmi(); }
+ bool is_class() { return this->IsMap(); }
+ bool is_constant() { return this->IsBox(); }
+ bool is_union() { return this->IsFixedArray(); }
- bool SlowIs(TypeImpl* that);
+ bool SlowIs(Type* that);
+
+ int as_bitset() { return Smi::cast(this)->value(); }
+ Handle<i::Map> as_class() { return Handle<i::Map>::cast(handle()); }
+ Handle<i::Object> as_constant() {
+ Handle<i::Box> box = Handle<i::Box>::cast(handle());
+ return i::handle(box->value(), box->GetIsolate());
+ }
+ Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); }
+
+ Handle<Type> handle() { return handle_via_isolate_of(this); }
+ Handle<Type> handle_via_isolate_of(Type* type) {
+ ASSERT(type->IsHeapObject());
+ return i::handle(this, i::HeapObject::cast(type)->GetIsolate());
+ }
+
+ static Type* from_bitset(int bitset) {
+ return static_cast<Type*>(i::Object::cast(i::Smi::FromInt(bitset)));
+ }
+ static Type* from_handle(Handle<i::HeapObject> handle) {
+ return static_cast<Type*>(i::Object::cast(*handle));
+ }
+
+ static Handle<Type> union_get(Handle<Unioned> unioned, int i) {
+ Type* type = static_cast<Type*>(unioned->get(i));
+ ASSERT(!type->is_union());
+ return type->handle_via_isolate_of(from_handle(unioned));
+ }
int LubBitset(); // least upper bound that's a bitset
int GlbBitset(); // greatest lower bound that's a bitset
@@ -275,131 +271,67 @@ class TypeImpl : public Config::Base {
static int LubBitset(i::Object* value);
static int LubBitset(i::Map* map);
- bool InUnion(UnionedHandle unioned, int current_size);
- int ExtendUnion(UnionedHandle unioned, int current_size);
+ bool InUnion(Handle<Unioned> unioned, int current_size);
+ int ExtendUnion(Handle<Unioned> unioned, int current_size);
int ExtendIntersection(
- UnionedHandle unioned, TypeHandle type, int current_size);
+ Handle<Unioned> unioned, Handle<Type> type, int current_size);
static const char* bitset_name(int bitset);
};
-struct HeapTypeConfig {
- typedef TypeImpl<HeapTypeConfig> Type;
- typedef i::Object Base;
- typedef i::FixedArray Unioned;
- typedef i::Isolate Region;
- template<class T> struct Handle { typedef i::Handle<T> type; };
-
- static i::Handle<Type> handle(Type* type) {
- return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
- }
-
- static bool is_bitset(Type* type) { return type->IsSmi(); }
- static bool is_class(Type* type) { return type->IsMap(); }
- static bool is_constant(Type* type) { return type->IsBox(); }
- static bool is_union(Type* type) { return type->IsFixedArray(); }
-
- static int as_bitset(Type* type) {
- return Smi::cast(type)->value();
- }
- static i::Handle<i::Map> as_class(Type* type) {
- return i::handle(i::Map::cast(type));
- }
- static i::Handle<i::Object> as_constant(Type* type) {
- i::Box* box = i::Box::cast(type);
- return i::handle(box->value(), box->GetIsolate());
- }
- static i::Handle<Unioned> as_union(Type* type) {
- return i::handle(i::FixedArray::cast(type));
- }
+// A simple struct to represent a pair of lower/upper type bounds.
+struct Bounds {
+ Handle<Type> lower;
+ Handle<Type> upper;
- static Type* from_bitset(int bitset) {
- return Type::cast(i::Smi::FromInt(bitset));
- }
- static i::Handle<Type> from_bitset(int bitset, Isolate* isolate) {
- return i::handle(from_bitset(bitset), isolate);
- }
- static i::Handle<Type> from_class(i::Handle<i::Map> map, Isolate* isolate) {
- return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
- }
- static i::Handle<Type> from_constant(
- i::Handle<i::Object> value, Isolate* isolate) {
- ASSERT(isolate || value->IsHeapObject());
- if (!isolate) isolate = i::HeapObject::cast(*value)->GetIsolate();
- i::Handle<Box> box = isolate->factory()->NewBox(value);
- return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
- }
- static i::Handle<Type> from_union(i::Handle<Unioned> unioned) {
- return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned));
+ Bounds() {}
+ Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) {
+ ASSERT(lower->Is(upper));
}
-
- static i::Handle<Unioned> union_create(int size, Isolate* isolate) {
- return isolate->factory()->NewFixedArray(size);
+ Bounds(Type* l, Type* u, Isolate* isl) : lower(l, isl), upper(u, isl) {
+ ASSERT(lower->Is(upper));
}
- static i::Handle<Type> union_get(i::Handle<Unioned> unioned, int i) {
- Type* type = static_cast<Type*>(unioned->get(i));
- ASSERT(!is_union(type));
- return i::handle(type, unioned->GetIsolate());
+ explicit Bounds(Handle<Type> t) : lower(t), upper(t) {
+ ASSERT(lower->Is(upper));
}
-};
-
-typedef TypeImpl<HeapTypeConfig> Type;
-
-
-// A simple struct to represent a pair of lower/upper type bounds.
-template<class Config>
-struct BoundsImpl {
- typedef TypeImpl<Config> Type;
- typedef typename Type::TypeHandle TypeHandle;
- typedef typename Type::Region Region;
-
- TypeHandle lower;
- TypeHandle upper;
-
- BoundsImpl() {}
- explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {}
- BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) {
+ Bounds(Type* t, Isolate* isl) : lower(t, isl), upper(t, isl) {
ASSERT(lower->Is(upper));
}
// Unrestricted bounds.
- static BoundsImpl Unbounded(Region* region) {
- return BoundsImpl(Type::None(region), Type::Any(region));
+ static Bounds Unbounded(Isolate* isl) {
+ return Bounds(Type::None(), Type::Any(), isl);
}
// Meet: both b1 and b2 are known to hold.
- static BoundsImpl Both(BoundsImpl b1, BoundsImpl b2, Region* region) {
- TypeHandle lower = Type::Union(b1.lower, b2.lower, region);
- TypeHandle upper = Type::Intersect(b1.upper, b2.upper, region);
+ static Bounds Both(Bounds b1, Bounds b2, Isolate* isl) {
+ Handle<Type> lower(Type::Union(b1.lower, b2.lower), isl);
+ Handle<Type> upper(Type::Intersect(b1.upper, b2.upper), isl);
// Lower bounds are considered approximate, correct as necessary.
- lower = Type::Intersect(lower, upper, region);
- return BoundsImpl(lower, upper);
+ lower = handle(Type::Intersect(lower, upper), isl);
+ return Bounds(lower, upper);
}
// Join: either b1 or b2 is known to hold.
- static BoundsImpl Either(BoundsImpl b1, BoundsImpl b2, Region* region) {
- TypeHandle lower = Type::Intersect(b1.lower, b2.lower, region);
- TypeHandle upper = Type::Union(b1.upper, b2.upper, region);
- return BoundsImpl(lower, upper);
+ static Bounds Either(Bounds b1, Bounds b2, Isolate* isl) {
+ return Bounds(
+ handle(Type::Intersect(b1.lower, b2.lower), isl),
+ handle(Type::Union(b1.upper, b2.upper), isl));
}
- static BoundsImpl NarrowLower(BoundsImpl b, TypeHandle t, Region* region) {
+ static Bounds NarrowLower(Bounds b, Handle<Type> t, Isolate* isl) {
// Lower bounds are considered approximate, correct as necessary.
- t = Type::Intersect(t, b.upper, region);
- TypeHandle lower = Type::Union(b.lower, t, region);
- return BoundsImpl(lower, b.upper);
+ t = handle(Type::Intersect(t, b.upper), isl);
+ return Bounds(handle(Type::Union(b.lower, t), isl), b.upper);
}
- static BoundsImpl NarrowUpper(BoundsImpl b, TypeHandle t, Region* region) {
- TypeHandle lower = Type::Intersect(b.lower, t, region);
- TypeHandle upper = Type::Intersect(b.upper, t, region);
- return BoundsImpl(lower, upper);
+ static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) {
+ return Bounds(
+ handle(Type::Intersect(b.lower, t), isl),
+ handle(Type::Intersect(b.upper, t), isl));
}
};
-typedef BoundsImpl<HeapTypeConfig> Bounds;
-
-
} } // namespace v8::internal
#endif // V8_TYPES_H_
« no previous file with comments | « src/type-info.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698