c - Using clang matchers to detect sequence of patterns -


is possible use clang matchers identify sequence of patterns in program?

for example need find cases in pattern1 happens before pattern2.

for instance:

pattern1 = assigning value pointer p
pattern2 = dereferencing pointer p

i can identify cases pattern1 , pattern2 happen in code, possible specify ordering? (say pattern1 has happen before pattern2 , match cases) thanks!

correct answer

in reality traversing asts sequence patterning (which basis of static analysis) not correct approach because don't know whether statement pattern1 going happen before pattern2

consider

 int foo() {        int = 0;        int *b;        int c = -1;        if(c < 0) goto fixit;  nowhat:        b = &a;  fixit:         c = *b;        goto nowhat;  } 

as can see ast not going here cfg correct thing use.

somewhat of answer using asts

if @ traversal matchers in ast (v6.0.0) are, pretty much, hierarchical in nature. looking extend matching siblings.

much of assumes know how implement custom ast matcher. if not, explained rather nicely manu sánchez in writing ast matchers libclang blog post.

not sure if gets actually writing sibling matcher, comes close it, start there , have implement akin this:

let's given code:

  class p {}; class q {}; class r {}; 

we want able like:

 (matcher = recorddecl(hasname("p"), \         hasnextsibling(recorddecl(hasname("r"))))` 

you can combine matcheschild , matchesparent in astmatchfinder class , traverse children of parent of current cursor (these siblings :p). read footnotes have implement boundcursors in order avoid runaway recursion.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -