| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_TYPES_H_ | 5 #ifndef V8_TYPES_H_ |
| 6 #define V8_TYPES_H_ | 6 #define V8_TYPES_H_ |
| 7 | 7 |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 class BitsetType; // Internal | 323 class BitsetType; // Internal |
| 324 class StructuralType; // Internal | 324 class StructuralType; // Internal |
| 325 class UnionType; // Internal | 325 class UnionType; // Internal |
| 326 | 326 |
| 327 class ClassType; | 327 class ClassType; |
| 328 class ConstantType; | 328 class ConstantType; |
| 329 class RangeType; | 329 class RangeType; |
| 330 class ContextType; | 330 class ContextType; |
| 331 class ArrayType; | 331 class ArrayType; |
| 332 class FunctionType; | 332 class FunctionType; |
| 333 class ObjectType; |
| 333 | 334 |
| 334 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; | 335 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; |
| 335 typedef typename Config::template Handle<ClassType>::type ClassHandle; | 336 typedef typename Config::template Handle<ClassType>::type ClassHandle; |
| 336 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; | 337 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; |
| 337 typedef typename Config::template Handle<RangeType>::type RangeHandle; | 338 typedef typename Config::template Handle<RangeType>::type RangeHandle; |
| 338 typedef typename Config::template Handle<ContextType>::type ContextHandle; | 339 typedef typename Config::template Handle<ContextType>::type ContextHandle; |
| 339 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; | 340 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; |
| 340 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; | 341 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; |
| 342 typedef typename Config::template Handle<ObjectType>::type ObjectHandle; |
| 341 typedef typename Config::template Handle<UnionType>::type UnionHandle; | 343 typedef typename Config::template Handle<UnionType>::type UnionHandle; |
| 342 typedef typename Config::Region Region; | 344 typedef typename Config::Region Region; |
| 343 | 345 |
| 344 // Constructors. | 346 // Constructors. |
| 345 | 347 |
| 346 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 348 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
| 347 static TypeImpl* type() { \ | 349 static TypeImpl* type() { \ |
| 348 return BitsetType::New(BitsetType::k##type); \ | 350 return BitsetType::New(BitsetType::k##type); \ |
| 349 } \ | 351 } \ |
| 350 static TypeHandle type(Region* region) { \ | 352 static TypeHandle type(Region* region) { \ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 } | 418 } |
| 417 static TypeHandle Function(TypeHandle result, int arity, TypeHandle* params, | 419 static TypeHandle Function(TypeHandle result, int arity, TypeHandle* params, |
| 418 Region* region) { | 420 Region* region) { |
| 419 FunctionHandle function = Function(result, Any(region), arity, region); | 421 FunctionHandle function = Function(result, Any(region), arity, region); |
| 420 for (int i = 0; i < arity; ++i) { | 422 for (int i = 0; i < arity; ++i) { |
| 421 function->InitParameter(i, params[i]); | 423 function->InitParameter(i, params[i]); |
| 422 } | 424 } |
| 423 return function; | 425 return function; |
| 424 } | 426 } |
| 425 | 427 |
| 428 static TypeHandle Object(int capacity, Region* region) { |
| 429 return ObjectType::New(capacity, region); |
| 430 } |
| 431 |
| 426 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); | 432 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); |
| 427 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); | 433 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); |
| 428 static TypeImpl* Union(TypeImpl* type1, TypeImpl* type2) { | 434 static TypeImpl* Union(TypeImpl* type1, TypeImpl* type2) { |
| 429 return BitsetType::New(type1->AsBitset() | type2->AsBitset()); | 435 return BitsetType::New(type1->AsBitset() | type2->AsBitset()); |
| 430 } | 436 } |
| 431 static TypeImpl* Intersect(TypeImpl* type1, TypeImpl* type2) { | 437 static TypeImpl* Intersect(TypeImpl* type1, TypeImpl* type2) { |
| 432 return BitsetType::New(type1->AsBitset() & type2->AsBitset()); | 438 return BitsetType::New(type1->AsBitset() & type2->AsBitset()); |
| 433 } | 439 } |
| 434 | 440 |
| 435 static TypeHandle Of(double value, Region* region) { | 441 static TypeHandle Of(double value, Region* region) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 497 } |
| 492 bool IsContext() { | 498 bool IsContext() { |
| 493 return Config::is_struct(this, StructuralType::kContextTag); | 499 return Config::is_struct(this, StructuralType::kContextTag); |
| 494 } | 500 } |
| 495 bool IsArray() { | 501 bool IsArray() { |
| 496 return Config::is_struct(this, StructuralType::kArrayTag); | 502 return Config::is_struct(this, StructuralType::kArrayTag); |
| 497 } | 503 } |
| 498 bool IsFunction() { | 504 bool IsFunction() { |
| 499 return Config::is_struct(this, StructuralType::kFunctionTag); | 505 return Config::is_struct(this, StructuralType::kFunctionTag); |
| 500 } | 506 } |
| 507 bool IsObject() { |
| 508 return Config::is_struct(this, StructuralType::kObjectTag); |
| 509 } |
| 501 | 510 |
| 502 ClassType* AsClass() { return ClassType::cast(this); } | 511 ClassType* AsClass() { return ClassType::cast(this); } |
| 503 ConstantType* AsConstant() { return ConstantType::cast(this); } | 512 ConstantType* AsConstant() { return ConstantType::cast(this); } |
| 504 RangeType* AsRange() { return RangeType::cast(this); } | 513 RangeType* AsRange() { return RangeType::cast(this); } |
| 505 ContextType* AsContext() { return ContextType::cast(this); } | 514 ContextType* AsContext() { return ContextType::cast(this); } |
| 506 ArrayType* AsArray() { return ArrayType::cast(this); } | 515 ArrayType* AsArray() { return ArrayType::cast(this); } |
| 507 FunctionType* AsFunction() { return FunctionType::cast(this); } | 516 FunctionType* AsFunction() { return FunctionType::cast(this); } |
| 517 ObjectType* AsObject() { return ObjectType::cast(this); } |
| 508 | 518 |
| 509 // Minimum and maximum of a numeric type. | 519 // Minimum and maximum of a numeric type. |
| 510 // These functions do not distinguish between -0 and +0. If the type equals | 520 // These functions do not distinguish between -0 and +0. If the type equals |
| 511 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these | 521 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these |
| 512 // functions on subtypes of Number. | 522 // functions on subtypes of Number. |
| 513 double Min(); | 523 double Min(); |
| 514 double Max(); | 524 double Max(); |
| 515 | 525 |
| 516 // Extracts a range from the type. If the type is a range, it just | 526 // Extracts a range from the type. If the type is a range, it just |
| 517 // returns it; if it is a union, it returns the range component. | 527 // returns it; if it is a union, it returns the range component. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 template<class> friend class TypeImpl; | 727 template<class> friend class TypeImpl; |
| 718 friend struct ZoneTypeConfig; // For tags. | 728 friend struct ZoneTypeConfig; // For tags. |
| 719 friend struct HeapTypeConfig; | 729 friend struct HeapTypeConfig; |
| 720 | 730 |
| 721 enum Tag { | 731 enum Tag { |
| 722 kClassTag, | 732 kClassTag, |
| 723 kConstantTag, | 733 kConstantTag, |
| 724 kContextTag, | 734 kContextTag, |
| 725 kArrayTag, | 735 kArrayTag, |
| 726 kFunctionTag, | 736 kFunctionTag, |
| 737 kObjectTag, |
| 727 kUnionTag | 738 kUnionTag |
| 728 }; | 739 }; |
| 729 | 740 |
| 730 int Length() { | 741 int Length() { |
| 731 return Config::struct_length(Config::as_struct(this)); | 742 return Config::struct_length(Config::as_struct(this)); |
| 732 } | 743 } |
| 733 TypeHandle Get(int i) { | 744 TypeHandle Get(int i) { |
| 734 DCHECK(0 <= i && i < this->Length()); | 745 DCHECK(0 <= i && i < this->Length()); |
| 735 return Config::struct_get(Config::as_struct(this), i); | 746 return Config::struct_get(Config::as_struct(this), i); |
| 736 } | 747 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 } | 961 } |
| 951 | 962 |
| 952 static FunctionType* cast(TypeImpl* type) { | 963 static FunctionType* cast(TypeImpl* type) { |
| 953 DCHECK(type->IsFunction()); | 964 DCHECK(type->IsFunction()); |
| 954 return static_cast<FunctionType*>(type); | 965 return static_cast<FunctionType*>(type); |
| 955 } | 966 } |
| 956 }; | 967 }; |
| 957 | 968 |
| 958 | 969 |
| 959 // ----------------------------------------------------------------------------- | 970 // ----------------------------------------------------------------------------- |
| 971 // Object types. |
| 972 // Structural type with the following layout: |
| 973 // 0 - Any type used when accessing unknown property. |
| 974 // i * 2 + 1 - Name of the ith property. |
| 975 // i * 2 + 2 - Type of the ith property. |
| 976 template <class Config> |
| 977 class TypeImpl<Config>::ObjectType : public StructuralType { |
| 978 public: |
| 979 typedef TypeImpl<Config> Type; |
| 980 typedef typename Type::Region Region; |
| 981 |
| 982 Handle<i::String> Name(int i) { |
| 983 return this->template GetValue<i::String>(2 * i + 1); |
| 984 } |
| 985 TypeHandle Property(int i) { return this->Get(2 * i + 2); } |
| 986 TypeHandle Property(Handle<i::String> name) { |
| 987 for (int i = 0; i < Width(); ++i) { |
| 988 if (name->Equals(*Name(i))) return Property(i); |
| 989 } |
| 990 return this->Get(0); |
| 991 } |
| 992 int Width() { return this->Length() / 2; } |
| 993 |
| 994 static ObjectHandle New(int capacity, Region* region) { |
| 995 ObjectHandle type = Config::template cast<ObjectType>(StructuralType::New( |
| 996 StructuralType::kObjectTag, capacity * 2 + 1, region)); |
| 997 type->AsObject()->Set(0, Type::Any(region)); |
| 998 return type; |
| 999 } |
| 1000 |
| 1001 void InitProperty(int i, Handle<i::String> name, TypeHandle type) { |
| 1002 this->template SetValue<i::String>(2 * i + 1, name); |
| 1003 this->Set(2 * i + 2, type); |
| 1004 } |
| 1005 |
| 1006 static ObjectType* cast(Type* type) { |
| 1007 DCHECK(type->IsObject()); |
| 1008 return static_cast<ObjectType*>(type); |
| 1009 } |
| 1010 }; |
| 1011 |
| 1012 |
| 1013 // ----------------------------------------------------------------------------- |
| 960 // Type iterators. | 1014 // Type iterators. |
| 961 | 1015 |
| 962 template<class Config> template<class T> | 1016 template<class Config> template<class T> |
| 963 class TypeImpl<Config>::Iterator { | 1017 class TypeImpl<Config>::Iterator { |
| 964 public: | 1018 public: |
| 965 bool Done() const { return index_ < 0; } | 1019 bool Done() const { return index_ < 0; } |
| 966 i::Handle<T> Current(); | 1020 i::Handle<T> Current(); |
| 967 void Advance(); | 1021 void Advance(); |
| 968 | 1022 |
| 969 private: | 1023 private: |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 bool Narrows(BoundsImpl that) { | 1217 bool Narrows(BoundsImpl that) { |
| 1164 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1218 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
| 1165 } | 1219 } |
| 1166 }; | 1220 }; |
| 1167 | 1221 |
| 1168 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1222 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
| 1169 | 1223 |
| 1170 } } // namespace v8::internal | 1224 } } // namespace v8::internal |
| 1171 | 1225 |
| 1172 #endif // V8_TYPES_H_ | 1226 #endif // V8_TYPES_H_ |
| OLD | NEW |