AstAttributeMechanism¶
Stores named attributes in Sage IR nodes.
Synopsis¶
Declared in <src/midend/astProcessing/AstAttributeMechanism.h>
class [[visibility("default")]] AstAttributeMechanism; 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.
Type Aliases¶
| Name | Description |
|---|---|
AttributeIdentifiers | Set of attribute names. |
Member Functions¶
| Name | Description |
|---|---|
AstAttributeMechanismAstAttributeMechanism(); [constructor] | Constructors |
~AstAttributeMechanism~AstAttributeMechanism(); [destructor] | Destructor. |
operator=AstAttributeMechanism& operator=(AstAttributeMechanism const& other); | Assignment operator. |
addbool add( std::string const& name, AstAttribute* value); | Insert a new value if the attribute doesn't already exist. |
clearAttributesvoid clearAttributes(); | Clears all attributes from the container. |
existsbool exists(std::string const& name) const; | Test for attribute existence. |
getAttributeIdentifiersAttributeIdentifiers getAttributeIdentifiers() const; | Names of the attributes currently stored in this container. |
operator[]AstAttribute* operator[](std::string const& name) const; | Get an attribute value. |
removevoid remove(std::string const& name); | Erases the specified attribute. |
replacebool replace( std::string const& name, AstAttribute* value); | Insert a new value if the attribute already exists. |
setvoid set( std::string const& name, AstAttribute* value); | Insert an attribute. |
sizesize_t size() const; | Number of attributes stored. |
Private Type Aliases¶
| Name |
|---|
attributeMap_ |
Private Member Functions¶
| Name |
|---|
assignFromvoid assignFrom(AstAttributeMechanism const& other); |
Private Data Members¶
| Name |
|---|
attributes_ |
Created with MrDocs