-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new match handler for Variable Declaration
copied from lavatool on master
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef VARDECLARGADDITIONHANDLER_H | ||
#define VARDECLARGADDITIONHANDLER_H | ||
|
||
using namespace clang; | ||
|
||
struct VarDeclArgAdditionHandler : public LavaMatchHandler { | ||
using LavaMatchHandler::LavaMatchHandler; // Inherit constructor | ||
|
||
virtual void handle(const MatchFinder::MatchResult &Result) { | ||
const VarDecl *vd = | ||
Result.Nodes.getNodeAs<VarDecl>("vardecl"); | ||
SourceLocation l1 = vd->getLocStart(); | ||
SourceLocation l2 = vd->getLocEnd(); | ||
bool inv; | ||
debug(FNARG) << "vardecl : [" << getStringBetween(*Mod.sm, l1, l2, &inv) << "]\n"; | ||
if (inv) { | ||
debug(FNARG) << "... is invalid\n"; | ||
return; | ||
} | ||
const Type *ft = vd->getType().getTypePtr(); | ||
assert (ft); | ||
if (ft->isFunctionPointerType()) { | ||
// field is a fn pointer | ||
const Type *pt = ft->getPointeeType().IgnoreParens().getTypePtr(); | ||
assert(pt); | ||
const FunctionType *fun_type = dyn_cast<FunctionType>(pt); | ||
assert(fun_type); | ||
const FunctionProtoType *prot = dyn_cast<FunctionProtoType>(fun_type); | ||
// add the data_flow arg | ||
AddArgGen(Mod, l1, l2, false, prot->getNumParams(), 3); | ||
} | ||
} | ||
}; | ||
|
||
|
||
#endif |