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

Unified Diff: src/types.h

Issue 1217803004: Add a type for objects with typed properties. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 5 years, 6 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 | « no previous file | 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 8d63908015db675fca8c0d8d46428808ad2ee14d..ee7cd4d1893389eb282ae5678b9cc88878618dae 100644
--- a/src/types.h
+++ b/src/types.h
@@ -330,6 +330,7 @@ class TypeImpl : public Config::Base {
class ContextType;
class ArrayType;
class FunctionType;
+ class ObjectType;
typedef typename Config::template Handle<TypeImpl>::type TypeHandle;
typedef typename Config::template Handle<ClassType>::type ClassHandle;
@@ -338,6 +339,7 @@ class TypeImpl : public Config::Base {
typedef typename Config::template Handle<ContextType>::type ContextHandle;
typedef typename Config::template Handle<ArrayType>::type ArrayHandle;
typedef typename Config::template Handle<FunctionType>::type FunctionHandle;
+ typedef typename Config::template Handle<ObjectType>::type ObjectHandle;
typedef typename Config::template Handle<UnionType>::type UnionHandle;
typedef typename Config::Region Region;
@@ -423,6 +425,10 @@ class TypeImpl : public Config::Base {
return function;
}
+ static TypeHandle Object(int capacity, Region* region) {
+ return ObjectType::New(capacity, region);
+ }
+
static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg);
static TypeImpl* Union(TypeImpl* type1, TypeImpl* type2) {
@@ -498,6 +504,9 @@ class TypeImpl : public Config::Base {
bool IsFunction() {
return Config::is_struct(this, StructuralType::kFunctionTag);
}
+ bool IsObject() {
+ return Config::is_struct(this, StructuralType::kObjectTag);
+ }
ClassType* AsClass() { return ClassType::cast(this); }
ConstantType* AsConstant() { return ConstantType::cast(this); }
@@ -505,6 +514,7 @@ class TypeImpl : public Config::Base {
ContextType* AsContext() { return ContextType::cast(this); }
ArrayType* AsArray() { return ArrayType::cast(this); }
FunctionType* AsFunction() { return FunctionType::cast(this); }
+ ObjectType* AsObject() { return ObjectType::cast(this); }
// Minimum and maximum of a numeric type.
// These functions do not distinguish between -0 and +0. If the type equals
@@ -724,6 +734,7 @@ class TypeImpl<Config>::StructuralType : public TypeImpl<Config> {
kContextTag,
kArrayTag,
kFunctionTag,
+ kObjectTag,
kUnionTag
};
@@ -957,6 +968,49 @@ class TypeImpl<Config>::FunctionType : public StructuralType {
// -----------------------------------------------------------------------------
+// Object types.
+// Structural type with the following layout:
+// 0 - Any type used when accessing unknown property.
+// i * 2 + 1 - Name of the ith property.
+// i * 2 + 2 - Type of the ith property.
+template <class Config>
+class TypeImpl<Config>::ObjectType : public StructuralType {
+ public:
+ typedef TypeImpl<Config> Type;
+ typedef typename Type::Region Region;
+
+ Handle<i::String> Name(int i) {
+ return this->template GetValue<i::String>(2 * i + 1);
+ }
+ TypeHandle Property(int i) { return this->Get(2 * i + 2); }
+ TypeHandle Property(Handle<i::String> name) {
+ for (int i = 0; i < Width(); ++i) {
+ if (name->Equals(*Name(i))) return Property(i);
+ }
+ return this->Get(0);
+ }
+ int Width() { return this->Length() / 2; }
+
+ static ObjectHandle New(int capacity, Region* region) {
+ ObjectHandle type = Config::template cast<ObjectType>(StructuralType::New(
+ StructuralType::kObjectTag, capacity * 2 + 1, region));
+ type->AsObject()->Set(0, Type::Any(region));
+ return type;
+ }
+
+ void InitProperty(int i, Handle<i::String> name, TypeHandle type) {
+ this->template SetValue<i::String>(2 * i + 1, name);
+ this->Set(2 * i + 2, type);
+ }
+
+ static ObjectType* cast(Type* type) {
+ DCHECK(type->IsObject());
+ return static_cast<ObjectType*>(type);
+ }
+};
+
+
+// -----------------------------------------------------------------------------
// Type iterators.
template<class Config> template<class T>
« no previous file with comments | « no previous file | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698