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(); | |
| 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))); |
| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 320 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 313 if (metadata.IsError()) { | 321 if (metadata.IsError()) { |
| 314 ThrowInvokeError(Error::Cast(metadata)); | 322 ThrowInvokeError(Error::Cast(metadata)); |
| 315 } | 323 } |
| 316 return metadata.raw(); | 324 return metadata.raw(); |
| 317 } | 325 } |
| 318 | 326 |
| 319 | 327 |
| 320 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 328 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { |
| 321 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 329 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 330 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(1)); | |
|
rmacnak
2013/08/02 00:50:19
Flip the order of the arguments and make this an i
Michael Lippautz (Google)
2013/08/02 17:05:44
Done.
| |
| 322 const Class& cls = Class::Handle(ref.GetClassReferent()); | 331 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 323 const Function& func = Function::Handle(cls.signature_function()); | 332 const Function& func = Function::Handle(cls.signature_function()); |
| 324 return CreateParameterMirrorList(func); | 333 return CreateParameterMirrorList(func, owner); |
| 325 } | 334 } |
| 326 | 335 |
| 327 | 336 |
| 328 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 337 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 329 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 338 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 330 const Class& cls = Class::Handle(ref.GetClassReferent()); | 339 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 331 const Function& func = Function::Handle(cls.signature_function()); | 340 const Function& func = Function::Handle(cls.signature_function()); |
| 332 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 341 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 333 return CreateTypeMirror(return_type); | 342 return CreateTypeMirror(return_type); |
| 334 } | 343 } |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 const Class& owner = Class::Handle(func.Owner()); | 1147 const Class& owner = Class::Handle(func.Owner()); |
| 1139 if (owner.IsTopLevel()) { | 1148 if (owner.IsTopLevel()) { |
| 1140 return CreateLibraryMirror(Library::Handle(owner.library())); | 1149 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1141 } | 1150 } |
| 1142 return CreateClassMirror(owner, Object::null_instance()); | 1151 return CreateClassMirror(owner, Object::null_instance()); |
| 1143 } | 1152 } |
| 1144 | 1153 |
| 1145 | 1154 |
| 1146 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { | 1155 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { |
| 1147 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1156 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1157 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(1)); | |
|
rmacnak
2013/08/02 00:50:19
As above.
Michael Lippautz (Google)
2013/08/02 17:05:44
Done.
| |
| 1148 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1158 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1149 return CreateParameterMirrorList(func); | 1159 return CreateParameterMirrorList(func, owner); |
| 1150 } | 1160 } |
| 1151 | 1161 |
| 1152 | 1162 |
| 1153 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1163 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1154 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1164 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1155 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1165 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1156 // We handle constructors in Dart code. | 1166 // We handle constructors in Dart code. |
| 1157 ASSERT(!func.IsConstructor()); | 1167 ASSERT(!func.IsConstructor()); |
| 1158 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1168 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1159 return CreateTypeMirror(return_type); | 1169 return CreateTypeMirror(return_type); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1181 | 1191 |
| 1182 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1192 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1183 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1193 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1184 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1194 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1185 | 1195 |
| 1186 const AbstractType& type = AbstractType::Handle(field.type()); | 1196 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1187 return CreateTypeMirror(type); | 1197 return CreateTypeMirror(type); |
| 1188 } | 1198 } |
| 1189 | 1199 |
| 1190 } // namespace dart | 1200 } // namespace dart |
| OLD | NEW |