Interface Declaration

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).
  • 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

      Declaration withAttribute(String name, Constable... values)
      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 as getAttribute(name).isEmpty() will return true.
      Parameters:
      name - The attribute name
      values - More attribute values
      Returns:
      the Declaration with attributes
    • stripAttributes

      Declaration stripAttributes()
      Get a declaration without current attributes
      Returns:
      the Declatation without any attributes
    • getAttribute

      Optional<List<Constable>> getAttribute(String name)
      The values of the specified attribute.
      Parameters:
      name - The attribute to retrieve
      Returns:
      The list of values associate with this attribute
    • attributeNames

      Set<String> attributeNames()
      The attributes associated with this declaration
      Returns:
      The attributes associated with this declaration
    • accept

      <R, D> R accept(Declaration.Visitor<R,D> visitor, D data)
      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

      boolean equals(Object o)
      Compares the specified object with this Declaration for equality. Returns true if and only if the specified object is also a Declaration and both the declarations are equal.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to be compared for equality with this Declaration
      Returns:
      true if the specified object is equal to this Declaration
      See Also:
    • hashCode

      int hashCode()
      Returns the hash code value for this Declaration.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this Declaration.
      See Also:
    • constant

      static Declaration.Constant constant(Position pos, String name, Object value, Type type)
      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

      static Declaration.Variable globalVariable(Position pos, String name, Type type)
      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

      static Declaration.Variable field(Position pos, String name, Type type)
      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

      static Declaration.Variable bitfield(Position pos, String name, Type type, MemoryLayout layout)
      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

      static Declaration.Variable parameter(Position pos, String name, Type type)
      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

      static Declaration.Scoped toplevel(Position pos, Declaration... decls)
      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

      static Declaration.Scoped namespace(Position pos, String name, Declaration... decls)
      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

      static Declaration.Scoped struct(Position pos, String name, Declaration... decls)
      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

      static Declaration.Scoped union(Position pos, String name, Declaration... decls)
      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_

      static Declaration.Scoped class_(Position pos, String name, Declaration... decls)
      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_

      static Declaration.Scoped enum_(Position pos, String name, Declaration... decls)
      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

      static Declaration.Typedef typedef(Position pos, String name, Type type)
      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.