Changes between Initial Version and Version 1 of RefactoringSteps/UpgradeModuleInterface


Ignore:
Timestamp:
Feb 19, 2012, 11:31:51 PM (12 years ago)
Author:
manualwiki
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RefactoringSteps/UpgradeModuleInterface

    v1 v1  
     1= Upgrade module interface = 
     2 
     3This transformation upgrades the calls of the old regular expression module regexp to the new re module. The transformation is based on a generic interface upgrade module, which is invoked with the right structural and semantic change descriptors. 
     4 
     5An example of upgrading regexp interface: 
     6 
     7{{{ 
     8case regexp:match(String, RE) of 
     9   {error, Reason} -> throw("Error: " ++ lists:flatten( 
     10                        regexp:format_error(Reason))); 
     11   {match, 1, Len} -> Len; 
     12   {match, St, Len} -> use(St, Len); 
     13   nomatch -> ok 
     14end 
     15}}} 
     16 
     17Result: 
     18 
     19{{{ 
     20try re:run(String, RE, [{capture, first}]) of 
     21   {match, [{0, Len}]} -> Len;      % [{1-1, Len}] works too 
     22   {match, [{St, Len}]} -> use(St+1, Len); 
     23   nomatch -> ok 
     24catch 
     25   error:badarg -> throw("Error: " ++ lists:flatten( 
     26                     "Bad regular expression")) 
     27end 
     28}}} 
     29 
     30 
     31== Side conditions == 
     32 
     33 * Patterns belong to applications to be updated should match at least one of the patterns written in the change descriptors. 
     34 
     35 
     36== Transformation steps and compensations == 
     37 
     38 1. Updating the function application: 
     39  * Modifying the called function’s identifier {{{regexp:match ->re:run}}} 
     40  * Matching the old function arguments and creating the new argument list {{{(String, RE) -> (String, RE, [capture, first])}}} 
     41 
     42 2. Finding the patterns to be updated and performing on them the matching and the replacing. Furthermore, applying the correction functions on the variable bindings or/and usages. 
     43  * Pattern: {{{match, 1, Len -> match, [0, Len]}}} 
     44  * Expression: {{{use(St, Len) -> use(St+1, Len)}}} 
     45 
     46 3.  Turning the case expression to a try expression and moving error pattern to the catch block (error:badarg is moved to a catch block after we changed case expression to try expression).