- All Known Subinterfaces:
Declaration.Constant
,Declaration.Function
,Declaration.Scoped
,Declaration.Typedef
,Declaration.Variable
public interface Declaration
Instances of this class are used to model declaration elements in the foreign language.
All declarations have a position (see
Position
) and a name. Instances of this class
support the visitor pattern (see accept(Visitor, Object)
and
Declaration.Visitor
).-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A constant value declaration.static interface
A function declaration.static interface
A scoped declaration is a container for one or more nested declarations.static interface
A typedef declarationstatic interface
A variable declaration.static interface
Declaration visitor interface. -
Method Summary
Modifier and TypeMethodDescription<R,
D> R accept
(Declaration.Visitor<R, D> visitor, D data) Entry point for visiting declaration instances.The attributes associated with this declarationstatic Declaration.Variable
bitfield
(Position pos, String name, Type type, MemoryLayout layout) Creates a new bitfield declaration with given name, type and layout.static Declaration.Scoped
bitfields
(Position pos, MemoryLayout layout, Declaration.Variable... bitfields) Creates a new bitfields group declaration with given name and layout.static Declaration.Scoped
class_
(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new class declaration with given name, layout and member declarations.static Declaration.Scoped
class_
(Position pos, String name, Declaration... decls) Creates a new class declaration with given name and member declarations.static Declaration.Constant
Creates a new constant declaration with given name and type.static Declaration.Scoped
enum_
(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new enum declaration with given name, layout and member declarations.static Declaration.Scoped
enum_
(Position pos, String name, Declaration... decls) Creates a new enum declaration with given name and member declarations.boolean
Compares the specified object with this Declaration for equality.static Declaration.Variable
Creates a new field declaration with given name and type.static Declaration.Function
function
(Position pos, String name, Type.Function type, Declaration.Variable... params) Creates a new function declaration with given name, type and parameter declarations.getAttribute
(String name) The values of the specified attribute.static Declaration.Variable
globalVariable
(Position pos, String name, Type type) Creates a new global variable declaration with given name and type.int
hashCode()
Returns the hash code value for this Declaration.name()
The name associated with this declaration.static Declaration.Scoped
namespace
(Position pos, String name, Declaration... decls) Creates a new namespace declaration with given name and member declarations.static Declaration.Variable
Creates a new parameter declaration with given name and type.pos()
The position associated with this declaration.Get a declaration without current attributesstatic Declaration.Scoped
struct
(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new struct declaration with given name, layout and member declarations.static Declaration.Scoped
struct
(Position pos, String name, Declaration... decls) Creates a new struct declaration with given name and member declarations.static Declaration.Scoped
toplevel
(Position pos, Declaration... decls) Creates a new toplevel declaration with given member declarations.static Declaration.Typedef
Creates a new typedef declaration with given name and declared type.static Declaration.Scoped
union
(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new union declaration with given name, layout and member declarations.static Declaration.Scoped
union
(Position pos, String name, Declaration... decls) Creates a new union declaration with given name and member declarations.withAttribute
(String name, Constable... values) Get a declaration with specified attribute.
-
Method Details
-
pos
Position pos()The position associated with this declaration.- Returns:
- The position associated with this declaration.
-
name
String name()The name associated with this declaration.- Returns:
- The name associated with this declaration.
-
withAttribute
Get a declaration with specified attribute. Set the values to the specified attribute while other attributes remains unchanged. If the specified attribute already exist, the new values are replacing the old ones. By not specifying any value, the attribute will become empty asgetAttribute(name).isEmpty()
will return true.- Parameters:
name
- The attribute namevalues
- More attribute values- Returns:
- the Declaration with attributes
-
stripAttributes
Declaration stripAttributes()Get a declaration without current attributes- Returns:
- the Declatation without any attributes
-
getAttribute
The values of the specified attribute.- Parameters:
name
- The attribute to retrieve- Returns:
- The list of values associate with this attribute
-
attributeNames
The attributes associated with this declaration- Returns:
- The attributes associated with this declaration
-
accept
Entry point for visiting declaration instances.- Type Parameters:
R
- the visitor's return type.D
- the visitor's argument type.- Parameters:
visitor
- the declaration visitor.data
- optional data to be passed to the visitor.- Returns:
- the result of visiting this declaration through the specified declaration visitor.
-
equals
Compares the specified object with this Declaration for equality. Returnstrue
if and only if the specified object is also a Declaration and both the declarations are equal. -
hashCode
int hashCode()Returns the hash code value for this Declaration. -
constant
Creates a new constant declaration with given name and type.- Parameters:
pos
- the constant declaration position.name
- the constant declaration name.value
- the constant declaration value.type
- the constant declaration type.- Returns:
- a new constant declaration with given name and type.
-
globalVariable
Creates a new global variable declaration with given name and type.- Parameters:
pos
- the global variable declaration position.name
- the global variable declaration name.type
- the global variable declaration type.- Returns:
- a new global variable declaration with given name and type.
-
field
Creates a new field declaration with given name and type.- Parameters:
pos
- the field declaration position.name
- the field declaration name.type
- the field declaration type.- Returns:
- a new field declaration with given name and type.
-
bitfield
Creates a new bitfield declaration with given name, type and layout.- Parameters:
pos
- the bitfield declaration position.name
- the bitfield declaration name.type
- the bitfield declaration type.layout
- the bitfield declaration layout.- Returns:
- a new bitfield declaration with given name, type and layout.
-
parameter
Creates a new parameter declaration with given name and type.- Parameters:
pos
- the parameter declaration position.name
- the parameter declaration name.type
- the parameter declaration type.- Returns:
- a new parameter declaration with given name and type.
-
toplevel
Creates a new toplevel declaration with given member declarations.- Parameters:
pos
- the toplevel declaration position.decls
- the toplevel declaration member declarations.- Returns:
- a new toplevel declaration with given member declarations.
-
namespace
Creates a new namespace declaration with given name and member declarations.- Parameters:
pos
- the namespace declaration position.name
- the namespace declaration name.decls
- the namespace declaration member declarations.- Returns:
- a new namespace declaration with given name and member declarations.
-
bitfields
static Declaration.Scoped bitfields(Position pos, MemoryLayout layout, Declaration.Variable... bitfields) Creates a new bitfields group declaration with given name and layout.- Parameters:
pos
- the bitfields group declaration position.layout
- the bitfields group declaration layout.bitfields
- the bitfields group member declarations.- Returns:
- a new bitfields group declaration with given name and layout.
-
struct
Creates a new struct declaration with given name and member declarations.- Parameters:
pos
- the struct declaration position.name
- the struct declaration name.decls
- the struct declaration member declarations.- Returns:
- a new struct declaration with given name, layout and member declarations.
-
struct
static Declaration.Scoped struct(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new struct declaration with given name, layout and member declarations.- Parameters:
pos
- the struct declaration position.name
- the struct declaration name.layout
- the struct declaration layout.decls
- the struct declaration member declarations.- Returns:
- a new struct declaration with given name, layout and member declarations.
-
union
Creates a new union declaration with given name and member declarations.- Parameters:
pos
- the union declaration position.name
- the union declaration name.decls
- the union declaration member declarations.- Returns:
- a new union declaration with given name and member declarations.
-
union
static Declaration.Scoped union(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new union declaration with given name, layout and member declarations.- Parameters:
pos
- the union declaration position.name
- the union declaration name.layout
- the union declaration layout.decls
- the union declaration member declarations.- Returns:
- a new union declaration with given name, layout and member declarations.
-
class_
Creates a new class declaration with given name and member declarations.- Parameters:
pos
- the class declaration position.name
- the class declaration name.decls
- the class declaration member declarations.- Returns:
- a new class declaration with given name and member declarations.
-
class_
static Declaration.Scoped class_(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new class declaration with given name, layout and member declarations.- Parameters:
pos
- the class declaration position.name
- the class declaration name.layout
- the class declaration layout.decls
- the class declaration member declarations.- Returns:
- a new class declaration with given name, layout and member declarations.
-
enum_
Creates a new enum declaration with given name and member declarations.- Parameters:
pos
- the enum declaration position.name
- the enum declaration name.decls
- the enum declaration member declarations.- Returns:
- a new enum declaration with given name, layout and member declarations.
-
enum_
static Declaration.Scoped enum_(Position pos, String name, MemoryLayout layout, Declaration... decls) Creates a new enum declaration with given name, layout and member declarations.- Parameters:
pos
- the enum declaration position.name
- the enum declaration name.layout
- the enum declaration layout.decls
- the enum declaration member declarations.- Returns:
- a new enum declaration with given name, layout and member declarations.
-
function
static Declaration.Function function(Position pos, String name, Type.Function type, Declaration.Variable... params) Creates a new function declaration with given name, type and parameter declarations.- Parameters:
pos
- the function declaration position.name
- the function declaration name.type
- the function declaration type.params
- the function declaration parameter declarations.- Returns:
- a new function declaration with given name, type and parameter declarations.
-
typedef
Creates a new typedef declaration with given name and declared type.- Parameters:
pos
- the typedef declaration position.name
- the typedef declaration name.type
- the typedef type- Returns:
- a new type declaration with given name and declared type.
-