TraversalChecker.cpp (239462) | TraversalChecker.cpp (249423) |
---|---|
1//== TraversalChecker.cpp -------------------------------------- -*- C++ -*--=// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13//===----------------------------------------------------------------------===// 14#include "ClangSACheckers.h" 15#include "clang/AST/ParentMap.h" 16#include "clang/AST/StmtObjC.h" 17#include "clang/StaticAnalyzer/Core/Checker.h" 18#include "clang/StaticAnalyzer/Core/CheckerManager.h" 19#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" 20#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" | 1//== TraversalChecker.cpp -------------------------------------- -*- C++ -*--=// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13//===----------------------------------------------------------------------===// 14#include "ClangSACheckers.h" 15#include "clang/AST/ParentMap.h" 16#include "clang/AST/StmtObjC.h" 17#include "clang/StaticAnalyzer/Core/Checker.h" 18#include "clang/StaticAnalyzer/Core/CheckerManager.h" 19#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" 20#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" |
21#include "llvm/Support/raw_ostream.h" |
|
21 22using namespace clang; 23using namespace ento; 24 25namespace { 26class TraversalDumper : public Checker< check::BranchCondition, | 22 23using namespace clang; 24using namespace ento; 25 26namespace { 27class TraversalDumper : public Checker< check::BranchCondition, |
27 check::EndPath > { | 28 check::EndFunction > { |
28public: 29 void checkBranchCondition(const Stmt *Condition, CheckerContext &C) const; | 29public: 30 void checkBranchCondition(const Stmt *Condition, CheckerContext &C) const; |
30 void checkEndPath(CheckerContext &C) const; | 31 void checkEndFunction(CheckerContext &C) const; |
31}; 32} 33 34void TraversalDumper::checkBranchCondition(const Stmt *Condition, 35 CheckerContext &C) const { 36 // Special-case Objective-C's for-in loop, which uses the entire loop as its 37 // condition. We just print the collection expression. 38 const Stmt *Parent = dyn_cast<ObjCForCollectionStmt>(Condition); --- 5 unchanged lines hidden (view full) --- 44 // It is mildly evil to print directly to llvm::outs() rather than emitting 45 // warnings, but this ensures things do not get filtered out by the rest of 46 // the static analyzer machinery. 47 SourceLocation Loc = Parent->getLocStart(); 48 llvm::outs() << C.getSourceManager().getSpellingLineNumber(Loc) << " " 49 << Parent->getStmtClassName() << "\n"; 50} 51 | 32}; 33} 34 35void TraversalDumper::checkBranchCondition(const Stmt *Condition, 36 CheckerContext &C) const { 37 // Special-case Objective-C's for-in loop, which uses the entire loop as its 38 // condition. We just print the collection expression. 39 const Stmt *Parent = dyn_cast<ObjCForCollectionStmt>(Condition); --- 5 unchanged lines hidden (view full) --- 45 // It is mildly evil to print directly to llvm::outs() rather than emitting 46 // warnings, but this ensures things do not get filtered out by the rest of 47 // the static analyzer machinery. 48 SourceLocation Loc = Parent->getLocStart(); 49 llvm::outs() << C.getSourceManager().getSpellingLineNumber(Loc) << " " 50 << Parent->getStmtClassName() << "\n"; 51} 52 |
52void TraversalDumper::checkEndPath(CheckerContext &C) const { 53 llvm::outs() << "--END PATH--\n"; | 53void TraversalDumper::checkEndFunction(CheckerContext &C) const { 54 llvm::outs() << "--END FUNCTION--\n"; |
54} 55 56void ento::registerTraversalDumper(CheckerManager &mgr) { 57 mgr.registerChecker<TraversalDumper>(); 58} 59 60//------------------------------------------------------------------------------ 61 62namespace { | 55} 56 57void ento::registerTraversalDumper(CheckerManager &mgr) { 58 mgr.registerChecker<TraversalDumper>(); 59} 60 61//------------------------------------------------------------------------------ 62 63namespace { |
63class CallDumper : public Checker< check::PreCall > { | 64class CallDumper : public Checker< check::PreCall, 65 check::PostCall > { |
64public: 65 void checkPreCall(const CallEvent &Call, CheckerContext &C) const; | 66public: 67 void checkPreCall(const CallEvent &Call, CheckerContext &C) const; |
68 void checkPostCall(const CallEvent &Call, CheckerContext &C) const; |
|
66}; 67} 68 69void CallDumper::checkPreCall(const CallEvent &Call, CheckerContext &C) const { 70 unsigned Indentation = 0; 71 for (const LocationContext *LC = C.getLocationContext()->getParent(); 72 LC != 0; LC = LC->getParent()) 73 ++Indentation; 74 75 // It is mildly evil to print directly to llvm::outs() rather than emitting 76 // warnings, but this ensures things do not get filtered out by the rest of 77 // the static analyzer machinery. 78 llvm::outs().indent(Indentation); 79 Call.dump(llvm::outs()); 80} 81 | 69}; 70} 71 72void CallDumper::checkPreCall(const CallEvent &Call, CheckerContext &C) const { 73 unsigned Indentation = 0; 74 for (const LocationContext *LC = C.getLocationContext()->getParent(); 75 LC != 0; LC = LC->getParent()) 76 ++Indentation; 77 78 // It is mildly evil to print directly to llvm::outs() rather than emitting 79 // warnings, but this ensures things do not get filtered out by the rest of 80 // the static analyzer machinery. 81 llvm::outs().indent(Indentation); 82 Call.dump(llvm::outs()); 83} 84 |
85void CallDumper::checkPostCall(const CallEvent &Call, CheckerContext &C) const { 86 const Expr *CallE = Call.getOriginExpr(); 87 if (!CallE) 88 return; 89 90 unsigned Indentation = 0; 91 for (const LocationContext *LC = C.getLocationContext()->getParent(); 92 LC != 0; LC = LC->getParent()) 93 ++Indentation; 94 95 // It is mildly evil to print directly to llvm::outs() rather than emitting 96 // warnings, but this ensures things do not get filtered out by the rest of 97 // the static analyzer machinery. 98 llvm::outs().indent(Indentation); 99 if (Call.getResultType()->isVoidType()) 100 llvm::outs() << "Returning void\n"; 101 else 102 llvm::outs() << "Returning " << C.getSVal(CallE) << "\n"; 103} 104 |
|
82void ento::registerCallDumper(CheckerManager &mgr) { 83 mgr.registerChecker<CallDumper>(); 84} | 105void ento::registerCallDumper(CheckerManager &mgr) { 106 mgr.registerChecker<CallDumper>(); 107} |