Chromium Code Reviews| 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. |