ROSE 0.11.145.192
NodeId.h
1#ifndef ROSE_AST_NodeId_H
2#define ROSE_AST_NodeId_H
3#include <RoseFirst.h>
4
5#include <string>
6#include <limits>
7
8#define NODEID_INCLUDE_ROSE_VERSION 1
9
10
11class SgNode;
12
13namespace Rose { namespace AST {
14
61 class ROSE_DLL_API NodeId {
62
63 private:
64
65 // \brief private internal constructor
66 NodeId(size_t poolId, size_t nodeId, SgNode* inNode) : poolIndex(poolId), nodeIndex(nodeId), node(inNode) {}
67
69 //(Never called publically)
70 static void initRunHash();
71
72
73 //DATA---------------------
74 //I'm not that concerned about data size because these aren't stored for each node, they can be
75 //recomputed at will
76 // The number of the memory pool this node lives at
77 size_t poolIndex;
78 // The index of this item in the memory pool
79 size_t nodeIndex;
80
82 SgNode* node;
83
99 static std::string run_hash;
100
101 public:
103 NodeId() : poolIndex(std::numeric_limits<size_t>::max()), nodeIndex(std::numeric_limits<size_t>::max()), node(nullptr) {}
104
105 NodeId(SgNode* sgnode);
106
108 NodeId(const NodeId &rhs) : poolIndex(rhs.poolIndex), nodeIndex(rhs.nodeIndex), node(rhs.node) {}
109
111 NodeId& operator=(const NodeId& rhs) {
112 poolIndex = rhs.poolIndex;
113 nodeIndex = rhs.nodeIndex;
114 node = rhs.node;
115 return *this;
116 }
117
119 static NodeId getId(SgNode *node);
120
122 static NodeId getId(const std::string& nodeIdString);
123
125 static SgNode *getNode(const std::string& nodeIdString) {
126 return getId(nodeIdString).getNode();
127 }
128
130 SgNode* getNode() const { return node;};
131
133 std::string toString() const;
134
135 bool operator==(const NodeId& rhs) const {
136 if(poolIndex == rhs.poolIndex &&
137 nodeIndex == rhs.nodeIndex &&
138 node == rhs.node) {
139 return true;
140 }
141 return false;
142 }
143
144 bool operator!=(const NodeId& rhs) const { return !(this->operator==(rhs)); }
145 bool operator< (const NodeId& rhs) const {
146 if(poolIndex < rhs.poolIndex ||
147 nodeIndex < rhs.nodeIndex ||
148 node < rhs.node) { //Should never reach this comparison...
149 return true;
150 }
151 return false;
152 }
153 bool operator<= (const NodeId& rhs) const {
154 if(poolIndex <= rhs.poolIndex ||
155 nodeIndex <= rhs.nodeIndex ||
156 node <= rhs.node) { //Should never reach this comparison...
157 return true;
158 }
159 return false;
160 }
161
162 bool operator> (const NodeId& rhs) const { return !(this->operator<=(rhs));}
163 bool operator>=(const NodeId& rhs) const { return !(this->operator< (rhs));}
164
165 };
166
167 } }
168
169#endif /* ROSE_AST_NodeId_H */
170
A mostly static class for creating and storing Unique Node Identifiers.
Definition NodeId.h:61
NodeId()
default constructor required for containers, but only makes invalid NodeIds
Definition NodeId.h:103
NodeId & operator=(const NodeId &rhs)
assignment operator
Definition NodeId.h:111
static SgNode * getNode(const std::string &nodeIdString)
Get the SgNode from a string (convinience function)
Definition NodeId.h:125
static NodeId getId(SgNode *node)
Get the Node ID for a particular SgNode*.
static NodeId getId(const std::string &nodeIdString)
Get the Node ID from a string (e.g. from json)
NodeId(const NodeId &rhs)
copy constructor
Definition NodeId.h:108
std::string toString() const
Get this node ID as a string.
SgNode * getNode() const
Get the SgNode* contained in this NodeId.
Definition NodeId.h:130
This class represents the base class for all IR nodes within Sage III.
The ROSE library.