org.overturetool.vdmj.runtime
Class Context

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<LexNameToken,Value>
          extended by org.overturetool.vdmj.runtime.Context
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<LexNameToken,Value>
Direct Known Subclasses:
RootContext

public class Context
extends java.util.HashMap<LexNameToken,Value>

A class to hold runtime name/value context information.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
 LexLocation location
          The location of the context.
 Context outer
          A link to a lower level context, if present.
 ThreadState threadState
          The thread state associated with this context.
 java.lang.String title
          The name of the location.
 
Constructor Summary
Context(LexLocation location, java.lang.String title, Context outer)
          Create a context at the given location.
 
Method Summary
 Value check(LexNameToken name)
          Get the value for a given name.
 Context deepCopy()
           
protected  java.lang.String format(java.lang.String indent, Context what)
           
 Value get(java.lang.Object name)
          Get a name, taking type overloading into account.
 int getDepth()
           
 Context getFrame(int depth)
           
 Context getFreeVariables()
          Get all visible names from this Context, with more visible values overriding those below.
 Context getGlobal()
          Find the outermost context from this one.
 RootContext getRoot()
          Find the nearest RootContext in the context chain.
 ObjectValue getSelf()
           
 Context getUpdateable()
          Build a new Context based on the current one, but with only the updateable values included (eg.
 Value lookup(LexNameToken name)
          Return the value of a name, else fail.
 void printStackTrace(java.io.PrintWriter out, boolean variables)
           
 void put(NameValuePairList nvl)
          Add a list of name/value pairs to this context.
 void setThreadState(DBGPReader dbgp, CPUValue cpu)
          Set the current thread state.
 java.lang.String toString()
           
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

location

public final LexLocation location
The location of the context.


title

public final java.lang.String title
The name of the location.


outer

public final Context outer
A link to a lower level context, if present.


threadState

public ThreadState threadState
The thread state associated with this context.

Constructor Detail

Context

public Context(LexLocation location,
               java.lang.String title,
               Context outer)
Create a context at the given location.

Parameters:
location -
title -
outer -
Method Detail

setThreadState

public void setThreadState(DBGPReader dbgp,
                           CPUValue cpu)
Set the current thread state. Note this must be called from the thread where the context will run, which may not be where the thread is created. And it must be called before any context chaining is performed.

Parameters:
cpu - TODO

getGlobal

public Context getGlobal()
Find the outermost context from this one.

Returns:
The outermost context.

getRoot

public RootContext getRoot()
Find the nearest RootContext in the context chain.


getUpdateable

public Context getUpdateable()
Build a new Context based on the current one, but with only the updateable values included (eg. "dcl" definitions and state).


deepCopy

public Context deepCopy()

put

public void put(NameValuePairList nvl)
Add a list of name/value pairs to this context.

Parameters:
nvl - A list of name/value pairs.

get

public Value get(java.lang.Object name)
Get a name, taking type overloading into account. If we use the superclass method, different names are considered different, because the map is driven by the names' hashCodes. The equals method of LexNameToken makes a TypeComparator check, which is what we need. But we try a simple super.get() first. TODO Slow though.

Specified by:
get in interface java.util.Map<LexNameToken,Value>
Overrides:
get in class java.util.HashMap<LexNameToken,Value>

getFreeVariables

public Context getFreeVariables()
Get all visible names from this Context, with more visible values overriding those below.

Returns:
A new Context with all visible names.

check

public Value check(LexNameToken name)
Get the value for a given name. This searches outer contexts, if any are present.

Parameters:
name - The name to look for.
Returns:
The value of the name, or null.

lookup

public Value lookup(LexNameToken name)
Return the value of a name, else fail. If the name is not present, a ContextException is thrown.

Parameters:
name - The name to look for.
Returns:
The value of the name.

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap<LexNameToken,Value>

format

protected java.lang.String format(java.lang.String indent,
                                  Context what)

printStackTrace

public void printStackTrace(java.io.PrintWriter out,
                            boolean variables)

getDepth

public int getDepth()

getFrame

public Context getFrame(int depth)

getSelf

public ObjectValue getSelf()


Copyright © 2009. All Rights Reserved.