Extract arithmetic operation information from C++ code

Clash Royale CLAN TAG#URR8PPP
Extract arithmetic operation information from C++ code
I am facing a problem of extracting arithmetic operation information from C++ source code. For example, I want to parse a C++ code such that I can find out the the line numbers for all the codes that conduct arithmetic operations as well as the name of the variables or literals involved in the operation and the corresponding operation type. I am interested in built-in types such as int and double as well as user-defined classes where arithmetic operators such as operator+, operator* are overloaded.
Any idea how this can be achieved?
Edit: I was hoping that some compilers might generate some intermediate results that I can utilize to achieve this goal. I did some search and it seems that libclang can generate some useful intermediate results, but I just want to get some suggestions before I spend too much time on digging into it.
Are you really trying to parse
h and cpp files yourself?? You should start reading Dragon's (Aho et al. ) book.– macroland
46 mins ago
h and cpp
The only way to parse C++ code is by using a C++ compiler. C++ is the most complicated general-purpose programming language in use today, and the only kind of a program in the world that knows how to parse C++ code is a C++ compiler. Looks like what you need to do is write your own C++ compiler, which should only take a few years. Just a few.
– Sam Varshavchik
13 mins ago
@njuffa yes I want to extract the information before optimization.
– Nan
34 secs ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
So you want to account for all arithmetic operation in the source code as written, regardless of whether such operations may be eliminated or modified in generated machine code during code optimizations, e.g. through CSE or strength reduction?
– njuffa
53 mins ago