LCOV - code coverage report
Current view: top level - src/compiler - node-aux-data.h (source / functions) Hit Total Coverage
Test: app.info Lines: 8 13 61.5 %
Date: 2017-04-26 Functions: 1 1 100.0 %

          Line data    Source code
       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_NODE_AUX_DATA_H_
       6             : #define V8_COMPILER_NODE_AUX_DATA_H_
       7             : 
       8             : #include "src/compiler/node.h"
       9             : #include "src/zone/zone-containers.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : namespace compiler {
      14             : 
      15             : // Forward declarations.
      16             : class Node;
      17             : 
      18             : template <class T, T def()>
      19             : class NodeAuxData {
      20             :  public:
      21             :   explicit NodeAuxData(Zone* zone) : aux_data_(zone) {}
      22             : 
      23    74228624 :   void Set(Node* node, T const& data) {
      24    74228624 :     size_t const id = node->id();
      25   148457248 :     if (id >= aux_data_.size()) aux_data_.resize(id + 1, def());
      26    74228599 :     aux_data_[id] = data;
      27    74228599 :   }
      28             : 
      29   324143232 :   T Get(Node* node) const {
      30   324143232 :     size_t const id = node->id();
      31   961977946 :     return (id < aux_data_.size()) ? aux_data_[id] : def();
      32             :   }
      33             : 
      34             :   class const_iterator;
      35             :   friend class const_iterator;
      36             : 
      37             :   const_iterator begin() const;
      38             :   const_iterator end() const;
      39             : 
      40             :  private:
      41             :   ZoneVector<T> aux_data_;
      42             : };
      43             : 
      44             : template <class T, T def()>
      45             : class NodeAuxData<T, def>::const_iterator {
      46             :  public:
      47             :   typedef std::forward_iterator_tag iterator_category;
      48             :   typedef int difference_type;
      49             :   typedef std::pair<size_t, T> value_type;
      50             :   typedef value_type* pointer;
      51             :   typedef value_type& reference;
      52             : 
      53             :   const_iterator(const ZoneVector<T>* data, size_t current)
      54             :       : data_(data), current_(current) {}
      55             :   const_iterator(const const_iterator& other)
      56             :       : data_(other.data_), current_(other.current_) {}
      57             : 
      58             :   value_type operator*() const {
      59           0 :     return std::make_pair(current_, (*data_)[current_]);
      60             :   }
      61             :   bool operator==(const const_iterator& other) const {
      62           0 :     return current_ == other.current_ && data_ == other.data_;
      63             :   }
      64             :   bool operator!=(const const_iterator& other) const {
      65             :     return !(*this == other);
      66             :   }
      67             :   const_iterator& operator++() {
      68           0 :     ++current_;
      69             :     return *this;
      70             :   }
      71             :   const_iterator operator++(int);
      72             : 
      73             :  private:
      74             :   const ZoneVector<T>* data_;
      75             :   size_t current_;
      76             : };
      77             : 
      78             : template <class T, T def()>
      79             : typename NodeAuxData<T, def>::const_iterator NodeAuxData<T, def>::begin()
      80             :     const {
      81           0 :   return typename NodeAuxData<T, def>::const_iterator(&aux_data_, 0);
      82             : }
      83             : 
      84             : template <class T, T def()>
      85             : typename NodeAuxData<T, def>::const_iterator NodeAuxData<T, def>::end() const {
      86             :   return typename NodeAuxData<T, def>::const_iterator(&aux_data_,
      87           0 :                                                       aux_data_.size());
      88             : }
      89             : 
      90             : }  // namespace compiler
      91             : }  // namespace internal
      92             : }  // namespace v8
      93             : 
      94             : #endif  // V8_COMPILER_NODE_AUX_DATA_H_

Generated by: LCOV version 1.10