Re: cfe-dev Digest, Vol 67, Issue 3

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: cfe-dev Digest, Vol 67, Issue 3

Rajendra
> Message: 2
> Date: Tue, 1 Jan 2013 22:10:30 +0800
> From: "=?gb18030?B?a2V2aW5seW54?=" <[hidden email]>
> To: "=?gb18030?B?Tmlrb2xhIFNtaWxqYW5pYw==?=" <[hidden email]>
> Cc: cfe-dev <[hidden email]>
> Subject: Re: [cfe-dev] how to determine a parameter has a type
> declarator in clang
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset="gb18030"
>
> Thanks for your reply. But i still can not figure it out. I get
> function declaration by these codes below:
>
> class MyASTVisitor : public RecursiveASTVisitor<MyASTVisitor>
> {
> public:
>     bool VisitFunctionDecl(FunctionDecl *f) {
>         for (FunctionDecl::param_iterator it = f->param_begin(); it
> != f->param_end(); ++it) {
>             ParmVarDecl *p = *it;
>             ...
>         }
>         return true;
>     }
> };
>
> which means I only get `FunctionDecl` object. I do not know how to
> get a `FunctionTypeInfo` you mentioned. Maybe I 'm not on the right
> way to parse a function definition/declaration.
>
> BTW, I'm writing a static code analyzer tool, and i will check
> whether a function parameter has a type declarator.
>

Try something like this:

   // Get function parameters
   std::cerr << "\n Function Parameters: \n";

   for (clang::FunctionDecl::param_iterator pit =
functionDecl->param_begin(); pit != functionDecl->param_end();
        pit++)
   {
     clang::Decl *param = *pit;

     const NamedDecl *namedDecl = dyn_cast<NamedDecl>(param);

     if (namedDecl)
     {
       std::cerr << "\tparam name = " << namedDecl->getNameAsString() <<
"\n";
     }

     const ValueDecl *valueDecl = dyn_cast<ValueDecl>(param);

     if (valueDecl)
     {
       QualType declQT = valueDecl->getType();
       clang::ASTContext &context = param->getASTContext();

       std::cerr << "\ttype = " <<
declQT.getAsString(context.getPrintingPolicy()) << "\n";
     }

- Rajendra

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev