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

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
     
    private ContextStack
     
    private Map<net.ssehub.easy.varModel.model.AbstractVariable,net.ssehub.easy.varModel.cst.ConstraintSyntaxTree>
     
    private net.ssehub.easy.varModel.model.AbstractVariable
     
    private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a copy visitor without mapping.
    Creates a copy visitor with explicit mapping.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    accept(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst)
    Accepts this on cst and returns BasicCopyVisitor.getResult().
    net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    acceptAndClear(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst)
    Accepts this on cst, returns BasicCopyVisitor.getResult() and clears this.
    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.
    void
    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.
    boolean
    Returns whether the last execution visited a self.
    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.
    private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    map(net.ssehub.easy.varModel.cst.Variable variable)
    Maps a variable to its accessor expression.
    void
    setMappings(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.
    void
    visitAnnotationVariable(net.ssehub.easy.varModel.cst.AttributeVariable variable)
     
    void
    visitComment(net.ssehub.easy.varModel.cst.Comment comment)
     
    void
    visitCompoundAccess(net.ssehub.easy.varModel.cst.CompoundAccess access)
     
    void
    visitDeferInitExpression(net.ssehub.easy.varModel.cst.DeferInitExpression expression)
    Visits a default init expression.
    void
    visitSelf(net.ssehub.easy.varModel.cst.Self self)
     
    void
    visitVariable(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mapping

      private Map<net.ssehub.easy.varModel.model.AbstractVariable,net.ssehub.easy.varModel.cst.ConstraintSyntaxTree> mapping
    • globalMapping

      private ContextStack 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

      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:
  • Method Details

    • 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:
      true for self, false else
    • clear

      public void clear()
      Clears this visitor for reuse.
      Overrides:
      clear in class net.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 over setMappings(ContextStack). If a variable mapping is defined by setMappings(ContextStack), potential transitive mappings of dest are considered and instead of orig-dest, a mapping from orig to the transitive value is registered.
      Parameters:
      orig - the original variable to be replaced (may be null, ignored)
      dest - the destination variable to replace orig (may be null, ignored)
      derefCount - the number of refBy operations to apply to the expression refering to dest
      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 over setMappings(ContextStack).
      Parameters:
      orig - the original variable to be replaced (may be null, ignored)
      ex - the expression to replace orig
      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

      public SubstitutionVisitor clearVariableMapping()
      Clears the entire variable mapping.
      Returns:
      this
    • setSelf

      public SubstitutionVisitor setSelf(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx)
      Defines self in terms of an expression.
      Parameters:
      selfEx - the expression (may be null, ignored then).
      Returns:
      this
    • setSelf

      public SubstitutionVisitor setSelf(net.ssehub.easy.varModel.model.AbstractVariable self)
      Defines self in terms of a variable declaration. Creates a variable on demand and re-uses it. Dont' call also setSelf(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 on cst and returns BasicCopyVisitor.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)
      Accepts this on cst, returns BasicCopyVisitor.getResult() and clears this.
      Parameters:
      cst - the constraint to visit
      Returns:
      the visiting result
    • visitAnnotationVariable

      public void visitAnnotationVariable(net.ssehub.easy.varModel.cst.AttributeVariable variable)
      Specified by:
      visitAnnotationVariable in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitAnnotationVariable in class net.ssehub.easy.varModel.cst.BasicCopyVisitor
    • visitVariable

      public void visitVariable(net.ssehub.easy.varModel.cst.Variable variable)
      Specified by:
      visitVariable in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitVariable in class net.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:
      visitCompoundAccess in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitCompoundAccess in class net.ssehub.easy.varModel.cst.BasicCopyVisitor
    • visitComment

      public void visitComment(net.ssehub.easy.varModel.cst.Comment comment)
      Specified by:
      visitComment in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitComment in class net.ssehub.easy.varModel.cst.BasicCopyVisitor
    • visitSelf

      public void visitSelf(net.ssehub.easy.varModel.cst.Self self)
      Specified by:
      visitSelf in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitSelf in class net.ssehub.easy.varModel.cst.BasicCopyVisitor
    • visitDeferInitExpression

      public void visitDeferInitExpression(net.ssehub.easy.varModel.cst.DeferInitExpression expression)
      Visits a default init expression.
      Specified by:
      visitDeferInitExpression in interface net.ssehub.easy.varModel.cst.IConstraintTreeVisitor
      Overrides:
      visitDeferInitExpression in class net.ssehub.easy.varModel.cst.BasicCopyVisitor
      Parameters:
      expression - the expression