Class ArrayDeclaration


public final class ArrayDeclaration extends Declaration

Array Declaration.


Simula Standard: 5.2 Array declaration

  array-declaration = [ type ] ARRAY array-segment { , array-segment }
  
     array-segment = array-identifier { , array-identifier } "(" bound-pair-list ")"
     
        array-identifier = identifier
        
        bound-pair-list = bound-pair { , bound-pair }
        
           bound-pair = arithmetic-expression : arithmetic-expression 

An array declaration declares one or several identifiers to represent multi-dimensional arrays of subscripted variables and gives the dimensions of the arrays, the bounds of the subscripts, and the type of the variables.

The subscript bounds for any array are given in the first subscript brackets following the identifier of this array in the form of a bound pair list. Each bound pair gives the lower bound of a subscript followed by : followed by the upper bound. The bound pair list gives the bounds of all subscripts taken in order from left to right.

NOTE: An initial "-" in upper bound may follow : directly (cf. 1.3). The scanner will treat ":-" within parentheses (round brackets) as two separate symbols ":" and "-" thus solving this ambiguity in the syntax.

The dimension is given as the number of entries in the bound pair lists.

All arrays declared in one declaration are of the same quoted type. If no type declarator is given the type real is understood.

The expressions are evaluated in the same way as subscript expressions. This evaluation takes place once at each entrance into the block through the block head. The expressions cannot include any identifier that is declared, either explicitly or implicitly, in the same block head as the array in question.

An array has elements only when the values of all upper bounds are not smaller than those of the corresponding lower bounds. If any lower bound value is greater than the corresponding upper bound value, the array has no elements. An attempt to access an element of an empty array leads to a run-time error. The array may, however, be created at block entry and it may be passed as a parameter.

The value of an array identifier is the ordered set of values of the corresponding array of subscripted variables.

Examples

          integer array a(2:20)                      ! 19 elements;
          real array  q(-7:if c < 0 then 2 else 1)   ! 10 or 9 elements;
          array  a,b,c(7:n,2:m), s(-2:10)            ! any value of n or m legal;

Link to GitHub: Source File.

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

  • Constructor Details

    • ArrayDeclaration

      private ArrayDeclaration(String identifier, Type type, Vector<ArrayDeclaration.BoundPair> boundPairList)
      Create a new ArrayDeclaration
      Parameters:
      identifier - the array identifier
      type - the array type
      boundPairList - The list of BoundPair
    • ArrayDeclaration

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

    • expectArrayDeclaration

      static void expectArrayDeclaration(Type type, DeclarationList declarationList)

      Parse an array declaration and add it to the given declaration list.

      
      Syntax:
      
      ArrayDeclaration = [ Type ] ARRAY ArraySegment { , ArraySegment }
        ArraySegment = IdentifierList "(" BoundPairList ")"
      
      	IdentifierList = Identifier { , Identifier }
      
      	BoundPairList = BoundPair { , BoundPair }
      	   BoundPair = ArithmeticExpression : ArithmeticExpression
      
      

      Precondition: Type ARRAY is already read.

      Parameters:
      type - the array's type
      declarationList - the given declaration list
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • doJavaCoding

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

      public void doDeclarationCoding()
      Description copied from class: SyntaxClass
      Output possible declaration Java code.
      Overrides:
      doDeclarationCoding in class SyntaxClass
    • 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.
    • getFieldIdentifier

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

      public static ClassDesc getClassDesc(Type type)
      Get the ClassDescr.
      Parameters:
      type - array's type.
      Returns:
      the ClassDescr.
    • buildDeclarationCode

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

      private static void buildGetArrayField(Type type, Meaning meaning, DeclarationScope declaredIn, String arrayIdent, boolean isParameter, CodeBuilder codeBuilder)
      ClassFile coding utility: Build 'Get Array Field'
      Parameters:
      type - the array type.
      meaning - the meaning.
      declaredIn - the owner.
      arrayIdent - the array identifier.
      isParameter - true: array is a parameter.
      codeBuilder - the codeBuilder to use.
    • prepIndexing

      private static void prepIndexing(Vector<Expression> checkedParams, CodeBuilder codeBuilder)
      ClassFile coding utility: Prepare for indexing.
      Parameters:
      checkedParams - the checked parameters
      codeBuilder - the codeBuilder to use.
    • arrayPutElement

      public void arrayPutElement(VariableExpression var, boolean isParameter, Expression rhs, CodeBuilder codeBuilder)

      ClassFile coding utility: Build invoke ARRAY_putELEMENT.

      Example: A.putELEMENT(A.index(2,5,9),666);
      
       aload_0
       getfield      #7   // Field A:Lsimula/runtime/RTS_INTEGER_ARRAY;
      
       dup
      
       *** prepIndexing ***
       iconst_3			// boundPairList.size()
       newarray       int
       dup
       iconst_0
       iconst_2
       iastore
       dup
       iconst_1
       iconst_5
       iastore
       dup
       iconst_2
       bipush        9
       iastore
      
       invokevirtual #33  // Method simula/runtime/RTS_INTEGER_ARRAY.index:([I)I
      
       sipush        666
      
       invokevirtual #37  // Method simula/runtime/RTS_INTEGER_ARRAY.putELEMENT:(II)I
      
      Parameters:
      var - the variable
      isParameter - true: variable is a parameter
      rhs - expression.
      codeBuilder - the codeBuilder to use.
    • arrayPutElement

      public static void arrayPutElement(Meaning meaning, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder)
      ClassFile coding utility: Build invoke ARRAY_putELEMENT.
      Parameters:
      meaning - variable's meaning.
      arrayIdent - array's identifier
      isParameter - true: variable is a parameter
      checkedParams - checked parameters.
      rhs - expression.
      codeBuilder - the codeBuilder to use.
    • arrayPutElement2

      public static void arrayPutElement2(Meaning meaning, Vector<Expression> checkedParams, Expression rhs, CodeBuilder codeBuilder)
      ClassFile coding utility: Build invoke ARRAY_putELEMENT.
      Parameters:
      meaning - variable's meaning.
      checkedParams - checked parameters.
      rhs - expression.
      codeBuilder - the codeBuilder to use.
    • arrayGetElement

      public void arrayGetElement(VariableExpression var, boolean isParameter, CodeBuilder codeBuilder)
      ClassFile coding utility: Build invoke ARRAY_getELEMENT.
      Parameters:
      var - the variable
      isParameter - true: variable is a parameter
      codeBuilder - the codeBuilder to use.
    • arrayGetElement

      public static void arrayGetElement(Type type, String arrayIdent, boolean isParameter, Vector<Expression> checkedParams, Meaning meaning, DeclarationScope declaredIn, CodeBuilder codeBuilder)
      ClassFile coding utility: Build invoke ARRAY_getELEMENT.
      Parameters:
      type - array's type
      arrayIdent - array's identifier
      isParameter - true: variable is a parameter
      checkedParams - checked parameters.
      meaning - variable's meaning.
      declaredIn - array's owner
      codeBuilder - the codeBuilder to use.
    • arrayGetElement2

      public static void arrayGetElement2(Type type, String arrayIdent, Vector<Expression> checkedParams, CodeBuilder codeBuilder)
      ClassFile coding utility: Build invoke ARRAY_getELEMENT.
      Parameters:
      type - array's type
      arrayIdent - array's identifier
      checkedParams - checked 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 ArrayDeclaration readObject(AttributeInputStream inpt) throws IOException
      Read and return an ArrayDeclaration object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the object read from the stream.
      Throws:
      IOException - if something went wrong.