ROSE 0.11.145.147
Public Member Functions | Static Public Member Functions | List of all members
Rose::AST::NodeId Class Reference

Description

A mostly static class for creating and storing Unique Node Identifiers.

This class by be used to uniquely identify a node by a string, or find a particular node from that string. There is no storage of the IDs on the AST or anywhere else. This class includes a couple of numbers, but those only exist as the NodeId does. Node and Ids are found and generated algorithmically. So using NodeIds does not increase the memory cost of ROSE.

It is based on the Node's location in the memory pool, so it is based on the stability of the memory pool. So it has a few constraints. It will be stable between runs of ROSE iff:

  1. The same version of ROSE is used
  2. The same command line arguments are given
  3. The same files are on the command line in the same order.
  4. No transformations occur.

Under those constraints the construction of the AST should be deterministic, so the memory pool construction should be as well. One hopes. There is one optimization that I may have to change if it becomes an issue. I'm leaving a note here in case it becomes an issue. The memory pools are stored via sorted insert in the pools array of each AST node type. This makes the lookup slightly faster as the memory pool is sorted. However, it is possible that as the AST is constructed a memory pool pointer could be allocatted out of order, resulting in a different order of memory pools. If this happens I suggest we go back to a regular push_back instead of a sorted_insert, and then when an ID is generated for an SgNode, we will have to use linear search. I haven't seen this in testing. -Jim Leek

The NodeId also has a hash for error checking. The hash checks the ROSE_VERSION and the ordered set of input files. However, there is one possible FUTURE problem. Currently ROSE only allows a single SgProject node. And we need to SgProject to get the list of files for the hash. So there is only a single static hash field. If, in the future, we allow multiple projects in the AST, this will be a problem. Because each hash will have to be associated with a project, so the user will have to provide an SgNode (from which the project may be queried) to calls like getId(string) where one it not required now.

Definition at line 61 of file NodeId.h.

#include <Rose/AST/NodeId.h>

Public Member Functions

 NodeId ()
 default constructor required for containers, but only makes invalid NodeIds
 
 NodeId (SgNode *sgnode)
 
 NodeId (const NodeId &rhs)
 copy constructor
 
NodeIdoperator= (const NodeId &rhs)
 assignment operator
 
SgNodegetNode () const
 Get the SgNode* contained in this NodeId.
 
std::string toString () const
 Get this node ID as a string.
 
bool operator== (const NodeId &rhs) const
 
bool operator!= (const NodeId &rhs) const
 
bool operator< (const NodeId &rhs) const
 
bool operator<= (const NodeId &rhs) const
 
bool operator> (const NodeId &rhs) const
 
bool operator>= (const NodeId &rhs) const
 

Static Public Member Functions

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)
 
static SgNodegetNode (const std::string &nodeIdString)
 Get the SgNode from a string (convinience function)
 

Constructor & Destructor Documentation

◆ NodeId() [1/2]

Rose::AST::NodeId::NodeId ( )
inline

default constructor required for containers, but only makes invalid NodeIds

Definition at line 103 of file NodeId.h.

◆ NodeId() [2/2]

Rose::AST::NodeId::NodeId ( const NodeId rhs)
inline

copy constructor

Definition at line 108 of file NodeId.h.

Member Function Documentation

◆ operator=()

NodeId & Rose::AST::NodeId::operator= ( const NodeId rhs)
inline

assignment operator

Definition at line 111 of file NodeId.h.

◆ getNode() [1/2]

static SgNode * Rose::AST::NodeId::getNode ( const std::string &  nodeIdString)
inlinestatic

Get the SgNode from a string (convinience function)

Definition at line 125 of file NodeId.h.

◆ getNode() [2/2]

SgNode * Rose::AST::NodeId::getNode ( ) const
inline

Get the SgNode* contained in this NodeId.

Definition at line 130 of file NodeId.h.

◆ operator==()

bool Rose::AST::NodeId::operator== ( const NodeId rhs) const
inline

Definition at line 135 of file NodeId.h.

◆ operator!=()

bool Rose::AST::NodeId::operator!= ( const NodeId rhs) const
inline

Definition at line 144 of file NodeId.h.

◆ operator<()

bool Rose::AST::NodeId::operator< ( const NodeId rhs) const
inline

Definition at line 145 of file NodeId.h.

◆ operator<=()

bool Rose::AST::NodeId::operator<= ( const NodeId rhs) const
inline

Definition at line 153 of file NodeId.h.

◆ operator>()

bool Rose::AST::NodeId::operator> ( const NodeId rhs) const
inline

Definition at line 162 of file NodeId.h.

◆ operator>=()

bool Rose::AST::NodeId::operator>= ( const NodeId rhs) const
inline

Definition at line 163 of file NodeId.h.


The documentation for this class was generated from the following file: