Skip to content

Commit

Permalink
Add new match handler for Variable Declaration
Browse files Browse the repository at this point in the history
copied from lavatool on master
  • Loading branch information
m4mbr3 committed Nov 1, 2018
1 parent 0889417 commit a342759
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tools/lavaTool/include/VarDeclArgAdditionHandler.h
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

0 comments on commit a342759

Please sign in to comment.