Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index 2ddf729fea1f0cbf3a6d29b3f23b0c3100edf420..248622662a4be3a742e84099c3c422939abaa036 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -5601,9 +5601,6 @@ const char* Function::KindToCString(RawFunction::Kind kind) { |
case RawFunction::kClosureFunction: |
return "ClosureFunction"; |
break; |
- case RawFunction::kImplicitClosureFunction: |
- return "ImplicitClosureFunction"; |
- break; |
case RawFunction::kSignatureFunction: |
return "SignatureFunction"; |
break; |
@@ -5990,23 +5987,20 @@ intptr_t Function::NumParameters() const { |
} |
intptr_t Function::NumImplicitParameters() const { |
- const RawFunction::Kind k = kind(); |
- if (k == RawFunction::kConstructor) { |
+ if (kind() == RawFunction::kConstructor) { |
// Type arguments for factory; instance for generative constructor. |
return 1; |
} |
- if ((k == RawFunction::kClosureFunction) || |
- (k == RawFunction::kImplicitClosureFunction) || |
- (k == RawFunction::kSignatureFunction)) { |
+ if ((kind() == RawFunction::kClosureFunction) || |
+ (kind() == RawFunction::kSignatureFunction)) { |
return 1; // Closure object. |
} |
if (!is_static()) { |
// Closure functions defined inside instance (i.e. non-static) functions are |
// marked as non-static, but they do not have a receiver. |
// Closures are handled above. |
- ASSERT((k != RawFunction::kClosureFunction) && |
- (k != RawFunction::kImplicitClosureFunction) && |
- (k != RawFunction::kSignatureFunction)); |
+ ASSERT((kind() != RawFunction::kClosureFunction) && |
+ (kind() != RawFunction::kSignatureFunction)); |
return 1; // Receiver. |
} |
return 0; // No implicit parameters. |
@@ -6536,12 +6530,26 @@ bool Function::IsImplicitConstructor() const { |
return IsGenerativeConstructor() && (token_pos() == end_token_pos()); |
} |
+bool Function::IsImplicitClosureFunction() const { |
+ if (!IsClosureFunction()) { |
+ return false; |
+ } |
+ const Function& parent = Function::Handle(parent_function()); |
+ return (parent.implicit_closure_function() == raw()); |
+} |
+ |
bool Function::IsImplicitStaticClosureFunction(RawFunction* func) { |
NoSafepointScope no_safepoint; |
uint32_t kind_tag = func->ptr()->kind_tag_; |
- return (KindBits::decode(kind_tag) == |
- RawFunction::kImplicitClosureFunction) && |
- StaticBit::decode(kind_tag); |
+ if (KindBits::decode(kind_tag) != RawFunction::kClosureFunction) { |
+ return false; |
+ } |
+ if (!StaticBit::decode(kind_tag)) { |
+ return false; |
+ } |
+ RawClosureData* data = reinterpret_cast<RawClosureData*>(func->ptr()->data_); |
+ RawFunction* parent_function = data->ptr()->parent_function_; |
+ return (parent_function->ptr()->data_ == reinterpret_cast<RawObject*>(func)); |
} |
bool Function::IsConstructorClosureFunction() const { |
@@ -6605,7 +6613,6 @@ RawFunction* Function::New(const String& name, |
result.SetInstructionsSafe( |
Code::Handle(StubCode::LazyCompile_entry()->code())); |
if (kind == RawFunction::kClosureFunction || |
- kind == RawFunction::kImplicitClosureFunction || |
kind == RawFunction::kConvertedClosureFunction) { |
ASSERT(space == Heap::kOld); |
const ClosureData& data = ClosureData::Handle(ClosureData::New()); |
@@ -6671,22 +6678,15 @@ RawFunction* Function::Clone(const Class& new_owner) const { |
return clone.raw(); |
} |
-RawFunction* Function::NewClosureFunctionWithKind(RawFunction::Kind kind, |
- const String& name, |
- const Function& parent, |
- TokenPosition token_pos) { |
- ASSERT((kind == RawFunction::kClosureFunction) || |
- (kind == RawFunction::kImplicitClosureFunction) || |
- (kind == RawFunction::kConvertedClosureFunction)); |
+RawFunction* Function::NewClosureFunction(const String& name, |
+ const Function& parent, |
+ TokenPosition token_pos) { |
ASSERT(!parent.IsNull()); |
- // Only static top-level functions are allowed to be converted right now. |
- ASSERT((kind != RawFunction::kConvertedClosureFunction) || |
- parent.is_static()); |
// Use the owner defining the parent function and not the class containing it. |
const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); |
ASSERT(!parent_owner.IsNull()); |
const Function& result = Function::Handle( |
- Function::New(name, kind, |
+ Function::New(name, RawFunction::kClosureFunction, |
/* is_static = */ parent.is_static(), |
/* is_const = */ false, |
/* is_abstract = */ false, |
@@ -6696,25 +6696,24 @@ RawFunction* Function::NewClosureFunctionWithKind(RawFunction::Kind kind, |
return result.raw(); |
} |
-RawFunction* Function::NewClosureFunction(const String& name, |
- const Function& parent, |
- TokenPosition token_pos) { |
- return NewClosureFunctionWithKind(RawFunction::kClosureFunction, name, parent, |
- token_pos); |
-} |
- |
-RawFunction* Function::NewImplicitClosureFunction(const String& name, |
- const Function& parent, |
- TokenPosition token_pos) { |
- return NewClosureFunctionWithKind(RawFunction::kImplicitClosureFunction, name, |
- parent, token_pos); |
-} |
- |
RawFunction* Function::NewConvertedClosureFunction(const String& name, |
const Function& parent, |
TokenPosition token_pos) { |
- return NewClosureFunctionWithKind(RawFunction::kConvertedClosureFunction, |
- name, parent, token_pos); |
+ ASSERT(!parent.IsNull()); |
+ // Only static top-level functions are allowed to be converted right now. |
+ ASSERT(parent.is_static()); |
+ // Use the owner defining the parent function and not the class containing it. |
+ const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); |
+ ASSERT(!parent_owner.IsNull()); |
+ const Function& result = Function::Handle( |
+ Function::New(name, RawFunction::kConvertedClosureFunction, |
+ /* is_static = */ true, |
+ /* is_const = */ false, |
+ /* is_abstract = */ false, |
+ /* is_external = */ false, |
+ /* is_native = */ false, parent_owner, token_pos)); |
+ result.set_parent_function(parent); |
+ return result.raw(); |
} |
RawFunction* Function::NewSignatureFunction(const Object& owner, |
@@ -6768,7 +6767,7 @@ RawFunction* Function::ImplicitClosureFunction() const { |
// Create closure function. |
const String& closure_name = String::Handle(zone, name()); |
const Function& closure_function = Function::Handle( |
- zone, NewImplicitClosureFunction(closure_name, *this, token_pos())); |
+ zone, NewClosureFunction(closure_name, *this, token_pos())); |
// Set closure function's context scope. |
if (is_static()) { |
@@ -7483,7 +7482,6 @@ const char* Function::ToCString() const { |
switch (kind()) { |
case RawFunction::kRegularFunction: |
case RawFunction::kClosureFunction: |
- case RawFunction::kImplicitClosureFunction: |
case RawFunction::kConvertedClosureFunction: |
case RawFunction::kGetterFunction: |
case RawFunction::kSetterFunction: |