[cfe-dev] QualType question

Boris Schäling via cfe-dev cfe-dev at lists.llvm.org
Sun Feb 7 03:37:48 PST 2016


"Tim Halloran via cfe-dev" <cfe-dev at lists.llvm.org> wrote in message news:CAFdkBy6St8R7p1cw0cUk_NCmJaq=+x719KuAk81cCgNTw0q49Q at mail.gmail.com...
I'm trying to refactor in C++: 

   using namespace std;
   string sp = " ";


into

   std::string sp = " ";

However when I examine the VarDecl node it is not obvious how to get to the namespace the "typedef <snip> sting" is declared in.
This worked for me: 
auto ty = varDecl->getType().getTypePtr();
if (ty->getTypeClass() == clang::Type::TypeClass::Typedef)
{
    auto tdty = ty->getAs<clang::TypedefType>();
    std::cout << tdty->getDecl()->getQualifiedNameAsString() << " " << varDecl->getNameAsString();
}

HTH, 
Boris 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160207/38e2dac3/attachment.html>


More information about the cfe-dev mailing list