Changes between Version 3 and Version 4 of SemanticQuery/Examples


Ignore:
Timestamp:
Feb 27, 2015, 1:40:32 PM (10 years ago)
Author:
manualwiki
Comment:

mostly sq-type related changes

Legend:

Unmodified
Added
Removed
Modified
  • SemanticQuery/Examples

    v3 v4  
    100100mods.funs[is_tail_recursive == non_tail_rec] 
    101101}}} 
     102 
     103== Practical example for using "-type", "-spec" related selectors and properties: == 
     104Let's say we are new to a project with a large code-base and our task is to implement a new interface in which we have to do some operations on a very complex data structure. The source of this complex structure is remote, but we know there are multiple compatible data structures already implemented, although not sure about the specifics, so we would like to investigate and do this without manually going through several thousand lines of code. 
     105 
     106We might start by running the following query: 
     107{{{ 
     108"files.typerefs" 
     109}}} 
     110This gives us all used types in every file. After scrolling to the end of the hundred and something pages of results, we at least know types properly specified, but not much else. 
     111Maybe we should only look at types defined in "general" modules: 
     112{{{ 
     113"mods[name ~ \"gen\"].types" 
     114}}} 
     115Unfortunately these seem to be either irrelevant or too general for us to use. We decide that we should look at types from other modules by filtering results using the "-spec" attributes (and let's assume, we are looking for a structure that has an "append" function implemented). 
     116But first we would like to know if "-spec" is used in our modules. 
     117{{{ 
     118"mods.funs[not (.name in files.specs.name)][loc > 10]" 
     119}}} 
     120The query results are promising, it looks like most of the non-trivial functions have a specification. 
     121We can take a look at returned types of functions named like "append": 
     122{{{ 
     123mods.funs[name ~ \"append\"].returntype 
     124}}} 
     125This query also gives us too many possible results, we are only interested in exported ones: 
     126{{{ 
     127mods.funs[name ~ \"append\"].returntype[exported] 
     128}}} 
     129Turns out most of them were exported. However when we have looked at types from "gen" modules, we may have noticed a type("person") for a structure which is a part of what we have to append to the large structure. 
     130{{{ 
     131mods.funs[name ~ \"append\"][.params.type.(subtype.(params)+)+[name = 'person']].returntype[exported] 
     132}}} 
     133This query only yields return-types of ~"append" functions that have a parameter whose type uses the "person" type. 
     134If we would like to see in which files these types have been used we could run the following: 
     135{{{ 
     136mods.funs[name ~ \"append\"][.params.type.(subtype.(params)+)+[name = 'person']].returntype[exported].references.file 
     137}}}