RefactorScript
Contents
Overview
Running RefactorScripts
RefactorScript Window
RefactorScript Language
Data Model
Common RefactorScripts
Overview
RefactorScript is a mechanism for generating boilerplate code based on the existing C/C++ structures or functions. The typical uses for RefactorScript are:
- Automatically generating constructors or operators based on fields
- Automatically generating NULL checks for functions
- Automatically generating mock classes
- Automatically generating implementations for function pointer fields
RefactorScript is supported in VisualGDB Custom Edition and higher.
Running RefactorScripts
There are 2 ways of running a RefactorScript:
- Selecting one or more classes, fields, methods, variables, etc. in Code Explorer -> Outline, and using the Run RefactorScript button.
- Using the smart tags directly in the code editor
RefactorScript Window
Running a RefactorScript using either of the ways opens the RefactorScript window with the following controls:
- The script selector (1) showing both the scripts shipped with VisualGDB (in C:\Program Files (x86)\Sysprogs\VisualGDB\RefactorScripts) and the user-defined scripts (stored in %LOCALAPPDATA%\VisualGDB\RefactorScripts).
- Save and Save As buttons that allow saving the scripts (2). Note that the scripts in Program Files cannot be modified, however creating a script with the same name under %LOCALAPPDATA% will automatically override the script from Program Files.
- The instant update button (3) that controls whether the output is updated each time you edit the script. RefactorScript is designed to run very fast, so we recommend keeping this setting on.
- The controls for the script arguments (4) automatically derived from the arguments to the main generator of the script.
- Script input inspector showing the inputs passed to the main generator (5) and the properties of the selected element (6).
- The output from the current script (7) or a list of errors.
- Buttons (8) for copying the script output to Clipboard, or inserting it in the code (the latter is only available when using SmartTags). You can also insert the results of running a RefactorScript by pressing Ctrl-Enter.
The script editor provides very basic suggestion popups triggered by the ‘$’ and ‘.’ symbols:The suggestion popups work by quickly running the script until the edited position. This ensures accurate results, but will not work for the code branches that are never executed (e.g. disabled via main generator arguments).
RefactorScript Language
RefactorScripts are an advanced form of code snippets. Lines prefixed with “>” are copied to the output, while expanding the $-expressions. Lines not prefixed with “>” follow C#-like syntax and are used to iterate over arrays, check conditions (e.g. skip non-pointers) and define intermediate variables.
You can find a detailed description of the RefactorScript language on this page.
Data Model
RefactorScripts can access exhaustive information about the selected classes, functions, fields or other C/C++ entities, that can be used to fine-tune their output. You can easily explore this information via the right side of the RefactorScript window, or see our RefactorScript data model reference for the full list of all provided fields.
Common RefactorScripts
See this section for a list of RefactorScripts shipped with VisualGDB, along with practical use examples.