public class BufferScopeWorker.BufferHelper
extends java.lang.Object
Constructor and Description |
---|
BufferHelper() |
Modifier and Type | Method and Description |
---|---|
BufferScopeTracker |
createBuffer(java.lang.String bufname,
Aast ref,
boolean stage)
Helper to simplify construction of a
BufferScopeTracker from
a rule set. |
void |
finalizeBuffers(java.lang.String bufname,
BufferBlockState bbs)
Moves any buffer scopes stored in the rollup list associated with
the given block into the global list of buffers, then clears the
rollup list.
|
BufferBlockState |
getBlockState(java.lang.String bufname)
Accesses the block state of the named buffer from the current block.
|
BufferList |
getBuffer(java.lang.String bufname)
Access the master
BufferList instance for the given buffer
name. |
java.util.Iterator |
getBuffers()
Returns an iterator to all
BufferList instances, one
instance per unique buffer name. |
BufferList |
getMasterList(java.lang.String bufname)
Accesses the master list of all buffers for this buffer name.
|
java.util.Iterator<java.lang.Long> |
getSuperTables(java.lang.String qname)
Get the IDs of the buffers or temp-tables defined in the super-classes for the specified
class.
|
private BufferList |
matchAfter(java.lang.String bufname,
java.lang.String delimiter)
Helper method to match a partial buffer name (the portion after the
given delimiter) with the corresponding, partial name of any
registered buffer.
|
void |
popScope(Aast node)
Pop the current block from the stack and maintain the block oriented
state for the next block based on the previous instances of
BufferBlockState for each buffer. |
void |
processExpansion(java.lang.String bufname,
BufferScopeTracker buf)
Updates the state of the block and the global state for this buffer
name with the resulting buffer scope that is the result of an
expansion.
|
void |
processFree(java.lang.String bufname,
Aast ast,
boolean stage)
Create a new buffer scope and set it as a pending free reference (if
there is no bind target) OR force an expansion by merging this
reference with the current bind target.
|
void |
processWeak(java.lang.String bufname,
BufferScopeTracker buf)
Updates the state of the containing block when a weak reference
is encountered.
|
void |
pushScope(Aast node)
Push a new block onto the stack and maintain the block oriented
state for each buffer using the
BufferBlockState . |
BufferList |
registerBuffer(java.lang.String unique,
java.lang.String bufname,
java.lang.String forceDMOAlias,
java.lang.String schemaname,
java.lang.String javaname,
boolean staticDef,
java.lang.String dbname,
boolean implicit,
boolean readOnly,
boolean dynamicTable)
Register this buffer name in the list of all possible buffers in
use in the current source file.
|
void |
rollupBuffers(java.lang.String bufname,
BufferBlockState bbs)
Combines any buffer scopes stored in the rollup list associated with
the given block into the global
active buffer scope for
that block, then clears the rollup list. |
private void |
setExpanded(BufferList master,
BufferBlockState state,
BufferScopeTracker buf)
Simple helper to set the
lastExpanded , the
bindTarget and firstWeak based on
a new expanded scope. |
public java.util.Iterator<java.lang.Long> getSuperTables(java.lang.String qname)
qname
- The qualified class name.public BufferList registerBuffer(java.lang.String unique, java.lang.String bufname, java.lang.String forceDMOAlias, java.lang.String schemaname, java.lang.String javaname, boolean staticDef, java.lang.String dbname, boolean implicit, boolean readOnly, boolean dynamicTable)
BufferList
.unique
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same.bufname
- The shortest unabbreviated unique buffer name.forceDMOAlias
- Explicit DMO alias for the converted buffer. Used for dynamic buffers.
null
if auto-converted alias should be used.schemaname
- The backing schema contruct that defines this node's
structure.javaname
- The converted Java name for this buffer. null
if this is an implicitly defined buffer.staticDef
- This is an explicit static buffer definition.dbname
- The logical database name for the buffer (this may be
different from the database name in the schema parameter).implicit
- true
if this buffer is being created due to
an implicit record reference, false
if the
buffer was explicitly defined (e.g. with a DEFINE BUFFER
statement).readOnly
- true
if the buffer is read-only (like the OLD
buffer of a database WRITE trigger).dynamicTable
- true
if the buffer is for a dynamic table.BufferList
instance.public BufferList getBuffer(java.lang.String bufname)
BufferList
instance for the given buffer
name. The returned object stores global state for the use of this
buffer name in the current Progress 4GL procedure.
Matching of bufname
against the names of registered
BufferLists is performed in a progressively lenient manner. The
first pass attempts to find an exact match on the full name. If
this fails to produce a result, another match is attempted, this
time ignoring the database qualifier (the portion up to and including
the first dot). If this fails to produce a result, another match is
attempted, this time ignoring the "uniqueness" qualifier (the
portion up to and including the first underscore). If this fails,
null
is returned.
Note: this manner of matching is a workaround for a shortcoming of the schema dictionary, which prevents an unqualified field from being identified with an explicitly defined buffer rather than with the table which backs it.
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same.null
if no such master exists.public java.util.Iterator getBuffers()
BufferList
instances, one
instance per unique buffer name.public void pushScope(Aast node)
BufferBlockState
.
If there is a bind target in the enclosing scope this bind target is propagated into the new scope. Likewise any pending rollup block is propagated. This must be done in order to ensure that relative down movement below the pending rollup point will not lose track of the fact that a rollup is needed at a higher level. Other state does not propagate "down" into the inner or nested block.
Due to a mismatch in location between where a weak or strong
reference occurs in the AST in relation to the block node to which
such references must be scoped, there may be a "staged" buffer
stored in the BufferList
for each buffer name. If present,
these staged scopes have their block nodes assigned and then it is
set as the active scope for the block.
The rules by which this scope calculation is handled are very complex. Please see the UAST Package Summary for complete details.
node
- The AST node associated with this new scope. Please note
that this must be the same as the node to which a buffer
would be scoped.public void popScope(Aast node)
BufferBlockState
for each buffer.
Certain state from nested blocks must be propagated to outer nesting levels during this operation. This provides the ability for certain deeply nested scopes to be used for "binding" or to trigger the "rollup process".
If there is a pending rollup (because of a scope expansion that occurred in the nested block) AND the target for that rollup is the outer block, then the rollup process is invoked.
Nested scope expansions and first weak references can propagate "up" to the outer block. The scope expansions in particular, also propagate into the bind target at enclosing levels.
If this is processing at the root node and there is a pending free reference, the associated buffer scope is added to the master list of buffers.
The rules by which this scope calculation is handled are very complex. Please see the UAST Package Summary for complete details.
node
- The AST node associated with this scope. Please note
that this must be the same as the node to which a buffer
would be scoped.public BufferBlockState getBlockState(java.lang.String bufname)
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same.null
if this is called at the root node.public BufferList getMasterList(java.lang.String bufname)
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same.java.lang.IllegalArgumentException
- If the buffer name is invalid.public void rollupBuffers(java.lang.String bufname, BufferBlockState bbs)
active
buffer scope for
that block, then clears the rollup list.
This processing occurs in the case where an implicit expansion of
scope has occurred. All buffers in the rollup list associated with
the block (that encloses the two buffers being combined) must be
merged with the scope being expanded. The scope being expanded is
found by obtaining the active
buffer scope for this
buffer name.
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.bbs
- The buffer-specific block state from which to obtain the
rollup list.java.lang.IllegalArgumentException
- If the buffer name is invalid.java.lang.RuntimeException
- If there is no active
buffer scope for this
buffer name.public void finalizeBuffers(java.lang.String bufname, BufferBlockState bbs)
This processing is done anytime it is known that the buffers in the
rollup list can no longer be merged with other buffer scopes (see
the rollupBuffers(java.lang.String, com.goldencode.p2j.convert.BufferBlockState)
method).
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.bbs
- The buffer-specific block state from which to obtain the
rollup list.java.lang.IllegalArgumentException
- If the buffer name is invalid.public BufferScopeTracker createBuffer(java.lang.String bufname, Aast ref, boolean stage)
BufferScopeTracker
from
a rule set.bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.ref
- The node which first references this buffer scope.stage
- true
if the new buffer should be temporarily
stored in the "staging" area of the BufferList
such that the next block open will associate this buffer
with the block. This is used to associate strong and
weak references with the block scope opened subsequently.java.lang.IllegalArgumentException
- If the reference's buffer name is invalid.public void processExpansion(java.lang.String bufname, BufferScopeTracker buf)
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.buf
- The expanded scope.java.lang.IllegalArgumentException
- If the buffer name is invalid or if an active scope exists
when this is called.public void processWeak(java.lang.String bufname, BufferScopeTracker buf)
This must only be called if there is no active scope and if there
is no pending free reference to which to bind (these cases are
expansions to be processed via processExpansion(java.lang.String, com.goldencode.p2j.convert.BufferScopeTracker)
, rather
than a standalone weak reference to be processed here).
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.buf
- The expanded scope.public void processFree(java.lang.String bufname, Aast ast, boolean stage)
bufname
- A name that uniquely represents all uses of this buffer
name when it also references the specific given schema
name. Since the same buffer names can be defined to
reference different schema entities between internal
procedures, external procedures and functions, this
name is needed to uniquely associate all references that
are really the same. Used to obtain the global
BufferList
for this buffer.ast
- The node representing the free reference.stage
- true
to force a delayed assignment of the
associated block until the next block open. This is
needed to allow certain constructs (at this time, the
FUNCTION -- KW_FUNCT -- PARAMETER -- KW_BUFFER -- record)
to emit in the proper location and with the proper block
node.private void setExpanded(BufferList master, BufferBlockState state, BufferScopeTracker buf)
lastExpanded
, the
bindTarget
and firstWeak
based on
a new expanded scope.master
- The master list of buffers for the current buffer name
being processed.state
- Block which is the target of the state update.buf
- The expanded scope.private BufferList matchAfter(java.lang.String bufname, java.lang.String delimiter)
bufname
- Buffer name to be matched.delimiter
- Marker string within bufname
(and presumably,
within each registered buffer's name) which delimits the
ignored, qualifying portion of the name, from the the
significant portion of the name.null
if no match is found.