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

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

Issue 10696155: Allocate types in proper heap space. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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') | no next file » | 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 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 // We either parse a type or assume that no type is specified. 1046 // We either parse a type or assume that no type is specified.
1047 if ((follower == Token::kLT) || // Parameterized type. 1047 if ((follower == Token::kLT) || // Parameterized type.
1048 (follower == Token::kPERIOD) || // Qualified class name of type. 1048 (follower == Token::kPERIOD) || // Qualified class name of type.
1049 Token::IsIdentifier(follower) || // Parameter name following a type. 1049 Token::IsIdentifier(follower) || // Parameter name following a type.
1050 (follower == Token::kTHIS)) { // Field parameter following a type. 1050 (follower == Token::kTHIS)) { // Field parameter following a type.
1051 // The types of formal parameters are never ignored, even in unchecked 1051 // The types of formal parameters are never ignored, even in unchecked
1052 // mode, because they are part of the function type of closurized 1052 // mode, because they are part of the function type of closurized
1053 // functions appearing in type tests with typedefs. 1053 // functions appearing in type tests with typedefs.
1054 parameter.type = &AbstractType::ZoneHandle( 1054 parameter.type = &AbstractType::ZoneHandle(
1055 ParseType(is_top_level_ ? ClassFinalizer::kTryResolve : 1055 ParseType(is_top_level_ ? ClassFinalizer::kTryResolve :
1056 ClassFinalizer::kFinalize)); 1056 ClassFinalizer::kCanonicalize));
1057 } else { 1057 } else {
1058 parameter.type = &Type::ZoneHandle(Type::DynamicType()); 1058 parameter.type = &Type::ZoneHandle(Type::DynamicType());
1059 } 1059 }
1060 } 1060 }
1061 if (!this_seen && (CurrentToken() == Token::kTHIS)) { 1061 if (!this_seen && (CurrentToken() == Token::kTHIS)) {
1062 ConsumeToken(); 1062 ConsumeToken();
1063 ExpectToken(Token::kPERIOD); 1063 ExpectToken(Token::kPERIOD);
1064 this_seen = true; 1064 this_seen = true;
1065 parameter.is_field_initializer = true; 1065 parameter.is_field_initializer = true;
1066 } 1066 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 script_); 1119 script_);
1120 // Record the function signature class in the current library. 1120 // Record the function signature class in the current library.
1121 library_.AddClass(signature_class); 1121 library_.AddClass(signature_class);
1122 } else { 1122 } else {
1123 signature_function.set_signature_class(signature_class); 1123 signature_function.set_signature_class(signature_class);
1124 } 1124 }
1125 ASSERT(signature_function.signature_class() == signature_class.raw()); 1125 ASSERT(signature_function.signature_class() == signature_class.raw());
1126 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); 1126 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType());
1127 if (!is_top_level_ && !signature_type.IsFinalized()) { 1127 if (!is_top_level_ && !signature_type.IsFinalized()) {
1128 signature_type ^= ClassFinalizer::FinalizeType( 1128 signature_type ^= ClassFinalizer::FinalizeType(
1129 signature_class, signature_type, ClassFinalizer::kFinalize); 1129 signature_class, signature_type, ClassFinalizer::kCanonicalize);
1130 } 1130 }
1131 // The type of the parameter is now the signature type. 1131 // The type of the parameter is now the signature type.
1132 parameter.type = &signature_type; 1132 parameter.type = &signature_type;
1133 } 1133 }
1134 } 1134 }
1135 1135
1136 if (CurrentToken() == Token::kASSIGN) { 1136 if (CurrentToken() == Token::kASSIGN) {
1137 if (!params->has_named_optional_parameters || 1137 if (!params->has_named_optional_parameters ||
1138 !allow_explicit_default_value) { 1138 !allow_explicit_default_value) {
1139 ErrorMsg("parameter must not specify a default value"); 1139 ErrorMsg("parameter must not specify a default value");
(...skipping 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 } 4158 }
4159 4159
4160 4160
4161 // Returns ast nodes of the variable initialization. Variables without an 4161 // Returns ast nodes of the variable initialization. Variables without an
4162 // explicit initializer are initialized to null. If several variables are 4162 // explicit initializer are initialized to null. If several variables are
4163 // declared, the individual initializers are collected in a sequence node. 4163 // declared, the individual initializers are collected in a sequence node.
4164 AstNode* Parser::ParseVariableDeclarationList() { 4164 AstNode* Parser::ParseVariableDeclarationList() {
4165 TRACE_PARSER("ParseVariableDeclarationList"); 4165 TRACE_PARSER("ParseVariableDeclarationList");
4166 bool is_final = (CurrentToken() == Token::kFINAL); 4166 bool is_final = (CurrentToken() == Token::kFINAL);
4167 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType( 4167 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType(
4168 FLAG_enable_type_checks ? ClassFinalizer::kFinalize : 4168 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize :
4169 ClassFinalizer::kIgnore)); 4169 ClassFinalizer::kIgnore));
4170 if (!IsIdentifier()) { 4170 if (!IsIdentifier()) {
4171 ErrorMsg("identifier expected"); 4171 ErrorMsg("identifier expected");
4172 } 4172 }
4173 4173
4174 AstNode* initializers = ParseVariableDeclaration(type, is_final); 4174 AstNode* initializers = ParseVariableDeclaration(type, is_final);
4175 ASSERT(initializers != NULL); 4175 ASSERT(initializers != NULL);
4176 while (CurrentToken() == Token::kCOMMA) { 4176 while (CurrentToken() == Token::kCOMMA) {
4177 ConsumeToken(); 4177 ConsumeToken();
4178 if (!IsIdentifier()) { 4178 if (!IsIdentifier()) {
(...skipping 16 matching lines...) Expand all
4195 AbstractType& result_type = AbstractType::Handle(); 4195 AbstractType& result_type = AbstractType::Handle();
4196 const String* variable_name = NULL; 4196 const String* variable_name = NULL;
4197 const String* function_name = NULL; 4197 const String* function_name = NULL;
4198 4198
4199 result_type = Type::DynamicType(); 4199 result_type = Type::DynamicType();
4200 if (CurrentToken() == Token::kVOID) { 4200 if (CurrentToken() == Token::kVOID) {
4201 ConsumeToken(); 4201 ConsumeToken();
4202 result_type = Type::VoidType(); 4202 result_type = Type::VoidType();
4203 } else if ((CurrentToken() == Token::kIDENT) && 4203 } else if ((CurrentToken() == Token::kIDENT) &&
4204 (LookaheadToken(1) != Token::kLPAREN)) { 4204 (LookaheadToken(1) != Token::kLPAREN)) {
4205 result_type = ParseType(ClassFinalizer::kFinalize); 4205 result_type = ParseType(ClassFinalizer::kCanonicalize);
4206 } 4206 }
4207 const intptr_t ident_pos = TokenPos(); 4207 const intptr_t ident_pos = TokenPos();
4208 if (IsIdentifier()) { 4208 if (IsIdentifier()) {
4209 variable_name = CurrentLiteral(); 4209 variable_name = CurrentLiteral();
4210 function_name = variable_name; 4210 function_name = variable_name;
4211 ConsumeToken(); 4211 ConsumeToken();
4212 } else { 4212 } else {
4213 if (!is_literal) { 4213 if (!is_literal) {
4214 ErrorMsg("function name expected"); 4214 ErrorMsg("function name expected");
4215 } 4215 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4322 // We need to create a new type for proper finalization, since the existing 4322 // We need to create a new type for proper finalization, since the existing
4323 // type is already marked as finalized. 4323 // type is already marked as finalized.
4324 Type& signature_type = Type::Handle(signature_class.SignatureType()); 4324 Type& signature_type = Type::Handle(signature_class.SignatureType());
4325 const AbstractTypeArguments& signature_type_arguments = 4325 const AbstractTypeArguments& signature_type_arguments =
4326 AbstractTypeArguments::Handle(signature_type.arguments()); 4326 AbstractTypeArguments::Handle(signature_type.arguments());
4327 4327
4328 // Since the signature type is cached by the signature class, it may have 4328 // Since the signature type is cached by the signature class, it may have
4329 // been finalized already. 4329 // been finalized already.
4330 if (!signature_type.IsFinalized()) { 4330 if (!signature_type.IsFinalized()) {
4331 signature_type ^= ClassFinalizer::FinalizeType( 4331 signature_type ^= ClassFinalizer::FinalizeType(
4332 signature_class, signature_type, ClassFinalizer::kFinalize); 4332 signature_class, signature_type, ClassFinalizer::kCanonicalize);
4333 // The call to ClassFinalizer::FinalizeType may have 4333 // The call to ClassFinalizer::FinalizeType may have
4334 // extended the vector of type arguments. 4334 // extended the vector of type arguments.
4335 ASSERT(signature_type_arguments.IsNull() || 4335 ASSERT(signature_type_arguments.IsNull() ||
4336 (signature_type_arguments.Length() == 4336 (signature_type_arguments.Length() ==
4337 signature_class.NumTypeArguments())); 4337 signature_class.NumTypeArguments()));
4338 // The signature_class should not have changed. 4338 // The signature_class should not have changed.
4339 ASSERT(signature_type.type_class() == signature_class.raw()); 4339 ASSERT(signature_type.type_class() == signature_class.raw());
4340 } 4340 }
4341 4341
4342 // Now patch the function type of the variable. 4342 // Now patch the function type of the variable.
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
4889 bool is_final = (CurrentToken() == Token::kFINAL); 4889 bool is_final = (CurrentToken() == Token::kFINAL);
4890 const String* loop_var_name = NULL; 4890 const String* loop_var_name = NULL;
4891 LocalVariable* loop_var = NULL; 4891 LocalVariable* loop_var = NULL;
4892 intptr_t loop_var_pos = 0; 4892 intptr_t loop_var_pos = 0;
4893 if (LookaheadToken(1) == Token::kIN) { 4893 if (LookaheadToken(1) == Token::kIN) {
4894 loop_var_pos = TokenPos(); 4894 loop_var_pos = TokenPos();
4895 loop_var_name = ExpectIdentifier("variable name expected"); 4895 loop_var_name = ExpectIdentifier("variable name expected");
4896 } else { 4896 } else {
4897 // The case without a type is handled above, so require a type here. 4897 // The case without a type is handled above, so require a type here.
4898 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType( 4898 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType(
4899 FLAG_enable_type_checks ? ClassFinalizer::kFinalize : 4899 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize :
4900 ClassFinalizer::kIgnore)); 4900 ClassFinalizer::kIgnore));
4901 loop_var_pos = TokenPos(); 4901 loop_var_pos = TokenPos();
4902 loop_var_name = ExpectIdentifier("variable name expected"); 4902 loop_var_name = ExpectIdentifier("variable name expected");
4903 loop_var = new LocalVariable(loop_var_pos, *loop_var_name, type); 4903 loop_var = new LocalVariable(loop_var_pos, *loop_var_name, type);
4904 if (is_final) { 4904 if (is_final) {
4905 loop_var->set_is_final(); 4905 loop_var->set_is_final();
4906 } 4906 }
4907 } 4907 }
4908 ExpectToken(Token::kIN); 4908 ExpectToken(Token::kIN);
4909 const intptr_t collection_pos = TokenPos(); 4909 const intptr_t collection_pos = TokenPos();
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
5145 5145
5146 5146
5147 // Parse the parameter specified in the catch clause. 5147 // Parse the parameter specified in the catch clause.
5148 void Parser::ParseCatchParameter(CatchParamDesc* catch_param) { 5148 void Parser::ParseCatchParameter(CatchParamDesc* catch_param) {
5149 TRACE_PARSER("ParseCatchParameter"); 5149 TRACE_PARSER("ParseCatchParameter");
5150 ASSERT(catch_param != NULL); 5150 ASSERT(catch_param != NULL);
5151 catch_param->is_final = (CurrentToken() == Token::kFINAL); 5151 catch_param->is_final = (CurrentToken() == Token::kFINAL);
5152 // The type of the catch parameter must always be resolved, even in unchecked 5152 // The type of the catch parameter must always be resolved, even in unchecked
5153 // mode. 5153 // mode.
5154 catch_param->type = &AbstractType::ZoneHandle( 5154 catch_param->type = &AbstractType::ZoneHandle(
5155 ParseFinalVarOrType(ClassFinalizer::kFinalizeWellFormed)); 5155 ParseFinalVarOrType(ClassFinalizer::kCanonicalizeWellFormed));
5156 catch_param->token_pos = TokenPos(); 5156 catch_param->token_pos = TokenPos();
5157 catch_param->var = ExpectIdentifier("identifier expected"); 5157 catch_param->var = ExpectIdentifier("identifier expected");
5158 } 5158 }
5159 5159
5160 5160
5161 // Populate local scope of the catch block with the catch parameters. 5161 // Populate local scope of the catch block with the catch parameters.
5162 void Parser::AddCatchParamsToScope(const CatchParamDesc& exception_param, 5162 void Parser::AddCatchParamsToScope(const CatchParamDesc& exception_param,
5163 const CatchParamDesc& stack_trace_param, 5163 const CatchParamDesc& stack_trace_param,
5164 LocalScope* scope) { 5164 LocalScope* scope) {
5165 ASSERT(exception_param.var != NULL); 5165 ASSERT(exception_param.var != NULL);
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
5980 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { 5980 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) {
5981 right_operand = ParseBinaryExpr(current_preced + 1); 5981 right_operand = ParseBinaryExpr(current_preced + 1);
5982 } else { 5982 } else {
5983 // For 'is' and 'as' we expect the right operand to be a type. 5983 // For 'is' and 'as' we expect the right operand to be a type.
5984 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { 5984 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) {
5985 ConsumeToken(); 5985 ConsumeToken();
5986 op_kind = Token::kISNOT; 5986 op_kind = Token::kISNOT;
5987 } 5987 }
5988 const intptr_t type_pos = TokenPos(); 5988 const intptr_t type_pos = TokenPos();
5989 const AbstractType& type = 5989 const AbstractType& type =
5990 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kFinalize)); 5990 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kCanonicalize));
5991 if (!type.IsInstantiated() && 5991 if (!type.IsInstantiated() &&
5992 (current_block_->scope->function_level() > 0)) { 5992 (current_block_->scope->function_level() > 0)) {
5993 // Make sure that the instantiator is captured. 5993 // Make sure that the instantiator is captured.
5994 CaptureReceiver(); 5994 CaptureReceiver();
5995 } 5995 }
5996 right_operand = new TypeNode(type_pos, type); 5996 right_operand = new TypeNode(type_pos, type);
5997 if ((op_kind == Token::kIS) && type.IsMalformed()) { 5997 if ((op_kind == Token::kIS) && type.IsMalformed()) {
5998 // Note that a type error is thrown even if the tested value is null 5998 // Note that a type error is thrown even if the tested value is null
5999 // in a type test. However, no cast exception is thrown if the value 5999 // in a type test. However, no cast exception is thrown if the value
6000 // is null in a type cast. 6000 // is null in a type cast.
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
6880 LibraryPrefix::Handle(unresolved_class.library_prefix()); 6880 LibraryPrefix::Handle(unresolved_class.library_prefix());
6881 // Local lookup in library prefix scope. 6881 // Local lookup in library prefix scope.
6882 resolved_type_class = lib_prefix.LookupLocalClass(unresolved_class_name); 6882 resolved_type_class = lib_prefix.LookupLocalClass(unresolved_class_name);
6883 } 6883 }
6884 // At this point, we can only have a parameterized_type. 6884 // At this point, we can only have a parameterized_type.
6885 Type& parameterized_type = Type::Handle(); 6885 Type& parameterized_type = Type::Handle();
6886 parameterized_type ^= type->raw(); 6886 parameterized_type ^= type->raw();
6887 if (!resolved_type_class.IsNull()) { 6887 if (!resolved_type_class.IsNull()) {
6888 // Replace unresolved class with resolved type class. 6888 // Replace unresolved class with resolved type class.
6889 parameterized_type.set_type_class(resolved_type_class); 6889 parameterized_type.set_type_class(resolved_type_class);
6890 } else if (finalization >= ClassFinalizer::kFinalize) { 6890 } else if (finalization >= ClassFinalizer::kCanonicalize) {
6891 // The type is malformed. 6891 // The type is malformed.
6892 ClassFinalizer::FinalizeMalformedType( 6892 ClassFinalizer::FinalizeMalformedType(
6893 Error::Handle(), // No previous error. 6893 Error::Handle(), // No previous error.
6894 current_class(), parameterized_type, finalization, 6894 current_class(), parameterized_type, finalization,
6895 "type '%s' is not loaded", 6895 "type '%s' is not loaded",
6896 String::Handle(parameterized_type.Name()).ToCString()); 6896 String::Handle(parameterized_type.Name()).ToCString());
6897 } 6897 }
6898 } 6898 }
6899 // Resolve type arguments, if any. 6899 // Resolve type arguments, if any.
6900 const AbstractTypeArguments& arguments = 6900 const AbstractTypeArguments& arguments =
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
7443 if (FLAG_enable_type_checks && !malformed_error.IsNull()) { 7443 if (FLAG_enable_type_checks && !malformed_error.IsNull()) {
7444 Type& parameterized_type = Type::Handle(); 7444 Type& parameterized_type = Type::Handle();
7445 parameterized_type ^= type.raw(); 7445 parameterized_type ^= type.raw();
7446 parameterized_type.set_type_class(Class::Handle(Object::dynamic_class())); 7446 parameterized_type.set_type_class(Class::Handle(Object::dynamic_class()));
7447 parameterized_type.set_arguments(AbstractTypeArguments::Handle()); 7447 parameterized_type.set_arguments(AbstractTypeArguments::Handle());
7448 parameterized_type.set_malformed_error(malformed_error); 7448 parameterized_type.set_malformed_error(malformed_error);
7449 } 7449 }
7450 if (finalization >= ClassFinalizer::kTryResolve) { 7450 if (finalization >= ClassFinalizer::kTryResolve) {
7451 const Class& scope_class = Class::Handle(TypeParametersScopeClass()); 7451 const Class& scope_class = Class::Handle(TypeParametersScopeClass());
7452 ResolveTypeFromClass(scope_class, finalization, &type); 7452 ResolveTypeFromClass(scope_class, finalization, &type);
7453 if (finalization >= ClassFinalizer::kFinalize) { 7453 if (finalization >= ClassFinalizer::kCanonicalize) {
7454 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); 7454 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization);
7455 } 7455 }
7456 } 7456 }
7457 return type.raw(); 7457 return type.raw();
7458 } 7458 }
7459 7459
7460 7460
7461 void Parser::CheckConstructorCallTypeArguments( 7461 void Parser::CheckConstructorCallTypeArguments(
7462 intptr_t pos, Function& constructor, 7462 intptr_t pos, Function& constructor,
7463 const AbstractTypeArguments& type_arguments) { 7463 const AbstractTypeArguments& type_arguments) {
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
7825 TRACE_PARSER("ParseCompoundLiteral"); 7825 TRACE_PARSER("ParseCompoundLiteral");
7826 bool is_const = false; 7826 bool is_const = false;
7827 if (CurrentToken() == Token::kCONST) { 7827 if (CurrentToken() == Token::kCONST) {
7828 is_const = true; 7828 is_const = true;
7829 ConsumeToken(); 7829 ConsumeToken();
7830 } 7830 }
7831 const intptr_t type_pos = TokenPos(); 7831 const intptr_t type_pos = TokenPos();
7832 Error& malformed_error = Error::Handle(); 7832 Error& malformed_error = Error::Handle();
7833 AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle( 7833 AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle(
7834 ParseTypeArguments(&malformed_error, 7834 ParseTypeArguments(&malformed_error,
7835 ClassFinalizer::kFinalizeWellFormed)); 7835 ClassFinalizer::kCanonicalizeWellFormed));
7836 // Map and List interfaces do not declare bounds on their type parameters, so 7836 // Map and List interfaces do not declare bounds on their type parameters, so
7837 // we should never see a malformed type error here. 7837 // we should never see a malformed type error here.
7838 // Note that a bound error is the only possible malformed type error returned 7838 // Note that a bound error is the only possible malformed type error returned
7839 // when requesting kFinalizeWellFormed type finalization. 7839 // when requesting kCanonicalizeWellFormed type finalization.
7840 ASSERT(malformed_error.IsNull()); 7840 ASSERT(malformed_error.IsNull());
7841 AstNode* primary = NULL; 7841 AstNode* primary = NULL;
7842 if ((CurrentToken() == Token::kLBRACK) || 7842 if ((CurrentToken() == Token::kLBRACK) ||
7843 (CurrentToken() == Token::kINDEX)) { 7843 (CurrentToken() == Token::kINDEX)) {
7844 primary = ParseListLiteral(type_pos, is_const, type_arguments); 7844 primary = ParseListLiteral(type_pos, is_const, type_arguments);
7845 } else if (CurrentToken() == Token::kLBRACE) { 7845 } else if (CurrentToken() == Token::kLBRACE) {
7846 primary = ParseMapLiteral(type_pos, is_const, type_arguments); 7846 primary = ParseMapLiteral(type_pos, is_const, type_arguments);
7847 } else { 7847 } else {
7848 ErrorMsg("unexpected token %s", Token::Str(CurrentToken())); 7848 ErrorMsg("unexpected token %s", Token::Str(CurrentToken()));
7849 } 7849 }
(...skipping 21 matching lines...) Expand all
7871 TRACE_PARSER("ParseNewOperator"); 7871 TRACE_PARSER("ParseNewOperator");
7872 const intptr_t new_pos = TokenPos(); 7872 const intptr_t new_pos = TokenPos();
7873 ASSERT((CurrentToken() == Token::kNEW) || (CurrentToken() == Token::kCONST)); 7873 ASSERT((CurrentToken() == Token::kNEW) || (CurrentToken() == Token::kCONST));
7874 bool is_const = (CurrentToken() == Token::kCONST); 7874 bool is_const = (CurrentToken() == Token::kCONST);
7875 ConsumeToken(); 7875 ConsumeToken();
7876 if (!IsIdentifier()) { 7876 if (!IsIdentifier()) {
7877 ErrorMsg("type name expected"); 7877 ErrorMsg("type name expected");
7878 } 7878 }
7879 intptr_t type_pos = TokenPos(); 7879 intptr_t type_pos = TokenPos();
7880 const AbstractType& type = AbstractType::Handle( 7880 const AbstractType& type = AbstractType::Handle(
7881 ParseType(ClassFinalizer::kFinalizeWellFormed)); 7881 ParseType(ClassFinalizer::kCanonicalizeWellFormed));
7882 // Malformed bounds never result in a compile time error, therefore, the 7882 // Malformed bounds never result in a compile time error, therefore, the
7883 // parsed type may be malformed although we requested kFinalizeWellFormed. 7883 // parsed type may be malformed although we requested kCanonicalizeWellFormed.
7884 // In that case, we throw a dynamic type error instead of calling the 7884 // In that case, we throw a dynamic type error instead of calling the
7885 // constructor. 7885 // constructor.
7886 if (type.IsTypeParameter()) { 7886 if (type.IsTypeParameter()) {
7887 ErrorMsg(type_pos, 7887 ErrorMsg(type_pos,
7888 "type parameter '%s' cannot be instantiated", 7888 "type parameter '%s' cannot be instantiated",
7889 String::Handle(type.Name()).ToCString()); 7889 String::Handle(type.Name()).ToCString());
7890 } 7890 }
7891 if (type.IsDynamicType()) { 7891 if (type.IsDynamicType()) {
7892 ErrorMsg(type_pos, "Dynamic cannot be instantiated"); 7892 ErrorMsg(type_pos, "Dynamic cannot be instantiated");
7893 } 7893 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
8005 8005
8006 // Now that the constructor to be called is identified, finalize the type 8006 // Now that the constructor to be called is identified, finalize the type
8007 // argument vector to be passed. 8007 // argument vector to be passed.
8008 // The type argument vector of the parsed type was finalized in ParseType. 8008 // The type argument vector of the parsed type was finalized in ParseType.
8009 // If the constructor class was changed from the interface class to the 8009 // If the constructor class was changed from the interface class to the
8010 // factory class, we need to finalize the type argument vector again, because 8010 // factory class, we need to finalize the type argument vector again, because
8011 // it may be longer due to the factory class extending a class, or/and because 8011 // it may be longer due to the factory class extending a class, or/and because
8012 // the bounds on the factory class may be tighter than on the interface. 8012 // the bounds on the factory class may be tighter than on the interface.
8013 if (constructor_class.raw() != type_class.raw()) { 8013 if (constructor_class.raw() != type_class.raw()) {
8014 const intptr_t num_type_parameters = constructor_class.NumTypeParameters(); 8014 const intptr_t num_type_parameters = constructor_class.NumTypeParameters();
8015 // TODO(regis): Temporary type args should be allocated in new gen heap.
8016 TypeArguments& temp_type_arguments = TypeArguments::Handle(); 8015 TypeArguments& temp_type_arguments = TypeArguments::Handle();
8017 if (!type_arguments.IsNull()) { 8016 if (!type_arguments.IsNull()) {
8018 // Copy the parsed type arguments starting at offset 0, because interfaces 8017 // Copy the parsed type arguments starting at offset 0, because interfaces
8019 // have no super types. 8018 // have no super types.
8020 ASSERT(type_class.NumTypeArguments() == type_class.NumTypeParameters()); 8019 ASSERT(type_class.NumTypeArguments() == type_class.NumTypeParameters());
8021 const intptr_t num_type_arguments = type_arguments.Length(); 8020 const intptr_t num_type_arguments = type_arguments.Length();
8022 temp_type_arguments = TypeArguments::New(num_type_parameters); 8021 temp_type_arguments = TypeArguments::New(num_type_parameters, Heap::kNew);
8023 AbstractType& type_argument = AbstractType::Handle(); 8022 AbstractType& type_argument = AbstractType::Handle();
8024 for (intptr_t i = 0; i < num_type_parameters; i++) { 8023 for (intptr_t i = 0; i < num_type_parameters; i++) {
8025 if (i < num_type_arguments) { 8024 if (i < num_type_arguments) {
8026 type_argument = type_arguments.TypeAt(i); 8025 type_argument = type_arguments.TypeAt(i);
8027 } else { 8026 } else {
8028 type_argument = Type::DynamicType(); 8027 type_argument = Type::DynamicType();
8029 } 8028 }
8030 temp_type_arguments.SetTypeAt(i, type_argument); 8029 temp_type_arguments.SetTypeAt(i, type_argument);
8031 } 8030 }
8032 } 8031 }
8033 // TODO(regis): Temporary type should be allocated in new gen heap. 8032 Type& temp_type = Type::Handle(Type::New(
8034 Type& temp_type = Type::Handle( 8033 constructor_class, temp_type_arguments, type.token_pos(), Heap::kNew));
8035 Type::New(constructor_class, temp_type_arguments, type.token_pos())); 8034 // No need to canonicalize temporary type.
8036 temp_type ^= ClassFinalizer::FinalizeType( 8035 temp_type ^= ClassFinalizer::FinalizeType(
8037 current_class(), temp_type, ClassFinalizer::kFinalize); 8036 current_class(), temp_type, ClassFinalizer::kFinalize);
8038 // The type argument vector may have been expanded with the type arguments 8037 // The type argument vector may have been expanded with the type arguments
8039 // of the super type when finalizing the temporary type. 8038 // of the super type when finalizing the temporary type.
8040 type_arguments = temp_type.arguments(); 8039 type_arguments = temp_type.arguments();
8041 // The type parameter bounds of the factory class may be more specific than 8040 // The type parameter bounds of the factory class may be more specific than
8042 // the type parameter bounds of the interface class. Therefore, although 8041 // the type parameter bounds of the interface class. Therefore, although
8043 // type was not malformed, temp_type may be malformed. 8042 // type was not malformed, temp_type may be malformed.
8044 if (!type.IsMalformed() && temp_type.IsMalformed()) { 8043 if (!type.IsMalformed() && temp_type.IsMalformed()) {
8045 const Error& error = Error::Handle(temp_type.malformed_error()); 8044 const Error& error = Error::Handle(temp_type.malformed_error());
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
8653 void Parser::SkipQualIdent() { 8652 void Parser::SkipQualIdent() {
8654 ASSERT(IsIdentifier()); 8653 ASSERT(IsIdentifier());
8655 ConsumeToken(); 8654 ConsumeToken();
8656 if (CurrentToken() == Token::kPERIOD) { 8655 if (CurrentToken() == Token::kPERIOD) {
8657 ConsumeToken(); // Consume the kPERIOD token. 8656 ConsumeToken(); // Consume the kPERIOD token.
8658 ExpectIdentifier("identifier expected after '.'"); 8657 ExpectIdentifier("identifier expected after '.'");
8659 } 8658 }
8660 } 8659 }
8661 8660
8662 } // namespace dart 8661 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698