Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Unified Diff: runtime/lib/mirrors.cc

Issue 23020025: Implement ParameterMirror.{isFinal,hasDefaultValue,defaultValue}. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors.cc
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
index e0c8b2327c4e75efe5ff64fc4e49c3e10a4ee74f..01eb32907b9a66c641d683b4964021cb69539d4a 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.
Michael Lippautz (Google) 2013/08/21 20:37:36 Moving the throw stuff to the top of the file, sin
+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);
+ }
+ 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(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);
+ 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.value() ? Bool::True() : Bool::False());
rmacnak 2013/08/23 23:15:27 is_final is already a handle, so you can pass it t
Michael Lippautz (Google) 2013/08/24 00:17:21 Done.
+ 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
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698