| 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_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
| 6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/compiler.h" // For CachedDataMode | 10 #include "src/compiler.h" // For CachedDataMode |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // TODO(marja): To be removed. The Traits object should contain all the data | 357 // TODO(marja): To be removed. The Traits object should contain all the data |
| 358 // it needs. | 358 // it needs. |
| 359 typedef v8::internal::Parser* Parser; | 359 typedef v8::internal::Parser* Parser; |
| 360 | 360 |
| 361 typedef Variable GeneratorVariable; | 361 typedef Variable GeneratorVariable; |
| 362 | 362 |
| 363 typedef v8::internal::AstProperties AstProperties; | 363 typedef v8::internal::AstProperties AstProperties; |
| 364 typedef Vector<VariableProxy*> ParameterIdentifierVector; | 364 typedef Vector<VariableProxy*> ParameterIdentifierVector; |
| 365 | 365 |
| 366 // Return types for traversing functions. | 366 // Return types for traversing functions. |
| 367 typedef const AstRawString* Identifier; | |
| 368 typedef v8::internal::Expression* Expression; | 367 typedef v8::internal::Expression* Expression; |
| 369 typedef Yield* YieldExpression; | 368 typedef Yield* YieldExpression; |
| 370 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 369 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 371 typedef v8::internal::ClassLiteral* ClassLiteral; | 370 typedef v8::internal::ClassLiteral* ClassLiteral; |
| 372 typedef v8::internal::Literal* Literal; | 371 typedef v8::internal::Literal* Literal; |
| 373 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 372 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 374 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 373 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 375 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 374 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 376 typedef ZoneList<v8::internal::Statement*>* StatementList; | 375 typedef ZoneList<v8::internal::Statement*>* StatementList; |
| 377 | 376 |
| 378 // For constructing objects returned by the traversing functions. | 377 // For constructing objects returned by the traversing functions. |
| 379 typedef AstNodeFactory Factory; | 378 typedef AstNodeFactory Factory; |
| 380 }; | 379 }; |
| 381 | 380 |
| 382 explicit ParserTraits(Parser* parser) : parser_(parser) {} | 381 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
| 383 | 382 |
| 384 // Helper functions for recursive descent. | 383 // Helper functions for recursive descent. |
| 385 bool IsEvalOrArguments(const AstRawString* identifier) const; | |
| 386 V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; | |
| 387 | 384 |
| 388 // Returns true if the expression is of type "this.foo". | 385 // Returns true if the expression is of type "this.foo". |
| 389 static bool IsThisProperty(Expression* expression); | 386 static bool IsThisProperty(Expression* expression); |
| 390 | 387 |
| 391 static bool IsIdentifier(Expression* expression); | 388 static bool IsIdentifier(Expression* expression); |
| 392 | 389 |
| 393 bool IsPrototype(const AstRawString* identifier) const; | 390 bool IsPrototype(const AstRawString* identifier) const; |
| 394 | 391 |
| 395 bool IsConstructor(const AstRawString* identifier) const; | 392 bool IsConstructor(const AstRawString* identifier) const; |
| 396 | 393 |
| 397 static const AstRawString* AsIdentifier(Expression* expression) { | 394 static const AstRawString* AsIdentifier(Expression* expression) { |
| 398 DCHECK(IsIdentifier(expression)); | 395 DCHECK(IsIdentifier(expression)); |
| 399 return expression->AsVariableProxy()->raw_name(); | 396 return expression->AsVariableProxy()->raw_name(); |
| 400 } | 397 } |
| 401 | 398 |
| 402 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 399 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
| 403 return ObjectLiteral::IsBoilerplateProperty(property); | 400 return ObjectLiteral::IsBoilerplateProperty(property); |
| 404 } | 401 } |
| 405 | 402 |
| 406 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { | |
| 407 return string->AsArrayIndex(index); | |
| 408 } | |
| 409 | |
| 410 static Expression* GetPropertyValue(ObjectLiteral::Property* property) { | 403 static Expression* GetPropertyValue(ObjectLiteral::Property* property) { |
| 411 return property->value(); | 404 return property->value(); |
| 412 } | 405 } |
| 413 | 406 |
| 414 // Functions for encapsulating the differences between parsing and preparsing; | 407 // Functions for encapsulating the differences between parsing and preparsing; |
| 415 // operations interleaved with the recursive descent. | 408 // operations interleaved with the recursive descent. |
| 416 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) { | 409 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) { |
| 417 fni->PushLiteralName(id); | 410 fni->PushLiteralName(id); |
| 418 } | 411 } |
| 419 | 412 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 bool is_reference_error = false); | 491 bool is_reference_error = false); |
| 499 void ReportMessage(const char* message, | 492 void ReportMessage(const char* message, |
| 500 const AstRawString* arg, | 493 const AstRawString* arg, |
| 501 bool is_reference_error = false); | 494 bool is_reference_error = false); |
| 502 void ReportMessageAt(Scanner::Location source_location, | 495 void ReportMessageAt(Scanner::Location source_location, |
| 503 const char* message, | 496 const char* message, |
| 504 const AstRawString* arg, | 497 const AstRawString* arg, |
| 505 bool is_reference_error = false); | 498 bool is_reference_error = false); |
| 506 | 499 |
| 507 // "null" return type creators. | 500 // "null" return type creators. |
| 508 static const AstRawString* EmptyIdentifier() { | |
| 509 return NULL; | |
| 510 } | |
| 511 static Expression* EmptyExpression() { | 501 static Expression* EmptyExpression() { |
| 512 return NULL; | 502 return NULL; |
| 513 } | 503 } |
| 514 static Expression* EmptyArrowParamList() { return NULL; } | 504 static Expression* EmptyArrowParamList() { return NULL; } |
| 515 static Literal* EmptyLiteral() { | 505 static Literal* EmptyLiteral() { |
| 516 return NULL; | 506 return NULL; |
| 517 } | 507 } |
| 518 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; } | 508 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; } |
| 519 static FunctionLiteral* EmptyFunctionLiteral() { return NULL; } | 509 static FunctionLiteral* EmptyFunctionLiteral() { return NULL; } |
| 520 | 510 |
| 521 // Used in error return values. | 511 // Used in error return values. |
| 522 static ZoneList<Expression*>* NullExpressionList() { | 512 static ZoneList<Expression*>* NullExpressionList() { |
| 523 return NULL; | 513 return NULL; |
| 524 } | 514 } |
| 525 | 515 |
| 526 // Non-NULL empty string. | |
| 527 V8_INLINE const AstRawString* EmptyIdentifierString(); | |
| 528 | |
| 529 // Odd-ball literal creators. | 516 // Odd-ball literal creators. |
| 530 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); | 517 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); |
| 531 | 518 |
| 532 // Producing data during the recursive descent. | 519 // Producing data during the recursive descent. |
| 533 const AstRawString* GetSymbol(Scanner* scanner); | |
| 534 const AstRawString* GetNextSymbol(Scanner* scanner); | |
| 535 const AstRawString* GetNumberAsSymbol(Scanner* scanner); | |
| 536 | |
| 537 Expression* ThisExpression(Scope* scope, AstNodeFactory* factory, | 520 Expression* ThisExpression(Scope* scope, AstNodeFactory* factory, |
| 538 int pos = RelocInfo::kNoPosition); | 521 int pos = RelocInfo::kNoPosition); |
| 539 Expression* SuperReference(Scope* scope, AstNodeFactory* factory, | 522 Expression* SuperReference(Scope* scope, AstNodeFactory* factory, |
| 540 int pos = RelocInfo::kNoPosition); | 523 int pos = RelocInfo::kNoPosition); |
| 541 Expression* DefaultConstructor(bool call_super, Scope* scope, int pos, | 524 Expression* DefaultConstructor(bool call_super, Scope* scope, int pos, |
| 542 int end_pos); | 525 int end_pos); |
| 543 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, | 526 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, |
| 544 AstNodeFactory* factory); | 527 AstNodeFactory* factory); |
| 545 Expression* ExpressionFromIdentifier(const AstRawString* name, int pos, | 528 Expression* ExpressionFromIdentifier(const AstRawString* name, int pos, |
| 546 Scope* scope, AstNodeFactory* factory); | 529 Scope* scope, AstNodeFactory* factory); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 bool pending_error_is_reference_error_; | 852 bool pending_error_is_reference_error_; |
| 870 | 853 |
| 871 // Other information which will be stored in Parser and moved to Isolate after | 854 // Other information which will be stored in Parser and moved to Isolate after |
| 872 // parsing. | 855 // parsing. |
| 873 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 856 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 874 int total_preparse_skipped_; | 857 int total_preparse_skipped_; |
| 875 HistogramTimer* pre_parse_timer_; | 858 HistogramTimer* pre_parse_timer_; |
| 876 }; | 859 }; |
| 877 | 860 |
| 878 | 861 |
| 879 bool ParserTraits::IsFutureStrictReserved( | |
| 880 const AstRawString* identifier) const { | |
| 881 return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); | |
| 882 } | |
| 883 | |
| 884 | |
| 885 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type, | 862 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type, |
| 886 FunctionKind kind) { | 863 FunctionKind kind) { |
| 887 return parser_->NewScope(parent_scope, scope_type, kind); | 864 return parser_->NewScope(parent_scope, scope_type, kind); |
| 888 } | 865 } |
| 889 | 866 |
| 890 | 867 |
| 891 const AstRawString* ParserTraits::EmptyIdentifierString() { | |
| 892 return parser_->ast_value_factory()->empty_string(); | |
| 893 } | |
| 894 | |
| 895 | |
| 896 void ParserTraits::SkipLazyFunctionBody(const AstRawString* function_name, | 868 void ParserTraits::SkipLazyFunctionBody(const AstRawString* function_name, |
| 897 int* materialized_literal_count, | 869 int* materialized_literal_count, |
| 898 int* expected_property_count, | 870 int* expected_property_count, |
| 899 bool* ok) { | 871 bool* ok) { |
| 900 return parser_->SkipLazyFunctionBody( | 872 return parser_->SkipLazyFunctionBody( |
| 901 function_name, materialized_literal_count, expected_property_count, ok); | 873 function_name, materialized_literal_count, expected_property_count, ok); |
| 902 } | 874 } |
| 903 | 875 |
| 904 | 876 |
| 905 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( | 877 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 } | 932 } |
| 961 | 933 |
| 962 | 934 |
| 963 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, | 935 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, |
| 964 int start, Expression* tag) { | 936 int start, Expression* tag) { |
| 965 return parser_->CloseTemplateLiteral(state, start, tag); | 937 return parser_->CloseTemplateLiteral(state, start, tag); |
| 966 } | 938 } |
| 967 } } // namespace v8::internal | 939 } } // namespace v8::internal |
| 968 | 940 |
| 969 #endif // V8_PARSER_H_ | 941 #endif // V8_PARSER_H_ |
| OLD | NEW |