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

Unified Diff: runtime/vm/parser.cc

Issue 10905109: Add named constructor name checking (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 11907)
+++ runtime/vm/parser.cc (working copy)
@@ -22,6 +22,8 @@
namespace dart {
+DEFINE_FLAG(bool, constructor_name_check, false,
+ "Named constructors may not clash with other members");
DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements.");
DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks.");
DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
@@ -480,6 +482,7 @@
name_pos = 0;
name = NULL;
redirect_name = NULL;
+ constructor_name = NULL;
params.Clear();
kind = RawFunction::kRegularFunction;
}
@@ -509,7 +512,11 @@
const AbstractType* type;
intptr_t name_pos;
String* name;
- String* redirect_name; // For constructors: NULL or redirected constructor.
+ // For constructors: NULL or redirected constructor.
+ String* redirect_name;
+ // For constructors: NULL for unnamed constructor,
+ // identifier after classname for named constructors.
+ String* constructor_name;
ParamList params;
RawFunction::Kind kind;
};
@@ -2399,6 +2406,14 @@
ErrorMsg(method->name_pos,
"field or method '%s' already defined", method->name->ToCString());
}
+ if (FLAG_constructor_name_check && method->constructor_name != NULL) {
+ if (members->FunctionNameExists(*method->constructor_name, method->kind)) {
+ ErrorMsg(method->name_pos,
+ "Named constructor '%s' conflicts with method or field '%s'",
+ method->name->ToCString(),
+ method->constructor_name->ToCString());
+ }
+ }
siva 2012/09/06 16:52:10 As discussed offline how do we report errors for t
hausner 2012/09/06 18:02:13 Correct. We really should have a simpler way to re
// Mangle the name for getter and setter functions and check function
// arity.
@@ -2865,8 +2880,8 @@
if (CurrentToken() == Token::kPERIOD) {
// Named constructor.
ConsumeToken();
- const String* name = ExpectIdentifier("identifier expected");
- ctor_suffix = String::Concat(ctor_suffix, *name);
+ member.constructor_name = ExpectIdentifier("identifier expected");
+ ctor_suffix = String::Concat(ctor_suffix, *member.constructor_name);
}
*member.name = String::Concat(*member.name, ctor_suffix);
// Ensure that names are symbols.

Powered by Google App Engine
This is Rietveld 408576698