- All Superinterfaces:
ASTNode
- All Known Subinterfaces:
AbstractFunctionDefinitionNode,EnumerationTypeNode,EnumeratorDeclarationNode,FieldDeclarationNode,FunctionDeclarationNode,FunctionDefinitionNode,OrdinaryDeclarationNode,OrdinaryLabelNode,PredicateNode,ScopeParameterizedDeclarationNode,StructureOrUnionTypeNode,TypedefDeclarationNode,VariableDeclarationNode
The root of the declaration node type hierarchy. According to C11, "A declaration specifies the interpretation and attributes of a set of identifiers." An object of this type specifies a declaration for exactly one identifier.
A DeclarationNode does not correspond exactly to the notion of "declaration" in the C Standard. For example, in the C Standard, a static assertion is a kind of declaration. This seems more like a grammatical convenience (since a static assertion can appear almost anywhere a declaration can) than a logical organization of the concepts, as a static assertion does not specify "the interpretation and attributes of a set of identifiers".
Every declaration node has at least one child: an identifier node for the
identifier being declared. It is possible for that identifier node to be
null, for example, in an anonymous struct or
enum.
Furthermore, every declaration node declares some abstract thing, called an
Entity. This class provides a method to get and set that entity.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.civl.abc.ast.node.IF.ASTNode
ASTNode.NodeKind -
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a deep copy of this AST node.Returns the entity whose existence is declared by this declaration.Gets the identifier node which contains the name of the entity being declared.getName()The name of the identifier being declared as a string.booleanIs this the defining declaration of the identifier? According to C11, "A definition of an identifier is a declaration for that identifier that: - for an object, causes storage to be reserved for that object; - for a function, includes the function body; - for an enumeration constant, is the (only) declaration of the identifier; - for a typedef name, is the first (or only) declaration of the identifier."voidSets the entity associated to this declaration.voidsetIdentifier(IdentifierNode identifier) Sets the identifier node.voidsetIsDefinition(boolean value) Sets the "isDefinition" field to the given boolean value.Methods inherited from interface dev.civl.abc.ast.node.IF.ASTNode
addAllTransformAnnotations, addTransformAnnotation, child, childIndex, children, diff, equiv, getAttribute, getOwner, getScope, getSource, id, keepOnly, nextDFS, nodeKind, numChildren, parent, prettyPrint, prettyRepresentation, prettyRepresentation, print, remove, removeChild, removeTransformAnnotation, setAttribute, setChild, setId, setOwner, setScope, toString, transformAnnotations
-
Method Details
-
getIdentifier
IdentifierNode getIdentifier()Gets the identifier node which contains the name of the entity being declared. May benull.- Returns:
- the identifier for the name of the entity being declared
-
getName
String getName()The name of the identifier being declared as a string. Could benull. If the identifier is notnull, this method returns the same string returned bygetIdentifier().name(). It is provided for convenience.- Returns:
- name of identifier being declared, or
nullif the declaration is anonymous
-
setIdentifier
Sets the identifier node.- Parameters:
identifier- the identifier node
-
isDefinition
boolean isDefinition()Is this the defining declaration of the identifier? According to C11, "A definition of an identifier is a declaration for that identifier that: - for an object, causes storage to be reserved for that object; - for a function, includes the function body; - for an enumeration constant, is the (only) declaration of the identifier; - for a typedef name, is the first (or only) declaration of the identifier."- Returns:
trueiff this is the identifier's definition.- See Also:
-
setIsDefinition
void setIsDefinition(boolean value) Sets the "isDefinition" field to the given boolean value.- Parameters:
value- new value for "isDefinition"- See Also:
-
getEntity
Entity getEntity()Returns the entity whose existence is declared by this declaration. This is initiallynull, and can be changed bysetEntity(Entity).- Returns:
- the entity declared by this declaration
- See Also:
-
setEntity
Sets the entity associated to this declaration.- Parameters:
entity- the entity to associate to this node- See Also:
-
copy
DeclarationNode copy()Description copied from interface:ASTNodeReturns a deep copy of this AST node. The node and all of its descendants will be cloned. The cloning does not copy analysis or attribute information.
-