OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2969 member.type = &AbstractType::ZoneHandle( | 2969 member.type = &AbstractType::ZoneHandle( |
2970 ParseType(ClassFinalizer::kTryResolve)); | 2970 ParseType(ClassFinalizer::kTryResolve)); |
2971 } | 2971 } |
2972 } | 2972 } |
2973 } | 2973 } |
2974 | 2974 |
2975 // Optionally parse a (possibly named) constructor name or factory. | 2975 // Optionally parse a (possibly named) constructor name or factory. |
2976 if (IsIdentifier() && | 2976 if (IsIdentifier() && |
2977 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { | 2977 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { |
2978 if (member.has_factory) { | 2978 if (member.has_factory) { |
2979 // TODO(regis): Simplify this code once the core library is fixed. | 2979 // The factory name may be qualified, but the first identifier must match |
2980 // See issue 6641. | 2980 // the name of the immediately enclosing class. |
2981 // Per specification, the name of the factory must be the name of the | |
2982 // immediately enclosing class. | |
2983 | |
2984 // The factory name may be qualified. | |
2985 QualIdent factory_name; | 2981 QualIdent factory_name; |
2986 ParseQualIdent(&factory_name); | 2982 ParseQualIdent(&factory_name); |
hausner
2012/11/28 00:26:38
Does it still make sense to use ParseQualIdent now
regis
2012/11/28 01:09:18
You are right. I simplified this code further.
| |
2987 member.name_pos = factory_name.ident_pos; | 2983 member.name_pos = factory_name.ident_pos; |
2988 member.name = factory_name.ident; // Unqualified identifier. | 2984 member.name = factory_name.ident; // Unqualified identifier. |
2989 // The class of the factory result type is specified by the factory name. | 2985 if ((factory_name.lib_prefix != NULL) || |
2986 !member.name->Equals(members->class_name())) { | |
2987 ErrorMsg("factory name must be '%s'", | |
2988 members->class_name().ToCString()); | |
2989 } | |
2990 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 2990 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
2991 if (factory_name.lib_prefix != NULL) { | |
2992 lib_prefix = factory_name.lib_prefix->raw(); | |
2993 } | |
2994 const Object& result_type_class = Object::Handle( | 2991 const Object& result_type_class = Object::Handle( |
2995 UnresolvedClass::New(lib_prefix, | 2992 UnresolvedClass::New(lib_prefix, |
2996 *factory_name.ident, | 2993 *factory_name.ident, |
2997 factory_name.ident_pos)); | 2994 factory_name.ident_pos)); |
2998 // The type arguments of the result type are set during finalization. | 2995 // The type arguments of the result type are set during finalization. |
2999 member.type = &Type::ZoneHandle(Type::New(result_type_class, | 2996 member.type = &Type::ZoneHandle(Type::New(result_type_class, |
3000 TypeArguments::Handle(), | 2997 TypeArguments::Handle(), |
3001 factory_name.ident_pos)); | 2998 factory_name.ident_pos)); |
3002 } else { | 2999 } else { |
3003 if (member.has_static) { | 3000 if (member.has_static) { |
(...skipping 5992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8996 constr_args)); | 8993 constr_args)); |
8997 if (constructor_result.IsUnhandledException()) { | 8994 if (constructor_result.IsUnhandledException()) { |
8998 return GenerateRethrow(literal_pos, constructor_result); | 8995 return GenerateRethrow(literal_pos, constructor_result); |
8999 } else { | 8996 } else { |
9000 const Instance& const_instance = Instance::Cast(constructor_result); | 8997 const Instance& const_instance = Instance::Cast(constructor_result); |
9001 return new LiteralNode(literal_pos, | 8998 return new LiteralNode(literal_pos, |
9002 Instance::ZoneHandle(const_instance.raw())); | 8999 Instance::ZoneHandle(const_instance.raw())); |
9003 } | 9000 } |
9004 } else { | 9001 } else { |
9005 // Factory call at runtime. | 9002 // Factory call at runtime. |
9006 String& factory_class_name = String::Handle(Symbols::MapImplementation()); | 9003 String& factory_class_name = String::Handle(Symbols::Map()); |
9007 const Class& factory_class = | 9004 const Class& factory_class = |
9008 Class::Handle(LookupCoreClass(factory_class_name)); | 9005 Class::Handle(LookupCoreClass(factory_class_name)); |
9009 ASSERT(!factory_class.IsNull()); | 9006 ASSERT(!factory_class.IsNull()); |
9010 const String& factory_method_name = | 9007 const String& factory_method_name = |
9011 String::Handle(Symbols::MapLiteralFactory()); | 9008 String::Handle(Symbols::MapLiteralFactory()); |
9012 const Function& factory_method = Function::ZoneHandle( | 9009 const Function& factory_method = Function::ZoneHandle( |
9013 factory_class.LookupFactory(factory_method_name)); | 9010 factory_class.LookupFactory(factory_method_name)); |
9014 ASSERT(!factory_method.IsNull()); | 9011 ASSERT(!factory_method.IsNull()); |
9015 if (!map_type_arguments.IsNull() && | 9012 if (!map_type_arguments.IsNull() && |
9016 !map_type_arguments.IsInstantiated() && | 9013 !map_type_arguments.IsInstantiated() && |
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10029 void Parser::SkipQualIdent() { | 10026 void Parser::SkipQualIdent() { |
10030 ASSERT(IsIdentifier()); | 10027 ASSERT(IsIdentifier()); |
10031 ConsumeToken(); | 10028 ConsumeToken(); |
10032 if (CurrentToken() == Token::kPERIOD) { | 10029 if (CurrentToken() == Token::kPERIOD) { |
10033 ConsumeToken(); // Consume the kPERIOD token. | 10030 ConsumeToken(); // Consume the kPERIOD token. |
10034 ExpectIdentifier("identifier expected after '.'"); | 10031 ExpectIdentifier("identifier expected after '.'"); |
10035 } | 10032 } |
10036 } | 10033 } |
10037 | 10034 |
10038 } // namespace dart | 10035 } // namespace dart |
OLD | NEW |