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

Side by Side Diff: runtime/vm/ast.cc

Issue 10689083: Compile an instance setter call when a static getter is declared, but no field (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 | « runtime/vm/ast.h ('k') | runtime/vm/parser.cc » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/ast.h" 5 #include "vm/ast.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.h"
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 10
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return new StoreIndexedNode(token_pos(), array(), index_expr(), rhs); 327 return new StoreIndexedNode(token_pos(), array(), index_expr(), rhs);
328 } 328 }
329 329
330 330
331 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) { 331 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
332 // If no setter exist, set the field directly. 332 // If no setter exist, set the field directly.
333 const String& setter_name = String::Handle(Field::SetterName(field_name())); 333 const String& setter_name = String::Handle(Field::SetterName(field_name()));
334 const Function& setter = 334 const Function& setter =
335 Function::ZoneHandle(cls().LookupStaticFunction(setter_name)); 335 Function::ZoneHandle(cls().LookupStaticFunction(setter_name));
336 if (setter.IsNull()) { 336 if (setter.IsNull()) {
337 const Field& field = Field::ZoneHandle(
338 cls().LookupStaticField(field_name()));
339 if (field.IsNull()) {
340 // A static getter is declared, but no setter and no field.
341 if (receiver() != NULL) {
342 return new InstanceSetterNode(token_pos(),
343 receiver(),
344 field_name(),
345 rhs);
346 }
347 return NULL;
348 }
337 // Access to a lazily initialized static field that has not yet been 349 // Access to a lazily initialized static field that has not yet been
338 // initialized is compiled to a static implicit getter. 350 // initialized is compiled to a static implicit getter.
339 // A setter may not exist for such a field. 351 // A setter may not exist for such a field.
340 #if defined(DEBUG) 352 #if defined(DEBUG)
341 const String& getter_name = String::Handle(Field::GetterName(field_name())); 353 const String& getter_name = String::Handle(Field::GetterName(field_name()));
342 const Function& getter = 354 const Function& getter =
343 Function::ZoneHandle(cls().LookupStaticFunction(getter_name)); 355 Function::ZoneHandle(cls().LookupStaticFunction(getter_name));
344 ASSERT(!getter.IsNull() && 356 ASSERT(!getter.IsNull() &&
345 (getter.kind() == RawFunction::kConstImplicitGetter)); 357 (getter.kind() == RawFunction::kConstImplicitGetter));
346 #endif 358 #endif
347 const Field& field = Field::ZoneHandle(
348 cls().LookupStaticField(field_name()));
349 ASSERT(!field.IsNull());
350 return new StoreStaticFieldNode(token_pos(), field, rhs); 359 return new StoreStaticFieldNode(token_pos(), field, rhs);
351 } else { 360 } else {
352 return new StaticSetterNode(token_pos(), cls(), field_name(), rhs); 361 return new StaticSetterNode(token_pos(), cls(), field_name(), rhs);
353 } 362 }
354 } 363 }
355 364
356 365
357 const Instance* StaticGetterNode::EvalConstExpr() const { 366 const Instance* StaticGetterNode::EvalConstExpr() const {
358 const String& getter_name = 367 const String& getter_name =
359 String::Handle(Field::GetterName(this->field_name())); 368 String::Handle(Field::GetterName(this->field_name()));
(...skipping 11 matching lines...) Expand all
371 if (result.IsError() || result.IsNull()) { 380 if (result.IsError() || result.IsNull()) {
372 // TODO(turnidge): We could get better error messages by returning 381 // TODO(turnidge): We could get better error messages by returning
373 // the Error object directly to the parser. This will involve 382 // the Error object directly to the parser. This will involve
374 // replumbing all of the EvalConstExpr methods. 383 // replumbing all of the EvalConstExpr methods.
375 return NULL; 384 return NULL;
376 } 385 }
377 return &Instance::ZoneHandle(Instance::Cast(result).raw()); 386 return &Instance::ZoneHandle(Instance::Cast(result).raw());
378 } 387 }
379 388
380 } // namespace dart 389 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698