| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // Get the port id from the SendPort instance. | 34 // Get the port id from the SendPort instance. |
| 35 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); | 35 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); |
| 36 if (id_obj.IsError()) { | 36 if (id_obj.IsError()) { |
| 37 Exceptions::PropagateError(Error::Cast(id_obj)); | 37 Exceptions::PropagateError(Error::Cast(id_obj)); |
| 38 UNREACHABLE(); | 38 UNREACHABLE(); |
| 39 } | 39 } |
| 40 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); | 40 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); |
| 41 Integer& id = Integer::Handle(); | 41 Integer& id = Integer::Handle(); |
| 42 id ^= id_obj.raw(); | 42 id ^= id_obj.raw(); |
| 43 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); | 43 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); |
| 44 return Bool::Get(PortMap::IsLocalPort(port_id)); | 44 return Bool::Get(PortMap::IsLocalPort(port_id)).raw(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 static RawInstance* CreateParameterMirrorList(const Function& func, | 48 static RawInstance* CreateParameterMirrorList(const Function& func, |
| 49 const Instance& owner_mirror) { | 49 const Instance& owner_mirror) { |
| 50 HANDLESCOPE(Isolate::Current()); | 50 HANDLESCOPE(Isolate::Current()); |
| 51 const intptr_t implicit_param_count = func.NumImplicitParameters(); | 51 const intptr_t implicit_param_count = func.NumImplicitParameters(); |
| 52 const intptr_t non_implicit_param_count = func.NumParameters() - | 52 const intptr_t non_implicit_param_count = func.NumParameters() - |
| 53 implicit_param_count; | 53 implicit_param_count; |
| 54 const intptr_t index_of_first_optional_param = | 54 const intptr_t index_of_first_optional_param = |
| 55 non_implicit_param_count - func.NumOptionalParameters(); | 55 non_implicit_param_count - func.NumOptionalParameters(); |
| 56 const intptr_t index_of_first_named_param = | 56 const intptr_t index_of_first_named_param = |
| 57 non_implicit_param_count - func.NumOptionalNamedParameters(); | 57 non_implicit_param_count - func.NumOptionalNamedParameters(); |
| 58 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); | 58 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); |
| 59 const Array& args = Array::Handle(Array::New(6)); | 59 const Array& args = Array::Handle(Array::New(6)); |
| 60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 61 args.SetAt(2, owner_mirror); | 61 args.SetAt(2, owner_mirror); |
| 62 Smi& pos = Smi::Handle(); | 62 Smi& pos = Smi::Handle(); |
| 63 String& name = String::Handle(); | 63 String& name = String::Handle(); |
| 64 Instance& param = Instance::Handle(); | 64 Instance& param = Instance::Handle(); |
| 65 for (intptr_t i = 0; i < non_implicit_param_count; i++) { | 65 for (intptr_t i = 0; i < non_implicit_param_count; i++) { |
| 66 pos ^= Smi::New(i); | 66 pos ^= Smi::New(i); |
| 67 name ^= func.ParameterNameAt(implicit_param_count + i); | 67 name ^= func.ParameterNameAt(implicit_param_count + i); |
| 68 args.SetAt(1, name); | 68 args.SetAt(1, name); |
| 69 args.SetAt(3, pos); | 69 args.SetAt(3, pos); |
| 70 args.SetAt(4, (i >= index_of_first_optional_param) ? | 70 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param)); |
| 71 Bool::True() : Bool::False()); | 71 args.SetAt(5, Bool::Get(i >= index_of_first_named_param)); |
| 72 args.SetAt(5, (i >= index_of_first_named_param) ? | |
| 73 Bool::True() : Bool::False()); | |
| 74 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | 72 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
| 75 results.SetAt(i, param); | 73 results.SetAt(i, param); |
| 76 } | 74 } |
| 77 results.MakeImmutable(); | 75 results.MakeImmutable(); |
| 78 return results.raw(); | 76 return results.raw(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 | 79 |
| 82 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, | 80 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
| 83 const Instance& owner_mirror) { | 81 const Instance& owner_mirror) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 126 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
| 129 } | 127 } |
| 130 | 128 |
| 131 | 129 |
| 132 static RawInstance* CreateMethodMirror(const Function& func, | 130 static RawInstance* CreateMethodMirror(const Function& func, |
| 133 const Instance& owner_mirror) { | 131 const Instance& owner_mirror) { |
| 134 const Array& args = Array::Handle(Array::New(12)); | 132 const Array& args = Array::Handle(Array::New(12)); |
| 135 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 133 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 136 args.SetAt(1, String::Handle(func.UserVisibleName())); | 134 args.SetAt(1, String::Handle(func.UserVisibleName())); |
| 137 args.SetAt(2, owner_mirror); | 135 args.SetAt(2, owner_mirror); |
| 138 args.SetAt(3, func.is_static() ? Bool::True() : Bool::False()); | 136 args.SetAt(3, Bool::Get(func.is_static())); |
| 139 args.SetAt(4, func.is_abstract() ? Bool::True() : Bool::False()); | 137 args.SetAt(4, Bool::Get(func.is_abstract())); |
| 140 args.SetAt(5, func.IsGetterFunction() ? Bool::True() : Bool::False()); | 138 args.SetAt(5, Bool::Get(func.IsGetterFunction())); |
| 141 args.SetAt(6, func.IsSetterFunction() ? Bool::True() : Bool::False()); | 139 args.SetAt(6, Bool::Get(func.IsSetterFunction())); |
| 142 args.SetAt(7, func.IsConstructor() ? Bool::True() : Bool::False()); | 140 args.SetAt(7, Bool::Get(func.IsConstructor())); |
| 143 // TODO(mlippautz): Implement different constructor kinds. | 141 // TODO(mlippautz): Implement different constructor kinds. |
| 144 args.SetAt(8, Bool::False()); | 142 args.SetAt(8, Bool::False()); |
| 145 args.SetAt(9, Bool::False()); | 143 args.SetAt(9, Bool::False()); |
| 146 args.SetAt(10, Bool::False()); | 144 args.SetAt(10, Bool::False()); |
| 147 args.SetAt(11, Bool::False()); | 145 args.SetAt(11, Bool::False()); |
| 148 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); | 146 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); |
| 149 } | 147 } |
| 150 | 148 |
| 151 | 149 |
| 152 static RawInstance* CreateVariableMirror(const Field& field, | 150 static RawInstance* CreateVariableMirror(const Field& field, |
| 153 const Instance& owner_mirror) { | 151 const Instance& owner_mirror) { |
| 154 const MirrorReference& field_ref = | 152 const MirrorReference& field_ref = |
| 155 MirrorReference::Handle(MirrorReference::New(field)); | 153 MirrorReference::Handle(MirrorReference::New(field)); |
| 156 | 154 |
| 157 const String& name = String::Handle(field.UserVisibleName()); | 155 const String& name = String::Handle(field.UserVisibleName()); |
| 158 | 156 |
| 159 const Array& args = Array::Handle(Array::New(6)); | 157 const Array& args = Array::Handle(Array::New(6)); |
| 160 args.SetAt(0, field_ref); | 158 args.SetAt(0, field_ref); |
| 161 args.SetAt(1, name); | 159 args.SetAt(1, name); |
| 162 args.SetAt(2, owner_mirror); | 160 args.SetAt(2, owner_mirror); |
| 163 args.SetAt(3, Instance::Handle()); // Null for type. | 161 args.SetAt(3, Instance::Handle()); // Null for type. |
| 164 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 162 args.SetAt(4, Bool::Get(field.is_static())); |
| 165 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 163 args.SetAt(5, Bool::Get(field.is_final())); |
| 166 | 164 |
| 167 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 165 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 168 } | 166 } |
| 169 | 167 |
| 170 static RawFunction* CallMethod(const Class& cls) { | 168 static RawFunction* CallMethod(const Class& cls) { |
| 171 if (cls.IsSignatureClass()) { | 169 if (cls.IsSignatureClass()) { |
| 172 return cls.signature_function(); | 170 return cls.signature_function(); |
| 173 } | 171 } |
| 174 | 172 |
| 175 Class& lookup_cls = Class::Handle(cls.raw()); | 173 Class& lookup_cls = Class::Handle(cls.raw()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 192 if (cls.IsSignatureClass()) { | 190 if (cls.IsSignatureClass()) { |
| 193 if (cls.IsCanonicalSignatureClass()) { | 191 if (cls.IsCanonicalSignatureClass()) { |
| 194 // We represent function types as canonical signature classes. | 192 // We represent function types as canonical signature classes. |
| 195 return CreateFunctionTypeMirror(cls, type); | 193 return CreateFunctionTypeMirror(cls, type); |
| 196 } else { | 194 } else { |
| 197 // We represent typedefs as non-canonical signature classes. | 195 // We represent typedefs as non-canonical signature classes. |
| 198 return CreateTypedefMirror(cls, owner_mirror); | 196 return CreateTypedefMirror(cls, owner_mirror); |
| 199 } | 197 } |
| 200 } | 198 } |
| 201 | 199 |
| 202 const Bool& is_generic = | 200 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
| 203 (cls.NumTypeParameters() == 0) ? Bool::False() : Bool::True(); | |
| 204 | 201 |
| 205 const Array& args = Array::Handle(Array::New(4)); | 202 const Array& args = Array::Handle(Array::New(4)); |
| 206 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 203 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 207 args.SetAt(1, type); | 204 args.SetAt(1, type); |
| 208 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 205 args.SetAt(2, String::Handle(cls.UserVisibleName())); |
| 209 args.SetAt(3, is_generic); | 206 args.SetAt(3, is_generic); |
| 210 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 207 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 211 } | 208 } |
| 212 | 209 |
| 213 | 210 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 UNREACHABLE(); | 347 UNREACHABLE(); |
| 351 } | 348 } |
| 352 Exceptions::PropagateError(error); | 349 Exceptions::PropagateError(error); |
| 353 UNREACHABLE(); | 350 UNREACHABLE(); |
| 354 } | 351 } |
| 355 | 352 |
| 356 | 353 |
| 357 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 354 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
| 358 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 355 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
| 359 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 356 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
| 360 return Bool::Get(a.referent() == b.referent()); | 357 return Bool::Get(a.referent() == b.referent()).raw(); |
| 361 } | 358 } |
| 362 | 359 |
| 363 | 360 |
| 364 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 361 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
| 365 const MirrorReference& decl_ref = | 362 const MirrorReference& decl_ref = |
| 366 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 363 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 367 const Object& decl = Object::Handle(decl_ref.referent()); | 364 const Object& decl = Object::Handle(decl_ref.referent()); |
| 368 | 365 |
| 369 Class& klass = Class::Handle(); | 366 Class& klass = Class::Handle(); |
| 370 Library& library = Library::Handle(); | 367 Library& library = Library::Handle(); |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 } | 1335 } |
| 1339 | 1336 |
| 1340 | 1337 |
| 1341 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1338 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1342 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1339 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1343 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1340 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1344 return field.type(); | 1341 return field.type(); |
| 1345 } | 1342 } |
| 1346 | 1343 |
| 1347 } // namespace dart | 1344 } // namespace dart |
| OLD | NEW |