cfe-dev Digest, Vol 67, Issue 3

Message: 2
Date: Tue, 1 Jan 2013 22:10:30 +0800
Cc: cfe-dev <cfe-dev@cs.uiuc.edu>
Subject: Re: [cfe-dev] how to determine a parameter has a type
  declarator in clang
Message-ID: <tencent_3B0F185D36A7D35B1138CC5C@qq.com>
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