[cfe-dev] using clang - getting type for C variable declaration

João Matos ripzonetriton at gmail.com
Thu Nov 8 08:47:21 PST 2012


You can use ValueDecl::getType.

http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html

On Thu, Nov 8, 2012 at 4:35 PM, Rajendra <rks at cse.iitb.ac.in> wrote:

> Hi,
>
> Using clang API, I want to get type for a declaration.
>
> e.g. declaration is: int x; I am getting variable name as x but I am not
> able to get type of x.
>
> If I can get clang::QualType then I can see type, but I am not getting how
> to get clang::QualType from clang::Decl
>
>   clang::DeclGroupRef::iterator it;
>
>   for (it = declGroupRef.begin(); it != declGroupRef.end(); it++)
>   {
>
>     clang::Decl* decl = *it;
>     std::cerr << "\tdecl statement: ";
>     decl->dump();        // --> this gives `int x'
>
>     const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);
>
>     if (namedDecl)
>     {
>       std::cerr << "\t\tidentifier name = "
>         << namedDecl->getNameAsString() << "\n";        // --> this gives
> `x'
>     }
>
>   }
>
> Any pointers?
>
> Rajendra
> ______________________________**_________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/**mailman/listinfo/cfe-dev<http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>
>



-- 
João Matos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121108/8d17558c/attachment.html>


More information about the cfe-dev mailing list