| 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_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser-base.h" | 9 #include "src/parsing/parser-base.h" |
| 10 | 10 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 class PreParserStatement { | 386 class PreParserStatement { |
| 387 public: | 387 public: |
| 388 static PreParserStatement Default() { | 388 static PreParserStatement Default() { |
| 389 return PreParserStatement(kUnknownStatement); | 389 return PreParserStatement(kUnknownStatement); |
| 390 } | 390 } |
| 391 | 391 |
| 392 static PreParserStatement Jump() { | 392 static PreParserStatement Jump() { |
| 393 return PreParserStatement(kJumpStatement); | 393 return PreParserStatement(kJumpStatement); |
| 394 } | 394 } |
| 395 | 395 |
| 396 static PreParserStatement FunctionDeclaration() { | |
| 397 return PreParserStatement(kFunctionDeclaration); | |
| 398 } | |
| 399 | |
| 400 // Creates expression statement from expression. | 396 // Creates expression statement from expression. |
| 401 // Preserves being an unparenthesized string literal, possibly | 397 // Preserves being an unparenthesized string literal, possibly |
| 402 // "use strict". | 398 // "use strict". |
| 403 static PreParserStatement ExpressionStatement( | 399 static PreParserStatement ExpressionStatement( |
| 404 PreParserExpression expression) { | 400 PreParserExpression expression) { |
| 405 if (expression.IsUseStrictLiteral()) { | 401 if (expression.IsUseStrictLiteral()) { |
| 406 return PreParserStatement(kUseStrictExpressionStatement); | 402 return PreParserStatement(kUseStrictExpressionStatement); |
| 407 } | 403 } |
| 408 if (expression.IsUseAsmLiteral()) { | 404 if (expression.IsUseAsmLiteral()) { |
| 409 return PreParserStatement(kUseAsmExpressionStatement); | 405 return PreParserStatement(kUseAsmExpressionStatement); |
| 410 } | 406 } |
| 411 if (expression.IsStringLiteral()) { | 407 if (expression.IsStringLiteral()) { |
| 412 return PreParserStatement(kStringLiteralExpressionStatement); | 408 return PreParserStatement(kStringLiteralExpressionStatement); |
| 413 } | 409 } |
| 414 return Default(); | 410 return Default(); |
| 415 } | 411 } |
| 416 | 412 |
| 417 bool IsStringLiteral() { | 413 bool IsStringLiteral() { |
| 418 return code_ == kStringLiteralExpressionStatement || IsUseStrictLiteral() || | 414 return code_ == kStringLiteralExpressionStatement || IsUseStrictLiteral() || |
| 419 IsUseAsmLiteral(); | 415 IsUseAsmLiteral(); |
| 420 } | 416 } |
| 421 | 417 |
| 422 bool IsUseStrictLiteral() { | 418 bool IsUseStrictLiteral() { |
| 423 return code_ == kUseStrictExpressionStatement; | 419 return code_ == kUseStrictExpressionStatement; |
| 424 } | 420 } |
| 425 | 421 |
| 426 bool IsUseAsmLiteral() { return code_ == kUseAsmExpressionStatement; } | 422 bool IsUseAsmLiteral() { return code_ == kUseAsmExpressionStatement; } |
| 427 | 423 |
| 428 bool IsFunctionDeclaration() { | |
| 429 return code_ == kFunctionDeclaration; | |
| 430 } | |
| 431 | |
| 432 bool IsJumpStatement() { | 424 bool IsJumpStatement() { |
| 433 return code_ == kJumpStatement; | 425 return code_ == kJumpStatement; |
| 434 } | 426 } |
| 435 | 427 |
| 436 // Dummy implementation for making statement->somefunc() work in both Parser | 428 // Dummy implementation for making statement->somefunc() work in both Parser |
| 437 // and PreParser. | 429 // and PreParser. |
| 438 PreParserStatement* operator->() { return this; } | 430 PreParserStatement* operator->() { return this; } |
| 439 | 431 |
| 440 PreParserStatementList statements() { return PreParserStatementList(); } | 432 PreParserStatementList statements() { return PreParserStatementList(); } |
| 441 void set_scope(Scope* scope) {} | 433 void set_scope(Scope* scope) {} |
| 442 | 434 |
| 443 private: | 435 private: |
| 444 enum Type { | 436 enum Type { |
| 445 kUnknownStatement, | 437 kUnknownStatement, |
| 446 kJumpStatement, | 438 kJumpStatement, |
| 447 kStringLiteralExpressionStatement, | 439 kStringLiteralExpressionStatement, |
| 448 kUseStrictExpressionStatement, | 440 kUseStrictExpressionStatement, |
| 449 kUseAsmExpressionStatement, | 441 kUseAsmExpressionStatement, |
| 450 kFunctionDeclaration | |
| 451 }; | 442 }; |
| 452 | 443 |
| 453 explicit PreParserStatement(Type code) : code_(code) {} | 444 explicit PreParserStatement(Type code) : code_(code) {} |
| 454 Type code_; | 445 Type code_; |
| 455 }; | 446 }; |
| 456 | 447 |
| 457 | 448 |
| 458 class PreParserFactory { | 449 class PreParserFactory { |
| 459 public: | 450 public: |
| 460 explicit PreParserFactory(void* unused_value_factory) {} | 451 explicit PreParserFactory(void* unused_value_factory) {} |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 private: | 748 private: |
| 758 // These types form an algebra over syntactic categories that is just | 749 // These types form an algebra over syntactic categories that is just |
| 759 // rich enough to let us recognize and propagate the constructs that | 750 // rich enough to let us recognize and propagate the constructs that |
| 760 // are either being counted in the preparser data, or is important | 751 // are either being counted in the preparser data, or is important |
| 761 // to throw the correct syntax error exceptions. | 752 // to throw the correct syntax error exceptions. |
| 762 | 753 |
| 763 // All ParseXXX functions take as the last argument an *ok parameter | 754 // All ParseXXX functions take as the last argument an *ok parameter |
| 764 // which is set to false if parsing failed; it is unchanged otherwise. | 755 // which is set to false if parsing failed; it is unchanged otherwise. |
| 765 // By making the 'exception handling' explicit, we are forced to check | 756 // By making the 'exception handling' explicit, we are forced to check |
| 766 // for failure at the call sites. | 757 // for failure at the call sites. |
| 767 Statement ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | |
| 768 bool default_export, bool* ok); | |
| 769 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | |
| 770 ZoneList<const AstRawString*>* names, | |
| 771 bool default_export, bool* ok); | |
| 772 Statement ParseFunctionDeclaration(bool* ok); | 758 Statement ParseFunctionDeclaration(bool* ok); |
| 773 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 759 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
| 774 bool default_export, bool* ok); | 760 bool default_export, bool* ok); |
| 775 Expression ParseAsyncFunctionExpression(bool* ok); | 761 Expression ParseAsyncFunctionExpression(bool* ok); |
| 776 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 762 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 777 bool default_export, bool* ok); | 763 bool default_export, bool* ok); |
| 778 Statement ParseExpressionOrLabelledStatement( | 764 Statement ParseExpressionOrLabelledStatement( |
| 779 ZoneList<const AstRawString*>* names, | 765 ZoneList<const AstRawString*>* names, |
| 780 AllowLabelledFunctionStatement allow_function, bool* ok); | 766 AllowLabelledFunctionStatement allow_function, bool* ok); |
| 781 Statement ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 767 Statement ParseIfStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 return PreParserExpression::Default(); | 864 return PreParserExpression::Default(); |
| 879 } | 865 } |
| 880 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } | 866 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
| 881 | 867 |
| 882 V8_INLINE void DeclareAndInitializeVariables( | 868 V8_INLINE void DeclareAndInitializeVariables( |
| 883 PreParserStatement block, | 869 PreParserStatement block, |
| 884 const DeclarationDescriptor* declaration_descriptor, | 870 const DeclarationDescriptor* declaration_descriptor, |
| 885 const DeclarationParsingResult::Declaration* declaration, | 871 const DeclarationParsingResult::Declaration* declaration, |
| 886 ZoneList<const AstRawString*>* names, bool* ok) {} | 872 ZoneList<const AstRawString*>* names, bool* ok) {} |
| 887 | 873 |
| 874 V8_INLINE PreParserStatement DeclareFunction( |
| 875 PreParserIdentifier variable_name, PreParserExpression function, int pos, |
| 876 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, |
| 877 bool* ok) { |
| 878 return Statement::Default(); |
| 879 } |
| 880 |
| 888 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 881 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
| 889 PreParserExpression assignment) {} | 882 PreParserExpression assignment) {} |
| 890 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 883 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
| 891 bool* ok) {} | 884 bool* ok) {} |
| 892 | 885 |
| 893 // Helper functions for recursive descent. | 886 // Helper functions for recursive descent. |
| 894 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { | 887 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
| 895 return identifier.IsEval(); | 888 return identifier.IsEval(); |
| 896 } | 889 } |
| 897 | 890 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 | 954 |
| 962 V8_INLINE bool IsStringLiteral(PreParserStatement statement) const { | 955 V8_INLINE bool IsStringLiteral(PreParserStatement statement) const { |
| 963 return statement.IsStringLiteral(); | 956 return statement.IsStringLiteral(); |
| 964 } | 957 } |
| 965 | 958 |
| 966 V8_INLINE static PreParserExpression GetPropertyValue( | 959 V8_INLINE static PreParserExpression GetPropertyValue( |
| 967 PreParserExpression property) { | 960 PreParserExpression property) { |
| 968 return PreParserExpression::Default(); | 961 return PreParserExpression::Default(); |
| 969 } | 962 } |
| 970 | 963 |
| 964 V8_INLINE static void GetDefaultStrings( |
| 965 PreParserIdentifier* default_string, |
| 966 PreParserIdentifier* star_default_star_string) {} |
| 967 |
| 971 // Functions for encapsulating the differences between parsing and preparsing; | 968 // Functions for encapsulating the differences between parsing and preparsing; |
| 972 // operations interleaved with the recursive descent. | 969 // operations interleaved with the recursive descent. |
| 973 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} | 970 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} |
| 974 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} | 971 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} |
| 975 V8_INLINE void PushPropertyName(PreParserExpression expression) {} | 972 V8_INLINE void PushPropertyName(PreParserExpression expression) {} |
| 973 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} |
| 976 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} | 974 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} |
| 977 | 975 |
| 978 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 976 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
| 979 PreParserExpression left, PreParserExpression right) {} | 977 PreParserExpression left, PreParserExpression right) {} |
| 980 | 978 |
| 981 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( | 979 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( |
| 982 PreParserExpression expression) { | 980 PreParserExpression expression) { |
| 983 // TODO(marja): To be able to produce the same errors, the preparser needs | 981 // TODO(marja): To be able to produce the same errors, the preparser needs |
| 984 // to start tracking which expressions are variables and which are assigned. | 982 // to start tracking which expressions are variables and which are assigned. |
| 985 return expression; | 983 return expression; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 function_state_->NextMaterializedLiteralIndex(); | 1286 function_state_->NextMaterializedLiteralIndex(); |
| 1289 function_state_->NextMaterializedLiteralIndex(); | 1287 function_state_->NextMaterializedLiteralIndex(); |
| 1290 } | 1288 } |
| 1291 return EmptyExpression(); | 1289 return EmptyExpression(); |
| 1292 } | 1290 } |
| 1293 | 1291 |
| 1294 } // namespace internal | 1292 } // namespace internal |
| 1295 } // namespace v8 | 1293 } // namespace v8 |
| 1296 | 1294 |
| 1297 #endif // V8_PARSING_PREPARSER_H | 1295 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |