org.problets.domain.model.variable
Class PtrModel

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.AccessVarModel
              extended by org.problets.domain.model.variable.PtrModel
All Implemented Interfaces:
java.lang.Cloneable

public class PtrModel
extends AccessVarModel
implements java.lang.Cloneable

Model for a pointer variable

Author:
Amruth Kumar

Field Summary
static int IDENTITY
           
static java.lang.String NOT_DECLARED
           
static java.lang.String NOT_INITIALIZED
           
static java.lang.String OUT_OF_SCOPE
           
static java.lang.String POINTEE_DEALLOCATED
           
static java.lang.String POINTEE_OUT_OF_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, 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
PtrModel(int index, java.lang.String inputType)
          We look for variables in the correct ordinality in symbolTable
PtrModel(java.lang.String inName, java.lang.String inputType)
          Constructor used by Expression to create a pointer of a given name when creating a static expression for printing purposes
 
Method Summary
 void addToAssignees(java.lang.String template, ActivationRecord activationRecord)
          Handles generating code for the following cases: Address of a variable assigned to a pointer Dynamic allocation to a pointer with no value/initialization value/array An expression to a pointer Since we do not assign to pointers at code generation time, we cannot say to which variable the pointer points.
 java.lang.Object clone()
          Returns a clone of this object, and provides the basis for cloning of derived classes
 void explainObject(StackModel stack, HeapModel heap, Behavior behavior, java.lang.String statement, int event, int lineNumber, boolean abbreviated)
          -----------------------------------------------------
 void explainProcess(RunEnv runEnv, Behavior behavior, java.lang.String statement, int event, int lineNumber)
          For each step (e.g., print), If the step has been properly set up, (e.g., pointer points to a var which is initialized) Gives the full-fledged explanation Else, (e.g., pointer is not yet assigned, is out of scope, not yet declared, etc.) Gives an "Attempt was made" explanation
 Scope getAssignScope()
          Returns a reference to the scope where the pointer was assigned
 void getCode(java.util.Vector codeText, java.lang.String codeType, java.lang.String template, int lineNumber)
          Assembles the code for the pointer that fits the occasion in the Vector passed as a parameter
 boolean getDynamicallyAllocated()
          Returns whether this pointer was dynamically allocated
 java.lang.Object getLValue()
          Returns a reference to the object to which the pointer points
 java.lang.String[] getPossibleErrors()
          Returns the possible errors for pointers May want to post-process based on Student Model
 Value getValue()
          Returns the DEreferenced value of the pointer
static void main(java.lang.String[] args)
          -----------------------------------------------------
 void print()
          -----------------------------------------------------
 void resetDynamicallyAllocated()
          Resets that the pointer was dynamically allocated
 void resetFlags()
          Resets the flags for the pointer variable
 void resetValue()
          Sets pointer to null
 void setDeclared()
          Sets the pointer to declared
 void setDynamicallyAllocated()
          Sets that the pointer was dynamically allocated
 void setValue(AbstractVarModel in_value, Scope in_scope)
          Sets the value of the pointer - value may be either a VarModel or AnonVarModel object - hence AbstractVarModel parameter
 void setValue(java.lang.Object inValue)
          Used by Assignment Expression
 
Methods inherited from class org.problets.domain.model.variable.AccessVarModel
getAssignees
 
Methods inherited from class org.problets.domain.model.variable.AbstractVarModel
getAllocated, getAssigned, getDeclared, getMetaDataType, getName, getType, getValueDifference, resetAllocated, resetDeclared, setAllocated
 
Methods inherited from class org.problets.domain.model.DomainModel
getId, getIdName, grade
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTITY

public static final int IDENTITY
See Also:
Constant Field Values

NOT_DECLARED

public static final java.lang.String NOT_DECLARED
See Also:
Constant Field Values

OUT_OF_SCOPE

public static final java.lang.String OUT_OF_SCOPE
See Also:
Constant Field Values

NOT_INITIALIZED

public static final java.lang.String NOT_INITIALIZED
See Also:
Constant Field Values

POINTEE_DEALLOCATED

public static final java.lang.String POINTEE_DEALLOCATED
See Also:
Constant Field Values

POINTEE_OUT_OF_SCOPE

public static final java.lang.String POINTEE_OUT_OF_SCOPE
See Also:
Constant Field Values
Constructor Detail

PtrModel

