|
|
|
@ -18,41 +18,42 @@ namespace gjb {
|
|
|
|
|
|
|
|
|
|
void MyFirstCheckCheck::registerMatchers(MatchFinder *Finder) {
|
|
|
|
|
// FIXME: Add matchers.
|
|
|
|
|
Finder->addMatcher(functionDecl(isExpansionInMainFile(),
|
|
|
|
|
anyOf(hasDescendant(compoundStmt().bind("cpd")),
|
|
|
|
|
unless(hasDescendant(compoundStmt().bind("cpd")))
|
|
|
|
|
),
|
|
|
|
|
anyOf(hasDescendant(returnStmt().bind("ret")),
|
|
|
|
|
unless(hasDescendant(returnStmt().bind("ret")))
|
|
|
|
|
))
|
|
|
|
|
.bind("func"),
|
|
|
|
|
this);
|
|
|
|
|
Finder->addMatcher(
|
|
|
|
|
functionDecl(isExpansionInMainFile(),
|
|
|
|
|
anyOf(hasDescendant(compoundStmt().bind("cpd")),
|
|
|
|
|
unless(hasDescendant(compoundStmt().bind("cpd")))),
|
|
|
|
|
anyOf(hasDescendant(returnStmt().bind("ret")),
|
|
|
|
|
unless(hasDescendant(returnStmt().bind("ret")))))
|
|
|
|
|
.bind("func"),
|
|
|
|
|
this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFirstCheckCheck::check(const MatchFinder::MatchResult &Result) {
|
|
|
|
|
// FIXME: Add callback implementation.
|
|
|
|
|
|
|
|
|
|
/// get Node which we want to get
|
|
|
|
|
if(const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("func")){
|
|
|
|
|
if(const auto *MatchedDecl =
|
|
|
|
|
Result.Nodes.getNodeAs<FunctionDecl>("func")){
|
|
|
|
|
/// ReturnType is not 'void' or 'void *'
|
|
|
|
|
if(MatchedDecl->getReturnType().getAsString() != "void"
|
|
|
|
|
&& MatchedDecl->getReturnType().getAsString() != "void *"
|
|
|
|
|
/// Func Name is not "main"
|
|
|
|
|
&& MatchedDecl->getName() != "main"){
|
|
|
|
|
/// Func has definition
|
|
|
|
|
if(const auto *MatchedCpd = Result.Nodes.getNodeAs<CompoundStmt>("cpd")){
|
|
|
|
|
if(const auto *MatchedCpd =
|
|
|
|
|
Result.Nodes.getNodeAs<CompoundStmt>("cpd")){
|
|
|
|
|
/// Func has ReturnStmt
|
|
|
|
|
if(const auto *MatchedStmt = Result.Nodes.getNodeAs<ReturnStmt>("ret")){
|
|
|
|
|
if(const auto *MatchedStmt =
|
|
|
|
|
Result.Nodes.getNodeAs<ReturnStmt>("ret")){
|
|
|
|
|
}
|
|
|
|
|
/// Func does not have ReturnStmt
|
|
|
|
|
else{
|
|
|
|
|
diag(MatchedDecl->getLocation(), "Function '%0' has no return")
|
|
|
|
|
<< MatchedDecl->getName();
|
|
|
|
|
diag(MatchedDecl->getLocation(),
|
|
|
|
|
"Function '%0' has no return") << MatchedDecl->getName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace gjb
|