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

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

Issue 212883009: Handle creating ParameterMirrors for the parameters of forwarding constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: different Created 6 years, 9 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/vm/object.h » ('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/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const intptr_t implicit_param_count = func.NumImplicitParameters(); 122 const intptr_t implicit_param_count = func.NumImplicitParameters();
123 const intptr_t non_implicit_param_count = func.NumParameters() - 123 const intptr_t non_implicit_param_count = func.NumParameters() -
124 implicit_param_count; 124 implicit_param_count;
125 const intptr_t index_of_first_optional_param = 125 const intptr_t index_of_first_optional_param =
126 non_implicit_param_count - func.NumOptionalParameters(); 126 non_implicit_param_count - func.NumOptionalParameters();
127 const intptr_t index_of_first_named_param = 127 const intptr_t index_of_first_named_param =
128 non_implicit_param_count - func.NumOptionalNamedParameters(); 128 non_implicit_param_count - func.NumOptionalNamedParameters();
129 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); 129 const Array& results = Array::Handle(Array::New(non_implicit_param_count));
130 const Array& args = Array::Handle(Array::New(9)); 130 const Array& args = Array::Handle(Array::New(9));
131 131
132 // Return for synthetic functions and getters.
133 if (func.IsGetterFunction() ||
134 func.IsImplicitConstructor() ||
135 func.IsImplicitGetterFunction() ||
136 func.IsImplicitSetterFunction()) {
137 return results.raw();
138 }
139
140 Smi& pos = Smi::Handle(); 132 Smi& pos = Smi::Handle();
141 String& name = String::Handle(); 133 String& name = String::Handle();
142 Instance& param = Instance::Handle(); 134 Instance& param = Instance::Handle();
143 Bool& is_final = Bool::Handle(); 135 Bool& is_final = Bool::Handle();
144 Object& default_value = Object::Handle(); 136 Object& default_value = Object::Handle();
145 Object& metadata = Object::Handle(); 137 Object& metadata = Object::Handle();
146 138
147 // We force compilation of constructors to ensure the types of initializing 139 // We force compilation of constructors to ensure the types of initializing
148 // formals have been corrected. We do not force the compilation of all types 140 // formals have been corrected. We do not force the compilation of all types
149 // of functions because some have no body, e.g. signature functions. 141 // of functions because some have no body, e.g. signature functions.
150 EnsureConstructorsAreCompiled(func); 142 EnsureConstructorsAreCompiled(func);
151 143
152 // Reparse the function for the following information: 144 bool has_extra_parameter_info = true;
153 // * The default value of a parameter. 145 if (non_implicit_param_count == 0) {
154 // * Whether a parameters has been deflared as final. 146 has_extra_parameter_info = false;
155 // * Any metadata associated with the parameter. 147 }
156 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); 148 if (func.IsImplicitConstructor()) {
157 if (result.IsError()) { 149 // This covers the default constructor and forwarding constructors.
158 ThrowInvokeError(Error::Cast(result)); 150 has_extra_parameter_info = false;
159 UNREACHABLE(); 151 }
152
153 Array& param_descriptor = Array::Handle();
154 if (has_extra_parameter_info) {
155 // Reparse the function for the following information:
156 // * The default value of a parameter.
157 // * Whether a parameters has been deflared as final.
158 // * Any metadata associated with the parameter.
159 const Object& result =
160 Object::Handle(Parser::ParseFunctionParameters(func));
161 if (result.IsError()) {
162 ThrowInvokeError(Error::Cast(result));
163 UNREACHABLE();
164 }
165 param_descriptor ^= result.raw();
166 ASSERT(param_descriptor.Length() ==
167 (Parser::kParameterEntrySize * non_implicit_param_count));
160 } 168 }
161 169
162 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 170 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
163 args.SetAt(2, owner_mirror); 171 args.SetAt(2, owner_mirror);
164 172
165 const Array& param_descriptor = Array::Cast(result); 173 if (!has_extra_parameter_info) {
166 ASSERT(param_descriptor.Length() == 174 is_final ^= Bool::True().raw();
167 (Parser::kParameterEntrySize * non_implicit_param_count)); 175 default_value = Object::null();
176 metadata = Object::null();
177 }
178
168 for (intptr_t i = 0; i < non_implicit_param_count; i++) { 179 for (intptr_t i = 0; i < non_implicit_param_count; i++) {
169 pos ^= Smi::New(i); 180 pos ^= Smi::New(i);
170 name ^= func.ParameterNameAt(implicit_param_count + i); 181 name ^= func.ParameterNameAt(implicit_param_count + i);
171 is_final ^= param_descriptor.At( 182 if (has_extra_parameter_info) {
172 i * Parser::kParameterEntrySize + Parser::kParameterIsFinalOffset); 183 is_final ^= param_descriptor.At(i * Parser::kParameterEntrySize +
173 default_value = param_descriptor.At( 184 Parser::kParameterIsFinalOffset);
174 i * Parser::kParameterEntrySize + Parser::kParameterDefaultValueOffset); 185 default_value = param_descriptor.At(i * Parser::kParameterEntrySize +
175 metadata = param_descriptor.At( 186 Parser::kParameterDefaultValueOffset);
176 i * Parser::kParameterEntrySize + Parser::kParameterMetadataOffset); 187 metadata = param_descriptor.At(i * Parser::kParameterEntrySize +
177 188 Parser::kParameterMetadataOffset);
189 }
178 ASSERT(default_value.IsNull() || default_value.IsInstance()); 190 ASSERT(default_value.IsNull() || default_value.IsInstance());
179 191
180 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See 192 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See
181 // above. 193 // above.
182 args.SetAt(1, name); 194 args.SetAt(1, name);
183 args.SetAt(3, pos); 195 args.SetAt(3, pos);
184 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param)); 196 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param));
185 args.SetAt(5, Bool::Get(i >= index_of_first_named_param)); 197 args.SetAt(5, Bool::Get(i >= index_of_first_named_param));
186 args.SetAt(6, is_final); 198 args.SetAt(6, is_final);
187 args.SetAt(7, default_value); 199 args.SetAt(7, default_value);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ThrowInvokeError(error); 354 ThrowInvokeError(error);
343 UNREACHABLE(); 355 UNREACHABLE();
344 } 356 }
345 357
346 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); 358 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0);
347 const Bool& is_mixin_app_alias = Bool::Get(cls.is_mixin_app_alias()); 359 const Bool& is_mixin_app_alias = Bool::Get(cls.is_mixin_app_alias());
348 360
349 const Array& args = Array::Handle(Array::New(8)); 361 const Array& args = Array::Handle(Array::New(8));
350 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 362 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
351 args.SetAt(1, type); 363 args.SetAt(1, type);
352 // We do not set the names of anonymous mixin applications because the mirrors 364 // Note that the VM does not consider mixin application aliases to be mixin
365 // applications, so this only covers anonymous mixin applications. We do not
366 // set the names of anonymous mixin applications here because the mirrors
353 // use a different naming convention than the VM (lib.S with lib.M and S&M 367 // use a different naming convention than the VM (lib.S with lib.M and S&M
354 // respectively). 368 // respectively).
355 if (!cls.IsAnonymousMixinApplication()) { 369 if (!cls.IsMixinApplication()) {
356 args.SetAt(2, String::Handle(cls.Name())); 370 args.SetAt(2, String::Handle(cls.Name()));
357 } 371 }
358 args.SetAt(3, owner_mirror); 372 args.SetAt(3, owner_mirror);
359 args.SetAt(4, Bool::Get(cls.is_abstract())); 373 args.SetAt(4, Bool::Get(cls.is_abstract()));
360 args.SetAt(5, is_generic); 374 args.SetAt(5, is_generic);
361 args.SetAt(6, is_mixin_app_alias); 375 args.SetAt(6, is_mixin_app_alias);
362 args.SetAt(7, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); 376 args.SetAt(7, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
363 return CreateMirror(Symbols::_LocalClassMirror(), args); 377 return CreateMirror(Symbols::_LocalClassMirror(), args);
364 } 378 }
365 379
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 DictionaryIterator entries(library); 1321 DictionaryIterator entries(library);
1308 1322
1309 AbstractType& type = AbstractType::Handle(); 1323 AbstractType& type = AbstractType::Handle();
1310 1324
1311 while (entries.HasNext()) { 1325 while (entries.HasNext()) {
1312 entry = entries.GetNext(); 1326 entry = entries.GetNext();
1313 if (entry.IsClass()) { 1327 if (entry.IsClass()) {
1314 const Class& klass = Class::Cast(entry); 1328 const Class& klass = Class::Cast(entry);
1315 // We filter out function signature classes and dynamic. 1329 // We filter out function signature classes and dynamic.
1316 // TODO(12478): Should not need to filter out dynamic. 1330 // TODO(12478): Should not need to filter out dynamic.
1331 // Note that the VM does not consider mixin application aliases to be
1332 // mixin applications.
1317 if (!klass.IsCanonicalSignatureClass() && 1333 if (!klass.IsCanonicalSignatureClass() &&
1318 !klass.IsDynamicClass() && 1334 !klass.IsDynamicClass() &&
1319 !klass.IsAnonymousMixinApplication()) { 1335 !klass.IsMixinApplication()) {
1320 type = klass.DeclarationType(); 1336 type = klass.DeclarationType();
1321 member_mirror = CreateClassMirror(klass, 1337 member_mirror = CreateClassMirror(klass,
1322 type, 1338 type,
1323 Bool::True(), // is_declaration 1339 Bool::True(), // is_declaration
1324 owner_mirror); 1340 owner_mirror);
1325 member_mirrors.Add(member_mirror); 1341 member_mirrors.Add(member_mirror);
1326 } 1342 }
1327 } else if (entry.IsField()) { 1343 } else if (entry.IsField()) {
1328 const Field& field = Field::Cast(entry); 1344 const Field& field = Field::Cast(entry);
1329 member_mirror = CreateVariableMirror(field, owner_mirror); 1345 member_mirror = CreateVariableMirror(field, owner_mirror);
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 } 2246 }
2231 2247
2232 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2248 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2233 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2249 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2234 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2250 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2235 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2251 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2236 } 2252 }
2237 2253
2238 2254
2239 } // namespace dart 2255 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698