Module dev.civl.mc

Interface MallocStatement

All Superinterfaces:
Sourceable, Statement

public interface MallocStatement extends Statement
A statement for dynamic allocation of objects. Results from translation of an expression like p = (double*)$malloc(invalid input: '&h', sizeof(double)*10) Where h is an object of heap type. Executing such a statement results in the creation of an array of elements of the specified type (in this case, reals) and length (in this case, 10). The array object is inserted into the heap pointed to by the first argument.
  • Method Details

    • getMallocId

      int getMallocId()
      The malloc statements in the model are indexed, so each has unique ID number. This returns it
      Returns:
      the ID number of this malloc statement
    • getScopeExpression

      Expression getScopeExpression()
      The first argument to the $malloc function is an expression of type pointer-to-heap. This returns that expression. In the example, it is the expression invalid input: '&h'.
      Returns:
      the first argument to $malloc
    • getStaticElementType

      CIVLType getStaticElementType()
      Returns the static type of the elements that are to be allocated. Each malloc statement must have a static type associated to it. The type can usually be determined by examining the cast expression which wraps the $malloc. In the example, the type is "double".
      Returns:
      the type of elements to malloc.
    • getDynamicElementType

      dev.civl.sarl.IF.type.SymbolicType getDynamicElementType()
      This returns the dynamic (symbolic type) corresponding to the static element type. It is obtained by ignoring any array extent expressions. Hence if the static type is "array of float of length 3*n+1" the dynamic type will be "array of real". Since that dynamic type includes in its domain array of any length, it is an over-estimate of the types of elements that can be allocaged. In the example, the dynamic type returned would be the symbolic type "real"
      Returns:
      dynamic type corresonding to static element type
    • getDynamicObjectType

      dev.civl.sarl.IF.type.SymbolicArrayType getDynamicObjectType()
      The object is the thing that is allocated; it is an array of some number of elements of the specified type. This returns the dynamic type of the object (which is always an array type). In the example, it would be "array of real".
      Returns:
    • getSizeExpression

      Expression getSizeExpression()
      The second argument to the $malloc function is an integer expression specifying the size (number of bytes) to malloc. It is typically some multiple of an expression of the form "sizeof(t)". This method returns the argument. In the example, it would be the expression sizeof(double)*10
      Returns:
      the second argument to the $malloc statement, an integer-valued expression
    • getLHS

      LHSExpression getLHS()
      Returns the expression on the left-hand side of the assignment. In the example, this would be p. This expression will be assigned a pointer to the first element of the array object created by the malloc. It may be null, but this is unusual.
      Returns:
      the left hand side of the assignment
    • complete

      void complete(dev.civl.sarl.IF.type.SymbolicType dynamicElementType, dev.civl.sarl.IF.type.SymbolicArrayType dynamicObjectType)
      complete the type information of the malloc statement. This has to be done separatedly because it might involve the bundle type.
      Parameters:
      dynamicElementType - the dynamic element type
      dynamicObjectType - the dynamic object type