I am using Libclang’s python binding. I have basically two queries:
I want to know how can we parse library function which are neither defined by user nor for which a library has been included.. For e.g. when I have the following source code –
char* a=(char *)malloc(4);
- Libclang is unable to parse malloc( ) because neither stdlib has been included in this code nor has a user-defined definition provided for malloc.
An object not defined using a constructor is not recognized by Libclang’s AST. For e.g., in the source code -
vector<int> color; color.push_back(1); color.push_back(2);
the push_back( )statements will not be parsed but when written like this:
vector<int> color=new vector<int>();
color.push_back(1);
color.push_back(2);
it parses correctly.
Another surprising manifestation of this behavior is when such objects are passed as function parameters to a user defined function. For e.g.
bool check(int **grid, vector<char> color){ color.push_back('a'); }
push_back( ) is still not identified but when this is written, things are parsed correctly
bool check(int **grid, vector<char> color, int anc, int cur){
vector<char> color = new vector<int>()
color.push_back('a');
Would be great if someone is able to suggest a workaround. Perhaps there’s a flag which when set is able to avoid this?
You need to add the following argument
-x c++ -std=c++11
when calling parse, otherwise it defaults to parsing C code for .h files. You might rename the header file to .hpp
Here is what my helper script looks like.
The source file I tested on looks like this