Skip to main content

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

Sergey Prigogin wrote:

On Fri, May 8, 2009 at 1:43 PM, Jeff Johnston <jjohnstn@xxxxxxxxxx <mailto:jjohnstn@xxxxxxxxxx>> wrote:

    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:


IASTName name = Â ast.getNodeSelector(null).findEnclosingName();
IBinding binding = name.resolveBinding();
String[] qualified;
if (binding instanceof ICPPBinding) {
  qualified = ((ICPPBinding) binding).getQualifiedName()
} else {
  qualified = new String[] { binding.getName() };

The only thing left is to join the names using "::" as a separator.

I'll try that.  Thank you.

-- Jeff J.

Back to the top