Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: src/preparser.h

Issue 252423007: Parser: Introduce StatementList + NewStatementList() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added PreParser::Statement typedef Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // These functions make list->Add(some_expression) work (and do nothing). 680 // These functions make list->Add(some_expression) work (and do nothing).
681 PreParserExpressionList() : length_(0) {} 681 PreParserExpressionList() : length_(0) {}
682 PreParserExpressionList* operator->() { return this; } 682 PreParserExpressionList* operator->() { return this; }
683 void Add(PreParserExpression, void*) { ++length_; } 683 void Add(PreParserExpression, void*) { ++length_; }
684 int length() const { return length_; } 684 int length() const { return length_; }
685 private: 685 private:
686 int length_; 686 int length_;
687 }; 687 };
688 688
689 689
690 class PreParserStatement {
691 public:
692 static PreParserStatement Default() {
693 return PreParserStatement(kUnknownStatement);
694 }
695
696 static PreParserStatement FunctionDeclaration() {
697 return PreParserStatement(kFunctionDeclaration);
698 }
699
700 // Creates expression statement from expression.
701 // Preserves being an unparenthesized string literal, possibly
702 // "use strict".
703 static PreParserStatement ExpressionStatement(
704 PreParserExpression expression) {
705 if (expression.IsUseStrictLiteral()) {
706 return PreParserStatement(kUseStrictExpressionStatement);
707 }
708 if (expression.IsStringLiteral()) {
709 return PreParserStatement(kStringLiteralExpressionStatement);
710 }
711 return Default();
712 }
713
714 bool IsStringLiteral() {
715 return code_ == kStringLiteralExpressionStatement;
716 }
717
718 bool IsUseStrictLiteral() {
719 return code_ == kUseStrictExpressionStatement;
720 }
721
722 bool IsFunctionDeclaration() {
723 return code_ == kFunctionDeclaration;
724 }
725
726 private:
727 enum Type {
728 kUnknownStatement,
729 kStringLiteralExpressionStatement,
730 kUseStrictExpressionStatement,
731 kFunctionDeclaration
732 };
733
734 explicit PreParserStatement(Type code) : code_(code) {}
735 Type code_;
736 };
737
738
739
740 // PreParserStatementList doesn't actually store the statements because
741 // the PreParser does not need them.
742 class PreParserStatementList {
743 public:
744 // These functions make list->Add(some_expression) work as no-ops.
745 PreParserStatementList() {}
746 PreParserStatementList* operator->() { return this; }
747 void Add(PreParserStatement, void*) {}
748 };
749
750
690 class PreParserScope { 751 class PreParserScope {
691 public: 752 public:
692 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type) 753 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type)
693 : scope_type_(scope_type) { 754 : scope_type_(scope_type) {
694 strict_mode_ = outer_scope ? outer_scope->strict_mode() : SLOPPY; 755 strict_mode_ = outer_scope ? outer_scope->strict_mode() : SLOPPY;
695 } 756 }
696 757
697 ScopeType type() { return scope_type_; } 758 ScopeType type() { return scope_type_; }
698 StrictMode strict_mode() const { return strict_mode_; } 759 StrictMode strict_mode() const { return strict_mode_; }
699 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } 760 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 884
824 // Return types for traversing functions. 885 // Return types for traversing functions.
825 typedef PreParserIdentifier Identifier; 886 typedef PreParserIdentifier Identifier;
826 typedef PreParserExpression Expression; 887 typedef PreParserExpression Expression;
827 typedef PreParserExpression YieldExpression; 888 typedef PreParserExpression YieldExpression;
828 typedef PreParserExpression FunctionLiteral; 889 typedef PreParserExpression FunctionLiteral;
829 typedef PreParserExpression ObjectLiteralProperty; 890 typedef PreParserExpression ObjectLiteralProperty;
830 typedef PreParserExpression Literal; 891 typedef PreParserExpression Literal;
831 typedef PreParserExpressionList ExpressionList; 892 typedef PreParserExpressionList ExpressionList;
832 typedef PreParserExpressionList PropertyList; 893 typedef PreParserExpressionList PropertyList;
894 typedef PreParserStatementList StatementList;
833 895
834 // For constructing objects returned by the traversing functions. 896 // For constructing objects returned by the traversing functions.
835 typedef PreParserFactory Factory; 897 typedef PreParserFactory Factory;
836 }; 898 };
837 899
838 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 900 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
839 901
840 // Custom operations executed when FunctionStates are created and 902 // Custom operations executed when FunctionStates are created and
841 // destructed. (The PreParser doesn't need to do anything.) 903 // destructed. (The PreParser doesn't need to do anything.)
842 template<typename FunctionState> 904 template<typename FunctionState>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 } 1048 }
987 1049
988 PreParserExpression ExpressionFromString(int pos, 1050 PreParserExpression ExpressionFromString(int pos,
989 Scanner* scanner, 1051 Scanner* scanner,
990 PreParserFactory* factory = NULL); 1052 PreParserFactory* factory = NULL);
991 1053
992 static PreParserExpressionList NewExpressionList(int size, void* zone) { 1054 static PreParserExpressionList NewExpressionList(int size, void* zone) {
993 return PreParserExpressionList(); 1055 return PreParserExpressionList();
994 } 1056 }
995 1057
1058 static PreParserStatementList NewStatementList(int size, void* zone) {
1059 return PreParserStatementList();
1060 }
1061
996 static PreParserExpressionList NewPropertyList(int size, void* zone) { 1062 static PreParserExpressionList NewPropertyList(int size, void* zone) {
997 return PreParserExpressionList(); 1063 return PreParserExpressionList();
998 } 1064 }
999 1065
1000 // Temporary glue; these functions will move to ParserBase. 1066 // Temporary glue; these functions will move to ParserBase.
1001 PreParserExpression ParseV8Intrinsic(bool* ok); 1067 PreParserExpression ParseV8Intrinsic(bool* ok);
1002 PreParserExpression ParseFunctionLiteral( 1068 PreParserExpression ParseFunctionLiteral(
1003 PreParserIdentifier name, 1069 PreParserIdentifier name,
1004 Scanner::Location function_name_location, 1070 Scanner::Location function_name_location,
1005 bool name_is_strict_reserved, 1071 bool name_is_strict_reserved,
(...skipping 16 matching lines...) Expand all
1022 // The grammar check is only performed in order to understand the program 1088 // The grammar check is only performed in order to understand the program
1023 // sufficiently to deduce some information about it, that can be used 1089 // sufficiently to deduce some information about it, that can be used
1024 // to speed up later parsing. Finding errors is not the goal of pre-parsing, 1090 // to speed up later parsing. Finding errors is not the goal of pre-parsing,
1025 // rather it is to speed up properly written and correct programs. 1091 // rather it is to speed up properly written and correct programs.
1026 // That means that contextual checks (like a label being declared where 1092 // That means that contextual checks (like a label being declared where
1027 // it is used) are generally omitted. 1093 // it is used) are generally omitted.
1028 class PreParser : public ParserBase<PreParserTraits> { 1094 class PreParser : public ParserBase<PreParserTraits> {
1029 public: 1095 public:
1030 typedef PreParserIdentifier Identifier; 1096 typedef PreParserIdentifier Identifier;
1031 typedef PreParserExpression Expression; 1097 typedef PreParserExpression Expression;
1098 typedef PreParserStatement Statement;
1032 1099
1033 enum PreParseResult { 1100 enum PreParseResult {
1034 kPreParseStackOverflow, 1101 kPreParseStackOverflow,
1035 kPreParseSuccess 1102 kPreParseSuccess
1036 }; 1103 };
1037 1104
1038 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) 1105 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit)
1039 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, 1106 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL,
1040 this) {} 1107 this) {}
1041 1108
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 kStatement, 1150 kStatement,
1084 kForStatement 1151 kForStatement
1085 }; 1152 };
1086 1153
1087 // If a list of variable declarations includes any initializers. 1154 // If a list of variable declarations includes any initializers.
1088 enum VariableDeclarationProperties { 1155 enum VariableDeclarationProperties {
1089 kHasInitializers, 1156 kHasInitializers,
1090 kHasNoInitializers 1157 kHasNoInitializers
1091 }; 1158 };
1092 1159
1093 class Statement {
1094 public:
1095 static Statement Default() {
1096 return Statement(kUnknownStatement);
1097 }
1098
1099 static Statement FunctionDeclaration() {
1100 return Statement(kFunctionDeclaration);
1101 }
1102
1103 // Creates expression statement from expression.
1104 // Preserves being an unparenthesized string literal, possibly
1105 // "use strict".
1106 static Statement ExpressionStatement(Expression expression) {
1107 if (expression.IsUseStrictLiteral()) {
1108 return Statement(kUseStrictExpressionStatement);
1109 }
1110 if (expression.IsStringLiteral()) {
1111 return Statement(kStringLiteralExpressionStatement);
1112 }
1113 return Default();
1114 }
1115
1116 bool IsStringLiteral() {
1117 return code_ == kStringLiteralExpressionStatement;
1118 }
1119
1120 bool IsUseStrictLiteral() {
1121 return code_ == kUseStrictExpressionStatement;
1122 }
1123
1124 bool IsFunctionDeclaration() {
1125 return code_ == kFunctionDeclaration;
1126 }
1127
1128 private:
1129 enum Type {
1130 kUnknownStatement,
1131 kStringLiteralExpressionStatement,
1132 kUseStrictExpressionStatement,
1133 kFunctionDeclaration
1134 };
1135
1136 explicit Statement(Type code) : code_(code) {}
1137 Type code_;
1138 };
1139 1160
1140 enum SourceElements { 1161 enum SourceElements {
1141 kUnknownSourceElements 1162 kUnknownSourceElements
1142 }; 1163 };
1143 1164
1144 // All ParseXXX functions take as the last argument an *ok parameter 1165 // All ParseXXX functions take as the last argument an *ok parameter
1145 // which is set to false if parsing failed; it is unchanged otherwise. 1166 // which is set to false if parsing failed; it is unchanged otherwise.
1146 // By making the 'exception handling' explicit, we are forced to check 1167 // By making the 'exception handling' explicit, we are forced to check
1147 // for failure at the call sites. 1168 // for failure at the call sites.
1148 Statement ParseSourceElement(bool* ok); 1169 Statement ParseSourceElement(bool* ok);
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 "accessor_get_set"); 2193 "accessor_get_set");
2173 } 2194 }
2174 *ok = false; 2195 *ok = false;
2175 } 2196 }
2176 } 2197 }
2177 2198
2178 2199
2179 } } // v8::internal 2200 } } // v8::internal
2180 2201
2181 #endif // V8_PREPARSER_H 2202 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698