Make AST generation deterministic: always call a static getter if it exists, regardless if the statuic field was initialized or not. Previously we may have created a LoadStaticFieldNode dependgin if the static field was already intialized at compile time.

Note that we do not generate implicit static getter nodes if their initialization is trivial.

R=hausner@google.com

Review URL: https://codereview.chromium.org//16136014

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23825 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
srdjan@google.com
2013-06-10 19:32:03 +00:00
parent d5dd12fa3e
commit 2b12036d2d
+22 -14
View File
@@ -8057,23 +8057,30 @@ bool Parser::IsInstantiatorRequired() const {
}
// If the field is already initialized, return no ast (NULL).
// Otherwise, if the field is constant, initialize the field and return no ast.
// If the field is not initialized and not const, return the ast for the getter.
// If the field is constant, initialize the field if necessary and return
// no ast (NULL).
// Otherwise return NULL if no implicit getter exists (either never created
// because trivial, or not needed or field not readable).
AstNode* Parser::RunStaticFieldInitializer(const Field& field) {
ASSERT(field.is_static());
const Class& field_owner = Class::ZoneHandle(field.owner());
const String& field_name = String::ZoneHandle(field.name());
const String& getter_name = String::Handle(Field::GetterName(field_name));
const Function& getter =
Function::Handle(field_owner.LookupStaticFunction(getter_name));
const Instance& value = Instance::Handle(field.value());
if (value.raw() == Object::transition_sentinel().raw()) {
if (field.is_const()) {
ErrorMsg("circular dependency while initializing static field '%s'",
String::Handle(field.name()).ToCString());
field_name.ToCString());
} else {
// The implicit static getter will throw the exception if necessary.
return new StaticGetterNode(TokenPos(),
NULL,
false,
Class::ZoneHandle(field.owner()),
String::ZoneHandle(field.name()));
field_owner,
field_name);
}
} else if (value.raw() == Object::sentinel().raw()) {
// This field has not been referenced yet and thus the value has
@@ -8081,13 +8088,9 @@ AstNode* Parser::RunStaticFieldInitializer(const Field& field) {
// to evaluate the expression and canonicalize the value.
if (field.is_const()) {
field.set_value(Object::transition_sentinel());
const String& field_name = String::Handle(field.name());
const String& getter_name =
String::Handle(Field::GetterName(field_name));
const Class& cls = Class::Handle(field.owner());
const int kNumArguments = 0; // no arguments.
const Function& func =
Function::Handle(Resolver::ResolveStatic(cls,
Function::Handle(Resolver::ResolveStatic(field_owner,
getter_name,
kNumArguments,
Object::empty_array(),
@@ -8120,15 +8123,20 @@ AstNode* Parser::RunStaticFieldInitializer(const Field& field) {
instance ^= instance.Canonicalize();
}
field.set_value(instance);
return NULL; // Constant
} else {
return new StaticGetterNode(TokenPos(),
NULL,
false,
Class::ZoneHandle(field.owner()),
String::ZoneHandle(field.name()));
field_owner,
field_name);
}
}
return NULL;
if (getter.IsNull() || (getter.kind() == RawFunction::kConstImplicitGetter)) {
return NULL;
}
ASSERT(getter.kind() == RawFunction::kImplicitGetter);
return new StaticGetterNode(TokenPos(), NULL, false, field_owner, field_name);
}