[
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:
ast.getNodeSelector(null).findEnclosingName();
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.