Class SubstitutionVisitor
java.lang.Object
net.ssehub.easy.varModel.cst.BasicCopyVisitor
net.ssehub.easy.reasoning.sseReasoner.model.SubstitutionVisitor
- All Implemented Interfaces:
net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
public class SubstitutionVisitor
extends net.ssehub.easy.varModel.cst.BasicCopyVisitor
Substitutes variables in a constraint syntax tree by copying the syntax tree. May be
reused after calling
clear(). addVariableMapping(AbstractVariable, Variable)
takes precedence over setMappings(ContextStack).- Author:
- Sizonenko, Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate net.ssehub.easy.varModel.cst.ConstraintSyntaxTreeprivate ContextStackprivate Map<net.ssehub.easy.varModel.model.AbstractVariable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree> private net.ssehub.easy.varModel.model.AbstractVariableprivate net.ssehub.easy.varModel.cst.ConstraintSyntaxTree -
Constructor Summary
ConstructorsConstructorDescriptionCreates a copy visitor without mapping.SubstitutionVisitor(ContextStack globalMapping) Creates a copy visitor with explicit mapping. -
Method Summary
Modifier and TypeMethodDescriptionnet.ssehub.easy.varModel.cst.ConstraintSyntaxTreeaccept(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Accepts this oncstand returnsBasicCopyVisitor.getResult().net.ssehub.easy.varModel.cst.ConstraintSyntaxTreeacceptAndClear(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) addVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable orig, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree ex) Adds a variable mapping to be considered during substitution.addVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable orig, net.ssehub.easy.varModel.model.AbstractVariable dest, int derefCount) Adds a variable mapping to be considered during substitution.voidclear()Clears this visitor for reuse.Clears the entire variable mapping.clearVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable var) Clears the mapping for a given variable.booleanReturns whether the last execution visited a self.voidexcludeFromMapping(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Excludes the given expression from mapping, e.g., if the expression is an already complete accessor expression and a mapping would be based on a previously registered (incorrect) mapping.private net.ssehub.easy.varModel.cst.ConstraintSyntaxTreemap(net.ssehub.easy.varModel.cst.Variable variable) Maps a variable to its accessor expression.voidsetMappings(ContextStack globalMapping) Sets the mapping.setSelf(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx) Defines self in terms of an expression.setSelf(net.ssehub.easy.varModel.model.AbstractVariable self) Defines self in terms of a variable declaration.voidvisitAnnotationVariable(net.ssehub.easy.varModel.cst.AttributeVariable variable) voidvisitComment(net.ssehub.easy.varModel.cst.Comment comment) voidvisitCompoundAccess(net.ssehub.easy.varModel.cst.CompoundAccess access) voidvisitDeferInitExpression(net.ssehub.easy.varModel.cst.DeferInitExpression expression) Visits a default init expression.voidvisitSelf(net.ssehub.easy.varModel.cst.Self self) voidvisitVariable(net.ssehub.easy.varModel.cst.Variable variable) Methods inherited from class net.ssehub.easy.varModel.cst.BasicCopyVisitor
getCopyExpressions, getCopyVariables, getLogger, getResult, inferDatatype, mapVariable, mapVariable, setCopyConstants, setCopyExpressions, setCopyVariables, setDoInferDatatype, setResult, visitBlockExpression, visitCompoundInitializer, visitConstantValue, visitContainerInitializer, visitContainerOperationCall, visitIfThen, visitLet, visitMultiAndExpression, visitOclFeatureCall, visitParenthesis, visitUnresolvedExpression
-
Field Details
-
mapping
private Map<net.ssehub.easy.varModel.model.AbstractVariable,net.ssehub.easy.varModel.cst.ConstraintSyntaxTree> mapping -
globalMapping
-
selfEx
private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx -
self
private net.ssehub.easy.varModel.model.AbstractVariable self -
containsSelf
private boolean containsSelf -
excludeFromMapping
private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree excludeFromMapping
-
-
Constructor Details
-
SubstitutionVisitor
public SubstitutionVisitor()Creates a copy visitor without mapping. -
SubstitutionVisitor
Creates a copy visitor with explicit mapping.- Parameters:
globalMapping- a mapping from variable declarations to new access expressions, existing variable declarations are taken over if no mapping is given, may be null in case of no mapping at all- See Also:
-
-
Method Details
-
setMappings
Sets the mapping. [init, reuse]- Parameters:
globalMapping- a mapping from variable declarations to new access expressions, existing variable declarations are taken over if no mapping is given, may be null in case of no mapping at all
-
containsSelf
public boolean containsSelf()Returns whether the last execution visited a self.- Returns:
truefor self,falseelse
-
clear
public void clear()Clears this visitor for reuse.- Overrides:
clearin classnet.ssehub.easy.varModel.cst.BasicCopyVisitor- See Also:
-
addVariableMapping
public SubstitutionVisitor addVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable orig, net.ssehub.easy.varModel.model.AbstractVariable dest, int derefCount) Adds a variable mapping to be considered during substitution. Takes precedence oversetMappings(ContextStack). If a variable mapping is defined bysetMappings(ContextStack), potential transitive mappings ofdestare considered and instead oforig-dest, a mapping fromorigto the transitive value is registered.- Parameters:
orig- the original variable to be replaced (may be null, ignored)dest- the destination variable to replaceorig(may be null, ignored)derefCount- the number of refBy operations to apply to the expression refering todest- Returns:
- this
-
addVariableMapping
public SubstitutionVisitor addVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable orig, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree ex) Adds a variable mapping to be considered during substitution. Takes precedence oversetMappings(ContextStack).- Parameters:
orig- the original variable to be replaced (may be null, ignored)ex- the expression to replaceorig- Returns:
- this
-
clearVariableMapping
public SubstitutionVisitor clearVariableMapping(net.ssehub.easy.varModel.model.AbstractVariable var) Clears the mapping for a given variable.- Parameters:
var- the variable to clear the mapping for (may be null, ignored)- Returns:
- this
-
clearVariableMapping
Clears the entire variable mapping.- Returns:
- this
-
setSelf
Defines self in terms of an expression.- Parameters:
selfEx- the expression (may be null, ignored then).- Returns:
- this
-
setSelf
Defines self in terms of a variable declaration. Creates a variable on demand and re-uses it. Dont' call alsosetSelf(ConstraintSyntaxTree)on the same expression.- Parameters:
self- the variable (declaration) representing self (may be null, ignored then).- Returns:
- this
-
accept
public net.ssehub.easy.varModel.cst.ConstraintSyntaxTree accept(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Accepts this oncstand returnsBasicCopyVisitor.getResult().- Parameters:
cst- the constraint to visit- Returns:
- the visiting result
-
acceptAndClear
public net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acceptAndClear(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) - Parameters:
cst- the constraint to visit- Returns:
- the visiting result
-
visitAnnotationVariable
public void visitAnnotationVariable(net.ssehub.easy.varModel.cst.AttributeVariable variable) - Specified by:
visitAnnotationVariablein interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitAnnotationVariablein classnet.ssehub.easy.varModel.cst.BasicCopyVisitor
-
visitVariable
public void visitVariable(net.ssehub.easy.varModel.cst.Variable variable) - Specified by:
visitVariablein interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitVariablein classnet.ssehub.easy.varModel.cst.BasicCopyVisitor
-
map
private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree map(net.ssehub.easy.varModel.cst.Variable variable) Maps a variable to its accessor expression.- Parameters:
variable- the variable to map- Returns:
- the accessor expression, may be null
-
excludeFromMapping
public void excludeFromMapping(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Excludes the given expression from mapping, e.g., if the expression is an already complete accessor expression and a mapping would be based on a previously registered (incorrect) mapping. Comparison is done by reference.- Parameters:
cst- the expression to exclude, may be null for no exclude
-
visitCompoundAccess
public void visitCompoundAccess(net.ssehub.easy.varModel.cst.CompoundAccess access) - Specified by:
visitCompoundAccessin interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitCompoundAccessin classnet.ssehub.easy.varModel.cst.BasicCopyVisitor
-
visitComment
public void visitComment(net.ssehub.easy.varModel.cst.Comment comment) - Specified by:
visitCommentin interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitCommentin classnet.ssehub.easy.varModel.cst.BasicCopyVisitor
-
visitSelf
public void visitSelf(net.ssehub.easy.varModel.cst.Self self) - Specified by:
visitSelfin interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitSelfin classnet.ssehub.easy.varModel.cst.BasicCopyVisitor
-
visitDeferInitExpression
public void visitDeferInitExpression(net.ssehub.easy.varModel.cst.DeferInitExpression expression) Visits a default init expression.- Specified by:
visitDeferInitExpressionin interfacenet.ssehub.easy.varModel.cst.IConstraintTreeVisitor- Overrides:
visitDeferInitExpressionin classnet.ssehub.easy.varModel.cst.BasicCopyVisitor- Parameters:
expression- the expression
-