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

Side by Side Diff: src/parsing/parser.h

Issue 2268413002: [parser] Clean up (pre)parser traits, part 3 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2273693002-ref-traits
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | 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 // 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_H_ 5 #ifndef V8_PARSING_PARSER_H_
6 #define V8_PARSING_PARSER_H_ 6 #define V8_PARSING_PARSER_H_
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/parsing/parser-base.h" 10 #include "src/parsing/parser-base.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 typedef AstNodeFactory Factory; 168 typedef AstNodeFactory Factory;
169 }; 169 };
170 170
171 // TODO(nikolaos): The traits methods should not need to call methods 171 // TODO(nikolaos): The traits methods should not need to call methods
172 // of the implementation object. 172 // of the implementation object.
173 Parser* delegate() { return reinterpret_cast<Parser*>(this); } 173 Parser* delegate() { return reinterpret_cast<Parser*>(this); }
174 const Parser* delegate() const { 174 const Parser* delegate() const {
175 return reinterpret_cast<const Parser*>(this); 175 return reinterpret_cast<const Parser*>(this);
176 } 176 }
177 177
178 // Rewrites the following types of unary expressions:
179 // not <literal> -> true / false
180 // + <numeric literal> -> <numeric literal>
181 // - <numeric literal> -> <numeric literal with value negated>
182 // ! <literal> -> true / false
183 // The following rewriting rules enable the collection of type feedback
184 // without any special stub and the multiplication is removed later in
185 // Crankshaft's canonicalization pass.
186 // + foo -> foo * 1
187 // - foo -> foo * (-1)
188 // ~ foo -> foo ^(~0)
189 Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
190 int pos, AstNodeFactory* factory);
191
192 Expression* BuildIteratorResult(Expression* value, bool done);
193
194 // Generate AST node that throws a ReferenceError with the given type.
195 Expression* NewThrowReferenceError(MessageTemplate::Template message,
196 int pos);
197
198 // Generate AST node that throws a SyntaxError with the given
199 // type. The first argument may be null (in the handle sense) in
200 // which case no arguments are passed to the constructor.
201 Expression* NewThrowSyntaxError(MessageTemplate::Template message,
202 const AstRawString* arg, int pos);
203
204 // Generate AST node that throws a TypeError with the given
205 // type. Both arguments must be non-null (in the handle sense).
206 Expression* NewThrowTypeError(MessageTemplate::Template message,
207 const AstRawString* arg, int pos);
208
209 // Reporting errors.
210 void ReportMessageAt(Scanner::Location source_location,
211 MessageTemplate::Template message,
212 const char* arg = NULL,
213 ParseErrorType error_type = kSyntaxError);
214 void ReportMessageAt(Scanner::Location source_location,
215 MessageTemplate::Template message,
216 const AstRawString* arg,
217 ParseErrorType error_type = kSyntaxError);
218
219 // "null" return type creators.
220 static const AstRawString* EmptyIdentifier() { return nullptr; }
221 static Expression* EmptyExpression() { return nullptr; }
222 static Literal* EmptyLiteral() { return nullptr; }
223 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return nullptr; }
224 static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
225
226 // Used in error return values.
227 static ZoneList<Expression*>* NullExpressionList() { return nullptr; }
228
229 // Non-NULL empty string.
230 V8_INLINE const AstRawString* EmptyIdentifierString() const;
231
232 // Odd-ball literal creators.
233 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory) const;
234
235 // Producing data during the recursive descent. 178 // Producing data during the recursive descent.
236 const AstRawString* GetSymbol(Scanner* scanner) const; 179 const AstRawString* GetSymbol(Scanner* scanner) const;
237 const AstRawString* GetNextSymbol(Scanner* scanner) const; 180 const AstRawString* GetNextSymbol(Scanner* scanner) const;
238 const AstRawString* GetNumberAsSymbol(Scanner* scanner) const; 181 const AstRawString* GetNumberAsSymbol(Scanner* scanner) const;
239 182
240 Expression* ThisExpression(int pos = kNoSourcePosition); 183 Expression* ThisExpression(int pos = kNoSourcePosition);
241 Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos); 184 Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
242 Expression* NewSuperCallReference(AstNodeFactory* factory, int pos); 185 Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
243 Expression* NewTargetExpression(int pos); 186 Expression* NewTargetExpression(int pos);
244 Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const; 187 Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const;
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 if (proxy != NULL) proxy->set_is_assigned(); 875 if (proxy != NULL) proxy->set_is_assigned();
933 return expression; 876 return expression;
934 } 877 }
935 878
936 // Returns true if we have a binary expression between two numeric 879 // Returns true if we have a binary expression between two numeric
937 // literals. In that case, *x will be changed to an expression which is the 880 // literals. In that case, *x will be changed to an expression which is the
938 // computed value. 881 // computed value.
939 bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y, 882 bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
940 Token::Value op, int pos); 883 Token::Value op, int pos);
941 884
885 // Rewrites the following types of unary expressions:
886 // not <literal> -> true / false
887 // + <numeric literal> -> <numeric literal>
888 // - <numeric literal> -> <numeric literal with value negated>
889 // ! <literal> -> true / false
890 // The following rewriting rules enable the collection of type feedback
891 // without any special stub and the multiplication is removed later in
892 // Crankshaft's canonicalization pass.
893 // + foo -> foo * 1
894 // - foo -> foo * (-1)
895 // ~ foo -> foo ^(~0)
896 Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
897 int pos);
898
899 Expression* BuildIteratorResult(Expression* value, bool done);
900
901 // Generate AST node that throws a ReferenceError with the given type.
902 V8_INLINE Expression* NewThrowReferenceError(
marja 2016/08/24 08:57:27 Why did you put the implementation in the parser.h
nickie 2016/08/24 09:16:31 We discussed this offline. No, it doesn't have an
903 MessageTemplate::Template message, int pos) {
904 return NewThrowError(Runtime::kNewReferenceError, message,
905 ast_value_factory()->empty_string(), pos);
906 }
907
908 // Generate AST node that throws a SyntaxError with the given
909 // type. The first argument may be null (in the handle sense) in
910 // which case no arguments are passed to the constructor.
911 V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate::Template message,
912 const AstRawString* arg, int pos) {
913 return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
914 }
915
916 // Generate AST node that throws a TypeError with the given
917 // type. Both arguments must be non-null (in the handle sense).
918 V8_INLINE Expression* NewThrowTypeError(MessageTemplate::Template message,
919 const AstRawString* arg, int pos) {
920 return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
921 }
922
923 // Reporting errors.
924 V8_INLINE void ReportMessageAt(Scanner::Location source_location,
925 MessageTemplate::Template message,
926 const char* arg = NULL,
927 ParseErrorType error_type = kSyntaxError) {
928 if (stack_overflow()) {
929 // Suppress the error message (syntax error or such) in the presence of a
930 // stack overflow. The isolate allows only one pending exception at at
931 // time
932 // and we want to report the stack overflow later.
933 return;
934 }
935 pending_error_handler_.ReportMessageAt(source_location.beg_pos,
936 source_location.end_pos, message,
937 arg, error_type);
938 }
939
940 V8_INLINE void ReportMessageAt(Scanner::Location source_location,
941 MessageTemplate::Template message,
942 const AstRawString* arg,
943 ParseErrorType error_type = kSyntaxError) {
944 if (stack_overflow()) {
945 // Suppress the error message (syntax error or such) in the presence of a
946 // stack overflow. The isolate allows only one pending exception at at
947 // time
948 // and we want to report the stack overflow later.
949 return;
950 }
951 pending_error_handler_.ReportMessageAt(source_location.beg_pos,
952 source_location.end_pos, message,
953 arg, error_type);
954 }
955
956 // "null" return type creators.
957 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; }
958 V8_INLINE static Expression* EmptyExpression() { return nullptr; }
959 V8_INLINE static Literal* EmptyLiteral() { return nullptr; }
960 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() {
961 return nullptr;
962 }
963 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
964
965 // Used in error return values.
966 V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
967 return nullptr;
968 }
969
970 // Non-NULL empty string.
971 V8_INLINE const AstRawString* EmptyIdentifierString() const {
972 return ast_value_factory()->empty_string();
973 }
974
975 // Odd-ball literal creators.
976 V8_INLINE Literal* GetLiteralTheHole(int position) {
977 return factory()->NewTheHoleLiteral(kNoSourcePosition);
978 }
979
942 // Parser's private field members. 980 // Parser's private field members.
943 981
944 Scanner scanner_; 982 Scanner scanner_;
945 PreParser* reusable_preparser_; 983 PreParser* reusable_preparser_;
946 Scope* original_scope_; // for ES5 function declarations in sloppy eval 984 Scope* original_scope_; // for ES5 function declarations in sloppy eval
947 Target* target_stack_; // for break, continue statements 985 Target* target_stack_; // for break, continue statements
948 ScriptCompiler::CompileOptions compile_options_; 986 ScriptCompiler::CompileOptions compile_options_;
949 ParseData* cached_parse_data_; 987 ParseData* cached_parse_data_;
950 988
951 PendingCompilationErrorHandler pending_error_handler_; 989 PendingCompilationErrorHandler pending_error_handler_;
952 990
953 // Other information which will be stored in Parser and moved to Isolate after 991 // Other information which will be stored in Parser and moved to Isolate after
954 // parsing. 992 // parsing.
955 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; 993 int use_counts_[v8::Isolate::kUseCounterFeatureCount];
956 int total_preparse_skipped_; 994 int total_preparse_skipped_;
957 HistogramTimer* pre_parse_timer_; 995 HistogramTimer* pre_parse_timer_;
958 996
959 bool parsing_on_main_thread_; 997 bool parsing_on_main_thread_;
960 998
961 #ifdef DEBUG 999 #ifdef DEBUG
962 void Print(AstNode* node); 1000 void Print(AstNode* node);
963 #endif // DEBUG 1001 #endif // DEBUG
964 }; 1002 };
965 1003
966 const AstRawString* ParserBaseTraits<Parser>::EmptyIdentifierString() const {
967 return delegate()->ast_value_factory()->empty_string();
968 }
969
970 1004
971 // Support for handling complex values (array and object literals) that 1005 // Support for handling complex values (array and object literals) that
972 // can be fully handled at compile time. 1006 // can be fully handled at compile time.
973 class CompileTimeValue: public AllStatic { 1007 class CompileTimeValue: public AllStatic {
974 public: 1008 public:
975 enum LiteralType { 1009 enum LiteralType {
976 OBJECT_LITERAL_FAST_ELEMENTS, 1010 OBJECT_LITERAL_FAST_ELEMENTS,
977 OBJECT_LITERAL_SLOW_ELEMENTS, 1011 OBJECT_LITERAL_SLOW_ELEMENTS,
978 ARRAY_LITERAL 1012 ARRAY_LITERAL
979 }; 1013 };
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 if (init_block != nullptr) { 1084 if (init_block != nullptr) {
1051 body->Add(init_block, delegate()->zone()); 1085 body->Add(init_block, delegate()->zone());
1052 } 1086 }
1053 } 1087 }
1054 } 1088 }
1055 1089
1056 } // namespace internal 1090 } // namespace internal
1057 } // namespace v8 1091 } // namespace v8
1058 1092
1059 #endif // V8_PARSING_PARSER_H_ 1093 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698