Class SubstitutionVisitor
- java.lang.Object
-
- net.ssehub.easy.varModel.cst.BasicCopyVisitor
-
- net.ssehub.easy.reasoning.sseReasoner.model.SubstitutionVisitor
-
- All Implemented Interfaces:
IConstraintTreeVisitor
public class SubstitutionVisitor extends BasicCopyVisitor
Substitutes variables in a constraint syntax tree by copying the syntax tree. May be reused after callingclear().#addVariableMapping(AbstractVariable, Variable)takes precedence over#setMappings(Map).- Author:
- Sizonenko, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private booleancontainsSelfprivate ConstraintSyntaxTreeexcludeFromMappingprivate ContextStackglobalMappingprivate java.util.Map<AbstractVariable,ConstraintSyntaxTree>mappingprivate AbstractVariableselfprivate ConstraintSyntaxTreeselfEx
-
Constructor Summary
Constructors Constructor Description SubstitutionVisitor()Creates a copy visitor without mapping.SubstitutionVisitor(ContextStack globalMapping)Creates a copy visitor with explicit mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConstraintSyntaxTreeaccept(ConstraintSyntaxTree cst)Accepts this oncstand returnsBasicCopyVisitor.getResult().ConstraintSyntaxTreeacceptAndClear(ConstraintSyntaxTree cst)SubstitutionVisitoraddVariableMapping(AbstractVariable orig, ConstraintSyntaxTree ex)Adds a variable mapping to be considered during substitution.SubstitutionVisitoraddVariableMapping(AbstractVariable orig, AbstractVariable dest, int derefCount)Adds a variable mapping to be considered during substitution.voidclear()Clears this visitor for reuse.SubstitutionVisitorclearVariableMapping()Clears the entire variable mapping.SubstitutionVisitorclearVariableMapping(AbstractVariable var)Clears the mapping for a given variable.booleancontainsSelf()Returns whether the last execution visited a self.voidexcludeFromMapping(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 ConstraintSyntaxTreemap(Variable variable)Maps a variable to its accessor expression.voidsetMappings(ContextStack globalMapping)Sets the mapping.SubstitutionVisitorsetSelf(ConstraintSyntaxTree selfEx)Defines self in terms of an expression.SubstitutionVisitorsetSelf(AbstractVariable self)Defines self in terms of a variable declaration.voidvisitAnnotationVariable(AttributeVariable variable)Visits aAttributeVariable.voidvisitComment(Comment comment)Visits a comment.voidvisitCompoundAccess(CompoundAccess access)Visits a compound access node.voidvisitDeferInitExpression(DeferInitExpression expression)Visits a default init expression.voidvisitSelf(Self self)Visits self.voidvisitVariable(Variable variable)Visits a 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 Detail
-
mapping
private java.util.Map<AbstractVariable,ConstraintSyntaxTree> mapping
-
globalMapping
private ContextStack globalMapping
-
selfEx
private ConstraintSyntaxTree selfEx
-
self
private AbstractVariable self
-
containsSelf
private boolean containsSelf
-
excludeFromMapping
private ConstraintSyntaxTree excludeFromMapping
-
-
Constructor Detail
-
SubstitutionVisitor
public SubstitutionVisitor()
Creates a copy visitor without mapping.
-
SubstitutionVisitor
public SubstitutionVisitor(ContextStack globalMapping)
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:
setMappings(ContextStack)
-
-
Method Detail
-
setMappings
public void setMappings(ContextStack globalMapping)
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 classBasicCopyVisitor- See Also:
clearVariableMapping()
-
addVariableMapping
public SubstitutionVisitor addVariableMapping(AbstractVariable orig, AbstractVariable dest, int derefCount)
Adds a variable mapping to be considered during substitution. Takes precedence over#setMappings(Map). If a variable mapping is defined by#setMappings(Map), 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(AbstractVariable orig, ConstraintSyntaxTree ex)
Adds a variable mapping to be considered during substitution. Takes precedence over#setMappings(Map).- Parameters:
orig- the original variable to be replaced (may be null, ignored)ex- the expression to replaceorig- Returns:
- this
-
clearVariableMapping
public SubstitutionVisitor clearVariableMapping(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
public SubstitutionVisitor clearVariableMapping()
Clears the entire variable mapping.- Returns:
- this
-
setSelf
public SubstitutionVisitor setSelf(ConstraintSyntaxTree selfEx)
Defines self in terms of an expression.- Parameters:
selfEx- the expression (may be null, ignored then).- Returns:
- this
-
setSelf
public SubstitutionVisitor setSelf(AbstractVariable self)
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 ConstraintSyntaxTree accept(ConstraintSyntaxTree cst)
Accepts this oncstand returnsBasicCopyVisitor.getResult().- Parameters:
cst- the constraint to visit- Returns:
- the visiting result
-
acceptAndClear
public ConstraintSyntaxTree acceptAndClear(ConstraintSyntaxTree cst)
- Parameters:
cst- the constraint to visit- Returns:
- the visiting result
-
visitAnnotationVariable
public void visitAnnotationVariable(AttributeVariable variable)
Description copied from interface:IConstraintTreeVisitorVisits aAttributeVariable.- Specified by:
visitAnnotationVariablein interfaceIConstraintTreeVisitor- Overrides:
visitAnnotationVariablein classBasicCopyVisitor- Parameters:
variable- the attribute variable which should be visited
-
visitVariable
public void visitVariable(Variable variable)
Description copied from interface:IConstraintTreeVisitorVisits a variable.- Specified by:
visitVariablein interfaceIConstraintTreeVisitor- Overrides:
visitVariablein classBasicCopyVisitor- Parameters:
variable- the variable which should be visited
-
map
private ConstraintSyntaxTree map(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(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(CompoundAccess access)
Description copied from interface:IConstraintTreeVisitorVisits a compound access node.- Specified by:
visitCompoundAccessin interfaceIConstraintTreeVisitor- Overrides:
visitCompoundAccessin classBasicCopyVisitor- Parameters:
access- the compound access node
-
visitComment
public void visitComment(Comment comment)
Description copied from interface:IConstraintTreeVisitorVisits a comment.- Specified by:
visitCommentin interfaceIConstraintTreeVisitor- Overrides:
visitCommentin classBasicCopyVisitor- Parameters:
comment- the comment node which should be visited
-
visitSelf
public void visitSelf(Self self)
Description copied from interface:IConstraintTreeVisitorVisits self.- Specified by:
visitSelfin interfaceIConstraintTreeVisitor- Overrides:
visitSelfin classBasicCopyVisitor- Parameters:
self- the self object to visit
-
visitDeferInitExpression
public void visitDeferInitExpression(DeferInitExpression expression)
Visits a default init expression.- Specified by:
visitDeferInitExpressionin interfaceIConstraintTreeVisitor- Overrides:
visitDeferInitExpressionin classBasicCopyVisitor- Parameters:
expression- the expression
-
-