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

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

Issue 2882973002: [coverage] Block coverage with support for IfStatements (Closed)
Patch Set: Comment nit Created 3 years, 7 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
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/ast/ast-types.h" 8 #include "src/ast/ast-types.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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 FeedbackVectorSpec* get_spec() { return &spec_; } 175 FeedbackVectorSpec* get_spec() { return &spec_; }
176 176
177 private: 177 private:
178 Flags flags_; 178 Flags flags_;
179 int node_count_; 179 int node_count_;
180 FeedbackVectorSpec spec_; 180 FeedbackVectorSpec spec_;
181 }; 181 };
182 182
183 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags) 183 DEFINE_OPERATORS_FOR_FLAGS(AstProperties::Flags)
184 184
185 struct SourceRange {
186 SourceRange() : from(kNoSourcePosition), to(kNoSourcePosition) {}
187 int32_t from, to;
marja 2017/05/18 11:30:17 In Scope, FunctionLiteral etc. there's already sta
jgruber 2017/05/22 09:43:32 No very strong feelings on this from my side, but
marja 2017/05/22 12:55:37 start + end sgtm
188 };
185 189
186 class AstNode: public ZoneObject { 190 class AstNode: public ZoneObject {
187 public: 191 public:
188 #define DECLARE_TYPE_ENUM(type) k##type, 192 #define DECLARE_TYPE_ENUM(type) k##type,
189 enum NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) }; 193 enum NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) };
190 #undef DECLARE_TYPE_ENUM 194 #undef DECLARE_TYPE_ENUM
191 195
192 void* operator new(size_t size, Zone* zone) { return zone->New(size); } 196 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
193 197
194 NodeType node_type() const { return NodeTypeField::decode(bit_field_); } 198 NodeType node_type() const { return NodeTypeField::decode(bit_field_); }
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 // given if-statement has a then- or an else-part containing code. 1012 // given if-statement has a then- or an else-part containing code.
1009 class IfStatement final : public Statement { 1013 class IfStatement final : public Statement {
1010 public: 1014 public:
1011 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 1015 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1012 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 1016 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1013 1017
1014 Expression* condition() const { return condition_; } 1018 Expression* condition() const { return condition_; }
1015 Statement* then_statement() const { return then_statement_; } 1019 Statement* then_statement() const { return then_statement_; }
1016 Statement* else_statement() const { return else_statement_; } 1020 Statement* else_statement() const { return else_statement_; }
1017 1021
1022 SourceRange then_range() const { return then_range_; }
1023 SourceRange else_range() const { return else_range_; }
1024
1018 void set_condition(Expression* e) { condition_ = e; } 1025 void set_condition(Expression* e) { condition_ = e; }
1019 void set_then_statement(Statement* s) { then_statement_ = s; } 1026 void set_then_statement(Statement* s) { then_statement_ = s; }
1020 void set_else_statement(Statement* s) { else_statement_ = s; } 1027 void set_else_statement(Statement* s) { else_statement_ = s; }
1021 1028
1022 bool IsJump() const { 1029 bool IsJump() const {
1023 return HasThenStatement() && then_statement()->IsJump() 1030 return HasThenStatement() && then_statement()->IsJump()
1024 && HasElseStatement() && else_statement()->IsJump(); 1031 && HasElseStatement() && else_statement()->IsJump();
1025 } 1032 }
1026 1033
1027 void set_base_id(int id) { base_id_ = id; } 1034 void set_base_id(int id) { base_id_ = id; }
1028 static int num_ids() { return parent_num_ids() + 3; } 1035 static int num_ids() { return parent_num_ids() + 3; }
1029 BailoutId IfId() const { return BailoutId(local_id(0)); } 1036 BailoutId IfId() const { return BailoutId(local_id(0)); }
1030 BailoutId ThenId() const { return BailoutId(local_id(1)); } 1037 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1031 BailoutId ElseId() const { return BailoutId(local_id(2)); } 1038 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1032 1039
1033 private: 1040 private:
1034 friend class AstNodeFactory; 1041 friend class AstNodeFactory;
1035 1042
1036 IfStatement(Expression* condition, Statement* then_statement, 1043 IfStatement(Expression* condition, Statement* then_statement,
1037 Statement* else_statement, int pos) 1044 Statement* else_statement, int pos, SourceRange then_range,
1045 SourceRange else_range)
1038 : Statement(pos, kIfStatement), 1046 : Statement(pos, kIfStatement),
1039 base_id_(BailoutId::None().ToInt()), 1047 base_id_(BailoutId::None().ToInt()),
1040 condition_(condition), 1048 condition_(condition),
1041 then_statement_(then_statement), 1049 then_statement_(then_statement),
1042 else_statement_(else_statement) {} 1050 else_statement_(else_statement),
1051 then_range_(then_range),
1052 else_range_(else_range) {}
1043 1053
1044 static int parent_num_ids() { return 0; } 1054 static int parent_num_ids() { return 0; }
1045 int base_id() const { 1055 int base_id() const {
1046 DCHECK(!BailoutId(base_id_).IsNone()); 1056 DCHECK(!BailoutId(base_id_).IsNone());
1047 return base_id_; 1057 return base_id_;
1048 } 1058 }
1049 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1059 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1050 1060
1051 int base_id_; 1061 int base_id_;
1052 Expression* condition_; 1062 Expression* condition_;
1053 Statement* then_statement_; 1063 Statement* then_statement_;
1054 Statement* else_statement_; 1064 Statement* else_statement_;
1065 SourceRange then_range_;
1066 SourceRange else_range_;
1055 }; 1067 };
1056 1068
1057 1069
1058 class TryStatement : public Statement { 1070 class TryStatement : public Statement {
1059 public: 1071 public:
1060 Block* try_block() const { return try_block_; } 1072 Block* try_block() const { return try_block_; }
1061 void set_try_block(Block* b) { try_block_ = b; } 1073 void set_try_block(Block* b) { try_block_ = b; }
1062 1074
1063 // Prediction of whether exceptions thrown into the handler for this try block 1075 // Prediction of whether exceptions thrown into the handler for this try block
1064 // will be caught. 1076 // will be caught.
(...skipping 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 ReturnStatement(expression, ReturnStatement::kAsyncReturn, pos); 3347 ReturnStatement(expression, ReturnStatement::kAsyncReturn, pos);
3336 } 3348 }
3337 3349
3338 WithStatement* NewWithStatement(Scope* scope, 3350 WithStatement* NewWithStatement(Scope* scope,
3339 Expression* expression, 3351 Expression* expression,
3340 Statement* statement, 3352 Statement* statement,
3341 int pos) { 3353 int pos) {
3342 return new (zone_) WithStatement(scope, expression, statement, pos); 3354 return new (zone_) WithStatement(scope, expression, statement, pos);
3343 } 3355 }
3344 3356
3345 IfStatement* NewIfStatement(Expression* condition, 3357 IfStatement* NewIfStatement(Expression* condition, Statement* then_statement,
3346 Statement* then_statement, 3358 Statement* else_statement, int pos,
3347 Statement* else_statement, 3359 SourceRange then_range = {},
3348 int pos) { 3360 SourceRange else_range = {}) {
3349 return new (zone_) 3361 return new (zone_) IfStatement(condition, then_statement, else_statement,
3350 IfStatement(condition, then_statement, else_statement, pos); 3362 pos, then_range, else_range);
3351 } 3363 }
3352 3364
3353 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, 3365 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope,
3354 Block* catch_block, int pos) { 3366 Block* catch_block, int pos) {
3355 return new (zone_) TryCatchStatement(try_block, scope, catch_block, 3367 return new (zone_) TryCatchStatement(try_block, scope, catch_block,
3356 HandlerTable::CAUGHT, pos); 3368 HandlerTable::CAUGHT, pos);
3357 } 3369 }
3358 3370
3359 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block, 3371 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block,
3360 Scope* scope, 3372 Scope* scope,
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
3755 : NULL; \ 3767 : NULL; \
3756 } 3768 }
3757 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3769 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3758 #undef DECLARE_NODE_FUNCTIONS 3770 #undef DECLARE_NODE_FUNCTIONS
3759 3771
3760 3772
3761 } // namespace internal 3773 } // namespace internal
3762 } // namespace v8 3774 } // namespace v8
3763 3775
3764 #endif // V8_AST_AST_H_ 3776 #endif // V8_AST_AST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698