BugType.h revision 9b663716449b618ba0390b1dbebc54fa8e971124
1//===---  BugType.h - Bug Information Desciption ----------------*- 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//===----------------------------------------------------------------------===//
9//
10//  This file defines BugType, a class representing a bug type.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_ANALYSIS_BUGTYPE
15#define LLVM_CLANG_ANALYSIS_BUGTYPE
16
17#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
18#include "llvm/ADT/FoldingSet.h"
19#include <string>
20
21namespace clang {
22
23namespace ento {
24
25class ExplodedNode;
26class ExprEngine;
27
28class BugType {
29private:
30  const std::string Name;
31  const std::string Category;
32  llvm::FoldingSet<BugReportEquivClass> EQClasses;
33  friend class BugReporter;
34  bool SuppressonSink;
35public:
36  BugType(llvm::StringRef name, llvm::StringRef cat)
37    : Name(name), Category(cat), SuppressonSink(false) {}
38  virtual ~BugType();
39
40  // FIXME: Should these be made strings as well?
41  llvm::StringRef getName() const { return Name; }
42  llvm::StringRef getCategory() const { return Category; }
43
44  /// isSuppressOnSink - Returns true if bug reports associated with this bug
45  ///  type should be suppressed if the end node of the report is post-dominated
46  ///  by a sink node.
47  bool isSuppressOnSink() const { return SuppressonSink; }
48  void setSuppressOnSink(bool x) { SuppressonSink = x; }
49
50  virtual void FlushReports(BugReporter& BR);
51
52  typedef llvm::FoldingSet<BugReportEquivClass>::iterator iterator;
53  iterator begin() { return EQClasses.begin(); }
54  iterator end() { return EQClasses.end(); }
55
56  typedef llvm::FoldingSet<BugReportEquivClass>::const_iterator const_iterator;
57  const_iterator begin() const { return EQClasses.begin(); }
58  const_iterator end() const { return EQClasses.end(); }
59};
60
61class BuiltinBug : public BugType {
62  const std::string desc;
63public:
64  BuiltinBug(const char *name, const char *description)
65    : BugType(name, "Logic error"), desc(description) {}
66
67  BuiltinBug(const char *name)
68    : BugType(name, "Logic error"), desc(name) {}
69
70  llvm::StringRef getDescription() const { return desc; }
71};
72
73} // end GR namespace
74
75} // end clang namespace
76#endif
77