Index: runtime/vm/object.cc |
=================================================================== |
--- runtime/vm/object.cc (revision 29679) |
+++ runtime/vm/object.cc (working copy) |
@@ -4224,7 +4224,9 @@ |
RawFunction* Function::implicit_closure_function() const { |
- if (IsClosureFunction() || IsSignatureFunction()) { |
+ if (IsClosureFunction() || |
+ IsSignatureFunction() || |
+ IsStaticInitializerFunction()) { |
return Function::null(); |
} |
const Object& obj = Object::Handle(raw_ptr()->data_); |
@@ -5427,6 +5429,35 @@ |
} |
+RawFunction* Function::NewStaticInitializer(const String& field_name, |
+ const AbstractType& result_type, |
+ const Class& cls, |
+ intptr_t initializer_pos) { |
+ 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 |
+ cls, |
+ initializer_pos)); |
+ init_function.set_result_type(result_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.set_is_optimizable(false); |
+ init_function.set_is_inlinable(false); |
+ return init_function.raw(); |
+} |
+ |
+ |
const char* Function::ToCString() const { |
const char* static_str = is_static() ? " static" : ""; |
const char* abstract_str = is_abstract() ? " abstract" : ""; |
@@ -5451,6 +5482,9 @@ |
case RawFunction::kImplicitSetter: |
kind_str = " setter"; |
break; |
+ case RawFunction::kStaticInitializer: |
+ kind_str = " static-initializer"; |
+ break; |
case RawFunction::kImplicitStaticFinalGetter: |
kind_str = " static-final-getter"; |
break; |
@@ -5522,6 +5556,9 @@ |
case RawFunction::kConstructor: |
kind_string = "constructor"; |
break; |
+ case RawFunction::kStaticInitializer: |
+ kind_string = "static initializer"; |
+ break; |
case RawFunction::kImplicitStaticFinalGetter: |
kind_string = "static final getter"; |
break; |