Transformation Language

For simplifying the implementation of refactorings and other program transformations, the IDC tool embeds a program transformation language, based on the Stratego language.


This is the current development implementation of the SimplifyExpression refactoring:

# Transformation to simplify an expression
simplify =
  Binary(Eq(t),Binary(Minus(t),x,y),Lit(t,0)) -> Binary(Eq(t),x,y) |
  Unary(Not(Bool),Binary(Eq(t),x,y)) -> Binary(NotEq(t),x,y) |
  Binary(And(_),x,x) -> x

# Transformation to check whether this refactoring is applicable given the root term and the current selection
applicable = 
  # boilerplate code to extract the selection
    # get the currently selected subterm
    ir.path.projectSelection ; 
    # check if it is an expression
    ir.match.expr ; 
    # and that 'simplify' succeeds once, from top to down

# Ask and process user input, and return a list of arguments
input = 
  # no user input is required

# Transformation to apply this refactoring given the root term, selection, and arguments
apply = 
  # boilerplate code to extract the selection
    # discard the arguments
    [root,[]] -> root ; 
    # apply 'simplify' once in the current selection, from top to down
      ir.path.isSelected ; 

# Transformation to perform some unit testing
testAnd = 
  simplify Binary(And(Int(32,Signed)),Sym("x"),Sym("x")) => Sym("x")