Home | History | Annotate | Download | only in compiler
      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_COMPILER_SOURCE_POSITION_TABLE_H_
      6 #define V8_COMPILER_COMPILER_SOURCE_POSITION_TABLE_H_
      7 
      8 #include "src/base/compiler-specific.h"
      9 #include "src/compiler/node-aux-data.h"
     10 #include "src/globals.h"
     11 #include "src/source-position.h"
     12 
     13 namespace v8 {
     14 namespace internal {
     15 namespace compiler {
     16 
     17 class V8_EXPORT_PRIVATE SourcePositionTable final
     18     : public NON_EXPORTED_BASE(ZoneObject) {
     19  public:
     20   class Scope final {
     21    public:
     22     Scope(SourcePositionTable* source_positions, SourcePosition position)
     23         : source_positions_(source_positions),
     24           prev_position_(source_positions->current_position_) {
     25       Init(position);
     26     }
     27     Scope(SourcePositionTable* source_positions, Node* node)
     28         : source_positions_(source_positions),
     29           prev_position_(source_positions->current_position_) {
     30       Init(source_positions_->GetSourcePosition(node));
     31     }
     32     ~Scope() { source_positions_->current_position_ = prev_position_; }
     33 
     34    private:
     35     void Init(SourcePosition position) {
     36       if (position.IsKnown()) source_positions_->current_position_ = position;
     37     }
     38 
     39     SourcePositionTable* const source_positions_;
     40     SourcePosition const prev_position_;
     41     DISALLOW_COPY_AND_ASSIGN(Scope);
     42   };
     43 
     44   explicit SourcePositionTable(Graph* graph);
     45 
     46   void AddDecorator();
     47   void RemoveDecorator();
     48 
     49   SourcePosition GetSourcePosition(Node* node) const;
     50   void SetSourcePosition(Node* node, SourcePosition position);
     51 
     52   void SetCurrentPosition(const SourcePosition& pos) {
     53     current_position_ = pos;
     54   }
     55 
     56   void Print(std::ostream& os) const;
     57 
     58  private:
     59   class Decorator;
     60 
     61   Graph* const graph_;
     62   Decorator* decorator_;
     63   SourcePosition current_position_;
     64   NodeAuxData<SourcePosition, SourcePosition::Unknown> table_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
     67 };
     68 
     69 }  // namespace compiler
     70 }  // namespace internal
     71 }  // namespace v8
     72 
     73 #endif  // V8_COMPILER_COMPILER_SOURCE_POSITION_TABLE_H_
     74