Chromium Code Reviews

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

Issue 2311903003: Move ParseHoistableDeclaration to ParserBase. (Closed)
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 1175 matching lines...)
1186 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); 1186 void ParseFormalParameter(FormalParametersT* parameters, bool* ok);
1187 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); 1187 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok);
1188 void CheckArityRestrictions(int param_count, FunctionKind function_type, 1188 void CheckArityRestrictions(int param_count, FunctionKind function_type,
1189 bool has_rest, int formals_start_pos, 1189 bool has_rest, int formals_start_pos,
1190 int formals_end_pos, bool* ok); 1190 int formals_end_pos, bool* ok);
1191 1191
1192 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, 1192 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context,
1193 DeclarationParsingResult* parsing_result, 1193 DeclarationParsingResult* parsing_result,
1194 ZoneList<const AstRawString*>* names, 1194 ZoneList<const AstRawString*>* names,
1195 bool* ok); 1195 bool* ok);
1196 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
1197 bool default_export, bool* ok);
1198 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
1199 ZoneList<const AstRawString*>* names,
1200 bool default_export, bool* ok);
1196 1201
1197 // Under some circumstances, we allow preparsing to abort if the preparsed 1202 // Under some circumstances, we allow preparsing to abort if the preparsed
1198 // function is "long and trivial", and fully parse instead. Our current 1203 // function is "long and trivial", and fully parse instead. Our current
1199 // definition of "long and trivial" is: 1204 // definition of "long and trivial" is:
1200 // - over kLazyParseTrialLimit statements 1205 // - over kLazyParseTrialLimit statements
1201 // - all starting with an identifier (i.e., no if, for, while, etc.) 1206 // - all starting with an identifier (i.e., no if, for, while, etc.)
1202 static const int kLazyParseTrialLimit = 200; 1207 static const int kLazyParseTrialLimit = 200;
1203 1208
1204 // TODO(nikolaos, marja): The first argument should not really be passed 1209 // TODO(nikolaos, marja): The first argument should not really be passed
1205 // by value. The method is expected to add the parsed statements to the 1210 // by value. The method is expected to add the parsed statements to the
(...skipping 2376 matching lines...)
3582 } while (Check(Token::COMMA)); 3587 } while (Check(Token::COMMA));
3583 3588
3584 parsing_result->bindings_loc = 3589 parsing_result->bindings_loc =
3585 Scanner::Location(bindings_start, scanner()->location().end_pos); 3590 Scanner::Location(bindings_start, scanner()->location().end_pos);
3586 3591
3587 DCHECK(*ok); 3592 DCHECK(*ok);
3588 return init_block; 3593 return init_block;
3589 } 3594 }
3590 3595
3591 template <typename Impl> 3596 template <typename Impl>
3597 typename ParserBase<Impl>::StatementT
3598 ParserBase<Impl>::ParseHoistableDeclaration(
3599 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3600 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(GetEmptyStatement));
3601 int pos = position();
3602 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
3603 if (Check(Token::MUL)) {
3604 flags |= ParseFunctionFlags::kIsGenerator;
3605 }
3606 return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
3607 }
3608
3609 template <typename Impl>
3610 typename ParserBase<Impl>::StatementT
3611 ParserBase<Impl>::ParseHoistableDeclaration(
3612 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
3613 bool default_export, bool* ok) {
3614 // FunctionDeclaration ::
3615 // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
3616 // 'function' '(' FormalParameters ')' '{' FunctionBody '}'
3617 // GeneratorDeclaration ::
3618 // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
3619 // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
3620 //
3621 // The anonymous forms are allowed iff [default_export] is true.
3622 //
3623 // 'function' and '*' (if present) have been consumed by the caller.
3624
3625 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
3626 const bool is_async = flags & ParseFunctionFlags::kIsAsync;
3627 DCHECK(!is_generator || !is_async);
3628
3629 IdentifierT name;
3630 FunctionNameValidity name_validity;
3631 IdentifierT variable_name;
3632 if (default_export && peek() == Token::LPAREN) {
3633 impl()->GetDefaultStrings(&name, &variable_name);
3634 name_validity = kSkipFunctionNameCheck;
3635 } else {
3636 bool is_strict_reserved;
3637 name = ParseIdentifierOrStrictReservedWord(
3638 &is_strict_reserved, CHECK_OK_CUSTOM(GetEmptyStatement));
3639 name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved
3640 : kFunctionNameValidityUnknown;
3641 variable_name = name;
3642 }
3643
3644 FuncNameInferrer::State fni_state(fni_);
3645 impl()->PushEnclosingName(name);
3646 FunctionLiteralT function = impl()->ParseFunctionLiteral(
3647 name, scanner()->location(), name_validity,
3648 is_generator ? FunctionKind::kGeneratorFunction
3649 : is_async ? FunctionKind::kAsyncFunction
3650 : FunctionKind::kNormalFunction,
3651 pos, FunctionLiteral::kDeclaration, language_mode(),
3652 CHECK_OK_CUSTOM(GetEmptyStatement));
3653
3654 return impl()->DeclareFunction(variable_name, function, pos, is_generator,
3655 is_async, names, ok);
3656 }
3657
3658 template <typename Impl>
3592 void ParserBase<Impl>::CheckArityRestrictions(int param_count, 3659 void ParserBase<Impl>::CheckArityRestrictions(int param_count,
3593 FunctionKind function_kind, 3660 FunctionKind function_kind,
3594 bool has_rest, 3661 bool has_rest,
3595 int formals_start_pos, 3662 int formals_start_pos,
3596 int formals_end_pos, bool* ok) { 3663 int formals_end_pos, bool* ok) {
3597 if (IsGetterFunction(function_kind)) { 3664 if (IsGetterFunction(function_kind)) {
3598 if (param_count != 0) { 3665 if (param_count != 0) {
3599 impl()->ReportMessageAt( 3666 impl()->ReportMessageAt(
3600 Scanner::Location(formals_start_pos, formals_end_pos), 3667 Scanner::Location(formals_start_pos, formals_end_pos),
3601 MessageTemplate::kBadGetterArity); 3668 MessageTemplate::kBadGetterArity);
(...skipping 657 matching lines...)
4259 has_seen_constructor_ = true; 4326 has_seen_constructor_ = true;
4260 return; 4327 return;
4261 } 4328 }
4262 } 4329 }
4263 4330
4264 4331
4265 } // namespace internal 4332 } // namespace internal
4266 } // namespace v8 4333 } // namespace v8
4267 4334
4268 #endif // V8_PARSING_PARSER_BASE_H 4335 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine