public class ContextStack
extends java.lang.Object
variable
mapping lookup starts with the current context and takes also previous contexts into account.
Each context may parts of a complex constraint accessing the path to contained compound variables (the complete
constraint over all stack contexts can be obtained from composeExpression(ConstraintSyntaxTree).
However, due to IVML assignment blocks, a translation context stack is not really straightforward.
In assignment blocks, additional implicit constraints to initialize annotations are introduced and
translated after the actual variable has been translated, i.e., outside the context of a compound
or container variable. Therefore, we allow registering contexts
with their variable in the parent context for later activation and
deactivation as long as the parent context exists. If re-activated,
an already popped context (which must not be cleaned up then) is pushed back onto the stack. If de-activated,
the re-activated context is popped again but not cleaned up. Registered contexts are cleaned up when the
parent context is popped.
| Modifier and Type | Class and Description |
|---|---|
private static class |
ContextStack.Context
A linked stack entry.
|
| Modifier and Type | Field and Description |
|---|---|
private ContextStack.Context |
currentContext |
private java.util.Set<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> |
globalExcludes |
private static net.ssehub.easy.basics.pool.Pool<ContextStack.Context> |
POOL |
private boolean |
registerContexts |
| Constructor and Description |
|---|
ContextStack()
Creates a context stack with implicit top-most (project) context.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activate(net.ssehub.easy.varModel.model.AbstractVariable decl)
Re-activates the context registered for
decl and re-pushes it onto the stack. |
boolean |
alreadyProcessed(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Returns whether
type was already processed. |
void |
clear()
Clears the stack, i.e., pops all contexts and clears the top-most (project) context for re-use.
|
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
composeExpression(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst)
Composes an all-quantified expression over the contexts of the stack.
|
boolean |
containsMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
Returns whether the current context contains a mapping for
var. |
void |
deactivate(net.ssehub.easy.varModel.model.AbstractVariable decl)
Deactivates the context registered for
decl. |
private ContextStack.Context |
findRegisteredContext(net.ssehub.easy.varModel.model.AbstractVariable decl)
Looks up the actual contexts whether
decl was registered previously with a context. |
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
getCurrentContainer()
Returns the current container expression from the top-most context.
|
net.ssehub.easy.varModel.model.DecisionVariableDeclaration |
getCurrentIterator()
Returns the current iterator variable from the top-most context.
|
net.ssehub.easy.varModel.model.datatypes.IDatatype |
getCurrentType()
Returns the type stored in the current context.
|
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
getMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
Returns the mapped access expression for
var taking into account all current
contexts of the stack starting with the current top-most one. |
boolean |
isContextsRegistering()
Returns whether context registering is actually enabled.
|
boolean |
isElementTypeExcluded(net.ssehub.easy.varModel.model.IModelElement element)
Returns whether the given
element if it is a type is excluded in the current
context. |
boolean |
isTypeExcluded(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Returns whether the given
type is excluded in the current context. |
void |
popContext()
Removes (and clears) the current context from the stack (except for the initial project context
which remains).
|
private ContextStack.Context |
popContextImpl()
Pops the actual context if not the initial (project) context but does not clean up the popped context.
|
void |
pushContext(net.ssehub.easy.varModel.model.AbstractVariable decl,
boolean recordProcessedTypes)
Pushes a new (compound) context to the stack.
|
void |
pushContext(net.ssehub.easy.varModel.model.AbstractVariable decl,
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree container,
net.ssehub.easy.varModel.model.DecisionVariableDeclaration iterator,
boolean recordProcessedTypes)
Pushes a new container context to the stack.
|
private void |
pushContextImpl(ContextStack.Context context)
Just pushes the given
context without changing it. |
void |
recordProcessed(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Records a processed type (in case of compounds also all refined types) in the closest actual context that allows
recording (see
ContextStack.Context.recordProcessedTypes and pushContext(AbstractVariable,
ConstraintSyntaxTree, DecisionVariableDeclaration, boolean)). |
private void |
recordProcessed(java.util.Set<net.ssehub.easy.varModel.model.datatypes.IDatatype> processed,
net.ssehub.easy.varModel.model.datatypes.Compound type)
Records a processed compound.
|
void |
registerMapping(net.ssehub.easy.varModel.model.AbstractVariable var,
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc)
Registers a mapping between the variable
var and its actual access expression acc into
the current top-most context. |
boolean |
setRegisterContexts(boolean registerContexts)
Enables or disables registering contexts.
|
void |
setTypeExcludes(java.util.Set<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> excludes)
Sets type excludes on the current context.
|
int |
size()
Returns the size of the context stack.
|
void |
transferTypeExcludes(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Transfers the type excludes from the next enclosing context defining type excludes to the current
context.
|
void |
unregisterMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
Unregisters a mapping for the variable
var from the current context. |
private static final net.ssehub.easy.basics.pool.Pool<ContextStack.Context> POOL
private ContextStack.Context currentContext
private boolean registerContexts
private java.util.Set<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> globalExcludes
public ContextStack()
public boolean setRegisterContexts(boolean registerContexts)
registerContexts - whether newly pushed contexts shall be registered from now onpublic boolean isContextsRegistering()
true if context registering is enabled, false elsepublic void clear()
public void pushContext(net.ssehub.easy.varModel.model.AbstractVariable decl,
boolean recordProcessedTypes)
decl - the variable to register the new context with if enabled,
may be null to explicitly prevent registrationrecordProcessedTypes - whether processed types indicated by #recordType(IDatatype) shall be recorded
or not (false)public void pushContext(net.ssehub.easy.varModel.model.AbstractVariable decl,
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree container,
net.ssehub.easy.varModel.model.DecisionVariableDeclaration iterator,
boolean recordProcessedTypes)
decl - the variable to register the new context with if enabled,
may be null to explicitly prevent registrationcontainer - the container expression (may be null)iterator - a container iterator variable for container, may be null but only if
container is nullrecordProcessedTypes - whether processed types indicated by #recordType(IDatatype) shall be recorded
or not (false)private void pushContextImpl(ContextStack.Context context)
context without changing it.context - the context to be pushedpublic void popContext()
private ContextStack.Context popContextImpl()
public void registerMapping(net.ssehub.easy.varModel.model.AbstractVariable var,
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc)
var and its actual access expression acc into
the current top-most context. Overrides any existing mapping in the top-most context. Preceeds any
existing mapping in a previous still active context.var - the variableacc - the access expressionpublic void unregisterMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
var from the current context.var - the variable to be unregisteredpublic boolean containsMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
var.var - the variable to look fortrue if there is a mapping, false elsepublic net.ssehub.easy.varModel.cst.ConstraintSyntaxTree getMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
var taking into account all current
contexts of the stack starting with the current top-most one.var - the variable to return the mapping forpublic net.ssehub.easy.varModel.cst.ConstraintSyntaxTree getCurrentContainer()
public net.ssehub.easy.varModel.model.DecisionVariableDeclaration getCurrentIterator()
public net.ssehub.easy.varModel.cst.ConstraintSyntaxTree composeExpression(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst)
throws net.ssehub.easy.varModel.cst.CSTSemanticException
cst will be returned.cst - the constraint expression to be composed, shall contain the access
expression of the top-most context to be effectivecst if there is nothing to composenet.ssehub.easy.varModel.cst.CSTSemanticException - if the composed expression is not validprivate ContextStack.Context findRegisteredContext(net.ssehub.easy.varModel.model.AbstractVariable decl)
decl was registered previously with a context.decl - the declaration to search forpublic void activate(net.ssehub.easy.varModel.model.AbstractVariable decl)
decl and re-pushes it onto the stack. Nothing happens if
no context was registered.decl - the declarationpublic void deactivate(net.ssehub.easy.varModel.model.AbstractVariable decl)
decl. Nothing happens if no context was registered.decl - the declarationpublic void recordProcessed(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
ContextStack.Context.recordProcessedTypes and pushContext(AbstractVariable,
ConstraintSyntaxTree, DecisionVariableDeclaration, boolean)). Stores type in the current
context for retrieval via getCurrentType().type - the type to recordprivate void recordProcessed(java.util.Set<net.ssehub.easy.varModel.model.datatypes.IDatatype> processed,
net.ssehub.easy.varModel.model.datatypes.Compound type)
processed - the set of already processed types (may be modified as a side effect)type - the type to be recordedpublic boolean alreadyProcessed(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
type was already processed. All current contexts with enabled
recording are considered.type - the type to look fortrue if the type was already processed, false if notpublic int size()
public void setTypeExcludes(java.util.Set<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> excludes)
transferred.excludes - the type excludes, null for noneisTypeExcluded(IDatatype),
isElementTypeExcluded(IModelElement)public void transferTypeExcludes(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
type - the type causing the transfer, to be stored in the current context (@link #getCurrentType()}setTypeExcludes(Set),
isTypeExcluded(IDatatype),
isElementTypeExcluded(IModelElement)public boolean isElementTypeExcluded(net.ssehub.easy.varModel.model.IModelElement element)
element if it is a type is excluded in the current
context.element - the element to check fortrue if excluded, false elsepublic boolean isTypeExcluded(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
type is excluded in the current context.type - the type to check fortrue if excluded, false elsepublic net.ssehub.easy.varModel.model.datatypes.IDatatype getCurrentType()
Copyright © 2009 - 2018 SSE. All Rights Reserved.