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

Unified Diff: runtime/vm/object.cc

Issue 471283002: Runtime support for evaluation of static field initializer expressions (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 39381)
+++ runtime/vm/object.cc (working copy)
@@ -2781,7 +2781,7 @@
new_list = Array::New(patch_len + orig_len);
for (intptr_t i = 0; i < patch_len; i++) {
field ^= patch_list.At(i);
- field.set_owner(*this);
+ field.set_owner(patch_class);
member_name = field.name();
// TODO(iposva): Verify non-public fields only.
@@ -5207,21 +5207,6 @@
}
-RawField* Function::saved_static_field() const {
- ASSERT(kind() == RawFunction::kStaticInitializer);
- const Object& obj = Object::Handle(raw_ptr()->data_);
- ASSERT(obj.IsField());
- return Field::Cast(obj).raw();
-}
-
-
-void Function::set_saved_static_field(const Field& value) const {
- ASSERT(kind() == RawFunction::kStaticInitializer);
- ASSERT(raw_ptr()->data_ == Object::null());
- set_data(value);
-}
-
-
RawFunction* Function::parent_function() const {
if (IsClosureFunction()) {
const Object& obj = Object::Handle(raw_ptr()->data_);
@@ -5246,7 +5231,6 @@
RawFunction* Function::implicit_closure_function() const {
if (IsClosureFunction() ||
IsSignatureFunction() ||
- IsStaticInitializerFunction() ||
IsFactory()) {
return Function::null();
}
@@ -5340,9 +5324,6 @@
case RawFunction::kImplicitStaticFinalGetter:
return "kImplicitStaticFinalGetter";
break;
- case RawFunction::kStaticInitializer:
- return "kStaticInitializer";
- break;
case RawFunction::kMethodExtractor:
return "kMethodExtractor";
break;
@@ -6688,36 +6669,6 @@
}
-RawFunction* Function::NewStaticInitializer(const Field& field) {
- ASSERT(field.is_static());
- const String& field_name = String::Handle(field.name());
- const String& init_name =
- String::Handle(Symbols::New(String::Handle(
- String::Concat(Symbols::InitPrefix(), field_name))));
- const Function& init_function = Function::ZoneHandle(
- Function::New(init_name,
- RawFunction::kStaticInitializer,
- true, // static
- false, // !const
- false, // !abstract
- false, // !external
- false, // !native
- Class::Handle(field.owner()),
- field.token_pos()));
- init_function.set_result_type(AbstractType::Handle(field.type()));
- // Static initializer functions are generated by the VM and are therfore
- // hidden from the user. Since they are only executed once, we avoid
- // optimizing and inlining them. After the field is initialized, the
- // optimizing compiler can eliminate the call to the static initializer
- // via constant folding.
- init_function.set_is_visible(false);
- init_function.SetIsOptimizable(false);
- init_function.set_is_inlinable(false);
- init_function.set_saved_static_field(field);
- return init_function.raw();
-}
-
-
const char* Function::ToCString() const {
const char* static_str = is_static() ? " static" : "";
const char* abstract_str = is_abstract() ? " abstract" : "";
@@ -6742,9 +6693,6 @@
case RawFunction::kImplicitSetter:
kind_str = " setter";
break;
- case RawFunction::kStaticInitializer:
- kind_str = " static-initializer";
- break;
case RawFunction::kImplicitStaticFinalGetter:
kind_str = " static-final-getter";
break;
@@ -7280,6 +7228,33 @@
}
+void Field::EvaluateInitializer() const {
+ ASSERT(is_static());
+ if (value() == Object::sentinel().raw()) {
+ set_value(Object::transition_sentinel());
+ Object& value = Object::Handle(Compiler::EvaluateStaticInitializer(*this));
+ if (value.IsError()) {
+ set_value(Object::null_instance());
+ Exceptions::PropagateError(Error::Cast(value));
+ UNREACHABLE();
+ }
+ ASSERT(value.IsNull() || value.IsInstance());
+ set_value(value.IsNull() ? Instance::null_instance()
+ : Instance::Cast(value));
+ return;
+ } else if (value() == Object::transition_sentinel().raw()) {
+ set_value(Object::null_instance());
+ const Array& ctor_args = Array::Handle(Array::New(1));
+ const String& field_name = String::Handle(name());
+ ctor_args.SetAt(0, field_name);
+ Exceptions::ThrowByType(Exceptions::kCyclicInitializationError, ctor_args);
+ UNREACHABLE();
+ return;
+ }
+ UNREACHABLE();
+}
+
+
static intptr_t GetListLength(const Object& value) {
if (value.IsTypedData()) {
const TypedData& list = TypedData::Cast(value);
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698