AstAttributeMechanism
Stores named attributes in Sage IR nodes.
Synopsis
Declared in <src/midend/astProcessing/AstAttributeMechanism.h>
class AstAttributeMechanism;
Types
Name |
Description |
Set of attribute names. |
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
Assignment operator. |
|
Insert a new value if the attribute doesn't already exist. |
|
Clears all attributes from the container. |
|
Test for attribute existence. |
|
List of stored attribute names. |
|
Get an attribute value. |
|
Erases the specified attribute. |
|
Insert a new value if the attribute already exists. |
|
Insert an attribute. |
|
Number of attributes stored. |
Private Types
Name |
Private Member Functions
Name |
Private Data Members
Name |
Description
This attribute container stores one non‐null, heap‐allocated attribute per user‐specified name. All values are derived from AstAttribute. Any object can have an attribute container data member. For example, each AST node (SgNode) contains one attribute container accessible via SgNode::get_attributeMechanism.
The value class's AstAttribute::getOwnershipPolicy "getOwnershipPolicy" method indicates whether the container owns the heap‐allocated attribute and therefore whether the container is responsible for invoking delete on the attribute when the container is destroyed. New attribute subclasses should use the AstAttribute::CONTAINER_OWNERSHIP policy if possible.
IR node attribute values are always on the heap. Whenever an attribute container is copied, the container invokes the AstAttribute::copy "copy" method on all its attributes. The attributes' copy should either allocate a new copy of the attribute or return a null pointer. Since these values must be derived from AstAttribute, it is not possible to directly store values whose type the user cannot modify to inherit from AstAttribute. This includes POD types and classes defined in 3rd party libraries (e.g., std::vector). To store such values, the user must wrap them in another class that does inherit from AstAttribute and which implements the necessary virtual functions.
The names of attributes are strings and the container does not check whether the string supplied to various container methods is spelled correctly. Using a misspelled attribute name is the same as using a different value name‐‐in effect, operating on a completely different, unintended attribute.
The AstAttributeMechanism is used by AST nodes (SgNode) and is available via SgNode::get_attributeMechanism, although that is not the preferred API. Instead, SgNode provides an additional methods that contain "attribute" as part of their name. These "attribute" methods are mostly just wrappers around SgNode::get_attributeMechanism.
For additional information, including examples, see attributes.
Created with MrDocs