0

Here's some background of what I'm trying to achieve. I'm in need of parsing C++ source code to find all instances where function X is called. This seems doable in libclang as mentioned in this post: Find all references of specific function declaration in libclang (Python) (though the answer implies it isn't as simple as you might think).

However, problem with libclang is that using it on Windows is often not recommended by many people. I can't use it on Linux because I'm hoping to use it on existing Visual C++ code that uses winapi.

With this barrier, I asked a colleague and he suggest I just simply search the source code using regular expression. I have my doubts that this is easy.

Can someone tell me if this approach is recommended?

Edit to address the comment of what my goal is: I need to do it programmatically because I'm tryng to integrate it to an infastructure that checks where the code was editted and then gives you an output on which end-user functionality is affected by that edit and thus needs to be rechecked. If I were to do this manually via the "find references" options in IDE, this means "finding references" in multiple levels until I reach the end-user level which is a lot of work for large code and prone to error.

marumaru
  • 55
  • 5
  • 2
    not clear to me what is the question. If you have doubts if something is easy then just try it. As software developers we are in the fortunate situation that we can try stuff without breaking anything – 463035818_is_not_an_ai Oct 20 '17 at 08:39
  • What about searching with OS tools? *nix: "grep -ir ". Windows: With Explorer / build in Search. – Ralph Erdt Oct 20 '17 at 08:44
  • 2
    I'd daresay searching for `functionName` **is** the easiest way. Alternatively, rename the function, and look at the compiler output complaining about it... – DevSolar Oct 20 '17 at 08:49
  • For a non-trivial code base using regular expressions could be too slow. Traversing the directory structure and text searching within the files would be easy and fast. Slightly harder to identify and ignore the declaration and definition of the name. Significantly harder if you want to ignore occurrences of the name within /**/ comments. – acraig5075 Oct 20 '17 at 09:01
  • What do you need this for? Can't you just use VS "Find all references"? If this is supposed to be done programmatically then there is no way you can get away with just regular expressions or simply finding something with the same name as that function. C++ syntax is exceptionally difficult to parse yet standard committee keeps inventing new crazy rules every month. And it goes without saying that you'll need to extract project settings of the target codebase somehow. – user7860670 Oct 20 '17 at 09:53
  • @VTT I need to do it programmatically because I'm tryng to integrate it to an infastructure that checks where the code was editted and then gives you an output on which end-user functionality is affected by that edit and needs to be re-tested. This also requires "finding references" in multiple levels until I reach the end-user level which is a lot of work for large code and prone to error. – marumaru Oct 22 '17 at 05:38
  • "using it on Windows is often not recommended by many people." Who are those people and what do they recommend instead? Why do you think you will find better advice here? – n. m. could be an AI Oct 22 '17 at 05:56
  • "[check]... which end-user functionality is affected by that edit and needs to be re-tested" - sounds like you need a better testing strategy. Regression tests would find differing behavior regardless of what caused it. – kmdreko Oct 22 '17 at 06:32

0 Answers0