public final 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 |
|---|---|
(package private) static class |
ContextStack.Context
A linked stack entry.
|
static class |
ContextStack.TranslateMode
(Compound) Translation mode for active type caches.
|
| 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 TypeCache |
typeCache |
| Constructor and Description |
|---|
ContextStack()
Creates a context stack with implicit top-most (project) context.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAsParentCache(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
TypeCache.IConstraintTarget target,
net.ssehub.easy.varModel.confModel.IDecisionVariable register,
net.ssehub.easy.varModel.model.AbstractVariable var)
Adds the type cache of
type as parent to the type cache that is currently in construction. |
void |
addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target,
boolean first,
net.ssehub.easy.varModel.model.Constraint constraint,
boolean register)
Adds a constraint to the type cache that is currently in construction for the actual context frame.
|
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.
|
(package private) void |
collectAnnotationAssignments(net.ssehub.easy.varModel.model.AttributeAssignment assng)
Collects annotation assignment names in this context.
|
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 |
constraintVarOnly(boolean clear)
Returns the flag of the current context whether only constraint variables shall be translated.
|
boolean |
containsMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
Returns whether the current context contains a mapping for
var. |
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.
|
TypeCache.Entry |
getInConstruction(boolean clear)
Returns whether the current context is currently constructing a type cache.
|
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
getLocalMapping(java.lang.String name)
Returns the local mapping for the given variable
name just from 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. |
ContextStack.TranslateMode |
getMappingMode(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Returns the type cache mapping mode when trying to register a new type.
|
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 |
isKnownAnnotationAssignment(java.lang.String name)
Returns whether
name is a known annotation assignment (annotation variable) in this context. |
boolean |
isTypeExcluded(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Returns whether the given
type is excluded in the current context. |
void |
notifyCashMapping()
Notifies the current context that mappings shall be cached upon
popContext(IDatatype). |
void |
popContext()
Removes (and clears) the current context from the stack (except for the initial project context
which remains).
|
void |
popContext(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
Pops a context and transfers the cache information.
|
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 |
recordAnnotationAssignments(net.ssehub.easy.varModel.model.datatypes.Compound type)
Records annotation assignments for the given compound
type for this context. |
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 |
registerForTypeCache(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
net.ssehub.easy.varModel.model.AbstractVariable var)
Registers the given type and the prototypical template variable
var as type in the type cache. |
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. |
void |
setConstraintVarOnly(boolean constraintVarOnly)
Changes the flag of the current context whether only constraint variables shall be translated.
|
void |
setInConstruction(TypeCache.Entry inConstruction)
Changes the type cache the current context is currently constructing.
|
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.
|
boolean |
transferConstraints(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
TypeCache.IConstraintTarget target,
net.ssehub.easy.varModel.confModel.IDecisionVariable register,
net.ssehub.easy.varModel.model.AbstractVariable var)
Transfers all constraints from the associated type cache entry into their respective target constraint
sets.
|
void |
transferToContext(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
net.ssehub.easy.varModel.model.AbstractVariable var)
Indicates that mapping information from the type cache shall be transferred into the current context.
|
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 java.util.Set<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> globalExcludes
private transient TypeCache typeCache
public ContextStack()
public 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 recordAnnotationAssignments(net.ssehub.easy.varModel.model.datatypes.Compound type)
type for this context.type - the compound typevoid collectAnnotationAssignments(net.ssehub.easy.varModel.model.AttributeAssignment assng)
assng - the assignment to collect forpublic boolean isKnownAnnotationAssignment(java.lang.String name)
name is a known annotation assignment (annotation variable) in this context.name - the variable nametrue if the annotation variable is known, false elsepublic 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(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
type - the type to transfer the data to if the actual context is in ContextStack.Context.inConstruction and
cashing is needed ContextStack.Context.cashMapping.public 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 getLocalMapping(java.lang.String name)
name just from the current context. Names are
registered once, to the most local (non-shadowed) variable.name - the name of the variablepublic void addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target,
boolean first,
net.ssehub.easy.varModel.model.Constraint constraint,
boolean register)
target - the target constraint listfirst - add to the front or to the end of targetconstraint - the (template) constraint to be storedregister - shall the constraint later be registered with VariablesMappublic boolean transferConstraints(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
TypeCache.IConstraintTarget target,
net.ssehub.easy.varModel.confModel.IDecisionVariable register,
net.ssehub.easy.varModel.model.AbstractVariable var)
var. [type cache]type - the type to transfer the constraints fortarget - the constraint targetregister - the variable to register the new constraints with VariablesMapvar - the actual variable for substitutiontrue if the transfer was done even if no constraint was transferred as no one was registered and
no further translation shall happen, false if translation can go on, e.g. the type cache for
type is currently in constructionpublic boolean constraintVarOnly(boolean clear)
clear - clears the original value to false (e.g., for temporary use)public void setConstraintVarOnly(boolean constraintVarOnly)
constraintVarOnly - the new value of the flagpublic void registerForTypeCache(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
net.ssehub.easy.varModel.model.AbstractVariable var)
var as type in the type cache.
As long as the containing context is active, all constraints added through
#addConstraint(ConstraintList, boolean, Constraint, boolean)) will be related to the created type
cache entry. Upon
#transferConstraints(IDatatype, IConstraintTarget, IDecisionVariable, AbstractVariable))
all occurrences of var will be substituted by a given variable. [type cache]type - the type to relate tovar - the template variablepublic TypeCache.Entry getInConstruction(boolean clear)
clear - clears the original value to null (e.g., for temporary use)public void setInConstruction(TypeCache.Entry inConstruction)
inConstruction - the type cache being in construction, may be null for nonepublic void notifyCashMapping()
popContext(IDatatype). [type cache]public ContextStack.TranslateMode getMappingMode(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
type - the type the mode shall be returned forpublic void transferToContext(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
net.ssehub.easy.varModel.model.AbstractVariable var)
TypeCache.ON_DEMAND_ACCESSORS. [type cache]type - the type to do the transfer forvar - the variable replacing the template variablepublic void addAsParentCache(net.ssehub.easy.varModel.model.datatypes.IDatatype type,
TypeCache.IConstraintTarget target,
net.ssehub.easy.varModel.confModel.IDecisionVariable register,
net.ssehub.easy.varModel.model.AbstractVariable var)
type as parent to the type cache that is currently in construction. [type cache]type - the type to addtarget - the target container for immediately transferring constraintsregister - whether constraints shall be registeredvar - the replacing variablepublic 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 validpublic 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.