Chromium Code Reviews| 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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 return lhs.raw() == rhs.raw(); | 34 return lhs.raw() == rhs.raw(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { | 37 inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { |
| 38 return !(lhs == rhs); | 38 return !(lhs == rhs); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 class SourcePositionTable final { | 42 class SourcePositionTable final { |
| 43 public: | 43 public: |
| 44 class Scope final { | |
| 45 public: | |
| 46 Scope(SourcePositionTable* source_positions, SourcePosition position) | |
| 47 : source_positions_(source_positions), | |
| 48 prev_position_(source_positions->current_position_) { | |
| 49 Init(position); | |
| 50 } | |
| 51 Scope(SourcePositionTable* source_positions, Node* node) | |
| 52 : source_positions_(source_positions), | |
| 53 prev_position_(source_positions->current_position_) { | |
| 54 Init(source_positions_->GetSourcePosition(node)); | |
| 55 } | |
| 56 ~Scope() { source_positions_->current_position_ = prev_position_; } | |
| 57 | |
| 58 private: | |
| 59 void Init(SourcePosition position) { | |
| 60 if (position.IsKnown()) source_positions_->current_position_ = position; | |
| 61 } | |
| 62 | |
| 63 SourcePositionTable* const source_positions_; | |
| 64 SourcePosition const prev_position_; | |
| 65 DISALLOW_COPY_AND_ASSIGN(Scope); | |
| 66 }; | |
| 67 | |
| 68 explicit SourcePositionTable(Graph* graph); | 44 explicit SourcePositionTable(Graph* graph); |
| 69 ~SourcePositionTable() { | 45 ~SourcePositionTable() { |
| 70 if (decorator_) RemoveDecorator(); | 46 if (decorator_) RemoveDecorator(); |
| 71 } | 47 } |
| 72 | 48 |
| 73 void AddDecorator(); | 49 void AddDecorator(); |
| 74 void RemoveDecorator(); | 50 void RemoveDecorator(); |
| 75 | 51 |
| 76 SourcePosition GetSourcePosition(Node* node) const; | 52 SourcePosition GetSourcePosition(Node* node) const; |
| 77 | 53 |
| 54 #ifdef DEBUG | |
|
titzer
2016/04/18 11:03:51
I'm not sure why this would only be useful in debu
Clemens Hammacher
2016/04/18 11:18:09
Right now it's only used in debug mode, but sure,
| |
| 55 Graph* GetGraph() const { return graph_; } | |
| 56 #endif | |
| 57 | |
| 78 void Print(std::ostream& os) const; | 58 void Print(std::ostream& os) const; |
| 79 | 59 |
| 80 private: | 60 private: |
| 81 class Decorator; | 61 class Decorator; |
| 62 friend class SourcePositionScope; | |
| 82 | 63 |
| 83 Graph* const graph_; | 64 Graph* const graph_; |
| 84 Decorator* decorator_; | 65 Decorator* decorator_; |
| 85 SourcePosition current_position_; | 66 SourcePosition current_position_; |
| 86 NodeAuxData<SourcePosition> table_; | 67 NodeAuxData<SourcePosition> table_; |
| 87 | 68 |
| 88 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); | 69 DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); |
| 89 }; | 70 }; |
| 90 | 71 |
| 72 class SourcePositionScope final { | |
|
titzer
2016/04/18 11:03:51
I think I prefer leaving this as an inner class in
Clemens Hammacher
2016/04/18 11:18:09
If we don't need to forward-reference it from comp
| |
| 73 public: | |
| 74 SourcePositionScope(SourcePositionTable* source_positions, | |
| 75 SourcePosition position = SourcePosition::Unknown()) | |
| 76 : source_positions_(source_positions), | |
| 77 prev_position_(source_positions->current_position_) { | |
| 78 Init(position); | |
| 79 } | |
| 80 SourcePositionScope(SourcePositionTable* source_positions, Node* node) | |
| 81 : source_positions_(source_positions), | |
| 82 prev_position_(source_positions->current_position_) { | |
| 83 Init(source_positions_->GetSourcePosition(node)); | |
| 84 } | |
| 85 ~SourcePositionScope() { | |
| 86 source_positions_->current_position_ = prev_position_; | |
| 87 } | |
| 88 | |
| 89 void SetCurrentPosition(SourcePosition position) { | |
| 90 DCHECK(position.IsKnown()); | |
| 91 source_positions_->current_position_ = position; | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 void Init(SourcePosition position) { | |
| 96 if (position.IsKnown()) SetCurrentPosition(position); | |
| 97 } | |
| 98 | |
| 99 SourcePositionTable* const source_positions_; | |
| 100 SourcePosition const prev_position_; | |
| 101 DISALLOW_COPY_AND_ASSIGN(SourcePositionScope); | |
| 102 }; | |
| 103 | |
| 91 } // namespace compiler | 104 } // namespace compiler |
| 92 } // namespace internal | 105 } // namespace internal |
| 93 } // namespace v8 | 106 } // namespace v8 |
| 94 | 107 |
| 95 #endif // V8_COMPILER_SOURCE_POSITION_H_ | 108 #endif // V8_COMPILER_SOURCE_POSITION_H_ |
| OLD | NEW |