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

Unified Diff: runtime/vm/parser.cc

Issue 11419191: Enforce rule in vm that factory name must match enclosing class name. (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 | « runtime/tests/vm/vm.status ('k') | runtime/vm/symbols.h » ('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 15427)
+++ runtime/vm/parser.cc (working copy)
@@ -2975,37 +2975,26 @@
// Optionally parse a (possibly named) constructor name or factory.
if (IsIdentifier() &&
(CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
+ member.name_pos = TokenPos();
+ member.name = CurrentLiteral(); // Unqualified identifier.
+ ConsumeToken();
if (member.has_factory) {
- // TODO(regis): Simplify this code once the core library is fixed.
- // See issue 6641.
- // Per specification, the name of the factory must be the name of the
- // immediately enclosing class.
-
- // The factory name may be qualified.
- QualIdent factory_name;
- ParseQualIdent(&factory_name);
- member.name_pos = factory_name.ident_pos;
- member.name = factory_name.ident; // Unqualified identifier.
- // The class of the factory result type is specified by the factory name.
- LibraryPrefix& lib_prefix = LibraryPrefix::Handle();
- if (factory_name.lib_prefix != NULL) {
- lib_prefix = factory_name.lib_prefix->raw();
+ // The factory name may be qualified, but the first identifier must match
+ // the name of the immediately enclosing class.
+ if (!member.name->Equals(members->class_name())) {
+ ErrorMsg(member.name_pos, "factory name must be '%s'",
+ members->class_name().ToCString());
}
const Object& result_type_class = Object::Handle(
- UnresolvedClass::New(lib_prefix,
- *factory_name.ident,
- factory_name.ident_pos));
+ UnresolvedClass::New(LibraryPrefix::Handle(),
+ *member.name,
+ member.name_pos));
// The type arguments of the result type are set during finalization.
member.type = &Type::ZoneHandle(Type::New(result_type_class,
TypeArguments::Handle(),
- factory_name.ident_pos));
- } else {
- if (member.has_static) {
- ErrorMsg("constructor cannot be static");
- }
- member.name_pos = TokenPos();
- member.name = CurrentLiteral();
- ConsumeToken();
+ member.name_pos));
+ } else if (member.has_static) {
+ ErrorMsg(member.name_pos, "constructor cannot be static");
}
// We must be dealing with a constructor or named constructor.
member.kind = RawFunction::kConstructor;
@@ -9003,7 +8992,7 @@
}
} else {
// Factory call at runtime.
- String& factory_class_name = String::Handle(Symbols::MapImplementation());
+ String& factory_class_name = String::Handle(Symbols::Map());
const Class& factory_class =
Class::Handle(LookupCoreClass(factory_class_name));
ASSERT(!factory_class.IsNull());
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698