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

Side by Side Diff: src/parsing/preparser.cc

Issue 2372733002: [parser] Refactor of (Parse|Desugar)*(Async|Arrow)* (Closed)
Patch Set: Rebase Created 4 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
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 // The PreParser checks that the syntax follows the grammar for JavaScript, 129 // The PreParser checks that the syntax follows the grammar for JavaScript,
130 // and collects some information about the program along the way. 130 // and collects some information about the program along the way.
131 // The grammar check is only performed in order to understand the program 131 // The grammar check is only performed in order to understand the program
132 // sufficiently to deduce some information about it, that can be used 132 // sufficiently to deduce some information about it, that can be used
133 // to speed up later parsing. Finding errors is not the goal of pre-parsing, 133 // to speed up later parsing. Finding errors is not the goal of pre-parsing,
134 // rather it is to speed up properly written and correct programs. 134 // rather it is to speed up properly written and correct programs.
135 // That means that contextual checks (like a label being declared where 135 // That means that contextual checks (like a label being declared where
136 // it is used) are generally omitted. 136 // it is used) are generally omitted.
137 137
138 PreParser::Statement PreParser::ParseAsyncFunctionDeclaration(
139 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
140 // AsyncFunctionDeclaration ::
141 // async [no LineTerminator here] function BindingIdentifier[Await]
142 // ( FormalParameters[Await] ) { AsyncFunctionBody }
143 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
144 int pos = position();
145 Expect(Token::FUNCTION, CHECK_OK);
146 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
147 return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
148 }
149
150 PreParser::Statement PreParser::ParseClassDeclaration( 138 PreParser::Statement PreParser::ParseClassDeclaration(
151 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 139 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
152 int pos = position(); 140 int pos = position();
153 bool is_strict_reserved = false; 141 bool is_strict_reserved = false;
154 Identifier name = 142 Identifier name =
155 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 143 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
156 ExpressionClassifier no_classifier(this); 144 ExpressionClassifier no_classifier(this);
157 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, 145 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
158 CHECK_OK); 146 CHECK_OK);
159 return Statement::Default(); 147 return Statement::Default();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 224
237 if (is_strict(language_mode)) { 225 if (is_strict(language_mode)) {
238 int end_position = scanner()->location().end_pos; 226 int end_position = scanner()->location().end_pos;
239 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 227 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
240 CheckDecimalLiteralWithLeadingZero(start_position, end_position); 228 CheckDecimalLiteralWithLeadingZero(start_position, end_position);
241 } 229 }
242 230
243 return Expression::Default(); 231 return Expression::Default();
244 } 232 }
245 233
246 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) {
247 // AsyncFunctionDeclaration ::
248 // async [no LineTerminator here] function ( FormalParameters[Await] )
249 // { AsyncFunctionBody }
250 //
251 // async [no LineTerminator here] function BindingIdentifier[Await]
252 // ( FormalParameters[Await] ) { AsyncFunctionBody }
253 int pos = position();
254 Expect(Token::FUNCTION, CHECK_OK);
255 bool is_strict_reserved = false;
256 Identifier name;
257 FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression;
258
259 if (peek_any_identifier()) {
260 type = FunctionLiteral::kNamedExpression;
261 name = ParseIdentifierOrStrictReservedWord(FunctionKind::kAsyncFunction,
262 &is_strict_reserved, CHECK_OK);
263 }
264
265 ParseFunctionLiteral(name, scanner()->location(),
266 is_strict_reserved ? kFunctionNameIsStrictReserved
267 : kFunctionNameValidityUnknown,
268 FunctionKind::kAsyncFunction, pos, type, language_mode(),
269 CHECK_OK);
270 return Expression::Default();
271 }
272
273 PreParser::LazyParsingResult PreParser::ParseLazyFunctionLiteralBody( 234 PreParser::LazyParsingResult PreParser::ParseLazyFunctionLiteralBody(
274 bool may_abort, bool* ok) { 235 bool may_abort, bool* ok) {
275 int body_start = position(); 236 int body_start = position();
276 PreParserStatementList body; 237 PreParserStatementList body;
277 LazyParsingResult result = ParseStatementList( 238 LazyParsingResult result = ParseStatementList(
278 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete)); 239 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete));
279 if (result == kLazyParsingAborted) return result; 240 if (result == kLazyParsingAborted) return result;
280 241
281 // Position right after terminal '}'. 242 // Position right after terminal '}'.
282 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 243 DCHECK_EQ(Token::RBRACE, scanner()->peek());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 &has_seen_constructor, CHECK_OK); 296 &has_seen_constructor, CHECK_OK);
336 ValidateExpression(CHECK_OK); 297 ValidateExpression(CHECK_OK);
337 impl()->AccumulateFormalParameterContainmentErrors(); 298 impl()->AccumulateFormalParameterContainmentErrors();
338 } 299 }
339 300
340 Expect(Token::RBRACE, CHECK_OK); 301 Expect(Token::RBRACE, CHECK_OK);
341 302
342 return Expression::Default(); 303 return Expression::Default();
343 } 304 }
344 305
345 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body,
346 bool accept_IN, int pos,
347 bool* ok) {
348 scope()->ForceContextAllocation();
349
350 PreParserExpression return_value =
351 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID);
352
353 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
354 }
355
356 PreParserExpression PreParser::ExpressionFromIdentifier( 306 PreParserExpression PreParser::ExpressionFromIdentifier(
357 PreParserIdentifier name, int start_position, int end_position, 307 PreParserIdentifier name, int start_position, int end_position,
358 InferName infer) { 308 InferName infer) {
359 if (track_unresolved_variables_) { 309 if (track_unresolved_variables_) {
360 AstNodeFactory factory(ast_value_factory()); 310 AstNodeFactory factory(ast_value_factory());
361 // Setting the Zone is necessary because zone_ might be the temp Zone, and 311 // Setting the Zone is necessary because zone_ might be the temp Zone, and
362 // AstValueFactory doesn't know about it. 312 // AstValueFactory doesn't know about it.
363 factory.set_zone(zone()); 313 factory.set_zone(zone());
364 DCHECK_NOT_NULL(name.string_); 314 DCHECK_NOT_NULL(name.string_);
365 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, 315 scope()->NewUnresolved(&factory, name.string_, start_position, end_position,
366 NORMAL_VARIABLE); 316 NORMAL_VARIABLE);
367 } 317 }
368 return PreParserExpression::FromIdentifier(name); 318 return PreParserExpression::FromIdentifier(name);
369 } 319 }
370 320
371 #undef CHECK_OK 321 #undef CHECK_OK
372 #undef CHECK_OK_CUSTOM 322 #undef CHECK_OK_CUSTOM
373 323
374 324
375 } // namespace internal 325 } // namespace internal
376 } // namespace v8 326 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698