| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_COMPILER_SOURCE_POSITION_H_ | |
| 6 #define V8_COMPILER_SOURCE_POSITION_H_ | |
| 7 | |
| 8 #include "src/base/compiler-specific.h" | |
| 9 #include "src/compiler/node-aux-data.h" | |
| 10 #include "src/globals.h" | |
| 11 | |
| 12 namespace v8 { | |
| 13 namespace internal { | |
| 14 namespace compiler { | |
| 15 | |
| 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 | |
| 43 : public NON_EXPORTED_BASE(ZoneObject) { | |
| 44 public: | |
| 45 class Scope final { | |
| 46 public: | |
| 47 Scope(SourcePositionTable* source_positions, SourcePosition position) | |
| 48 : source_positions_(source_positions), | |
| 49 prev_position_(source_positions->current_position_) { | |
| 50 Init(position); | |
| 51 } | |
| 52 Scope(SourcePositionTable* source_positions, Node* node) | |
| 53 : source_positions_(source_positions), | |
| 54 prev_position_(source_positions->current_position_) { | |
| 55 Init(source_positions_->GetSourcePosition(node)); | |
| 56 } | |
| 57 ~Scope() { source_positions_->current_position_ = prev_position_; } | |
| 58 | |
| 59 private: | |
| 60 void Init(SourcePosition position) { | |
| 61 if (position.IsKnown()) source_positions_->current_position_ = position; | |
| 62 } | |
| 63 | |
| 64 SourcePositionTable* const source_positions_; | |
| 65 SourcePosition const prev_position_; | |
| 66 DISALLOW_COPY_AND_ASSIGN(Scope); | |
| 67 }; | |
| 68 | |
| 69 explicit SourcePositionTable(Graph* graph); | |
| 70 | |
| 71 void AddDecorator(); | |
| 72 void RemoveDecorator(); | |
| 73 | |
| 74 SourcePosition GetSourcePosition(Node* node) const; | |
| 75 void SetSourcePosition(Node* node, SourcePosition position); | |
| 76 | |
| 77 void set_current_position(int position) { | |
| 78 current_position_ = SourcePosition(position); | |
| 79 } | |
| 80 | |
| 81 void Print(std::ostream& os) const; | |
| 82 | |
| 83 private: | |
| 84 class Decorator; | |
| 85 | |
| 86 Graph* const graph_; | |
| 87 Decorator* decorator_; | |
| 88 SourcePosition current_position_; | |
| 89 NodeAuxData<SourcePosition> table_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); | |
| 92 }; | |
| 93 | |
| 94 } // namespace compiler | |
| 95 } // namespace internal | |
| 96 } // namespace v8 | |
| 97 | |
| 98 #endif // V8_COMPILER_SOURCE_POSITION_H_ | |
| OLD | NEW |