In one of my checker, i am using FunctionDecl class to get the function declaration. Now i want to get the name of the function for which i enter into the checkASTDecl method. As we know that in checkASTDecl() we get pointer of class FunctionDecl. So, can any one help me with way to get the name of function for which i entered into checkASTDecl.
Here is the sample code i have written:
namespace {
class FuncPrototypeChecker : public Checker<check::ASTDecl<FunctioeDecl> > {
mutable OwningPtr<BugType> TernaryOperatorBug;
public:
void checkASTDecl(const FunctionDecl *D,
AnalysisManager &mgr, BugReporter &BR) const;
};
}
void FuncPrototypeChecker::checkASTDecl(const FunctionDecl *D,
AnalysisManager &mgr,
BugReporter &BR) const {
/* Get the name of the function from FunctionDecl *D */
}
I want to get the name of the function for which i entered the method FuncPrototypeChecker::checkASTDecl(). Please help me with the way i can achieve it. Thanks in advance.
In fact, clang has a class to store names of decls (not just a
FunctionDecl
), calledDeclarationNameInfo
(see clang api for DeclarationNameInfo)You can get a
DeclarationNameInfo
instance for aFunctionDecl
using the API call:and the get the name as a string by:
The result returned will be a
std::string
.There is more information about the
FunctionDecl
API available in clang api for FunctionDecl.