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

Side by Side Diff: runtime/vm/parser.cc

Issue 9368032: Represent declared type parameters of a class as an array of TypeParameter (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2601 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 } 2612 }
2613 SetPosition(saved_pos); 2613 SetPosition(saved_pos);
2614 return is_alias_name; 2614 return is_alias_name;
2615 } 2615 }
2616 2616
2617 2617
2618 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { 2618 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) {
2619 TRACE_PARSER("ParseFunctionTypeAlias"); 2619 TRACE_PARSER("ParseFunctionTypeAlias");
2620 ExpectToken(Token::kTYPEDEF); 2620 ExpectToken(Token::kTYPEDEF);
2621 2621
2622 // Allocate an interface to hold the type parameters and their 'extends' 2622 // Allocate an interface to hold the type parameters and their bounds.
2623 // constraints. Make it the owner of the function type descriptor. 2623 // Make it the owner of the function type descriptor.
2624 const Class& alias_owner = Class::Handle( 2624 const Class& alias_owner = Class::Handle(
2625 Class::New(String::Handle(String::NewSymbol(":alias_owner")), 2625 Class::New(String::Handle(String::NewSymbol(":alias_owner")),
2626 Script::Handle(), 2626 Script::Handle(),
2627 token_index_)); 2627 token_index_));
2628 alias_owner.set_is_interface(); 2628 alias_owner.set_is_interface();
2629 alias_owner.set_library(library_); 2629 alias_owner.set_library(library_);
2630 set_current_class(alias_owner); 2630 set_current_class(alias_owner);
2631 2631
2632 // Parse the result type of the function type. 2632 // Parse the result type of the function type.
2633 AbstractType& result_type = Type::Handle(Type::DynamicType()); 2633 AbstractType& result_type = Type::Handle(Type::DynamicType());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 script_, 2770 script_,
2771 factory_name.ident_pos)); 2771 factory_name.ident_pos));
2772 factory_class.set_library(library_); 2772 factory_class.set_library(library_);
2773 factory_class.set_is_finalized(); 2773 factory_class.set_is_finalized();
2774 ParseTypeParameters(factory_class); 2774 ParseTypeParameters(factory_class);
2775 unresolved_factory_class.set_factory_signature_class(factory_class); 2775 unresolved_factory_class.set_factory_signature_class(factory_class);
2776 interface.set_factory_class(unresolved_factory_class); 2776 interface.set_factory_class(unresolved_factory_class);
2777 // If a type parameter list is included in the default factory clause (it 2777 // If a type parameter list is included in the default factory clause (it
2778 // can be omitted), verify that it matches the list of type parameters of 2778 // can be omitted), verify that it matches the list of type parameters of
2779 // the interface in number and names. 2779 // the interface in number and names.
2780 const intptr_t num_default_type_params = factory_class.NumTypeParameters(); 2780 if (factory_class.NumTypeParameters() > 0) {
2781 if (num_default_type_params > 0) { 2781 const TypeArguments& interface_type_parameters =
2782 String& interface_type_param_name = String::Handle(); 2782 TypeArguments::Handle(interface.type_parameters());
2783 String& factory_type_param_name = String::Handle(); 2783 const TypeArguments& factory_type_parameters =
2784 const Array& interface_type_param_names = 2784 TypeArguments::Handle(factory_class.type_parameters());
2785 Array::Handle(interface.type_parameters()); 2785 if (!AbstractTypeArguments::AreEqual(interface_type_parameters,
2786 const Array& factory_type_param_names = 2786 factory_type_parameters)) {
2787 Array::Handle(factory_class.type_parameters());
2788 bool mismatch = interface.NumTypeParameters() != num_default_type_params;
2789 for (intptr_t i = 0; !mismatch && (i < num_default_type_params); i++) {
2790 interface_type_param_name ^= interface_type_param_names.At(i);
2791 factory_type_param_name ^= factory_type_param_names.At(i);
2792 if (!interface_type_param_name.Equals(factory_type_param_name)) {
2793 mismatch = true;
2794 }
2795 }
2796 if (mismatch) {
2797 const String& interface_name = String::Handle(interface.Name()); 2787 const String& interface_name = String::Handle(interface.Name());
2798 ErrorMsg(factory_name.ident_pos, 2788 ErrorMsg(factory_name.ident_pos,
2799 "mismatch in number or names of type parameters between " 2789 "mismatch in number or names of type parameters between "
2800 "interface '%s' and default factory class '%s'.\n", 2790 "interface '%s' and default factory class '%s'.\n",
2801 interface_name.ToCString(), 2791 interface_name.ToCString(),
2802 factory_name.ident->ToCString()); 2792 factory_name.ident->ToCString());
2803 } 2793 }
2804 } 2794 }
2805 } 2795 }
2806 2796
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 ConsumeToken(); 2853 ConsumeToken();
2864 ExpectIdentifier("name expected"); 2854 ExpectIdentifier("name expected");
2865 } 2855 }
2866 SkipTypeArguments(); 2856 SkipTypeArguments();
2867 } 2857 }
2868 } 2858 }
2869 2859
2870 2860
2871 void Parser::ParseTypeParameters(const Class& cls) { 2861 void Parser::ParseTypeParameters(const Class& cls) {
2872 if (CurrentToken() == Token::kLT) { 2862 if (CurrentToken() == Token::kLT) {
2873 GrowableArray<String*> type_parameters; 2863 GrowableArray<AbstractType*> type_parameters_array;
2874 GrowableArray<AbstractType*> type_parameter_extends; 2864 GrowableArray<AbstractType*> bounds_array;
2865 intptr_t index = 0;
2875 do { 2866 do {
2876 ConsumeToken(); 2867 ConsumeToken();
2877 if (CurrentToken() != Token::kIDENT) { 2868 if (CurrentToken() != Token::kIDENT) {
2878 ErrorMsg("type parameter name expected"); 2869 ErrorMsg("type parameter name expected");
2879 } 2870 }
2880 String& type_parameter_name = *CurrentLiteral(); 2871 String& type_parameter_name = *CurrentLiteral();
2872 AbstractType& type_parameter = TypeParameter::ZoneHandle(
2873 TypeParameter::New(index, type_parameter_name, token_index_));
2881 ConsumeToken(); 2874 ConsumeToken();
2882 AbstractType& type_extends = Type::ZoneHandle(Type::DynamicType()); 2875 AbstractType& bound = Type::ZoneHandle(Type::DynamicType());
2883 if (CurrentToken() == Token::kEXTENDS) { 2876 if (CurrentToken() == Token::kEXTENDS) {
2884 ConsumeToken(); 2877 ConsumeToken();
2885 type_extends = ParseType(kCanResolve); 2878 bound = ParseType(kCanResolve);
2886 } 2879 }
2887 type_parameters.Add(&type_parameter_name); 2880 type_parameters_array.Add(&type_parameter);
2888 type_parameter_extends.Add(&type_extends); 2881 bounds_array.Add(&bound);
2882 index++;
2889 } while (CurrentToken() == Token::kCOMMA); 2883 } while (CurrentToken() == Token::kCOMMA);
2890 Token::Kind token = CurrentToken(); 2884 Token::Kind token = CurrentToken();
2891 if ((token == Token::kGT) || (token == Token::kSHR)) { 2885 if ((token == Token::kGT) || (token == Token::kSHR)) {
2892 ConsumeRightAngleBracket(); 2886 ConsumeRightAngleBracket();
2893 } else { 2887 } else {
2894 ErrorMsg("right angle bracket expected"); 2888 ErrorMsg("right angle bracket expected");
2895 } 2889 }
2896 cls.set_type_parameters(Array::Handle(NewArray<String>(type_parameters))); 2890 const TypeArguments& type_parameters =
2897 const TypeArguments& extends_array = 2891 TypeArguments::Handle(NewTypeArguments(type_parameters_array));
2898 TypeArguments::Handle(NewTypeArguments(type_parameter_extends)); 2892 const TypeArguments& bounds =
2899 cls.set_type_parameter_extends(extends_array); 2893 TypeArguments::Handle(NewTypeArguments(bounds_array));
2894 cls.set_type_parameters(type_parameters);
2895 cls.set_type_parameter_bounds(bounds);
2900 // Try to resolve the upper bounds, which will at least resolve the 2896 // Try to resolve the upper bounds, which will at least resolve the
2901 // referenced type parameters. 2897 // referenced type parameters.
2902 AbstractType& type_extends = AbstractType::Handle(); 2898 AbstractType& bound = AbstractType::Handle();
2903 const intptr_t num_types = extends_array.Length(); 2899 const intptr_t num_types = bounds.Length();
2904 for (intptr_t i = 0; i < num_types; i++) { 2900 for (intptr_t i = 0; i < num_types; i++) {
2905 type_extends = extends_array.TypeAt(i); 2901 bound = bounds.TypeAt(i);
2906 ResolveTypeFromClass(cls, kCanResolve, &type_extends); 2902 ResolveTypeFromClass(cls, kCanResolve, &bound);
2907 extends_array.SetTypeAt(i, type_extends); 2903 bounds.SetTypeAt(i, bound);
2908 } 2904 }
2909 } 2905 }
2910 } 2906 }
2911 2907
2912 2908
2913 RawAbstractTypeArguments* Parser::ParseTypeArguments( 2909 RawAbstractTypeArguments* Parser::ParseTypeArguments(
2914 TypeResolution type_resolution) { 2910 TypeResolution type_resolution) {
2915 if (CurrentToken() == Token::kLT) { 2911 if (CurrentToken() == Token::kLT) {
2916 GrowableArray<AbstractType*> types; 2912 GrowableArray<AbstractType*> types;
2917 do { 2913 do {
(...skipping 3449 matching lines...) Expand 10 before | Expand all | Expand 10 after
6367 const Class& type_class, 6363 const Class& type_class,
6368 const AbstractTypeArguments& type_arguments, 6364 const AbstractTypeArguments& type_arguments,
6369 const Function& constructor, 6365 const Function& constructor,
6370 ArgumentListNode* arguments) { 6366 ArgumentListNode* arguments) {
6371 // +2 for implicit receiver and construction phase arguments. 6367 // +2 for implicit receiver and construction phase arguments.
6372 GrowableArray<const Object*> arg_values(arguments->length() + 2); 6368 GrowableArray<const Object*> arg_values(arguments->length() + 2);
6373 Instance& instance = Instance::Handle(); 6369 Instance& instance = Instance::Handle();
6374 if (!constructor.IsFactory()) { 6370 if (!constructor.IsFactory()) {
6375 instance = Instance::New(type_class); 6371 instance = Instance::New(type_class);
6376 if (!type_arguments.IsNull()) { 6372 if (!type_arguments.IsNull()) {
6377 // TODO(regis): Where should we check the constraints on type parameters? 6373 // TODO(regis): Where should we check the type parameter bounds?
6378 if (!type_arguments.IsInstantiated()) { 6374 if (!type_arguments.IsInstantiated()) {
6379 ErrorMsg("type must be constant in const constructor"); 6375 ErrorMsg("type must be constant in const constructor");
6380 } 6376 }
6381 instance.SetTypeArguments(type_arguments); 6377 instance.SetTypeArguments(type_arguments);
6382 } 6378 }
6383 arg_values.Add(&instance); 6379 arg_values.Add(&instance);
6384 arg_values.Add(&Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 6380 arg_values.Add(&Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
6385 } else { 6381 } else {
6386 // Prepend type_arguments to list of arguments to factory. 6382 // Prepend type_arguments to list of arguments to factory.
6387 ASSERT(type_arguments.IsZoneHandle()); 6383 ASSERT(type_arguments.IsZoneHandle());
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
7760 void Parser::SkipQualIdent() { 7756 void Parser::SkipQualIdent() {
7761 ASSERT(IsIdentifier()); 7757 ASSERT(IsIdentifier());
7762 ConsumeToken(); 7758 ConsumeToken();
7763 if (CurrentToken() == Token::kPERIOD) { 7759 if (CurrentToken() == Token::kPERIOD) {
7764 ConsumeToken(); // Consume the kPERIOD token. 7760 ConsumeToken(); // Consume the kPERIOD token.
7765 ExpectIdentifier("identifier expected after '.'"); 7761 ExpectIdentifier("identifier expected after '.'");
7766 } 7762 }
7767 } 7763 }
7768 7764
7769 } // namespace dart 7765 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698