org.problets.domain.model.variable.aggregate
Class ArrayModel

java.lang.Object
  extended by org.problets.domain.model.DomainModel
      extended by org.problets.domain.model.variable.AbstractVarModel
          extended by org.problets.domain.model.variable.aggregate.AggregateVarModel
              extended by org.problets.domain.model.variable.aggregate.ArrayModel
All Implemented Interfaces:
java.lang.Cloneable

public class ArrayModel
extends AggregateVarModel
implements java.lang.Cloneable

Class: ArrayModel Purpose: Represents an array of AbstractVarModel objects


Field Summary
static java.lang.String NOT_ALLOCATED
          Error to occur when a reference is made to unallocated array
static java.lang.String NOT_DECLARED
          Error to occur when array is accessed before it is declared
static java.lang.String NOT_INITIALIZED
          Error to occur when array is referenced before it is initialized
static java.lang.String OUT_OF_BOUNDS
          Error to occur in case of out of bounds access.
static java.lang.String OUT_OF_SCOPE
          Error to occur when array is accessed out of it's scope
 
Fields inherited from class org.problets.domain.model.DomainModel
BOOLEAN, BREAKPOINT, CHARACTER, DOUBLE_PRECISION_REAL, ERROR_TYPE, EVAL_STATUS, expACTION, expASSIGNMENT, expAUTO_DEALLOCATION, expCALL, expCONDITION, expDECLARATION, expDEREFERENCING, expDYNAMIC_ALLOCATION, expDYNAMIC_ALLOCATION_INITIALIZATION, expDYNAMIC_DEALLOCATION, expELSE_CLAUSE, expERROR, expEXECUTION, expIF_CLAUSE, expINITIALIZATION, expINPUT, expPARAMETER_PASSING, expPRINT, expQUESTIONABLE, expREFERENCING, expRETURN, expRUNTIME_ERROR, expSEMANTIC_ERROR, expSYNTAX_ERROR, expUPDATE, IDENTITY, MAX_OBJECT_IDENTITY, MIN_OBJECT_IDENTITY, QUADRUPLE_PRECISION_REAL, RUNTIME_ERROR, SEMANTIC_ERROR, SIGNED_INTEGER, SIGNED_LONG, SIGNED_SHORT, SINGLE_PRECISION_REAL, SYNTAX_ERROR, UNDEFINED_TYPE, UNSIGNED_INTEGER, UNSIGNED_LONG, UNSIGNED_SHORT, WARNING
 
Constructor Summary
ArrayModel(int index, java.lang.String inputType)
          Used for null activationRecords.
ArrayModel(int index, java.lang.String inputType, java.lang.String sizeString, java.lang.String initializationList, ActivationRecord activationRecord)
          Creates an array with a random name
 
Method Summary
 void assignAll(Value value)
          Assigns each of the elements in the array to a value
 java.lang.Object clone()
          Clones the array
static void cloneElementValues(ArrayModel toModel, ArrayModel fromModel)
          Sets the elements of the array to clones of the given array's values
static java.util.Vector createSubscriptExprVector(java.lang.String subscriptString, ActivationRecord activationRecord)
          Creates an expression for each subscript and returns them in a vector
 boolean equalElementValues(ArrayModel a_model)
          Determines if this array has the same values as the to compare against
 void explainObject(StackModel stack, HeapModel heap, Behavior behavior, java.lang.String statement, int event, int lineNumber, boolean abbreviated)
          To generate error messages for arrays after execution.
 void explainProcess(RunEnv runEnv, Behavior behavior, java.lang.String statement, int event, int lineNumber)
          Executes a statement and provides an explanation based on what type of statement was executed.
 java.util.Vector getArrayDimensions()
          Returns the dimensions of the array in a vector.
static java.util.Vector getAskAndTells(java.lang.String template)
          Returns a vector of variables in a template that contain an #ask# or #tell# command
 void getCode(java.util.Vector codeText, java.lang.String codeType, java.lang.String template, int lineNumber)
          Generates code for the template before execution
 java.lang.Object getElement(int index)
          Gets an element in the array at a specified index
 AbstractVarModel getElement(java.lang.String subscriptStringTemplate, ActivationRecord activationRecord)
          returns the element at the given string of subscripts.
