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:
- The same version of ROSE is used
- The same command line arguments are given
- The same files are on the command line in the same order.
- 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.