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.
Example
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
ir.path.Applicable(
# 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
OnceTD(simplify)
)
# Ask and process user input, and return a list of arguments
input =
# no user input is required
ir.path.Input(![])
# Transformation to apply this refactoring given the root term, selection, and arguments
apply =
# boilerplate code to extract the selection
ir.path.Apply(
# discard the arguments
[root,[]] -> root ;
# apply 'simplify' once in the current selection, from top to down
OnceTD(
ir.path.isSelected ;
InnerMost(simplify)
)
)
# Transformation to perform some unit testing
testAnd =
simplify Binary(And(Int(32,Signed)),Sym("x"),Sym("x")) => Sym("x")