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

Unified 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. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index bdb2cad9c31162df670ea7c0cc0d7f2f8c7d99da..bdc2fcea7d3141193b936076607cdad590e49e07 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -1193,6 +1193,11 @@ class ParserBase {
DeclarationParsingResult* parsing_result,
ZoneList<const AstRawString*>* names,
bool* ok);
+ StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
+ bool default_export, bool* ok);
+ StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
+ ZoneList<const AstRawString*>* names,
+ bool default_export, bool* ok);
// Under some circumstances, we allow preparsing to abort if the preparsed
// function is "long and trivial", and fully parse instead. Our current
@@ -3589,6 +3594,68 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
}
template <typename Impl>
+typename ParserBase<Impl>::StatementT
+ParserBase<Impl>::ParseHoistableDeclaration(
+ ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
+ Expect(Token::FUNCTION, CHECK_OK_CUSTOM(GetEmptyStatement));
+ int pos = position();
+ ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
+ if (Check(Token::MUL)) {
+ flags |= ParseFunctionFlags::kIsGenerator;
+ }
+ return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
+}
+
+template <typename Impl>
+typename ParserBase<Impl>::StatementT
+ParserBase<Impl>::ParseHoistableDeclaration(
+ int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
+ bool default_export, bool* ok) {
+ // FunctionDeclaration ::
+ // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
+ // 'function' '(' FormalParameters ')' '{' FunctionBody '}'
+ // GeneratorDeclaration ::
+ // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
+ // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}'
+ //
+ // The anonymous forms are allowed iff [default_export] is true.
+ //
+ // 'function' and '*' (if present) have been consumed by the caller.
+
+ const bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
+ const bool is_async = flags & ParseFunctionFlags::kIsAsync;
+ DCHECK(!is_generator || !is_async);
+
+ IdentifierT name;
+ FunctionNameValidity name_validity;
+ IdentifierT variable_name;
+ if (default_export && peek() == Token::LPAREN) {
+ impl()->GetDefaultStrings(&name, &variable_name);
+ name_validity = kSkipFunctionNameCheck;
+ } else {
+ bool is_strict_reserved;
+ name = ParseIdentifierOrStrictReservedWord(
+ &is_strict_reserved, CHECK_OK_CUSTOM(GetEmptyStatement));
+ name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved
+ : kFunctionNameValidityUnknown;
+ variable_name = name;
+ }
+
+ FuncNameInferrer::State fni_state(fni_);
+ impl()->PushEnclosingName(name);
+ FunctionLiteralT function = impl()->ParseFunctionLiteral(
+ name, scanner()->location(), name_validity,
+ is_generator ? FunctionKind::kGeneratorFunction
+ : is_async ? FunctionKind::kAsyncFunction
+ : FunctionKind::kNormalFunction,
+ pos, FunctionLiteral::kDeclaration, language_mode(),
+ CHECK_OK_CUSTOM(GetEmptyStatement));
+
+ return impl()->DeclareFunction(variable_name, function, pos, is_generator,
+ is_async, names, ok);
+}
+
+template <typename Impl>
void ParserBase<Impl>::CheckArityRestrictions(int param_count,
FunctionKind function_kind,
bool has_rest,

Powered by Google App Engine
This is Rietveld 408576698