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

Side by Side Diff: src/preparser.h

Issue 1399893002: [es7] implement |do| expressions proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Less code duplication in Rewriter Created 5 years, 2 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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/bailout-reason.h" 8 #include "src/bailout-reason.h"
9 #include "src/expression-classifier.h" 9 #include "src/expression-classifier.h"
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 class ParserBase : public Traits { 81 class ParserBase : public Traits {
82 public: 82 public:
83 // Shorten type names defined by Traits. 83 // Shorten type names defined by Traits.
84 typedef typename Traits::Type::Expression ExpressionT; 84 typedef typename Traits::Type::Expression ExpressionT;
85 typedef typename Traits::Type::Identifier IdentifierT; 85 typedef typename Traits::Type::Identifier IdentifierT;
86 typedef typename Traits::Type::FormalParameter FormalParameterT; 86 typedef typename Traits::Type::FormalParameter FormalParameterT;
87 typedef typename Traits::Type::FormalParameters FormalParametersT; 87 typedef typename Traits::Type::FormalParameters FormalParametersT;
88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
89 typedef typename Traits::Type::Literal LiteralT; 89 typedef typename Traits::Type::Literal LiteralT;
90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
91 typedef typename Traits::Type::StatementList StatementListT;
91 92
92 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, 93 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
93 v8::Extension* extension, AstValueFactory* ast_value_factory, 94 v8::Extension* extension, AstValueFactory* ast_value_factory,
94 ParserRecorder* log, typename Traits::Type::Parser this_object) 95 ParserRecorder* log, typename Traits::Type::Parser this_object)
95 : Traits(this_object), 96 : Traits(this_object),
96 parenthesized_function_(false), 97 parenthesized_function_(false),
97 scope_(NULL), 98 scope_(NULL),
98 function_state_(NULL), 99 function_state_(NULL),
99 extension_(extension), 100 extension_(extension),
100 fni_(NULL), 101 fni_(NULL),
101 ast_value_factory_(ast_value_factory), 102 ast_value_factory_(ast_value_factory),
102 log_(log), 103 log_(log),
103 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 104 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
104 stack_limit_(stack_limit), 105 stack_limit_(stack_limit),
105 zone_(zone), 106 zone_(zone),
106 scanner_(scanner), 107 scanner_(scanner),
107 stack_overflow_(false), 108 stack_overflow_(false),
108 allow_lazy_(false), 109 allow_lazy_(false),
109 allow_natives_(false), 110 allow_natives_(false),
110 allow_harmony_sloppy_(false), 111 allow_harmony_sloppy_(false),
111 allow_harmony_sloppy_function_(false), 112 allow_harmony_sloppy_function_(false),
112 allow_harmony_sloppy_let_(false), 113 allow_harmony_sloppy_let_(false),
113 allow_harmony_rest_parameters_(false), 114 allow_harmony_rest_parameters_(false),
114 allow_harmony_default_parameters_(false), 115 allow_harmony_default_parameters_(false),
115 allow_harmony_spread_calls_(false), 116 allow_harmony_spread_calls_(false),
116 allow_harmony_destructuring_(false), 117 allow_harmony_destructuring_(false),
117 allow_harmony_spread_arrays_(false), 118 allow_harmony_spread_arrays_(false),
118 allow_harmony_new_target_(false), 119 allow_harmony_new_target_(false),
119 allow_strong_mode_(false), 120 allow_strong_mode_(false),
120 allow_legacy_const_(true) {} 121 allow_legacy_const_(true),
122 allow_harmony_do_expressions_(false) {}
121 123
122 #define ALLOW_ACCESSORS(name) \ 124 #define ALLOW_ACCESSORS(name) \
123 bool allow_##name() const { return allow_##name##_; } \ 125 bool allow_##name() const { return allow_##name##_; } \
124 void set_allow_##name(bool allow) { allow_##name##_ = allow; } 126 void set_allow_##name(bool allow) { allow_##name##_ = allow; }
125 127
126 ALLOW_ACCESSORS(lazy); 128 ALLOW_ACCESSORS(lazy);
127 ALLOW_ACCESSORS(natives); 129 ALLOW_ACCESSORS(natives);
128 ALLOW_ACCESSORS(harmony_sloppy); 130 ALLOW_ACCESSORS(harmony_sloppy);
129 ALLOW_ACCESSORS(harmony_sloppy_function); 131 ALLOW_ACCESSORS(harmony_sloppy_function);
130 ALLOW_ACCESSORS(harmony_sloppy_let); 132 ALLOW_ACCESSORS(harmony_sloppy_let);
131 ALLOW_ACCESSORS(harmony_rest_parameters); 133 ALLOW_ACCESSORS(harmony_rest_parameters);
132 ALLOW_ACCESSORS(harmony_default_parameters); 134 ALLOW_ACCESSORS(harmony_default_parameters);
133 ALLOW_ACCESSORS(harmony_spread_calls); 135 ALLOW_ACCESSORS(harmony_spread_calls);
134 ALLOW_ACCESSORS(harmony_destructuring); 136 ALLOW_ACCESSORS(harmony_destructuring);
135 ALLOW_ACCESSORS(harmony_spread_arrays); 137 ALLOW_ACCESSORS(harmony_spread_arrays);
136 ALLOW_ACCESSORS(harmony_new_target); 138 ALLOW_ACCESSORS(harmony_new_target);
137 ALLOW_ACCESSORS(strong_mode); 139 ALLOW_ACCESSORS(strong_mode);
138 ALLOW_ACCESSORS(legacy_const); 140 ALLOW_ACCESSORS(legacy_const);
141 ALLOW_ACCESSORS(harmony_do_expressions);
139 #undef ALLOW_ACCESSORS 142 #undef ALLOW_ACCESSORS
140 143
144 INLINE(bool CheckStackOverflow()) {
adamk 2015/10/15 10:59:33 I don't think you need this anymore.
145 if (stack_overflow_) return true;
146 if (GetCurrentStackPosition() >= stack_limit_) return false;
147 stack_overflow_ = true;
148 return true;
149 }
150
151 uintptr_t stack_limit() const { return stack_limit_; }
152
141 protected: 153 protected:
142 enum AllowRestrictedIdentifiers { 154 enum AllowRestrictedIdentifiers {
143 kAllowRestrictedIdentifiers, 155 kAllowRestrictedIdentifiers,
144 kDontAllowRestrictedIdentifiers 156 kDontAllowRestrictedIdentifiers
145 }; 157 };
146 158
147 enum Mode { 159 enum Mode {
148 PARSE_LAZILY, 160 PARSE_LAZILY,
149 PARSE_EAGERLY 161 PARSE_EAGERLY
150 }; 162 };
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 bool allow_harmony_sloppy_function_; 846 bool allow_harmony_sloppy_function_;
835 bool allow_harmony_sloppy_let_; 847 bool allow_harmony_sloppy_let_;
836 bool allow_harmony_rest_parameters_; 848 bool allow_harmony_rest_parameters_;
837 bool allow_harmony_default_parameters_; 849 bool allow_harmony_default_parameters_;
838 bool allow_harmony_spread_calls_; 850 bool allow_harmony_spread_calls_;
839 bool allow_harmony_destructuring_; 851 bool allow_harmony_destructuring_;
840 bool allow_harmony_spread_arrays_; 852 bool allow_harmony_spread_arrays_;
841 bool allow_harmony_new_target_; 853 bool allow_harmony_new_target_;
842 bool allow_strong_mode_; 854 bool allow_strong_mode_;
843 bool allow_legacy_const_; 855 bool allow_legacy_const_;
856 bool allow_harmony_do_expressions_;
844 }; 857 };
845 858
846 859
847 class PreParserIdentifier { 860 class PreParserIdentifier {
848 public: 861 public:
849 PreParserIdentifier() : type_(kUnknownIdentifier) {} 862 PreParserIdentifier() : type_(kUnknownIdentifier) {}
850 static PreParserIdentifier Default() { 863 static PreParserIdentifier Default() {
851 return PreParserIdentifier(kUnknownIdentifier); 864 return PreParserIdentifier(kUnknownIdentifier);
852 } 865 }
853 static PreParserIdentifier Eval() { 866 static PreParserIdentifier Eval() {
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 ExpressionClassifier* classifier) { 1703 ExpressionClassifier* classifier) {
1691 if (!classifier->is_simple_parameter_list()) { 1704 if (!classifier->is_simple_parameter_list()) {
1692 scope->SetHasNonSimpleParameters(); 1705 scope->SetHasNonSimpleParameters();
1693 } 1706 }
1694 } 1707 }
1695 1708
1696 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 1709 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
1697 1710
1698 // Temporary glue; these functions will move to ParserBase. 1711 // Temporary glue; these functions will move to ParserBase.
1699 PreParserExpression ParseV8Intrinsic(bool* ok); 1712 PreParserExpression ParseV8Intrinsic(bool* ok);
1713 V8_INLINE PreParserExpression ParseDoExpression(bool* ok);
1700 PreParserExpression ParseFunctionLiteral( 1714 PreParserExpression ParseFunctionLiteral(
1701 PreParserIdentifier name, Scanner::Location function_name_location, 1715 PreParserIdentifier name, Scanner::Location function_name_location,
1702 FunctionNameValidity function_name_validity, FunctionKind kind, 1716 FunctionNameValidity function_name_validity, FunctionKind kind,
1703 int function_token_position, FunctionLiteral::FunctionType type, 1717 int function_token_position, FunctionLiteral::FunctionType type,
1704 FunctionLiteral::ArityRestriction arity_restriction, 1718 FunctionLiteral::ArityRestriction arity_restriction,
1705 LanguageMode language_mode, bool* ok); 1719 LanguageMode language_mode, bool* ok);
1706 1720
1707 PreParserExpression ParseClassLiteral(PreParserIdentifier name, 1721 PreParserExpression ParseClassLiteral(PreParserIdentifier name,
1708 Scanner::Location class_name_location, 1722 Scanner::Location class_name_location,
1709 bool name_is_strict_reserved, int pos, 1723 bool name_is_strict_reserved, int pos,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 Statement ParseSwitchStatement(bool* ok); 1844 Statement ParseSwitchStatement(bool* ok);
1831 Statement ParseDoWhileStatement(bool* ok); 1845 Statement ParseDoWhileStatement(bool* ok);
1832 Statement ParseWhileStatement(bool* ok); 1846 Statement ParseWhileStatement(bool* ok);
1833 Statement ParseForStatement(bool* ok); 1847 Statement ParseForStatement(bool* ok);
1834 Statement ParseThrowStatement(bool* ok); 1848 Statement ParseThrowStatement(bool* ok);
1835 Statement ParseTryStatement(bool* ok); 1849 Statement ParseTryStatement(bool* ok);
1836 Statement ParseDebuggerStatement(bool* ok); 1850 Statement ParseDebuggerStatement(bool* ok);
1837 Expression ParseConditionalExpression(bool accept_IN, bool* ok); 1851 Expression ParseConditionalExpression(bool accept_IN, bool* ok);
1838 Expression ParseObjectLiteral(bool* ok); 1852 Expression ParseObjectLiteral(bool* ok);
1839 Expression ParseV8Intrinsic(bool* ok); 1853 Expression ParseV8Intrinsic(bool* ok);
1854 Expression ParseDoExpression(bool* ok);
1840 1855
1841 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, 1856 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count,
1842 int* expected_property_count, bool* ok); 1857 int* expected_property_count, bool* ok);
1843 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 1858 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
1844 PreParserIdentifier function_name, int pos, 1859 PreParserIdentifier function_name, int pos,
1845 const PreParserFormalParameters& parameters, FunctionKind kind, 1860 const PreParserFormalParameters& parameters, FunctionKind kind,
1846 FunctionLiteral::FunctionType function_type, bool* ok); 1861 FunctionLiteral::FunctionType function_type, bool* ok);
1847 1862
1848 Expression ParseFunctionLiteral( 1863 Expression ParseFunctionLiteral(
1849 Identifier name, Scanner::Location function_name_location, 1864 Identifier name, Scanner::Location function_name_location,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 // lists that are too long. 1910 // lists that are too long.
1896 1911
1897 // Accomodate array literal for rest parameter. 1912 // Accomodate array literal for rest parameter.
1898 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { 1913 if (params.IsArrowFunctionFormalParametersWithRestParameter()) {
1899 ++parameters->materialized_literals_count; 1914 ++parameters->materialized_literals_count;
1900 pre_parser_->function_state_->NextMaterializedLiteralIndex(); 1915 pre_parser_->function_state_->NextMaterializedLiteralIndex();
1901 } 1916 }
1902 } 1917 }
1903 1918
1904 1919
1920 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) {
1921 return pre_parser_->ParseDoExpression(ok);
1922 }
1923
1924
1905 PreParserStatementList PreParser::ParseEagerFunctionBody( 1925 PreParserStatementList PreParser::ParseEagerFunctionBody(
1906 PreParserIdentifier function_name, int pos, 1926 PreParserIdentifier function_name, int pos,
1907 const PreParserFormalParameters& parameters, FunctionKind kind, 1927 const PreParserFormalParameters& parameters, FunctionKind kind,
1908 FunctionLiteral::FunctionType function_type, bool* ok) { 1928 FunctionLiteral::FunctionType function_type, bool* ok) {
1909 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1929 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1910 1930
1911 ParseStatementList(Token::RBRACE, ok); 1931 ParseStatementList(Token::RBRACE, ok);
1912 if (!*ok) return PreParserStatementList(); 1932 if (!*ok) return PreParserStatementList();
1913 1933
1914 Expect(Token::RBRACE, ok); 1934 Expect(Token::RBRACE, ok);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 // 'false' 2235 // 'false'
2216 // Identifier 2236 // Identifier
2217 // Number 2237 // Number
2218 // String 2238 // String
2219 // ArrayLiteral 2239 // ArrayLiteral
2220 // ObjectLiteral 2240 // ObjectLiteral
2221 // RegExpLiteral 2241 // RegExpLiteral
2222 // ClassLiteral 2242 // ClassLiteral
2223 // '(' Expression ')' 2243 // '(' Expression ')'
2224 // TemplateLiteral 2244 // TemplateLiteral
2245 // do Block
2225 2246
2226 int beg_pos = scanner()->peek_location().beg_pos; 2247 int beg_pos = scanner()->peek_location().beg_pos;
2227 int end_pos = scanner()->peek_location().end_pos; 2248 int end_pos = scanner()->peek_location().end_pos;
2228 ExpressionT result = this->EmptyExpression(); 2249 ExpressionT result = this->EmptyExpression();
2229 Token::Value token = peek(); 2250 Token::Value token = peek();
2230 switch (token) { 2251 switch (token) {
2231 case Token::THIS: { 2252 case Token::THIS: {
2232 BindingPatternUnexpectedToken(classifier); 2253 BindingPatternUnexpectedToken(classifier);
2233 Consume(Token::THIS); 2254 Consume(Token::THIS);
2234 if (FLAG_strong_this && is_strong(language_mode())) { 2255 if (FLAG_strong_this && is_strong(language_mode())) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2395 MessageTemplate::kUnexpectedTemplateString); 2416 MessageTemplate::kUnexpectedTemplateString);
2396 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, 2417 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos,
2397 classifier, CHECK_OK); 2418 classifier, CHECK_OK);
2398 break; 2419 break;
2399 2420
2400 case Token::MOD: 2421 case Token::MOD:
2401 if (allow_natives() || extension_ != NULL) { 2422 if (allow_natives() || extension_ != NULL) {
2402 result = this->ParseV8Intrinsic(CHECK_OK); 2423 result = this->ParseV8Intrinsic(CHECK_OK);
2403 break; 2424 break;
2404 } 2425 }
2426
2427 case Token::DO:
2428 if (token == Token::DO && allow_harmony_do_expressions()) {
adamk 2015/10/15 10:59:33 Didn't we just switch on |token|?
caitp (gmail) 2015/10/15 11:24:17 It can fall through from the above, unfortunately
adamk 2015/10/15 12:01:25 What if you restructured the cases to have returns
caitp (gmail) 2015/10/15 12:34:07 I think doing that will add a lot of unrelated noi
adamk 2015/10/15 12:42:27 If you want to wait on it, please add a TODO.
2429 BindingPatternUnexpectedToken(classifier);
2430 result = Traits::ParseDoExpression(CHECK_OK);
2431 break;
2432 }
2405 // If we're not allowing special syntax we fall-through to the 2433 // If we're not allowing special syntax we fall-through to the
2406 // default case. 2434 // default case.
2407 2435
2408 default: { 2436 default: {
2409 Next(); 2437 Next();
2410 ReportUnexpectedToken(token); 2438 ReportUnexpectedToken(token);
2411 *ok = false; 2439 *ok = false;
2412 } 2440 }
2413 } 2441 }
2414 2442
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
4186 return; 4214 return;
4187 } 4215 }
4188 has_seen_constructor_ = true; 4216 has_seen_constructor_ = true;
4189 return; 4217 return;
4190 } 4218 }
4191 } 4219 }
4192 } // namespace internal 4220 } // namespace internal
4193 } // namespace v8 4221 } // namespace v8
4194 4222
4195 #endif // V8_PREPARSER_H 4223 #endif // V8_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698