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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 23224016: Implement ParameterMirror.metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const Instance& owner_mirror) { 118 const Instance& owner_mirror) {
119 HANDLESCOPE(Isolate::Current()); 119 HANDLESCOPE(Isolate::Current());
120 const intptr_t implicit_param_count = func.NumImplicitParameters(); 120 const intptr_t implicit_param_count = func.NumImplicitParameters();
121 const intptr_t non_implicit_param_count = func.NumParameters() - 121 const intptr_t non_implicit_param_count = func.NumParameters() -
122 implicit_param_count; 122 implicit_param_count;
123 const intptr_t index_of_first_optional_param = 123 const intptr_t index_of_first_optional_param =
124 non_implicit_param_count - func.NumOptionalParameters(); 124 non_implicit_param_count - func.NumOptionalParameters();
125 const intptr_t index_of_first_named_param = 125 const intptr_t index_of_first_named_param =
126 non_implicit_param_count - func.NumOptionalNamedParameters(); 126 non_implicit_param_count - func.NumOptionalNamedParameters();
127 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); 127 const Array& results = Array::Handle(Array::New(non_implicit_param_count));
128 const Array& args = Array::Handle(Array::New(8)); 128 const Array& args = Array::Handle(Array::New(9));
129 129
130 // Return for synthetic functions and getters. 130 // Return for synthetic functions and getters.
131 if (func.IsGetterFunction() || 131 if (func.IsGetterFunction() ||
132 func.IsImplicitConstructor() || 132 func.IsImplicitConstructor() ||
133 func.IsImplicitGetterFunction() || 133 func.IsImplicitGetterFunction() ||
134 func.IsImplicitSetterFunction()) { 134 func.IsImplicitSetterFunction()) {
135 return results.raw(); 135 return results.raw();
136 } 136 }
137 137
138 Smi& pos = Smi::Handle(); 138 Smi& pos = Smi::Handle();
139 String& name = String::Handle(); 139 String& name = String::Handle();
140 Instance& param = Instance::Handle(); 140 Instance& param = Instance::Handle();
141 Bool& is_final = Bool::Handle(); 141 Bool& is_final = Bool::Handle();
142 Object& default_value = Object::Handle(); 142 Object& default_value = Object::Handle();
143 Object& metadata = Object::Handle();
143 144
144 // Reparse the function for the following information: 145 // Reparse the function for the following information:
145 // * The default value of a parameter. 146 // * The default value of a parameter.
146 // * Whether a parameters has been deflared as final. 147 // * Whether a parameters has been deflared as final.
148 // * Any metadata associated with the parameter.
147 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); 149 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func));
148 if (result.IsError()) { 150 if (result.IsError()) {
149 ThrowInvokeError(Error::Cast(result)); 151 ThrowInvokeError(Error::Cast(result));
150 UNREACHABLE(); 152 UNREACHABLE();
151 } 153 }
152 154
153 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 155 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
154 args.SetAt(2, owner_mirror); 156 args.SetAt(2, owner_mirror);
155 157
156 const Array& param_descriptor = Array::Cast(result); 158 const Array& param_descriptor = Array::Cast(result);
157 ASSERT(param_descriptor.Length() == (2 * non_implicit_param_count)); 159 ASSERT(param_descriptor.Length() ==
160 (Parser::kParameterEntrySize * non_implicit_param_count));
158 for (intptr_t i = 0; i < non_implicit_param_count; i++) { 161 for (intptr_t i = 0; i < non_implicit_param_count; i++) {
159 pos ^= Smi::New(i); 162 pos ^= Smi::New(i);
160 name ^= func.ParameterNameAt(implicit_param_count + i); 163 name ^= func.ParameterNameAt(implicit_param_count + i);
161 is_final ^= param_descriptor.At(i * 2); 164 is_final ^= param_descriptor.At(
162 default_value = param_descriptor.At(i * 2 + 1); 165 i * Parser::kParameterEntrySize + Parser::kParameterIsFinalOffset);
166 default_value = param_descriptor.At(
167 i * Parser::kParameterEntrySize + Parser::kParameterDefaultValueOffset);
168 metadata = param_descriptor.At(
169 i * Parser::kParameterEntrySize + Parser::kParameterMetadataOffset);
170
163 ASSERT(default_value.IsNull() || default_value.IsInstance()); 171 ASSERT(default_value.IsNull() || default_value.IsInstance());
164 172
165 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See 173 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See
166 // above. 174 // above.
167 args.SetAt(1, name); 175 args.SetAt(1, name);
168 args.SetAt(3, pos); 176 args.SetAt(3, pos);
169 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param)); 177 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param));
170 args.SetAt(5, Bool::Get(i >= index_of_first_named_param)); 178 args.SetAt(5, Bool::Get(i >= index_of_first_named_param));
171 args.SetAt(6, is_final); 179 args.SetAt(6, is_final);
172 args.SetAt(7, default_value); 180 args.SetAt(7, default_value);
181 args.SetAt(8, metadata);
173 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); 182 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args);
174 results.SetAt(i, param); 183 results.SetAt(i, param);
175 } 184 }
176 results.MakeImmutable(); 185 results.MakeImmutable();
177 return results.raw(); 186 return results.raw();
178 } 187 }
179 188
180 189
181 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, 190 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param,
182 const Instance& owner_mirror) { 191 const Instance& owner_mirror) {
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } 1398 }
1390 1399
1391 1400
1392 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1401 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1393 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1402 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1394 const Field& field = Field::Handle(ref.GetFieldReferent()); 1403 const Field& field = Field::Handle(ref.GetFieldReferent());
1395 return field.type(); 1404 return field.type();
1396 } 1405 }
1397 1406
1398 } // namespace dart 1407 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698