Changes between Initial Version and Version 1 of ErlangShellInterface


Ignore:
Timestamp:
Mar 6, 2012, 11:40:11 PM (13 years ago)
Author:
manualwiki
Comment:

Created ri page, with some sections

Legend:

Unmodified
Added
Removed
Modified
  • ErlangShellInterface

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