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 3807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3818 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier(); | 3818 RawFunction::AsyncModifier async_modifier = ParseFunctionModifier(); |
3819 if ((method->IsFactoryOrConstructor() || method->IsSetter()) && | 3819 if ((method->IsFactoryOrConstructor() || method->IsSetter()) && |
3820 (async_modifier != RawFunction::kNoModifier)) { | 3820 (async_modifier != RawFunction::kNoModifier)) { |
3821 ReportError(modifier_pos, | 3821 ReportError(modifier_pos, |
3822 "%s '%s' may not be async, async* or sync*", | 3822 "%s '%s' may not be async, async* or sync*", |
3823 (method->IsSetter()) ? "setter" : "constructor", | 3823 (method->IsSetter()) ? "setter" : "constructor", |
3824 method->name->ToCString()); | 3824 method->name->ToCString()); |
3825 } | 3825 } |
3826 | 3826 |
3827 intptr_t method_end_pos = TokenPos(); | 3827 intptr_t method_end_pos = TokenPos(); |
| 3828 String* native_name = NULL; |
3828 if ((CurrentToken() == Token::kLBRACE) || | 3829 if ((CurrentToken() == Token::kLBRACE) || |
3829 (CurrentToken() == Token::kARROW)) { | 3830 (CurrentToken() == Token::kARROW)) { |
3830 if (method->has_abstract) { | 3831 if (method->has_abstract) { |
3831 ReportError(TokenPos(), | 3832 ReportError(TokenPos(), |
3832 "abstract method '%s' may not have a function body", | 3833 "abstract method '%s' may not have a function body", |
3833 method->name->ToCString()); | 3834 method->name->ToCString()); |
3834 } else if (method->has_external) { | 3835 } else if (method->has_external) { |
3835 ReportError(TokenPos(), | 3836 ReportError(TokenPos(), |
3836 "external %s '%s' may not have a function body", | 3837 "external %s '%s' may not have a function body", |
3837 method->IsFactoryOrConstructor() ? "constructor" : "method", | 3838 method->IsFactoryOrConstructor() ? "constructor" : "method", |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3873 method->name->ToCString()); | 3874 method->name->ToCString()); |
3874 } else if (method->IsConstructor() && method->has_const) { | 3875 } else if (method->IsConstructor() && method->has_const) { |
3875 ReportError(method->name_pos, | 3876 ReportError(method->name_pos, |
3876 "const constructor '%s' may not be native", | 3877 "const constructor '%s' may not be native", |
3877 method->name->ToCString()); | 3878 method->name->ToCString()); |
3878 } | 3879 } |
3879 if (method->redirect_name != NULL) { | 3880 if (method->redirect_name != NULL) { |
3880 ReportError(method->name_pos, | 3881 ReportError(method->name_pos, |
3881 "Constructor with redirection may not have a function body"); | 3882 "Constructor with redirection may not have a function body"); |
3882 } | 3883 } |
3883 ParseNativeDeclaration(); | 3884 native_name = &ParseNativeDeclaration(); |
3884 method_end_pos = TokenPos(); | 3885 method_end_pos = TokenPos(); |
3885 ExpectSemicolon(); | 3886 ExpectSemicolon(); |
3886 method->has_native = true; | 3887 method->has_native = true; |
3887 } else { | 3888 } else { |
3888 // We haven't found a method body. Issue error if one is required. | 3889 // We haven't found a method body. Issue error if one is required. |
3889 const bool must_have_body = | 3890 const bool must_have_body = |
3890 method->has_static && | 3891 method->has_static && |
3891 !method->has_external && | 3892 !method->has_external && |
3892 redirection_type.IsNull(); | 3893 redirection_type.IsNull(); |
3893 if (must_have_body) { | 3894 if (must_have_body) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3951 func.set_result_type(*method->type); | 3952 func.set_result_type(*method->type); |
3952 func.set_end_token_pos(method_end_pos); | 3953 func.set_end_token_pos(method_end_pos); |
3953 func.set_is_redirecting(is_redirecting); | 3954 func.set_is_redirecting(is_redirecting); |
3954 func.set_modifier(async_modifier); | 3955 func.set_modifier(async_modifier); |
3955 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { | 3956 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { |
3956 func.set_is_reflectable(false); | 3957 func.set_is_reflectable(false); |
3957 } | 3958 } |
3958 if (method->metadata_pos > 0) { | 3959 if (method->metadata_pos > 0) { |
3959 library_.AddFunctionMetadata(func, method->metadata_pos); | 3960 library_.AddFunctionMetadata(func, method->metadata_pos); |
3960 } | 3961 } |
| 3962 if (method->has_native) { |
| 3963 func.set_native_name(*native_name); |
| 3964 } |
3961 | 3965 |
3962 // If this method is a redirecting factory, set the redirection information. | 3966 // If this method is a redirecting factory, set the redirection information. |
3963 if (!redirection_type.IsNull()) { | 3967 if (!redirection_type.IsNull()) { |
3964 ASSERT(func.IsFactory()); | 3968 ASSERT(func.IsFactory()); |
3965 func.SetRedirectionType(redirection_type); | 3969 func.SetRedirectionType(redirection_type); |
3966 if (!redirection_identifier.IsNull()) { | 3970 if (!redirection_identifier.IsNull()) { |
3967 func.SetRedirectionIdentifier(redirection_identifier); | 3971 func.SetRedirectionIdentifier(redirection_identifier); |
3968 } | 3972 } |
3969 } | 3973 } |
3970 | 3974 |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5577 const intptr_t function_pos = TokenPos(); | 5581 const intptr_t function_pos = TokenPos(); |
5578 ParamList params; | 5582 ParamList params; |
5579 const bool allow_explicit_default_values = true; | 5583 const bool allow_explicit_default_values = true; |
5580 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); | 5584 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
5581 | 5585 |
5582 const intptr_t modifier_pos = TokenPos(); | 5586 const intptr_t modifier_pos = TokenPos(); |
5583 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); | 5587 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); |
5584 | 5588 |
5585 intptr_t function_end_pos = function_pos; | 5589 intptr_t function_end_pos = function_pos; |
5586 bool is_native = false; | 5590 bool is_native = false; |
| 5591 String* native_name = NULL; |
5587 if (is_external) { | 5592 if (is_external) { |
5588 function_end_pos = TokenPos(); | 5593 function_end_pos = TokenPos(); |
5589 ExpectSemicolon(); | 5594 ExpectSemicolon(); |
5590 } else if (CurrentToken() == Token::kLBRACE) { | 5595 } else if (CurrentToken() == Token::kLBRACE) { |
5591 SkipBlock(); | 5596 SkipBlock(); |
5592 function_end_pos = TokenPos(); | 5597 function_end_pos = TokenPos(); |
5593 ExpectToken(Token::kRBRACE); | 5598 ExpectToken(Token::kRBRACE); |
5594 } else if (CurrentToken() == Token::kARROW) { | 5599 } else if (CurrentToken() == Token::kARROW) { |
5595 if ((func_modifier & RawFunction::kGeneratorBit) != 0) { | 5600 if ((func_modifier & RawFunction::kGeneratorBit) != 0) { |
5596 ReportError(modifier_pos, | 5601 ReportError(modifier_pos, |
5597 "=> style function may not be sync* or async* generator"); | 5602 "=> style function may not be sync* or async* generator"); |
5598 } | 5603 } |
5599 ConsumeToken(); | 5604 ConsumeToken(); |
5600 BoolScope allow_await(&this->await_is_keyword_, | 5605 BoolScope allow_await(&this->await_is_keyword_, |
5601 func_modifier != RawFunction::kNoModifier); | 5606 func_modifier != RawFunction::kNoModifier); |
5602 SkipExpr(); | 5607 SkipExpr(); |
5603 function_end_pos = TokenPos(); | 5608 function_end_pos = TokenPos(); |
5604 ExpectSemicolon(); | 5609 ExpectSemicolon(); |
5605 } else if (IsSymbol(Symbols::Native())) { | 5610 } else if (IsSymbol(Symbols::Native())) { |
5606 ParseNativeDeclaration(); | 5611 native_name = &ParseNativeDeclaration(); |
5607 function_end_pos = TokenPos(); | 5612 function_end_pos = TokenPos(); |
5608 ExpectSemicolon(); | 5613 ExpectSemicolon(); |
5609 is_native = true; | 5614 is_native = true; |
5610 } else { | 5615 } else { |
5611 ReportError("function block expected"); | 5616 ReportError("function block expected"); |
5612 } | 5617 } |
5613 Function& func = Function::Handle(Z, | 5618 Function& func = Function::Handle(Z, |
5614 Function::New(func_name, | 5619 Function::New(func_name, |
5615 RawFunction::kRegularFunction, | 5620 RawFunction::kRegularFunction, |
5616 is_static, | 5621 is_static, |
5617 /* is_const = */ false, | 5622 /* is_const = */ false, |
5618 /* is_abstract = */ false, | 5623 /* is_abstract = */ false, |
5619 is_external, | 5624 is_external, |
5620 is_native, | 5625 is_native, |
5621 current_class(), | 5626 current_class(), |
5622 decl_begin_pos)); | 5627 decl_begin_pos)); |
5623 func.set_result_type(result_type); | 5628 func.set_result_type(result_type); |
5624 func.set_end_token_pos(function_end_pos); | 5629 func.set_end_token_pos(function_end_pos); |
5625 func.set_modifier(func_modifier); | 5630 func.set_modifier(func_modifier); |
5626 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { | 5631 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { |
5627 func.set_is_reflectable(false); | 5632 func.set_is_reflectable(false); |
5628 } | 5633 } |
| 5634 if (is_native) { |
| 5635 func.set_native_name(*native_name); |
| 5636 } |
5629 AddFormalParamsToFunction(¶ms, func); | 5637 AddFormalParamsToFunction(¶ms, func); |
5630 top_level->AddFunction(func); | 5638 top_level->AddFunction(func); |
5631 if (!is_patch) { | 5639 if (!is_patch) { |
5632 library_.AddObject(func, func_name); | 5640 library_.AddObject(func, func_name); |
5633 } else { | 5641 } else { |
5634 library_.ReplaceObject(func, func_name); | 5642 library_.ReplaceObject(func, func_name); |
5635 } | 5643 } |
5636 if (metadata_pos >= 0) { | 5644 if (metadata_pos >= 0) { |
5637 library_.AddFunctionMetadata(func, metadata_pos); | 5645 library_.AddFunctionMetadata(func, metadata_pos); |
5638 } | 5646 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5727 | 5735 |
5728 const intptr_t modifier_pos = TokenPos(); | 5736 const intptr_t modifier_pos = TokenPos(); |
5729 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); | 5737 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); |
5730 if (!is_getter && (func_modifier != RawFunction::kNoModifier)) { | 5738 if (!is_getter && (func_modifier != RawFunction::kNoModifier)) { |
5731 ReportError(modifier_pos, | 5739 ReportError(modifier_pos, |
5732 "setter function cannot be async, async* or sync*"); | 5740 "setter function cannot be async, async* or sync*"); |
5733 } | 5741 } |
5734 | 5742 |
5735 intptr_t accessor_end_pos = accessor_pos; | 5743 intptr_t accessor_end_pos = accessor_pos; |
5736 bool is_native = false; | 5744 bool is_native = false; |
| 5745 String* native_name = NULL; |
5737 if (is_external) { | 5746 if (is_external) { |
5738 accessor_end_pos = TokenPos(); | 5747 accessor_end_pos = TokenPos(); |
5739 ExpectSemicolon(); | 5748 ExpectSemicolon(); |
5740 } else if (CurrentToken() == Token::kLBRACE) { | 5749 } else if (CurrentToken() == Token::kLBRACE) { |
5741 SkipBlock(); | 5750 SkipBlock(); |
5742 accessor_end_pos = TokenPos(); | 5751 accessor_end_pos = TokenPos(); |
5743 ExpectToken(Token::kRBRACE); | 5752 ExpectToken(Token::kRBRACE); |
5744 } else if (CurrentToken() == Token::kARROW) { | 5753 } else if (CurrentToken() == Token::kARROW) { |
5745 if (is_getter && ((func_modifier & RawFunction::kGeneratorBit) != 0)) { | 5754 if (is_getter && ((func_modifier & RawFunction::kGeneratorBit) != 0)) { |
5746 ReportError(modifier_pos, | 5755 ReportError(modifier_pos, |
5747 "=> style getter may not be sync* or async* generator"); | 5756 "=> style getter may not be sync* or async* generator"); |
5748 } | 5757 } |
5749 ConsumeToken(); | 5758 ConsumeToken(); |
5750 BoolScope allow_await(&this->await_is_keyword_, | 5759 BoolScope allow_await(&this->await_is_keyword_, |
5751 func_modifier != RawFunction::kNoModifier); | 5760 func_modifier != RawFunction::kNoModifier); |
5752 SkipExpr(); | 5761 SkipExpr(); |
5753 accessor_end_pos = TokenPos(); | 5762 accessor_end_pos = TokenPos(); |
5754 ExpectSemicolon(); | 5763 ExpectSemicolon(); |
5755 } else if (IsSymbol(Symbols::Native())) { | 5764 } else if (IsSymbol(Symbols::Native())) { |
5756 ParseNativeDeclaration(); | 5765 native_name = &ParseNativeDeclaration(); |
5757 accessor_end_pos = TokenPos(); | 5766 accessor_end_pos = TokenPos(); |
5758 ExpectSemicolon(); | 5767 ExpectSemicolon(); |
5759 is_native = true; | 5768 is_native = true; |
5760 } else { | 5769 } else { |
5761 ReportError("function block expected"); | 5770 ReportError("function block expected"); |
5762 } | 5771 } |
5763 Function& func = Function::Handle(Z, | 5772 Function& func = Function::Handle(Z, |
5764 Function::New(accessor_name, | 5773 Function::New(accessor_name, |
5765 is_getter ? RawFunction::kGetterFunction : | 5774 is_getter ? RawFunction::kGetterFunction : |
5766 RawFunction::kSetterFunction, | 5775 RawFunction::kSetterFunction, |
5767 is_static, | 5776 is_static, |
5768 /* is_const = */ false, | 5777 /* is_const = */ false, |
5769 /* is_abstract = */ false, | 5778 /* is_abstract = */ false, |
5770 is_external, | 5779 is_external, |
5771 is_native, | 5780 is_native, |
5772 current_class(), | 5781 current_class(), |
5773 decl_begin_pos)); | 5782 decl_begin_pos)); |
5774 func.set_result_type(result_type); | 5783 func.set_result_type(result_type); |
5775 func.set_end_token_pos(accessor_end_pos); | 5784 func.set_end_token_pos(accessor_end_pos); |
5776 func.set_modifier(func_modifier); | 5785 func.set_modifier(func_modifier); |
5777 if (is_native) { | 5786 if (is_native) { |
5778 func.set_is_debuggable(false); | 5787 func.set_is_debuggable(false); |
| 5788 func.set_native_name(*native_name); |
5779 } | 5789 } |
5780 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { | 5790 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { |
5781 func.set_is_reflectable(false); | 5791 func.set_is_reflectable(false); |
5782 } | 5792 } |
5783 AddFormalParamsToFunction(¶ms, func); | 5793 AddFormalParamsToFunction(¶ms, func); |
5784 top_level->AddFunction(func); | 5794 top_level->AddFunction(func); |
5785 if (!is_patch) { | 5795 if (!is_patch) { |
5786 library_.AddObject(func, accessor_name); | 5796 library_.AddObject(func, accessor_name); |
5787 } else { | 5797 } else { |
5788 library_.ReplaceObject(func, accessor_name); | 5798 library_.ReplaceObject(func, accessor_name); |
(...skipping 8543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14332 void Parser::SkipQualIdent() { | 14342 void Parser::SkipQualIdent() { |
14333 ASSERT(IsIdentifier()); | 14343 ASSERT(IsIdentifier()); |
14334 ConsumeToken(); | 14344 ConsumeToken(); |
14335 if (CurrentToken() == Token::kPERIOD) { | 14345 if (CurrentToken() == Token::kPERIOD) { |
14336 ConsumeToken(); // Consume the kPERIOD token. | 14346 ConsumeToken(); // Consume the kPERIOD token. |
14337 ExpectIdentifier("identifier expected after '.'"); | 14347 ExpectIdentifier("identifier expected after '.'"); |
14338 } | 14348 } |
14339 } | 14349 } |
14340 | 14350 |
14341 } // namespace dart | 14351 } // namespace dart |
OLD | NEW |