Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: runtime/vm/parser.cc

Issue 1412633007: Save the native name on the function instead of finding it in the token stream for lazily-linked na… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
5578 const intptr_t function_pos = TokenPos(); 5582 const intptr_t function_pos = TokenPos();
5579 ParamList params; 5583 ParamList params;
5580 const bool allow_explicit_default_values = true; 5584 const bool allow_explicit_default_values = true;
5581 ParseFormalParameterList(allow_explicit_default_values, false, &params); 5585 ParseFormalParameterList(allow_explicit_default_values, false, &params);
5582 5586
5583 const intptr_t modifier_pos = TokenPos(); 5587 const intptr_t modifier_pos = TokenPos();
5584 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); 5588 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier();
5585 5589
5586 intptr_t function_end_pos = function_pos; 5590 intptr_t function_end_pos = function_pos;
5587 bool is_native = false; 5591 bool is_native = false;
5592 String* native_name = NULL;
5588 if (is_external) { 5593 if (is_external) {
5589 function_end_pos = TokenPos(); 5594 function_end_pos = TokenPos();
5590 ExpectSemicolon(); 5595 ExpectSemicolon();
5591 } else if (CurrentToken() == Token::kLBRACE) { 5596 } else if (CurrentToken() == Token::kLBRACE) {
5592 SkipBlock(); 5597 SkipBlock();
5593 function_end_pos = TokenPos(); 5598 function_end_pos = TokenPos();
5594 ExpectToken(Token::kRBRACE); 5599 ExpectToken(Token::kRBRACE);
5595 } else if (CurrentToken() == Token::kARROW) { 5600 } else if (CurrentToken() == Token::kARROW) {
5596 if ((func_modifier & RawFunction::kGeneratorBit) != 0) { 5601 if ((func_modifier & RawFunction::kGeneratorBit) != 0) {
5597 ReportError(modifier_pos, 5602 ReportError(modifier_pos,
5598 "=> style function may not be sync* or async* generator"); 5603 "=> style function may not be sync* or async* generator");
5599 } 5604 }
5600 ConsumeToken(); 5605 ConsumeToken();
5601 BoolScope allow_await(&this->await_is_keyword_, 5606 BoolScope allow_await(&this->await_is_keyword_,
5602 func_modifier != RawFunction::kNoModifier); 5607 func_modifier != RawFunction::kNoModifier);
5603 SkipExpr(); 5608 SkipExpr();
5604 function_end_pos = TokenPos(); 5609 function_end_pos = TokenPos();
5605 ExpectSemicolon(); 5610 ExpectSemicolon();
5606 } else if (IsSymbol(Symbols::Native())) { 5611 } else if (IsSymbol(Symbols::Native())) {
5607 ParseNativeDeclaration(); 5612 native_name = &ParseNativeDeclaration();
5608 function_end_pos = TokenPos(); 5613 function_end_pos = TokenPos();
5609 ExpectSemicolon(); 5614 ExpectSemicolon();
5610 is_native = true; 5615 is_native = true;
5611 } else { 5616 } else {
5612 ReportError("function block expected"); 5617 ReportError("function block expected");
5613 } 5618 }
5614 Function& func = Function::Handle(Z, 5619 Function& func = Function::Handle(Z,
5615 Function::New(func_name, 5620 Function::New(func_name,
5616 RawFunction::kRegularFunction, 5621 RawFunction::kRegularFunction,
5617 is_static, 5622 is_static,
5618 /* is_const = */ false, 5623 /* is_const = */ false,
5619 /* is_abstract = */ false, 5624 /* is_abstract = */ false,
5620 is_external, 5625 is_external,
5621 is_native, 5626 is_native,
5622 current_class(), 5627 current_class(),
5623 decl_begin_pos)); 5628 decl_begin_pos));
5624 func.set_result_type(result_type); 5629 func.set_result_type(result_type);
5625 func.set_end_token_pos(function_end_pos); 5630 func.set_end_token_pos(function_end_pos);
5626 func.set_modifier(func_modifier); 5631 func.set_modifier(func_modifier);
5627 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { 5632 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) {
5628 func.set_is_reflectable(false); 5633 func.set_is_reflectable(false);
5629 } 5634 }
5635 if (is_native) {
5636 func.set_native_name(*native_name);
5637 }
5630 AddFormalParamsToFunction(&params, func); 5638 AddFormalParamsToFunction(&params, func);
5631 top_level->AddFunction(func); 5639 top_level->AddFunction(func);
5632 if (!is_patch) { 5640 if (!is_patch) {
5633 library_.AddObject(func, func_name); 5641 library_.AddObject(func, func_name);
5634 } else { 5642 } else {
5635 library_.ReplaceObject(func, func_name); 5643 library_.ReplaceObject(func, func_name);
5636 } 5644 }
5637 if (metadata_pos >= 0) { 5645 if (metadata_pos >= 0) {
5638 library_.AddFunctionMetadata(func, metadata_pos); 5646 library_.AddFunctionMetadata(func, metadata_pos);
5639 } 5647 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
5728 5736
5729 const intptr_t modifier_pos = TokenPos(); 5737 const intptr_t modifier_pos = TokenPos();
5730 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); 5738 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier();
5731 if (!is_getter && (func_modifier != RawFunction::kNoModifier)) { 5739 if (!is_getter && (func_modifier != RawFunction::kNoModifier)) {
5732 ReportError(modifier_pos, 5740 ReportError(modifier_pos,
5733 "setter function cannot be async, async* or sync*"); 5741 "setter function cannot be async, async* or sync*");
5734 } 5742 }
5735 5743
5736 intptr_t accessor_end_pos = accessor_pos; 5744 intptr_t accessor_end_pos = accessor_pos;
5737 bool is_native = false; 5745 bool is_native = false;
5746 String* native_name = NULL;
5738 if (is_external) { 5747 if (is_external) {
5739 accessor_end_pos = TokenPos(); 5748 accessor_end_pos = TokenPos();
5740 ExpectSemicolon(); 5749 ExpectSemicolon();
5741 } else if (CurrentToken() == Token::kLBRACE) { 5750 } else if (CurrentToken() == Token::kLBRACE) {
5742 SkipBlock(); 5751 SkipBlock();
5743 accessor_end_pos = TokenPos(); 5752 accessor_end_pos = TokenPos();
5744 ExpectToken(Token::kRBRACE); 5753 ExpectToken(Token::kRBRACE);
5745 } else if (CurrentToken() == Token::kARROW) { 5754 } else if (CurrentToken() == Token::kARROW) {
5746 if (is_getter && ((func_modifier & RawFunction::kGeneratorBit) != 0)) { 5755 if (is_getter && ((func_modifier & RawFunction::kGeneratorBit) != 0)) {
5747 ReportError(modifier_pos, 5756 ReportError(modifier_pos,
5748 "=> style getter may not be sync* or async* generator"); 5757 "=> style getter may not be sync* or async* generator");
5749 } 5758 }
5750 ConsumeToken(); 5759 ConsumeToken();
5751 BoolScope allow_await(&this->await_is_keyword_, 5760 BoolScope allow_await(&this->await_is_keyword_,
5752 func_modifier != RawFunction::kNoModifier); 5761 func_modifier != RawFunction::kNoModifier);
5753 SkipExpr(); 5762 SkipExpr();
5754 accessor_end_pos = TokenPos(); 5763 accessor_end_pos = TokenPos();
5755 ExpectSemicolon(); 5764 ExpectSemicolon();
5756 } else if (IsSymbol(Symbols::Native())) { 5765 } else if (IsSymbol(Symbols::Native())) {
5757 ParseNativeDeclaration(); 5766 native_name = &ParseNativeDeclaration();
5758 accessor_end_pos = TokenPos(); 5767 accessor_end_pos = TokenPos();
5759 ExpectSemicolon(); 5768 ExpectSemicolon();
5760 is_native = true; 5769 is_native = true;
5761 } else { 5770 } else {
5762 ReportError("function block expected"); 5771 ReportError("function block expected");
5763 } 5772 }
5764 Function& func = Function::Handle(Z, 5773 Function& func = Function::Handle(Z,
5765 Function::New(accessor_name, 5774 Function::New(accessor_name,
5766 is_getter ? RawFunction::kGetterFunction : 5775 is_getter ? RawFunction::kGetterFunction :
5767 RawFunction::kSetterFunction, 5776 RawFunction::kSetterFunction,
5768 is_static, 5777 is_static,
5769 /* is_const = */ false, 5778 /* is_const = */ false,
5770 /* is_abstract = */ false, 5779 /* is_abstract = */ false,
5771 is_external, 5780 is_external,
5772 is_native, 5781 is_native,
5773 current_class(), 5782 current_class(),
5774 decl_begin_pos)); 5783 decl_begin_pos));
5775 func.set_result_type(result_type); 5784 func.set_result_type(result_type);
5776 func.set_end_token_pos(accessor_end_pos); 5785 func.set_end_token_pos(accessor_end_pos);
5777 func.set_modifier(func_modifier); 5786 func.set_modifier(func_modifier);
5778 if (is_native) { 5787 if (is_native) {
5779 func.set_is_debuggable(false); 5788 func.set_is_debuggable(false);
5789 func.set_native_name(*native_name);
5780 } 5790 }
5781 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { 5791 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) {
5782 func.set_is_reflectable(false); 5792 func.set_is_reflectable(false);
5783 } 5793 }
5784 AddFormalParamsToFunction(&params, func); 5794 AddFormalParamsToFunction(&params, func);
5785 top_level->AddFunction(func); 5795 top_level->AddFunction(func);
5786 if (!is_patch) { 5796 if (!is_patch) {
5787 library_.AddObject(func, accessor_name); 5797 library_.AddObject(func, accessor_name);
5788 } else { 5798 } else {
5789 library_.ReplaceObject(func, accessor_name); 5799 library_.ReplaceObject(func, accessor_name);
(...skipping 8543 matching lines...) Expand 10 before | Expand all | Expand 10 after
14333 void Parser::SkipQualIdent() { 14343 void Parser::SkipQualIdent() {
14334 ASSERT(IsIdentifier()); 14344 ASSERT(IsIdentifier());
14335 ConsumeToken(); 14345 ConsumeToken();
14336 if (CurrentToken() == Token::kPERIOD) { 14346 if (CurrentToken() == Token::kPERIOD) {
14337 ConsumeToken(); // Consume the kPERIOD token. 14347 ConsumeToken(); // Consume the kPERIOD token.
14338 ExpectIdentifier("identifier expected after '.'"); 14348 ExpectIdentifier("identifier expected after '.'");
14339 } 14349 }
14340 } 14350 }
14341 14351
14342 } // namespace dart 14352 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698