public PtrModel(int index,
                java.lang.String inputType)
We look for variables in the correct ordinality in symbolTable

Parameters:
-

PtrModel

public PtrModel(java.lang.String inName,
                java.lang.String inputType)
Constructor used by Expression to create a pointer of a given name when creating a static expression for printing purposes

Method Detail

clone

public java.lang.Object clone()
Description copied from class: DomainModel
Returns a clone of this object, and provides the basis for cloning of derived classes

Overrides:
clone in class AbstractVarModel

getValue

public Value getValue()
Returns the DEreferenced value of the pointer

Overrides:
getValue in class AbstractVarModel
Parameters:
-
Returns:

getLValue

public java.lang.Object getLValue()
Returns a reference to the object to which the pointer points

Parameters:
-
Returns:

getAssignScope

public Scope getAssignScope()
Returns a reference to the scope where the pointer was assigned

Parameters:
-
Returns:

getDynamicallyAllocated

public boolean getDynamicallyAllocated()
Returns whether this pointer was dynamically allocated

Parameters:
-
Returns:

resetFlags

public void resetFlags()
Resets the flags for the pointer variable

Overrides:
resetFlags in class AbstractVarModel
Parameters:
-

setDeclared

public void setDeclared()
Sets the pointer to declared

Overrides:
setDeclared in class AbstractVarModel
Parameters:
none -

setValue

public void setValue(AbstractVarModel in_value,
                     Scope in_scope)
Sets the value of the pointer - value may be either a VarModel or AnonVarModel object - hence AbstractVarModel parameter

Parameters:
-

setValue

public void setValue(java.lang.Object inValue)
Description copied from class: AbstractVarModel
Used by Assignment Expression

Overrides:
setValue in class AbstractVarModel

resetValue

public void resetValue()
Sets pointer to null

Parameters:
-

setDynamicallyAllocated

public void setDynamicallyAllocated()
Sets that the pointer was dynamically allocated

Parameters:
-

resetDynamicallyAllocated

public void resetDynamicallyAllocated()
Resets that the pointer was dynamically allocated

Parameters:
-

addToAssignees

public void addToAssignees(java.lang.String template,
                           ActivationRecord activationRecord)
Handles generating code for the following cases: Address of a variable assigned to a pointer Dynamic allocation to a pointer with no value/initialization value/array An expression to a pointer Since we do not assign to pointers at code generation time, we cannot say to which variable the pointer points. Since the following is possible; int * ptr = & count; while( true ) { cout << *ptr; // What pointee object should be included here? ptr = & index; } we cannot figure out in getCode() all the variables to which a pointer points. Instead, we will do this in the constructor, i.e., every time a pointer is initialized/ assigned, we add the variable/anonymous variable assigned to the pointer to an assigneeVector. During getCode(), for statements printing pointer variables, we will add all the elements in assigneeVector to codeLineObjects.

Overrides:
addToAssignees in class AccessVarModel

getCode

public void getCode(java.util.Vector codeText,
                    java.lang.String codeType,
                    java.lang.String template,
                    int lineNumber)
Assembles the code for the pointer that fits the occasion in the Vector passed as a parameter

Specified by:
getCode in class AbstractVarModel
Parameters:
-

getPossibleErrors

public java.lang.String[] getPossibleErrors()
Returns the possible errors for pointers May want to post-process based on Student Model

Specified by:
getPossibleErrors in class AbstractVarModel

explainProcess

public void explainProcess(RunEnv runEnv,
                           Behavior behavior,
                           java.lang.String statement,
                           int event,
                           int lineNumber)
For each step (e.g., print), If the step has been properly set up, (e.g., pointer points to a var which is initialized) Gives the full-fledged explanation Else, (e.g., pointer is not yet assigned, is out of scope, not yet declared, etc.) Gives an "Attempt was made" explanation

Specified by:
explainProcess in class AbstractVarModel
Parameters:
-

explainObject

public void explainObject(StackModel stack,
                          HeapModel heap,
                          Behavior behavior,
                          java.lang.String statement,
                          int event,
                          int lineNumber,
                          boolean abbreviated)
-----------------------------------------------------

Specified by:
explainObject in class AbstractVarModel
Parameters:
-

main

public static void main(java.lang.String[] args)
-----------------------------------------------------

Parameters:
-

print

public void print()
-----------------------------------------------------

Specified by:
print in class AbstractVarModel
Parameters:
-