ArrayInitializer (API documentation of hlt.language packages)
Date: 2013-01-30

hlt.language.design.kernel

## Class ArrayInitializer

- java.lang.Object
- - hlt.language.design.kernel.Expression
  - - hlt.language.design.kernel.ProtoExpression
    - - hlt.language.design.kernel.ArrayInitializer

- All Implemented Interfaces:
    Locatable

      public class ArrayInitializer
      extends ProtoExpression

  This is the class for a special kind of expressions used essentially for initializing an array with a specified dimension vector from an expression that evaluates to an array whose dimension vectors is almost identical to that of the specified one. By "almost", we mean that:
  - where an integer is expected as the specified dimension's indexable, the array's corresponding indexable must be the same integer;
  - where a set is expected as the specified dimension's indexable, the array's corresponding indexable must be either an integer that must be equal to the set's size, or the same set;
  - where an int range is expected as the specified dimension's indexable, the array's corresponding indexable must be either an integer that must be equal to the range's size, or the same range, or a set of integers that contains all the elements of the range.
  The type of the elements of the specified array must correspond to the one specified as the element type in this expression.

- - ### Field Summary

    - ### Fields inherited from class hlt.language.design.kernel.Expression

      `VOID_ASSIGNMENTS`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Expression` | `array()`
    `void` | `compile(Compiler compiler)` To compile an `ArrayInitializer`, we: compile the array, compile the dimensions (ints are systematically boxed so that the value of a dimension's indexable is always popped off the object stack), compile the number of dimensions, compile the extension depth, generate an `ARRAY_INITIALIZE`.
    `static Let` | `construct(Type elementType, java.util.AbstractList dimension, Expression array)` Returns a `Let` wrapping a new array initializer constructed with the specified parameters.
    `Expression` | `copy()` Returns a deep copy of this expression.
    `Expression[]` | `dimension()`
    `Type` | `elementType()`
    `int` | `numberOfSubexpressions()` Returns the number of subexpressions
    `void` | `setCheckedType()` This method sets the final unambiguously checked type of this expression, possibly along with other final information that may be needed by the compiler for generating code.
    `Expression` | `setSubexpression(int n, Expression expression)` Returns this expression after setting its n-th subexpression to the specified expression; if there is no subexpression at the given position, this throws a `NoSuchSubexpressionException`
    `Expression` | `subexpression(int n)` Returns the n-th subexpression of this expression; if there is no subexpression at the given position, this throws a `NoSuchSubexpressionException`
    `java.lang.String` | `toString()`
    `void` | `typeCheck(TypeChecker typeChecker)` Type-checking proceeds as follows: each dimension expression is type-checked to have an index set type; this is then checked as an array type corresponding to the element type and the dimensions' types; the array is type-checked to be an array of the same number of dimensions as this, each dimension type is verified to be such that: where this dimension type is int, that of the array must be int too; where this dimension type is set, that of the array must be either int, or set of same base type; where this dimension type is int range, that of the array must be either int, int range, or a set of int.
    `Expression` | `typedCopy()` Returns a deep copy of this expression this and all its subexpressions share the same type as their copy's counterparts.

    - ### Methods inherited from class hlt.language.design.kernel.ProtoExpression

      `checkedType, setCheckedType, setType, type, typeRef`

    - ### Methods inherited from class hlt.language.design.kernel.Expression

      `addType, addTypes, boxSort, containsFreeName, enclosingScope, extent, getEnd, getStart, isConstant, isEquality, isFalse, isHiddenSlicing, isNull, isSelector, isSlicing, isTrue, isVoid, locationString, otherTypes, parameters, sanitizeNames, sanitizeSorts, setCheckedTypeLocked, setEnd, setExtent, setOtherTypes, setStart, shiftOffsets, shiftOffsets, sort, substitute, typeCheck, typeCheck, typeCheckLocked`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### copy

          public final Expression copy()

      Description copied from class: `Expression`
      Returns a deep copy of this expression. The types are not not copied. NB: This is a convenience for building expressions that should be used exclusively before any processing (in particular sanitizing), is done on this expression.
      Specified by:
        `copy` in class `Expression`

    - #### typedCopy

          public final Expression typedCopy()

      Description copied from class: `Expression`
      Returns a deep copy of this expression this and all its subexpressions share the same type as their copy's counterparts. NB: This is a convenience for building expressions that should be used exclusively before any processing (in particular sanitizing), is done on this expression.
      Specified by:
        `typedCopy` in class `Expression`

    - #### construct

          public static final Let construct(Type elementType,
                      java.util.AbstractList dimension,
                      Expression array)

      Returns a `Let` wrapping a new array initializer constructed with the specified parameters.

    - #### numberOfSubexpressions

          public final int numberOfSubexpressions()

      Description copied from class: `Expression`
      Returns the number of subexpressions
      Overrides:
        `numberOfSubexpressions` in class `Expression`

    - #### subexpression

          public final Expression subexpression(int n)
                                         throws NoSuchSubexpressionException

      Description copied from class: `Expression`
      Returns the n-th subexpression of this expression; if there is no subexpression at the given position, this throws a `NoSuchSubexpressionException`
      Overrides:
        `subexpression` in class `Expression`
      Throws:
        `NoSuchSubexpressionException`

    - #### setSubexpression

          public final Expression setSubexpression(int n,
                                    Expression expression)
                                            throws NoSuchSubexpressionException

      Description copied from class: `Expression`
      Returns this expression after setting its n-th subexpression to the specified expression; if there is no subexpression at the given position, this throws a `NoSuchSubexpressionException`
      Overrides:
        `setSubexpression` in class `Expression`
      Throws:
        `NoSuchSubexpressionException`

    - #### elementType

          public final Type elementType()

    - #### dimension

          public final Expression[] dimension()

    - #### array

          public final Expression array()

    - #### setCheckedType

          public final void setCheckedType()

      Description copied from class: `Expression`
      This method sets the final unambiguously checked type of this expression, possibly along with other final information that may be needed by the compiler for generating code.
      Specified by:
        `setCheckedType` in class `Expression`

    - #### typeCheck

          public final void typeCheck(TypeChecker typeChecker)
                               throws TypingErrorException

      Type-checking proceeds as follows:
      1. each dimension expression is type-checked to have an index set type;
      2. this is then checked as an array type corresponding to the element type and the dimensions' types;
      3. the array is type-checked to be an array of the same number of dimensions as this,
      4. each dimension type is verified to be such that:
         - where this dimension type is int, that of the array must be int too;
         - where this dimension type is set, that of the array must be either int, or set of same base type;
         - where this dimension type is int range, that of the array must be either int, int range, or a set of int.
      Specified by:
        `typeCheck` in class `Expression`
      Throws:
        `TypingErrorException`

    - #### compile

          public final void compile(Compiler compiler)

      To compile an `ArrayInitializer`, we:
      1. compile the array,
      2. compile the dimensions (ints are systematically boxed so that the value of a dimension's indexable is always popped off the object stack),
      3. compile the number of dimensions,
      4. compile the extension depth,
      5. generate an `ARRAY_INITIALIZE`.
      Specified by:
        `compile` in class `Expression`

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`