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

Side by Side Diff: src/ast/ast.cc

Issue 2142233003: Templatize AstVisitor with its subclass (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 5 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 | « src/ast/ast.h ('k') | src/ast/ast-expression-rewriter.h » ('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 #include "src/ast/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 8
9 #include "src/ast/prettyprinter.h" 9 #include "src/ast/prettyprinter.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
11 #include "src/base/hashmap.h" 11 #include "src/base/hashmap.h"
12 #include "src/builtins/builtins.h" 12 #include "src/builtins/builtins.h"
13 #include "src/code-stubs.h" 13 #include "src/code-stubs.h"
14 #include "src/contexts.h" 14 #include "src/contexts.h"
15 #include "src/conversions.h" 15 #include "src/conversions.h"
16 #include "src/parsing/parser.h" 16 #include "src/parsing/parser.h"
17 #include "src/property-details.h" 17 #include "src/property-details.h"
18 #include "src/property.h" 18 #include "src/property.h"
19 #include "src/string-stream.h" 19 #include "src/string-stream.h"
20 #include "src/type-info.h" 20 #include "src/type-info.h"
21 21
22 namespace v8 { 22 namespace v8 {
23 namespace internal { 23 namespace internal {
24 24
25 // ---------------------------------------------------------------------------- 25 // ----------------------------------------------------------------------------
26 // All the Accept member functions for each syntax tree node type.
27
28 #define DECL_ACCEPT(type) \
29 void type::Accept(AstVisitor* v) { v->Visit##type(this); }
30 AST_NODE_LIST(DECL_ACCEPT)
31 #undef DECL_ACCEPT
32
33
34 // ----------------------------------------------------------------------------
35 // Implementation of other node functionality. 26 // Implementation of other node functionality.
36 27
37 #ifdef DEBUG 28 #ifdef DEBUG
38 29
39 void AstNode::Print(Isolate* isolate) { 30 void AstNode::Print(Isolate* isolate) {
40 AstPrinter::PrintOut(isolate, this); 31 AstPrinter::PrintOut(isolate, this);
41 } 32 }
42 33
43 34
44 #endif // DEBUG 35 #endif // DEBUG
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 JUMP_NODE_LIST(GENERATE_CASE) 166 JUMP_NODE_LIST(GENERATE_CASE)
176 #undef GENERATE_CASE 167 #undef GENERATE_CASE
177 #undef JUMP_NODE_LIST 168 #undef JUMP_NODE_LIST
178 default: 169 default:
179 return false; 170 return false;
180 } 171 }
181 } 172 }
182 173
183 VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position, 174 VariableProxy::VariableProxy(Zone* zone, Variable* var, int start_position,
184 int end_position) 175 int end_position)
185 : Expression(zone, start_position), 176 : Expression(zone, start_position, kVariableProxy),
186 bit_field_(IsThisField::encode(var->is_this()) | 177 bit_field_(IsThisField::encode(var->is_this()) |
187 IsAssignedField::encode(false) | 178 IsAssignedField::encode(false) |
188 IsResolvedField::encode(false)), 179 IsResolvedField::encode(false)),
189 raw_name_(var->raw_name()), 180 raw_name_(var->raw_name()),
190 end_position_(end_position) { 181 end_position_(end_position) {
191 BindTo(var); 182 BindTo(var);
192 } 183 }
193 184
194
195 VariableProxy::VariableProxy(Zone* zone, const AstRawString* name, 185 VariableProxy::VariableProxy(Zone* zone, const AstRawString* name,
196 Variable::Kind variable_kind, int start_position, 186 Variable::Kind variable_kind, int start_position,
197 int end_position) 187 int end_position)
198 : Expression(zone, start_position), 188 : Expression(zone, start_position, kVariableProxy),
199 bit_field_(IsThisField::encode(variable_kind == Variable::THIS) | 189 bit_field_(IsThisField::encode(variable_kind == Variable::THIS) |
200 IsAssignedField::encode(false) | 190 IsAssignedField::encode(false) |
201 IsResolvedField::encode(false)), 191 IsResolvedField::encode(false)),
202 raw_name_(name), 192 raw_name_(name),
203 end_position_(end_position) {} 193 end_position_(end_position) {}
204 194
205
206 void VariableProxy::BindTo(Variable* var) { 195 void VariableProxy::BindTo(Variable* var) {
207 DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name()); 196 DCHECK((is_this() && var->is_this()) || raw_name() == var->raw_name());
208 set_var(var); 197 set_var(var);
209 set_is_resolved(); 198 set_is_resolved();
210 var->set_is_used(); 199 var->set_is_used();
211 } 200 }
212 201
213 202
214 void VariableProxy::AssignFeedbackVectorSlots(Isolate* isolate, 203 void VariableProxy::AssignFeedbackVectorSlots(Isolate* isolate,
215 FeedbackVectorSpec* spec, 204 FeedbackVectorSpec* spec,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 237 }
249 } 238 }
250 239
251 void ForInStatement::AssignFeedbackVectorSlots(Isolate* isolate, 240 void ForInStatement::AssignFeedbackVectorSlots(Isolate* isolate,
252 FeedbackVectorSpec* spec, 241 FeedbackVectorSpec* spec,
253 FeedbackVectorSlotCache* cache) { 242 FeedbackVectorSlotCache* cache) {
254 AssignVectorSlots(each(), spec, &each_slot_); 243 AssignVectorSlots(each(), spec, &each_slot_);
255 for_in_feedback_slot_ = spec->AddGeneralSlot(); 244 for_in_feedback_slot_ = spec->AddGeneralSlot();
256 } 245 }
257 246
258
259 Assignment::Assignment(Zone* zone, Token::Value op, Expression* target, 247 Assignment::Assignment(Zone* zone, Token::Value op, Expression* target,
260 Expression* value, int pos) 248 Expression* value, int pos)
261 : Expression(zone, pos), 249 : Expression(zone, pos, kAssignment),
262 bit_field_( 250 bit_field_(
263 IsUninitializedField::encode(false) | KeyTypeField::encode(ELEMENT) | 251 IsUninitializedField::encode(false) | KeyTypeField::encode(ELEMENT) |
264 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)), 252 StoreModeField::encode(STANDARD_STORE) | TokenField::encode(op)),
265 target_(target), 253 target_(target),
266 value_(value), 254 value_(value),
267 binary_operation_(NULL) {} 255 binary_operation_(NULL) {}
268 256
269
270 void Assignment::AssignFeedbackVectorSlots(Isolate* isolate, 257 void Assignment::AssignFeedbackVectorSlots(Isolate* isolate,
271 FeedbackVectorSpec* spec, 258 FeedbackVectorSpec* spec,
272 FeedbackVectorSlotCache* cache) { 259 FeedbackVectorSlotCache* cache) {
273 AssignVectorSlots(target(), spec, &slot_); 260 AssignVectorSlots(target(), spec, &slot_);
274 } 261 }
275 262
276 263
277 void CountOperation::AssignFeedbackVectorSlots(Isolate* isolate, 264 void CountOperation::AssignFeedbackVectorSlots(Isolate* isolate,
278 FeedbackVectorSpec* spec, 265 FeedbackVectorSpec* spec,
279 FeedbackVectorSlotCache* cache) { 266 FeedbackVectorSlotCache* cache) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 } else { 911 } else {
925 return is_super ? KEYED_SUPER_PROPERTY_CALL : KEYED_PROPERTY_CALL; 912 return is_super ? KEYED_SUPER_PROPERTY_CALL : KEYED_PROPERTY_CALL;
926 } 913 }
927 } 914 }
928 915
929 return OTHER_CALL; 916 return OTHER_CALL;
930 } 917 }
931 918
932 919
933 // ---------------------------------------------------------------------------- 920 // ----------------------------------------------------------------------------
934 // Implementation of AstVisitor
935
936 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) {
937 for (int i = 0; i < declarations->length(); i++) {
938 Visit(declarations->at(i));
939 }
940 }
941
942
943 void AstVisitor::VisitStatements(ZoneList<Statement*>* statements) {
944 for (int i = 0; i < statements->length(); i++) {
945 Statement* stmt = statements->at(i);
946 Visit(stmt);
947 if (stmt->IsJump()) break;
948 }
949 }
950
951
952 void AstVisitor::VisitExpressions(ZoneList<Expression*>* expressions) {
953 for (int i = 0; i < expressions->length(); i++) {
954 // The variable statement visiting code may pass NULL expressions
955 // to this code. Maybe this should be handled by introducing an
956 // undefined expression or literal? Revisit this code if this
957 // changes
958 Expression* expression = expressions->at(i);
959 if (expression != NULL) Visit(expression);
960 }
961 }
962
963 // ----------------------------------------------------------------------------
964 // Implementation of AstTraversalVisitor 921 // Implementation of AstTraversalVisitor
965 922
966 #define RECURSE(call) \ 923 #define RECURSE(call) \
967 do { \ 924 do { \
968 DCHECK(!HasStackOverflow()); \ 925 DCHECK(!HasStackOverflow()); \
969 call; \ 926 call; \
970 if (HasStackOverflow()) return; \ 927 if (HasStackOverflow()) return; \
971 } while (false) 928 } while (false)
972 929
973 #define RECURSE_EXPRESSION(call) \ 930 #define RECURSE_EXPRESSION(call) \
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 void AstTraversalVisitor::VisitRewritableExpression( 1213 void AstTraversalVisitor::VisitRewritableExpression(
1257 RewritableExpression* expr) { 1214 RewritableExpression* expr) {
1258 RECURSE(Visit(expr->expression())); 1215 RECURSE(Visit(expr->expression()));
1259 } 1216 }
1260 1217
1261 #undef RECURSE_EXPRESSION 1218 #undef RECURSE_EXPRESSION
1262 #undef RECURSE 1219 #undef RECURSE
1263 1220
1264 CaseClause::CaseClause(Zone* zone, Expression* label, 1221 CaseClause::CaseClause(Zone* zone, Expression* label,
1265 ZoneList<Statement*>* statements, int pos) 1222 ZoneList<Statement*>* statements, int pos)
1266 : Expression(zone, pos), 1223 : Expression(zone, pos, kCaseClause),
1267 label_(label), 1224 label_(label),
1268 statements_(statements), 1225 statements_(statements),
1269 compare_type_(Type::None()) {} 1226 compare_type_(Type::None()) {}
1270 1227
1271 uint32_t Literal::Hash() { 1228 uint32_t Literal::Hash() {
1272 return raw_value()->IsString() 1229 return raw_value()->IsString()
1273 ? raw_value()->AsString()->hash() 1230 ? raw_value()->AsString()->hash()
1274 : ComputeLongHash(double_to_uint64(raw_value()->AsNumber())); 1231 : ComputeLongHash(double_to_uint64(raw_value()->AsNumber()));
1275 } 1232 }
1276 1233
1277 1234
1278 // static 1235 // static
1279 bool Literal::Match(void* literal1, void* literal2) { 1236 bool Literal::Match(void* literal1, void* literal2) {
1280 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1237 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1281 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1238 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1282 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 1239 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
1283 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1240 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1284 } 1241 }
1285 1242
1286 1243
1287 } // namespace internal 1244 } // namespace internal
1288 } // namespace v8 1245 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast.h ('k') | src/ast/ast-expression-rewriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698