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

Side by Side Diff: src/parsing/parser-base.h

Issue 1841093002: Add optional types to function/method declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1817353007-typ-mod
Patch Set: Created 4 years, 8 months 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 name_expression, value, ObjectLiteralProperty::COMPUTED, false, 1739 name_expression, value, ObjectLiteralProperty::COMPUTED, false,
1740 false); 1740 false);
1741 } 1741 }
1742 } 1742 }
1743 1743
1744 // Method definitions are never valid in patterns. 1744 // Method definitions are never valid in patterns.
1745 classifier->RecordPatternError( 1745 classifier->RecordPatternError(
1746 Scanner::Location(next_beg_pos, scanner()->location().end_pos), 1746 Scanner::Location(next_beg_pos, scanner()->location().end_pos),
1747 MessageTemplate::kInvalidDestructuringTarget); 1747 MessageTemplate::kInvalidDestructuringTarget);
1748 1748
1749 if (is_generator || peek() == Token::LPAREN) { 1749 if (is_generator || peek() == Token::LPAREN ||
1750 (scope_->typed() && peek() == Token::LT)) {
1750 // MethodDefinition 1751 // MethodDefinition
1751 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' 1752 // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
1752 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' 1753 // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
1753 if (!*is_computed_name) { 1754 if (!*is_computed_name) {
1754 checker->CheckProperty(name_token, kMethodProperty, is_static, 1755 checker->CheckProperty(name_token, kMethodProperty, is_static,
1755 is_generator, 1756 is_generator,
1756 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1757 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1757 } 1758 }
1758 1759
1759 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod 1760 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod
1760 : FunctionKind::kConciseMethod; 1761 : FunctionKind::kConciseMethod;
1762 typesystem::TypeFlags type_flags = (is_get || is_set)
1763 ? typesystem::kDisallowTypeParameters
1764 : typesystem::kNormalTypes;
1761 1765
1762 if (in_class && !is_static && this->IsConstructor(*name)) { 1766 if (in_class && !is_static && this->IsConstructor(*name)) {
1763 *has_seen_constructor = true; 1767 *has_seen_constructor = true;
1764 kind = has_extends ? FunctionKind::kSubclassConstructor 1768 kind = has_extends ? FunctionKind::kSubclassConstructor
1765 : FunctionKind::kBaseConstructor; 1769 : FunctionKind::kBaseConstructor;
1770 type_flags = typesystem::kConstructorTypes;
1766 } 1771 }
1767 1772
1768 value = this->ParseFunctionLiteral( 1773 value = this->ParseFunctionLiteral(
1769 *name, scanner()->location(), kSkipFunctionNameCheck, kind, 1774 *name, scanner()->location(), kSkipFunctionNameCheck, kind,
1770 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, 1775 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod,
1771 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1776 language_mode(), type_flags,
1777 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1772 1778
1773 return factory()->NewObjectLiteralProperty(name_expression, value, 1779 return factory()->NewObjectLiteralProperty(name_expression, value,
1774 ObjectLiteralProperty::COMPUTED, 1780 ObjectLiteralProperty::COMPUTED,
1775 is_static, *is_computed_name); 1781 is_static, *is_computed_name);
1776 } 1782 }
1777 1783
1778 if (in_class && name_token == Token::STATIC && !is_static) { 1784 if (in_class && name_token == Token::STATIC && !is_static) {
1779 // ClassElement (static) 1785 // ClassElement (static)
1780 // 'static' MethodDefinition 1786 // 'static' MethodDefinition
1781 *name = this->EmptyIdentifier(); 1787 *name = this->EmptyIdentifier();
(...skipping 19 matching lines...) Expand all
1801 if (!*is_computed_name) { 1807 if (!*is_computed_name) {
1802 checker->CheckProperty(name_token, kAccessorProperty, is_static, 1808 checker->CheckProperty(name_token, kAccessorProperty, is_static,
1803 is_generator, 1809 is_generator,
1804 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1810 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1805 } 1811 }
1806 1812
1807 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( 1813 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral(
1808 *name, scanner()->location(), kSkipFunctionNameCheck, 1814 *name, scanner()->location(), kSkipFunctionNameCheck,
1809 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, 1815 is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction,
1810 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, 1816 RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod,
1811 language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1817 language_mode(), typesystem::kDisallowTypeParameters,
1818 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1812 1819
1813 // Make sure the name expression is a string since we need a Name for 1820 // Make sure the name expression is a string since we need a Name for
1814 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this 1821 // Runtime_DefineAccessorPropertyUnchecked and since we can determine this
1815 // statically we can skip the extra runtime check. 1822 // statically we can skip the extra runtime check.
1816 if (!*is_computed_name) { 1823 if (!*is_computed_name) {
1817 name_expression = 1824 name_expression =
1818 factory()->NewStringLiteral(*name, name_expression->position()); 1825 factory()->NewStringLiteral(*name, name_expression->position());
1819 } 1826 }
1820 1827
1821 return factory()->NewObjectLiteralProperty( 1828 return factory()->NewObjectLiteralProperty(
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 is_generator, &is_strict_reserved_name, CHECK_OK); 2593 is_generator, &is_strict_reserved_name, CHECK_OK);
2587 function_name_location = scanner()->location(); 2594 function_name_location = scanner()->location();
2588 function_type = FunctionLiteral::kNamedExpression; 2595 function_type = FunctionLiteral::kNamedExpression;
2589 } 2596 }
2590 result = this->ParseFunctionLiteral( 2597 result = this->ParseFunctionLiteral(
2591 name, function_name_location, 2598 name, function_name_location,
2592 is_strict_reserved_name ? kFunctionNameIsStrictReserved 2599 is_strict_reserved_name ? kFunctionNameIsStrictReserved
2593 : kFunctionNameValidityUnknown, 2600 : kFunctionNameValidityUnknown,
2594 is_generator ? FunctionKind::kGeneratorFunction 2601 is_generator ? FunctionKind::kGeneratorFunction
2595 : FunctionKind::kNormalFunction, 2602 : FunctionKind::kNormalFunction,
2596 function_token_position, function_type, language_mode(), CHECK_OK); 2603 function_token_position, function_type, language_mode(),
2604 typesystem::kNormalTypes, CHECK_OK);
2597 } else if (peek() == Token::SUPER) { 2605 } else if (peek() == Token::SUPER) {
2598 const bool is_new = false; 2606 const bool is_new = false;
2599 result = ParseSuperExpression(is_new, classifier, CHECK_OK); 2607 result = ParseSuperExpression(is_new, classifier, CHECK_OK);
2600 } else { 2608 } else {
2601 result = ParsePrimaryExpression(classifier, CHECK_OK); 2609 result = ParsePrimaryExpression(classifier, CHECK_OK);
2602 } 2610 }
2603 2611
2604 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK); 2612 result = ParseMemberExpressionContinuation(result, classifier, CHECK_OK);
2605 return result; 2613 return result;
2606 } 2614 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 ValidateBindingPattern(classifier, ok); 2763 ValidateBindingPattern(classifier, ok);
2756 if (!*ok) return; 2764 if (!*ok) return;
2757 2765
2758 if (!Traits::IsIdentifier(pattern)) { 2766 if (!Traits::IsIdentifier(pattern)) {
2759 parameters->is_simple = false; 2767 parameters->is_simple = false;
2760 ValidateFormalParameterInitializer(classifier, ok); 2768 ValidateFormalParameterInitializer(classifier, ok);
2761 if (!*ok) return; 2769 if (!*ok) return;
2762 classifier->RecordNonSimpleParameter(); 2770 classifier->RecordNonSimpleParameter();
2763 } 2771 }
2764 2772
2773 // Parse optional question mark.
2774 bool optional = false;
2775 if (scope_->typed()) optional = Check(Token::CONDITIONAL);
2776
2777 // Parse optional type annotation.
2778 typename TypeSystem::Type type = this->EmptyType();
2779 if (scope_->typed() && Check(Token::COLON)) {
2780 type = ParseValidType(ok);
2781 if (!*ok) return;
2782 }
2783 USE(type); // TODO(nikolaos): really use it!
2784
2765 ExpressionT initializer = Traits::EmptyExpression(); 2785 ExpressionT initializer = Traits::EmptyExpression();
2766 if (!is_rest && Check(Token::ASSIGN)) { 2786 if (!is_rest && !optional && Check(Token::ASSIGN)) {
2767 ExpressionClassifier init_classifier(this); 2787 ExpressionClassifier init_classifier(this);
2768 initializer = ParseAssignmentExpression(true, &init_classifier, ok); 2788 initializer = ParseAssignmentExpression(true, &init_classifier, ok);
2769 if (!*ok) return; 2789 if (!*ok) return;
2770 Traits::RewriteNonPattern(&init_classifier, ok); 2790 Traits::RewriteNonPattern(&init_classifier, ok);
2771 ValidateFormalParameterInitializer(&init_classifier, ok); 2791 ValidateFormalParameterInitializer(&init_classifier, ok);
2772 if (!*ok) return; 2792 if (!*ok) return;
2773 parameters->is_simple = false; 2793 parameters->is_simple = false;
2774 init_classifier.Discard(); 2794 init_classifier.Discard();
2775 classifier->RecordNonSimpleParameter(); 2795 classifier->RecordNonSimpleParameter();
2776 2796
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 has_seen_constructor_ = true; 3655 has_seen_constructor_ = true;
3636 return; 3656 return;
3637 } 3657 }
3638 } 3658 }
3639 3659
3640 3660
3641 } // namespace internal 3661 } // namespace internal
3642 } // namespace v8 3662 } // namespace v8
3643 3663
3644 #endif // V8_PARSING_PARSER_BASE_H 3664 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698