wiki:RefactoringSteps/InlineMacro

Version 1 (modified by manualwiki, 13 years ago) (diff)

--

Inline macro substitution

The inline macro substitution refactoring step substitutes a selected macro application with the corresponding macro body and takes care of necessary compensations.

Inline macro application ?Add(A,A):

-module(inlmac).
-define(Add(A,B),A+B).

double(A)-> ?Add(A,A).

Macro inlined:

-module(inlmac).
-define(Add(A,B),A+B).

double(A)->A+A.

Side conditions

  • The selected macro must not contain stringification or another macro in its definition.
  • The selection must not be inside a macro definition.
  • If the selection is not specify a macro usage the transformation starts an interaction to let the user specify one. It gives a list with the possible macro usages.

Transformation steps and compensations

  1. All the side conditions must met.
  1. The following must be gathered that are necessary to fully finish the transformation:
    • Edges to be deleted: those between ‘subst’ and both its children and the macro definition; ones connecting all intermediate ‘token’ nodes with ‘subst’, the containing expression and the original lexical tokens; and the one between the ‘subst’ node and its arguments.
    • Nodes to be deleted: those lexical children of the ‘subst’ nodes parameter child which do not participate in the final solution (commas), children of the ‘subst’ node, the ‘subst’ node itself and the intermediate ‘token’ nodes.
    • Edges to be rewired: those edges that originally connected a nonshared lexical node created specifically for the given substitution.
    • Nodes to be created: those nodes which must be cloned from the macro definition because they are shared between all usages.