static java.lang.String getLHSSubscripts(java.lang.String statement, int startPosition)
          Returns the bracket string on the left side of an assignment statement.
 java.lang.String[] getPossibleErrors()
          Returns the possible errors for arrays.
 int getSize()
          Returns the size of the array
 int getTotalElementCount()
          Returns the number of elements in an array, whether it is one or multi-dimensional
 java.util.Vector getValueDifference(AbstractVarModel currentModel, int line)
          Returns a vector of ValueDifference objects containing the corresponding elements of this array and the currentModel array.
static void main(java.lang.String[] args)
          Method for debugging
 void print()
          Prints to standard output the elements of the array
 java.lang.String printArrayElements(java.lang.String elementDelimiter)
          Returns a string containing the names of the elements in the array followed by their values.
 java.lang.String printArrayTable()
          Prints the array's elements in a table format.
 void resetAllocated()
          Overrides super resetAllocated to reset allocation for entire array
 void resetDeclared()
          Overrides super resetAllocated to reset allocation for entire array
 void resetFlags()
          Overrides super.resetFlags to reset the array recursively
 void setAllocated()
          Overrides super setAllocated to allocate entire array
 void setDeclared()
          Overrides super setDeclared to declare entire array
 void setValue(Value value)
          Overrides super setValue to set the value to each element in the array
 java.lang.String toString()
           
 
Methods inherited from class org.problets.domain.model.variable.AbstractVarModel
getAllocated, getAssigned, getDeclared, getMetaDataType, getName, getType, getValue, setValue
 
Methods inherited from class org.problets.domain.model.DomainModel
getId, getIdName, grade
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_ALLOCATED

public static final java.lang.String NOT_ALLOCATED
Error to occur when a reference is made to unallocated array

See Also:
Constant Field Values

NOT_DECLARED

public static final java.lang.String NOT_DECLARED
Error to occur when array is accessed before it is declared

See Also:
Constant Field Values

OUT_OF_SCOPE

public static final java.lang.String OUT_OF_SCOPE
Error to occur when array is accessed out of it's scope

See Also:
Constant Field Values

NOT_INITIALIZED

public static final java.lang.String NOT_INITIALIZED
Error to occur when array is referenced before it is initialized

See Also:
Constant Field Values

OUT_OF_BOUNDS

public static final java.lang.String OUT_OF_BOUNDS
Error to occur in case of out of bounds access. If language supports runtime bounds checking, then the error should be prepended by RUNIME_ERROR, else should be prepended by SEMANTIC_ERROR

See Also:
Constant Field Values
Constructor Detail

ArrayModel

public ArrayModel(int index,
                  java.lang.String inputType)
Used for null activationRecords. (Never expected to be used in a valid context)

Parameters:
index - used to get the random name of the array
inputType - the template data type of the array

ArrayModel

public ArrayModel(int index,
                  java.lang.String inputType,
                  java.lang.String sizeString,
                  java.lang.String initializationList,
                  ActivationRecord activationRecord)
Creates an array with a random name

Parameters:
index - index to the symbol table - used to get the random name of the array
inputType - the template data type of the array
sizeString - holds a consecutive string of sizes enclosed in square-brackets
initializationList - holds initializers for the array elements in the form of a comma seperated list enclosed in curly-braces. This is a C-style array initializer list, and should be left empty if there is no initializer list.
activationRecord - the activation record for the current scope
Method Detail

clone

public java.lang.Object clone()
Clones the array

Overrides:
clone in class AggregateVarModel
Returns:
the cloned array

cloneElementValues

public static void cloneElementValues(ArrayModel toModel,
                                      ArrayModel fromModel)
Sets the elements of the array to clones of the given array's values

Parameters:
toModel - the ArrayModel to set it's values to the clones of fromModel
fromModel - the ArrayModel that will have it's values cloned

equalElementValues

public final boolean equalElementValues(ArrayModel a_model)
Determines if this array has the same values as the to compare against

Parameters:
a_model - the array to compare against
Returns:
true if both arrays have the same element values

getTotalElementCount

public int getTotalElementCount()
Returns the number of elements in an array, whether it is one or multi-dimensional


getSize

public int getSize()
Returns the size of the array

Returns:
size the size of the array

getElement

public AbstractVarModel getElement(java.lang.String subscriptStringTemplate,
                                   ActivationRecord activationRecord)
returns the element at the given string of subscripts. If and error is present in the subscripts (such as out of bounds), an ErrorVarModel is returned.

Parameters:
subscriptStringTemplate - the string of subscripts
activationRecord - the activation record for the current scope
Returns:
the element at the subscripts

getElement

public java.lang.Object getElement(int index)
Gets an element in the array at a specified index

Parameters:
index - the index of the element requested
Returns:
the element requested

