OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_COMPILER_SOURCE_POSITION_H_ | 5 #ifndef V8_COMPILER_SOURCE_POSITION_H_ |
6 #define V8_COMPILER_SOURCE_POSITION_H_ | 6 #define V8_COMPILER_SOURCE_POSITION_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/compiler/node-aux-data.h" | 9 #include "src/compiler/node-aux-data.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 // Encapsulates encoding and decoding of sources positions from which Nodes | 15 // Encapsulates encoding and decoding of sources positions from which Nodes |
16 // originated. | 16 // originated. |
17 class SourcePosition final { | 17 class SourcePosition final { |
18 public: | 18 public: |
19 explicit SourcePosition(int raw = kUnknownPosition) : raw_(raw) {} | 19 explicit SourcePosition(int raw = kUnknownPosition) : raw_(raw) {} |
20 | 20 |
21 static SourcePosition Unknown() { return SourcePosition(kUnknownPosition); } | 21 static SourcePosition Unknown() { return SourcePosition(kUnknownPosition); } |
22 bool IsUnknown() const { return raw() == kUnknownPosition; } | 22 bool IsUnknown() const { return raw() == kUnknownPosition; } |
23 | 23 bool IsKnown() const { return raw() != kUnknownPosition; } |
24 static SourcePosition Invalid() { return SourcePosition(kInvalidPosition); } | |
25 bool IsInvalid() const { return raw() == kInvalidPosition; } | |
26 | 24 |
27 int raw() const { return raw_; } | 25 int raw() const { return raw_; } |
28 | 26 |
29 private: | 27 private: |
30 static const int kInvalidPosition = -2; | |
31 static const int kUnknownPosition = RelocInfo::kNoPosition; | 28 static const int kUnknownPosition = RelocInfo::kNoPosition; |
32 STATIC_ASSERT(kInvalidPosition != kUnknownPosition); | |
33 int raw_; | 29 int raw_; |
34 }; | 30 }; |
35 | 31 |
36 | 32 |
37 inline bool operator==(const SourcePosition& lhs, const SourcePosition& rhs) { | 33 inline bool operator==(const SourcePosition& lhs, const SourcePosition& rhs) { |
38 return lhs.raw() == rhs.raw(); | 34 return lhs.raw() == rhs.raw(); |
39 } | 35 } |
40 | 36 |
41 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { | 37 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { |
42 return !(lhs == rhs); | 38 return !(lhs == rhs); |
(...skipping 11 matching lines...) Expand all Loading... |
54 } | 50 } |
55 Scope(SourcePositionTable* source_positions, Node* node) | 51 Scope(SourcePositionTable* source_positions, Node* node) |
56 : source_positions_(source_positions), | 52 : source_positions_(source_positions), |
57 prev_position_(source_positions->current_position_) { | 53 prev_position_(source_positions->current_position_) { |
58 Init(source_positions_->GetSourcePosition(node)); | 54 Init(source_positions_->GetSourcePosition(node)); |
59 } | 55 } |
60 ~Scope() { source_positions_->current_position_ = prev_position_; } | 56 ~Scope() { source_positions_->current_position_ = prev_position_; } |
61 | 57 |
62 private: | 58 private: |
63 void Init(SourcePosition position) { | 59 void Init(SourcePosition position) { |
64 if (!position.IsUnknown() || prev_position_.IsInvalid()) { | 60 if (position.IsKnown()) source_positions_->current_position_ = position; |
65 source_positions_->current_position_ = position; | |
66 } | |
67 } | 61 } |
68 | 62 |
69 SourcePositionTable* const source_positions_; | 63 SourcePositionTable* const source_positions_; |
70 SourcePosition const prev_position_; | 64 SourcePosition const prev_position_; |
71 DISALLOW_COPY_AND_ASSIGN(Scope); | 65 DISALLOW_COPY_AND_ASSIGN(Scope); |
72 }; | 66 }; |
73 | 67 |
74 explicit SourcePositionTable(Graph* graph); | 68 explicit SourcePositionTable(Graph* graph); |
75 ~SourcePositionTable() { | 69 ~SourcePositionTable() { |
76 if (decorator_) RemoveDecorator(); | 70 if (decorator_) RemoveDecorator(); |
(...skipping 15 matching lines...) Expand all Loading... |
92 NodeAuxData<SourcePosition> table_; | 86 NodeAuxData<SourcePosition> table_; |
93 | 87 |
94 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); | 88 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); |
95 }; | 89 }; |
96 | 90 |
97 } // namespace compiler | 91 } // namespace compiler |
98 } // namespace internal | 92 } // namespace internal |
99 } // namespace v8 | 93 } // namespace v8 |
100 | 94 |
101 #endif // V8_COMPILER_SOURCE_POSITION_H_ | 95 #endif // V8_COMPILER_SOURCE_POSITION_H_ |
OLD | NEW |