Chromium Code Reviews| 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/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 // }; | 75 // }; |
| 76 // // ... | 76 // // ... |
| 77 // }; | 77 // }; |
| 78 | 78 |
| 79 template <typename Traits> | 79 template <typename Traits> |
| 80 class ParserBase : public Traits { | 80 class ParserBase : public Traits { |
| 81 public: | 81 public: |
| 82 // Shorten type names defined by Traits. | 82 // Shorten type names defined by Traits. |
| 83 typedef typename Traits::Type::Expression ExpressionT; | 83 typedef typename Traits::Type::Expression ExpressionT; |
| 84 typedef typename Traits::Type::Identifier IdentifierT; | 84 typedef typename Traits::Type::Identifier IdentifierT; |
| 85 typedef typename Traits::Type::IdentifierList IdentifierListT; | |
| 85 typedef typename Traits::Type::FormalParameter FormalParameterT; | 86 typedef typename Traits::Type::FormalParameter FormalParameterT; |
| 86 typedef typename Traits::Type::FormalParameters FormalParametersT; | 87 typedef typename Traits::Type::FormalParameters FormalParametersT; |
| 87 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 88 typedef typename Traits::Type::Literal LiteralT; | 89 typedef typename Traits::Type::Literal LiteralT; |
| 89 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 90 typedef typename Traits::Type::StatementList StatementListT; | 91 typedef typename Traits::Type::StatementList StatementListT; |
| 91 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; | 92 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; |
| 92 typedef typename Traits::Type::TypeSystem TypeSystem; | 93 typedef typename Traits::Type::TypeSystem TypeSystem; |
| 93 | 94 |
| 94 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 95 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 | 836 |
| 836 // Parsing optional types. | 837 // Parsing optional types. |
| 837 typename TypeSystem::Type ParseValidType(bool* ok); | 838 typename TypeSystem::Type ParseValidType(bool* ok); |
| 838 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok); | 839 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok); |
| 839 typename TypeSystem::Type ParseType(bool* ok); | 840 typename TypeSystem::Type ParseType(bool* ok); |
| 840 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok); | 841 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok); |
| 841 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok); | 842 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok); |
| 842 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok); | 843 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok); |
| 843 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok); | 844 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok); |
| 844 typename TypeSystem::TypeArguments ParseTypeArguments(bool* ok); | 845 typename TypeSystem::TypeArguments ParseTypeArguments(bool* ok); |
| 846 IdentifierListT ParsePropertyNameList(bool* ok); | |
| 845 | 847 |
| 846 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type, | 848 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type, |
| 847 Scanner::Location location, bool* ok) { | 849 Scanner::Location location, bool* ok) { |
| 848 typename TypeSystem::Type result = type->Uncover(ok); | 850 typename TypeSystem::Type result = type->Uncover(ok); |
| 849 if (*ok) { | 851 if (*ok) { |
| 850 if (!result->IsStringLiteralType()) return result; | 852 if (!result->IsStringLiteralType()) return result; |
| 851 *ok = false; | 853 *ok = false; |
| 852 } | 854 } |
| 853 ReportMessageAt(location, MessageTemplate::kInvalidType); | 855 ReportMessageAt(location, MessageTemplate::kInvalidType); |
| 854 return type; | 856 return type; |
| (...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3281 } else if (CheckContextualKeyword(CStrVector("number"))) { | 3283 } else if (CheckContextualKeyword(CStrVector("number"))) { |
| 3282 type = factory()->NewPredefinedType( | 3284 type = factory()->NewPredefinedType( |
| 3283 typesystem::PredefinedType::kNumberType, pos); | 3285 typesystem::PredefinedType::kNumberType, pos); |
| 3284 } else if (CheckContextualKeyword(CStrVector("string"))) { | 3286 } else if (CheckContextualKeyword(CStrVector("string"))) { |
| 3285 type = factory()->NewPredefinedType( | 3287 type = factory()->NewPredefinedType( |
| 3286 typesystem::PredefinedType::kStringType, pos); | 3288 typesystem::PredefinedType::kStringType, pos); |
| 3287 } else if (CheckContextualKeyword(CStrVector("symbol"))) { | 3289 } else if (CheckContextualKeyword(CStrVector("symbol"))) { |
| 3288 type = factory()->NewPredefinedType( | 3290 type = factory()->NewPredefinedType( |
| 3289 typesystem::PredefinedType::kSymbolType, pos); | 3291 typesystem::PredefinedType::kSymbolType, pos); |
| 3290 } else { | 3292 } else { |
| 3291 // TODO(nikolaos): Missing typeof. | |
| 3292 IdentifierT name = ParseIdentifierName(CHECK_OK_TYPE); | 3293 IdentifierT name = ParseIdentifierName(CHECK_OK_TYPE); |
| 3293 typename TypeSystem::TypeArguments type_arguments = | 3294 typename TypeSystem::TypeArguments type_arguments = |
| 3294 this->NullTypeArguments(); | 3295 this->NullTypeArguments(); |
| 3295 if (peek() == Token::LT) { // Braces required here. | 3296 if (peek() == Token::LT) { // Braces required here. |
| 3296 type_arguments = ParseTypeArguments(CHECK_OK_TYPE); | 3297 type_arguments = ParseTypeArguments(CHECK_OK_TYPE); |
| 3297 } | 3298 } |
| 3298 type = factory()->NewTypeReference(name, type_arguments, pos); | 3299 type = factory()->NewTypeReference(name, type_arguments, pos); |
| 3299 } | 3300 } |
| 3300 break; | 3301 break; |
| 3301 } | 3302 } |
| 3303 case Token::TYPEOF: { | |
| 3304 Consume(Token::TYPEOF); | |
| 3305 IdentifierT name = ParseIdentifierName(CHECK_OK_TYPE); | |
| 3306 IdentifierListT property_names = this->NullIdentifierList(); | |
| 3307 if (peek() == Token::PERIOD) { // Braces required here. | |
| 3308 property_names = ParsePropertyNameList(CHECK_OK_TYPE); | |
| 3309 } | |
| 3310 type = factory()->NewQueryType(name, property_names, pos); | |
| 3311 break; | |
| 3312 } | |
| 3302 case Token::VOID: { | 3313 case Token::VOID: { |
| 3303 Consume(Token::VOID); | 3314 Consume(Token::VOID); |
| 3304 type = factory()->NewPredefinedType(typesystem::PredefinedType::kVoidType, | 3315 type = factory()->NewPredefinedType(typesystem::PredefinedType::kVoidType, |
| 3305 pos); | 3316 pos); |
| 3306 break; | 3317 break; |
| 3307 } | 3318 } |
| 3308 case Token::THIS: { | 3319 case Token::THIS: { |
| 3309 Consume(Token::THIS); | 3320 Consume(Token::THIS); |
| 3310 type = factory()->NewThisType(pos); | 3321 type = factory()->NewThisType(pos); |
| 3311 break; | 3322 break; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 3331 while (Check(Token::LBRACK)) { // Braces required here | 3342 while (Check(Token::LBRACK)) { // Braces required here |
| 3332 Expect(Token::RBRACK, CHECK_OK_TYPE); | 3343 Expect(Token::RBRACK, CHECK_OK_TYPE); |
| 3333 type = factory()->NewArrayType(type, pos); | 3344 type = factory()->NewArrayType(type, pos); |
| 3334 } | 3345 } |
| 3335 } | 3346 } |
| 3336 | 3347 |
| 3337 return type; | 3348 return type; |
| 3338 } | 3349 } |
| 3339 | 3350 |
| 3340 | 3351 |
| 3352 template <typename Traits> | |
| 3353 typename ParserBase<Traits>::IdentifierListT | |
|
rossberg
2016/03/17 12:34:09
Doesn't make much sense to allow identifier lists
rossberg
2016/03/17 12:37:17
Ah sorry, I was confused. Disregard that comment.
| |
| 3354 ParserBase<Traits>::ParsePropertyNameList(bool* ok) { | |
| 3355 Expect(Token::PERIOD, CHECK_OK_CUSTOM(NullIdentifierList)); | |
| 3356 IdentifierListT property_names = this->EmptyIdentifierList(); | |
| 3357 do { | |
| 3358 IdentifierT property_name = | |
| 3359 ParseIdentifierName(CHECK_OK_CUSTOM(NullIdentifierList)); | |
| 3360 property_names->Add(property_name, zone()); | |
| 3361 } while (Check(Token::PERIOD)); | |
| 3362 return property_names; | |
| 3363 } | |
| 3364 | |
| 3365 | |
| 3341 #undef CHECK_OK | 3366 #undef CHECK_OK |
| 3342 #undef CHECK_OK_CUSTOM | 3367 #undef CHECK_OK_CUSTOM |
| 3343 #undef CHECK_OK_TYPE | 3368 #undef CHECK_OK_TYPE |
| 3344 | 3369 |
| 3345 | 3370 |
| 3346 template <typename Traits> | 3371 template <typename Traits> |
| 3347 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3372 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| 3348 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3373 Token::Value property, PropertyKind type, bool is_static, bool is_generator, |
| 3349 bool* ok) { | 3374 bool* ok) { |
| 3350 DCHECK(!is_static); | 3375 DCHECK(!is_static); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3395 has_seen_constructor_ = true; | 3420 has_seen_constructor_ = true; |
| 3396 return; | 3421 return; |
| 3397 } | 3422 } |
| 3398 } | 3423 } |
| 3399 | 3424 |
| 3400 | 3425 |
| 3401 } // namespace internal | 3426 } // namespace internal |
| 3402 } // namespace v8 | 3427 } // namespace v8 |
| 3403 | 3428 |
| 3404 #endif // V8_PARSING_PARSER_BASE_H | 3429 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |