org.problets.domain.model.implement
Class ActivationRecord

java.lang.Object
  extended by org.problets.domain.model.implement.ActivationRecord
All Implemented Interfaces:
java.lang.Cloneable

public class ActivationRecord
extends java.lang.Object
implements java.lang.Cloneable

Creates and maintains the activation record for a Scope object. The activation record holds the name of this scope object, a list of variables, pointers, and nested scope objects, as well as a static link to parent scope object.

Author:
Amruth Kumar

Constructor Summary
ActivationRecord(ActivationRecord parentActivationRecord, Scope inScope)
          Initializes the vectors to hold the variables and pointers in this scope; initializes the vector to hold the activation records of embedded scopes; save a reference to the scope of which this is the activation record; saves a reference to the activation record of the parent scope, and adds self as a child of parent's activation record, if one exists
 
Method Summary
 void add(ActivationRecord activationRecord)
          Adds an embedded scope's activationRecord as a child of this activationRecord
 void cast(ActivationRecord partial)
          Sets all the variables in this activation record that are also in partial as declared and all the rest as not declared.
 ActivationRecord deepClone()
          Clones this activation record, as well as its variables and pointers, but NOT embedded scopes
 void explainProcess(RunEnv runEnv, Behavior behavior, java.lang.String statement, int event, int lineNumber)
          Explains the event that occurs during the execution of statement on line lineNumber
 void getAllChildReferences(java.util.Vector referenceList)
          Provides reference to the activation records of all the embedded scopes
 void getAllPointeeReferences(java.util.Vector referenceList)
          Provides reference to all the anonymous objects pointed to by pointers in this activation record
 void getAllVariableReferences(java.util.Vector referenceList)
          Provides reference to all the variables and pointers in this activation record
 ActivationRecord getParent()
          Returns a reference to the activation record of the static parent
 PtrModel getPointer(int index, boolean searchParents, boolean searchChildren)
          Returns a reference to the pointer of given index by searching this activation record, followed by activation records of ancestral scopes, followed by the activation records of nested scopes

searchParents = false; searchChildren = false;
Only check this scope object for the variable

searchParents = false; searchChildren = true;
NOT LIKELY USAGE - except when the procedure calls itself recursively when the flags are true & true

searchParents = true; searchChildren = false;
Check this scope object, and all its ancestors

searchParents = true; searchChildren = true;
Check this scope object, its static parents and children - Used to create buggy code.
 Scope getScopeModel()
          Returns a reference to the Scope of which this is the activation record
 AbstractVarModel getVariable(int index, boolean searchParents, boolean searchChildren)
          Returns a reference to the variable of given index by searching this activation record, followed by activation records of ancestral scopes, followed by the activation records of nested scopes

searchParents = false; searchChildren = false;
Only check this scope object for the variable

searchParents = false; searchChildren = true;
NOT LIKELY USAGE - except when the procedure calls itself recursively when the flags are true & true

searchParents = true; searchChildren = false;
Check this scope object, and all its ancestors

searchParents = true; searchChildren = true;
Check this scope object, its static parents and children - Used to create buggy code.
 boolean hasChildren()
          Returns true if this activation record has descendant activation records corresponding to embedded scopes
 boolean isEmpty()
          Returns true if no variables or pointers have been declared in this activation record, and false otherwise.
static void main(java.lang.String[] args)
           
 void print()
          Prints the name of the scope corresponding to this activation record, name of the parent scope, followe by all the variables and pointers in this scope
 void replaceChild(ActivationRecord replacement)
          If an activation record exists for the scope for which the replacement activation record parameter has been provided, replaces the old activation record with the new replacement.
 void setPointer(PtrModel pointer, int index)
          Inserts a pointer to the activation record at the given index
 void setStaticLink(ActivationRecord activationRecord)
          Sets the passed parameter as the parent of this activation record
 void setVariable(AbstractVarModel variable, int index)
          Inserts a variable to the activation record at the given index
 ActivationRecord shallowClone()
          Clones this activation record, but not its variables, pointers or embedded scopes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActivationRecord

public ActivationRecord(ActivationRecord parentActivationRecord,
                        Scope inScope)
Initializes the vectors to hold the variables and pointers in this scope; initializes the vector to hold the activation records of embedded scopes; save a reference to the scope of which this is the activation record; saves a reference to the activation record of the parent scope, and adds self as a child of parent's activation record, if one exists

Parameters:
parentActivationRecord - ActivationRecord of the parent scope, destination of this ActivationRecord's static link
inScope - Scope of which this is the activation record
Method Detail

shallowClone

public ActivationRecord shallowClone()
Clones this activation record, but not its variables, pointers or embedded scopes

Returns:
ActivationRecord that is the clone of the current activation record

deepClone

public ActivationRecord deepClone()
Clones this activation record, as well as its variables and pointers, but NOT embedded scopes

Returns:
ActivationRecord that is the deep clone of the current activation record

getPointer

public PtrModel getPointer(int index,
                           boolean searchParents,
                           boolean searchChildren)
Returns a reference to the pointer of given index by searching this activation record, followed by activation records of ancestral scopes, followed by the activation records of nested scopes

searchParents = false; searchChildren = false;
Only check this scope object for the variable

searchParents = false; searchChildren = true;
NOT LIKELY USAGE - except when the procedure calls itself recursively when the flags are true & true

searchParents = true; searchChildren = false;
Check this scope object, and all its ancestors

searchParents = true; searchChildren = true;
Check this scope object, its static parents and children - Used to create buggy code. In order to prevent infinite recursion, it passes only one of these as true for each recursive call

Parameters:
index - - integer index of the pointer, e.g., 1 in P1
searchParents - - boolean value specifying whether activation records of ancestor scopes should be searched if the pointer does not exist in this activation record - used to look for nonlocal referencing environment
searchChildren - - boolean value specifying whether activation records of embedded scopes should be searched if the pointer does not exist in this activation record - used to support generation of INcorrect code, not used for correct code
Returns:
PtrModel Reference to the pointer of the given index if it was found, and null if it was not found

getVariable

public AbstractVarModel getVariable(int index,
                                    boolean searchParents,
                                    boolean searchChildren)
Returns a reference to the variable of given index by searching this activation record, followed by activation records of ancestral scopes, followed by the activation records of nested scopes

searchParents = false; searchChildren = false;
Only check this scope object for the variable

searchParents = false; searchChildren = true;
NOT LIKELY USAGE - except when the procedure calls itself recursively when the flags are true & true

searchParents = true; searchChildren = false;
Check this scope object, and all its ancestors

searchParents = true; searchChildren = true;
Check this scope object, its static parents and children - Used to create buggy code. In order to prevent infinite recursion, it passes only one of these as true for each recursive call

Parameters:
index - - integer index of the variable, e.g., 1 in V1
searchParents - - boolean value specifying whether activation records of ancestor scopes should be searched if the variable does not exist in this activation record - used to look for nonlocal referencing environment
searchChildren - - boolean value specifying whether activation records of embedded scopes should be searched if the variable does not exist in this activation record - used to support generation of INcorrect code, not used for correct code
Returns:
PtrModel Reference to the variable of the given index if it was found, and null if it was not found

getParent

public ActivationRecord getParent()
Returns a reference to the activation record of the static parent

Returns:
ActivationRecord of the parent

getScopeModel

public Scope getScopeModel()
Returns a reference to the Scope of which this is the activation record

Returns:
Scope of this activation record

getAllVariableReferences

public void getAllVariableReferences(java.util.Vector referenceList)
Provides reference to all the variables and pointers in this activation record

Parameters:
referenceList - Vector to which references of all the variables and pointers in this activation record are added

getAllPointeeReferences

public void getAllPointeeReferences(java.util.Vector referenceList)
Provides reference to all the anonymous objects pointed to by pointers in this activation record

Parameters:
referenceList - Vector to which references of all the pointee objects of pointers in this activation record are added

getAllChildReferences

public void getAllChildReferences(java.util.Vector referenceList)
Provides reference to the activation records of all the embedded scopes

Parameters:
referenceList - Vector to which references of the activation records of all the embedded scopes are added

hasChildren

public boolean hasChildren()
Returns true if this activation record has descendant activation records corresponding to embedded scopes

Returns:
True if this activation record has descendant activation records corresponding to embedded scopes, and false otherwise

isEmpty

public boolean isEmpty()
Returns true if no variables or pointers have been declared in this activation record, and false otherwise.

Returns:
True if no variables or pointers have been declared in this activation record, and false otherwise.

cast

public void cast(ActivationRecord partial)
Sets all the variables in this activation record that are also in partial as declared and all the rest as not declared. Partial is an alias to this activation record. THE FOLLOWING FUNCTION ACTUALLY RESETS ALL THE VARIABLES IN THIS AR AND SETS ALL THE VARIABLES IN PARTIAL. NOT JAVADOC'ING IT TILLTHE FUNCTION IS FIXED OR VERIFIED.


add

public void add(ActivationRecord activationRecord)
Adds an embedded scope's activationRecord as a child of this activationRecord

Parameters:
activationRecord - ActivationRecord of the embedded scope

replaceChild

public void replaceChild(ActivationRecord replacement)
If an activation record exists for the scope for which the replacement activation record parameter has been provided, replaces the old activation record with the new replacement. Otherwise, adds the replacement activation record as a child of this activation record.

Parameters:
replacement - ActivationRecord of an embedded scope that will either replace the old ActivationRecord (if one exists) for the same embedded scope, or be added as a child of this ActivationRecord

setPointer

public void setPointer(PtrModel pointer,
                       int index)
Inserts a pointer to the activation record at the given index

Parameters:
pointer - - PtrModel object to be inserted into the activation record
index - - Integer index where the pointer is to be inserted into the activation record

setVariable

public void setVariable(AbstractVarModel variable,
                        int index)
Inserts a variable to the activation record at the given index

Parameters:
pointer - - AbstractVarModel object to be inserted into the activation record
index - - Integer index where the variable is to be inserted into the activation record

setStaticLink

public void setStaticLink(ActivationRecord activationRecord)
Sets the passed parameter as the parent of this activation record

Parameters:
activationRecord - ActivationRecord of the static parent

explainProcess

public void explainProcess(RunEnv runEnv,
                           Behavior behavior,
                           java.lang.String statement,
                           int event,
                           int lineNumber)
Explains the event that occurs during the execution of statement on line lineNumber

Parameters:
runEnv - RunEnv or the running environment for execution, including data stack, heap, input, output and code stack
behavior - Behavior of the executed program, including explanation, errors, output, dataTrace and controlTrace
statement - Substring of the template corresponding to the next statement being executed
event - Integer representing one of the events described in DomainModel that occurs during the execution of the statement
lineNumber - Integer indicating the line number of this statement in the overall program

print

public void print()
Prints the name of the scope corresponding to this activation record, name of the parent scope, followe by all the variables and pointers in this scope


main

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