Class SimpleVariableDeclaration

Direct Known Subclasses:
LabelDeclaration

public class SimpleVariableDeclaration extends Declaration

Simple Variable Declaration.


Simula Standard: 5.1 Simple variable declarations

 simple-variable-declaration
       =  type  type-list

   type-list
       =  type-list-element  { , type-list-element }

   type-list-element
       =  identifier
       |  constant-element 

   constant-element
       =  identifier  "="  value-expression
       |  identifier  "="  text-expression
  

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • constant

      protected boolean constant
      Constant indicator. Is used to prevent assignment of a new value.
    • constantElement

      public Expression constantElement
      The constant initial value.
  • Constructor Details

    • SimpleVariableDeclaration

      public SimpleVariableDeclaration(Type type, String identifier)
      Create a new SimpleVariableDeclaration.
      Parameters:
      type - the variable type
      identifier - the variable identifier
    • SimpleVariableDeclaration

      SimpleVariableDeclaration(Type type, String identifier, boolean constant, Constant constantElement)
      Create a new SimpleVariableDeclaration.
      Parameters:
      type - the variable type
      identifier - the variable identifier
      constant - the constant indicator
      constantElement - a constant initial value
    • SimpleVariableDeclaration

      public SimpleVariableDeclaration()
      Default constructor used by Attribute File I/O
  • Method Details

    • isConstant

      public boolean isConstant()
      Constant indicator. Is used to prevent assignment of a new value.
      Returns:
      the constant indicator
    • expectSimpleVariable

      static void expectSimpleVariable(Type type, DeclarationList declarationList)

      Parse a simple variable declaration.

      
      Syntax:
      
       simple-variable-declaration
             =  type  type-list
      
         type-list
             =  type-list-element  { , type-list-element }
      
         type-list-element
             =  identifier
             |  constant-element 
      
         constant-element
             =  identifier  "="  value-expression
             |  identifier  "="  text-expression
        
      

      Precodition: Type is already read.

      Parameters:
      type - the variable type
      declarationList - the declaration list to update
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • doDeclarationCoding

      public void doDeclarationCoding()
      Description copied from class: SyntaxClass
      Output possible declaration Java code.
      Overrides:
      doDeclarationCoding in class SyntaxClass
    • toJavaCode

      public String toJavaCode()
      Description copied from class: SyntaxClass
      Generate Java code for this Syntax Class.
      Overrides:
      toJavaCode in class SyntaxClass
      Returns:
      Java code
    • getFieldRefEntry

      public FieldRefEntry getFieldRefEntry(ConstantPoolBuilder pool)
      ClassFile coding utility: get FieldRefEntry of this SimpleVariable.
      Parameters:
      pool - the ConstantPoolBuilder to use.
      Returns:
      the FieldRefEntry of this SimpleVariable.
    • getFieldIdentifier

      public String getFieldIdentifier()
      Description copied from class: Declaration
      ClassFile coding utility: get getFieldIdentifier.
      Overrides:
      getFieldIdentifier in class Declaration
      Returns:
      the resulting String.
    • buildDeclaration

      public void buildDeclaration(ClassBuilder classBuilder, BlockDeclaration encloser)
      Description copied from class: Declaration
      Output Java ByteCode. Treat Declaration.
      Overrides:
      buildDeclaration in class Declaration
      Parameters:
      classBuilder - the classBuilder to use.
      encloser - the owning block.
    • buildInitAttribute

      public void buildInitAttribute(CodeBuilder codeBuilder)
      Description copied from class: Declaration
      Output Java ByteCode. Build init code for an Attribute.
      Overrides:
      buildInitAttribute in class Declaration
      Parameters:
      codeBuilder - the codeBuilder to use.
    • printTree

      public void printTree(int indent, Object head)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
      head - the head of the tree.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeObject

      public void writeObject(AttributeOutputStream oupt) throws IOException
      Description copied from class: SyntaxClass
      Write a SyntaxClass object to a AttributeOutputStream.
      Overrides:
      writeObject in class SyntaxClass
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static SimpleVariableDeclaration readObject(AttributeInputStream inpt) throws IOException
      Read and return an object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the object read from the stream.
      Throws:
      IOException - if something went wrong.