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

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

Issue 2324843005: [parser] Refactor of Parse*Statement*, part 6 (Closed)
Patch Set: Reorder methods 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
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/interpreter/bytecode_expectations/Switch.golden » ('j') | 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 *ok = false; 157 *ok = false;
158 return Statement::Default(); 158 return Statement::Default();
159 } 159 }
160 } 160 }
161 // PreParser is not able to parse "export default" yet (since PreParser is 161 // PreParser is not able to parse "export default" yet (since PreParser is
162 // at the moment only used for functions, and it cannot occur 162 // at the moment only used for functions, and it cannot occur
163 // there). TODO(marja): update this when it is. 163 // there). TODO(marja): update this when it is.
164 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok); 164 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
165 } 165 }
166 166
167 PreParser::Statement PreParser::ParseSwitchStatement(
168 ZoneList<const AstRawString*>* labels, bool* ok) {
169 // SwitchStatement ::
170 // 'switch' '(' Expression ')' '{' CaseClause* '}'
171
172 Expect(Token::SWITCH, CHECK_OK);
173 Expect(Token::LPAREN, CHECK_OK);
174 ParseExpression(true, CHECK_OK);
175 Expect(Token::RPAREN, CHECK_OK);
176
177 {
178 BlockState cases_block_state(&scope_state_);
179 Expect(Token::LBRACE, CHECK_OK);
180 Token::Value token = peek();
181 while (token != Token::RBRACE) {
182 if (token == Token::CASE) {
183 Expect(Token::CASE, CHECK_OK);
184 ParseExpression(true, CHECK_OK);
185 } else {
186 Expect(Token::DEFAULT, CHECK_OK);
187 }
188 Expect(Token::COLON, CHECK_OK);
189 token = peek();
190 Statement statement = Statement::Jump();
191 while (token != Token::CASE &&
192 token != Token::DEFAULT &&
193 token != Token::RBRACE) {
194 statement = ParseStatementListItem(CHECK_OK);
195 token = peek();
196 }
197 }
198 }
199 Expect(Token::RBRACE, ok);
200 return Statement::Default();
201 }
202
203 PreParser::Statement PreParser::ParseForStatement( 167 PreParser::Statement PreParser::ParseForStatement(
204 ZoneList<const AstRawString*>* labels, bool* ok) { 168 ZoneList<const AstRawString*>* labels, bool* ok) {
205 // ForStatement :: 169 // ForStatement ::
206 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 170 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
207 171
208 // Create an in-between scope for let-bound iteration variables. 172 // Create an in-between scope for let-bound iteration variables.
209 bool has_lexical = false; 173 bool has_lexical = false;
210 174
211 BlockState block_state(&scope_state_); 175 BlockState block_state(&scope_state_);
212 Expect(Token::FOR, CHECK_OK); 176 Expect(Token::FOR, CHECK_OK);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 539
576 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); 540 body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
577 } 541 }
578 542
579 #undef CHECK_OK 543 #undef CHECK_OK
580 #undef CHECK_OK_CUSTOM 544 #undef CHECK_OK_CUSTOM
581 545
582 546
583 } // namespace internal 547 } // namespace internal
584 } // namespace v8 548 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/interpreter/bytecode_expectations/Switch.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698