Chromium Code Reviews| Index: runtime/vm/object.cc |
| =================================================================== |
| --- runtime/vm/object.cc (revision 3925) |
| +++ runtime/vm/object.cc (working copy) |
| @@ -382,7 +382,8 @@ |
| const Script& script, |
| const Library& lib) { |
| const String& name = String::Handle(String::NewSymbol(cname)); |
| - const Class& cls = Class::Handle(Class::NewInterface(name, script)); |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
| + const Class& cls = Class::Handle(Class::NewInterface(name, script, kPos)); |
| lib.AddClass(cls); |
| return cls.raw(); |
| } |
| @@ -821,17 +822,20 @@ |
| // matching the type parameters here. |
| if (num_type_params > 0) { |
| const Array& type_params = Array::Handle(type_parameters()); |
| + // TODO(regis): Simply use the type parameters as type arguments, once type |
| + // parameters are stored as an array of TypeParameter, rather than String. |
| signature_type_arguments = TypeArguments::New(num_type_params); |
| String& type_param_name = String::Handle(); |
| AbstractType& type_param = AbstractType::Handle(); |
| for (int i = 0; i < num_type_params; i++) { |
| type_param_name ^= type_params.At(i); |
| - type_param = AbstractType::NewTypeParameter(i, type_param_name); |
| + // TODO(regis): Use dummy token index 1 for now; see TODO above. |
|
siva
2012/02/06 18:13:08
The comment says use dummy token index 1 but in th
regis
2012/02/06 19:43:16
I tried to use 0 for a non-existing source and 1 f
|
| + type_param = AbstractType::NewTypeParameter(i, type_param_name, 1); |
| signature_type_arguments.SetTypeAt(i, type_param); |
| } |
| } |
| const Type& signature_type = Type::Handle( |
| - Type::New(*this, signature_type_arguments)); |
| + Type::New(*this, signature_type_arguments, token_index())); |
| // Return the still unfinalized signature type. |
| ASSERT(!signature_type.IsFinalized()); |
| @@ -867,6 +871,8 @@ |
| result.raw_ptr()->class_state_ = RawClass::kPreFinalized; |
| result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| result.raw_ptr()->num_native_fields_ = 0; |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
|
siva
2012/02/06 18:13:08
Ditto comment regarding dummy token index.
regis
2012/02/06 19:43:16
Done.
|
| + result.raw_ptr()->token_index_ = kPos; |
| result.InitEmptyFields(); |
| return result.raw(); |
| } |
| @@ -1024,7 +1030,8 @@ |
| // Return a TypeParameter if the type_name is a type parameter of this class. |
| // Return null otherwise. |
| -RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
| +RawTypeParameter* Class::LookupTypeParameter(const String& type_name, |
| + intptr_t token_index) const { |
| ASSERT(!type_name.IsNull()); |
| const Array& type_params = Array::Handle(type_parameters()); |
| if (!type_params.IsNull()) { |
| @@ -1033,7 +1040,7 @@ |
| for (intptr_t i = 0; i < num_type_params; i++) { |
| type_param ^= type_params.At(i); |
| if (type_param.Equals(type_name)) { |
| - return TypeParameter::New(i, type_name); |
| + return TypeParameter::New(i, type_name, token_index); |
| } |
| } |
| } |
| @@ -1114,7 +1121,10 @@ |
| template <class FakeInstance> |
| -RawClass* Class::New(const String& name, const Script& script) { |
| +RawClass* Class::New(const String& name, |
| + const Script& script, |
| + intptr_t token_index) { |
| + ASSERT(token_index >= 0); |
| Class& class_class = Class::Handle(Object::class_class()); |
| Class& result = Class::Handle(); |
| { |
| @@ -1132,6 +1142,7 @@ |
| result.set_instance_kind(FakeInstance::kInstanceKind); |
| result.set_name(name); |
| result.set_script(script); |
| + result.set_token_index(token_index); |
| result.raw_ptr()->is_const_ = false; |
| result.raw_ptr()->is_interface_ = false; |
| result.raw_ptr()->class_state_ = RawClass::kAllocated; |
| @@ -1142,14 +1153,18 @@ |
| } |
| -RawClass* Class::New(const String& name, const Script& script) { |
| - Class& result = Class::Handle(New<Instance>(name, script)); |
| +RawClass* Class::New(const String& name, |
| + const Script& script, |
| + intptr_t token_index) { |
| + Class& result = Class::Handle(New<Instance>(name, script, token_index)); |
| return result.raw(); |
| } |
| -RawClass* Class::NewInterface(const String& name, const Script& script) { |
| - Class& result = Class::Handle(New<Instance>(name, script)); |
| +RawClass* Class::NewInterface(const String& name, |
| + const Script& script, |
| + intptr_t token_index) { |
| + Class& result = Class::Handle(New<Instance>(name, script, token_index)); |
| result.set_is_interface(); |
| return result.raw(); |
| } |
| @@ -1173,7 +1188,8 @@ |
| type_parameter_extends = owner_class.type_parameter_extends(); |
| } |
| } |
| - Class& result = Class::Handle(New<Closure>(name, script)); |
| + const intptr_t token_index = signature_function.token_index(); |
| + Class& result = Class::Handle(New<Closure>(name, script, token_index)); |
| const Type& super_type = Type::Handle(Type::ObjectType()); |
| ASSERT(!super_type.IsNull()); |
| result.set_super_type(super_type); |
| @@ -1276,7 +1292,8 @@ |
| int field_count) { |
| Class& cls = Class::Handle(library->LookupClass(name)); |
| if (cls.IsNull()) { |
| - cls = New<Instance>(name, Script::Handle()); |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
|
siva
2012/02/06 18:13:08
Ditto comment (0 or 1)?
regis
2012/02/06 19:43:16
Done.
|
| + cls = New<Instance>(name, Script::Handle(), kPos); |
| cls.SetFields(Array::Handle(Array::Empty())); |
| cls.SetFunctions(Array::Handle(Array::Empty())); |
| // Set super class to Object. |
| @@ -1306,6 +1323,12 @@ |
| } |
| +void Class::set_token_index(intptr_t token_index) const { |
| + ASSERT(token_index >= 0); |
| + raw_ptr()->token_index_ = token_index; |
| +} |
| + |
| + |
| void Class::set_is_interface() const { |
| raw_ptr()->is_interface_ = true; |
| } |
| @@ -1756,13 +1779,13 @@ |
| } |
| -RawUnresolvedClass* UnresolvedClass::New(intptr_t token_index, |
| - const LibraryPrefix& library_prefix, |
| - const String& ident) { |
| +RawUnresolvedClass* UnresolvedClass::New(const LibraryPrefix& library_prefix, |
| + const String& ident, |
| + intptr_t token_index) { |
| const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New()); |
| - type.set_token_index(token_index); |
| type.set_library_prefix(library_prefix); |
| type.set_ident(ident); |
| + type.set_token_index(token_index); |
| return type.raw(); |
| } |
| @@ -1778,6 +1801,7 @@ |
| void UnresolvedClass::set_token_index(intptr_t token_index) const { |
| + ASSERT(token_index >= 0); |
| raw_ptr()->token_index_ = token_index; |
| } |
| @@ -1855,6 +1879,13 @@ |
| } |
| +intptr_t AbstractType::token_index() const { |
| + // AbstractType is an abstract class. |
| + UNREACHABLE(); |
| + return -1; |
| +} |
| + |
| + |
| bool AbstractType::IsInstantiated() const { |
| // AbstractType is an abstract class. |
| UNREACHABLE(); |
| @@ -2071,8 +2102,8 @@ |
| } |
| RawAbstractType* AbstractType::NewTypeParameter( |
| - intptr_t index, const String& name) { |
| - return TypeParameter::New(index, name); |
| + intptr_t index, const String& name, intptr_t token_index) { |
| + return TypeParameter::New(index, name, token_index); |
| } |
| @@ -2146,10 +2177,10 @@ |
| } |
| -RawType* Type::NewRawType(const Class& type_class) { |
| +RawType* Type::NewRawType(const Class& type_class, intptr_t token_index) { |
| const AbstractTypeArguments& type_arguments = |
| AbstractTypeArguments::Handle(type_class.type_parameter_extends()); |
| - return New(Object::Handle(type_class.raw()), type_arguments); |
| + return New(Object::Handle(type_class.raw()), type_arguments, token_index); |
| } |
| @@ -2157,9 +2188,9 @@ |
| const Class& type_class) { |
| ASSERT(!type_class.HasTypeArguments()); |
| const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
| Type& type = Type::Handle(); |
| - type ^= Type::New( |
| - Object::Handle(type_class.raw()), no_type_arguments); |
| + type ^= Type::New(Object::Handle(type_class.raw()), no_type_arguments, kPos); |
| type.set_is_finalized(); |
| type ^= type.Canonicalize(); |
| return type.raw(); |
| @@ -2235,7 +2266,8 @@ |
| type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); |
| const Class& cls = Class::Handle(type_class()); |
| ASSERT(cls.is_finalized()); |
| - Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); |
| + Type& instantiated_type = Type::Handle( |
| + Type::New(cls, type_arguments, token_index())); |
| ASSERT(type_arguments.IsNull() || |
| (type_arguments.Length() == cls.NumTypeArguments())); |
| instantiated_type.set_is_finalized(); |
| @@ -2331,15 +2363,23 @@ |
| RawType* Type::New(const Object& clazz, |
| - const AbstractTypeArguments& arguments) { |
| + const AbstractTypeArguments& arguments, |
| + intptr_t token_index) { |
| const Type& result = Type::Handle(Type::New()); |
| result.set_type_class(clazz); |
| result.set_arguments(arguments); |
| + result.set_token_index(token_index); |
| result.raw_ptr()->type_state_ = RawType::kAllocated; |
| return result.raw(); |
| } |
| +void Type::set_token_index(intptr_t token_index) const { |
| + ASSERT(token_index >= 0); |
| + raw_ptr()->token_index_ = token_index; |
| +} |
| + |
| + |
| void Type::set_type_state(int8_t state) const { |
| ASSERT(state == RawType::kAllocated || |
| state == RawType::kBeingFinalized || |
| @@ -2430,15 +2470,23 @@ |
| } |
| -RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { |
| +RawTypeParameter* TypeParameter::New( |
| + intptr_t index, const String& name, intptr_t token_index) { |
| const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); |
| result.set_index(index); |
| result.set_name(name); |
| + result.set_token_index(token_index); |
| result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; |
| return result.raw(); |
| } |
| +void TypeParameter::set_token_index(intptr_t token_index) const { |
| + ASSERT(token_index >= 0); |
| + raw_ptr()->token_index_ = token_index; |
| +} |
| + |
| + |
| void TypeParameter::set_type_state(int8_t state) const { |
| ASSERT(state == RawTypeParameter::kAllocated || |
| state == RawTypeParameter::kBeingFinalized || |
| @@ -2471,6 +2519,11 @@ |
| } |
| +intptr_t InstantiatedType::token_index() const { |
| + return AbstractType::Handle(uninstantiated_type()).token_index(); |
| +} |
| + |
| + |
| void InstantiatedType::set_uninstantiated_type( |
| const AbstractType& value) const { |
| StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); |
| @@ -3406,11 +3459,7 @@ |
| } |
| const Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| if (!signature_type.IsFinalized()) { |
| - Error& error = Error::Handle(); |
| - ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| - signature_type, |
| - &error); |
| - ASSERT(error.IsNull()); |
| + ClassFinalizer::FinalizeType(signature_class, signature_type); |
| } |
| ASSERT(closure_function.signature_class() == signature_class.raw()); |
| set_implicit_closure_function(closure_function); |
| @@ -5517,7 +5566,8 @@ |
| if (cls.HasTypeArguments()) { |
| type_arguments = GetTypeArguments(); |
| } |
| - const Type& type = Type::Handle(Type::New(cls, type_arguments)); |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
| + const Type& type = Type::Handle(Type::New(cls, type_arguments, kPos)); |
| type.set_is_finalized(); |
| return type.raw(); |
| } |
| @@ -5658,7 +5708,8 @@ |
| if (num_type_arguments > 0) { |
| type_arguments = GetTypeArguments(); |
| } |
| - const Type& type = Type::Handle(Type::New(cls, type_arguments)); |
| + const intptr_t kPos = 0; // Dummy token index for unspecified position. |
| + const Type& type = Type::Handle(Type::New(cls, type_arguments, kPos)); |
| const String& type_name = String::Handle(type.Name()); |
| // Calculate the size of the string. |
| intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; |