| 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 4549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4560 TokenPosition metadata_pos) { | 4560 TokenPosition metadata_pos) { |
| 4561 TRACE_PARSER("ParseClassDeclaration"); | 4561 TRACE_PARSER("ParseClassDeclaration"); |
| 4562 bool is_patch = false; | 4562 bool is_patch = false; |
| 4563 bool is_abstract = false; | 4563 bool is_abstract = false; |
| 4564 TokenPosition declaration_pos = | 4564 TokenPosition declaration_pos = |
| 4565 metadata_pos.IsReal() ? metadata_pos : TokenPos(); | 4565 metadata_pos.IsReal() ? metadata_pos : TokenPos(); |
| 4566 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 4566 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 4567 is_patch = true; | 4567 is_patch = true; |
| 4568 metadata_pos = TokenPosition::kNoSource; | 4568 metadata_pos = TokenPosition::kNoSource; |
| 4569 declaration_pos = TokenPos(); | 4569 declaration_pos = TokenPos(); |
| 4570 } else if (is_patch_source() && | |
| 4571 (CurrentToken() == Token::kIDENT) && | |
| 4572 CurrentLiteral()->Equals("patch")) { | |
| 4573 if (FLAG_warn_patch) { | |
| 4574 ReportWarning("deprecated use of patch 'keyword'"); | |
| 4575 } | |
| 4576 ConsumeToken(); | |
| 4577 is_patch = true; | |
| 4578 } else if (CurrentToken() == Token::kABSTRACT) { | 4570 } else if (CurrentToken() == Token::kABSTRACT) { |
| 4579 is_abstract = true; | 4571 is_abstract = true; |
| 4580 ConsumeToken(); | 4572 ConsumeToken(); |
| 4581 } | 4573 } |
| 4582 ExpectToken(Token::kCLASS); | 4574 ExpectToken(Token::kCLASS); |
| 4583 const TokenPosition classname_pos = TokenPos(); | 4575 const TokenPosition classname_pos = TokenPos(); |
| 4584 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 4576 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 4585 if (FLAG_trace_parser) { | 4577 if (FLAG_trace_parser) { |
| 4586 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); | 4578 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); |
| 4587 } | 4579 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4752 } | 4744 } |
| 4753 | 4745 |
| 4754 | 4746 |
| 4755 void Parser::ParseClassDefinition(const Class& cls) { | 4747 void Parser::ParseClassDefinition(const Class& cls) { |
| 4756 TRACE_PARSER("ParseClassDefinition"); | 4748 TRACE_PARSER("ParseClassDefinition"); |
| 4757 INC_STAT(thread(), num_classes_parsed, 1); | 4749 INC_STAT(thread(), num_classes_parsed, 1); |
| 4758 set_current_class(cls); | 4750 set_current_class(cls); |
| 4759 is_top_level_ = true; | 4751 is_top_level_ = true; |
| 4760 String& class_name = String::Handle(Z, cls.Name()); | 4752 String& class_name = String::Handle(Z, cls.Name()); |
| 4761 SkipMetadata(); | 4753 SkipMetadata(); |
| 4762 if (is_patch_source() && | 4754 if (CurrentToken() == Token::kABSTRACT) { |
| 4763 (CurrentToken() == Token::kIDENT) && | |
| 4764 CurrentLiteral()->Equals("patch")) { | |
| 4765 ConsumeToken(); | |
| 4766 } else if (CurrentToken() == Token::kABSTRACT) { | |
| 4767 ConsumeToken(); | 4755 ConsumeToken(); |
| 4768 } | 4756 } |
| 4769 ExpectToken(Token::kCLASS); | 4757 ExpectToken(Token::kCLASS); |
| 4770 const TokenPosition class_pos = TokenPos(); | 4758 const TokenPosition class_pos = TokenPos(); |
| 4771 ClassDesc members(Z, cls, class_name, false, class_pos); | 4759 ClassDesc members(Z, cls, class_name, false, class_pos); |
| 4772 while (CurrentToken() != Token::kLBRACE) { | 4760 while (CurrentToken() != Token::kLBRACE) { |
| 4773 ConsumeToken(); | 4761 ConsumeToken(); |
| 4774 } | 4762 } |
| 4775 ExpectToken(Token::kLBRACE); | 4763 ExpectToken(Token::kLBRACE); |
| 4776 while (CurrentToken() != Token::kRBRACE) { | 4764 while (CurrentToken() != Token::kRBRACE) { |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5639 TokenPosition metadata_pos) { | 5627 TokenPosition metadata_pos) { |
| 5640 TRACE_PARSER("ParseTopLevelFunction"); | 5628 TRACE_PARSER("ParseTopLevelFunction"); |
| 5641 const TokenPosition decl_begin_pos = TokenPos(); | 5629 const TokenPosition decl_begin_pos = TokenPos(); |
| 5642 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); | 5630 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); |
| 5643 const bool is_static = true; | 5631 const bool is_static = true; |
| 5644 bool is_external = false; | 5632 bool is_external = false; |
| 5645 bool is_patch = false; | 5633 bool is_patch = false; |
| 5646 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 5634 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 5647 is_patch = true; | 5635 is_patch = true; |
| 5648 metadata_pos = TokenPosition::kNoSource; | 5636 metadata_pos = TokenPosition::kNoSource; |
| 5649 } else if (is_patch_source() && | |
| 5650 (CurrentToken() == Token::kIDENT) && | |
| 5651 CurrentLiteral()->Equals("patch") && | |
| 5652 (LookaheadToken(1) != Token::kLPAREN)) { | |
| 5653 if (FLAG_warn_patch) { | |
| 5654 ReportWarning("deprecated use of patch 'keyword'"); | |
| 5655 } | |
| 5656 ConsumeToken(); | |
| 5657 is_patch = true; | |
| 5658 } else if (CurrentToken() == Token::kEXTERNAL) { | 5637 } else if (CurrentToken() == Token::kEXTERNAL) { |
| 5659 ConsumeToken(); | 5638 ConsumeToken(); |
| 5660 is_external = true; | 5639 is_external = true; |
| 5661 } | 5640 } |
| 5662 if (CurrentToken() == Token::kVOID) { | 5641 if (CurrentToken() == Token::kVOID) { |
| 5663 ConsumeToken(); | 5642 ConsumeToken(); |
| 5664 result_type = Type::VoidType(); | 5643 result_type = Type::VoidType(); |
| 5665 } else { | 5644 } else { |
| 5666 // Parse optional type. | 5645 // Parse optional type. |
| 5667 if ((CurrentToken() == Token::kIDENT) && | 5646 if ((CurrentToken() == Token::kIDENT) && |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5768 TokenPosition metadata_pos) { | 5747 TokenPosition metadata_pos) { |
| 5769 TRACE_PARSER("ParseTopLevelAccessor"); | 5748 TRACE_PARSER("ParseTopLevelAccessor"); |
| 5770 const TokenPosition decl_begin_pos = TokenPos(); | 5749 const TokenPosition decl_begin_pos = TokenPos(); |
| 5771 const bool is_static = true; | 5750 const bool is_static = true; |
| 5772 bool is_external = false; | 5751 bool is_external = false; |
| 5773 bool is_patch = false; | 5752 bool is_patch = false; |
| 5774 AbstractType& result_type = AbstractType::Handle(Z); | 5753 AbstractType& result_type = AbstractType::Handle(Z); |
| 5775 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { | 5754 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { |
| 5776 is_patch = true; | 5755 is_patch = true; |
| 5777 metadata_pos = TokenPosition::kNoSource; | 5756 metadata_pos = TokenPosition::kNoSource; |
| 5778 } else if (is_patch_source() && | |
| 5779 (CurrentToken() == Token::kIDENT) && | |
| 5780 CurrentLiteral()->Equals("patch")) { | |
| 5781 if (FLAG_warn_patch) { | |
| 5782 ReportWarning("deprecated use of patch 'keyword'"); | |
| 5783 } | |
| 5784 ConsumeToken(); | |
| 5785 is_patch = true; | |
| 5786 } else if (CurrentToken() == Token::kEXTERNAL) { | 5757 } else if (CurrentToken() == Token::kEXTERNAL) { |
| 5787 ConsumeToken(); | 5758 ConsumeToken(); |
| 5788 is_external = true; | 5759 is_external = true; |
| 5789 } | 5760 } |
| 5790 bool is_getter = (CurrentToken() == Token::kGET); | 5761 bool is_getter = (CurrentToken() == Token::kGET); |
| 5791 if (CurrentToken() == Token::kGET || | 5762 if (CurrentToken() == Token::kGET || |
| 5792 CurrentToken() == Token::kSET) { | 5763 CurrentToken() == Token::kSET) { |
| 5793 ConsumeToken(); | 5764 ConsumeToken(); |
| 5794 result_type = Type::DynamicType(); | 5765 result_type = Type::DynamicType(); |
| 5795 } else { | 5766 } else { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6319 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | 6290 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6320 } else if (CurrentToken() == Token::kENUM) { | 6291 } else if (CurrentToken() == Token::kENUM) { |
| 6321 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos); | 6292 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6322 } else if ((CurrentToken() == Token::kTYPEDEF) && | 6293 } else if ((CurrentToken() == Token::kTYPEDEF) && |
| 6323 (LookaheadToken(1) != Token::kLPAREN)) { | 6294 (LookaheadToken(1) != Token::kLPAREN)) { |
| 6324 set_current_class(toplevel_class); | 6295 set_current_class(toplevel_class); |
| 6325 ParseTypedef(pending_classes, tl_owner, metadata_pos); | 6296 ParseTypedef(pending_classes, tl_owner, metadata_pos); |
| 6326 } else if ((CurrentToken() == Token::kABSTRACT) && | 6297 } else if ((CurrentToken() == Token::kABSTRACT) && |
| 6327 (LookaheadToken(1) == Token::kCLASS)) { | 6298 (LookaheadToken(1) == Token::kCLASS)) { |
| 6328 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | 6299 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); |
| 6329 } else if (is_patch_source() && IsSymbol(Symbols::Patch()) && | |
| 6330 (LookaheadToken(1) == Token::kCLASS)) { | |
| 6331 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); | |
| 6332 } else { | 6300 } else { |
| 6333 set_current_class(toplevel_class); | 6301 set_current_class(toplevel_class); |
| 6334 if (IsVariableDeclaration()) { | 6302 if (IsVariableDeclaration()) { |
| 6335 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos); | 6303 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos); |
| 6336 } else if (IsFunctionDeclaration()) { | 6304 } else if (IsFunctionDeclaration()) { |
| 6337 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos); | 6305 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos); |
| 6338 } else if (IsTopLevelAccessor()) { | 6306 } else if (IsTopLevelAccessor()) { |
| 6339 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos); | 6307 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos); |
| 6340 } else if (CurrentToken() == Token::kEOS) { | 6308 } else if (CurrentToken() == Token::kEOS) { |
| 6341 break; | 6309 break; |
| (...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8186 return is_var_decl; | 8154 return is_var_decl; |
| 8187 } | 8155 } |
| 8188 | 8156 |
| 8189 | 8157 |
| 8190 // Look ahead to detect whether the next tokens should be parsed as | 8158 // Look ahead to detect whether the next tokens should be parsed as |
| 8191 // a function declaration. Token position remains unchanged. | 8159 // a function declaration. Token position remains unchanged. |
| 8192 bool Parser::IsFunctionDeclaration() { | 8160 bool Parser::IsFunctionDeclaration() { |
| 8193 const TokenPosition saved_pos = TokenPos(); | 8161 const TokenPosition saved_pos = TokenPos(); |
| 8194 bool is_external = false; | 8162 bool is_external = false; |
| 8195 SkipMetadata(); | 8163 SkipMetadata(); |
| 8196 if (is_top_level_) { | 8164 if (is_top_level_ && (CurrentToken() == Token::kEXTERNAL)) { |
| 8197 if (is_patch_source() && | 8165 // Skip over 'external' for top-level function declarations. |
| 8198 (CurrentToken() == Token::kIDENT) && | 8166 is_external = true; |
| 8199 CurrentLiteral()->Equals("patch") && | 8167 ConsumeToken(); |
| 8200 (LookaheadToken(1) != Token::kLPAREN)) { | |
| 8201 // Skip over 'patch' for top-level function declarations in patch sources. | |
| 8202 ConsumeToken(); | |
| 8203 } else if (CurrentToken() == Token::kEXTERNAL) { | |
| 8204 // Skip over 'external' for top-level function declarations. | |
| 8205 is_external = true; | |
| 8206 ConsumeToken(); | |
| 8207 } | |
| 8208 } | 8168 } |
| 8209 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { | 8169 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { |
| 8210 // Possibly a function without explicit return type. | 8170 // Possibly a function without explicit return type. |
| 8211 ConsumeToken(); // Consume function identifier. | 8171 ConsumeToken(); // Consume function identifier. |
| 8212 } else if (TryParseReturnType()) { | 8172 } else if (TryParseReturnType()) { |
| 8213 if (!IsIdentifier()) { | 8173 if (!IsIdentifier()) { |
| 8214 SetPosition(saved_pos); | 8174 SetPosition(saved_pos); |
| 8215 return false; | 8175 return false; |
| 8216 } | 8176 } |
| 8217 ConsumeToken(); // Consume function identifier. | 8177 ConsumeToken(); // Consume function identifier. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8232 return true; | 8192 return true; |
| 8233 } | 8193 } |
| 8234 } | 8194 } |
| 8235 SetPosition(saved_pos); | 8195 SetPosition(saved_pos); |
| 8236 return false; | 8196 return false; |
| 8237 } | 8197 } |
| 8238 | 8198 |
| 8239 | 8199 |
| 8240 bool Parser::IsTopLevelAccessor() { | 8200 bool Parser::IsTopLevelAccessor() { |
| 8241 const TokenPosition saved_pos = TokenPos(); | 8201 const TokenPosition saved_pos = TokenPos(); |
| 8242 if (is_patch_source() && IsSymbol(Symbols::Patch())) { | 8202 if (CurrentToken() == Token::kEXTERNAL) { |
| 8243 ConsumeToken(); | |
| 8244 } else if (CurrentToken() == Token::kEXTERNAL) { | |
| 8245 ConsumeToken(); | 8203 ConsumeToken(); |
| 8246 } | 8204 } |
| 8247 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { | 8205 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { |
| 8248 SetPosition(saved_pos); | 8206 SetPosition(saved_pos); |
| 8249 return true; | 8207 return true; |
| 8250 } | 8208 } |
| 8251 if (TryParseReturnType()) { | 8209 if (TryParseReturnType()) { |
| 8252 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { | 8210 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { |
| 8253 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. | 8211 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. |
| 8254 SetPosition(saved_pos); | 8212 SetPosition(saved_pos); |
| (...skipping 6526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14781 const ArgumentListNode& function_args, | 14739 const ArgumentListNode& function_args, |
| 14782 const LocalVariable* temp_for_last_arg, | 14740 const LocalVariable* temp_for_last_arg, |
| 14783 bool is_super_invocation) { | 14741 bool is_super_invocation) { |
| 14784 UNREACHABLE(); | 14742 UNREACHABLE(); |
| 14785 return NULL; | 14743 return NULL; |
| 14786 } | 14744 } |
| 14787 | 14745 |
| 14788 } // namespace dart | 14746 } // namespace dart |
| 14789 | 14747 |
| 14790 #endif // DART_PRECOMPILED_RUNTIME | 14748 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |