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
), called DeclarationNameInfo
(see clang api for DeclarationNameInfo)
You can get a DeclarationNameInfo
instance for a FunctionDecl
using the API call:
functionDecl->getNameInfo();
and the get the name as a string by:
functionDecl->getNameInfo().getAsString();
The result returned will be a std::string
.
There is more information about the FunctionDecl
API available in clang api for FunctionDecl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With