5 #ifndef V8_AST_AST_SOURCE_RANGES_H_ 6 #define V8_AST_AST_SOURCE_RANGES_H_ 8 #include "src/ast/ast.h" 9 #include "src/zone/zone-containers.h" 18 SourceRange(
int start,
int end) : start(start), end(end) {}
19 bool IsEmpty()
const {
return start == kNoSourcePosition; }
25 int end = kNoSourcePosition) {
26 return that.IsEmpty() ? Empty() :
SourceRange(that.end, end);
33 #define AST_SOURCE_RANGE_LIST(V) \ 39 V(IterationStatement) \ 45 V(TryCatchStatement) \ 46 V(TryFinallyStatement) 48 enum class SourceRangeKind {
61 virtual SourceRange GetRange(SourceRangeKind kind) = 0;
67 : right_range_(right_range) {}
69 SourceRange GetRange(SourceRangeKind kind)
override {
70 DCHECK_EQ(kind, SourceRangeKind::kRight);
81 : continuation_position_(continuation_position) {}
83 SourceRange GetRange(SourceRangeKind kind)
override {
84 DCHECK_EQ(kind, SourceRangeKind::kContinuation);
85 return SourceRange::OpenEnded(continuation_position_);
89 int32_t continuation_position_;
101 : body_range_(body_range) {}
103 SourceRange GetRange(SourceRangeKind kind)
override {
104 DCHECK_EQ(kind, SourceRangeKind::kBody);
116 : then_range_(then_range), else_range_(else_range) {}
118 SourceRange GetRange(SourceRangeKind kind)
override {
120 case SourceRangeKind::kThen:
122 case SourceRangeKind::kElse:
138 : then_range_(then_range), else_range_(else_range) {}
140 SourceRange GetRange(SourceRangeKind kind)
override {
142 case SourceRangeKind::kElse:
144 case SourceRangeKind::kThen:
146 case SourceRangeKind::kContinuation: {
148 else_range_.IsEmpty() ? then_range_ : else_range_;
149 return SourceRange::ContinuationOf(trailing_range);
164 : body_range_(body_range) {}
166 SourceRange GetRange(SourceRangeKind kind)
override {
168 case SourceRangeKind::kBody:
170 case SourceRangeKind::kContinuation:
171 return SourceRange::ContinuationOf(body_range_);
195 DCHECK(index < ranges_.size());
196 return ranges_[index];
199 void AddRange(
const SourceRange& range) { ranges_.push_back(range); }
200 size_t RangeCount()
const {
return ranges_.size(); }
202 SourceRange GetRange(SourceRangeKind kind)
override { UNREACHABLE(); }
229 : catch_range_(catch_range) {}
231 SourceRange GetRange(SourceRangeKind kind)
override {
233 case SourceRangeKind::kCatch:
235 case SourceRangeKind::kContinuation:
236 return SourceRange::ContinuationOf(catch_range_);
249 : finally_range_(finally_range) {}
251 SourceRange GetRange(SourceRangeKind kind)
override {
253 case SourceRangeKind::kFinally:
254 return finally_range_;
255 case SourceRangeKind::kContinuation:
256 return SourceRange::ContinuationOf(finally_range_);
273 auto it = map_.find(node);
274 if (it == map_.end())
return nullptr;
279 #define DEFINE_MAP_INSERT(type) \ 280 void Insert(type* node, type##SourceRanges* ranges) { \ 281 DCHECK_NOT_NULL(node); \ 282 map_.emplace(node, ranges); \ 284 AST_SOURCE_RANGE_LIST(DEFINE_MAP_INSERT)
285 #undef DEFINE_MAP_INSERT 294 #endif // V8_AST_AST_SOURCE_RANGES_H_