ROSE  0.11.109.0
NodeId.h
1 
2 #ifndef ROSE_AST_NodeId_H
3 #define ROSE_AST_NodeId_H
4 
5 #include <string>
6 #include <limits>
7 
8 #define NODEID_INCLUDE_ROSE_VERSION 1
9 
10 
11 class SgNode;
12 
13 namespace Rose { namespace AST {
14 
51 class ROSE_DLL_API NodeId {
52 
53 private:
54 
55  // \brief private internal constructor
56  NodeId(size_t poolId, size_t nodeId, SgNode* inNode) : poolIndex(poolId), nodeIndex(nodeId), node(inNode) {}
57 
58 
59  //DATA---------------------
60  //I'm not that concerned about data size because these aren't stored for each node, they can be
61  //recomputed at will
62  // The number of the memory pool this node lives at
63  size_t poolIndex;
64  // The index of this item in the memory pool
65  size_t nodeIndex;
66 
68  SgNode* node;
69 
70 
71 public:
73  NodeId() : poolIndex(std::numeric_limits<size_t>::max()), nodeIndex(std::numeric_limits<size_t>::max()), node(nullptr) {}
74 
75  NodeId(SgNode* sgnode);
76 
78  NodeId(const NodeId &rhs) : poolIndex(rhs.poolIndex), nodeIndex(rhs.nodeIndex), node(rhs.node) {}
79 
81  NodeId& operator=(const NodeId& rhs) {
82  poolIndex = rhs.poolIndex;
83  nodeIndex = rhs.nodeIndex;
84  node = rhs.node;
85  return *this;
86  }
87 
89  static NodeId getId(SgNode *node);
90 
92  static NodeId getId(const std::string& nodeIdString);
93 
95  static SgNode *getNode(const std::string& nodeIdString) {
96  return getId(nodeIdString).getNode();
97  }
98 
100  SgNode* getNode() const { return node;};
101 
103  std::string toString() const;
104 
105  bool operator==(const NodeId& rhs) const {
106  if(poolIndex == rhs.poolIndex &&
107  nodeIndex == rhs.nodeIndex &&
108  node == rhs.node) {
109  return true;
110  }
111  return false;
112  }
113 
114  bool operator!=(const NodeId& rhs) const { return !(this->operator==(rhs)); }
115  bool operator< (const NodeId& rhs) const {
116  if(poolIndex < rhs.poolIndex ||
117  nodeIndex < rhs.nodeIndex ||
118  node < rhs.node) { //Should never reach this comparison...
119  return true;
120  }
121  return false;
122  }
123  bool operator<= (const NodeId& rhs) const {
124  if(poolIndex <= rhs.poolIndex ||
125  nodeIndex <= rhs.nodeIndex ||
126  node <= rhs.node) { //Should never reach this comparison...
127  return true;
128  }
129  return false;
130  }
131 
132  bool operator> (const NodeId& rhs) const { return !(this->operator<=(rhs));}
133  bool operator>=(const NodeId& rhs) const { return !(this->operator< (rhs));}
134 
135 };
136 
137 } }
138 
139 #endif /* ROSE_AST_NodeId_H */
140 
NodeId & operator=(const NodeId &rhs)
assignment operator
Definition: NodeId.h:81
STL namespace.
SgNode * getNode() const
Get the SgNode* contained in this NodeId.
Definition: NodeId.h:100
Main namespace for the ROSE library.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9737
static SgNode * getNode(const std::string &nodeIdString)
Get the SgNode from a string (convinience function)
Definition: NodeId.h:95
A mostly static class for creating and storing Unique Node Identifiers.
Definition: NodeId.h:51
NodeId()
default constructor required for containers, but only makes invalid NodeIds
Definition: NodeId.h:73
NodeId(const NodeId &rhs)
copy constructor
Definition: NodeId.h:78