| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 | 250 |
| 251 void Parser::TryBlocks::AddNodeForFinallyInlining(AstNode* node) { | 251 void Parser::TryBlocks::AddNodeForFinallyInlining(AstNode* node) { |
| 252 inlined_finally_nodes_.Add(node); | 252 inlined_finally_nodes_.Add(node); |
| 253 } | 253 } |
| 254 | 254 |
| 255 | 255 |
| 256 // For parsing a compilation unit. | 256 // For parsing a compilation unit. |
| 257 Parser::Parser(const Script& script, const Library& library, intptr_t token_pos) | 257 Parser::Parser(const Script& script, const Library& library, intptr_t token_pos) |
| 258 : script_(Script::Handle(script.raw())), | 258 : isolate_(Isolate::Current()), |
| 259 tokens_iterator_(TokenStream::Handle(script.tokens()), token_pos), | 259 script_(Script::Handle(isolate_, script.raw())), |
| 260 tokens_iterator_(TokenStream::Handle(isolate_, script.tokens()), |
| 261 token_pos), |
| 260 token_kind_(Token::kILLEGAL), | 262 token_kind_(Token::kILLEGAL), |
| 261 current_block_(NULL), | 263 current_block_(NULL), |
| 262 is_top_level_(false), | 264 is_top_level_(false), |
| 263 current_member_(NULL), | 265 current_member_(NULL), |
| 264 allow_function_literals_(true), | 266 allow_function_literals_(true), |
| 265 parsed_function_(NULL), | 267 parsed_function_(NULL), |
| 266 innermost_function_(Function::Handle()), | 268 innermost_function_(Function::Handle(isolate_)), |
| 267 literal_token_(LiteralToken::Handle()), | 269 literal_token_(LiteralToken::Handle(isolate_)), |
| 268 current_class_(Class::Handle()), | 270 current_class_(Class::Handle(isolate_)), |
| 269 library_(Library::Handle(library.raw())), | 271 library_(Library::Handle(isolate_, library.raw())), |
| 270 try_blocks_list_(NULL) { | 272 try_blocks_list_(NULL) { |
| 271 ASSERT(tokens_iterator_.IsValid()); | 273 ASSERT(tokens_iterator_.IsValid()); |
| 272 ASSERT(!library.IsNull()); | 274 ASSERT(!library.IsNull()); |
| 273 } | 275 } |
| 274 | 276 |
| 275 | 277 |
| 276 // For parsing a function. | 278 // For parsing a function. |
| 277 Parser::Parser(const Script& script, | 279 Parser::Parser(const Script& script, |
| 278 ParsedFunction* parsed_function, | 280 ParsedFunction* parsed_function, |
| 279 intptr_t token_position) | 281 intptr_t token_position) |
| 280 : script_(Script::Handle(script.raw())), | 282 : isolate_(Isolate::Current()), |
| 281 tokens_iterator_(TokenStream::Handle(script.tokens()), token_position), | 283 script_(Script::Handle(isolate_, script.raw())), |
| 284 tokens_iterator_(TokenStream::Handle(isolate_, script.tokens()), |
| 285 token_position), |
| 282 token_kind_(Token::kILLEGAL), | 286 token_kind_(Token::kILLEGAL), |
| 283 current_block_(NULL), | 287 current_block_(NULL), |
| 284 is_top_level_(false), | 288 is_top_level_(false), |
| 285 current_member_(NULL), | 289 current_member_(NULL), |
| 286 allow_function_literals_(true), | 290 allow_function_literals_(true), |
| 287 parsed_function_(parsed_function), | 291 parsed_function_(parsed_function), |
| 288 innermost_function_(Function::Handle(parsed_function->function().raw())), | 292 innermost_function_(Function::Handle(isolate_, |
| 289 literal_token_(LiteralToken::Handle()), | 293 parsed_function->function().raw())), |
| 290 current_class_(Class::Handle(parsed_function->function().Owner())), | 294 literal_token_(LiteralToken::Handle(isolate_)), |
| 295 current_class_(Class::Handle(isolate_, |
| 296 parsed_function->function().Owner())), |
| 291 library_(Library::Handle(Class::Handle( | 297 library_(Library::Handle(Class::Handle( |
| 298 isolate_, |
| 292 parsed_function->function().origin()).library())), | 299 parsed_function->function().origin()).library())), |
| 293 try_blocks_list_(NULL) { | 300 try_blocks_list_(NULL) { |
| 294 ASSERT(tokens_iterator_.IsValid()); | 301 ASSERT(tokens_iterator_.IsValid()); |
| 295 ASSERT(!current_function().IsNull()); | 302 ASSERT(!current_function().IsNull()); |
| 296 if (FLAG_enable_type_checks) { | 303 if (FLAG_enable_type_checks) { |
| 297 EnsureExpressionTemp(); | 304 EnsureExpressionTemp(); |
| 298 } | 305 } |
| 299 } | 306 } |
| 300 | 307 |
| 301 | 308 |
| (...skipping 3427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3729 ExpectIdentifier("name expected"); | 3736 ExpectIdentifier("name expected"); |
| 3730 } | 3737 } |
| 3731 SkipTypeArguments(); | 3738 SkipTypeArguments(); |
| 3732 } | 3739 } |
| 3733 } | 3740 } |
| 3734 | 3741 |
| 3735 | 3742 |
| 3736 void Parser::ParseTypeParameters(const Class& cls) { | 3743 void Parser::ParseTypeParameters(const Class& cls) { |
| 3737 TRACE_PARSER("ParseTypeParameters"); | 3744 TRACE_PARSER("ParseTypeParameters"); |
| 3738 if (CurrentToken() == Token::kLT) { | 3745 if (CurrentToken() == Token::kLT) { |
| 3739 Isolate* isolate = Isolate::Current(); | |
| 3740 const GrowableObjectArray& type_parameters_array = | 3746 const GrowableObjectArray& type_parameters_array = |
| 3741 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 3747 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 3742 intptr_t index = 0; | 3748 intptr_t index = 0; |
| 3743 TypeParameter& type_parameter = TypeParameter::Handle(); | 3749 TypeParameter& type_parameter = TypeParameter::Handle(); |
| 3744 TypeParameter& existing_type_parameter = TypeParameter::Handle(); | 3750 TypeParameter& existing_type_parameter = TypeParameter::Handle(); |
| 3745 String& existing_type_parameter_name = String::Handle(); | 3751 String& existing_type_parameter_name = String::Handle(); |
| 3746 AbstractType& type_parameter_bound = Type::Handle(); | 3752 AbstractType& type_parameter_bound = Type::Handle(); |
| 3747 do { | 3753 do { |
| 3748 ConsumeToken(); | 3754 ConsumeToken(); |
| 3749 SkipMetadata(); | 3755 SkipMetadata(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3760 } | 3766 } |
| 3761 } | 3767 } |
| 3762 if (CurrentToken() == Token::kEXTENDS) { | 3768 if (CurrentToken() == Token::kEXTENDS) { |
| 3763 ConsumeToken(); | 3769 ConsumeToken(); |
| 3764 // A bound may refer to the owner of the type parameter it applies to, | 3770 // A bound may refer to the owner of the type parameter it applies to, |
| 3765 // i.e. to the class or interface currently being parsed. | 3771 // i.e. to the class or interface currently being parsed. |
| 3766 // Postpone resolution in order to avoid resolving the class and its | 3772 // Postpone resolution in order to avoid resolving the class and its |
| 3767 // type parameters, as they are not fully parsed yet. | 3773 // type parameters, as they are not fully parsed yet. |
| 3768 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); | 3774 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); |
| 3769 } else { | 3775 } else { |
| 3770 type_parameter_bound = isolate->object_store()->object_type(); | 3776 type_parameter_bound = isolate()->object_store()->object_type(); |
| 3771 } | 3777 } |
| 3772 type_parameter = TypeParameter::New(cls, | 3778 type_parameter = TypeParameter::New(cls, |
| 3773 index, | 3779 index, |
| 3774 type_parameter_name, | 3780 type_parameter_name, |
| 3775 type_parameter_bound, | 3781 type_parameter_bound, |
| 3776 type_parameter_pos); | 3782 type_parameter_pos); |
| 3777 type_parameters_array.Add(type_parameter); | 3783 type_parameters_array.Add(type_parameter); |
| 3778 index++; | 3784 index++; |
| 3779 } while (CurrentToken() == Token::kCOMMA); | 3785 } while (CurrentToken() == Token::kCOMMA); |
| 3780 Token::Kind token = CurrentToken(); | 3786 Token::Kind token = CurrentToken(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3895 "mixin type '%s' may not be a type parameter", | 3901 "mixin type '%s' may not be a type parameter", |
| 3896 String::Handle(mixin_type.UserVisibleName()).ToCString()); | 3902 String::Handle(mixin_type.UserVisibleName()).ToCString()); |
| 3897 } | 3903 } |
| 3898 | 3904 |
| 3899 // The name of the mixin application class is a combination of | 3905 // The name of the mixin application class is a combination of |
| 3900 // the superclass and mixin class. | 3906 // the superclass and mixin class. |
| 3901 String& mixin_app_name = String::Handle(); | 3907 String& mixin_app_name = String::Handle(); |
| 3902 mixin_app_name = mixin_super_type.ClassName(); | 3908 mixin_app_name = mixin_super_type.ClassName(); |
| 3903 mixin_app_name = String::Concat(mixin_app_name, Symbols::Ampersand()); | 3909 mixin_app_name = String::Concat(mixin_app_name, Symbols::Ampersand()); |
| 3904 mixin_app_name = String::Concat(mixin_app_name, | 3910 mixin_app_name = String::Concat(mixin_app_name, |
| 3905 String::Handle(mixin_type.ClassName())); | 3911 String::Handle(mixin_type.ClassName())); |
| 3906 mixin_app_name = Symbols::New(mixin_app_name); | 3912 mixin_app_name = Symbols::New(mixin_app_name); |
| 3907 | 3913 |
| 3908 mixin_application = Class::New(mixin_app_name, script_, mixin_pos); | 3914 mixin_application = Class::New(mixin_app_name, script_, mixin_pos); |
| 3909 mixin_application.set_super_type(mixin_super_type); | 3915 mixin_application.set_super_type(mixin_super_type); |
| 3910 mixin_application.set_mixin(Type::Cast(mixin_type)); | 3916 mixin_application.set_mixin(Type::Cast(mixin_type)); |
| 3911 mixin_application.set_library(library_); | 3917 mixin_application.set_library(library_); |
| 3912 mixin_application.set_is_synthesized_class(); | 3918 mixin_application.set_is_synthesized_class(); |
| 3913 AddImplicitConstructor(mixin_application); | 3919 AddImplicitConstructor(mixin_application); |
| 3914 // Add the mixin type to the interfaces that the mixin application | 3920 // Add the mixin type to the interfaces that the mixin application |
| 3915 // class implements. This is necessary so that type tests work. | 3921 // class implements. This is necessary so that type tests work. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4221 } else { | 4227 } else { |
| 4222 library_.ReplaceObject(func, accessor_name); | 4228 library_.ReplaceObject(func, accessor_name); |
| 4223 } | 4229 } |
| 4224 } | 4230 } |
| 4225 | 4231 |
| 4226 | 4232 |
| 4227 | 4233 |
| 4228 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, | 4234 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, |
| 4229 intptr_t token_pos, | 4235 intptr_t token_pos, |
| 4230 const String& url) { | 4236 const String& url) { |
| 4231 Isolate* isolate = Isolate::Current(); | 4237 Dart_LibraryTagHandler handler = isolate()->library_tag_handler(); |
| 4232 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); | |
| 4233 if (handler == NULL) { | 4238 if (handler == NULL) { |
| 4234 if (url.StartsWith(Symbols::DartScheme())) { | 4239 if (url.StartsWith(Symbols::DartScheme())) { |
| 4235 if (tag == Dart_kCanonicalizeUrl) { | 4240 if (tag == Dart_kCanonicalizeUrl) { |
| 4236 return url.raw(); | 4241 return url.raw(); |
| 4237 } | 4242 } |
| 4238 return Object::null(); | 4243 return Object::null(); |
| 4239 } | 4244 } |
| 4240 ErrorMsg(token_pos, "no library handler registered"); | 4245 ErrorMsg(token_pos, "no library handler registered"); |
| 4241 } | 4246 } |
| 4242 Dart_Handle result = handler(tag, | 4247 Dart_Handle result = handler(tag, |
| 4243 Api::NewHandle(isolate, library_.raw()), | 4248 Api::NewHandle(isolate(), library_.raw()), |
| 4244 Api::NewHandle(isolate, url.raw())); | 4249 Api::NewHandle(isolate(), url.raw())); |
| 4245 if (Dart_IsError(result)) { | 4250 if (Dart_IsError(result)) { |
| 4246 // In case of an error we append an explanatory error message to the | 4251 // In case of an error we append an explanatory error message to the |
| 4247 // error obtained from the library tag handler. | 4252 // error obtained from the library tag handler. |
| 4248 Error& prev_error = Error::Handle(); | 4253 Error& prev_error = Error::Handle(); |
| 4249 prev_error ^= Api::UnwrapHandle(result); | 4254 prev_error ^= Api::UnwrapHandle(result); |
| 4250 AppendErrorMsg(prev_error, token_pos, "library handler failed"); | 4255 AppendErrorMsg(prev_error, token_pos, "library handler failed"); |
| 4251 } | 4256 } |
| 4252 if (tag == Dart_kCanonicalizeUrl) { | 4257 if (tag == Dart_kCanonicalizeUrl) { |
| 4253 if (!Dart_IsString(result)) { | 4258 if (!Dart_IsString(result)) { |
| 4254 ErrorMsg(token_pos, "library handler failed URI canonicalization"); | 4259 ErrorMsg(token_pos, "library handler failed URI canonicalization"); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4466 } | 4471 } |
| 4467 ExpectSemicolon(); | 4472 ExpectSemicolon(); |
| 4468 } | 4473 } |
| 4469 | 4474 |
| 4470 | 4475 |
| 4471 void Parser::ParseTopLevel() { | 4476 void Parser::ParseTopLevel() { |
| 4472 TRACE_PARSER("ParseTopLevel"); | 4477 TRACE_PARSER("ParseTopLevel"); |
| 4473 // Collect the classes found at the top level in this growable array. | 4478 // Collect the classes found at the top level in this growable array. |
| 4474 // They need to be registered with class finalization after parsing | 4479 // They need to be registered with class finalization after parsing |
| 4475 // has been completed. | 4480 // has been completed. |
| 4476 Isolate* isolate = Isolate::Current(); | 4481 ObjectStore* object_store = isolate()->object_store(); |
| 4477 ObjectStore* object_store = isolate->object_store(); | |
| 4478 const GrowableObjectArray& pending_classes = | 4482 const GrowableObjectArray& pending_classes = |
| 4479 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); | 4483 GrowableObjectArray::Handle(isolate(), object_store->pending_classes()); |
| 4480 SetPosition(0); | 4484 SetPosition(0); |
| 4481 is_top_level_ = true; | 4485 is_top_level_ = true; |
| 4482 TopLevel top_level; | 4486 TopLevel top_level; |
| 4483 Class& toplevel_class = Class::Handle( | 4487 Class& toplevel_class = Class::Handle( |
| 4484 Class::New(Symbols::TopLevel(), script_, TokenPos())); | 4488 Class::New(Symbols::TopLevel(), script_, TokenPos())); |
| 4485 toplevel_class.set_library(library_); | 4489 toplevel_class.set_library(library_); |
| 4486 | 4490 |
| 4487 if (is_library_source() || is_patch_source()) { | 4491 if (is_library_source() || is_patch_source()) { |
| 4488 ParseLibraryDefinition(); | 4492 ParseLibraryDefinition(); |
| 4489 } else if (is_part_source()) { | 4493 } else if (is_part_source()) { |
| (...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6547 OS::Print("%s", buf.ToCString()); | 6551 OS::Print("%s", buf.ToCString()); |
| 6548 } | 6552 } |
| 6549 | 6553 |
| 6550 | 6554 |
| 6551 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) { | 6555 void Parser::ErrorMsg(intptr_t token_pos, const char* format, ...) { |
| 6552 va_list args; | 6556 va_list args; |
| 6553 va_start(args, format); | 6557 va_start(args, format); |
| 6554 const Error& error = Error::Handle( | 6558 const Error& error = Error::Handle( |
| 6555 FormatError(script_, token_pos, "Error", format, args)); | 6559 FormatError(script_, token_pos, "Error", format, args)); |
| 6556 va_end(args); | 6560 va_end(args); |
| 6557 Isolate::Current()->long_jump_base()->Jump(1, error); | 6561 isolate()->long_jump_base()->Jump(1, error); |
| 6558 UNREACHABLE(); | 6562 UNREACHABLE(); |
| 6559 } | 6563 } |
| 6560 | 6564 |
| 6561 | 6565 |
| 6562 void Parser::ErrorMsg(const char* format, ...) { | 6566 void Parser::ErrorMsg(const char* format, ...) { |
| 6563 va_list args; | 6567 va_list args; |
| 6564 va_start(args, format); | 6568 va_start(args, format); |
| 6565 const Error& error = Error::Handle( | 6569 const Error& error = Error::Handle( |
| 6566 FormatError(script_, TokenPos(), "Error", format, args)); | 6570 FormatError(script_, TokenPos(), "Error", format, args)); |
| 6567 va_end(args); | 6571 va_end(args); |
| 6568 Isolate::Current()->long_jump_base()->Jump(1, error); | 6572 isolate()->long_jump_base()->Jump(1, error); |
| 6569 UNREACHABLE(); | 6573 UNREACHABLE(); |
| 6570 } | 6574 } |
| 6571 | 6575 |
| 6572 | 6576 |
| 6573 void Parser::ErrorMsg(const Error& error) { | 6577 void Parser::ErrorMsg(const Error& error) { |
| 6574 Isolate::Current()->long_jump_base()->Jump(1, error); | 6578 isolate()->long_jump_base()->Jump(1, error); |
| 6575 UNREACHABLE(); | 6579 UNREACHABLE(); |
| 6576 } | 6580 } |
| 6577 | 6581 |
| 6578 | 6582 |
| 6579 void Parser::AppendErrorMsg( | 6583 void Parser::AppendErrorMsg( |
| 6580 const Error& prev_error, intptr_t token_pos, const char* format, ...) { | 6584 const Error& prev_error, intptr_t token_pos, const char* format, ...) { |
| 6581 va_list args; | 6585 va_list args; |
| 6582 va_start(args, format); | 6586 va_start(args, format); |
| 6583 const Error& error = Error::Handle(FormatErrorWithAppend( | 6587 const Error& error = Error::Handle(FormatErrorWithAppend( |
| 6584 prev_error, script_, token_pos, "Error", format, args)); | 6588 prev_error, script_, token_pos, "Error", format, args)); |
| 6585 va_end(args); | 6589 va_end(args); |
| 6586 Isolate::Current()->long_jump_base()->Jump(1, error); | 6590 isolate()->long_jump_base()->Jump(1, error); |
| 6587 UNREACHABLE(); | 6591 UNREACHABLE(); |
| 6588 } | 6592 } |
| 6589 | 6593 |
| 6590 | 6594 |
| 6591 void Parser::Warning(intptr_t token_pos, const char* format, ...) { | 6595 void Parser::Warning(intptr_t token_pos, const char* format, ...) { |
| 6592 if (FLAG_silent_warnings) return; | 6596 if (FLAG_silent_warnings) return; |
| 6593 va_list args; | 6597 va_list args; |
| 6594 va_start(args, format); | 6598 va_start(args, format); |
| 6595 const Error& error = Error::Handle( | 6599 const Error& error = Error::Handle( |
| 6596 FormatError(script_, token_pos, "Warning", format, args)); | 6600 FormatError(script_, token_pos, "Warning", format, args)); |
| 6597 va_end(args); | 6601 va_end(args); |
| 6598 if (FLAG_warning_as_error) { | 6602 if (FLAG_warning_as_error) { |
| 6599 Isolate::Current()->long_jump_base()->Jump(1, error); | 6603 isolate()->long_jump_base()->Jump(1, error); |
| 6600 UNREACHABLE(); | 6604 UNREACHABLE(); |
| 6601 } else { | 6605 } else { |
| 6602 OS::Print("%s", error.ToErrorCString()); | 6606 OS::Print("%s", error.ToErrorCString()); |
| 6603 } | 6607 } |
| 6604 } | 6608 } |
| 6605 | 6609 |
| 6606 | 6610 |
| 6607 void Parser::Warning(const char* format, ...) { | 6611 void Parser::Warning(const char* format, ...) { |
| 6608 if (FLAG_silent_warnings) return; | 6612 if (FLAG_silent_warnings) return; |
| 6609 va_list args; | 6613 va_list args; |
| 6610 va_start(args, format); | 6614 va_start(args, format); |
| 6611 const Error& error = Error::Handle( | 6615 const Error& error = Error::Handle( |
| 6612 FormatError(script_, TokenPos(), "Warning", format, args)); | 6616 FormatError(script_, TokenPos(), "Warning", format, args)); |
| 6613 va_end(args); | 6617 va_end(args); |
| 6614 if (FLAG_warning_as_error) { | 6618 if (FLAG_warning_as_error) { |
| 6615 Isolate::Current()->long_jump_base()->Jump(1, error); | 6619 isolate()->long_jump_base()->Jump(1, error); |
| 6616 UNREACHABLE(); | 6620 UNREACHABLE(); |
| 6617 } else { | 6621 } else { |
| 6618 OS::Print("%s", error.ToErrorCString()); | 6622 OS::Print("%s", error.ToErrorCString()); |
| 6619 } | 6623 } |
| 6620 } | 6624 } |
| 6621 | 6625 |
| 6622 | 6626 |
| 6623 void Parser::Unimplemented(const char* msg) { | 6627 void Parser::Unimplemented(const char* msg) { |
| 6624 ErrorMsg(TokenPos(), "%s", msg); | 6628 ErrorMsg(TokenPos(), "%s", msg); |
| 6625 } | 6629 } |
| (...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8092 // generated AST is not deterministic. Therefore mark the function as | 8096 // generated AST is not deterministic. Therefore mark the function as |
| 8093 // not optimizable. | 8097 // not optimizable. |
| 8094 current_function().set_is_optimizable(false); | 8098 current_function().set_is_optimizable(false); |
| 8095 field.set_value(Instance::null_object()); | 8099 field.set_value(Instance::null_object()); |
| 8096 // It is a compile-time error if evaluation of a compile-time constant | 8100 // It is a compile-time error if evaluation of a compile-time constant |
| 8097 // would raise an exception. | 8101 // would raise an exception. |
| 8098 AppendErrorMsg(error, TokenPos(), | 8102 AppendErrorMsg(error, TokenPos(), |
| 8099 "error initializing const field '%s'", | 8103 "error initializing const field '%s'", |
| 8100 String::Handle(field.name()).ToCString()); | 8104 String::Handle(field.name()).ToCString()); |
| 8101 } else { | 8105 } else { |
| 8102 Isolate::Current()->long_jump_base()->Jump(1, error); | 8106 isolate()->long_jump_base()->Jump(1, error); |
| 8103 } | 8107 } |
| 8104 } | 8108 } |
| 8105 ASSERT(const_value.IsNull() || const_value.IsInstance()); | 8109 ASSERT(const_value.IsNull() || const_value.IsInstance()); |
| 8106 Instance& instance = Instance::Handle(); | 8110 Instance& instance = Instance::Handle(); |
| 8107 instance ^= const_value.raw(); | 8111 instance ^= const_value.raw(); |
| 8108 if (!instance.IsNull()) { | 8112 if (!instance.IsNull()) { |
| 8109 instance ^= instance.Canonicalize(); | 8113 instance ^= instance.Canonicalize(); |
| 8110 } | 8114 } |
| 8111 field.set_value(instance); | 8115 field.set_value(instance); |
| 8112 } else { | 8116 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8155 arg_values, | 8159 arg_values, |
| 8156 arg_descriptor)); | 8160 arg_descriptor)); |
| 8157 if (result.IsError()) { | 8161 if (result.IsError()) { |
| 8158 // An exception may not occur in every parse attempt, i.e., the | 8162 // An exception may not occur in every parse attempt, i.e., the |
| 8159 // generated AST is not deterministic. Therefore mark the function as | 8163 // generated AST is not deterministic. Therefore mark the function as |
| 8160 // not optimizable. | 8164 // not optimizable. |
| 8161 current_function().set_is_optimizable(false); | 8165 current_function().set_is_optimizable(false); |
| 8162 if (result.IsUnhandledException()) { | 8166 if (result.IsUnhandledException()) { |
| 8163 return result.raw(); | 8167 return result.raw(); |
| 8164 } else { | 8168 } else { |
| 8165 Isolate::Current()->long_jump_base()->Jump(1, Error::Cast(result)); | 8169 isolate()->long_jump_base()->Jump(1, Error::Cast(result)); |
| 8166 UNREACHABLE(); | 8170 UNREACHABLE(); |
| 8167 return Object::null(); | 8171 return Object::null(); |
| 8168 } | 8172 } |
| 8169 } else { | 8173 } else { |
| 8170 if (!instance.IsNull()) { | 8174 if (!instance.IsNull()) { |
| 8171 instance ^= instance.Canonicalize(); | 8175 instance ^= instance.Canonicalize(); |
| 8172 } | 8176 } |
| 8173 return instance.raw(); | 8177 return instance.raw(); |
| 8174 } | 8178 } |
| 8175 } | 8179 } |
| 8176 | 8180 |
| 8177 | 8181 |
| 8178 // Do a lookup for the identifier in the block scope and the class scope | 8182 // Do a lookup for the identifier in the block scope and the class scope |
| 8179 // return true if the identifier is found, false otherwise. | 8183 // return true if the identifier is found, false otherwise. |
| 8180 // If node is non NULL return an AST node corresponding to the identifier. | 8184 // If node is non NULL return an AST node corresponding to the identifier. |
| 8181 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, | 8185 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, |
| 8182 const String &ident, | 8186 const String &ident, |
| 8183 AstNode** node) { | 8187 AstNode** node) { |
| 8184 TRACE_PARSER("ResolveIdentInLocalScope"); | 8188 TRACE_PARSER("ResolveIdentInLocalScope"); |
| 8185 Isolate* isolate = Isolate::Current(); | |
| 8186 // First try to find the identifier in the nested local scopes. | 8189 // First try to find the identifier in the nested local scopes. |
| 8187 LocalVariable* local = LookupLocalScope(ident); | 8190 LocalVariable* local = LookupLocalScope(ident); |
| 8188 if (local != NULL) { | 8191 if (local != NULL) { |
| 8189 if (node != NULL) { | 8192 if (node != NULL) { |
| 8190 if (local->IsConst()) { | 8193 if (local->IsConst()) { |
| 8191 *node = new LiteralNode(ident_pos, *local->ConstValue()); | 8194 *node = new LiteralNode(ident_pos, *local->ConstValue()); |
| 8192 } else { | 8195 } else { |
| 8193 *node = new LoadLocalNode(ident_pos, local); | 8196 *node = new LoadLocalNode(ident_pos, local); |
| 8194 } | 8197 } |
| 8195 } | 8198 } |
| 8196 return true; | 8199 return true; |
| 8197 } | 8200 } |
| 8198 | 8201 |
| 8199 // Try to find the identifier in the class scope of the current class. | 8202 // Try to find the identifier in the class scope of the current class. |
| 8200 // If the current class is the result of a mixin application, we must | 8203 // If the current class is the result of a mixin application, we must |
| 8201 // use the class scope of the class from which the function originates. | 8204 // use the class scope of the class from which the function originates. |
| 8202 Class& cls = Class::Handle(isolate); | 8205 Class& cls = Class::Handle(isolate()); |
| 8203 if (current_class().mixin() == Type::null()) { | 8206 if (current_class().mixin() == Type::null()) { |
| 8204 cls = current_class().raw(); | 8207 cls = current_class().raw(); |
| 8205 } else { | 8208 } else { |
| 8206 cls = parsed_function()->function().origin(); | 8209 cls = parsed_function()->function().origin(); |
| 8207 } | 8210 } |
| 8208 Function& func = Function::Handle(isolate, Function::null()); | 8211 Function& func = Function::Handle(isolate(), Function::null()); |
| 8209 Field& field = Field::Handle(isolate, Field::null()); | 8212 Field& field = Field::Handle(isolate(), Field::null()); |
| 8210 | 8213 |
| 8211 // First check if a field exists. | 8214 // First check if a field exists. |
| 8212 field = cls.LookupField(ident); | 8215 field = cls.LookupField(ident); |
| 8213 if (!field.IsNull()) { | 8216 if (!field.IsNull()) { |
| 8214 if (node != NULL) { | 8217 if (node != NULL) { |
| 8215 if (!field.is_static()) { | 8218 if (!field.is_static()) { |
| 8216 CheckInstanceFieldAccess(ident_pos, ident); | 8219 CheckInstanceFieldAccess(ident_pos, ident); |
| 8217 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 8220 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 8218 } else { | 8221 } else { |
| 8219 *node = GenerateStaticFieldLookup(field, ident_pos); | 8222 *node = GenerateStaticFieldLookup(field, ident_pos); |
| 8220 } | 8223 } |
| 8221 } | 8224 } |
| 8222 return true; | 8225 return true; |
| 8223 } | 8226 } |
| 8224 | 8227 |
| 8225 // Check if an instance/static function exists. | 8228 // Check if an instance/static function exists. |
| 8226 func = cls.LookupFunction(ident); | 8229 func = cls.LookupFunction(ident); |
| 8227 if (!func.IsNull() && | 8230 if (!func.IsNull() && |
| 8228 (func.IsDynamicFunction() || func.IsStaticFunction())) { | 8231 (func.IsDynamicFunction() || func.IsStaticFunction())) { |
| 8229 if (node != NULL) { | 8232 if (node != NULL) { |
| 8230 *node = new PrimaryNode(ident_pos, | 8233 *node = new PrimaryNode(ident_pos, |
| 8231 Function::ZoneHandle(isolate, func.raw())); | 8234 Function::ZoneHandle(isolate(), func.raw())); |
| 8232 } | 8235 } |
| 8233 return true; | 8236 return true; |
| 8234 } | 8237 } |
| 8235 | 8238 |
| 8236 // Now check if a getter/setter method exists for it in which case | 8239 // Now check if a getter/setter method exists for it in which case |
| 8237 // it is still a field. | 8240 // it is still a field. |
| 8238 func = cls.LookupGetterFunction(ident); | 8241 func = cls.LookupGetterFunction(ident); |
| 8239 if (!func.IsNull()) { | 8242 if (!func.IsNull()) { |
| 8240 if (func.IsDynamicFunction()) { | 8243 if (func.IsDynamicFunction()) { |
| 8241 if (node != NULL) { | 8244 if (node != NULL) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 8253 AstNode* receiver = NULL; | 8256 AstNode* receiver = NULL; |
| 8254 const bool kTestOnly = true; | 8257 const bool kTestOnly = true; |
| 8255 ASSERT(!current_function().IsInFactoryScope()); | 8258 ASSERT(!current_function().IsInFactoryScope()); |
| 8256 if (!current_function().is_static() && | 8259 if (!current_function().is_static() && |
| 8257 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { | 8260 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { |
| 8258 receiver = LoadReceiver(ident_pos); | 8261 receiver = LoadReceiver(ident_pos); |
| 8259 } | 8262 } |
| 8260 *node = new StaticGetterNode(ident_pos, | 8263 *node = new StaticGetterNode(ident_pos, |
| 8261 receiver, | 8264 receiver, |
| 8262 false, | 8265 false, |
| 8263 Class::ZoneHandle(isolate, cls.raw()), | 8266 Class::ZoneHandle(isolate(), cls.raw()), |
| 8264 ident); | 8267 ident); |
| 8265 } | 8268 } |
| 8266 return true; | 8269 return true; |
| 8267 } | 8270 } |
| 8268 } | 8271 } |
| 8269 func = cls.LookupSetterFunction(ident); | 8272 func = cls.LookupSetterFunction(ident); |
| 8270 if (!func.IsNull()) { | 8273 if (!func.IsNull()) { |
| 8271 if (func.IsDynamicFunction()) { | 8274 if (func.IsDynamicFunction()) { |
| 8272 if (node != NULL) { | 8275 if (node != NULL) { |
| 8273 // We create a getter node even though a getter doesn't exist as | 8276 // We create a getter node even though a getter doesn't exist as |
| 8274 // it could be followed by an assignment which will convert it to | 8277 // it could be followed by an assignment which will convert it to |
| 8275 // a setter node. If there is no assignment we will get an error | 8278 // a setter node. If there is no assignment we will get an error |
| 8276 // when we try to invoke the getter. | 8279 // when we try to invoke the getter. |
| 8277 CheckInstanceFieldAccess(ident_pos, ident); | 8280 CheckInstanceFieldAccess(ident_pos, ident); |
| 8278 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 8281 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 8279 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 8282 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 8280 } | 8283 } |
| 8281 return true; | 8284 return true; |
| 8282 } else if (func.IsStaticFunction()) { | 8285 } else if (func.IsStaticFunction()) { |
| 8283 if (node != NULL) { | 8286 if (node != NULL) { |
| 8284 // We create a getter node even though a getter doesn't exist as | 8287 // We create a getter node even though a getter doesn't exist as |
| 8285 // it could be followed by an assignment which will convert it to | 8288 // it could be followed by an assignment which will convert it to |
| 8286 // a setter node. If there is no assignment we will get an error | 8289 // a setter node. If there is no assignment we will get an error |
| 8287 // when we try to invoke the getter. | 8290 // when we try to invoke the getter. |
| 8288 *node = new StaticGetterNode(ident_pos, | 8291 *node = new StaticGetterNode(ident_pos, |
| 8289 NULL, | 8292 NULL, |
| 8290 false, | 8293 false, |
| 8291 Class::ZoneHandle(isolate, cls.raw()), | 8294 Class::ZoneHandle(isolate(), cls.raw()), |
| 8292 ident); | 8295 ident); |
| 8293 } | 8296 } |
| 8294 return true; | 8297 return true; |
| 8295 } | 8298 } |
| 8296 } | 8299 } |
| 8297 | 8300 |
| 8298 // Nothing found in scope of current class. | 8301 // Nothing found in scope of current class. |
| 8299 if (node != NULL) { | 8302 if (node != NULL) { |
| 8300 *node = NULL; | 8303 *node = NULL; |
| 8301 } | 8304 } |
| 8302 return false; // Not an unqualified identifier. | 8305 return false; // Not an unqualified identifier. |
| 8303 } | 8306 } |
| 8304 | 8307 |
| 8305 | 8308 |
| 8306 static RawObject* LookupNameInLibrary(const Library& lib, const String& name) { | 8309 static RawObject* LookupNameInLibrary(Isolate* isolate, |
| 8307 Object& obj = Object::Handle(); | 8310 const Library& lib, |
| 8311 const String& name) { |
| 8312 Object& obj = Object::Handle(isolate); |
| 8308 obj = lib.LookupLocalObject(name); | 8313 obj = lib.LookupLocalObject(name); |
| 8309 if (!obj.IsNull()) { | 8314 if (!obj.IsNull()) { |
| 8310 return obj.raw(); | 8315 return obj.raw(); |
| 8311 } | 8316 } |
| 8312 String& accessor_name = String::Handle(Field::GetterName(name)); | 8317 String& accessor_name = String::Handle(isolate, Field::GetterName(name)); |
| 8313 obj = lib.LookupLocalObject(accessor_name); | 8318 obj = lib.LookupLocalObject(accessor_name); |
| 8314 if (!obj.IsNull()) { | 8319 if (!obj.IsNull()) { |
| 8315 return obj.raw(); | 8320 return obj.raw(); |
| 8316 } | 8321 } |
| 8317 accessor_name = Field::SetterName(name); | 8322 accessor_name = Field::SetterName(name); |
| 8318 obj = lib.LookupLocalObject(accessor_name); | 8323 obj = lib.LookupLocalObject(accessor_name); |
| 8319 return obj.raw(); | 8324 return obj.raw(); |
| 8320 } | 8325 } |
| 8321 | 8326 |
| 8322 | 8327 |
| 8323 static RawObject* LookupNameInImport(const Namespace& ns, const String& name) { | 8328 static RawObject* LookupNameInImport(Isolate* isolate, |
| 8324 Object& obj = Object::Handle(); | 8329 const Namespace& ns, |
| 8330 const String& name) { |
| 8331 Object& obj = Object::Handle(isolate); |
| 8325 obj = ns.Lookup(name); | 8332 obj = ns.Lookup(name); |
| 8326 if (!obj.IsNull()) { | 8333 if (!obj.IsNull()) { |
| 8327 return obj.raw(); | 8334 return obj.raw(); |
| 8328 } | 8335 } |
| 8329 // If the given name is filtered out by the import, don't look up the | 8336 // If the given name is filtered out by the import, don't look up the |
| 8330 // getter and setter names. | 8337 // getter and setter names. |
| 8331 if (ns.HidesName(name)) { | 8338 if (ns.HidesName(name)) { |
| 8332 return Object::null(); | 8339 return Object::null(); |
| 8333 } | 8340 } |
| 8334 String& accessor_name = String::Handle(Field::GetterName(name)); | 8341 String& accessor_name = String::Handle(isolate, Field::GetterName(name)); |
| 8335 obj = ns.Lookup(accessor_name); | 8342 obj = ns.Lookup(accessor_name); |
| 8336 if (!obj.IsNull()) { | 8343 if (!obj.IsNull()) { |
| 8337 return obj.raw(); | 8344 return obj.raw(); |
| 8338 } | 8345 } |
| 8339 accessor_name = Field::SetterName(name); | 8346 accessor_name = Field::SetterName(name); |
| 8340 obj = ns.Lookup(accessor_name); | 8347 obj = ns.Lookup(accessor_name); |
| 8341 return obj.raw(); | 8348 return obj.raw(); |
| 8342 } | 8349 } |
| 8343 | 8350 |
| 8344 | 8351 |
| 8345 // Resolve a name by checking the global scope of the current | 8352 // Resolve a name by checking the global scope of the current |
| 8346 // library. If not found in the current library, then look in the scopes | 8353 // library. If not found in the current library, then look in the scopes |
| 8347 // of all libraries that are imported without a library prefix. | 8354 // of all libraries that are imported without a library prefix. |
| 8348 // Issue an error if the name is not found in the global scope | 8355 // Issue an error if the name is not found in the global scope |
| 8349 // of the current library, but is defined in more than one imported | 8356 // of the current library, but is defined in more than one imported |
| 8350 // library, i.e. if the name cannot be resolved unambiguously. | 8357 // library, i.e. if the name cannot be resolved unambiguously. |
| 8351 RawObject* Parser::ResolveNameInCurrentLibraryScope(intptr_t ident_pos, | 8358 RawObject* Parser::ResolveNameInCurrentLibraryScope(intptr_t ident_pos, |
| 8352 const String& name, | 8359 const String& name, |
| 8353 Error* error) { | 8360 Error* error) { |
| 8354 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); | 8361 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); |
| 8355 Object& obj = Object::Handle(LookupNameInLibrary(library_, name)); | 8362 HANDLESCOPE(isolate()); |
| 8363 Object& obj = Object::Handle(isolate(), |
| 8364 LookupNameInLibrary(isolate(), library_, name)); |
| 8356 if (obj.IsNull()) { | 8365 if (obj.IsNull()) { |
| 8357 // Name is not found in current library. Check scope of all | 8366 // Name is not found in current library. Check scope of all |
| 8358 // imported libraries. | 8367 // imported libraries. |
| 8359 String& first_lib_url = String::Handle(); | 8368 String& first_lib_url = String::Handle(isolate()); |
| 8360 Namespace& import = Namespace::Handle(); | 8369 Namespace& import = Namespace::Handle(isolate()); |
| 8361 intptr_t num_imports = library_.num_imports(); | 8370 intptr_t num_imports = library_.num_imports(); |
| 8362 Object& imported_obj = Object::Handle(); | 8371 Object& imported_obj = Object::Handle(isolate()); |
| 8363 Library& lib = Library::Handle(); | 8372 Library& lib = Library::Handle(isolate()); |
| 8364 for (int i = 0; i < num_imports; i++) { | 8373 for (int i = 0; i < num_imports; i++) { |
| 8365 import = library_.ImportAt(i); | 8374 import = library_.ImportAt(i); |
| 8366 imported_obj = LookupNameInImport(import, name); | 8375 imported_obj = LookupNameInImport(isolate(), import, name); |
| 8367 if (!imported_obj.IsNull()) { | 8376 if (!imported_obj.IsNull()) { |
| 8368 lib ^= import.library(); | 8377 lib ^= import.library(); |
| 8369 if (!first_lib_url.IsNull()) { | 8378 if (!first_lib_url.IsNull()) { |
| 8370 // Found duplicate definition. | 8379 // Found duplicate definition. |
| 8371 Error& ambiguous_ref_error = Error::Handle(); | 8380 Error& ambiguous_ref_error = Error::Handle(); |
| 8372 if (first_lib_url.raw() == lib.url()) { | 8381 if (first_lib_url.raw() == lib.url()) { |
| 8373 ambiguous_ref_error = FormatErrorMsg( | 8382 ambiguous_ref_error = FormatErrorMsg( |
| 8374 script_, ident_pos, "Error", | 8383 script_, ident_pos, "Error", |
| 8375 "ambiguous reference: " | 8384 "ambiguous reference: " |
| 8376 "'%s' as library '%s' is imported multiple times", | 8385 "'%s' as library '%s' is imported multiple times", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8452 // Lexically unresolved primary identifiers are referenced by their name. | 8461 // Lexically unresolved primary identifiers are referenced by their name. |
| 8453 return new PrimaryNode(ident_pos, ident); | 8462 return new PrimaryNode(ident_pos, ident); |
| 8454 } | 8463 } |
| 8455 | 8464 |
| 8456 | 8465 |
| 8457 RawObject* Parser::ResolveNameInPrefixScope(intptr_t ident_pos, | 8466 RawObject* Parser::ResolveNameInPrefixScope(intptr_t ident_pos, |
| 8458 const LibraryPrefix& prefix, | 8467 const LibraryPrefix& prefix, |
| 8459 const String& name, | 8468 const String& name, |
| 8460 Error* error) { | 8469 Error* error) { |
| 8461 TRACE_PARSER("ResolveNameInPrefixScope"); | 8470 TRACE_PARSER("ResolveNameInPrefixScope"); |
| 8462 Namespace& import = Namespace::Handle(); | 8471 HANDLESCOPE(isolate()); |
| 8463 String& first_lib_url = String::Handle(); | 8472 Namespace& import = Namespace::Handle(isolate()); |
| 8464 Object& obj = Object::Handle(); | 8473 String& first_lib_url = String::Handle(isolate()); |
| 8465 Object& resolved_obj = Object::Handle(); | 8474 Object& obj = Object::Handle(isolate()); |
| 8466 const Array& imports = Array::Handle(prefix.imports()); | 8475 Object& resolved_obj = Object::Handle(isolate()); |
| 8476 const Array& imports = Array::Handle(isolate(), prefix.imports()); |
| 8477 Library& lib = Library::Handle(isolate()); |
| 8467 for (intptr_t i = 0; i < prefix.num_imports(); i++) { | 8478 for (intptr_t i = 0; i < prefix.num_imports(); i++) { |
| 8468 import ^= imports.At(i); | 8479 import ^= imports.At(i); |
| 8469 resolved_obj = LookupNameInImport(import, name); | 8480 resolved_obj = LookupNameInImport(isolate(), import, name); |
| 8470 if (!resolved_obj.IsNull()) { | 8481 if (!resolved_obj.IsNull()) { |
| 8471 obj = resolved_obj.raw(); | 8482 obj = resolved_obj.raw(); |
| 8472 const Library& lib = Library::Handle(import.library()); | 8483 lib = import.library(); |
| 8473 if (first_lib_url.IsNull()) { | 8484 if (first_lib_url.IsNull()) { |
| 8474 first_lib_url = lib.url(); | 8485 first_lib_url = lib.url(); |
| 8475 } else { | 8486 } else { |
| 8476 // Found duplicate definition. | 8487 // Found duplicate definition. |
| 8477 Error& ambiguous_ref_error = Error::Handle(); | 8488 Error& ambiguous_ref_error = Error::Handle(); |
| 8478 if (first_lib_url.raw() == lib.url()) { | 8489 if (first_lib_url.raw() == lib.url()) { |
| 8479 ambiguous_ref_error = FormatErrorMsg( | 8490 ambiguous_ref_error = FormatErrorMsg( |
| 8480 script_, ident_pos, "Error", | 8491 script_, ident_pos, "Error", |
| 8481 "ambiguous reference: '%s.%s' is imported multiple times", | 8492 "ambiguous reference: '%s.%s' is imported multiple times", |
| 8482 String::Handle(prefix.name()).ToCString(), | 8493 String::Handle(prefix.name()).ToCString(), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8643 } else { | 8654 } else { |
| 8644 ParseQualIdent(&type_name); | 8655 ParseQualIdent(&type_name); |
| 8645 // An identifier cannot be resolved in a local scope when top level parsing. | 8656 // An identifier cannot be resolved in a local scope when top level parsing. |
| 8646 if (!is_top_level_ && | 8657 if (!is_top_level_ && |
| 8647 (type_name.lib_prefix == NULL) && | 8658 (type_name.lib_prefix == NULL) && |
| 8648 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { | 8659 ResolveIdentInLocalScope(type_name.ident_pos, *type_name.ident, NULL)) { |
| 8649 ErrorMsg(type_name.ident_pos, "using '%s' in this context is invalid", | 8660 ErrorMsg(type_name.ident_pos, "using '%s' in this context is invalid", |
| 8650 type_name.ident->ToCString()); | 8661 type_name.ident->ToCString()); |
| 8651 } | 8662 } |
| 8652 } | 8663 } |
| 8653 Object& type_class = Object::Handle(); | 8664 Object& type_class = Object::Handle(isolate()); |
| 8654 // Leave type_class as null if type finalization mode is kIgnore. | 8665 // Leave type_class as null if type finalization mode is kIgnore. |
| 8655 if (finalization != ClassFinalizer::kIgnore) { | 8666 if (finalization != ClassFinalizer::kIgnore) { |
| 8656 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 8667 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(isolate()); |
| 8657 if (type_name.lib_prefix != NULL) { | 8668 if (type_name.lib_prefix != NULL) { |
| 8658 lib_prefix = type_name.lib_prefix->raw(); | 8669 lib_prefix = type_name.lib_prefix->raw(); |
| 8659 } | 8670 } |
| 8660 type_class = UnresolvedClass::New(lib_prefix, | 8671 type_class = UnresolvedClass::New(lib_prefix, |
| 8661 *type_name.ident, | 8672 *type_name.ident, |
| 8662 type_name.ident_pos); | 8673 type_name.ident_pos); |
| 8663 } | 8674 } |
| 8664 Error& malformed_error = Error::Handle(); | 8675 Error& malformed_error = Error::Handle(isolate()); |
| 8665 AbstractTypeArguments& type_arguments = | 8676 AbstractTypeArguments& type_arguments = |
| 8666 AbstractTypeArguments::Handle(ParseTypeArguments(&malformed_error, | 8677 AbstractTypeArguments::Handle(isolate(), |
| 8678 ParseTypeArguments(&malformed_error, |
| 8667 finalization)); | 8679 finalization)); |
| 8668 if (finalization == ClassFinalizer::kIgnore) { | 8680 if (finalization == ClassFinalizer::kIgnore) { |
| 8669 return Type::DynamicType(); | 8681 return Type::DynamicType(); |
| 8670 } | 8682 } |
| 8671 AbstractType& type = AbstractType::Handle( | 8683 AbstractType& type = AbstractType::Handle( |
| 8684 isolate(), |
| 8672 Type::New(type_class, type_arguments, type_name.ident_pos)); | 8685 Type::New(type_class, type_arguments, type_name.ident_pos)); |
| 8673 // In production mode, malformed type arguments are mapped to dynamic. | 8686 // In production mode, malformed type arguments are mapped to dynamic. |
| 8674 // In checked mode, a type with malformed type arguments is malformed. | 8687 // In checked mode, a type with malformed type arguments is malformed. |
| 8675 if (FLAG_enable_type_checks && !malformed_error.IsNull()) { | 8688 if (FLAG_enable_type_checks && !malformed_error.IsNull()) { |
| 8676 Type& parameterized_type = Type::Handle(); | 8689 Type& parameterized_type = Type::Handle(isolate()); |
| 8677 parameterized_type ^= type.raw(); | 8690 parameterized_type ^= type.raw(); |
| 8678 parameterized_type.set_type_class(Class::Handle(Object::dynamic_class())); | 8691 parameterized_type.set_type_class( |
| 8692 Class::Handle(isolate(), Object::dynamic_class())); |
| 8679 parameterized_type.set_arguments( | 8693 parameterized_type.set_arguments( |
| 8680 AbstractTypeArguments::null_object()); | 8694 AbstractTypeArguments::null_object()); |
| 8681 parameterized_type.set_malformed_error(malformed_error); | 8695 parameterized_type.set_malformed_error(malformed_error); |
| 8682 } | 8696 } |
| 8683 if (finalization >= ClassFinalizer::kTryResolve) { | 8697 if (finalization >= ClassFinalizer::kTryResolve) { |
| 8684 ResolveTypeFromClass(current_class(), finalization, &type); | 8698 ResolveTypeFromClass(current_class(), finalization, &type); |
| 8685 if (finalization >= ClassFinalizer::kCanonicalize) { | 8699 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 8686 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); | 8700 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); |
| 8687 } | 8701 } |
| 8688 } | 8702 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8733 "the element type"); | 8747 "the element type"); |
| 8734 } | 8748 } |
| 8735 if (is_const && !element_type.IsInstantiated()) { | 8749 if (is_const && !element_type.IsInstantiated()) { |
| 8736 ErrorMsg(type_pos, | 8750 ErrorMsg(type_pos, |
| 8737 "the type argument of a constant list literal cannot include " | 8751 "the type argument of a constant list literal cannot include " |
| 8738 "a type variable"); | 8752 "a type variable"); |
| 8739 } | 8753 } |
| 8740 } | 8754 } |
| 8741 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); | 8755 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); |
| 8742 const Class& array_class = Class::Handle( | 8756 const Class& array_class = Class::Handle( |
| 8743 Isolate::Current()->object_store()->array_class()); | 8757 isolate()->object_store()->array_class()); |
| 8744 Type& type = Type::ZoneHandle( | 8758 Type& type = Type::ZoneHandle( |
| 8745 Type::New(array_class, type_arguments, type_pos)); | 8759 Type::New(array_class, type_arguments, type_pos)); |
| 8746 type ^= ClassFinalizer::FinalizeType( | 8760 type ^= ClassFinalizer::FinalizeType( |
| 8747 current_class(), type, ClassFinalizer::kCanonicalize); | 8761 current_class(), type, ClassFinalizer::kCanonicalize); |
| 8748 GrowableArray<AstNode*> element_list; | 8762 GrowableArray<AstNode*> element_list; |
| 8749 // Parse the list elements. Note: there may be an optional extra | 8763 // Parse the list elements. Note: there may be an optional extra |
| 8750 // comma after the last element. | 8764 // comma after the last element. |
| 8751 if (!is_empty_literal) { | 8765 if (!is_empty_literal) { |
| 8752 const bool saved_mode = SetAllowFunctionLiterals(true); | 8766 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 8753 while (CurrentToken() != Token::kRBRACK) { | 8767 while (CurrentToken() != Token::kRBRACK) { |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9658 ReturnNode* ret = new ReturnNode(expr->token_pos(), expr); | 9672 ReturnNode* ret = new ReturnNode(expr->token_pos(), expr); |
| 9659 // Compile time constant expressions cannot reference anything from a | 9673 // Compile time constant expressions cannot reference anything from a |
| 9660 // local scope. | 9674 // local scope. |
| 9661 LocalScope* empty_scope = new LocalScope(NULL, 0, 0); | 9675 LocalScope* empty_scope = new LocalScope(NULL, 0, 0); |
| 9662 SequenceNode* seq = new SequenceNode(expr->token_pos(), empty_scope); | 9676 SequenceNode* seq = new SequenceNode(expr->token_pos(), empty_scope); |
| 9663 seq->Add(ret); | 9677 seq->Add(ret); |
| 9664 | 9678 |
| 9665 Object& result = Object::Handle(Compiler::ExecuteOnce(seq)); | 9679 Object& result = Object::Handle(Compiler::ExecuteOnce(seq)); |
| 9666 if (result.IsError()) { | 9680 if (result.IsError()) { |
| 9667 // Propagate the compilation error. | 9681 // Propagate the compilation error. |
| 9668 Isolate::Current()->long_jump_base()->Jump(1, Error::Cast(result)); | 9682 isolate()->long_jump_base()->Jump(1, Error::Cast(result)); |
| 9669 UNREACHABLE(); | 9683 UNREACHABLE(); |
| 9670 } | 9684 } |
| 9671 ASSERT(result.IsInstance()); | 9685 ASSERT(result.IsInstance()); |
| 9672 Instance& value = Instance::ZoneHandle(); | 9686 Instance& value = Instance::ZoneHandle(); |
| 9673 value ^= result.raw(); | 9687 value ^= result.raw(); |
| 9674 if (!value.IsNull()) { | 9688 if (!value.IsNull()) { |
| 9675 value ^= value.Canonicalize(); | 9689 value ^= value.Canonicalize(); |
| 9676 } | 9690 } |
| 9677 return value; | 9691 return value; |
| 9678 } | 9692 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9960 void Parser::SkipQualIdent() { | 9974 void Parser::SkipQualIdent() { |
| 9961 ASSERT(IsIdentifier()); | 9975 ASSERT(IsIdentifier()); |
| 9962 ConsumeToken(); | 9976 ConsumeToken(); |
| 9963 if (CurrentToken() == Token::kPERIOD) { | 9977 if (CurrentToken() == Token::kPERIOD) { |
| 9964 ConsumeToken(); // Consume the kPERIOD token. | 9978 ConsumeToken(); // Consume the kPERIOD token. |
| 9965 ExpectIdentifier("identifier expected after '.'"); | 9979 ExpectIdentifier("identifier expected after '.'"); |
| 9966 } | 9980 } |
| 9967 } | 9981 } |
| 9968 | 9982 |
| 9969 } // namespace dart | 9983 } // namespace dart |
| OLD | NEW |