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

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

Issue 2882973002: [coverage] Block coverage with support for IfStatements (Closed)
Patch Set: Address comments Created 3 years, 6 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/api.cc ('k') | src/compilation-info.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/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() : start(kNoSourcePosition), end(kNoSourcePosition) {}
187 bool IsEmpty() const { return start == kNoSourcePosition; }
188 int32_t start, end;
189 };
185 190
186 class AstNode: public ZoneObject { 191 class AstNode: public ZoneObject {
187 public: 192 public:
188 #define DECLARE_TYPE_ENUM(type) k##type, 193 #define DECLARE_TYPE_ENUM(type) k##type,
189 enum NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) }; 194 enum NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) };
190 #undef DECLARE_TYPE_ENUM 195 #undef DECLARE_TYPE_ENUM
191 196
192 void* operator new(size_t size, Zone* zone) { return zone->New(size); } 197 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
193 198
194 NodeType node_type() const { return NodeTypeField::decode(bit_field_); } 199 NodeType node_type() const { return NodeTypeField::decode(bit_field_); }
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 // given if-statement has a then- or an else-part containing code. 999 // given if-statement has a then- or an else-part containing code.
995 class IfStatement final : public Statement { 1000 class IfStatement final : public Statement {
996 public: 1001 public:
997 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 1002 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
998 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 1003 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
999 1004
1000 Expression* condition() const { return condition_; } 1005 Expression* condition() const { return condition_; }
1001 Statement* then_statement() const { return then_statement_; } 1006 Statement* then_statement() const { return then_statement_; }
1002 Statement* else_statement() const { return else_statement_; } 1007 Statement* else_statement() const { return else_statement_; }
1003 1008
1009 SourceRange then_range() const { return then_range_; }
1010 SourceRange else_range() const { return else_range_; }
1011
1004 void set_condition(Expression* e) { condition_ = e; } 1012 void set_condition(Expression* e) { condition_ = e; }
1005 void set_then_statement(Statement* s) { then_statement_ = s; } 1013 void set_then_statement(Statement* s) { then_statement_ = s; }
1006 void set_else_statement(Statement* s) { else_statement_ = s; } 1014 void set_else_statement(Statement* s) { else_statement_ = s; }
1007 1015
1008 bool IsJump() const { 1016 bool IsJump() const {
1009 return HasThenStatement() && then_statement()->IsJump() 1017 return HasThenStatement() && then_statement()->IsJump()
1010 && HasElseStatement() && else_statement()->IsJump(); 1018 && HasElseStatement() && else_statement()->IsJump();
1011 } 1019 }
1012 1020
1013 void set_base_id(int id) { base_id_ = id; } 1021 void set_base_id(int id) { base_id_ = id; }
1014 static int num_ids() { return parent_num_ids() + 3; } 1022 static int num_ids() { return parent_num_ids() + 3; }
1015 BailoutId IfId() const { return BailoutId(local_id(0)); } 1023 BailoutId IfId() const { return BailoutId(local_id(0)); }
1016 BailoutId ThenId() const { return BailoutId(local_id(1)); } 1024 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1017 BailoutId ElseId() const { return BailoutId(local_id(2)); } 1025 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1018 1026
1019 private: 1027 private:
1020 friend class AstNodeFactory; 1028 friend class AstNodeFactory;
1021 1029
1022 IfStatement(Expression* condition, Statement* then_statement, 1030 IfStatement(Expression* condition, Statement* then_statement,
1023 Statement* else_statement, int pos) 1031 Statement* else_statement, int pos, SourceRange then_range,
1032 SourceRange else_range)
1024 : Statement(pos, kIfStatement), 1033 : Statement(pos, kIfStatement),
1025 base_id_(BailoutId::None().ToInt()), 1034 base_id_(BailoutId::None().ToInt()),
1026 condition_(condition), 1035 condition_(condition),
1027 then_statement_(then_statement), 1036 then_statement_(then_statement),
1028 else_statement_(else_statement) {} 1037 else_statement_(else_statement),
1038 then_range_(then_range),
1039 else_range_(else_range) {}
1029 1040
1030 static int parent_num_ids() { return 0; } 1041 static int parent_num_ids() { return 0; }
1031 int base_id() const { 1042 int base_id() const {
1032 DCHECK(!BailoutId(base_id_).IsNone()); 1043 DCHECK(!BailoutId(base_id_).IsNone());
1033 return base_id_; 1044 return base_id_;
1034 } 1045 }
1035 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1046 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1036 1047
1037 int base_id_; 1048 int base_id_;
1038 Expression* condition_; 1049 Expression* condition_;
1039 Statement* then_statement_; 1050 Statement* then_statement_;
1040 Statement* else_statement_; 1051 Statement* else_statement_;
1052 SourceRange then_range_;
1053 SourceRange else_range_;
1041 }; 1054 };
1042 1055
1043 1056
1044 class TryStatement : public Statement { 1057 class TryStatement : public Statement {
1045 public: 1058 public:
1046 Block* try_block() const { return try_block_; } 1059 Block* try_block() const { return try_block_; }
1047 void set_try_block(Block* b) { try_block_ = b; } 1060 void set_try_block(Block* b) { try_block_ = b; }
1048 1061
1049 // Prediction of whether exceptions thrown into the handler for this try block 1062 // Prediction of whether exceptions thrown into the handler for this try block
1050 // will be caught. 1063 // will be caught.
(...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after
3309 ReturnStatement(expression, ReturnStatement::kAsyncReturn, pos); 3322 ReturnStatement(expression, ReturnStatement::kAsyncReturn, pos);
3310 } 3323 }
3311 3324
3312 WithStatement* NewWithStatement(Scope* scope, 3325 WithStatement* NewWithStatement(Scope* scope,
3313 Expression* expression, 3326 Expression* expression,
3314 Statement* statement, 3327 Statement* statement,
3315 int pos) { 3328 int pos) {
3316 return new (zone_) WithStatement(scope, expression, statement, pos); 3329 return new (zone_) WithStatement(scope, expression, statement, pos);
3317 } 3330 }
3318 3331
3319 IfStatement* NewIfStatement(Expression* condition, 3332 IfStatement* NewIfStatement(Expression* condition, Statement* then_statement,
3320 Statement* then_statement, 3333 Statement* else_statement, int pos,
3321 Statement* else_statement, 3334 SourceRange then_range = {},
3322 int pos) { 3335 SourceRange else_range = {}) {
3323 return new (zone_) 3336 return new (zone_) IfStatement(condition, then_statement, else_statement,
3324 IfStatement(condition, then_statement, else_statement, pos); 3337 pos, then_range, else_range);
3325 } 3338 }
3326 3339
3327 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, 3340 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope,
3328 Block* catch_block, int pos) { 3341 Block* catch_block, int pos) {
3329 return new (zone_) TryCatchStatement(try_block, scope, catch_block, 3342 return new (zone_) TryCatchStatement(try_block, scope, catch_block,
3330 HandlerTable::CAUGHT, pos); 3343 HandlerTable::CAUGHT, pos);
3331 } 3344 }
3332 3345
3333 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block, 3346 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block,
3334 Scope* scope, 3347 Scope* scope,
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 : NULL; \ 3724 : NULL; \
3712 } 3725 }
3713 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3726 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3714 #undef DECLARE_NODE_FUNCTIONS 3727 #undef DECLARE_NODE_FUNCTIONS
3715 3728
3716 3729
3717 } // namespace internal 3730 } // namespace internal
3718 } // namespace v8 3731 } // namespace v8
3719 3732
3720 #endif // V8_AST_AST_H_ 3733 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/compilation-info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698