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

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

Issue 2368083002: [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: More changes to address reviewers' comments 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
« src/parsing/parser-base.h ('K') | « 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // AsyncFunctionDeclaration :: 126 // AsyncFunctionDeclaration ::
127 // async [no LineTerminator here] function BindingIdentifier[Await] 127 // async [no LineTerminator here] function BindingIdentifier[Await]
128 // ( FormalParameters[Await] ) { AsyncFunctionBody } 128 // ( FormalParameters[Await] ) { AsyncFunctionBody }
129 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); 129 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
130 int pos = position(); 130 int pos = position();
131 Expect(Token::FUNCTION, CHECK_OK); 131 Expect(Token::FUNCTION, CHECK_OK);
132 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync; 132 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
133 return ParseHoistableDeclaration(pos, flags, names, default_export, ok); 133 return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
134 } 134 }
135 135
136 PreParser::Statement PreParser::ParseClassDeclaration(
137 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
138 int pos = position();
139 bool is_strict_reserved = false;
140 Identifier name =
141 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
142 ExpressionClassifier no_classifier(this);
143 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
144 CHECK_OK);
145 return Statement::Default();
146 }
147
148 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { 136 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
149 Consume(Token::FUNCTION); 137 Consume(Token::FUNCTION);
150 int pos = position(); 138 int pos = position();
151 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; 139 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
152 if (Check(Token::MUL)) { 140 if (Check(Token::MUL)) {
153 flags |= ParseFunctionFlags::kIsGenerator; 141 flags |= ParseFunctionFlags::kIsGenerator;
154 if (allow_harmony_restrictive_declarations()) { 142 if (allow_harmony_restrictive_declarations()) {
155 ReportMessageAt(scanner()->location(), 143 ReportMessageAt(scanner()->location(),
156 MessageTemplate::kGeneratorInLegacyContext); 144 MessageTemplate::kGeneratorInLegacyContext);
157 *ok = false; 145 *ok = false;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 int body_end = scanner()->peek_location().end_pos; 258 int body_end = scanner()->peek_location().end_pos;
271 DeclarationScope* scope = this->scope()->AsDeclarationScope(); 259 DeclarationScope* scope = this->scope()->AsDeclarationScope();
272 DCHECK(scope->is_function_scope()); 260 DCHECK(scope->is_function_scope());
273 log_->LogFunction(body_start, body_end, 261 log_->LogFunction(body_start, body_end,
274 function_state_->materialized_literal_count(), 262 function_state_->materialized_literal_count(),
275 function_state_->expected_property_count(), language_mode(), 263 function_state_->expected_property_count(), language_mode(),
276 scope->uses_super_property(), scope->calls_eval()); 264 scope->uses_super_property(), scope->calls_eval());
277 return kLazyParsingComplete; 265 return kLazyParsingComplete;
278 } 266 }
279 267
280 PreParserExpression PreParser::ParseClassLiteral(
281 PreParserIdentifier name, Scanner::Location class_name_location,
282 bool name_is_strict_reserved, int pos, bool* ok) {
283 // All parts of a ClassDeclaration and ClassExpression are strict code.
284 if (name_is_strict_reserved) {
285 ReportMessageAt(class_name_location,
286 MessageTemplate::kUnexpectedStrictReserved);
287 *ok = false;
288 return EmptyExpression();
289 }
290 if (IsEvalOrArguments(name)) {
291 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments);
292 *ok = false;
293 return EmptyExpression();
294 }
295
296 LanguageMode class_language_mode = language_mode();
297 BlockState block_state(&scope_state_);
298 scope()->SetLanguageMode(
299 static_cast<LanguageMode>(class_language_mode | STRICT));
300 // TODO(marja): Make PreParser use scope names too.
301 // this->scope()->SetScopeName(name);
302
303 bool has_extends = Check(Token::EXTENDS);
304 if (has_extends) {
305 ExpressionClassifier extends_classifier(this);
306 ParseLeftHandSideExpression(CHECK_OK);
307 CheckNoTailCallExpressions(CHECK_OK);
308 ValidateExpression(CHECK_OK);
309 impl()->AccumulateFormalParameterContainmentErrors();
310 }
311
312 ClassLiteralChecker checker(this);
313 bool has_seen_constructor = false;
314
315 Expect(Token::LBRACE, CHECK_OK);
316 while (peek() != Token::RBRACE) {
317 if (Check(Token::SEMICOLON)) continue;
318 bool is_computed_name = false; // Classes do not care about computed
319 // property names here.
320 ExpressionClassifier property_classifier(this);
321 ParseClassPropertyDefinition(&checker, has_extends, &is_computed_name,
322 &has_seen_constructor, CHECK_OK);
323 ValidateExpression(CHECK_OK);
324 impl()->AccumulateFormalParameterContainmentErrors();
325 }
326
327 Expect(Token::RBRACE, CHECK_OK);
328
329 return Expression::Default();
330 }
331
332 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, 268 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body,
333 bool accept_IN, int pos, 269 bool accept_IN, int pos,
334 bool* ok) { 270 bool* ok) {
335 scope()->ForceContextAllocation(); 271 scope()->ForceContextAllocation();
336 272
337 PreParserExpression return_value = 273 PreParserExpression return_value =
338 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); 274 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID);
339 275
340 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 276 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
341 } 277 }
342 278
343 #undef CHECK_OK 279 #undef CHECK_OK
344 #undef CHECK_OK_CUSTOM 280 #undef CHECK_OK_CUSTOM
345 281
346 282
347 } // namespace internal 283 } // namespace internal
348 } // namespace v8 284 } // namespace v8
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698