Hello,<br><br>I'm working on a parser for C headers. I need to find all functions *declared* in a single header, but this header may include additional headers and I want to ignore functions from these additional headers. I use a recursive AST visitor to find out all Decls in the header.<br>
To make a difference between functions declared in my header, or declared in included headers,<br>I use:<br><br>if ( d->getKind() == clang::Decl::Function )<br>    {<br>    clang::FunctionDecl *fdecl =<br>                clang::dyn_cast<clang::FunctionDecl> ( d );<br>
<br>        clang::SourceLocation loc = d->getLocation();<br>        if ( ast->getSourceManager().isFromMainFile ( loc ) )<br>        {<br>            // function declaration is in the main file, keep it<br>        }<br>
<br>...<br><br>This works well, but if I have some code like:<br><br>#ifdef CHECK_ERRORS<br>#define foo_my_func foo_my_func_safe<br>#else<br>#define foo_my_func foo_my_func_unsafe<br>#endif<br><br>void foo_my_func(void);<br>
<br>Then the renamed function foo_my_func_unsafe is found in the file...<br>But ast->getSourceManager().isFromMainFile ( loc ) returns *false*. The<br>function is hence filtered even though it's actually declared in the main header.<br>
<br>What's the best way to check if a function (or a class, or any decl) is<br>declared in the main file (the single C header in my case), taking in account this<br>macro renaming case?<br><br>Thank you for your help,<br>
<br>Pascal<br>