| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 Clear(); | 421 Clear(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void Clear() { | 424 void Clear() { |
| 425 num_fixed_parameters = 0; | 425 num_fixed_parameters = 0; |
| 426 num_optional_parameters = 0; | 426 num_optional_parameters = 0; |
| 427 has_optional_positional_parameters = false; | 427 has_optional_positional_parameters = false; |
| 428 has_optional_named_parameters = false; | 428 has_optional_named_parameters = false; |
| 429 has_field_initializer = false; | 429 has_field_initializer = false; |
| 430 implicitly_final = false; | 430 implicitly_final = false; |
| 431 skipped = false; |
| 431 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 432 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
| 432 } | 433 } |
| 433 | 434 |
| 434 void AddFinalParameter(intptr_t name_pos, | 435 void AddFinalParameter(intptr_t name_pos, |
| 435 const String* name, | 436 const String* name, |
| 436 const AbstractType* type) { | 437 const AbstractType* type) { |
| 437 this->num_fixed_parameters++; | 438 this->num_fixed_parameters++; |
| 438 ParamDesc param; | 439 ParamDesc param; |
| 439 param.name_pos = name_pos; | 440 param.name_pos = name_pos; |
| 440 param.name = name; | 441 param.name = name; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 453 void SetImplicitlyFinal() { | 454 void SetImplicitlyFinal() { |
| 454 implicitly_final = true; | 455 implicitly_final = true; |
| 455 } | 456 } |
| 456 | 457 |
| 457 int num_fixed_parameters; | 458 int num_fixed_parameters; |
| 458 int num_optional_parameters; | 459 int num_optional_parameters; |
| 459 bool has_optional_positional_parameters; | 460 bool has_optional_positional_parameters; |
| 460 bool has_optional_named_parameters; | 461 bool has_optional_named_parameters; |
| 461 bool has_field_initializer; | 462 bool has_field_initializer; |
| 462 bool implicitly_final; | 463 bool implicitly_final; |
| 464 bool skipped; |
| 463 ZoneGrowableArray<ParamDesc>* parameters; | 465 ZoneGrowableArray<ParamDesc>* parameters; |
| 464 }; | 466 }; |
| 465 | 467 |
| 466 | 468 |
| 467 struct MemberDesc { | 469 struct MemberDesc { |
| 468 MemberDesc() { | 470 MemberDesc() { |
| 469 Clear(); | 471 Clear(); |
| 470 } | 472 } |
| 471 void Clear() { | 473 void Clear() { |
| 472 has_abstract = false; | 474 has_abstract = false; |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 AddFormalParamsToFunction(&func_params, signature_function); | 1175 AddFormalParamsToFunction(&func_params, signature_function); |
| 1174 const String& signature = String::Handle(signature_function.Signature()); | 1176 const String& signature = String::Handle(signature_function.Signature()); |
| 1175 // Lookup the signature class, i.e. the class whose name is the signature. | 1177 // Lookup the signature class, i.e. the class whose name is the signature. |
| 1176 // We only lookup in the current library, but not in its imports, and only | 1178 // We only lookup in the current library, but not in its imports, and only |
| 1177 // create a new canonical signature class if it does not exist yet. | 1179 // create a new canonical signature class if it does not exist yet. |
| 1178 Class& signature_class = Class::ZoneHandle( | 1180 Class& signature_class = Class::ZoneHandle( |
| 1179 library_.LookupLocalClass(signature)); | 1181 library_.LookupLocalClass(signature)); |
| 1180 if (signature_class.IsNull()) { | 1182 if (signature_class.IsNull()) { |
| 1181 signature_class = Class::NewSignatureClass(signature, | 1183 signature_class = Class::NewSignatureClass(signature, |
| 1182 signature_function, | 1184 signature_function, |
| 1183 script_); | 1185 script_, |
| 1184 // Record the function signature class in the current library. | 1186 parameter.name_pos); |
| 1185 library_.AddClass(signature_class); | 1187 // Record the function signature class in the current library, unless |
| 1188 // we are currently skipping a formal parameter list, in which case |
| 1189 // the signature class could remain unfinalized. |
| 1190 if (!params->skipped) { |
| 1191 library_.AddClass(signature_class); |
| 1192 } |
| 1186 } else { | 1193 } else { |
| 1187 signature_function.set_signature_class(signature_class); | 1194 signature_function.set_signature_class(signature_class); |
| 1188 } | 1195 } |
| 1189 ASSERT(signature_function.signature_class() == signature_class.raw()); | 1196 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 1190 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); | 1197 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); |
| 1191 if (!is_top_level_ && !signature_type.IsFinalized()) { | 1198 if (!is_top_level_ && !signature_type.IsFinalized()) { |
| 1192 signature_type ^= ClassFinalizer::FinalizeType( | 1199 signature_type ^= ClassFinalizer::FinalizeType( |
| 1193 signature_class, signature_type, ClassFinalizer::kCanonicalize); | 1200 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
| 1194 } | 1201 } |
| 1195 // The type of the parameter is now the signature type. | 1202 // The type of the parameter is now the signature type. |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 } | 2157 } |
| 2151 } | 2158 } |
| 2152 OpenBlock(); // Block to collect constructor body nodes. | 2159 OpenBlock(); // Block to collect constructor body nodes. |
| 2153 | 2160 |
| 2154 // Insert the implicit super call to the super constructor body. | 2161 // Insert the implicit super call to the super constructor body. |
| 2155 if (super_call != NULL) { | 2162 if (super_call != NULL) { |
| 2156 ArgumentListNode* initializer_args = super_call->arguments(); | 2163 ArgumentListNode* initializer_args = super_call->arguments(); |
| 2157 const Function& super_ctor = super_call->function(); | 2164 const Function& super_ctor = super_call->function(); |
| 2158 // Patch the initializer call so it only executes the super initializer. | 2165 // Patch the initializer call so it only executes the super initializer. |
| 2159 initializer_args->SetNodeAt(1, | 2166 initializer_args->SetNodeAt(1, |
| 2160 new LiteralNode(TokenPos(), | 2167 new LiteralNode(TokenPos(), |
| 2161 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); | 2168 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); |
| 2162 | 2169 |
| 2163 ArgumentListNode* super_call_args = new ArgumentListNode(TokenPos()); | 2170 ArgumentListNode* super_call_args = new ArgumentListNode(TokenPos()); |
| 2164 // First argument is the receiver. | 2171 // First argument is the receiver. |
| 2165 super_call_args->Add(new LoadLocalNode(TokenPos(), receiver)); | 2172 super_call_args->Add(new LoadLocalNode(TokenPos(), receiver)); |
| 2166 // Second argument is the construction phase argument. | 2173 // Second argument is the construction phase argument. |
| 2167 AstNode* phase_parameter = | 2174 AstNode* phase_parameter = |
| 2168 new LiteralNode(TokenPos(), | 2175 new LiteralNode(TokenPos(), |
| 2169 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody))); | 2176 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody))); |
| 2170 super_call_args->Add(phase_parameter); | 2177 super_call_args->Add(phase_parameter); |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3119 ConsumeToken(); | 3126 ConsumeToken(); |
| 3120 } | 3127 } |
| 3121 const intptr_t class_pos = TokenPos(); | 3128 const intptr_t class_pos = TokenPos(); |
| 3122 ExpectToken(Token::kCLASS); | 3129 ExpectToken(Token::kCLASS); |
| 3123 const intptr_t classname_pos = TokenPos(); | 3130 const intptr_t classname_pos = TokenPos(); |
| 3124 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 3131 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 3125 if (FLAG_trace_parser) { | 3132 if (FLAG_trace_parser) { |
| 3126 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); | 3133 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); |
| 3127 } | 3134 } |
| 3128 Class& cls = Class::Handle(); | 3135 Class& cls = Class::Handle(); |
| 3136 TypeArguments& orig_type_parameters = TypeArguments::Handle(); |
| 3129 Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); | 3137 Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); |
| 3130 if (obj.IsNull()) { | 3138 if (obj.IsNull()) { |
| 3131 if (is_patch) { | 3139 if (is_patch) { |
| 3132 ErrorMsg(classname_pos, "missing class '%s' cannot be patched", | 3140 ErrorMsg(classname_pos, "missing class '%s' cannot be patched", |
| 3133 class_name.ToCString()); | 3141 class_name.ToCString()); |
| 3134 } | 3142 } |
| 3135 cls = Class::New(class_name, script_, classname_pos); | 3143 cls = Class::New(class_name, script_, classname_pos); |
| 3136 library_.AddClass(cls); | 3144 library_.AddClass(cls); |
| 3137 } else { | 3145 } else { |
| 3138 if (!obj.IsClass()) { | 3146 if (!obj.IsClass()) { |
| 3139 ErrorMsg(classname_pos, "'%s' is already defined", | 3147 ErrorMsg(classname_pos, "'%s' is already defined", |
| 3140 class_name.ToCString()); | 3148 class_name.ToCString()); |
| 3141 } | 3149 } |
| 3142 cls ^= obj.raw(); | 3150 cls ^= obj.raw(); |
| 3143 if (is_patch) { | 3151 if (is_patch) { |
| 3152 // Preserve and reuse the original type parameters and bounds since the |
| 3153 // ones defined in the patch class will not be finalized. |
| 3154 orig_type_parameters = cls.type_parameters(); |
| 3144 String& patch = String::Handle( | 3155 String& patch = String::Handle( |
| 3145 String::Concat(Symbols::PatchSpace(), class_name)); | 3156 String::Concat(Symbols::PatchSpace(), class_name)); |
| 3146 patch = Symbols::New(patch); | 3157 patch = Symbols::New(patch); |
| 3147 cls = Class::New(patch, script_, classname_pos); | 3158 cls = Class::New(patch, script_, classname_pos); |
| 3148 cls.set_library(library_); | 3159 cls.set_library(library_); |
| 3149 } else { | 3160 } else { |
| 3150 // Not patching a class, but it has been found. This must be one of the | 3161 // Not patching a class, but it has been found. This must be one of the |
| 3151 // pre-registered classes from object.cc or a duplicate definition. | 3162 // pre-registered classes from object.cc or a duplicate definition. |
| 3152 if (cls.functions() != Object::empty_array().raw()) { | 3163 if (cls.functions() != Object::empty_array().raw()) { |
| 3153 ErrorMsg(classname_pos, "class '%s' is already defined", | 3164 ErrorMsg(classname_pos, "class '%s' is already defined", |
| 3154 class_name.ToCString()); | 3165 class_name.ToCString()); |
| 3155 } | 3166 } |
| 3156 // Pre-registered classes need their scripts connected at this time. | 3167 // Pre-registered classes need their scripts connected at this time. |
| 3157 cls.set_script(script_); | 3168 cls.set_script(script_); |
| 3158 } | 3169 } |
| 3159 } | 3170 } |
| 3160 ASSERT(!cls.IsNull()); | 3171 ASSERT(!cls.IsNull()); |
| 3161 ASSERT(cls.functions() == Object::empty_array().raw()); | 3172 ASSERT(cls.functions() == Object::empty_array().raw()); |
| 3162 set_current_class(cls); | 3173 set_current_class(cls); |
| 3163 ParseTypeParameters(cls); | 3174 ParseTypeParameters(cls); |
| 3175 if (is_patch) { |
| 3176 // Check that the new type parameters are identical to the original ones. |
| 3177 const TypeArguments& new_type_parameters = |
| 3178 TypeArguments::Handle(cls.type_parameters()); |
| 3179 const int new_type_params_count = |
| 3180 new_type_parameters.IsNull() ? 0 : new_type_parameters.Length(); |
| 3181 const int orig_type_params_count = |
| 3182 orig_type_parameters.IsNull() ? 0 : orig_type_parameters.Length(); |
| 3183 if (new_type_params_count != orig_type_params_count) { |
| 3184 ErrorMsg(classname_pos, |
| 3185 "class '%s' must be patched with identical type parameters", |
| 3186 class_name.ToCString()); |
| 3187 } |
| 3188 TypeParameter& new_type_param = TypeParameter::Handle(); |
| 3189 TypeParameter& orig_type_param = TypeParameter::Handle(); |
| 3190 String& new_name = String::Handle(); |
| 3191 String& orig_name = String::Handle(); |
| 3192 for (int i = 0; i < new_type_params_count; i++) { |
| 3193 new_type_param ^= new_type_parameters.TypeAt(i); |
| 3194 orig_type_param ^= orig_type_parameters.TypeAt(i); |
| 3195 new_name = new_type_param.name(); |
| 3196 orig_name = orig_type_param.name(); |
| 3197 if (!new_name.Equals(orig_name)) { |
| 3198 ErrorMsg(new_type_param.token_pos(), |
| 3199 "type parameter '%s' of patch class '%s' does not match " |
| 3200 "original type parameter '%s'", |
| 3201 new_name.ToCString(), |
| 3202 class_name.ToCString(), |
| 3203 orig_name.ToCString()); |
| 3204 } |
| 3205 // We do not check that the bounds are repeated. We use the original ones. |
| 3206 // TODO(regis): Should we check? |
| 3207 } |
| 3208 cls.set_type_parameters(orig_type_parameters); |
| 3209 } |
| 3164 Type& super_type = Type::Handle(); | 3210 Type& super_type = Type::Handle(); |
| 3165 if (CurrentToken() == Token::kEXTENDS) { | 3211 if (CurrentToken() == Token::kEXTENDS) { |
| 3166 ConsumeToken(); | 3212 ConsumeToken(); |
| 3167 const intptr_t type_pos = TokenPos(); | 3213 const intptr_t type_pos = TokenPos(); |
| 3168 const AbstractType& type = AbstractType::Handle( | 3214 const AbstractType& type = AbstractType::Handle( |
| 3169 ParseType(ClassFinalizer::kTryResolve)); | 3215 ParseType(ClassFinalizer::kTryResolve)); |
| 3170 if (type.IsTypeParameter()) { | 3216 if (type.IsTypeParameter()) { |
| 3171 ErrorMsg(type_pos, | 3217 ErrorMsg(type_pos, |
| 3172 "class '%s' may not extend type parameter '%s'", | 3218 "class '%s' may not extend type parameter '%s'", |
| 3173 class_name.ToCString(), | 3219 class_name.ToCString(), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3211 array = Array::MakeArray(members.fields()); | 3257 array = Array::MakeArray(members.fields()); |
| 3212 cls.SetFields(array); | 3258 cls.SetFields(array); |
| 3213 | 3259 |
| 3214 // Creating a new array for functions marks the class as parsed. | 3260 // Creating a new array for functions marks the class as parsed. |
| 3215 array = Array::MakeArray(members.functions()); | 3261 array = Array::MakeArray(members.functions()); |
| 3216 cls.SetFunctions(array); | 3262 cls.SetFunctions(array); |
| 3217 | 3263 |
| 3218 if (!is_patch) { | 3264 if (!is_patch) { |
| 3219 pending_classes.Add(cls, Heap::kOld); | 3265 pending_classes.Add(cls, Heap::kOld); |
| 3220 } else { | 3266 } else { |
| 3221 // Lookup the patched class and apply the changes. | 3267 // Apply the changes to the patched class looked up above. |
| 3222 obj = library_.LookupLocalObject(class_name); | 3268 ASSERT(obj.raw() == library_.LookupLocalObject(class_name)); |
| 3269 // The patched class must not be finalized yet. |
| 3270 ASSERT(!Class::Cast(obj).is_finalized()); |
| 3223 const char* err_msg = Class::Cast(obj).ApplyPatch(cls); | 3271 const char* err_msg = Class::Cast(obj).ApplyPatch(cls); |
| 3224 if (err_msg != NULL) { | 3272 if (err_msg != NULL) { |
| 3225 ErrorMsg(classname_pos, "applying patch failed with '%s'", err_msg); | 3273 ErrorMsg(classname_pos, "applying patch failed with '%s'", err_msg); |
| 3226 } | 3274 } |
| 3227 } | 3275 } |
| 3228 } | 3276 } |
| 3229 | 3277 |
| 3230 | 3278 |
| 3231 // Add an implicit constructor if no explicit constructor is present. | 3279 // Add an implicit constructor if no explicit constructor is present. |
| 3232 void Parser::AddImplicitConstructor(ClassDesc* class_desc) { | 3280 void Parser::AddImplicitConstructor(ClassDesc* class_desc) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 SetPosition(saved_pos); | 3371 SetPosition(saved_pos); |
| 3324 return is_alias_name; | 3372 return is_alias_name; |
| 3325 } | 3373 } |
| 3326 | 3374 |
| 3327 | 3375 |
| 3328 void Parser::ParseFunctionTypeAlias( | 3376 void Parser::ParseFunctionTypeAlias( |
| 3329 const GrowableObjectArray& pending_classes) { | 3377 const GrowableObjectArray& pending_classes) { |
| 3330 TRACE_PARSER("ParseFunctionTypeAlias"); | 3378 TRACE_PARSER("ParseFunctionTypeAlias"); |
| 3331 ExpectToken(Token::kTYPEDEF); | 3379 ExpectToken(Token::kTYPEDEF); |
| 3332 | 3380 |
| 3333 // Allocate an abstract class to hold the type parameters and their bounds. | |
| 3334 // Make it the owner of the function type descriptor. | |
| 3335 const Class& alias_owner = Class::Handle( | |
| 3336 Class::New(Symbols::AliasOwner(), Script::Handle(), TokenPos())); | |
| 3337 | |
| 3338 alias_owner.set_is_abstract(); | |
| 3339 alias_owner.set_library(library_); | |
| 3340 set_current_class(alias_owner); | |
| 3341 | |
| 3342 // Parse the result type of the function type. | 3381 // Parse the result type of the function type. |
| 3343 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 3382 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
| 3344 if (CurrentToken() == Token::kVOID) { | 3383 if (CurrentToken() == Token::kVOID) { |
| 3345 ConsumeToken(); | 3384 ConsumeToken(); |
| 3346 result_type = Type::VoidType(); | 3385 result_type = Type::VoidType(); |
| 3347 } else if (!IsFunctionTypeAliasName()) { | 3386 } else if (!IsFunctionTypeAliasName()) { |
| 3348 // Type annotations in typedef are never ignored, even in unchecked mode. | 3387 // Type annotations in typedef are never ignored, even in unchecked mode. |
| 3349 // Wait until we have an owner class before resolving the result type. | 3388 // Wait until we have an owner class before resolving the result type. |
| 3350 result_type = ParseType(ClassFinalizer::kDoNotResolve); | 3389 result_type = ParseType(ClassFinalizer::kDoNotResolve); |
| 3351 } | 3390 } |
| 3352 | 3391 |
| 3353 const intptr_t alias_name_pos = TokenPos(); | 3392 const intptr_t alias_name_pos = TokenPos(); |
| 3354 const String* alias_name = | 3393 const String* alias_name = |
| 3355 ExpectUserDefinedTypeIdentifier("function alias name expected"); | 3394 ExpectUserDefinedTypeIdentifier("function alias name expected"); |
| 3356 | 3395 |
| 3396 // Lookup alias name and report an error if it is already defined in |
| 3397 // the library scope. |
| 3398 const Object& obj = Object::Handle(library_.LookupLocalObject(*alias_name)); |
| 3399 if (!obj.IsNull()) { |
| 3400 ErrorMsg(alias_name_pos, |
| 3401 "'%s' is already defined", alias_name->ToCString()); |
| 3402 } |
| 3403 |
| 3404 // Create the function type alias signature class. It will be linked to its |
| 3405 // signature function after it has been parsed. The type parameters, in order |
| 3406 // to be properly finalized, need to be associated to this signature class as |
| 3407 // they are parsed. |
| 3408 const Class& function_type_alias = Class::Handle( |
| 3409 Class::NewSignatureClass(*alias_name, |
| 3410 Function::Handle(), |
| 3411 script_, |
| 3412 alias_name_pos)); |
| 3413 library_.AddClass(function_type_alias); |
| 3414 set_current_class(function_type_alias); |
| 3357 // Parse the type parameters of the function type. | 3415 // Parse the type parameters of the function type. |
| 3358 ParseTypeParameters(alias_owner); | 3416 ParseTypeParameters(function_type_alias); |
| 3359 // At this point, the type parameters have been parsed, so we can resolve the | 3417 // At this point, the type parameters have been parsed, so we can resolve the |
| 3360 // result type. | 3418 // result type. |
| 3361 if (!result_type.IsNull()) { | 3419 if (!result_type.IsNull()) { |
| 3362 ResolveTypeFromClass(alias_owner, | 3420 ResolveTypeFromClass(function_type_alias, |
| 3363 ClassFinalizer::kTryResolve, | 3421 ClassFinalizer::kTryResolve, |
| 3364 &result_type); | 3422 &result_type); |
| 3365 } | 3423 } |
| 3366 // Parse the formal parameters of the function type. | 3424 // Parse the formal parameters of the function type. |
| 3367 if (CurrentToken() != Token::kLPAREN) { | 3425 if (CurrentToken() != Token::kLPAREN) { |
| 3368 ErrorMsg("formal parameter list expected"); | 3426 ErrorMsg("formal parameter list expected"); |
| 3369 } | 3427 } |
| 3370 ParamList func_params; | 3428 ParamList func_params; |
| 3371 | 3429 |
| 3372 // Add implicit closure object parameter. | 3430 // Add implicit closure object parameter. |
| 3373 func_params.AddFinalParameter( | 3431 func_params.AddFinalParameter( |
| 3374 TokenPos(), | 3432 TokenPos(), |
| 3375 &Symbols::ClosureParameter(), | 3433 &Symbols::ClosureParameter(), |
| 3376 &Type::ZoneHandle(Type::DynamicType())); | 3434 &Type::ZoneHandle(Type::DynamicType())); |
| 3377 | 3435 |
| 3378 const bool no_explicit_default_values = false; | 3436 const bool no_explicit_default_values = false; |
| 3379 ParseFormalParameterList(no_explicit_default_values, &func_params); | 3437 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 3438 ExpectSemicolon(); |
| 3380 // The field 'is_static' has no meaning for signature functions. | 3439 // The field 'is_static' has no meaning for signature functions. |
| 3381 Function& signature_function = Function::Handle( | 3440 Function& signature_function = Function::Handle( |
| 3382 Function::New(*alias_name, | 3441 Function::New(*alias_name, |
| 3383 RawFunction::kSignatureFunction, | 3442 RawFunction::kSignatureFunction, |
| 3384 /* is_static = */ false, | 3443 /* is_static = */ false, |
| 3385 /* is_const = */ false, | 3444 /* is_const = */ false, |
| 3386 /* is_abstract = */ false, | 3445 /* is_abstract = */ false, |
| 3387 /* is_external = */ false, | 3446 /* is_external = */ false, |
| 3388 alias_owner, | 3447 function_type_alias, |
| 3389 alias_name_pos)); | 3448 alias_name_pos)); |
| 3390 signature_function.set_result_type(result_type); | 3449 signature_function.set_result_type(result_type); |
| 3391 AddFormalParamsToFunction(&func_params, signature_function); | 3450 AddFormalParamsToFunction(&func_params, signature_function); |
| 3451 |
| 3452 // Patch the signature function in the signature class. |
| 3453 function_type_alias.PatchSignatureFunction(signature_function); |
| 3454 |
| 3392 const String& signature = String::Handle(signature_function.Signature()); | 3455 const String& signature = String::Handle(signature_function.Signature()); |
| 3393 if (FLAG_trace_parser) { | 3456 if (FLAG_trace_parser) { |
| 3394 OS::Print("TopLevel parsing function type alias '%s'\n", | 3457 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 3395 signature.ToCString()); | 3458 signature.ToCString()); |
| 3396 } | 3459 } |
| 3397 // Lookup the signature class, i.e. the class whose name is the signature. | 3460 // Lookup the signature class, i.e. the class whose name is the signature. |
| 3398 // We only lookup in the current library, but not in its imports, and only | 3461 // We only lookup in the current library, but not in its imports, and only |
| 3399 // create a new canonical signature class if it does not exist yet. | 3462 // create a new canonical signature class if it does not exist yet. |
| 3400 Class& signature_class = Class::ZoneHandle( | 3463 Class& signature_class = Class::ZoneHandle( |
| 3401 library_.LookupLocalClass(signature)); | 3464 library_.LookupLocalClass(signature)); |
| 3402 if (signature_class.IsNull()) { | 3465 if (signature_class.IsNull()) { |
| 3403 signature_class = Class::NewSignatureClass(signature, | 3466 signature_class = Class::NewSignatureClass(signature, |
| 3404 signature_function, | 3467 signature_function, |
| 3405 script_); | 3468 script_, |
| 3469 alias_name_pos); |
| 3406 // Record the function signature class in the current library. | 3470 // Record the function signature class in the current library. |
| 3407 library_.AddClass(signature_class); | 3471 library_.AddClass(signature_class); |
| 3408 } else { | 3472 } else { |
| 3409 // Forget the just created signature function and use the existing one. | 3473 // Forget the just created signature function and use the existing one. |
| 3410 signature_function = signature_class.signature_function(); | 3474 signature_function = signature_class.signature_function(); |
| 3475 function_type_alias.PatchSignatureFunction(signature_function); |
| 3411 } | 3476 } |
| 3412 ASSERT(signature_function.signature_class() == signature_class.raw()); | 3477 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 3413 | 3478 |
| 3414 // Lookup alias name and report an error if it is already defined in | 3479 // The alias should not be marked as finalized yet, since it needs to be |
| 3415 // the library scope. | |
| 3416 const Object& obj = Object::Handle(library_.LookupLocalObject(*alias_name)); | |
| 3417 if (!obj.IsNull()) { | |
| 3418 ErrorMsg(alias_name_pos, | |
| 3419 "'%s' is already defined", alias_name->ToCString()); | |
| 3420 } | |
| 3421 | |
| 3422 // Create the function type alias, but share the signature function of the | |
| 3423 // canonical signature class. | |
| 3424 Class& function_type_alias = Class::Handle( | |
| 3425 Class::NewSignatureClass(*alias_name, | |
| 3426 signature_function, | |
| 3427 script_)); | |
| 3428 // This alias should not be marked as finalized yet, since it needs to be | |
| 3429 // checked in the class finalizer for illegal self references. | 3480 // checked in the class finalizer for illegal self references. |
| 3430 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); | 3481 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); |
| 3431 ASSERT(!function_type_alias.is_finalized()); | 3482 ASSERT(!function_type_alias.is_finalized()); |
| 3432 library_.AddClass(function_type_alias); | |
| 3433 ExpectSemicolon(); | |
| 3434 pending_classes.Add(function_type_alias, Heap::kOld); | 3483 pending_classes.Add(function_type_alias, Heap::kOld); |
| 3435 } | 3484 } |
| 3436 | 3485 |
| 3437 | 3486 |
| 3438 // Consumes exactly one right angle bracket. If the current token is a single | 3487 // Consumes exactly one right angle bracket. If the current token is a single |
| 3439 // bracket token, it is consumed normally. However, if it is a double or triple | 3488 // bracket token, it is consumed normally. However, if it is a double or triple |
| 3440 // bracket, it is replaced by a single or double bracket token without | 3489 // bracket, it is replaced by a single or double bracket token without |
| 3441 // incrementing the token index. | 3490 // incrementing the token index. |
| 3442 void Parser::ConsumeRightAngleBracket() { | 3491 void Parser::ConsumeRightAngleBracket() { |
| 3443 if (token_kind_ == Token::kGT) { | 3492 if (token_kind_ == Token::kGT) { |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4361 ParsePartHeader(); | 4410 ParsePartHeader(); |
| 4362 } | 4411 } |
| 4363 | 4412 |
| 4364 while (true) { | 4413 while (true) { |
| 4365 set_current_class(Class::Handle()); // No current class. | 4414 set_current_class(Class::Handle()); // No current class. |
| 4366 SkipMetadata(); | 4415 SkipMetadata(); |
| 4367 if (CurrentToken() == Token::kCLASS) { | 4416 if (CurrentToken() == Token::kCLASS) { |
| 4368 ParseClassDefinition(pending_classes); | 4417 ParseClassDefinition(pending_classes); |
| 4369 } else if ((CurrentToken() == Token::kTYPEDEF) && | 4418 } else if ((CurrentToken() == Token::kTYPEDEF) && |
| 4370 (LookaheadToken(1) != Token::kLPAREN)) { | 4419 (LookaheadToken(1) != Token::kLPAREN)) { |
| 4420 set_current_class(toplevel_class); |
| 4371 ParseFunctionTypeAlias(pending_classes); | 4421 ParseFunctionTypeAlias(pending_classes); |
| 4372 } else if ((CurrentToken() == Token::kABSTRACT) && | 4422 } else if ((CurrentToken() == Token::kABSTRACT) && |
| 4373 (LookaheadToken(1) == Token::kCLASS)) { | 4423 (LookaheadToken(1) == Token::kCLASS)) { |
| 4374 ParseClassDefinition(pending_classes); | 4424 ParseClassDefinition(pending_classes); |
| 4375 } else if (is_patch_source() && IsLiteral("patch") && | 4425 } else if (is_patch_source() && IsLiteral("patch") && |
| 4376 (LookaheadToken(1) == Token::kCLASS)) { | 4426 (LookaheadToken(1) == Token::kCLASS)) { |
| 4377 ParseClassDefinition(pending_classes); | 4427 ParseClassDefinition(pending_classes); |
| 4378 } else { | 4428 } else { |
| 4379 set_current_class(toplevel_class); | 4429 set_current_class(toplevel_class); |
| 4380 if (IsVariableDeclaration()) { | 4430 if (IsVariableDeclaration()) { |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4852 } | 4902 } |
| 4853 if (signature_class.IsNull()) { | 4903 if (signature_class.IsNull()) { |
| 4854 signature_class = library_.LookupLocalClass(signature); | 4904 signature_class = library_.LookupLocalClass(signature); |
| 4855 } | 4905 } |
| 4856 if (signature_class.IsNull()) { | 4906 if (signature_class.IsNull()) { |
| 4857 // If we don't have a signature class yet, this must be a closure we | 4907 // If we don't have a signature class yet, this must be a closure we |
| 4858 // have not parsed before. | 4908 // have not parsed before. |
| 4859 ASSERT(is_new_closure); | 4909 ASSERT(is_new_closure); |
| 4860 signature_class = Class::NewSignatureClass(signature, | 4910 signature_class = Class::NewSignatureClass(signature, |
| 4861 function, | 4911 function, |
| 4862 script_); | 4912 script_, |
| 4913 function.token_pos()); |
| 4863 // Record the function signature class in the current library. | 4914 // Record the function signature class in the current library. |
| 4864 library_.AddClass(signature_class); | 4915 library_.AddClass(signature_class); |
| 4865 } else if (is_new_closure) { | 4916 } else if (is_new_closure) { |
| 4866 function.set_signature_class(signature_class); | 4917 function.set_signature_class(signature_class); |
| 4867 } | 4918 } |
| 4868 ASSERT(function.signature_class() == signature_class.raw()); | 4919 ASSERT(function.signature_class() == signature_class.raw()); |
| 4869 | 4920 |
| 4870 // Local functions are registered in the enclosing class, but | 4921 // Local functions are registered in the enclosing class, but |
| 4871 // ignored during class finalization. The enclosing class has | 4922 // ignored during class finalization. The enclosing class has |
| 4872 // already been finalized. | 4923 // already been finalized. |
| (...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7813 } | 7864 } |
| 7814 | 7865 |
| 7815 | 7866 |
| 7816 const Type* Parser::ReceiverType(intptr_t type_pos) const { | 7867 const Type* Parser::ReceiverType(intptr_t type_pos) const { |
| 7817 ASSERT(!current_class().IsNull()); | 7868 ASSERT(!current_class().IsNull()); |
| 7818 TypeArguments& type_arguments = TypeArguments::Handle(); | 7869 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 7819 if (current_class().NumTypeParameters() > 0) { | 7870 if (current_class().NumTypeParameters() > 0) { |
| 7820 type_arguments = current_class().type_parameters(); | 7871 type_arguments = current_class().type_parameters(); |
| 7821 } | 7872 } |
| 7822 Type& type = Type::ZoneHandle( | 7873 Type& type = Type::ZoneHandle( |
| 7823 Type::New(current_class(), type_arguments, type_pos)); | 7874 Type::New(current_class(), type_arguments, type_pos)); |
| 7824 if (!is_top_level_) { | 7875 if (!is_top_level_) { |
| 7825 type ^= ClassFinalizer::FinalizeType( | 7876 type ^= ClassFinalizer::FinalizeType( |
| 7826 current_class(), type, ClassFinalizer::kCanonicalizeWellFormed); | 7877 current_class(), type, ClassFinalizer::kCanonicalizeWellFormed); |
| 7827 } | 7878 } |
| 7828 return &type; | 7879 return &type; |
| 7829 } | 7880 } |
| 7830 | 7881 |
| 7831 | 7882 |
| 7832 bool Parser::IsInstantiatorRequired() const { | 7883 bool Parser::IsInstantiatorRequired() const { |
| 7833 ASSERT(!current_function().IsNull()); | 7884 ASSERT(!current_function().IsNull()); |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9428 | 9479 |
| 9429 void Parser::SkipFunctionLiteral() { | 9480 void Parser::SkipFunctionLiteral() { |
| 9430 if (IsIdentifier()) { | 9481 if (IsIdentifier()) { |
| 9431 if (LookaheadToken(1) != Token::kLPAREN) { | 9482 if (LookaheadToken(1) != Token::kLPAREN) { |
| 9432 SkipType(true); | 9483 SkipType(true); |
| 9433 } | 9484 } |
| 9434 ExpectIdentifier("function name expected"); | 9485 ExpectIdentifier("function name expected"); |
| 9435 } | 9486 } |
| 9436 if (CurrentToken() == Token::kLPAREN) { | 9487 if (CurrentToken() == Token::kLPAREN) { |
| 9437 const bool allow_explicit_default_values = true; | 9488 const bool allow_explicit_default_values = true; |
| 9438 ParamList ignore_params; | 9489 ParamList params; |
| 9439 ParseFormalParameterList(allow_explicit_default_values, &ignore_params); | 9490 params.skipped = true; |
| 9491 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 9440 } | 9492 } |
| 9441 if (CurrentToken() == Token::kLBRACE) { | 9493 if (CurrentToken() == Token::kLBRACE) { |
| 9442 SkipBlock(); | 9494 SkipBlock(); |
| 9443 } else if (CurrentToken() == Token::kARROW) { | 9495 } else if (CurrentToken() == Token::kARROW) { |
| 9444 ConsumeToken(); | 9496 ConsumeToken(); |
| 9445 SkipExpr(); | 9497 SkipExpr(); |
| 9446 } | 9498 } |
| 9447 } | 9499 } |
| 9448 | 9500 |
| 9449 | 9501 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9700 void Parser::SkipQualIdent() { | 9752 void Parser::SkipQualIdent() { |
| 9701 ASSERT(IsIdentifier()); | 9753 ASSERT(IsIdentifier()); |
| 9702 ConsumeToken(); | 9754 ConsumeToken(); |
| 9703 if (CurrentToken() == Token::kPERIOD) { | 9755 if (CurrentToken() == Token::kPERIOD) { |
| 9704 ConsumeToken(); // Consume the kPERIOD token. | 9756 ConsumeToken(); // Consume the kPERIOD token. |
| 9705 ExpectIdentifier("identifier expected after '.'"); | 9757 ExpectIdentifier("identifier expected after '.'"); |
| 9706 } | 9758 } |
| 9707 } | 9759 } |
| 9708 | 9760 |
| 9709 } // namespace dart | 9761 } // namespace dart |
| OLD | NEW |