[cfe-dev] how to determine a parameter has a type declarator in clang

kevinlynx kevinlynx at gmail.com
Tue Jan 1 06:10:30 PST 2013


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.




------------------ 原始邮件 ------------------
发件人: "Nikola Smiljanic"<popizdeh at gmail.com>;
发送时间: 2013年1月1日(星期二) 晚上7:56
收件人: "kevinlynx"<kevinlynx at gmail.com>; 
抄送: "cfe-dev"<cfe-dev at cs.uiuc.edu>; 
主题: Re: [cfe-dev] how to determine a parameter has a type declarator in clang



Have a look at ArgInfo member of FunctionTypeInfo, the comment for ParamInfo structure has the relevant part:

/// ParamInfo - An array of paraminfo objects is allocated whenever a function
 /// declarator is parsed.  There are two interesting styles of arguments here:
/// K&R-style identifier lists and parameter type lists.  K&R-style identifier
/// lists will have information about the identifier, but no type information.
 /// Parameter type lists will have type info (if the actions module provides
/// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.

On Mon, Dec 31, 2012 at 6:40 PM, kevinlynx <kevinlynx at gmail.com> wrote:
 
I use clang to do some code analyse. And now i have a function below

    void func(p)
 
some compilers will process p as an integer. And i want to know how to determine whether p has a type declarator ?




_______________________________________________
 cfe-dev mailing list
 cfe-dev at cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130101/80c19954/attachment.html>


More information about the cfe-dev mailing list