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

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

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 unified diff | Download patch
« src/parsing/preparser.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { 125 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) {
126 if (is_strict(language_mode()) || peek() != Token::FUNCTION || 126 if (is_strict(language_mode()) || peek() != Token::FUNCTION ||
127 (legacy && allow_harmony_restrictive_declarations())) { 127 (legacy && allow_harmony_restrictive_declarations())) {
128 return ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok); 128 return ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok);
129 } else { 129 } else {
130 BlockState block_state(&scope_state_); 130 BlockState block_state(&scope_state_);
131 return ParseFunctionDeclaration(ok); 131 return ParseFunctionDeclaration(ok);
132 } 132 }
133 } 133 }
134 134
135 PreParser::Statement PreParser::ParseHoistableDeclaration(
136 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names,
137 bool default_export, bool* ok) {
138 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator;
139 const bool is_async = flags & ParseFunctionFlags::kIsAsync;
140 DCHECK(!is_generator || !is_async);
141
142 bool is_strict_reserved = false;
143 Identifier name = ParseIdentifierOrStrictReservedWord(
144 &is_strict_reserved, CHECK_OK);
145
146 ParseFunctionLiteral(name, scanner()->location(),
147 is_strict_reserved ? kFunctionNameIsStrictReserved
148 : kFunctionNameValidityUnknown,
149 is_generator ? FunctionKind::kGeneratorFunction
150 : is_async ? FunctionKind::kAsyncFunction
151 : FunctionKind::kNormalFunction,
152 pos, FunctionLiteral::kDeclaration, language_mode(),
153 CHECK_OK);
154 return Statement::FunctionDeclaration();
155 }
156
157 PreParser::Statement PreParser::ParseAsyncFunctionDeclaration( 135 PreParser::Statement PreParser::ParseAsyncFunctionDeclaration(
158 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 136 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
159 // AsyncFunctionDeclaration :: 137 // AsyncFunctionDeclaration ::
160 // async [no LineTerminator here] function BindingIdentifier[Await] 138 // async [no LineTerminator here] function BindingIdentifier[Await]
161 // ( FormalParameters[Await] ) { AsyncFunctionBody } 139 // ( FormalParameters[Await] ) { AsyncFunctionBody }
162 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); 140 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
163 int pos = position(); 141 int pos = position();
164 Expect(Token::FUNCTION, CHECK_OK); 142 Expect(Token::FUNCTION, CHECK_OK);
165 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync; 143 ParseFunctionFlags flags = ParseFunctionFlags::kIsAsync;
166 return ParseHoistableDeclaration(pos, flags, names, default_export, ok); 144 return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
167 } 145 }
168 146
169 PreParser::Statement PreParser::ParseHoistableDeclaration(
170 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
171 // FunctionDeclaration ::
172 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
173 // GeneratorDeclaration ::
174 // 'function' '*' Identifier '(' FormalParameterListopt ')'
175 // '{' FunctionBody '}'
176
177 Expect(Token::FUNCTION, CHECK_OK);
178 int pos = position();
179 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
180 if (Check(Token::MUL)) {
181 flags |= ParseFunctionFlags::kIsGenerator;
182 }
183 return ParseHoistableDeclaration(pos, flags, names, default_export, ok);
184 }
185
186 PreParser::Statement PreParser::ParseClassDeclaration( 147 PreParser::Statement PreParser::ParseClassDeclaration(
187 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 148 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
188 int pos = position(); 149 int pos = position();
189 bool is_strict_reserved = false; 150 bool is_strict_reserved = false;
190 Identifier name = 151 Identifier name =
191 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 152 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
192 ExpressionClassifier no_classifier(this); 153 ExpressionClassifier no_classifier(this);
193 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, 154 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
194 CHECK_OK); 155 CHECK_OK);
195 return Statement::Default(); 156 return Statement::Default();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; 191 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
231 if (Check(Token::MUL)) { 192 if (Check(Token::MUL)) {
232 flags |= ParseFunctionFlags::kIsGenerator; 193 flags |= ParseFunctionFlags::kIsGenerator;
233 if (allow_harmony_restrictive_declarations()) { 194 if (allow_harmony_restrictive_declarations()) {
234 ReportMessageAt(scanner()->location(), 195 ReportMessageAt(scanner()->location(),
235 MessageTemplate::kGeneratorInLegacyContext); 196 MessageTemplate::kGeneratorInLegacyContext);
236 *ok = false; 197 *ok = false;
237 return Statement::Default(); 198 return Statement::Default();
238 } 199 }
239 } 200 }
201 // PreParser is not able to parse "export default" yet (since PreParser is
202 // at the moment only used for functions, and it cannot occur
203 // there). TODO(marja): update this when it is.
240 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok); 204 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
241 } 205 }
242 206
243 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( 207 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
244 ZoneList<const AstRawString*>* names, 208 ZoneList<const AstRawString*>* names,
245 AllowLabelledFunctionStatement allow_function, bool* ok) { 209 AllowLabelledFunctionStatement allow_function, bool* ok) {
246 // ExpressionStatement | LabelledStatement :: 210 // ExpressionStatement | LabelledStatement ::
247 // Expression ';' 211 // Expression ';'
248 // Identifier ':' Statement 212 // Identifier ':' Statement
249 213
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 878
915 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 879 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
916 } 880 }
917 881
918 #undef CHECK_OK 882 #undef CHECK_OK
919 #undef CHECK_OK_CUSTOM 883 #undef CHECK_OK_CUSTOM
920 884
921 885
922 } // namespace internal 886 } // namespace internal
923 } // namespace v8 887 } // namespace v8
OLDNEW
« src/parsing/preparser.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698