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_TABLE_H_ |
6 #define V8_COMPILER_SOURCE_POSITION_H_ | 6 #define V8_COMPILER_SOURCE_POSITION_TABLE_H_ |
7 | 7 |
8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
9 #include "src/compiler/node-aux-data.h" | 9 #include "src/compiler/node-aux-data.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
11 #include "src/source-position.h" | |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 // Encapsulates encoding and decoding of sources positions from which Nodes | |
17 // originated. | |
18 class SourcePosition final { | |
19 public: | |
20 explicit SourcePosition(int raw = kUnknownPosition) : raw_(raw) {} | |
21 | |
22 static SourcePosition Unknown() { return SourcePosition(kUnknownPosition); } | |
23 bool IsUnknown() const { return raw() == kUnknownPosition; } | |
24 bool IsKnown() const { return raw() != kUnknownPosition; } | |
25 | |
26 int raw() const { return raw_; } | |
27 | |
28 private: | |
29 static const int kUnknownPosition = kNoSourcePosition; | |
30 int raw_; | |
31 }; | |
32 | |
33 | |
34 inline bool operator==(const SourcePosition& lhs, const SourcePosition& rhs) { | |
35 return lhs.raw() == rhs.raw(); | |
36 } | |
37 | |
38 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { | |
39 return !(lhs == rhs); | |
40 } | |
41 | |
42 class V8_EXPORT_PRIVATE SourcePositionTable final | 17 class V8_EXPORT_PRIVATE SourcePositionTable final |
43 : public NON_EXPORTED_BASE(ZoneObject) { | 18 : public NON_EXPORTED_BASE(ZoneObject) { |
44 public: | 19 public: |
45 class Scope final { | 20 class Scope final { |
46 public: | 21 public: |
47 Scope(SourcePositionTable* source_positions, SourcePosition position) | 22 Scope(SourcePositionTable* source_positions, SourcePosition position) |
48 : source_positions_(source_positions), | 23 : source_positions_(source_positions), |
49 prev_position_(source_positions->current_position_) { | 24 prev_position_(source_positions->current_position_) { |
50 Init(position); | 25 Init(position); |
51 } | 26 } |
(...skipping 15 matching lines...) Expand all Loading... | |
67 }; | 42 }; |
68 | 43 |
69 explicit SourcePositionTable(Graph* graph); | 44 explicit SourcePositionTable(Graph* graph); |
70 | 45 |
71 void AddDecorator(); | 46 void AddDecorator(); |
72 void RemoveDecorator(); | 47 void RemoveDecorator(); |
73 | 48 |
74 SourcePosition GetSourcePosition(Node* node) const; | 49 SourcePosition GetSourcePosition(Node* node) const; |
75 void SetSourcePosition(Node* node, SourcePosition position); | 50 void SetSourcePosition(Node* node, SourcePosition position); |
76 | 51 |
77 void set_current_position(int position) { | 52 void SetCurrentPosition(SourcePosition pos) { current_position_ = pos; } |
vogelheim
2016/11/07 17:53:27
nitpick: const SourcePosition& ?? I think this wil
| |
78 current_position_ = SourcePosition(position); | |
79 } | |
80 | 53 |
81 void Print(std::ostream& os) const; | 54 void Print(std::ostream& os) const; |
82 | 55 |
83 private: | 56 private: |
84 class Decorator; | 57 class Decorator; |
85 | 58 |
86 Graph* const graph_; | 59 Graph* const graph_; |
87 Decorator* decorator_; | 60 Decorator* decorator_; |
88 SourcePosition current_position_; | 61 SourcePosition current_position_; |
89 NodeAuxData<SourcePosition> table_; | 62 NodeAuxData<SourcePosition> table_; |
90 | 63 |
91 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); | 64 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); |
92 }; | 65 }; |
93 | 66 |
94 } // namespace compiler | 67 } // namespace compiler |
95 } // namespace internal | 68 } // namespace internal |
96 } // namespace v8 | 69 } // namespace v8 |
97 | 70 |
98 #endif // V8_COMPILER_SOURCE_POSITION_H_ | 71 #endif // V8_COMPILER_SOURCE_POSITION_TABLE_H_ |
OLD | NEW |