51 | | = Using the web interface |
| 64 | In the next examples we will use the source of the Mnesaia database as a target software. |
| 65 | * starting the tool: {{{bin/referl -db kcmini}}} |
| 66 | * building the database: |
| 67 | {{{ |
| 68 | Eshell V10.6.1 (abort with ^G) |
| 69 | (refactorerl@localhost)1> ri:ls(). |
| 70 | {{ok,[]},{error,[]}} |
| 71 | ok |
| 72 | (refactorerl@localhost)2> ri:envs(). |
| 73 | output = original |
| 74 | appbase = "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib" |
| 75 | ok |
| 76 | (refactorerl@localhost)3> ri:add(erlang, mnesia). |
| 77 | Adding: /usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src |
| 78 | | 5.20 kB/s >>>>>>>>>>>>>>>>>>>| [ 420/ 420] mnesia.erl |
| 79 | | 6.78 kB/s >>>>>>>>>>>>>>>>>>>| [ 5/ 5] mnesia_app.erl |
| 80 | | 8.12 kB/s >>>>>>>>>>>>>>>>>>>| [ 3/ 3] mnesia_backend_type.erl |
| 81 | | 5.13 kB/s >>>>>>>>>>>>>>>>>>>| [ 12/ 12] mnesia_backup.erl |
| 82 | |>>>>>>>>>>>> 6.05 kB/s| [ 48/ 87] mnesia_bup.erl |
| 83 | .... |
| 84 | (refactorerl@localhost)4> ri:ls(). |
| 85 | {{ok,["/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_app.erl", |
| 86 | "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_controller.erl", |
| 87 | "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_ext_sup.erl", |
| 88 | "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_frag_hash.erl", |
| 89 | .... |
| 90 | }}} |
| 91 | |
| 92 | {{{ri:ls()}}} checks the content of the database, so it lists the already analysed files. |
| 93 | {{{ri:envs()}}} checks the environmental variables of !RefactorErl. You might realise that the path of the Erlang installation library was already set, so we can use its subkey to add the mnesia application: {{{ri:add(erlang, mnesia).}}} |
| 94 | |
| 95 | The query {{{ri:q("mods.loc:sum").}}} returns the line of code analyzed: |
| 96 | {{{ |
| 97 | (refactorerl@localhost)5> ri:q("mods.loc:sum"). |
| 98 | sum = 24299 |
| 99 | }}} |
57 | | = Code duplicates |
| 105 | The query language was designed according to the syntactic/semantic entities of the Erlang language. So it introduces files, macros, modules, functions, expressions, records, record fields, etc. |
| 106 | |
| 107 | The detailed description of the queries can be found [wiki:SemanticQuery here]. The description of the entities, its properties and selectors are defined [http://pnyf.inf.elte.hu/trac/refactorerl/wiki/SemanticQuery/Components here], but you can use the {{{?}}} selector in {{{ri}}}: {{{ri:q("mods.?")}}}. For further examples please check this [http://pnyf.inf.elte.hu/trac/refactorerl/wiki/SemanticQuery/Examples page]. |
| 108 | |
| 109 | Once you build a query, you need an initial selector to start. That can be either a position based entity selection {{{@fun}}} -- the function pointed in the web interface, or a global starting point, like {{{mods}}} -- all analysed modules. |
| 110 | |
| 111 | Once you selected an entity, you may ask some property of that entity: |
| 112 | * {{{mods.name}}} -- the name of the module |
| 113 | or ask its connected entities: |
| 114 | * {{{mods.funs}}} -- functions defined in the modules |
| 115 | |
| 116 | You can also filter the entities: |
| 117 | * {{{mods[name=foo].funs.calls}}} -- what are the functions that are called in the functions of the foo module |
| 118 | |
| 119 | In the following, we will show some queries on the previously built database from the source of Mnesia. |
| 120 | |
| 121 | == Detecting relations, gathering information about the source code |
| 122 | |
| 123 | * {{{ri:q(mods[name=mnesia_log].funs).}}} -- listing all the functions from the mnesia_log module |
| 124 | * {{{ri:q(mods[name=mnesia_log].funs.name).}}} -- listing the name of the functions from the mnesia_log module |
| 125 | * {{{ri:q(mods[name=mnesia_log].funs.refs).}}} -- listing the references (the function applications) of the the functions from the mnesia_log module |
| 126 | * {{{ri:q(mods[name=mnesia_log].funs[.refs]).}}} |
| 127 | * {{{mods[name=mnesia_log].funs[name=open_log]}}} |
| 128 | * {{{mods[name=mnesia_log].funs[name=open_log, arity=4]}}} |
| 129 | * {{{mods[name=mnesia_log].funs[name=open_log].refs}}} |
| 130 | * {{{mods[name=mnesia_log].funs[name=open_log].called_by}}} |
| 131 | * {{{@fun.called_by}}} |
| 132 | * {{{mods[name=mnesia_log].funs[name=open_log].calls}}} |
| 133 | * {{{@fun.calls}}} |
| 134 | |
| 135 | == Checking design rules |
| 136 | |
| 137 | == Detecting vulnerabilities |
| 138 | |
| 139 | == |