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 "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 7288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7299 | 7299 |
7300 AstNode* Parser::ParseFunctionStatement(bool is_literal) { | 7300 AstNode* Parser::ParseFunctionStatement(bool is_literal) { |
7301 TRACE_PARSER("ParseFunctionStatement"); | 7301 TRACE_PARSER("ParseFunctionStatement"); |
7302 AbstractType& result_type = AbstractType::Handle(Z); | 7302 AbstractType& result_type = AbstractType::Handle(Z); |
7303 const String* variable_name = NULL; | 7303 const String* variable_name = NULL; |
7304 const String* function_name = NULL; | 7304 const String* function_name = NULL; |
7305 | 7305 |
7306 result_type = Type::DynamicType(); | 7306 result_type = Type::DynamicType(); |
7307 | 7307 |
7308 const intptr_t function_pos = TokenPos(); | 7308 const intptr_t function_pos = TokenPos(); |
| 7309 intptr_t metadata_pos = -1; |
7309 if (is_literal) { | 7310 if (is_literal) { |
7310 ASSERT(CurrentToken() == Token::kLPAREN); | 7311 ASSERT(CurrentToken() == Token::kLPAREN); |
7311 function_name = &Symbols::AnonymousClosure(); | 7312 function_name = &Symbols::AnonymousClosure(); |
7312 } else { | 7313 } else { |
| 7314 metadata_pos = SkipMetadata(); |
7313 if (CurrentToken() == Token::kVOID) { | 7315 if (CurrentToken() == Token::kVOID) { |
7314 ConsumeToken(); | 7316 ConsumeToken(); |
7315 result_type = Type::VoidType(); | 7317 result_type = Type::VoidType(); |
7316 } else if ((CurrentToken() == Token::kIDENT) && | 7318 } else if ((CurrentToken() == Token::kIDENT) && |
7317 (LookaheadToken(1) != Token::kLPAREN)) { | 7319 (LookaheadToken(1) != Token::kLPAREN)) { |
7318 result_type = ParseType(ClassFinalizer::kCanonicalize); | 7320 result_type = ParseType(ClassFinalizer::kCanonicalize); |
7319 } | 7321 } |
7320 const intptr_t name_pos = TokenPos(); | 7322 const intptr_t name_pos = TokenPos(); |
7321 variable_name = ExpectIdentifier("function name expected"); | 7323 variable_name = ExpectIdentifier("function name expected"); |
7322 function_name = variable_name; | 7324 function_name = variable_name; |
(...skipping 29 matching lines...) Expand all Loading... |
7352 if (function.IsNull() || (function.token_pos() != function_pos) || | 7354 if (function.IsNull() || (function.token_pos() != function_pos) || |
7353 (function.parent_function() != innermost_function().raw())) { | 7355 (function.parent_function() != innermost_function().raw())) { |
7354 // The function will be registered in the lookup table by the | 7356 // The function will be registered in the lookup table by the |
7355 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure | 7357 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure |
7356 // function has been properly setup. | 7358 // function has been properly setup. |
7357 is_new_closure = true; | 7359 is_new_closure = true; |
7358 function = Function::NewClosureFunction(*function_name, | 7360 function = Function::NewClosureFunction(*function_name, |
7359 innermost_function(), | 7361 innermost_function(), |
7360 function_pos); | 7362 function_pos); |
7361 function.set_result_type(result_type); | 7363 function.set_result_type(result_type); |
| 7364 if (metadata_pos >= 0) { |
| 7365 library_.AddFunctionMetadata(function, metadata_pos); |
| 7366 } |
7362 } | 7367 } |
7363 | 7368 |
7364 // The function type needs to be finalized at compile time, since the closure | 7369 // The function type needs to be finalized at compile time, since the closure |
7365 // may be type checked at run time when assigned to a function variable, | 7370 // may be type checked at run time when assigned to a function variable, |
7366 // passed as a function argument, or returned as a function result. | 7371 // passed as a function argument, or returned as a function result. |
7367 | 7372 |
7368 LocalVariable* function_variable = NULL; | 7373 LocalVariable* function_variable = NULL; |
7369 Type& function_type = Type::ZoneHandle(Z); | 7374 Type& function_type = Type::ZoneHandle(Z); |
7370 if (variable_name != NULL) { | 7375 if (variable_name != NULL) { |
7371 // Since the function type depends on the signature of the closure function, | 7376 // Since the function type depends on the signature of the closure function, |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7715 SetPosition(saved_pos); | 7720 SetPosition(saved_pos); |
7716 return is_var_decl; | 7721 return is_var_decl; |
7717 } | 7722 } |
7718 | 7723 |
7719 | 7724 |
7720 // Look ahead to detect whether the next tokens should be parsed as | 7725 // Look ahead to detect whether the next tokens should be parsed as |
7721 // a function declaration. Token position remains unchanged. | 7726 // a function declaration. Token position remains unchanged. |
7722 bool Parser::IsFunctionDeclaration() { | 7727 bool Parser::IsFunctionDeclaration() { |
7723 const intptr_t saved_pos = TokenPos(); | 7728 const intptr_t saved_pos = TokenPos(); |
7724 bool is_external = false; | 7729 bool is_external = false; |
| 7730 SkipMetadata(); |
7725 if (is_top_level_) { | 7731 if (is_top_level_) { |
7726 if (is_patch_source() && | 7732 if (is_patch_source() && |
7727 (CurrentToken() == Token::kIDENT) && | 7733 (CurrentToken() == Token::kIDENT) && |
7728 CurrentLiteral()->Equals("patch") && | 7734 CurrentLiteral()->Equals("patch") && |
7729 (LookaheadToken(1) != Token::kLPAREN)) { | 7735 (LookaheadToken(1) != Token::kLPAREN)) { |
7730 // Skip over 'patch' for top-level function declarations in patch sources. | 7736 // Skip over 'patch' for top-level function declarations in patch sources. |
7731 ConsumeToken(); | 7737 ConsumeToken(); |
7732 } else if (CurrentToken() == Token::kEXTERNAL) { | 7738 } else if (CurrentToken() == Token::kEXTERNAL) { |
7733 // Skip over 'external' for top-level function declarations. | 7739 // Skip over 'external' for top-level function declarations. |
7734 is_external = true; | 7740 is_external = true; |
(...skipping 5664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13399 void Parser::SkipQualIdent() { | 13405 void Parser::SkipQualIdent() { |
13400 ASSERT(IsIdentifier()); | 13406 ASSERT(IsIdentifier()); |
13401 ConsumeToken(); | 13407 ConsumeToken(); |
13402 if (CurrentToken() == Token::kPERIOD) { | 13408 if (CurrentToken() == Token::kPERIOD) { |
13403 ConsumeToken(); // Consume the kPERIOD token. | 13409 ConsumeToken(); // Consume the kPERIOD token. |
13404 ExpectIdentifier("identifier expected after '.'"); | 13410 ExpectIdentifier("identifier expected after '.'"); |
13405 } | 13411 } |
13406 } | 13412 } |
13407 | 13413 |
13408 } // namespace dart | 13414 } // namespace dart |
OLD | NEW |