Package ru.ispras.castle.ast.basis
Class SyntaxNode<TagT extends java.lang.Enum<TagT>>
- java.lang.Object
-
- ru.ispras.castle.ast.basis.SyntaxNode<TagT>
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
Assignment
public abstract class SyntaxNode<TagT extends java.lang.Enum<TagT>> extends java.lang.Object implements java.lang.Cloneable
SyntaxNode
represents a basic node of an abstract syntax tree (AST).- See Also:
SymbolTable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SyntaxNode.Kind
SyntaxNode.Kind
classifies nodes according to the has-name and has-scope flags.
-
Constructor Summary
Constructors Modifier Constructor Description protected
SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind)
Creates an AST node.protected
SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind, java.lang.String name, SyntaxNode<TagT> parent)
Creates an AST node.protected
SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind, SyntaxNode<TagT> parent)
Creates an AST node.protected
SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, SyntaxNode.Kind kind)
Creates an AST node.protected
SyntaxNode(SyntaxNode<TagT> syntaxNode)
Creates an AST node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(SyntaxNode<TagT> child)
Adds a child to the node.boolean
containsAttribute(java.lang.String key)
Checks whether the node contains the given attribute.SyntaxNode<TagT>
find(java.lang.String name)
Searches for a child with the given name in the current scope.SyntaxNode<TagT>
findRecursively(java.lang.String name)
Searches for a child with the given name in the current and upper scopes.java.lang.Object
getAttribute(java.lang.String key)
Returns the attribute value.java.util.Collection<SyntaxNode<TagT>>
getChildren()
Returns the collection of the children.java.util.Collection<SyntaxNode<TagT>>
getChildren(TagT tag)
Returns the collection of the children of the given tag.SyntaxNode.Kind
getKind()
Returns the kind of the node.java.lang.String
getName()
Returns the name of the node.SyntaxNode<TagT>
getParent()
Returns the parent of the node ornull
if the node is a root.TagT
getTag()
Returns the tag of the node.java.lang.Class<TagT>
getTagType()
Returns the type of the node tag.boolean
hasName()
Checks whether the node has name.boolean
hasScope()
Checks whether the node has scope.void
setAttribute(java.lang.String key, java.lang.Object value)
Sets the attribute value.void
setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Sets the attribute values.void
setName(java.lang.String name)
Sets the name of the node.void
setParent(SyntaxNode<TagT> parent)
Sets the parent of the node.protected void
setRedefinitionHandler(ErrorHandler<TagT> handler)
Sets the redefinition handler.
-
-
-
Constructor Detail
-
SyntaxNode
protected SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind, java.lang.String name, SyntaxNode<TagT> parent)
Creates an AST node.- Parameters:
tagType
- the node tag type.tag
- the node tag.childrenTags
- the admissible tags of the node's children.kind
- the node kind.name
- the node name.parent
- the node parent.
-
SyntaxNode
protected SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind, SyntaxNode<TagT> parent)
Creates an AST node.- Parameters:
tagType
- the node tag type.tag
- the node tag.childrenTags
- the admissible tags of the node's children.kind
- the node kind.parent
- the node parent.
-
SyntaxNode
protected SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, java.util.EnumSet<TagT> childrenTags, SyntaxNode.Kind kind)
Creates an AST node.- Parameters:
tagType
- the node tag type.tag
- the node tag.childrenTags
- the admissible tags of the node's children.kind
- the node kind.
-
SyntaxNode
protected SyntaxNode(java.lang.Class<TagT> tagType, TagT tag, SyntaxNode.Kind kind)
Creates an AST node.- Parameters:
tagType
- the node tag type.tag
- the node tag.kind
- the node kind.
-
SyntaxNode
protected SyntaxNode(SyntaxNode<TagT> syntaxNode)
Creates an AST node.- Parameters:
syntaxNode
- the node that this is copied from.
-
-
Method Detail
-
getTagType
public final java.lang.Class<TagT> getTagType()
Returns the type of the node tag.- Returns:
- the node tag type.
-
getTag
public final TagT getTag()
Returns the tag of the node.- Returns:
- the node tag.
-
getKind
public final SyntaxNode.Kind getKind()
Returns the kind of the node.- Returns:
- the node kind.
-
containsAttribute
public final boolean containsAttribute(java.lang.String key)
Checks whether the node contains the given attribute.- Parameters:
key
- the attribute key.- Returns:
true
if the node contains the attribute;false
otherwise.
-
getAttribute
public final java.lang.Object getAttribute(java.lang.String key)
Returns the attribute value.- Parameters:
key
- the attribute key.- Returns:
- the attribute value or
null
if the attribute has not been set.
-
setAttribute
public final void setAttribute(java.lang.String key, java.lang.Object value)
Sets the attribute value.- Parameters:
key
- the attribute key.value
- the attribute value
-
setAttributes
public final void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Sets the attribute values.- Parameters:
attributes
- the attributes to be set.
-
hasName
public final boolean hasName()
Checks whether the node has name.- Returns:
true
if the node has name;false
otherwise.
-
hasScope
public final boolean hasScope()
Checks whether the node has scope.- Returns:
true
if the node has scope;false
otherwise.
-
getName
public final java.lang.String getName()
Returns the name of the node.- Returns:
- the node name.
-
setName
public final void setName(java.lang.String name)
Sets the name of the node.- Parameters:
name
- the node name.
-
getParent
public final SyntaxNode<TagT> getParent()
Returns the parent of the node ornull
if the node is a root.- Returns:
- the node parent.
-
setParent
public final void setParent(SyntaxNode<TagT> parent)
Sets the parent of the node.- Parameters:
parent
- the node parent.
-
getChildren
public final java.util.Collection<SyntaxNode<TagT>> getChildren()
Returns the collection of the children.- Returns:
- the children.
-
getChildren
public final java.util.Collection<SyntaxNode<TagT>> getChildren(TagT tag)
Returns the collection of the children of the given tag.- Parameters:
tag
- the child tag.- Returns:
- the children.
-
find
public final SyntaxNode<TagT> find(java.lang.String name)
Searches for a child with the given name in the current scope.- Parameters:
name
- the child name.- Returns:
- the child node or
null
.
-
findRecursively
public final SyntaxNode<TagT> findRecursively(java.lang.String name)
Searches for a child with the given name in the current and upper scopes.- Parameters:
name
- the child name.- Returns:
- the child node or
null
.
-
add
public final void add(SyntaxNode<TagT> child)
Adds a child to the node.- Parameters:
child
- the child to be added.
-
setRedefinitionHandler
protected final void setRedefinitionHandler(ErrorHandler<TagT> handler)
Sets the redefinition handler.- Parameters:
handler
- the handler to be set.
-
-