BugReporter.h revision a43df9539644bf1c258e12710cd69d79b0b078cd
121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//===---  BugReporter.h - Generate PathDiagnostics --------------*- C++ -*-===//
221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//
3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o//                     The LLVM Compiler Infrastructure
421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//
521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o// This file is distributed under the University of Illinois Open Source
621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o// License. See LICENSE.TXT for details.
7543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o//
8543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o//===----------------------------------------------------------------------===//
921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//
1021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//  This file defines BugReporter, a utility class for generating
1121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//  PathDiagnostics for analyses based on ProgramState.
1221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//
13e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall//===----------------------------------------------------------------------===//
1421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
1521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifndef LLVM_CLANG_GR_BUGREPORTER
1621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#define LLVM_CLANG_GR_BUGREPORTER
17e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
1831dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o#include "clang/Basic/SourceLocation.h"
1921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h"
2021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
2121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
221e1da29fbd4204a267ebd7c64d37e1f95a9dad08Theodore Ts'o#include "llvm/ADT/FoldingSet.h"
231e1da29fbd4204a267ebd7c64d37e1f95a9dad08Theodore Ts'o#include "llvm/ADT/ilist.h"
241e1da29fbd4204a267ebd7c64d37e1f95a9dad08Theodore Ts'o#include "llvm/ADT/ilist_node.h"
2521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "llvm/ADT/ImmutableSet.h"
2621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "llvm/ADT/DenseSet.h"
2721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#include "llvm/ADT/SmallSet.h"
2821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
2921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'onamespace clang {
3021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
31e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallclass ASTContext;
32b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'oclass DiagnosticsEngine;
3321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass Stmt;
3421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass ParentMap;
3521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
3621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'onamespace ento {
37e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
3821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass PathDiagnostic;
3921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass ExplodedNode;
4021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass ExplodedGraph;
4121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass BugReport;
4221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass BugReporter;
43e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallclass BugReporterContext;
4421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass ExprEngine;
4521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass BugType;
4621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
4721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//===----------------------------------------------------------------------===//
4821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o// Interface for individual bug reports.
4921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o//===----------------------------------------------------------------------===//
50efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
5121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o/// This class provides an interface through which checkers can create
5221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o/// individual bug reports.
5321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oclass BugReport : public llvm::ilist_node<BugReport> {
5421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'opublic:
55e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall  class NodeResolver {
5621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o    virtual void anchor();
5721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  public:
5821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o    virtual ~NodeResolver() {}
5921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o    virtual const ExplodedNode*
6021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o            getOriginalNode(const ExplodedNode *N) = 0;
6121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  };
62e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
6321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef const SourceRange *ranges_iterator;
6421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef SmallVector<BugReporterVisitor *, 8> VisitorList;
6521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef VisitorList::iterator visitor_iterator;
6621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef SmallVector<StringRef, 2> ExtraTextList;
67e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
6821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oprotected:
6921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  friend class BugReporter;
7021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  friend class BugReportEquivClass;
7121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
7221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  BugType& BT;
7321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  const Decl *DeclWithIssue;
7421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  std::string ShortDescription;
7521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  std::string Description;
76e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall  PathDiagnosticLocation Location;
7721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  PathDiagnosticLocation UniqueingLocation;
7821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  const ExplodedNode *ErrorNode;
7921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  SmallVector<SourceRange, 4> Ranges;
8021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  ExtraTextList ExtraText;
8121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
8221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef llvm::DenseSet<SymbolRef> Symbols;
8321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  typedef llvm::DenseSet<const MemRegion *> Regions;
8421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
8521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  /// A (stack of) a set of symbols that are registered with this
8621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o  /// report as being "interesting", and thus used to help decide which
87  /// diagnostics to include when constructing the final path diagnostic.
88  /// The stack is largely used by BugReporter when generating PathDiagnostics
89  /// for multiple PathDiagnosticConsumers.
90  llvm::SmallVector<Symbols *, 2> interestingSymbols;
91
92  /// A (stack of) set of regions that are registered with this report as being
93  /// "interesting", and thus used to help decide which diagnostics
94  /// to include when constructing the final path diagnostic.
95  /// The stack is largely used by BugReporter when generating PathDiagnostics
96  /// for multiple PathDiagnosticConsumers.
97  llvm::SmallVector<Regions *, 2> interestingRegions;
98
99  /// A set of location contexts that correspoind to call sites which should be
100  /// considered "interesting".
101  llvm::SmallSet<const LocationContext *, 2> InterestingLocationContexts;
102
103  /// A set of custom visitors which generate "event" diagnostics at
104  /// interesting points in the path.
105  VisitorList Callbacks;
106
107  /// Used for ensuring the visitors are only added once.
108  llvm::FoldingSet<BugReporterVisitor> CallbacksSet;
109
110  /// Used for clients to tell if the report's configuration has changed
111  /// since the last time they checked.
112  unsigned ConfigurationChangeToken;
113
114  /// When set, this flag disables all callstack pruning from a diagnostic
115  /// path.  This is useful for some reports that want maximum fidelty
116  /// when reporting an issue.
117  bool DoNotPrunePath;
118
119private:
120  // Used internally by BugReporter.
121  Symbols &getInterestingSymbols();
122  Regions &getInterestingRegions();
123
124  void lazyInitializeInterestingSets();
125  void pushInterestingSymbolsAndRegions();
126  void popInterestingSymbolsAndRegions();
127
128public:
129  BugReport(BugType& bt, StringRef desc, const ExplodedNode *errornode)
130    : BT(bt), DeclWithIssue(0), Description(desc), ErrorNode(errornode),
131      ConfigurationChangeToken(0), DoNotPrunePath(false) {}
132
133  BugReport(BugType& bt, StringRef shortDesc, StringRef desc,
134            const ExplodedNode *errornode)
135    : BT(bt), DeclWithIssue(0), ShortDescription(shortDesc), Description(desc),
136      ErrorNode(errornode), ConfigurationChangeToken(0),
137      DoNotPrunePath(false) {}
138
139  BugReport(BugType& bt, StringRef desc, PathDiagnosticLocation l)
140    : BT(bt), DeclWithIssue(0), Description(desc), Location(l), ErrorNode(0),
141      ConfigurationChangeToken(0),
142      DoNotPrunePath(false) {}
143
144  /// \brief Create a BugReport with a custom uniqueing location.
145  ///
146  /// The reports that have the same report location, description, bug type, and
147  /// ranges are uniqued - only one of the equivalent reports will be presented
148  /// to the user. This method allows to rest the location which should be used
149  /// for uniquing reports. For example, memory leaks checker, could set this to
150  /// the allocation site, rather then the location where the bug is reported.
151  BugReport(BugType& bt, StringRef desc, const ExplodedNode *errornode,
152            PathDiagnosticLocation LocationToUnique)
153    : BT(bt), DeclWithIssue(0), Description(desc),
154      UniqueingLocation(LocationToUnique),
155      ErrorNode(errornode), ConfigurationChangeToken(0) {}
156
157  virtual ~BugReport();
158
159  const BugType& getBugType() const { return BT; }
160  BugType& getBugType() { return BT; }
161
162  const ExplodedNode *getErrorNode() const { return ErrorNode; }
163
164  const StringRef getDescription() const { return Description; }
165
166  const StringRef getShortDescription(bool UseFallback = true) const {
167    if (ShortDescription.empty() && UseFallback)
168      return Description;
169    return ShortDescription;
170  }
171
172  /// Indicates whether or not any path pruning should take place
173  /// when generating a PathDiagnostic from this BugReport.
174  bool shouldPrunePath() const { return !DoNotPrunePath; }
175
176  /// Disable all path pruning when generating a PathDiagnostic.
177  void disablePathPruning() { DoNotPrunePath = true; }
178
179  void markInteresting(SymbolRef sym);
180  void markInteresting(const MemRegion *R);
181  void markInteresting(SVal V);
182  void markInteresting(const LocationContext *LC);
183
184  bool isInteresting(SymbolRef sym);
185  bool isInteresting(const MemRegion *R);
186  bool isInteresting(SVal V);
187  bool isInteresting(const LocationContext *LC);
188
189  unsigned getConfigurationChangeToken() const {
190    return ConfigurationChangeToken;
191  }
192
193  /// Return the canonical declaration, be it a method or class, where
194  /// this issue semantically occurred.
195  const Decl *getDeclWithIssue() const;
196
197  /// Specifically set the Decl where an issue occurred.  This isn't necessary
198  /// for BugReports that cover a path as it will be automatically inferred.
199  void setDeclWithIssue(const Decl *declWithIssue) {
200    DeclWithIssue = declWithIssue;
201  }
202
203  /// \brief This allows for addition of meta data to the diagnostic.
204  ///
205  /// Currently, only the HTMLDiagnosticClient knows how to display it.
206  void addExtraText(StringRef S) {
207    ExtraText.push_back(S);
208  }
209
210  virtual const ExtraTextList &getExtraText() {
211    return ExtraText;
212  }
213
214  /// \brief Return the "definitive" location of the reported bug.
215  ///
216  ///  While a bug can span an entire path, usually there is a specific
217  ///  location that can be used to identify where the key issue occurred.
218  ///  This location is used by clients rendering diagnostics.
219  virtual PathDiagnosticLocation getLocation(const SourceManager &SM) const;
220
221  const Stmt *getStmt() const;
222
223  /// \brief Add a range to a bug report.
224  ///
225  /// Ranges are used to highlight regions of interest in the source code.
226  /// They should be at the same source code line as the BugReport location.
227  /// By default, the source range of the statement corresponding to the error
228  /// node will be used; add a single invalid range to specify absence of
229  /// ranges.
230  void addRange(SourceRange R) {
231    assert((R.isValid() || Ranges.empty()) && "Invalid range can only be used "
232                           "to specify that the report does not have a range.");
233    Ranges.push_back(R);
234  }
235
236  /// \brief Get the SourceRanges associated with the report.
237  virtual std::pair<ranges_iterator, ranges_iterator> getRanges();
238
239  /// \brief Add custom or predefined bug report visitors to this report.
240  ///
241  /// The visitors should be used when the default trace is not sufficient.
242  /// For example, they allow constructing a more elaborate trace.
243  /// \sa registerConditionVisitor(), registerTrackNullOrUndefValue(),
244  /// registerFindLastStore(), registerNilReceiverVisitor(), and
245  /// registerVarDeclsLastStore().
246  void addVisitor(BugReporterVisitor *visitor);
247
248	/// Iterators through the custom diagnostic visitors.
249  visitor_iterator visitor_begin() { return Callbacks.begin(); }
250  visitor_iterator visitor_end() { return Callbacks.end(); }
251
252  /// Profile to identify equivalent bug reports for error report coalescing.
253  /// Reports are uniqued to ensure that we do not emit multiple diagnostics
254  /// for each bug.
255  virtual void Profile(llvm::FoldingSetNodeID& hash) const;
256};
257
258} // end ento namespace
259} // end clang namespace
260
261namespace llvm {
262  template<> struct ilist_traits<clang::ento::BugReport>
263    : public ilist_default_traits<clang::ento::BugReport> {
264    clang::ento::BugReport *createSentinel() const {
265      return static_cast<clang::ento::BugReport *>(&Sentinel);
266    }
267    void destroySentinel(clang::ento::BugReport *) const {}
268
269    clang::ento::BugReport *provideInitialHead() const {
270      return createSentinel();
271    }
272    clang::ento::BugReport *ensureHead(clang::ento::BugReport *) const {
273      return createSentinel();
274    }
275  private:
276    mutable ilist_half_node<clang::ento::BugReport> Sentinel;
277  };
278}
279
280namespace clang {
281namespace ento {
282
283//===----------------------------------------------------------------------===//
284// BugTypes (collections of related reports).
285//===----------------------------------------------------------------------===//
286
287class BugReportEquivClass : public llvm::FoldingSetNode {
288  /// List of *owned* BugReport objects.
289  llvm::ilist<BugReport> Reports;
290
291  friend class BugReporter;
292  void AddReport(BugReport* R) { Reports.push_back(R); }
293public:
294  BugReportEquivClass(BugReport* R) { Reports.push_back(R); }
295  ~BugReportEquivClass();
296
297  void Profile(llvm::FoldingSetNodeID& ID) const {
298    assert(!Reports.empty());
299    Reports.front().Profile(ID);
300  }
301
302  typedef llvm::ilist<BugReport>::iterator iterator;
303  typedef llvm::ilist<BugReport>::const_iterator const_iterator;
304
305  iterator begin() { return Reports.begin(); }
306  iterator end() { return Reports.end(); }
307
308  const_iterator begin() const { return Reports.begin(); }
309  const_iterator end() const { return Reports.end(); }
310};
311
312//===----------------------------------------------------------------------===//
313// BugReporter and friends.
314//===----------------------------------------------------------------------===//
315
316class BugReporterData {
317public:
318  virtual ~BugReporterData();
319  virtual DiagnosticsEngine& getDiagnostic() = 0;
320  virtual ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() = 0;
321  virtual ASTContext &getASTContext() = 0;
322  virtual SourceManager& getSourceManager() = 0;
323};
324
325/// BugReporter is a utility class for generating PathDiagnostics for analysis.
326/// It collects the BugReports and BugTypes and knows how to generate
327/// and flush the corresponding diagnostics.
328class BugReporter {
329public:
330  enum Kind { BaseBRKind, GRBugReporterKind };
331
332private:
333  typedef llvm::ImmutableSet<BugType*> BugTypesTy;
334  BugTypesTy::Factory F;
335  BugTypesTy BugTypes;
336
337  const Kind kind;
338  BugReporterData& D;
339
340  /// Generate and flush the diagnostics for the given bug report.
341  void FlushReport(BugReportEquivClass& EQ);
342
343  /// Generate and flush the diagnostics for the given bug report
344  /// and PathDiagnosticConsumer.
345  void FlushReport(BugReport *exampleReport,
346                   PathDiagnosticConsumer &PD,
347                   ArrayRef<BugReport*> BugReports);
348
349  /// The set of bug reports tracked by the BugReporter.
350  llvm::FoldingSet<BugReportEquivClass> EQClasses;
351  /// A vector of BugReports for tracking the allocated pointers and cleanup.
352  std::vector<BugReportEquivClass *> EQClassesVector;
353
354  /// A map from PathDiagnosticPiece to the LocationContext of the inlined
355  /// function call it represents.
356  llvm::DenseMap<const PathDiagnosticCallPiece*,
357                 const LocationContext*> LocationContextMap;
358
359protected:
360  BugReporter(BugReporterData& d, Kind k) : BugTypes(F.getEmptySet()), kind(k),
361                                            D(d) {}
362
363public:
364  BugReporter(BugReporterData& d) : BugTypes(F.getEmptySet()), kind(BaseBRKind),
365                                    D(d) {}
366  virtual ~BugReporter();
367
368  /// \brief Generate and flush diagnostics for all bug reports.
369  void FlushReports();
370
371  Kind getKind() const { return kind; }
372
373  DiagnosticsEngine& getDiagnostic() {
374    return D.getDiagnostic();
375  }
376
377  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() {
378    return D.getPathDiagnosticConsumers();
379  }
380
381  /// \brief Iterator over the set of BugTypes tracked by the BugReporter.
382  typedef BugTypesTy::iterator iterator;
383  iterator begin() { return BugTypes.begin(); }
384  iterator end() { return BugTypes.end(); }
385
386  /// \brief Iterator over the set of BugReports tracked by the BugReporter.
387  typedef llvm::FoldingSet<BugReportEquivClass>::iterator EQClasses_iterator;
388  EQClasses_iterator EQClasses_begin() { return EQClasses.begin(); }
389  EQClasses_iterator EQClasses_end() { return EQClasses.end(); }
390
391  ASTContext &getContext() { return D.getASTContext(); }
392
393  SourceManager& getSourceManager() { return D.getSourceManager(); }
394
395  virtual void GeneratePathDiagnostic(PathDiagnostic& pathDiagnostic,
396                                      PathDiagnosticConsumer &PC,
397                                      ArrayRef<BugReport *> &bugReports) {}
398
399  bool RemoveUneededCalls(PathPieces &pieces, BugReport *R,
400                          PathDiagnosticCallPiece *CallWithLoc = 0);
401
402  void Register(BugType *BT);
403
404  /// \brief Add the given report to the set of reports tracked by BugReporter.
405  ///
406  /// The reports are usually generated by the checkers. Further, they are
407  /// folded based on the profile value, which is done to coalesce similar
408  /// reports.
409  void EmitReport(BugReport *R);
410
411  void EmitBasicReport(const Decl *DeclWithIssue,
412                       StringRef BugName, StringRef BugCategory,
413                       StringRef BugStr, PathDiagnosticLocation Loc,
414                       SourceRange* RangeBeg, unsigned NumRanges);
415
416  void EmitBasicReport(const Decl *DeclWithIssue,
417                       StringRef BugName, StringRef BugCategory,
418                       StringRef BugStr, PathDiagnosticLocation Loc) {
419    EmitBasicReport(DeclWithIssue, BugName, BugCategory, BugStr, Loc, 0, 0);
420  }
421
422  void EmitBasicReport(const Decl *DeclWithIssue,
423                       StringRef BugName, StringRef Category,
424                       StringRef BugStr, PathDiagnosticLocation Loc,
425                       SourceRange R) {
426    EmitBasicReport(DeclWithIssue, BugName, Category, BugStr, Loc, &R, 1);
427  }
428
429  static bool classof(const BugReporter* R) { return true; }
430
431  void addCallPieceLocationContextPair(const PathDiagnosticCallPiece *C,
432                                       const LocationContext *LC) {
433    LocationContextMap[C] = LC;
434  }
435private:
436  llvm::StringMap<BugType *> StrBugTypes;
437
438  /// \brief Returns a BugType that is associated with the given name and
439  /// category.
440  BugType *getBugTypeForName(StringRef name, StringRef category);
441};
442
443// FIXME: Get rid of GRBugReporter.  It's the wrong abstraction.
444class GRBugReporter : public BugReporter {
445  ExprEngine& Eng;
446public:
447  GRBugReporter(BugReporterData& d, ExprEngine& eng)
448    : BugReporter(d, GRBugReporterKind), Eng(eng) {}
449
450  virtual ~GRBugReporter();
451
452  /// getEngine - Return the analysis engine used to analyze a given
453  ///  function or method.
454  ExprEngine &getEngine() { return Eng; }
455
456  /// getGraph - Get the exploded graph created by the analysis engine
457  ///  for the analyzed method or function.
458  ExplodedGraph &getGraph();
459
460  /// getStateManager - Return the state manager used by the analysis
461  ///  engine.
462  ProgramStateManager &getStateManager();
463
464  virtual void GeneratePathDiagnostic(PathDiagnostic &pathDiagnostic,
465                                      PathDiagnosticConsumer &PC,
466                                      ArrayRef<BugReport*> &bugReports);
467
468  /// classof - Used by isa<>, cast<>, and dyn_cast<>.
469  static bool classof(const BugReporter* R) {
470    return R->getKind() == GRBugReporterKind;
471  }
472};
473
474class BugReporterContext {
475  virtual void anchor();
476  GRBugReporter &BR;
477public:
478  BugReporterContext(GRBugReporter& br) : BR(br) {}
479
480  virtual ~BugReporterContext() {}
481
482  GRBugReporter& getBugReporter() { return BR; }
483
484  ExplodedGraph &getGraph() { return BR.getGraph(); }
485
486  ProgramStateManager& getStateManager() {
487    return BR.getStateManager();
488  }
489
490  SValBuilder& getSValBuilder() {
491    return getStateManager().getSValBuilder();
492  }
493
494  ASTContext &getASTContext() {
495    return BR.getContext();
496  }
497
498  SourceManager& getSourceManager() {
499    return BR.getSourceManager();
500  }
501
502  virtual BugReport::NodeResolver& getNodeResolver() = 0;
503};
504
505} // end GR namespace
506
507} // end clang namespace
508
509#endif
510