Refactoring Legacy Code with gmStudio Commands
The Refactor Commands
Section titled “The Refactor Commands”This page describes the use of the basic Refactor commands.
Refactoring
Section titled “Refactoring”The Refactor Commands directs the translator to make changes to the low-level semantic model of your codebase as it moves from source form to target form. These changes will be propagated across the codebase as appropriate.
Within gmStudio the transformation of a source codebase to a target codebase proceeds in 8 steps:
- Loading the source code
- Pre-Processing the source code (optional)
- Building a detailed symbol table from the identifiers declared in the source code and in the external libraries referenced by the source code
- Building a low-level semantic model from the logic in the source code
- Analyzing the symbol table and semantic model and transforming it to fit the target requirements
- Authoring the target code for the semantic model and symbol table
- Post-Processing the target code (optional)
- Authoring the target code
During this process there are 3 points at which refactoring operations can be made; shown here in the context of a Translation Script.
<gmBasic> ... <Compile Project="%SrcPath%" > ' step 1: load code ' step 2: pre-process code ' step 3: build symbol table
First, after step 3, which builds the symbol table. This is a very effective place to strengthen the specifications of the symbols so that the compiler can take advantage of this additional information while generating the pseudo-code.
<Refactor ... >
' step 4: compile program logic into semantic model </Compile>
Second, after step 4 when the compiler has completed but the code analyzer has not yet run. This is an excellent time to introduce .NET types explicitly and to do any removals.
<Refactor ... > ' step 5: analyze the semantic model <Analyse />
Third, after step 5, when the analyzer has run, but before the author has executed. This is the best time to do symbol renaming and code re-authoring.
<Refactor ... >
<Author /> ...<gmBasic>Refactor Sub-Commands
Section titled “Refactor Sub-Commands”The Refactor command has five sub-commands:
- FixType: Specifies the binary type of a component or group of components
- Remove: Removes component from being authored
- Rename: Changes the authored name of components
- Reauthor: Replaces the authored content of a subprogram
- Migrate: Specifies a wide range of code re-engineering operations
- Transform: Specifies a wide range of code re-engineering operations
See Also
Section titled “See Also”Additional details are presented in the Reference section.