Index: runtime/lib/mirrors.cc |
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
index e0c8b2327c4e75efe5ff64fc4e49c3e10a4ee74f..02f53396144001fff18a1f6851a25edb4622cb52 100644 |
--- a/runtime/lib/mirrors.cc |
+++ b/runtime/lib/mirrors.cc |
@@ -8,6 +8,7 @@ |
#include "vm/dart_entry.h" |
#include "vm/exceptions.h" |
#include "vm/object_store.h" |
+#include "vm/parser.h" |
#include "vm/port.h" |
#include "vm/symbols.h" |
@@ -28,6 +29,95 @@ static RawInstance* CreateMirror(const String& mirror_class_name, |
} |
+// Note a "raw type" is not the same as a RawType. |
+static RawAbstractType* RawTypeOfClass(const Class& cls) { |
+ Type& type = Type::Handle(Type::New(cls, |
+ Object::null_abstract_type_arguments(), |
+ Scanner::kDummyTokenIndex)); |
+ return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); |
+} |
+ |
+ |
+static void ThrowMirroredCompilationError(const String& message) { |
+ Array& args = Array::Handle(Array::New(1)); |
+ args.SetAt(0, message); |
+ |
+ Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
+ UNREACHABLE(); |
+} |
+ |
+ |
+static void ThrowInvokeError(const Error& error) { |
+ if (error.IsLanguageError()) { |
+ // A compilation error that was delayed by lazy compilation. |
+ const LanguageError& compilation_error = LanguageError::Cast(error); |
+ String& message = String::Handle(compilation_error.message()); |
+ ThrowMirroredCompilationError(message); |
+ UNREACHABLE(); |
+ } |
+ Exceptions::PropagateError(error); |
+ UNREACHABLE(); |
+} |
+ |
+ |
+static void ThrowNoSuchMethod(const Instance& receiver, |
+ const String& function_name, |
+ const Function& function, |
+ const InvocationMirror::Call call, |
+ const InvocationMirror::Type type) { |
+ const Smi& invocation_type = Smi::Handle(Smi::New( |
+ InvocationMirror::EncodeType(call, type))); |
+ |
+ const Array& args = Array::Handle(Array::New(6)); |
+ args.SetAt(0, receiver); |
+ args.SetAt(1, function_name); |
+ args.SetAt(2, invocation_type); |
+ if (!function.IsNull()) { |
+ const int total_num_parameters = function.NumParameters(); |
+ const Array& array = Array::Handle(Array::New(total_num_parameters)); |
+ String& param_name = String::Handle(); |
+ for (int i = 0; i < total_num_parameters; i++) { |
+ param_name = function.ParameterNameAt(i); |
+ array.SetAt(i, param_name); |
+ } |
siva
2013/08/26 05:05:43
What about args 3 and 4, you should document those
Michael Lippautz (Google)
2013/08/26 19:45:57
Done.
|
+ args.SetAt(5, array); |
+ } |
+ |
+ Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); |
+ UNREACHABLE(); |
+} |
+ |
+ |
+static void ThrowNoSuchMethod(const Class& klass, |
+ const String& function_name, |
+ const Function& function, |
+ const InvocationMirror::Call call, |
+ const InvocationMirror::Type type) { |
+ AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass)); |
+ |
+ ThrowNoSuchMethod(runtime_type, |
+ function_name, |
+ function, |
+ call, |
+ type); |
+ UNREACHABLE(); |
+} |
+ |
+ |
+static void ThrowNoSuchMethod(const Library& library, |
+ const String& function_name, |
+ const Function& function, |
+ const InvocationMirror::Call call, |
+ const InvocationMirror::Type type) { |
+ ThrowNoSuchMethod(Instance::null_instance(), |
+ function_name, |
+ function, |
+ call, |
+ type); |
+ UNREACHABLE(); |
+} |
siva
2013/08/26 05:05:43
Not sure if it is worth having so many overloaded
Michael Lippautz (Google)
2013/08/26 19:45:57
Done.
|
+ |
+ |
DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { |
GET_NON_NULL_NATIVE_ARGUMENT(Instance, port, arguments->NativeArgAt(0)); |
@@ -56,21 +146,51 @@ static RawInstance* CreateParameterMirrorList(const Function& func, |
const intptr_t index_of_first_named_param = |
non_implicit_param_count - func.NumOptionalNamedParameters(); |
const Array& results = Array::Handle(Array::New(non_implicit_param_count)); |
- const Array& args = Array::Handle(Array::New(6)); |
+ const Array& args = Array::Handle(Array::New(8)); |
+ |
+ // Return for synthetic functions and getters. |
+ if (func.IsGetterFunction() || |
+ func.IsImplicitConstructor() || |
+ func.IsImplicitGetterFunction() || |
+ func.IsImplicitSetterFunction()) { |
+ return results.raw(); |
+ } |
+ |
args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
args.SetAt(2, owner_mirror); |
+ |
Smi& pos = Smi::Handle(); |
String& name = String::Handle(); |
Instance& param = Instance::Handle(); |
+ Bool& is_final = Bool::Handle(); |
+ Object& default_value = Object::Handle(); |
+ |
+ // Reparse the function for the following information: |
+ // * The default value of a parameter. |
+ // * Whether a parameters has been deflared as final. |
+ const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); |
+ if (result.IsError()) { |
+ ThrowInvokeError(Error::Cast(result)); |
+ UNREACHABLE(); |
+ } |
+ |
+ const Array& param_descriptor = Array::Cast(result); |
siva
2013/08/26 05:05:43
We normally use the Cast operator only after an if
Michael Lippautz (Google)
2013/08/26 19:45:57
result is either an error (which checked above) or
siva
2013/08/27 00:31:02
Ok.
On 2013/08/26 19:45:57, Michael Lippautz wrot
|
+ ASSERT(param_descriptor.Length() == (2 * non_implicit_param_count)); |
for (intptr_t i = 0; i < non_implicit_param_count; i++) { |
pos ^= Smi::New(i); |
name ^= func.ParameterNameAt(implicit_param_count + i); |
+ is_final ^= param_descriptor.At(i * 2); |
+ default_value = param_descriptor.At(i * 2 + 1); |
+ ASSERT(default_value.IsNull() || default_value.IsInstance()); |
+ |
args.SetAt(1, name); |
args.SetAt(3, pos); |
args.SetAt(4, (i >= index_of_first_optional_param) ? |
Bool::True() : Bool::False()); |
args.SetAt(5, (i >= index_of_first_named_param) ? |
Bool::True() : Bool::False()); |
+ args.SetAt(6, is_final); |
+ args.SetAt(7, default_value); |
param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
results.SetAt(i, param); |
} |
@@ -209,15 +329,6 @@ static RawInstance* CreateClassMirror(const Class& cls, |
} |
-// Note a "raw type" is not the same as a RawType. |
-static RawAbstractType* RawTypeOfClass(const Class& cls) { |
- Type& type = Type::Handle(Type::New(cls, |
- Object::null_abstract_type_arguments(), |
- Scanner::kDummyTokenIndex)); |
- return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); |
-} |
- |
- |
static RawInstance* CreateLibraryMirror(const Library& lib) { |
const Array& args = Array::Handle(Array::New(3)); |
args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
@@ -324,28 +435,6 @@ DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
} |
-static void ThrowMirroredCompilationError(const String& message) { |
- Array& args = Array::Handle(Array::New(1)); |
- args.SetAt(0, message); |
- |
- Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
- UNREACHABLE(); |
-} |
- |
- |
-static void ThrowInvokeError(const Error& error) { |
- if (error.IsLanguageError()) { |
- // A compilation error that was delayed by lazy compilation. |
- const LanguageError& compilation_error = LanguageError::Cast(error); |
- String& message = String::Handle(compilation_error.message()); |
- ThrowMirroredCompilationError(message); |
- UNREACHABLE(); |
- } |
- Exceptions::PropagateError(error); |
- UNREACHABLE(); |
-} |
- |
- |
DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
@@ -841,64 +930,6 @@ DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { |
} |
-static void ThrowNoSuchMethod(const Instance& receiver, |
- const String& function_name, |
- const Function& function, |
- const InvocationMirror::Call call, |
- const InvocationMirror::Type type) { |
- const Smi& invocation_type = Smi::Handle(Smi::New( |
- InvocationMirror::EncodeType(call, type))); |
- |
- const Array& args = Array::Handle(Array::New(6)); |
- args.SetAt(0, receiver); |
- args.SetAt(1, function_name); |
- args.SetAt(2, invocation_type); |
- if (!function.IsNull()) { |
- const int total_num_parameters = function.NumParameters(); |
- const Array& array = Array::Handle(Array::New(total_num_parameters)); |
- String& param_name = String::Handle(); |
- for (int i = 0; i < total_num_parameters; i++) { |
- param_name = function.ParameterNameAt(i); |
- array.SetAt(i, param_name); |
- } |
- args.SetAt(5, array); |
- } |
- |
- Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); |
- UNREACHABLE(); |
-} |
- |
- |
-static void ThrowNoSuchMethod(const Class& klass, |
- const String& function_name, |
- const Function& function, |
- const InvocationMirror::Call call, |
- const InvocationMirror::Type type) { |
- AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass)); |
- |
- ThrowNoSuchMethod(runtime_type, |
- function_name, |
- function, |
- call, |
- type); |
- UNREACHABLE(); |
-} |
- |
- |
-static void ThrowNoSuchMethod(const Library& library, |
- const String& function_name, |
- const Function& function, |
- const InvocationMirror::Call call, |
- const InvocationMirror::Type type) { |
- ThrowNoSuchMethod(Instance::null_instance(), |
- function_name, |
- function, |
- call, |
- type); |
- UNREACHABLE(); |
-} |
- |
- |
DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { |
// Argument 0 is the mirror, which is unused by the native. It exists |
// because this native is an instance method in order to be polymorphic |