OLD | NEW |
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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 DCHECK_EQ(result, kLazyParsingComplete); | 1212 DCHECK_EQ(result, kLazyParsingComplete); |
1213 } | 1213 } |
1214 LazyParsingResult ParseStatementList(StatementListT body, int end_token, | 1214 LazyParsingResult ParseStatementList(StatementListT body, int end_token, |
1215 bool may_abort, bool* ok); | 1215 bool may_abort, bool* ok); |
1216 StatementT ParseStatementListItem(bool* ok); | 1216 StatementT ParseStatementListItem(bool* ok); |
1217 StatementT ParseStatement(ZoneList<const AstRawString*>* labels, | 1217 StatementT ParseStatement(ZoneList<const AstRawString*>* labels, |
1218 AllowLabelledFunctionStatement allow_function, | 1218 AllowLabelledFunctionStatement allow_function, |
1219 bool* ok); | 1219 bool* ok); |
1220 StatementT ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels, | 1220 StatementT ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels, |
1221 bool* ok); | 1221 bool* ok); |
| 1222 BlockT ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); |
1222 | 1223 |
1223 bool IsNextLetKeyword(); | 1224 bool IsNextLetKeyword(); |
1224 bool IsTrivialExpression(); | 1225 bool IsTrivialExpression(); |
1225 | 1226 |
1226 // Checks if the expression is a valid reference expression (e.g., on the | 1227 // Checks if the expression is a valid reference expression (e.g., on the |
1227 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 1228 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
1228 // we allow calls for web compatibility and rewrite them to a runtime throw. | 1229 // we allow calls for web compatibility and rewrite them to a runtime throw. |
1229 ExpressionT CheckAndRewriteReferenceExpression( | 1230 ExpressionT CheckAndRewriteReferenceExpression( |
1230 ExpressionT expression, int beg_pos, int end_pos, | 1231 ExpressionT expression, int beg_pos, int end_pos, |
1231 MessageTemplate::Template message, bool* ok); | 1232 MessageTemplate::Template message, bool* ok); |
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4194 case Token::THROW: | 4195 case Token::THROW: |
4195 return impl()->ParseThrowStatement(ok); | 4196 return impl()->ParseThrowStatement(ok); |
4196 case Token::TRY: | 4197 case Token::TRY: |
4197 return impl()->ParseTryStatement(ok); | 4198 return impl()->ParseTryStatement(ok); |
4198 default: | 4199 default: |
4199 UNREACHABLE(); | 4200 UNREACHABLE(); |
4200 return impl()->NullStatement(); | 4201 return impl()->NullStatement(); |
4201 } | 4202 } |
4202 } | 4203 } |
4203 | 4204 |
| 4205 template <typename Impl> |
| 4206 typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock( |
| 4207 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 4208 // Block :: |
| 4209 // '{' StatementList '}' |
| 4210 |
| 4211 // Construct block expecting 16 statements. |
| 4212 BlockT body = factory()->NewBlock(labels, 16, false, kNoSourcePosition); |
| 4213 |
| 4214 // Parse the statements and collect escaping labels. |
| 4215 Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullBlock)); |
| 4216 { |
| 4217 BlockState block_state(&scope_state_); |
| 4218 block_state.set_start_position(scanner()->location().beg_pos); |
| 4219 typename Types::Target target(this, body); |
| 4220 |
| 4221 while (peek() != Token::RBRACE) { |
| 4222 StatementT stat = ParseStatementListItem(CHECK_OK_CUSTOM(NullBlock)); |
| 4223 if (!impl()->IsNullOrEmptyStatement(stat)) { |
| 4224 body->statements()->Add(stat, zone()); |
| 4225 } |
| 4226 } |
| 4227 |
| 4228 Expect(Token::RBRACE, CHECK_OK_CUSTOM(NullBlock)); |
| 4229 block_state.set_end_position(scanner()->location().end_pos); |
| 4230 body->set_scope(block_state.FinalizedBlockScope()); |
| 4231 } |
| 4232 return body; |
| 4233 } |
| 4234 |
4204 #undef CHECK_OK | 4235 #undef CHECK_OK |
4205 #undef CHECK_OK_CUSTOM | 4236 #undef CHECK_OK_CUSTOM |
4206 | 4237 |
4207 template <typename Impl> | 4238 template <typename Impl> |
4208 void ParserBase<Impl>::ObjectLiteralChecker::CheckProperty( | 4239 void ParserBase<Impl>::ObjectLiteralChecker::CheckProperty( |
4209 Token::Value property, PropertyKind type, MethodKind method_type, | 4240 Token::Value property, PropertyKind type, MethodKind method_type, |
4210 bool* ok) { | 4241 bool* ok) { |
4211 DCHECK(!IsStaticMethod(method_type)); | 4242 DCHECK(!IsStaticMethod(method_type)); |
4212 DCHECK(!IsSpecialMethod(method_type) || | 4243 DCHECK(!IsSpecialMethod(method_type) || |
4213 type == PropertyKind::kMethodProperty); | 4244 type == PropertyKind::kMethodProperty); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4259 has_seen_constructor_ = true; | 4290 has_seen_constructor_ = true; |
4260 return; | 4291 return; |
4261 } | 4292 } |
4262 } | 4293 } |
4263 | 4294 |
4264 | 4295 |
4265 } // namespace internal | 4296 } // namespace internal |
4266 } // namespace v8 | 4297 } // namespace v8 |
4267 | 4298 |
4268 #endif // V8_PARSING_PARSER_BASE_H | 4299 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |