Chromium Code Reviews| 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/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/port.h" | 10 #include "vm/port.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 UNREACHABLE(); | 37 UNREACHABLE(); |
| 38 } | 38 } |
| 39 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); | 39 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); |
| 40 Integer& id = Integer::Handle(); | 40 Integer& id = Integer::Handle(); |
| 41 id ^= id_obj.raw(); | 41 id ^= id_obj.raw(); |
| 42 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); | 42 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); |
| 43 return Bool::Get(PortMap::IsLocalPort(port_id)); | 43 return Bool::Get(PortMap::IsLocalPort(port_id)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 static RawInstance* CreateParameterMirrorList(const Function& func) { | 47 static RawInstance* CreateParameterMirrorList(const Function& func, |
| 48 const Instance& owner_mirror) { | |
| 48 HANDLESCOPE(Isolate::Current()); | 49 HANDLESCOPE(Isolate::Current()); |
| 49 const intptr_t param_cnt = func.num_fixed_parameters() - | 50 const intptr_t param_cnt = func.NumParameters() - |
| 50 func.NumImplicitParameters() + | 51 func.NumImplicitParameters(); |
| 51 func.NumOptionalParameters(); | 52 const intptr_t implicit_cnt = func.NumImplicitParameters(); |
| 53 const intptr_t first_optional = func.num_fixed_parameters() - | |
| 54 func.NumImplicitParameters(); | |
| 55 const intptr_t first_named = func.NumParameters() - | |
| 56 func.NumImplicitParameters() - | |
| 57 func.NumOptionalNamedParameters(); | |
|
siva
2013/08/06 23:54:54
I would probably write this code as follows to mak
Michael Lippautz (Google)
2013/08/07 00:21:42
Done.
| |
| 52 const Array& results = Array::Handle(Array::New(param_cnt)); | 58 const Array& results = Array::Handle(Array::New(param_cnt)); |
| 53 const Array& args = Array::Handle(Array::New(3)); | 59 const Array& args = Array::Handle(Array::New(6)); |
| 54 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 61 args.SetAt(2, owner_mirror); | |
| 55 Smi& pos = Smi::Handle(); | 62 Smi& pos = Smi::Handle(); |
| 56 Instance& param = Instance::Handle(); | 63 Instance& param = Instance::Handle(); |
| 57 for (intptr_t i = 0; i < param_cnt; i++) { | 64 for (intptr_t i = 0; i < param_cnt; i++) { |
| 58 pos ^= Smi::New(i); | 65 pos ^= Smi::New(i); |
| 59 args.SetAt(1, pos); | 66 args.SetAt(1, String::Handle(func.ParameterNameAt(implicit_cnt + i))); |
|
siva
2013/08/06 23:54:54
String::Handle() should be hoisted out of the loop
Michael Lippautz (Google)
2013/08/07 00:21:42
Done.
| |
| 60 args.SetAt(2, (i >= func.num_fixed_parameters()) ? | 67 args.SetAt(3, pos); |
| 61 Bool::True() : Bool::False()); | 68 args.SetAt(4, (i >= first_optional) ? Bool::True() : Bool::False()); |
| 69 args.SetAt(5, (i >= first_named) ? Bool::True() : Bool::False()); | |
| 62 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | 70 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
| 63 results.SetAt(i, param); | 71 results.SetAt(i, param); |
| 64 } | 72 } |
| 65 results.MakeImmutable(); | 73 results.MakeImmutable(); |
| 66 return results.raw(); | 74 return results.raw(); |
| 67 } | 75 } |
| 68 | 76 |
| 69 | 77 |
| 70 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, | 78 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
| 71 const Instance& owner_mirror) { | 79 const Instance& owner_mirror) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 324 } |
| 317 | 325 |
| 318 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 326 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 319 if (metadata.IsError()) { | 327 if (metadata.IsError()) { |
| 320 ThrowInvokeError(Error::Cast(metadata)); | 328 ThrowInvokeError(Error::Cast(metadata)); |
| 321 } | 329 } |
| 322 return metadata.raw(); | 330 return metadata.raw(); |
| 323 } | 331 } |
| 324 | 332 |
| 325 | 333 |
| 326 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) { |
| 327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 335 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); |
| 336 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | |
| 328 const Class& cls = Class::Handle(ref.GetClassReferent()); | 337 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 329 const Function& func = Function::Handle(cls.signature_function()); | 338 const Function& func = Function::Handle(cls.signature_function()); |
| 330 return CreateParameterMirrorList(func); | 339 return CreateParameterMirrorList(func, owner); |
| 331 } | 340 } |
| 332 | 341 |
| 333 | 342 |
| 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 343 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 344 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 336 const Class& cls = Class::Handle(ref.GetClassReferent()); | 345 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 337 const Function& func = Function::Handle(cls.signature_function()); | 346 const Function& func = Function::Handle(cls.signature_function()); |
| 338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 347 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 339 return CreateTypeMirror(return_type); | 348 return CreateTypeMirror(return_type); |
| 340 } | 349 } |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 func.parent_function()), Object::null_instance()); | 1151 func.parent_function()), Object::null_instance()); |
| 1143 } | 1152 } |
| 1144 const Class& owner = Class::Handle(func.Owner()); | 1153 const Class& owner = Class::Handle(func.Owner()); |
| 1145 if (owner.IsTopLevel()) { | 1154 if (owner.IsTopLevel()) { |
| 1146 return CreateLibraryMirror(Library::Handle(owner.library())); | 1155 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1147 } | 1156 } |
| 1148 return CreateClassMirror(owner, Object::null_instance()); | 1157 return CreateClassMirror(owner, Object::null_instance()); |
| 1149 } | 1158 } |
| 1150 | 1159 |
| 1151 | 1160 |
| 1152 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { | 1161 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { |
| 1153 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1162 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); |
| 1163 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | |
| 1154 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1164 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1155 return CreateParameterMirrorList(func); | 1165 return CreateParameterMirrorList(func, owner); |
| 1156 } | 1166 } |
| 1157 | 1167 |
| 1158 | 1168 |
| 1159 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1169 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1160 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1170 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1161 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1171 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1162 // We handle constructors in Dart code. | 1172 // We handle constructors in Dart code. |
| 1163 ASSERT(!func.IsConstructor()); | 1173 ASSERT(!func.IsConstructor()); |
| 1164 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1174 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1165 return CreateTypeMirror(return_type); | 1175 return CreateTypeMirror(return_type); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1187 | 1197 |
| 1188 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1198 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1189 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1199 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1190 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1200 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1191 | 1201 |
| 1192 const AbstractType& type = AbstractType::Handle(field.type()); | 1202 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1193 return CreateTypeMirror(type); | 1203 return CreateTypeMirror(type); |
| 1194 } | 1204 } |
| 1195 | 1205 |
| 1196 } // namespace dart | 1206 } // namespace dart |
| OLD | NEW |