[cfe-users] Get AST of uncomplete C++ code

Dr S3curity via cfe-users cfe-users at lists.llvm.org
Tue Apr 21 05:40:28 PDT 2020


Hi,

Imagine the very basic code below, it has some missing elements, we dont
have the foo() function and MyClass class,

```test.cpp
int main(int argc, char *argv[])
{
    MyClass* mc = new MyClass();
    mc.get_count();
    foo(1, 2, 3);
    std::cout << "this is a test" << endl;
}
```

How can I get AST for that code?
I tried `clang -Xclang -ast-dump -fsyntax-only test.cpp`, I can get the AST
tree but without MyClass and foo() function, it doesn't even say foo is a
function with 3 integer parameters.

This can be problematic for different cases for example IDE's where you
dont have all the project dependencies but yet you need to know what are
the elements in your code.

Is that possible to do with libclang? Any other suggestions are welcome.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200421/4cdaeafc/attachment.html>


More information about the cfe-users mailing list