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

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

Issue 1693523002: [es6] More efficient way of marking AST call expressions in tail positions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Removed MarkTail() from Statement Created 4 years, 10 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.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 #ifndef V8_AST_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/ast/ast-value-factory.h" 9 #include "src/ast/ast-value-factory.h"
10 #include "src/ast/modules.h" 10 #include "src/ast/modules.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 int position_; 237 int position_;
238 }; 238 };
239 239
240 240
241 class Statement : public AstNode { 241 class Statement : public AstNode {
242 public: 242 public:
243 explicit Statement(Zone* zone, int position) : AstNode(position) {} 243 explicit Statement(Zone* zone, int position) : AstNode(position) {}
244 244
245 bool IsEmpty() { return AsEmptyStatement() != NULL; } 245 bool IsEmpty() { return AsEmptyStatement() != NULL; }
246 virtual bool IsJump() const { return false; } 246 virtual bool IsJump() const { return false; }
247 virtual void MarkTail() {}
248 }; 247 };
249 248
250 249
251 class SmallMapList final { 250 class SmallMapList final {
252 public: 251 public:
253 SmallMapList() {} 252 SmallMapList() {}
254 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {} 253 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
255 254
256 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); } 255 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
257 void Clear() { list_.Clear(); } 256 void Clear() { list_.Clear(); }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 bool ignore_completion_value() const { return ignore_completion_value_; } 464 bool ignore_completion_value() const { return ignore_completion_value_; }
466 465
467 static int num_ids() { return parent_num_ids() + 1; } 466 static int num_ids() { return parent_num_ids() + 1; }
468 BailoutId DeclsId() const { return BailoutId(local_id(0)); } 467 BailoutId DeclsId() const { return BailoutId(local_id(0)); }
469 468
470 bool IsJump() const override { 469 bool IsJump() const override {
471 return !statements_.is_empty() && statements_.last()->IsJump() 470 return !statements_.is_empty() && statements_.last()->IsJump()
472 && labels() == NULL; // Good enough as an approximation... 471 && labels() == NULL; // Good enough as an approximation...
473 } 472 }
474 473
475 void MarkTail() override {
476 for (int i = 0; i < statements_.length(); i++) {
477 Statement* stmt = statements_.at(i);
478 stmt->MarkTail();
479 }
480 }
481
482 Scope* scope() const { return scope_; } 474 Scope* scope() const { return scope_; }
483 void set_scope(Scope* scope) { scope_ = scope; } 475 void set_scope(Scope* scope) { scope_ = scope; }
484 476
485 protected: 477 protected:
486 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity, 478 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
487 bool ignore_completion_value, int pos) 479 bool ignore_completion_value, int pos)
488 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos), 480 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
489 statements_(capacity, zone), 481 statements_(capacity, zone),
490 ignore_completion_value_(ignore_completion_value), 482 ignore_completion_value_(ignore_completion_value),
491 scope_(NULL) {} 483 scope_(NULL) {}
(...skipping 10 matching lines...) Expand all
502 494
503 class DoExpression final : public Expression { 495 class DoExpression final : public Expression {
504 public: 496 public:
505 DECLARE_NODE_TYPE(DoExpression) 497 DECLARE_NODE_TYPE(DoExpression)
506 498
507 Block* block() { return block_; } 499 Block* block() { return block_; }
508 void set_block(Block* b) { block_ = b; } 500 void set_block(Block* b) { block_ = b; }
509 VariableProxy* result() { return result_; } 501 VariableProxy* result() { return result_; }
510 void set_result(VariableProxy* v) { result_ = v; } 502 void set_result(VariableProxy* v) { result_ = v; }
511 503
512 void MarkTail() override { block_->MarkTail(); }
513
514 protected: 504 protected:
515 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) 505 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
516 : Expression(zone, pos), block_(block), result_(result) { 506 : Expression(zone, pos), block_(block), result_(result) {
517 DCHECK_NOT_NULL(block_); 507 DCHECK_NOT_NULL(block_);
518 DCHECK_NOT_NULL(result_); 508 DCHECK_NOT_NULL(result_);
519 } 509 }
520 static int parent_num_ids() { return Expression::num_ids(); } 510 static int parent_num_ids() { return Expression::num_ids(); }
521 511
522 private: 512 private:
523 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 513 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1005
1016 1006
1017 class ReturnStatement final : public JumpStatement { 1007 class ReturnStatement final : public JumpStatement {
1018 public: 1008 public:
1019 DECLARE_NODE_TYPE(ReturnStatement) 1009 DECLARE_NODE_TYPE(ReturnStatement)
1020 1010
1021 Expression* expression() const { return expression_; } 1011 Expression* expression() const { return expression_; }
1022 1012
1023 void set_expression(Expression* e) { expression_ = e; } 1013 void set_expression(Expression* e) { expression_ = e; }
1024 1014
1025 void MarkTail() override { expression_->MarkTail(); }
1026
1027 protected: 1015 protected:
1028 explicit ReturnStatement(Zone* zone, Expression* expression, int pos) 1016 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
1029 : JumpStatement(zone, pos), expression_(expression) { } 1017 : JumpStatement(zone, pos), expression_(expression) { }
1030 1018
1031 private: 1019 private:
1032 Expression* expression_; 1020 Expression* expression_;
1033 }; 1021 };
1034 1022
1035 1023
1036 class WithStatement final : public Statement { 1024 class WithStatement final : public Statement {
1037 public: 1025 public:
1038 DECLARE_NODE_TYPE(WithStatement) 1026 DECLARE_NODE_TYPE(WithStatement)
1039 1027
1040 Scope* scope() { return scope_; } 1028 Scope* scope() { return scope_; }
1041 Expression* expression() const { return expression_; } 1029 Expression* expression() const { return expression_; }
1042 void set_expression(Expression* e) { expression_ = e; } 1030 void set_expression(Expression* e) { expression_ = e; }
1043 Statement* statement() const { return statement_; } 1031 Statement* statement() const { return statement_; }
1044 void set_statement(Statement* s) { statement_ = s; } 1032 void set_statement(Statement* s) { statement_ = s; }
1045 1033
1046 void set_base_id(int id) { base_id_ = id; } 1034 void set_base_id(int id) { base_id_ = id; }
1047 static int num_ids() { return parent_num_ids() + 2; } 1035 static int num_ids() { return parent_num_ids() + 2; }
1048 BailoutId ToObjectId() const { return BailoutId(local_id(0)); } 1036 BailoutId ToObjectId() const { return BailoutId(local_id(0)); }
1049 BailoutId EntryId() const { return BailoutId(local_id(1)); } 1037 BailoutId EntryId() const { return BailoutId(local_id(1)); }
1050 1038
1051 void MarkTail() override { statement_->MarkTail(); }
1052
1053 protected: 1039 protected:
1054 WithStatement(Zone* zone, Scope* scope, Expression* expression, 1040 WithStatement(Zone* zone, Scope* scope, Expression* expression,
1055 Statement* statement, int pos) 1041 Statement* statement, int pos)
1056 : Statement(zone, pos), 1042 : Statement(zone, pos),
1057 scope_(scope), 1043 scope_(scope),
1058 expression_(expression), 1044 expression_(expression),
1059 statement_(statement), 1045 statement_(statement),
1060 base_id_(BailoutId::None().ToInt()) {} 1046 base_id_(BailoutId::None().ToInt()) {}
1061 static int parent_num_ids() { return 0; } 1047 static int parent_num_ids() { return 0; }
1062 1048
(...skipping 22 matching lines...) Expand all
1085 return label_; 1071 return label_;
1086 } 1072 }
1087 void set_label(Expression* e) { label_ = e; } 1073 void set_label(Expression* e) { label_ = e; }
1088 Label* body_target() { return &body_target_; } 1074 Label* body_target() { return &body_target_; }
1089 ZoneList<Statement*>* statements() const { return statements_; } 1075 ZoneList<Statement*>* statements() const { return statements_; }
1090 1076
1091 static int num_ids() { return parent_num_ids() + 2; } 1077 static int num_ids() { return parent_num_ids() + 2; }
1092 BailoutId EntryId() const { return BailoutId(local_id(0)); } 1078 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1093 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); } 1079 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1094 1080
1095 void MarkTail() override {
1096 for (int i = 0; i < statements_->length(); i++) {
1097 Statement* stmt = statements_->at(i);
1098 stmt->MarkTail();
1099 }
1100 }
1101
1102 Type* compare_type() { return compare_type_; } 1081 Type* compare_type() { return compare_type_; }
1103 void set_compare_type(Type* type) { compare_type_ = type; } 1082 void set_compare_type(Type* type) { compare_type_ = type; }
1104 1083
1105 protected: 1084 protected:
1106 static int parent_num_ids() { return Expression::num_ids(); } 1085 static int parent_num_ids() { return Expression::num_ids(); }
1107 1086
1108 private: 1087 private:
1109 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements, 1088 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1110 int pos); 1089 int pos);
1111 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1090 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
(...skipping 12 matching lines...) Expand all
1124 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { 1103 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1125 tag_ = tag; 1104 tag_ = tag;
1126 cases_ = cases; 1105 cases_ = cases;
1127 } 1106 }
1128 1107
1129 Expression* tag() const { return tag_; } 1108 Expression* tag() const { return tag_; }
1130 ZoneList<CaseClause*>* cases() const { return cases_; } 1109 ZoneList<CaseClause*>* cases() const { return cases_; }
1131 1110
1132 void set_tag(Expression* t) { tag_ = t; } 1111 void set_tag(Expression* t) { tag_ = t; }
1133 1112
1134 void MarkTail() override {
1135 for (int i = 0; i < cases_->length(); i++) {
1136 CaseClause* clause = cases_->at(i);
1137 clause->MarkTail();
1138 }
1139 }
1140
1141 protected: 1113 protected:
1142 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos) 1114 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1143 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 1115 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1144 tag_(NULL), 1116 tag_(NULL),
1145 cases_(NULL) {} 1117 cases_(NULL) {}
1146 1118
1147 private: 1119 private:
1148 Expression* tag_; 1120 Expression* tag_;
1149 ZoneList<CaseClause*>* cases_; 1121 ZoneList<CaseClause*>* cases_;
1150 }; 1122 };
(...skipping 17 matching lines...) Expand all
1168 1140
1169 void set_condition(Expression* e) { condition_ = e; } 1141 void set_condition(Expression* e) { condition_ = e; }
1170 void set_then_statement(Statement* s) { then_statement_ = s; } 1142 void set_then_statement(Statement* s) { then_statement_ = s; }
1171 void set_else_statement(Statement* s) { else_statement_ = s; } 1143 void set_else_statement(Statement* s) { else_statement_ = s; }
1172 1144
1173 bool IsJump() const override { 1145 bool IsJump() const override {
1174 return HasThenStatement() && then_statement()->IsJump() 1146 return HasThenStatement() && then_statement()->IsJump()
1175 && HasElseStatement() && else_statement()->IsJump(); 1147 && HasElseStatement() && else_statement()->IsJump();
1176 } 1148 }
1177 1149
1178 void MarkTail() override {
1179 then_statement_->MarkTail();
1180 else_statement_->MarkTail();
1181 }
1182
1183 void set_base_id(int id) { base_id_ = id; } 1150 void set_base_id(int id) { base_id_ = id; }
1184 static int num_ids() { return parent_num_ids() + 3; } 1151 static int num_ids() { return parent_num_ids() + 3; }
1185 BailoutId IfId() const { return BailoutId(local_id(0)); } 1152 BailoutId IfId() const { return BailoutId(local_id(0)); }
1186 BailoutId ThenId() const { return BailoutId(local_id(1)); } 1153 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1187 BailoutId ElseId() const { return BailoutId(local_id(2)); } 1154 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1188 1155
1189 protected: 1156 protected:
1190 IfStatement(Zone* zone, Expression* condition, Statement* then_statement, 1157 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1191 Statement* else_statement, int pos) 1158 Statement* else_statement, int pos)
1192 : Statement(zone, pos), 1159 : Statement(zone, pos),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 1209
1243 class TryCatchStatement final : public TryStatement { 1210 class TryCatchStatement final : public TryStatement {
1244 public: 1211 public:
1245 DECLARE_NODE_TYPE(TryCatchStatement) 1212 DECLARE_NODE_TYPE(TryCatchStatement)
1246 1213
1247 Scope* scope() { return scope_; } 1214 Scope* scope() { return scope_; }
1248 Variable* variable() { return variable_; } 1215 Variable* variable() { return variable_; }
1249 Block* catch_block() const { return catch_block_; } 1216 Block* catch_block() const { return catch_block_; }
1250 void set_catch_block(Block* b) { catch_block_ = b; } 1217 void set_catch_block(Block* b) { catch_block_ = b; }
1251 1218
1252 void MarkTail() override { catch_block_->MarkTail(); }
1253
1254 protected: 1219 protected:
1255 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope, 1220 TryCatchStatement(Zone* zone, Block* try_block, Scope* scope,
1256 Variable* variable, Block* catch_block, int pos) 1221 Variable* variable, Block* catch_block, int pos)
1257 : TryStatement(zone, try_block, pos), 1222 : TryStatement(zone, try_block, pos),
1258 scope_(scope), 1223 scope_(scope),
1259 variable_(variable), 1224 variable_(variable),
1260 catch_block_(catch_block) {} 1225 catch_block_(catch_block) {}
1261 1226
1262 private: 1227 private:
1263 Scope* scope_; 1228 Scope* scope_;
1264 Variable* variable_; 1229 Variable* variable_;
1265 Block* catch_block_; 1230 Block* catch_block_;
1266 }; 1231 };
1267 1232
1268 1233
1269 class TryFinallyStatement final : public TryStatement { 1234 class TryFinallyStatement final : public TryStatement {
1270 public: 1235 public:
1271 DECLARE_NODE_TYPE(TryFinallyStatement) 1236 DECLARE_NODE_TYPE(TryFinallyStatement)
1272 1237
1273 Block* finally_block() const { return finally_block_; } 1238 Block* finally_block() const { return finally_block_; }
1274 void set_finally_block(Block* b) { finally_block_ = b; } 1239 void set_finally_block(Block* b) { finally_block_ = b; }
1275 1240
1276 void MarkTail() override { finally_block_->MarkTail(); }
1277
1278 protected: 1241 protected:
1279 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block, 1242 TryFinallyStatement(Zone* zone, Block* try_block, Block* finally_block,
1280 int pos) 1243 int pos)
1281 : TryStatement(zone, try_block, pos), finally_block_(finally_block) {} 1244 : TryStatement(zone, try_block, pos), finally_block_(finally_block) {}
1282 1245
1283 private: 1246 private:
1284 Block* finally_block_; 1247 Block* finally_block_;
1285 }; 1248 };
1286 1249
1287 1250
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 // the parser-level zone. 3512 // the parser-level zone.
3550 Zone* parser_zone_; 3513 Zone* parser_zone_;
3551 AstValueFactory* ast_value_factory_; 3514 AstValueFactory* ast_value_factory_;
3552 }; 3515 };
3553 3516
3554 3517
3555 } // namespace internal 3518 } // namespace internal
3556 } // namespace v8 3519 } // namespace v8
3557 3520
3558 #endif // V8_AST_AST_H_ 3521 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698