| 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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 | 453 |
| 454 // For parsing a compilation unit. | 454 // For parsing a compilation unit. |
| 455 Parser::Parser(const Script& script, | 455 Parser::Parser(const Script& script, |
| 456 const Library& library, | 456 const Library& library, |
| 457 TokenPosition token_pos) | 457 TokenPosition token_pos) |
| 458 : thread_(Thread::Current()), | 458 : thread_(Thread::Current()), |
| 459 isolate_(thread()->isolate()), | 459 isolate_(thread()->isolate()), |
| 460 allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld), |
| 460 script_(Script::Handle(zone(), script.raw())), | 461 script_(Script::Handle(zone(), script.raw())), |
| 461 tokens_iterator_(zone(), | 462 tokens_iterator_(zone(), |
| 462 TokenStream::Handle(zone(), script.tokens()), | 463 TokenStream::Handle(zone(), script.tokens()), |
| 463 token_pos), | 464 token_pos), |
| 464 token_kind_(Token::kILLEGAL), | 465 token_kind_(Token::kILLEGAL), |
| 465 current_block_(NULL), | 466 current_block_(NULL), |
| 466 is_top_level_(false), | 467 is_top_level_(false), |
| 467 await_is_keyword_(false), | 468 await_is_keyword_(false), |
| 468 current_member_(NULL), | 469 current_member_(NULL), |
| 469 allow_function_literals_(true), | 470 allow_function_literals_(true), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 482 ASSERT(!library.IsNull()); | 483 ASSERT(!library.IsNull()); |
| 483 } | 484 } |
| 484 | 485 |
| 485 | 486 |
| 486 // For parsing a function. | 487 // For parsing a function. |
| 487 Parser::Parser(const Script& script, | 488 Parser::Parser(const Script& script, |
| 488 ParsedFunction* parsed_function, | 489 ParsedFunction* parsed_function, |
| 489 TokenPosition token_pos) | 490 TokenPosition token_pos) |
| 490 : thread_(Thread::Current()), | 491 : thread_(Thread::Current()), |
| 491 isolate_(thread()->isolate()), | 492 isolate_(thread()->isolate()), |
| 493 allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld), |
| 492 script_(Script::Handle(zone(), script.raw())), | 494 script_(Script::Handle(zone(), script.raw())), |
| 493 tokens_iterator_(zone(), | 495 tokens_iterator_(zone(), |
| 494 TokenStream::Handle(zone(), script.tokens()), | 496 TokenStream::Handle(zone(), script.tokens()), |
| 495 token_pos), | 497 token_pos), |
| 496 token_kind_(Token::kILLEGAL), | 498 token_kind_(Token::kILLEGAL), |
| 497 current_block_(NULL), | 499 current_block_(NULL), |
| 498 is_top_level_(false), | 500 is_top_level_(false), |
| 499 await_is_keyword_(false), | 501 await_is_keyword_(false), |
| 500 current_member_(NULL), | 502 current_member_(NULL), |
| 501 allow_function_literals_(true), | 503 allow_function_literals_(true), |
| (...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 unexpected_token_found = true; | 1946 unexpected_token_found = true; |
| 1945 break; | 1947 break; |
| 1946 default: | 1948 default: |
| 1947 // nothing. | 1949 // nothing. |
| 1948 break; | 1950 break; |
| 1949 } | 1951 } |
| 1950 } while (!token_stack.is_empty() && is_match && !unexpected_token_found); | 1952 } while (!token_stack.is_empty() && is_match && !unexpected_token_found); |
| 1951 if (!is_match) { | 1953 if (!is_match) { |
| 1952 const Error& error = Error::Handle(LanguageError::NewFormatted( | 1954 const Error& error = Error::Handle(LanguageError::NewFormatted( |
| 1953 Error::Handle(), script_, opening_pos, Report::AtLocation, | 1955 Error::Handle(), script_, opening_pos, Report::AtLocation, |
| 1954 Report::kWarning, Heap::kNew, "unbalanced '%s' opens here", | 1956 Report::kWarning, allocation_space_, "unbalanced '%s' opens here", |
| 1955 Token::Str(opening_token))); | 1957 Token::Str(opening_token))); |
| 1956 ReportErrors(error, script_, token_pos, "unbalanced '%s'", | 1958 ReportErrors(error, script_, token_pos, "unbalanced '%s'", |
| 1957 Token::Str(token)); | 1959 Token::Str(token)); |
| 1958 } else if (unexpected_token_found) { | 1960 } else if (unexpected_token_found) { |
| 1959 ReportError(start_pos, "unterminated '%s'", Token::Str(opening_token)); | 1961 ReportError(start_pos, "unterminated '%s'", Token::Str(opening_token)); |
| 1960 } | 1962 } |
| 1961 } | 1963 } |
| 1962 | 1964 |
| 1963 | 1965 |
| 1964 void Parser::SkipBlock() { | 1966 void Parser::SkipBlock() { |
| (...skipping 3696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5661 void Parser::ParseInterfaceList(const Class& cls) { | 5663 void Parser::ParseInterfaceList(const Class& cls) { |
| 5662 TRACE_PARSER("ParseInterfaceList"); | 5664 TRACE_PARSER("ParseInterfaceList"); |
| 5663 ASSERT(CurrentToken() == Token::kIMPLEMENTS); | 5665 ASSERT(CurrentToken() == Token::kIMPLEMENTS); |
| 5664 const GrowableObjectArray& all_interfaces = | 5666 const GrowableObjectArray& all_interfaces = |
| 5665 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 5667 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 5666 AbstractType& interface = AbstractType::Handle(Z); | 5668 AbstractType& interface = AbstractType::Handle(Z); |
| 5667 // First get all the interfaces already implemented by class. | 5669 // First get all the interfaces already implemented by class. |
| 5668 Array& cls_interfaces = Array::Handle(Z, cls.interfaces()); | 5670 Array& cls_interfaces = Array::Handle(Z, cls.interfaces()); |
| 5669 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { | 5671 for (intptr_t i = 0; i < cls_interfaces.Length(); i++) { |
| 5670 interface ^= cls_interfaces.At(i); | 5672 interface ^= cls_interfaces.At(i); |
| 5671 all_interfaces.Add(interface); | 5673 all_interfaces.Add(interface, Heap::kOld); |
| 5672 } | 5674 } |
| 5673 // Now parse and add the new interfaces. | 5675 // Now parse and add the new interfaces. |
| 5674 do { | 5676 do { |
| 5675 ConsumeToken(); | 5677 ConsumeToken(); |
| 5676 TokenPosition interface_pos = TokenPos(); | 5678 TokenPosition interface_pos = TokenPos(); |
| 5677 interface = ParseType(ClassFinalizer::kResolveTypeParameters); | 5679 interface = ParseType(ClassFinalizer::kResolveTypeParameters); |
| 5678 if (interface.IsTypeParameter()) { | 5680 if (interface.IsTypeParameter()) { |
| 5679 ReportError(interface_pos, | 5681 ReportError(interface_pos, |
| 5680 "type parameter '%s' may not be used in interface list", | 5682 "type parameter '%s' may not be used in interface list", |
| 5681 String::Handle(Z, interface.UserVisibleName()).ToCString()); | 5683 String::Handle(Z, interface.UserVisibleName()).ToCString()); |
| 5682 } | 5684 } |
| 5683 all_interfaces.Add(interface); | 5685 all_interfaces.Add(interface, Heap::kOld); |
| 5684 } while (CurrentToken() == Token::kCOMMA); | 5686 } while (CurrentToken() == Token::kCOMMA); |
| 5685 cls_interfaces = Array::MakeArray(all_interfaces); | 5687 cls_interfaces = Array::MakeArray(all_interfaces); |
| 5686 cls.set_interfaces(cls_interfaces); | 5688 cls.set_interfaces(cls_interfaces); |
| 5687 } | 5689 } |
| 5688 | 5690 |
| 5689 | 5691 |
| 5690 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { | 5692 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { |
| 5691 TRACE_PARSER("ParseMixins"); | 5693 TRACE_PARSER("ParseMixins"); |
| 5692 ASSERT(CurrentToken() == Token::kWITH); | 5694 ASSERT(CurrentToken() == Token::kWITH); |
| 5693 const GrowableObjectArray& mixin_types = | 5695 const GrowableObjectArray& mixin_types = |
| 5694 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 5696 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 5695 AbstractType& mixin_type = AbstractType::Handle(Z); | 5697 AbstractType& mixin_type = AbstractType::Handle(Z); |
| 5696 do { | 5698 do { |
| 5697 ConsumeToken(); | 5699 ConsumeToken(); |
| 5698 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); | 5700 mixin_type = ParseType(ClassFinalizer::kResolveTypeParameters); |
| 5699 if (mixin_type.IsDynamicType()) { | 5701 if (mixin_type.IsDynamicType()) { |
| 5700 // The string 'dynamic' is not resolved yet at this point, but a malformed | 5702 // The string 'dynamic' is not resolved yet at this point, but a malformed |
| 5701 // type mapped to dynamic can be encountered here. | 5703 // type mapped to dynamic can be encountered here. |
| 5702 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type"); | 5704 ReportError(mixin_type.token_pos(), "illegal mixin of a malformed type"); |
| 5703 } | 5705 } |
| 5704 if (mixin_type.IsTypeParameter()) { | 5706 if (mixin_type.IsTypeParameter()) { |
| 5705 ReportError(mixin_type.token_pos(), | 5707 ReportError(mixin_type.token_pos(), |
| 5706 "mixin type '%s' may not be a type parameter", | 5708 "mixin type '%s' may not be a type parameter", |
| 5707 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); | 5709 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); |
| 5708 } | 5710 } |
| 5709 mixin_types.Add(mixin_type); | 5711 mixin_types.Add(mixin_type, Heap::kOld); |
| 5710 } while (CurrentToken() == Token::kCOMMA); | 5712 } while (CurrentToken() == Token::kCOMMA); |
| 5711 return MixinAppType::New(super_type, | 5713 return MixinAppType::New(super_type, |
| 5712 Array::Handle(Z, Array::MakeArray(mixin_types))); | 5714 Array::Handle(Z, Array::MakeArray(mixin_types))); |
| 5713 } | 5715 } |
| 5714 | 5716 |
| 5715 | 5717 |
| 5716 void Parser::ParseTopLevelVariable(TopLevel* top_level, | 5718 void Parser::ParseTopLevelVariable(TopLevel* top_level, |
| 5717 const Object& owner, | 5719 const Object& owner, |
| 5718 TokenPosition metadata_pos) { | 5720 TokenPosition metadata_pos) { |
| 5719 TRACE_PARSER("ParseTopLevelVariable"); | 5721 TRACE_PARSER("ParseTopLevelVariable"); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6177 library_.SetName(lib_name); | 6179 library_.SetName(lib_name); |
| 6178 ExpectSemicolon(); | 6180 ExpectSemicolon(); |
| 6179 } | 6181 } |
| 6180 | 6182 |
| 6181 | 6183 |
| 6182 void Parser::ParseIdentList(GrowableObjectArray* names) { | 6184 void Parser::ParseIdentList(GrowableObjectArray* names) { |
| 6183 if (!IsIdentifier()) { | 6185 if (!IsIdentifier()) { |
| 6184 ReportError("identifier expected"); | 6186 ReportError("identifier expected"); |
| 6185 } | 6187 } |
| 6186 while (IsIdentifier()) { | 6188 while (IsIdentifier()) { |
| 6187 names->Add(*CurrentLiteral()); | 6189 names->Add(*CurrentLiteral(), allocation_space_); |
| 6188 ConsumeToken(); // Identifier. | 6190 ConsumeToken(); // Identifier. |
| 6189 if (CurrentToken() != Token::kCOMMA) { | 6191 if (CurrentToken() != Token::kCOMMA) { |
| 6190 return; | 6192 return; |
| 6191 } | 6193 } |
| 6192 ConsumeToken(); // Comma. | 6194 ConsumeToken(); // Comma. |
| 6193 } | 6195 } |
| 6194 } | 6196 } |
| 6195 | 6197 |
| 6196 | 6198 |
| 6197 void Parser::ParseLibraryImportExport(const Object& tl_owner, | 6199 void Parser::ParseLibraryImportExport(const Object& tl_owner, |
| 6198 TokenPosition metadata_pos) { | 6200 TokenPosition metadata_pos) { |
| 6199 ASSERT(Thread::Current()->IsMutatorThread()); | 6201 ASSERT(Thread::Current()->IsMutatorThread()); |
| 6200 bool is_import = (CurrentToken() == Token::kIMPORT); | 6202 bool is_import = (CurrentToken() == Token::kIMPORT); |
| 6201 bool is_export = (CurrentToken() == Token::kEXPORT); | 6203 bool is_export = (CurrentToken() == Token::kEXPORT); |
| 6202 ASSERT(is_import || is_export); | 6204 ASSERT(is_import || is_export); |
| 6203 const TokenPosition import_pos = TokenPos(); | 6205 const TokenPosition import_pos = TokenPos(); |
| 6204 ConsumeToken(); | 6206 ConsumeToken(); |
| 6205 CheckToken(Token::kSTRING, "library url expected"); | 6207 CheckToken(Token::kSTRING, "library url expected"); |
| 6206 AstNode* url_literal = ParseStringLiteral(false); | 6208 AstNode* url_literal = ParseStringLiteral(false); |
| 6207 if (FLAG_conditional_directives) { | 6209 if (FLAG_conditional_directives) { |
| 6208 bool condition_triggered = false; | 6210 bool condition_triggered = false; |
| 6209 while (CurrentToken() == Token::kIF) { | 6211 while (CurrentToken() == Token::kIF) { |
| 6210 // Conditional import: if (env == val) uri. | 6212 // Conditional import: if (env == val) uri. |
| 6211 ConsumeToken(); | 6213 ConsumeToken(); |
| 6212 ExpectToken(Token::kLPAREN); | 6214 ExpectToken(Token::kLPAREN); |
| 6213 // Parse dotted name. | 6215 // Parse dotted name. |
| 6214 const GrowableObjectArray& pieces = | 6216 const GrowableObjectArray& pieces = GrowableObjectArray::Handle( |
| 6215 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6217 Z, GrowableObjectArray::New(allocation_space_)); |
| 6216 pieces.Add(*ExpectIdentifier("identifier expected")); | 6218 pieces.Add(*ExpectIdentifier("identifier expected"), allocation_space_); |
| 6217 while (CurrentToken() == Token::kPERIOD) { | 6219 while (CurrentToken() == Token::kPERIOD) { |
| 6218 pieces.Add(Symbols::Dot()); | 6220 pieces.Add(Symbols::Dot(), allocation_space_); |
| 6219 ConsumeToken(); | 6221 ConsumeToken(); |
| 6220 pieces.Add(*ExpectIdentifier("identifier expected")); | 6222 pieces.Add(*ExpectIdentifier("identifier expected"), allocation_space_); |
| 6221 } | 6223 } |
| 6222 AstNode* valueNode = NULL; | 6224 AstNode* valueNode = NULL; |
| 6223 if (CurrentToken() == Token::kEQ) { | 6225 if (CurrentToken() == Token::kEQ) { |
| 6224 ConsumeToken(); | 6226 ConsumeToken(); |
| 6225 CheckToken(Token::kSTRING, "string literal expected"); | 6227 CheckToken(Token::kSTRING, "string literal expected"); |
| 6226 valueNode = ParseStringLiteral(false); | 6228 valueNode = ParseStringLiteral(false); |
| 6227 ASSERT(valueNode->IsLiteralNode()); | 6229 ASSERT(valueNode->IsLiteralNode()); |
| 6228 ASSERT(valueNode->AsLiteralNode()->literal().IsString()); | 6230 ASSERT(valueNode->AsLiteralNode()->literal().IsString()); |
| 6229 } | 6231 } |
| 6230 ExpectToken(Token::kRPAREN); | 6232 ExpectToken(Token::kRPAREN); |
| 6231 CheckToken(Token::kSTRING, "library url expected"); | 6233 CheckToken(Token::kSTRING, "library url expected"); |
| 6232 AstNode* conditional_url_literal = ParseStringLiteral(false); | 6234 AstNode* conditional_url_literal = ParseStringLiteral(false); |
| 6233 | 6235 |
| 6234 // If there was already a condition that triggered, don't try to match | 6236 // If there was already a condition that triggered, don't try to match |
| 6235 // again. | 6237 // again. |
| 6236 if (condition_triggered) { | 6238 if (condition_triggered) { |
| 6237 continue; | 6239 continue; |
| 6238 } | 6240 } |
| 6239 // Check if this conditional line overrides the default import. | 6241 // Check if this conditional line overrides the default import. |
| 6240 const String& key = String::Handle( | 6242 const String& key = String::Handle(String::ConcatAll( |
| 6241 String::ConcatAll(Array::Handle(Array::MakeArray(pieces)))); | 6243 Array::Handle(Array::MakeArray(pieces)), allocation_space_)); |
| 6242 const String& value = | 6244 const String& value = |
| 6243 (valueNode == NULL) | 6245 (valueNode == NULL) |
| 6244 ? Symbols::True() | 6246 ? Symbols::True() |
| 6245 : String::Cast(valueNode->AsLiteralNode()->literal()); | 6247 : String::Cast(valueNode->AsLiteralNode()->literal()); |
| 6246 // Call the embedder to supply us with the environment. | 6248 // Call the embedder to supply us with the environment. |
| 6247 const String& env_value = | 6249 const String& env_value = |
| 6248 String::Handle(Api::GetEnvironmentValue(T, key)); | 6250 String::Handle(Api::GetEnvironmentValue(T, key)); |
| 6249 if (!env_value.IsNull() && env_value.Equals(value)) { | 6251 if (!env_value.IsNull() && env_value.Equals(value)) { |
| 6250 condition_triggered = true; | 6252 condition_triggered = true; |
| 6251 url_literal = conditional_url_literal; | 6253 url_literal = conditional_url_literal; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6269 if (is_import && (CurrentToken() == Token::kAS)) { | 6271 if (is_import && (CurrentToken() == Token::kAS)) { |
| 6270 ConsumeToken(); | 6272 ConsumeToken(); |
| 6271 prefix_pos = TokenPos(); | 6273 prefix_pos = TokenPos(); |
| 6272 prefix = ExpectIdentifier("prefix identifier expected")->raw(); | 6274 prefix = ExpectIdentifier("prefix identifier expected")->raw(); |
| 6273 } | 6275 } |
| 6274 | 6276 |
| 6275 Array& show_names = Array::Handle(Z); | 6277 Array& show_names = Array::Handle(Z); |
| 6276 Array& hide_names = Array::Handle(Z); | 6278 Array& hide_names = Array::Handle(Z); |
| 6277 if (is_deferred_import || IsSymbol(Symbols::Show()) || | 6279 if (is_deferred_import || IsSymbol(Symbols::Show()) || |
| 6278 IsSymbol(Symbols::Hide())) { | 6280 IsSymbol(Symbols::Hide())) { |
| 6279 GrowableObjectArray& show_list = | 6281 GrowableObjectArray& show_list = GrowableObjectArray::Handle( |
| 6280 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6282 Z, GrowableObjectArray::New(allocation_space_)); |
| 6281 GrowableObjectArray& hide_list = | 6283 GrowableObjectArray& hide_list = GrowableObjectArray::Handle( |
| 6282 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6284 Z, GrowableObjectArray::New(allocation_space_)); |
| 6283 // Libraries imported through deferred import automatically hide | 6285 // Libraries imported through deferred import automatically hide |
| 6284 // the name 'loadLibrary'. | 6286 // the name 'loadLibrary'. |
| 6285 if (is_deferred_import) { | 6287 if (is_deferred_import) { |
| 6286 hide_list.Add(Symbols::LoadLibrary()); | 6288 hide_list.Add(Symbols::LoadLibrary()); |
| 6287 } | 6289 } |
| 6288 for (;;) { | 6290 for (;;) { |
| 6289 if (IsSymbol(Symbols::Show())) { | 6291 if (IsSymbol(Symbols::Show())) { |
| 6290 ConsumeToken(); | 6292 ConsumeToken(); |
| 6291 ParseIdentList(&show_list); | 6293 ParseIdentList(&show_list); |
| 6292 } else if (IsSymbol(Symbols::Hide())) { | 6294 } else if (IsSymbol(Symbols::Hide())) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6741 finally_clause = NULL; | 6743 finally_clause = NULL; |
| 6742 AddFinallyClauseToNode(true, node_to_inline, node); | 6744 AddFinallyClauseToNode(true, node_to_inline, node); |
| 6743 node_index++; | 6745 node_index++; |
| 6744 } | 6746 } |
| 6745 } while (finally_clause == NULL); | 6747 } while (finally_clause == NULL); |
| 6746 | 6748 |
| 6747 if (try_stack_ != NULL) { | 6749 if (try_stack_ != NULL) { |
| 6748 try_stack_->exit_finally(); | 6750 try_stack_->exit_finally(); |
| 6749 } | 6751 } |
| 6750 | 6752 |
| 6751 const GrowableObjectArray& handler_types = | |
| 6752 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | |
| 6753 // Catch block handles all exceptions. | 6753 // Catch block handles all exceptions. |
| 6754 handler_types.Add(Object::dynamic_type()); | 6754 const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld)); |
| 6755 handler_types.SetAt(0, Object::dynamic_type()); |
| 6755 | 6756 |
| 6756 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( | 6757 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( |
| 6757 TokenPosition::kNoSource, catch_handler_list, | 6758 TokenPosition::kNoSource, catch_handler_list, handler_types, context_var, |
| 6758 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var, | |
| 6759 exception_var, stack_trace_var, saved_exception_var, | 6759 exception_var, stack_trace_var, saved_exception_var, |
| 6760 saved_stack_trace_var, AllocateTryIndex(), true); | 6760 saved_stack_trace_var, AllocateTryIndex(), true); |
| 6761 | 6761 |
| 6762 const intptr_t try_index = try_statement->try_index(); | 6762 const intptr_t try_index = try_statement->try_index(); |
| 6763 | 6763 |
| 6764 AstNode* try_catch_node = new (Z) | 6764 AstNode* try_catch_node = new (Z) |
| 6765 TryCatchNode(TokenPosition::kNoSource, body, context_var, catch_clause, | 6765 TryCatchNode(TokenPosition::kNoSource, body, context_var, catch_clause, |
| 6766 finally_clause, try_index, finally_clause); | 6766 finally_clause, try_index, finally_clause); |
| 6767 current_block_->statements->Add(try_catch_node); | 6767 current_block_->statements->Add(try_catch_node); |
| 6768 return CloseBlock(); | 6768 return CloseBlock(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6843 new (Z) LoadLocalNode(TokenPosition::kNoSource, async_completer), | 6843 new (Z) LoadLocalNode(TokenPosition::kNoSource, async_completer), |
| 6844 Symbols::CompleterCompleteError(), completer_args)); | 6844 Symbols::CompleterCompleteError(), completer_args)); |
| 6845 ReturnNode* return_node = new (Z) ReturnNode(func_end_pos); | 6845 ReturnNode* return_node = new (Z) ReturnNode(func_end_pos); |
| 6846 // Behavior like a continuation return, i.e,. don't call a completer. | 6846 // Behavior like a continuation return, i.e,. don't call a completer. |
| 6847 return_node->set_return_type(ReturnNode::kContinuation); | 6847 return_node->set_return_type(ReturnNode::kContinuation); |
| 6848 current_block_->statements->Add(return_node); | 6848 current_block_->statements->Add(return_node); |
| 6849 AstNode* catch_block = CloseBlock(); | 6849 AstNode* catch_block = CloseBlock(); |
| 6850 current_block_->statements->Add(catch_block); | 6850 current_block_->statements->Add(catch_block); |
| 6851 SequenceNode* catch_handler_list = CloseBlock(); | 6851 SequenceNode* catch_handler_list = CloseBlock(); |
| 6852 | 6852 |
| 6853 const GrowableObjectArray& handler_types = | 6853 const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld)); |
| 6854 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 6854 handler_types.SetAt(0, *exception_param.type); |
| 6855 handler_types.SetLength(0); | |
| 6856 handler_types.Add(*exception_param.type); | |
| 6857 | 6855 |
| 6858 TryStack* try_statement = PopTry(); | 6856 TryStack* try_statement = PopTry(); |
| 6859 const intptr_t try_index = try_statement->try_index(); | 6857 const intptr_t try_index = try_statement->try_index(); |
| 6860 | 6858 |
| 6861 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( | 6859 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( |
| 6862 TokenPosition::kNoSource, catch_handler_list, | 6860 TokenPosition::kNoSource, catch_handler_list, handler_types, context_var, |
| 6863 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var, | |
| 6864 exception_var, stack_trace_var, saved_exception_var, | 6861 exception_var, stack_trace_var, saved_exception_var, |
| 6865 saved_stack_trace_var, CatchClauseNode::kInvalidTryIndex, true); | 6862 saved_stack_trace_var, CatchClauseNode::kInvalidTryIndex, true); |
| 6866 AstNode* try_catch_node = new (Z) TryCatchNode( | 6863 AstNode* try_catch_node = new (Z) TryCatchNode( |
| 6867 TokenPosition::kNoSource, try_block, context_var, catch_clause, | 6864 TokenPosition::kNoSource, try_block, context_var, catch_clause, |
| 6868 NULL, // No finally clause. | 6865 NULL, // No finally clause. |
| 6869 try_index, | 6866 try_index, |
| 6870 NULL); // No rethrow-finally clause. | 6867 NULL); // No rethrow-finally clause. |
| 6871 current_block_->statements->Add(try_catch_node); | 6868 current_block_->statements->Add(try_catch_node); |
| 6872 return CloseBlock(); | 6869 return CloseBlock(); |
| 6873 } | 6870 } |
| (...skipping 3159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10033 type_tests.Add(new (Z) LiteralNode(catch_pos, Bool::True())); | 10030 type_tests.Add(new (Z) LiteralNode(catch_pos, Bool::True())); |
| 10034 if (is_bad_type) { | 10031 if (is_bad_type) { |
| 10035 // Replace the body with one that throws. | 10032 // Replace the body with one that throws. |
| 10036 SequenceNode* block = new (Z) SequenceNode(catch_pos, NULL); | 10033 SequenceNode* block = new (Z) SequenceNode(catch_pos, NULL); |
| 10037 block->Add(ThrowTypeError(catch_pos, *exception_param.type)); | 10034 block->Add(ThrowTypeError(catch_pos, *exception_param.type)); |
| 10038 catch_blocks.Last() = block; | 10035 catch_blocks.Last() = block; |
| 10039 } | 10036 } |
| 10040 // This catch clause will handle all exceptions. We can safely forget | 10037 // This catch clause will handle all exceptions. We can safely forget |
| 10041 // all previous catch clause types. | 10038 // all previous catch clause types. |
| 10042 handler_types.SetLength(0); | 10039 handler_types.SetLength(0); |
| 10043 handler_types.Add(*exception_param.type); | 10040 handler_types.Add(*exception_param.type, Heap::kOld); |
| 10044 } else { | 10041 } else { |
| 10045 // Has a type specification that is not malformed or malbounded. Now | 10042 // Has a type specification that is not malformed or malbounded. Now |
| 10046 // form an 'if type check' to guard the catch handler code. | 10043 // form an 'if type check' to guard the catch handler code. |
| 10047 if (!exception_param.type->IsInstantiated() && (FunctionLevel() > 0)) { | 10044 if (!exception_param.type->IsInstantiated() && (FunctionLevel() > 0)) { |
| 10048 // Make sure that the instantiators are captured. | 10045 // Make sure that the instantiators are captured. |
| 10049 CaptureAllInstantiators(); | 10046 CaptureAllInstantiators(); |
| 10050 } | 10047 } |
| 10051 TypeNode* exception_type = | 10048 TypeNode* exception_type = |
| 10052 new (Z) TypeNode(catch_pos, *exception_param.type); | 10049 new (Z) TypeNode(catch_pos, *exception_param.type); |
| 10053 AstNode* exception_value = | 10050 AstNode* exception_value = |
| 10054 new (Z) LoadLocalNode(catch_pos, exception_var); | 10051 new (Z) LoadLocalNode(catch_pos, exception_var); |
| 10055 if (!exception_type->type().IsInstantiated()) { | 10052 if (!exception_type->type().IsInstantiated()) { |
| 10056 EnsureExpressionTemp(); | 10053 EnsureExpressionTemp(); |
| 10057 } | 10054 } |
| 10058 type_tests.Add(new (Z) ComparisonNode(catch_pos, Token::kIS, | 10055 type_tests.Add(new (Z) ComparisonNode(catch_pos, Token::kIS, |
| 10059 exception_value, exception_type)); | 10056 exception_value, exception_type)); |
| 10060 | 10057 |
| 10061 // Do not add uninstantiated types (e.g. type parameter T or generic | 10058 // Do not add uninstantiated types (e.g. type parameter T or generic |
| 10062 // type List<T>), since the debugger won't be able to instantiate it | 10059 // type List<T>), since the debugger won't be able to instantiate it |
| 10063 // when walking the stack. | 10060 // when walking the stack. |
| 10064 // | 10061 // |
| 10065 // This means that the debugger is not able to determine whether an | 10062 // This means that the debugger is not able to determine whether an |
| 10066 // exception is caught if the catch clause uses generic types. It | 10063 // exception is caught if the catch clause uses generic types. It |
| 10067 // will report the exception as uncaught when in fact it might be | 10064 // will report the exception as uncaught when in fact it might be |
| 10068 // caught and handled when we unwind the stack. | 10065 // caught and handled when we unwind the stack. |
| 10069 if (!generic_catch_seen && exception_param.type->IsInstantiated()) { | 10066 if (!generic_catch_seen && exception_param.type->IsInstantiated()) { |
| 10070 handler_types.Add(*exception_param.type); | 10067 handler_types.Add(*exception_param.type, Heap::kOld); |
| 10071 } | 10068 } |
| 10072 } | 10069 } |
| 10073 | 10070 |
| 10074 ASSERT(type_tests.length() == catch_blocks.length()); | 10071 ASSERT(type_tests.length() == catch_blocks.length()); |
| 10075 } | 10072 } |
| 10076 | 10073 |
| 10077 // Build the if/then/else nest from the inside out. Keep the AST simple | 10074 // Build the if/then/else nest from the inside out. Keep the AST simple |
| 10078 // for the case of a single generic catch clause. The initial value of | 10075 // for the case of a single generic catch clause. The initial value of |
| 10079 // current is the last (innermost) else block if there were any catch | 10076 // current is the last (innermost) else block if there were any catch |
| 10080 // clauses. | 10077 // clauses. |
| (...skipping 2550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12631 | 12628 |
| 12632 | 12629 |
| 12633 void Parser::InsertCachedConstantValue(const Script& script, | 12630 void Parser::InsertCachedConstantValue(const Script& script, |
| 12634 TokenPosition token_pos, | 12631 TokenPosition token_pos, |
| 12635 const Instance& value) { | 12632 const Instance& value) { |
| 12636 ASSERT(Thread::Current()->IsMutatorThread()); | 12633 ASSERT(Thread::Current()->IsMutatorThread()); |
| 12637 const intptr_t kInitialConstMapSize = 16; | 12634 const intptr_t kInitialConstMapSize = 16; |
| 12638 ASSERT(!script.InVMHeap()); | 12635 ASSERT(!script.InVMHeap()); |
| 12639 if (script.compile_time_constants() == Array::null()) { | 12636 if (script.compile_time_constants() == Array::null()) { |
| 12640 const Array& array = Array::Handle( | 12637 const Array& array = Array::Handle( |
| 12641 HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kNew)); | 12638 HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kOld)); |
| 12642 script.set_compile_time_constants(array); | 12639 script.set_compile_time_constants(array); |
| 12643 } | 12640 } |
| 12644 ConstantsMap constants(script.compile_time_constants()); | 12641 ConstantsMap constants(script.compile_time_constants()); |
| 12645 constants.InsertNewOrGetValue(token_pos, value); | 12642 constants.InsertNewOrGetValue(token_pos, value); |
| 12646 script.set_compile_time_constants(constants.Release()); | 12643 script.set_compile_time_constants(constants.Release()); |
| 12647 } | 12644 } |
| 12648 | 12645 |
| 12649 | 12646 |
| 12650 void Parser::CacheConstantValue(TokenPosition token_pos, | 12647 void Parser::CacheConstantValue(TokenPosition token_pos, |
| 12651 const Instance& value) { | 12648 const Instance& value) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12779 ArgumentListNode* arguments) { | 12776 ArgumentListNode* arguments) { |
| 12780 NoReloadScope no_reload_scope(isolate(), thread()); | 12777 NoReloadScope no_reload_scope(isolate(), thread()); |
| 12781 NoOOBMessageScope no_msg_scope(thread()); | 12778 NoOOBMessageScope no_msg_scope(thread()); |
| 12782 // Factories and constructors are not generic functions. | 12779 // Factories and constructors are not generic functions. |
| 12783 const int kTypeArgsLen = 0; | 12780 const int kTypeArgsLen = 0; |
| 12784 // Factories have one extra argument: the type arguments. | 12781 // Factories have one extra argument: the type arguments. |
| 12785 // Constructors have one extra arguments: receiver. | 12782 // Constructors have one extra arguments: receiver. |
| 12786 const int kNumExtraArgs = 1; | 12783 const int kNumExtraArgs = 1; |
| 12787 const int num_arguments = arguments->length() + kNumExtraArgs; | 12784 const int num_arguments = arguments->length() + kNumExtraArgs; |
| 12788 const Array& arg_values = | 12785 const Array& arg_values = |
| 12789 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); | 12786 Array::Handle(Z, Array::New(num_arguments, allocation_space_)); |
| 12790 Instance& instance = Instance::Handle(Z); | 12787 Instance& instance = Instance::Handle(Z); |
| 12791 if (!constructor.IsFactory()) { | 12788 if (!constructor.IsFactory()) { |
| 12792 instance = Instance::New(type_class, Heap::kOld); | 12789 instance = Instance::New(type_class, allocation_space_); |
| 12793 if (!type_arguments.IsNull()) { | 12790 if (!type_arguments.IsNull()) { |
| 12794 if (!type_arguments.IsInstantiated()) { | 12791 if (!type_arguments.IsInstantiated()) { |
| 12795 ReportError("type must be constant in const constructor"); | 12792 ReportError("type must be constant in const constructor"); |
| 12796 } | 12793 } |
| 12797 instance.SetTypeArguments( | 12794 instance.SetTypeArguments( |
| 12798 TypeArguments::Handle(Z, type_arguments.Canonicalize())); | 12795 TypeArguments::Handle(Z, type_arguments.Canonicalize())); |
| 12799 } | 12796 } |
| 12800 arg_values.SetAt(0, instance); | 12797 arg_values.SetAt(0, instance); |
| 12801 } else { | 12798 } else { |
| 12802 // Prepend type_arguments to list of arguments to factory. | 12799 // Prepend type_arguments to list of arguments to factory. |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13318 (CurrentToken() == Token::kPERIOD) && | 13315 (CurrentToken() == Token::kPERIOD) && |
| 13319 (Token::IsIdentifier(LookaheadToken(1)))) { | 13316 (Token::IsIdentifier(LookaheadToken(1)))) { |
| 13320 if (!is_top_level_ && (current_block_ != NULL)) { | 13317 if (!is_top_level_ && (current_block_ != NULL)) { |
| 13321 // Add the unresolved prefix name to the list of referenced | 13318 // Add the unresolved prefix name to the list of referenced |
| 13322 // names of this scope. | 13319 // names of this scope. |
| 13323 current_block_->scope->AddReferencedName(TokenPos(), type_name); | 13320 current_block_->scope->AddReferencedName(TokenPos(), type_name); |
| 13324 } | 13321 } |
| 13325 ConsumeToken(); // Period token. | 13322 ConsumeToken(); // Period token. |
| 13326 ASSERT(IsIdentifier()); | 13323 ASSERT(IsIdentifier()); |
| 13327 String& qualified_name = String::Handle(Z, type_name.raw()); | 13324 String& qualified_name = String::Handle(Z, type_name.raw()); |
| 13328 qualified_name = String::Concat(qualified_name, Symbols::Dot()); | 13325 qualified_name = |
| 13329 qualified_name = String::Concat(qualified_name, *CurrentLiteral()); | 13326 String::Concat(qualified_name, Symbols::Dot(), allocation_space_); |
| 13327 qualified_name = |
| 13328 String::Concat(qualified_name, *CurrentLiteral(), allocation_space_); |
| 13330 ConsumeToken(); | 13329 ConsumeToken(); |
| 13331 // The type is malformed. Skip over its type arguments. | 13330 // The type is malformed. Skip over its type arguments. |
| 13332 ParseTypeArguments(ClassFinalizer::kIgnore); | 13331 ParseTypeArguments(ClassFinalizer::kIgnore); |
| 13333 return ClassFinalizer::NewFinalizedMalformedType( | 13332 return ClassFinalizer::NewFinalizedMalformedType( |
| 13334 Error::Handle(Z), // No previous error. | 13333 Error::Handle(Z), // No previous error. |
| 13335 script_, ident_pos, "qualified name '%s' does not refer to a type", | 13334 script_, ident_pos, "qualified name '%s' does not refer to a type", |
| 13336 qualified_name.ToCString()); | 13335 qualified_name.ToCString()); |
| 13337 } | 13336 } |
| 13338 | 13337 |
| 13339 // If parsing inside a local scope, check whether the type name | 13338 // If parsing inside a local scope, check whether the type name |
| (...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15255 const ArgumentListNode& function_args, | 15254 const ArgumentListNode& function_args, |
| 15256 const LocalVariable* temp_for_last_arg, | 15255 const LocalVariable* temp_for_last_arg, |
| 15257 bool is_super_invocation) { | 15256 bool is_super_invocation) { |
| 15258 UNREACHABLE(); | 15257 UNREACHABLE(); |
| 15259 return NULL; | 15258 return NULL; |
| 15260 } | 15259 } |
| 15261 | 15260 |
| 15262 } // namespace dart | 15261 } // namespace dart |
| 15263 | 15262 |
| 15264 #endif // DART_PRECOMPILED_RUNTIME | 15263 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |