| 1 | |
| 2 | == RefactorErl Console Interface == |
| 3 | After start up you can use the ri module to interact easily with the tool. With this you can add files/directories to the database, run semantic queries, create backups, or even do transformations. |
| 4 | |
| 5 | |
| 6 | == General help == |
| 7 | Help can be acquired in ri with |
| 8 | |
| 9 | {{{ |
| 10 | ri:help(). |
| 11 | }}} |
| 12 | |
| 13 | or even shorter as |
| 14 | |
| 15 | {{{ |
| 16 | ri:h(). |
| 17 | }}} |
| 18 | |
| 19 | This function lists several topics, on which further help is available as |
| 20 | |
| 21 | {{{ |
| 22 | ri:h(Topic). |
| 23 | }}} |
| 24 | |
| 25 | If the name of a function is known, specic help can be acquired by adding |
| 26 | an _h postfix to the name. For example, help for the function add is available |
| 27 | as |
| 28 | |
| 29 | |
| 30 | {{{ |
| 31 | ri:add_h() |
| 32 | }}} |
| 33 | |
| 34 | |
| 35 | == Compiling the tool == |
| 36 | The tool can be recompiled by invoking |
| 37 | |
| 38 | {{{ |
| 39 | ri:build(). |
| 40 | }}} |
| 41 | |
| 42 | This function can also take a list of build parameters. This feature is mostly |
| 43 | used through development. |
| 44 | Note that this function tries to compile the C++ files as well, if these were |
| 45 | not compiled before. So if you want to prevent this, then you have to specify the |
| 46 | no_nif additional parameter to the function. So in this case the recompilation |
| 47 | looks like this: |
| 48 | |
| 49 | {{{ |
| 50 | ri:build(no_nif). |
| 51 | }}} |
| 52 | |
| 53 | |
| 54 | == Managing files == |
| 55 | You can add files to the RefactorErl database by calling the |
| 56 | add function with either a filename as a string or a module name as an atom. |
| 57 | Note that in the latter case, "ri" defaults to the current working directory |
| 58 | (which you may work around by including a path in your singe-quoted atom). |
| 59 | If you specify a directory instead of a regular filename, then it will be recursively |
| 60 | traversed. You may just as well give a list of atoms or strings to add more files |
| 61 | at once. All of the following example commands would add the same le: |
| 62 | |
| 63 | {{{ |
| 64 | cd(dir), ri:add(modname). |
| 65 | ri:add('dir/modname'). |
| 66 | ri:add(['dir/modname']). |
| 67 | ri:add("dir/modname.erl"). |
| 68 | ri:add("/current/dir/modname.erl"). |
| 69 | }}} |
| 70 | |
| 71 | The module displays the progression of loading. |
| 72 | Removing files from the database is similarly easy and also recursive, except |
| 73 | for one difference. As the system by the time you want to remove a module must |
| 74 | know the exact location of the said, you need not restrict yourself to dropping a |
| 75 | module relative to the current directory, but must in exchange use real module |
| 76 | names that do not contain path delimiters. The following will equally work: |
| 77 | |
| 78 | {{{ |
| 79 | ri:drop(modname). |
| 80 | ri:drop([modname]). |
| 81 | ri:drop("dir/modname.erl"). |
| 82 | ri:drop("/current/dir/modname.erl"). |
| 83 | }}} |
| 84 | |
| 85 | Modules can be loaded as applications, but the base of your library has to |
| 86 | be set before: |
| 87 | |
| 88 | {{{ |
| 89 | ri:addenv(appbase, "path/to/my/applib"). |
| 90 | }}} |
| 91 | |
| 92 | You can check the already given application base directories: |
| 93 | |
| 94 | {{{ |
| 95 | ri:envs(). |
| 96 | }}} |
| 97 | |
| 98 | Let's see an example: |
| 99 | |
| 100 | {{{ |
| 101 | (refactorerl@localhost)18> ri:envs(). |
| 102 | output = original |
| 103 | appbase = "/usr/local/lib/erlang/lib" |
| 104 | |
| 105 | (refactorerl@localhost)19> ri:add(usr, synatx_tools). |
| 106 | Application synatx_tools not found under usr |
| 107 | not_found |
| 108 | |
| 109 | (refactorerl@localhost)20> ri:add(usr, syntax_tools). |
| 110 | Adding: /usr/local/lib/erlang/lib/syntax_tools-1.6.7.1/src |
| 111 | ... |
| 112 | }}} |
| 113 | |
| 114 | You can also set include directories to your include files using: |
| 115 | |
| 116 | {{{ |
| 117 | ri:addenv(include, "path/to/my/include"). |
| 118 | }}} |
| 119 | |
| 120 | It is possible to delete the defined environment variables: |
| 121 | |
| 122 | {{{ |
| 123 | ri:delenv(include). |
| 124 | }}} |
| 125 | |
| 126 | Loaded files can be saved using |
| 127 | |
| 128 | {{{ |
| 129 | ri:save(Filename). |
| 130 | }}} |
| 131 | |
| 132 | For convenience, both the filenames and the directory names can be given |
| 133 | as atoms as well as strings. |
| 134 | The list of loaded files can be obtained by calling |
| 135 | |
| 136 | {{{ |
| 137 | ri:ls(). |
| 138 | }}} |
| 139 | |
| 140 | This call also displays the status of the loaded files (error or no_error). |
| 141 | If the module m is loaded, |
| 142 | |
| 143 | {{{ |
| 144 | ri:ls(m). |
| 145 | }}} |
| 146 | |
| 147 | will give information about the functions, records and macros in the file. |
| 148 | The contents of a file can be listed by |
| 149 | |
| 150 | {{{ |
| 151 | ri:cat(m). |
| 152 | }}} |
| 153 | |
| 154 | Loading BEAM files. Usually, Erlang source files (having the extension |
| 155 | .erl) are loaded into RefactorErl. In addition, RefactorErl is also capable of |
| 156 | loading compiled .beam files. |
| 157 | |
| 158 | {{{ |
| 159 | ri:add("compiled.beam"). |
| 160 | }}} |
| 161 | |
| 162 | Note that this feature is applicable only to those .beam files that were compiled |
| 163 | with the debug_info option. Also note that the resulting file will be pretty |
| 164 | printed by RefactorErl. |
| 165 | |
| 166 | == Using transformations == |
| 167 | Transformations can be called using their abbreviated |
| 168 | names, and the list of required parameters. These commands are listed in |
| 169 | [[RefactoringSteps|refactoring functionalities]]. |
| 170 | There is another way to call a transormation. This way let the user to |
| 171 | choose: user want to specify all of arguments or not. There are lots of cases |
| 172 | when the user can not specify all of the required arguments. In this case the |
| 173 | tool can help the user with interactions. The tool ask questions and the user |
| 174 | has to answer it to specify the missing arguments. The interactions also work if |
| 175 | there is some problem with the given arguments. |
| 176 | |
| 177 | == Manipulating the graph == |
| 178 | You can reset RefactorErl by invoking |
| 179 | |
| 180 | {{{ |
| 181 | ri:reset(). |
| 182 | }}} |
| 183 | |
| 184 | This will remove all loaded files. This function should be called if the graph |
| 185 | gets corrupted. |
| 186 | You can add a checkpoint using |
| 187 | |
| 188 | {{{ |
| 189 | ri:backup(). |
| 190 | }}} |
| 191 | |
| 192 | If the transformations you have performed are not satisfactory, you can go |
| 193 | back to the previous checkpoint using |
| 194 | |
| 195 | {{{ |
| 196 | ri:undo(). |
| 197 | }}} |
| 198 | |
| 199 | If you use NIF, then it is little different:[[BR]] |
| 200 | You can create backups with '''ri:backup/0''' or '''ri:backup/1''' and you can load |
| 201 | these backups with '''ri:restore/1'''. |
| 202 | When execute a transformation a backup will be created, which name differs |
| 203 | from the ordinary backups, and the '''ri:undo/0''' function will restore that. |
| 204 | |
| 205 | == Inspecting the graph == |
| 206 | You can draw the semantic representation graph of RefactorErl by calling |
| 207 | |
| 208 | {{{ |
| 209 | ri:graph(). |
| 210 | }}} |
| 211 | |
| 212 | This function produces a .dot file (by default, graph.dot, although this can be |
| 213 | customised), which can be transformed to several visual formats using Graphviz. |
| 214 | One of these transformations is available from RefactorErl for convenience: |
| 215 | |
| 216 | {{{ |
| 217 | ri:svg(). |
| 218 | }}} |
| 219 | |
| 220 | The representation can be ltered: |
| 221 | |
| 222 | {{{ |
| 223 | ri:svg(OutFile, Filter). |
| 224 | }}} |
| 225 | |
| 226 | where Filter is one of the following:[[BR]] |
| 227 | all: default, all edges except environmental ones are shown |
| 228 | syn: only syntactic edges are shown |
| 229 | sem: only semantic edges are shown |
| 230 | lex: only lexical edges are shown |
| 231 | all_env: all edges are shown, no ltering |
| 232 | ctx: context related edges are shown |
| 233 | not_lex: all edges except lexical ones are shown |
| 234 | dataflow: dataflow related edges are shown |
| 235 | a list of the above: shows the union of the designated subgraphs |
| 236 | |
| 237 | == Using queries == |
| 238 | Queries 6 can be invoked by either |
| 239 | |
| 240 | {{{ |
| 241 | ri:q(Query). |
| 242 | }}} |
| 243 | |
| 244 | or |
| 245 | |
| 246 | {{{ |
| 247 | ri:q(Module, Regexp, Query). |
| 248 | }}} |
| 249 | |
| 250 | The former is applicable when a query starts generally, such as |
| 251 | |
| 252 | {{{ |
| 253 | ri:q("mods.funs.name"). |
| 254 | }}} |
| 255 | |
| 256 | For those queries that begin from a selected position (these queries start |
| 257 | with "@" when used from Emacs), the second variant is required. As the console |
| 258 | cannot mark a position, the first and the second component indicate the starting |
| 259 | point for the query. The following example shows how to get all the variables |
| 260 | used in the body of the function f/2 from the module m. |
| 261 | |
| 262 | {{{ |
| 263 | ri:q(m, "f\\\\(X, Y\\\\)", "@fun.var"). |
| 264 | }}} |
| 265 | |
| 266 | Additional options can be given to a semantic query in a proplist as the last |
| 267 | argument. The following arguments are currently recognized: |
| 268 | {out,FileName} - write the textual output of a query to a file |
| 269 | linenum - prepends match sites with le and line number information |
| 270 | similar to grep -n. |
| 271 | The following example outputs all dened functions with line numbers to a |
| 272 | file named result.txt. |
| 273 | |
| 274 | {{{ |
| 275 | ri:q("mods.funs",[linenum,{out,"result.txt"}]). |
| 276 | }}} |