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 | 433 |
442 private: | 434 private: |
443 enum Type { | 435 enum Type { |
444 kUnknownStatement, | 436 kUnknownStatement, |
445 kJumpStatement, | 437 kJumpStatement, |
446 kStringLiteralExpressionStatement, | 438 kStringLiteralExpressionStatement, |
447 kUseStrictExpressionStatement, | 439 kUseStrictExpressionStatement, |
448 kUseAsmExpressionStatement, | 440 kUseAsmExpressionStatement, |
449 kFunctionDeclaration | |
450 }; | 441 }; |
451 | 442 |
452 explicit PreParserStatement(Type code) : code_(code) {} | 443 explicit PreParserStatement(Type code) : code_(code) {} |
453 Type code_; | 444 Type code_; |
454 }; | 445 }; |
455 | 446 |
456 | 447 |
457 class PreParserFactory { | 448 class PreParserFactory { |
458 public: | 449 public: |
459 explicit PreParserFactory(void* unused_value_factory) {} | 450 explicit PreParserFactory(void* unused_value_factory) {} |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 // These types form an algebra over syntactic categories that is just | 744 // These types form an algebra over syntactic categories that is just |
754 // rich enough to let us recognize and propagate the constructs that | 745 // rich enough to let us recognize and propagate the constructs that |
755 // are either being counted in the preparser data, or is important | 746 // are either being counted in the preparser data, or is important |
756 // to throw the correct syntax error exceptions. | 747 // to throw the correct syntax error exceptions. |
757 | 748 |
758 // All ParseXXX functions take as the last argument an *ok parameter | 749 // All ParseXXX functions take as the last argument an *ok parameter |
759 // which is set to false if parsing failed; it is unchanged otherwise. | 750 // which is set to false if parsing failed; it is unchanged otherwise. |
760 // By making the 'exception handling' explicit, we are forced to check | 751 // By making the 'exception handling' explicit, we are forced to check |
761 // for failure at the call sites. | 752 // for failure at the call sites. |
762 Statement ParseScopedStatement(bool legacy, bool* ok); | 753 Statement ParseScopedStatement(bool legacy, bool* ok); |
763 Statement ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | |
764 bool default_export, bool* ok); | |
765 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | |
766 ZoneList<const AstRawString*>* names, | |
767 bool default_export, bool* ok); | |
768 Statement ParseFunctionDeclaration(bool* ok); | 754 Statement ParseFunctionDeclaration(bool* ok); |
769 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 755 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
770 bool default_export, bool* ok); | 756 bool default_export, bool* ok); |
771 Expression ParseAsyncFunctionExpression(bool* ok); | 757 Expression ParseAsyncFunctionExpression(bool* ok); |
772 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 758 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
773 bool default_export, bool* ok); | 759 bool default_export, bool* ok); |
774 Statement ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); | 760 Statement ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); |
775 Statement ParseVariableStatement(VariableDeclarationContext var_context, | 761 Statement ParseVariableStatement(VariableDeclarationContext var_context, |
776 ZoneList<const AstRawString*>* names, | 762 ZoneList<const AstRawString*>* names, |
777 bool* ok); | 763 bool* ok); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 return PreParserExpression::Default(); | 866 return PreParserExpression::Default(); |
881 } | 867 } |
882 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } | 868 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
883 | 869 |
884 V8_INLINE void DeclareAndInitializeVariables( | 870 V8_INLINE void DeclareAndInitializeVariables( |
885 PreParserStatement block, | 871 PreParserStatement block, |
886 const DeclarationDescriptor* declaration_descriptor, | 872 const DeclarationDescriptor* declaration_descriptor, |
887 const DeclarationParsingResult::Declaration* declaration, | 873 const DeclarationParsingResult::Declaration* declaration, |
888 ZoneList<const AstRawString*>* names, bool* ok) {} | 874 ZoneList<const AstRawString*>* names, bool* ok) {} |
889 | 875 |
876 V8_INLINE PreParserStatement DeclareFunction( | |
877 PreParserIdentifier variable_name, PreParserExpression function, int pos, | |
878 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, | |
879 bool* ok) { | |
880 return Statement::Default(); | |
881 } | |
882 | |
890 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 883 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
891 PreParserExpression assignment) {} | 884 PreParserExpression assignment) {} |
892 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 885 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
893 bool* ok) {} | 886 bool* ok) {} |
894 | 887 |
895 // Helper functions for recursive descent. | 888 // Helper functions for recursive descent. |
896 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { | 889 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
897 return identifier.IsEval(); | 890 return identifier.IsEval(); |
898 } | 891 } |
899 | 892 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 | 956 |
964 V8_INLINE bool IsStringLiteral(PreParserStatement statement) const { | 957 V8_INLINE bool IsStringLiteral(PreParserStatement statement) const { |
965 return statement.IsStringLiteral(); | 958 return statement.IsStringLiteral(); |
966 } | 959 } |
967 | 960 |
968 V8_INLINE static PreParserExpression GetPropertyValue( | 961 V8_INLINE static PreParserExpression GetPropertyValue( |
969 PreParserExpression property) { | 962 PreParserExpression property) { |
970 return PreParserExpression::Default(); | 963 return PreParserExpression::Default(); |
971 } | 964 } |
972 | 965 |
966 V8_INLINE static void GetDefaultStrings( | |
967 PreParserIdentifier* default_string, | |
968 PreParserIdentifier* star_default_star_string) {} | |
969 | |
973 // Functions for encapsulating the differences between parsing and preparsing; | 970 // Functions for encapsulating the differences between parsing and preparsing; |
974 // operations interleaved with the recursive descent. | 971 // operations interleaved with the recursive descent. |
975 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} | 972 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} |
976 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} | 973 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} |
977 V8_INLINE void PushPropertyName(PreParserExpression expression) {} | 974 V8_INLINE void PushPropertyName(PreParserExpression expression) {} |
975 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} | |
978 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} | 976 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} |
979 | 977 |
980 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 978 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
981 PreParserExpression left, PreParserExpression right) {} | 979 PreParserExpression left, PreParserExpression right) {} |
982 | 980 |
983 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( | 981 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( |
984 PreParserExpression expression) { | 982 PreParserExpression expression) { |
985 // TODO(marja): To be able to produce the same errors, the preparser needs | 983 // TODO(marja): To be able to produce the same errors, the preparser needs |
986 // to start tracking which expressions are variables and which are assigned. | 984 // to start tracking which expressions are variables and which are assigned. |
987 return expression; | 985 return expression; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 } | 1042 } |
1045 V8_INLINE static PreParserExpression EmptyLiteral() { | 1043 V8_INLINE static PreParserExpression EmptyLiteral() { |
1046 return PreParserExpression::Default(); | 1044 return PreParserExpression::Default(); |
1047 } | 1045 } |
1048 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() { | 1046 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() { |
1049 return PreParserExpression::Default(); | 1047 return PreParserExpression::Default(); |
1050 } | 1048 } |
1051 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { | 1049 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { |
1052 return PreParserExpression::Default(); | 1050 return PreParserExpression::Default(); |
1053 } | 1051 } |
1052 V8_INLINE static PreParserStatement GetEmptyStatement() { | |
nickie
2016/09/06 17:29:57
Again, there's NullStatement in line 1076.
marja
2016/09/08 11:15:58
Done.
| |
1053 return PreParserStatement::Default(); | |
1054 } | |
1054 | 1055 |
1055 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) { | 1056 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) { |
1056 return expr.IsEmpty(); | 1057 return expr.IsEmpty(); |
1057 } | 1058 } |
1058 | 1059 |
1059 V8_INLINE static PreParserExpressionList NullExpressionList() { | 1060 V8_INLINE static PreParserExpressionList NullExpressionList() { |
1060 return PreParserExpressionList::Null(); | 1061 return PreParserExpressionList::Null(); |
1061 } | 1062 } |
1062 | 1063 |
1063 V8_INLINE static bool IsNullExpressionList(PreParserExpressionList exprs) { | 1064 V8_INLINE static bool IsNullExpressionList(PreParserExpressionList exprs) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1274 function_state_->NextMaterializedLiteralIndex(); | 1275 function_state_->NextMaterializedLiteralIndex(); |
1275 function_state_->NextMaterializedLiteralIndex(); | 1276 function_state_->NextMaterializedLiteralIndex(); |
1276 } | 1277 } |
1277 return EmptyExpression(); | 1278 return EmptyExpression(); |
1278 } | 1279 } |
1279 | 1280 |
1280 } // namespace internal | 1281 } // namespace internal |
1281 } // namespace v8 | 1282 } // namespace v8 |
1282 | 1283 |
1283 #endif // V8_PARSING_PREPARSER_H | 1284 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |