org.prorefactor.treeparser
Class SymbolScope

java.lang.Object
  extended by org.prorefactor.treeparser.SymbolScope
All Implemented Interfaces:
Xferable
Direct Known Subclasses:
SymbolScopeRoot

public class SymbolScope
extends java.lang.Object
implements Xferable

For keeping track of PROCEDURE, FUNCTION, and trigger scopes within a 4gl compile unit. Note that scopes are nested. There is the outer program scope, and within it the other types of scopes which may themselves nest trigger scopes. (Trigger scopes may be deeply nested). These scopes are defined Symbol scopes. They have nothing to do with record or frame scoping!


Field Summary
protected  java.util.ArrayList<Symbol> allSymbols
           
protected  java.util.Map<java.lang.String,TableBuffer> bufferMap
           
protected  java.util.ArrayList<Call> callList
           
protected  java.util.ArrayList<SymbolScope> childScopes
           
protected  java.util.Map<java.lang.String,FieldLevelWidgetI> fieldLevelWidgetMap
           
protected  SymbolScope parentScope
           
protected  Block rootBlock
           
protected  SymbolScopeRoot rootScope
           
protected  java.util.Map<java.lang.String,Routine> routineMap
           
protected  java.util.Map<java.lang.Integer,java.util.Map> typeMap
           
protected  java.util.Map<Table,TableBuffer> unnamedBuffers
           
protected  java.util.Map<java.lang.String,Variable> variableMap
           
 
Constructor Summary
  SymbolScope()
          Only to be used for persistence/serialization.
protected SymbolScope(SymbolScope parentScope)
          Only Scope and derivatives may create a Scope object.
 
Method Summary
 void add(FieldLevelWidgetI widget)
          Add a FieldLevelWidget for names lookup.
 void add(Routine routine)
          Add a Routine for call handling.
 void add(Symbol symbol)
          Add a Symbol for names lookup.
 void add(TableBuffer tableBuffer)
          Add a TableBuffer for names lookup.
 void add(Variable var)
          Add a Variable for names lookup.
 SymbolScope addScope()
          Add a new scope to this scope.
 TableBuffer defineBuffer(java.lang.String name, Table table)
          Define a new BufferSymbol.
 int depth()
          Get the integer "depth" of the scope.
 java.util.ArrayList<Symbol> getAllSymbols()
          Get a *copy* of the list of all symbols in this scope
<T extends Symbol>
java.util.ArrayList<T>
getAllSymbols(java.lang.Class<T> klass)
          Get a list of this scope's symbols which match a given class
 java.util.ArrayList<Symbol> getAllSymbolsDeep()
          Get a list of this scope's symbols, and all symbols of all descendant scopes.
<T extends Symbol>
java.util.ArrayList<T>
getAllSymbolsDeep(java.lang.Class<T> klass)
          Get a list of this scope's symbols, and all symbols of all descendant scopes, which match a given class.
 java.util.Set getBufferSet()
          Get the set of named buffers
 TableBuffer getBufferSymbol(java.lang.String inName)
          Given a name, find a BufferSymbol (or create if necessary for unnamed buffer).
 java.util.ArrayList<Call> getCallList()
           
 java.util.ArrayList<SymbolScope> getChildScopes()
          Get a *copy* of the list of child scopes
 java.util.ArrayList<SymbolScope> getChildScopesDeep()
          Get a list of all child scopes, and their child scopes, etc
 SymbolScope getParentScope()
           
 Block getRootBlock()
           
 SymbolScopeRoot getRootScope()
           
 TableBuffer getUnnamedBuffer(Table table)
          Get or create the unnamed buffer for a schema table.
 java.util.Collection<Variable> getVariables()
          Get the Variables.
 boolean hasRoutine(java.lang.String name)
          Answer whether the scope has a Routine named by param.
 boolean isActiveIn(SymbolScope theScope)
          Is this scope active in the input scope? In other words, is this scope the input scope, or any of the parents of the input scope?
 TableBuffer lookupBuffer(java.lang.String inName)
          Lookup a named record/table buffer in this scope or an enclosing scope.
 Dataset lookupDataset(java.lang.String name)
           
 Datasource lookupDatasource(java.lang.String name)
           
 FieldLevelWidgetI lookupFieldLevelWidget(java.lang.String inName)
          Lookup a FieldLevelWidget in this scope or an enclosing scope.
 Query lookupQuery(java.lang.String name)
           
 Routine lookupRoutine(java.lang.String name)
           
 Stream lookupStream(java.lang.String name)
           
 Symbol lookupSymbol(java.lang.Integer symbolType, java.lang.String name)
           
 Symbol lookupSymbolLocally(java.lang.Integer symbolType, java.lang.String name)
           
 TableBuffer lookupTableOrBufferSymbol(java.lang.String inName)
          Lookup a Table or a BufferSymbol, schema table first.
 TableBuffer lookupTempTable(java.lang.String name)
           
 Variable lookupVariable(java.lang.String inName)
          Lookup a Variable in this scope or an enclosing scope.
 Widget lookupWidget(int widgetType, java.lang.String name)
          Lookup a Widget based on TokenType (FRAME, BUTTON, etc) and the name in this scope or enclosing scope.
 void registerCall(Call call)
           
 void setRootBlock(Block block)
           
 void writeXferBytes(DataXferStream out)
          Implement Xferable.
 void writeXferSchema(DataXferStream out)
          Implement Xferable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allSymbols

protected java.util.ArrayList<Symbol> allSymbols

callList

protected java.util.ArrayList<Call> callList

childScopes

protected java.util.ArrayList<SymbolScope> childScopes

rootBlock

protected Block rootBlock

bufferMap

protected java.util.Map<java.lang.String,TableBuffer> bufferMap

fieldLevelWidgetMap

protected java.util.Map<java.lang.String,FieldLevelWidgetI> fieldLevelWidgetMap

routineMap

protected java.util.Map<java.lang.String,Routine> routineMap

unnamedBuffers

protected java.util.Map<Table,TableBuffer> unnamedBuffers

typeMap

protected java.util.Map<java.lang.Integer,java.util.Map> typeMap

variableMap

protected java.util.Map<java.lang.String,Variable> variableMap

parentScope

protected SymbolScope parentScope

rootScope

protected SymbolScopeRoot rootScope
Constructor Detail

SymbolScope

public SymbolScope()
Only to be used for persistence/serialization.


SymbolScope

protected SymbolScope(SymbolScope parentScope)
Only Scope and derivatives may create a Scope object.

Parameters:
parentScope - null if called by the SymbolScopeRoot constructor.
Method Detail

add

public void add(FieldLevelWidgetI widget)
Add a FieldLevelWidget for names lookup.


add

public void add(Routine routine)
Add a Routine for call handling. Note that this isn't really complete. It's possible to have an IN SUPER declaration, as well as a local definition. The local definition should be the one in this map, but as it stands, the *last added* is what will be found.


add

public void add(TableBuffer tableBuffer)
Add a TableBuffer for names lookup. This is called when copying a SymbolScopeSuper's symbols for inheritance purposes.


add

public void add(Variable var)
Add a Variable for names lookup.


add

public void add(Symbol symbol)
Add a Symbol for names lookup.


addScope

public SymbolScope addScope()
Add a new scope to this scope.


defineBuffer

public TableBuffer defineBuffer(java.lang.String name,
                                Table table)
Define a new BufferSymbol.

Parameters:
name - Input "" for a default or unnamed buffer, otherwise the "named buffer" name.

depth

public int depth()
Get the integer "depth" of the scope. Zero might be either the unit (program/class) scope, or if this is a class which inherits from super classes, then zero would be the top of the inheritance chain. Functions and procedures will always be depth: (unitDepth + 1), and trigger scopes can be nested, so they will always be one or greater. I use this function for unit testing - I want to be able to examine the scope of a symbol, and make sure that the symbol belongs to the scope that I expect.


getAllSymbols

public java.util.ArrayList<Symbol> getAllSymbols()
Get a *copy* of the list of all symbols in this scope


getAllSymbols

public <T extends Symbol> java.util.ArrayList<T> getAllSymbols(java.lang.Class<T> klass)
Get a list of this scope's symbols which match a given class


getAllSymbolsDeep

public java.util.ArrayList<Symbol> getAllSymbolsDeep()
Get a list of this scope's symbols, and all symbols of all descendant scopes.


getAllSymbolsDeep

public <T extends Symbol> java.util.ArrayList<T> getAllSymbolsDeep(java.lang.Class<T> klass)
Get a list of this scope's symbols, and all symbols of all descendant scopes, which match a given class.


getBufferSet

public java.util.Set getBufferSet()
Get the set of named buffers


getBufferSymbol

public TableBuffer getBufferSymbol(java.lang.String inName)
Given a name, find a BufferSymbol (or create if necessary for unnamed buffer).


getCallList

public java.util.ArrayList<Call> getCallList()

getChildScopes

public java.util.ArrayList<SymbolScope> getChildScopes()
Get a *copy* of the list of child scopes


getChildScopesDeep

public java.util.ArrayList<SymbolScope> getChildScopesDeep()
Get a list of all child scopes, and their child scopes, etc


getParentScope

public SymbolScope getParentScope()

getRootBlock

public Block getRootBlock()

getRootScope

public SymbolScopeRoot getRootScope()

getUnnamedBuffer

public TableBuffer getUnnamedBuffer(Table table)
Get or create the unnamed buffer for a schema table.


getVariables

public java.util.Collection<Variable> getVariables()
Get the Variables. (vars, params, etc, etc.)


hasRoutine

public boolean hasRoutine(java.lang.String name)
Answer whether the scope has a Routine named by param.

Parameters:
name - - the name of the routine.

isActiveIn

public boolean isActiveIn(SymbolScope theScope)
Is this scope active in the input scope? In other words, is this scope the input scope, or any of the parents of the input scope?


lookupBuffer

public TableBuffer lookupBuffer(java.lang.String inName)
Lookup a named record/table buffer in this scope or an enclosing scope.

Parameters:
inName - String buffer name.
Returns:
A Buffer, or null if not found.

lookupDataset

public Dataset lookupDataset(java.lang.String name)

lookupDatasource

public Datasource lookupDatasource(java.lang.String name)

lookupFieldLevelWidget

public FieldLevelWidgetI lookupFieldLevelWidget(java.lang.String inName)
Lookup a FieldLevelWidget in this scope or an enclosing scope.


lookupQuery

public Query lookupQuery(java.lang.String name)

lookupRoutine

public Routine lookupRoutine(java.lang.String name)

lookupStream

public Stream lookupStream(java.lang.String name)

lookupSymbol

public Symbol lookupSymbol(java.lang.Integer symbolType,
                           java.lang.String name)

lookupSymbolLocally

public Symbol lookupSymbolLocally(java.lang.Integer symbolType,
                                  java.lang.String name)

lookupTableOrBufferSymbol

public TableBuffer lookupTableOrBufferSymbol(java.lang.String inName)
Lookup a Table or a BufferSymbol, schema table first. It seems to work like this: unabbreviated schema name, then buffer/temp/work name, then abbreviated schema names. Sheesh.


lookupTempTable

public TableBuffer lookupTempTable(java.lang.String name)

lookupVariable

public Variable lookupVariable(java.lang.String inName)
Lookup a Variable in this scope or an enclosing scope.

Parameters:
inName - The string field name to lookup.
Returns:
A Variable, or null if not found.

lookupWidget

public Widget lookupWidget(int widgetType,
                           java.lang.String name)
Lookup a Widget based on TokenType (FRAME, BUTTON, etc) and the name in this scope or enclosing scope.


registerCall

public void registerCall(Call call)

setRootBlock

public void setRootBlock(Block block)

writeXferBytes

public void writeXferBytes(DataXferStream out)
                    throws java.io.IOException
Implement Xferable.

Specified by:
writeXferBytes in interface Xferable
Throws:
java.io.IOException

writeXferSchema

public void writeXferSchema(DataXferStream out)
                     throws java.io.IOException
Implement Xferable.

Specified by:
writeXferSchema in interface Xferable
Throws:
java.io.IOException


Copyright © 2008 Joanju Software. All Rights Reserved.