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

hlt.language.design.kernel

## Class ArrayExtension

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

- All Implemented Interfaces:
    Locatable

      public class ArrayExtension
      extends ProtoExpression

  This is the class denoting an array literal - i.e., expressions enumerating elements that comprise the extension of an array or map. This is always a unidimensional array. In addition, an array extension may be constrained by an index set coming from an `ArrayInitializer`. In this case, care must be taken to reconcile the contents of the extension with the constraining index set. This somewhat complicates (1) type-checking as it must proceed to verify that indexing types are such that they can be made to agree, and (2) compiling that must generate instructions to perform appropriate runtime tests.

- - ### Field Summary

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

      `VOID_ASSIGNMENTS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ArrayExtension(java.util.AbstractList elements, java.util.AbstractList indices)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `compile(Compiler compiler)` compile the elements compile the size if there is no index set constraint: compile the indexable, if there is one generate `MAKE_[ARRAY,MAP]_[I,R,O]` if there is an index set constraint: compile the index set generate size tests and conversion check for index set generate `MAKE_ARRAY_[I,R,O]` or `SHUFFLE_MAP_[I,R,O]` depending on whether or not indexables have been reconciled with a permutation array
    `Expression` | `copy()` Returns a deep copy of this expression.
    `Expression[]` | `elements()`
    `Expression` | `indexable()`
    `Expression` | `indexSet()`
    `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.
    `void` | `setIndexSet(Expression indexSet)`
    `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`
    `int` | `size()`
    `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)` Typechecking proceeds as follows: type-check all the elements to have the same type; if there is no indexable (i.e., this is not a map) force the indexer type to be int else (i.e., this is a set-indexed map) typecheck the indexable as a set unify the indexable type and the indexer type if there is an index set (i.e., this is constrained by an `ArrayInitializer`) typecheck the index set to be a legal indexing type unify the base type of the index set type with the indexable' base type if there is one type-check this array extension as an array with the extension's element type as array base type, and the array's indexer type as indexer type.
    `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`

- - ### Constructor Detail

    - #### ArrayExtension

          public ArrayExtension(java.util.AbstractList elements,
                        java.util.AbstractList indices)

  - ### 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`

    - #### setIndexSet

          public final void setIndexSet(Expression indexSet)

    - #### size

          public final int size()

    - #### 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`

    - #### elements

          public final Expression[] elements()

    - #### indexable

          public final Expression indexable()

    - #### indexSet

          public final Expression indexSet()

    - #### 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

      Typechecking proceeds as follows:
      1. type-check all the elements to have the same type;
      2. if there is no indexable (i.e., this is not a map)
         - force the indexer type to be int
      3. else (i.e., this is a set-indexed map)
         - typecheck the indexable as a set
         - unify the indexable type and the indexer type
      4. if there is an index set (i.e., this is constrained by an `ArrayInitializer`)
         - typecheck the index set to be a legal indexing type
         - unify the base type of the index set type with the indexable' base type if there is one
      5. type-check this array extension as an array with the extension's element type as array base type, and the array's indexer type as indexer type.
      Specified by:
        `typeCheck` in class `Expression`
      Throws:
        `TypingErrorException`

    - #### compile

          public final void compile(Compiler compiler)

      1. compile the elements
      2. compile the size
      3. if there is no index set constraint:
         1. compile the indexable, if there is one
         2. generate `MAKE_[ARRAY,MAP]_[I,R,O]`
         if there is an index set constraint:
         1. compile the index set
         2. generate size tests and conversion check for index set
         3. generate `MAKE_ARRAY_[I,R,O]` or `SHUFFLE_MAP_[I,R,O]` depending on whether or not indexables have been reconciled with a permutation array
      Specified by:
        `compile` in class `Expression`

    - #### toString

          public final java.lang.String toString()

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