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

Unified Diff: runtime/vm/parser.cc

Issue 11414019: Disallow const native factories (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « no previous file | tests/language/const_native_factory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 14970)
+++ runtime/vm/parser.cc (working copy)
@@ -2439,13 +2439,13 @@
"static method '%s' cannot be abstract",
method->name->ToCString());
}
- if (method->has_const && !(method->IsConstructor() || method->IsFactory())) {
+ if (method->has_const && !method->IsFactoryOrConstructor()) {
ErrorMsg(method->name_pos, "'const' not allowed for methods");
}
- if (method->IsFactoryOrConstructor() && method->has_abstract) {
+ if (method->has_abstract && method->IsFactoryOrConstructor()) {
ErrorMsg(method->name_pos, "constructor cannot be abstract");
}
- if (method->IsConstructor() && method->has_const) {
+ if (method->has_const && method->IsConstructor()) {
Class& cls = Class::Handle(library_.LookupClass(members->class_name()));
cls.set_is_const();
}
@@ -2612,14 +2612,10 @@
ErrorMsg(method->name_pos,
"external method '%s' may not have a function body",
method->name->ToCString());
- } else if (method->IsConstructor() && method->has_const) {
+ } else if (method->IsFactoryOrConstructor() && method->has_const) {
ErrorMsg(method->name_pos,
- "const constructor '%s' may not have a function body",
+ "const constructor or factory '%s' may not have a function body",
method->name->ToCString());
- } else if (method->IsFactory() && method->has_const) {
- ErrorMsg(method->name_pos,
- "const factory '%s' may not have a function body",
- method->name->ToCString());
} else if (members->is_interface()) {
ErrorMsg(method->name_pos,
"function body not allowed in interface declaration");
@@ -2644,9 +2640,9 @@
} else if (members->is_interface()) {
ErrorMsg(method->name_pos,
"function body not allowed in interface declaration");
- } else if (method->IsConstructor() && method->has_const) {
+ } else if (method->IsFactoryOrConstructor() && method->has_const) {
ErrorMsg(method->name_pos,
- "const constructor '%s' may not have a function body",
+ "const constructor or factory '%s' may not be native",
method->name->ToCString());
}
if (method->redirect_name != NULL) {
@@ -8100,22 +8096,17 @@
// +2 for implicit receiver and construction phase arguments.
GrowableArray<const Object*> arg_values(arguments->length() + 2);
Instance& instance = Instance::Handle();
- if (!constructor.IsFactory()) {
- instance = Instance::New(type_class, Heap::kOld);
- if (!type_arguments.IsNull()) {
- if (!type_arguments.IsInstantiated()) {
- ErrorMsg("type must be constant in const constructor");
- }
- instance.SetTypeArguments(
- AbstractTypeArguments::Handle(type_arguments.Canonicalize()));
+ ASSERT(!constructor.IsFactory());
+ instance = Instance::New(type_class, Heap::kOld);
+ if (!type_arguments.IsNull()) {
+ if (!type_arguments.IsInstantiated()) {
+ ErrorMsg("type must be constant in const constructor");
}
- arg_values.Add(&instance);
- arg_values.Add(&Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
- } else {
- // Prepend type_arguments to list of arguments to factory.
- ASSERT(type_arguments.IsZoneHandle());
- arg_values.Add(&type_arguments);
+ instance.SetTypeArguments(
+ AbstractTypeArguments::Handle(type_arguments.Canonicalize()));
}
+ arg_values.Add(&instance);
+ arg_values.Add(&Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
for (int i = 0; i < arguments->length(); i++) {
AstNode* arg = arguments->NodeAt(i);
// Arguments have been evaluated to a literal value already.
@@ -8134,10 +8125,6 @@
return Object::null();
}
} else {
- if (constructor.IsFactory()) {
- // The factory method returns the allocated object.
- instance ^= result.raw();
- }
if (!instance.IsNull()) {
instance ^= instance.Canonicalize();
}
« no previous file with comments | « no previous file | tests/language/const_native_factory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698