| 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 4616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4627 TokenPosition metadata_pos) { | 4627 TokenPosition metadata_pos) { |
| 4628 TRACE_PARSER("ParseClassDeclaration"); | 4628 TRACE_PARSER("ParseClassDeclaration"); |
| 4629 bool is_patch = false; | 4629 bool is_patch = false; |
| 4630 bool is_abstract = false; | 4630 bool is_abstract = false; |
| 4631 TokenPosition declaration_pos = | 4631 TokenPosition declaration_pos = |
| 4632 metadata_pos.IsReal() ? metadata_pos : TokenPos(); | 4632 metadata_pos.IsReal() ? metadata_pos : TokenPos(); |
| 4633 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 4633 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 4634 is_patch = true; | 4634 is_patch = true; |
| 4635 metadata_pos = TokenPosition::kNoSource; | 4635 metadata_pos = TokenPosition::kNoSource; |
| 4636 declaration_pos = TokenPos(); | 4636 declaration_pos = TokenPos(); |
| 4637 } else if (is_patch_source() && | |
| 4638 (CurrentToken() == Token::kIDENT) && | |
| 4639 CurrentLiteral()->Equals("patch")) { | |
| 4640 if (FLAG_warn_patch) { | |
| 4641 ReportWarning("deprecated use of patch 'keyword'"); | |
| 4642 } | |
| 4643 ConsumeToken(); | |
| 4644 is_patch = true; | |
| 4645 } else if (CurrentToken() == Token::kABSTRACT) { | 4637 } else if (CurrentToken() == Token::kABSTRACT) { |
| 4646 is_abstract = true; | 4638 is_abstract = true; |
| 4647 ConsumeToken(); | 4639 ConsumeToken(); |
| 4648 } | 4640 } |
| 4649 ExpectToken(Token::kCLASS); | 4641 ExpectToken(Token::kCLASS); |
| 4650 const TokenPosition classname_pos = TokenPos(); | 4642 const TokenPosition classname_pos = TokenPos(); |
| 4651 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 4643 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 4652 if (FLAG_trace_parser) { | 4644 if (FLAG_trace_parser) { |
| 4653 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); | 4645 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); |
| 4654 } | 4646 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4819 } | 4811 } |
| 4820 | 4812 |
| 4821 | 4813 |
| 4822 void Parser::ParseClassDefinition(const Class& cls) { | 4814 void Parser::ParseClassDefinition(const Class& cls) { |
| 4823 TRACE_PARSER("ParseClassDefinition"); | 4815 TRACE_PARSER("ParseClassDefinition"); |
| 4824 INC_STAT(thread(), num_classes_parsed, 1); | 4816 INC_STAT(thread(), num_classes_parsed, 1); |
| 4825 set_current_class(cls); | 4817 set_current_class(cls); |
| 4826 is_top_level_ = true; | 4818 is_top_level_ = true; |
| 4827 String& class_name = String::Handle(Z, cls.Name()); | 4819 String& class_name = String::Handle(Z, cls.Name()); |
| 4828 SkipMetadata(); | 4820 SkipMetadata(); |
| 4829 if (is_patch_source() && | 4821 if (CurrentToken() == Token::kABSTRACT) { |
| 4830 (CurrentToken() == Token::kIDENT) && | |
| 4831 CurrentLiteral()->Equals("patch")) { | |
| 4832 ConsumeToken(); | |
| 4833 } else if (CurrentToken() == Token::kABSTRACT) { | |
| 4834 ConsumeToken(); | 4822 ConsumeToken(); |
| 4835 } | 4823 } |
| 4836 ExpectToken(Token::kCLASS); | 4824 ExpectToken(Token::kCLASS); |
| 4837 const TokenPosition class_pos = TokenPos(); | 4825 const TokenPosition class_pos = TokenPos(); |
| 4838 ClassDesc members(Z, cls, class_name, false, class_pos); | 4826 ClassDesc members(Z, cls, class_name, false, class_pos); |
| 4839 while (CurrentToken() != Token::kLBRACE) { | 4827 while (CurrentToken() != Token::kLBRACE) { |
| 4840 ConsumeToken(); | 4828 ConsumeToken(); |
| 4841 } | 4829 } |
| 4842 ExpectToken(Token::kLBRACE); | 4830 ExpectToken(Token::kLBRACE); |
| 4843 while (CurrentToken() != Token::kRBRACE) { | 4831 while (CurrentToken() != Token::kRBRACE) { |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5700 TokenPosition metadata_pos) { | 5688 TokenPosition metadata_pos) { |
| 5701 TRACE_PARSER("ParseTopLevelFunction"); | 5689 TRACE_PARSER("ParseTopLevelFunction"); |
| 5702 const TokenPosition decl_begin_pos = TokenPos(); | 5690 const TokenPosition decl_begin_pos = TokenPos(); |
| 5703 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); | 5691 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); |
| 5704 const bool is_static = true; | 5692 const bool is_static = true; |
| 5705 bool is_external = false; | 5693 bool is_external = false; |
| 5706 bool is_patch = false; | 5694 bool is_patch = false; |
| 5707 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 5695 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 5708 is_patch = true; | 5696 is_patch = true; |
| 5709 metadata_pos = TokenPosition::kNoSource; | 5697 metadata_pos = TokenPosition::kNoSource; |
| 5710 } else if (is_patch_source() && | |
| 5711 (CurrentToken() == Token::kIDENT) && | |
| 5712 CurrentLiteral()->Equals("patch") && | |
| 5713 (LookaheadToken(1) != Token::kLPAREN)) { | |
| 5714 if (FLAG_warn_patch) { | |
| 5715 ReportWarning("deprecated use of patch 'keyword'"); | |
| 5716 } | |
| 5717 ConsumeToken(); | |
| 5718 is_patch = true; | |
| 5719 } else if (CurrentToken() == Token::kEXTERNAL) { | 5698 } else if (CurrentToken() == Token::kEXTERNAL) { |
| 5720 ConsumeToken(); | 5699 ConsumeToken(); |
| 5721 is_external = true; | 5700 is_external = true; |
| 5722 } | 5701 } |
| 5723 if (CurrentToken() == Token::kVOID) { | 5702 if (CurrentToken() == Token::kVOID) { |
| 5724 ConsumeToken(); | 5703 ConsumeToken(); |
| 5725 result_type = Type::VoidType(); | 5704 result_type = Type::VoidType(); |
| 5726 } else { | 5705 } else { |
| 5727 // Parse optional type. | 5706 // Parse optional type. |
| 5728 if (IsFunctionReturnType()) { | 5707 if (IsFunctionReturnType()) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5840 TokenPosition metadata_pos) { | 5819 TokenPosition metadata_pos) { |
| 5841 TRACE_PARSER("ParseTopLevelAccessor"); | 5820 TRACE_PARSER("ParseTopLevelAccessor"); |
| 5842 const TokenPosition decl_begin_pos = TokenPos(); | 5821 const TokenPosition decl_begin_pos = TokenPos(); |
| 5843 const bool is_static = true; | 5822 const bool is_static = true; |
| 5844 bool is_external = false; | 5823 bool is_external = false; |
| 5845 bool is_patch = false; | 5824 bool is_patch = false; |
| 5846 AbstractType& result_type = AbstractType::Handle(Z); | 5825 AbstractType& result_type = AbstractType::Handle(Z); |
| 5847 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 5826 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 5848 is_patch = true; | 5827 is_patch = true; |
| 5849 metadata_pos = TokenPosition::kNoSource; | 5828 metadata_pos = TokenPosition::kNoSource; |
| 5850 } else if (is_patch_source() && | |
| 5851 (CurrentToken() == Token::kIDENT) && | |
| 5852 CurrentLiteral()->Equals("patch")) { | |
| 5853 if (FLAG_warn_patch) { | |
| 5854 ReportWarning("deprecated use of patch 'keyword'"); | |
| 5855 } | |
| 5856 ConsumeToken(); | |
| 5857 is_patch = true; | |
| 5858 } else if (CurrentToken() == Token::kEXTERNAL) { | 5829 } else if (CurrentToken() == Token::kEXTERNAL) { |
| 5859 ConsumeToken(); | 5830 ConsumeToken(); |
| 5860 is_external = true; | 5831 is_external = true; |
| 5861 } | 5832 } |
| 5862 bool is_getter = (CurrentToken() == Token::kGET); | 5833 bool is_getter = (CurrentToken() == Token::kGET); |
| 5863 if (CurrentToken() == Token::kGET || | 5834 if (CurrentToken() == Token::kGET || |
| 5864 CurrentToken() == Token::kSET) { | 5835 CurrentToken() == Token::kSET) { |
| 5865 ConsumeToken(); | 5836 ConsumeToken(); |
| 5866 result_type = Type::DynamicType(); | 5837 result_type = Type::DynamicType(); |
| 5867 } else { | 5838 } else { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6391 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | 6362 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6392 } else if (CurrentToken() == Token::kENUM) { | 6363 } else if (CurrentToken() == Token::kENUM) { |
| 6393 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos); | 6364 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6394 } else if ((CurrentToken() == Token::kTYPEDEF) && | 6365 } else if ((CurrentToken() == Token::kTYPEDEF) && |
| 6395 (LookaheadToken(1) != Token::kLPAREN)) { | 6366 (LookaheadToken(1) != Token::kLPAREN)) { |
| 6396 set_current_class(toplevel_class); | 6367 set_current_class(toplevel_class); |
| 6397 ParseTypedef(pending_classes, tl_owner, metadata_pos); | 6368 ParseTypedef(pending_classes, tl_owner, metadata_pos); |
| 6398 } else if ((CurrentToken() == Token::kABSTRACT) && | 6369 } else if ((CurrentToken() == Token::kABSTRACT) && |
| 6399 (LookaheadToken(1) == Token::kCLASS)) { | 6370 (LookaheadToken(1) == Token::kCLASS)) { |
| 6400 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | 6371 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6401 } else if (is_patch_source() && IsSymbol(Symbols::Patch()) && | |
| 6402 (LookaheadToken(1) == Token::kCLASS)) { | |
| 6403 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | |
| 6404 } else { | 6372 } else { |
| 6405 set_current_class(toplevel_class); | 6373 set_current_class(toplevel_class); |
| 6406 if (IsVariableDeclaration()) { | 6374 if (IsVariableDeclaration()) { |
| 6407 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos); | 6375 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos); |
| 6408 } else if (IsFunctionDeclaration()) { | 6376 } else if (IsFunctionDeclaration()) { |
| 6409 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos); | 6377 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos); |
| 6410 } else if (IsTopLevelAccessor()) { | 6378 } else if (IsTopLevelAccessor()) { |
| 6411 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos); | 6379 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos); |
| 6412 } else if (CurrentToken() == Token::kEOS) { | 6380 } else if (CurrentToken() == Token::kEOS) { |
| 6413 break; | 6381 break; |
| (...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8359 return false; | 8327 return false; |
| 8360 } | 8328 } |
| 8361 | 8329 |
| 8362 | 8330 |
| 8363 // Look ahead to detect whether the next tokens should be parsed as | 8331 // Look ahead to detect whether the next tokens should be parsed as |
| 8364 // a function declaration. Token position remains unchanged. | 8332 // a function declaration. Token position remains unchanged. |
| 8365 bool Parser::IsFunctionDeclaration() { | 8333 bool Parser::IsFunctionDeclaration() { |
| 8366 bool is_external = false; | 8334 bool is_external = false; |
| 8367 TokenPosScope decl_pos(this); | 8335 TokenPosScope decl_pos(this); |
| 8368 SkipMetadata(); | 8336 SkipMetadata(); |
| 8369 if (is_top_level_) { | 8337 if ((is_top_level_) && (CurrentToken() == Token::kEXTERNAL)) { |
| 8370 if (is_patch_source() && | 8338 // Skip over 'external' for top-level function declarations. |
| 8371 (CurrentToken() == Token::kIDENT) && | 8339 is_external = true; |
| 8372 CurrentLiteral()->Equals("patch") && | 8340 ConsumeToken(); |
| 8373 (LookaheadToken(1) != Token::kLPAREN)) { | |
| 8374 // Skip over 'patch' for top-level function declarations in patch sources. | |
| 8375 ConsumeToken(); | |
| 8376 } else if (CurrentToken() == Token::kEXTERNAL) { | |
| 8377 // Skip over 'external' for top-level function declarations. | |
| 8378 is_external = true; | |
| 8379 ConsumeToken(); | |
| 8380 } | |
| 8381 } | 8341 } |
| 8382 const TokenPosition type_or_name_pos = TokenPos(); | 8342 const TokenPosition type_or_name_pos = TokenPos(); |
| 8383 if (TryParseReturnType()) { | 8343 if (TryParseReturnType()) { |
| 8384 if (!IsIdentifier()) { | 8344 if (!IsIdentifier()) { |
| 8385 SetPosition(type_or_name_pos); | 8345 SetPosition(type_or_name_pos); |
| 8386 } | 8346 } |
| 8387 } else { | 8347 } else { |
| 8388 SetPosition(type_or_name_pos); | 8348 SetPosition(type_or_name_pos); |
| 8389 } | 8349 } |
| 8390 // Check for function name followed by optional type parameters. | 8350 // Check for function name followed by optional type parameters. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 8410 IsSymbol(Symbols::Async()) || | 8370 IsSymbol(Symbols::Async()) || |
| 8411 IsSymbol(Symbols::Sync())) { | 8371 IsSymbol(Symbols::Sync())) { |
| 8412 return true; | 8372 return true; |
| 8413 } | 8373 } |
| 8414 return false; | 8374 return false; |
| 8415 } | 8375 } |
| 8416 | 8376 |
| 8417 | 8377 |
| 8418 bool Parser::IsTopLevelAccessor() { | 8378 bool Parser::IsTopLevelAccessor() { |
| 8419 const TokenPosScope saved_pos(this); | 8379 const TokenPosScope saved_pos(this); |
| 8420 if (is_patch_source() && IsSymbol(Symbols::Patch())) { | 8380 if (CurrentToken() == Token::kEXTERNAL) { |
| 8421 ConsumeToken(); | |
| 8422 } else if (CurrentToken() == Token::kEXTERNAL) { | |
| 8423 ConsumeToken(); | 8381 ConsumeToken(); |
| 8424 } | 8382 } |
| 8425 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { | 8383 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { |
| 8426 return true; | 8384 return true; |
| 8427 } | 8385 } |
| 8428 if (TryParseReturnType()) { | 8386 if (TryParseReturnType()) { |
| 8429 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { | 8387 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { |
| 8430 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. | 8388 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. |
| 8431 return true; | 8389 return true; |
| 8432 } | 8390 } |
| (...skipping 6554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14987 const ArgumentListNode& function_args, | 14945 const ArgumentListNode& function_args, |
| 14988 const LocalVariable* temp_for_last_arg, | 14946 const LocalVariable* temp_for_last_arg, |
| 14989 bool is_super_invocation) { | 14947 bool is_super_invocation) { |
| 14990 UNREACHABLE(); | 14948 UNREACHABLE(); |
| 14991 return NULL; | 14949 return NULL; |
| 14992 } | 14950 } |
| 14993 | 14951 |
| 14994 } // namespace dart | 14952 } // namespace dart |
| 14995 | 14953 |
| 14996 #endif // DART_PRECOMPILED_RUNTIME | 14954 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |