org.problets.domain.model
Class CodeModel

java.lang.Object
  extended by org.problets.domain.model.DomainModel
      extended by org.problets.domain.model.CodeModel
All Implemented Interfaces:
java.lang.Cloneable

public class CodeModel
extends DomainModel

CodeModel To generate the code for the problem

Author:
Amruth Kumar

Field Summary
static int BLOCK_SCOPE
           
static int FILE_SCOPE
           
static int FUNCTION_SCOPE
           
static int IDENTITY
           
static int PROGRAM_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
CodeModel(Template inTemplate)
           
 
Method Summary
 boolean done()
          Rewind through fast forward - Idea from Guido Rossling, SIGCSE 2005 Not used - DataVisualizer.rewind() subsumes this functtion public void rewind( int limit ) { // First, re-initialize the whole model, start execution init(); // Initialize a counter of the steps to be executed // - we have already executed first step in init() int instructionCounter = 2; while( instructionCounter <= limit ) { step(); instructionCounter++; } }
 void explain(Behavior behavior)
          Version called by client, who wants to execute the original copy of the code
 int[] getAllLineNumbers()
          Returns an array of all line numbers in the code
 Behavior getBehavior()
          Returns a reference to the behavior of this program.
 void getCode(java.util.Vector codeText)
          Called by: CodeView in constructor and set_code() methods Calls: Scope.getCode() method // COULD REUSE THISCODETEXT INSTEAD
 HeapModel getHeap()
          Returns the heap of the current program - needed by CodeViz
 InputStream getInputStream()
          Returns the input stream of the current program - needed by CodeViz
 Template getOriginalTemplate()
          Returns a reference to the original template (before preprocessing) whose preprocessed version is used for this code
 java.lang.String getOutputAsString()
           
 int[] getOutputLineNumbers()
          Returns an array of line numbers corresponding to output statements in the code
 OutputStream getOutputStream()
          Returns the output stream of the current program - needed by CodeViz
 Program getProgram()
          Return a reference to the program in this code
 Behavior getSolution()
          This method is more efficient than calling getBehavior() since this executes the code once and returns the result as many times as desired
 StackModel getStack()
          Returns the stack of the current program - needed by CodeViz
 Behavior getStepBehavior()
          Returns a reference to the behavior for stepping through a code
 RunEnv getStepRunEnv()
          Returns a reference to the run time environment for stepping through a code
 Template getTemplate()
          Returns a reference to the template used for this code - needed by TutorModel to obtain antecedents etc.
 void init()
          Initializes the data structures to facilitate visualization, driven by the user.
static void main(java.lang.String[] args)
           
 void step()
           
 void update(Template inTemplate)
          The method that generates code for a new template This will be called by ProbletPanel for the codeModel, instead of allocating new codeModel
 
Methods inherited from class org.problets.domain.model.DomainModel
clone, 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

PROGRAM_SCOPE

public static final int PROGRAM_SCOPE
See Also:
Constant Field Values

FILE_SCOPE

public static final int FILE_SCOPE
See Also:
Constant Field Values

FUNCTION_SCOPE

public static final int FUNCTION_SCOPE
See Also:
Constant Field Values

BLOCK_SCOPE

public static final int BLOCK_SCOPE
See Also:
Constant Field Values
Constructor Detail

CodeModel

public CodeModel(Template inTemplate)
Method Detail

getCode

public void getCode(java.util.Vector codeText)
Called by: CodeView in constructor and set_code() methods Calls: Scope.getCode() method // COULD REUSE THISCODETEXT INSTEAD


getTemplate

public Template getTemplate()
Returns a reference to the template used for this code - needed by TutorModel to obtain antecedents etc.


getOriginalTemplate

public Template getOriginalTemplate()
Returns a reference to the original template (before preprocessing) whose preprocessed version is used for this code


getOutputAsString

public java.lang.String getOutputAsString()

getProgram

public Program getProgram()
Return a reference to the program in this code


getStack

public StackModel getStack()
Returns the stack of the current program - needed by CodeViz


getHeap

public HeapModel getHeap()
Returns the heap of the current program - needed by CodeViz


getInputStream

public InputStream getInputStream()
Returns the input stream of the current program - needed by CodeViz


getOutputStream

public OutputStream getOutputStream()
Returns the output stream of the current program - needed by CodeViz


getStepRunEnv

public RunEnv getStepRunEnv()
Returns a reference to the run time environment for stepping through a code


getStepBehavior

public Behavior getStepBehavior()
Returns a reference to the behavior for stepping through a code


getBehavior

public Behavior getBehavior()
Returns a reference to the behavior of this program. We do not want to execute the original program as soon as it is generated, because: 1) We do not want the visualization of variables to show the values assigned over the course of execution. We DO want to execute the original program as soon as it is generated, because: 1) For state problems, this is the only way we can generate the question based on a snapshot of the values of variables. 2) If we do immediate feedback or error flagging, we will need the correct answer upfront. Therefore, we will create a new copy of scope, (which will share only the template and SymbolTable with the original scope) execute the code and return the behavior resulting from its execution.


getSolution

public Behavior getSolution()
This method is more efficient than calling getBehavior() since this executes the code once and returns the result as many times as desired


getOutputLineNumbers

public int[] getOutputLineNumbers()
Returns an array of line numbers corresponding to output statements in the code


getAllLineNumbers

public int[] getAllLineNumbers()
Returns an array of all line numbers in the code


update

public void update(Template inTemplate)
The method that generates code for a new template This will be called by ProbletPanel for the codeModel, instead of allocating new codeModel


explain

public void explain(Behavior behavior)
Version called by client, who wants to execute the original copy of the code


init

public void init()
Initializes the data structures to facilitate visualization, driven by the user. Subsequently, lets the user visualize the execution of a program one instruction at a time. Reuses the SymbolTable and template created earlier. Re-initializes stack, heap, input, output. In the future, my want to reuse input - so as not to ask the user for the same inputs again. THIS FUNCTION SHOULD BE COMPLETELY RE-ENTRANT SO THAT IT CAN BE CALLED TO COMPUTE THE CORRECT BEHAVIOR OF A DUPLICATE COPY OF THE CODE


step

public void step()

done

public boolean done()
Rewind through fast forward - Idea from Guido Rossling, SIGCSE 2005 Not used - DataVisualizer.rewind() subsumes this functtion public void rewind( int limit ) { // First, re-initialize the whole model, start execution init(); // Initialize a counter of the steps to be executed // - we have already executed first step in init() int instructionCounter = 2; while( instructionCounter <= limit ) { step(); instructionCounter++; } }


main

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