CheckerRegistration.cpp revision 2e471a3e476396be1ddca4ab8b9df721bcfc9437
1//===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
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// Defines the registration function for the analyzer checkers.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
15#include "../Checkers/ClangSACheckerProvider.h"
16#include "clang/StaticAnalyzer/Core/CheckerManager.h"
17#include "clang/StaticAnalyzer/Core/CheckerProvider.h"
18#include "clang/Frontend/AnalyzerOptions.h"
19#include "clang/Frontend/FrontendDiagnostic.h"
20#include "clang/Basic/Diagnostic.h"
21#include "llvm/ADT/OwningPtr.h"
22#include "llvm/ADT/SmallVector.h"
23
24using namespace clang;
25using namespace ento;
26
27CheckerManager *ento::registerCheckers(const AnalyzerOptions &opts,
28                                       const LangOptions &langOpts,
29                                       Diagnostic &diags) {
30  llvm::OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts));
31
32  llvm::SmallVector<CheckerOptInfo, 8> checkerOpts;
33  for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
34    const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
35    checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
36  }
37
38  llvm::OwningPtr<CheckerProvider> provider(createClangSACheckerProvider());
39  provider->registerCheckers(*checkerMgr,
40                             checkerOpts.data(), checkerOpts.size());
41
42  // FIXME: Load CheckerProviders from plugins.
43
44  for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
45    if (checkerOpts[i].isUnclaimed())
46      diags.Report(diag::warn_unkwown_analyzer_checker)
47          << checkerOpts[i].getName();
48  }
49
50  return checkerMgr.take();
51}
52