getPossibleErrors

public java.lang.String[] getPossibleErrors()
Returns the possible errors for arrays.

Specified by:
getPossibleErrors in class AbstractVarModel
Returns:
The errors for arrays

getValueDifference

public java.util.Vector getValueDifference(AbstractVarModel currentModel,
                                           int line)
Returns a vector of ValueDifference objects containing the corresponding elements of this array and the currentModel array. Overrides AbstractVarModel.getValueDifference().

Overrides:
getValueDifference in class AbstractVarModel
Parameters:
currentModel - the array containing all the current values.
line - the line number of the value difference
Returns:
A Vector ValueDifference objects

getArrayDimensions

public java.util.Vector getArrayDimensions()
Returns the dimensions of the array in a vector.

Returns:
the vector of dimensions

setDeclared

public void setDeclared()
Overrides super setDeclared to declare entire array

Overrides:
setDeclared in class AbstractVarModel

setAllocated

public void setAllocated()
Overrides super setAllocated to allocate entire array

Overrides:
setAllocated in class AbstractVarModel

resetDeclared

public void resetDeclared()
Overrides super resetAllocated to reset allocation for entire array

Overrides:
resetDeclared in class AbstractVarModel

resetAllocated

public void resetAllocated()
Overrides super resetAllocated to reset allocation for entire array

Overrides:
resetAllocated in class AbstractVarModel

resetFlags

public void resetFlags()
Overrides super.resetFlags to reset the array recursively

Overrides:
resetFlags in class AbstractVarModel

setValue

public void setValue(Value value)
Overrides super setValue to set the value to each element in the array


assignAll

public void assignAll(Value value)
Assigns each of the elements in the array to a value

Parameters:
value - the value to set each element to

getCode

public void getCode(java.util.Vector codeText,
                    java.lang.String codeType,
                    java.lang.String template,
                    int lineNumber)
Generates code for the template before execution

Specified by:
getCode in class AbstractVarModel
Parameters:
codeText - the actual code
codeType - the type of code
template - the template to create the code for
lineNumber - the line number of the statement

createSubscriptExprVector

public static java.util.Vector createSubscriptExprVector(java.lang.String subscriptString,
                                                         ActivationRecord activationRecord)
Creates an expression for each subscript and returns them in a vector

Parameters:
subscriptString - the string of subscripts
activationRecord - the activation record for the current scope
Returns:
the vector of subscript expressions

explainProcess

public void explainProcess(RunEnv runEnv,
                           Behavior behavior,
                           java.lang.String statement,
                           int event,
                           int lineNumber)
Executes a statement and provides an explanation based on what type of statement was executed.

Specified by:
explainProcess in class AbstractVarModel
Parameters:
runEnv - The run time environment
behavior - The current behavior
statement - The statement to execute
event - The event of execution (ex. initialization, assignment, referencing,...)
lineNumber - The line number of the statement

explainObject

public void explainObject(StackModel stack,
                          HeapModel heap,
                          Behavior behavior,
                          java.lang.String statement,
                          int event,
                          int lineNumber,
                          boolean abbreviated)
To generate error messages for arrays after execution.

Specified by:
explainObject in class AbstractVarModel
Parameters:
stack - the runtime stack
heap - the runtime heap
behavior - the current behavior
statement - the statement
event - the execution event
lineNumber - the line number of the statement
abbreviated - switch for abreviated explanations

getLHSSubscripts

public static java.lang.String getLHSSubscripts(java.lang.String statement,
                                                int startPosition)
Returns the bracket string on the left side of an assignment statement. If the statement is not an assignment, the first found bracket string is returned.

Parameters:
statement - The assignment statement
startPosition - The index to begin searching from
Returns:
The LHS bracket string

print

public void print()
Prints to standard output the elements of the array

Specified by:
print in class AbstractVarModel

printArrayElements

public java.lang.String printArrayElements(java.lang.String elementDelimiter)
Returns a string containing the names of the elements in the array followed by their values.

Parameters:
elementDelimiter - the string to put between elements
Returns:
the elements and their values

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printArrayTable

public java.lang.String printArrayTable()
Prints the array's elements in a table format.

Returns:
a string with a table representation of the array

getAskAndTells

public static java.util.Vector getAskAndTells(java.lang.String template)
Returns a vector of variables in a template that contain an #ask# or #tell# command

Parameters:
template - the template to search
Returns:
the vector of ask and tell variables

main

public static void main(java.lang.String[] args)
Method for debugging

Parameters:
args - arguments