wiki:RefactoringSteps/RenameMacro

Rename macro

The "rename macro" transformation renames a macro and all of its occurrences in either modules and header files. The condition of the renaming is that there is no name conflict with another record in the file containing the macro, in any of its includes or anywhere it has been included at.

Renaming macro LessEq to Leq:

-define(LessEq, =<).

max(X,Z) ->
   if
      X ?LessEq Z -> Z;
      X>=Z -> X
   end.

Result:

-define(Leq, =<).

max(Y,Z) ->
   if
      Y ?Leq Z -> Z;
      Y>=Z -> Y
   end.

Side conditions

  • No macro already exist with the same new name in either
    • in a file hosting definition or usage of the macro,
    • in files included by the said,
    • in files that include the said.
  • If one of the above conditions fails, the transformation starts an interaction to ask for a new macro name.
  • If the user does not specify a macro or the specified macro does not exist, the transformation starts an interaction to ask for a macro.

Transformation steps and compensations

  1. The macro name is replaced with the new name at both definitions and all usage sites.
Last modified 12 years ago Last modified on Feb 15, 2012, 7:25:44 PM