Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev]: How does one get the namespace for a C++ declaration in the AST?

I have the following C++ code:

#include <iostream>
#include <string>
using namespace std;

int main() {
   string *a = new string("abc");
   a->size();
   a->append("a", 2);
std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
   return 0;
}

I have written a libstdc++ hover help plugin which is generated from the actual libstdc++ documentation.

When a user hovers over the "append" method above, I backtrack and find "a". I use a SharedASTJob to get the enclosing ASTName via:

ast.getNodeSelector(null).findEnclosingName();

I then do a second SharedASTJob to getDeclarationsinAST() for the binding of "a". This gets me an IASTSimpleDeclaration to which I perform ast.getDeclSpecifier(). This gets me an IASTNamedTypeSpecifier to which I get the name via getName().

The problem for the above case is that I only get "string". I need to get: "std::string" or "std::basic_string<char, etc..>" as I have a map of fully-qualified class and typedef names to which I can resolve the online help. I use a separate SharedASTJob to resolve to the correct append method signature and this is working great. For example, if the above test is changed to use std::string explicitly, everything works fine.

So how do I resolve the namespace for the declaration of a? I can send code off-line if further details are needed.

Thanks,

-- Jeff J.



Back to the top