CheckerRegistration.cpp revision 08b86531ade68727c56918f162816075b87c864a
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 "clang/StaticAnalyzer/Frontend/FrontendActions.h" 16#include "clang/StaticAnalyzer/Checkers/ClangCheckers.h" 17#include "clang/StaticAnalyzer/Core/CheckerManager.h" 18#include "clang/StaticAnalyzer/Core/CheckerOptInfo.h" 19#include "clang/StaticAnalyzer/Core/CheckerRegistry.h" 20#include "clang/Frontend/AnalyzerOptions.h" 21#include "clang/Frontend/FrontendDiagnostic.h" 22#include "clang/Basic/Diagnostic.h" 23#include "llvm/Support/raw_ostream.h" 24#include "llvm/ADT/OwningPtr.h" 25#include "llvm/ADT/SmallVector.h" 26 27using namespace clang; 28using namespace ento; 29 30static void registerCheckers(CheckerRegistry ®istry, 31 ArrayRef<std::string> plugins) { 32 registerBuiltinCheckers(registry); 33 34 // FIXME: register plugins. 35} 36 37CheckerManager *ento::createCheckerManager(const AnalyzerOptions &opts, 38 const LangOptions &langOpts, 39 ArrayRef<std::string> plugins, 40 Diagnostic &diags) { 41 llvm::OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts)); 42 43 SmallVector<CheckerOptInfo, 8> checkerOpts; 44 for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { 45 const std::pair<std::string, bool> &opt = opts.CheckersControlList[i]; 46 checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); 47 } 48 49 CheckerRegistry allCheckers; 50 registerCheckers(allCheckers, plugins); 51 allCheckers.initializeManager(*checkerMgr, checkerOpts); 52 53 checkerMgr->finishedCheckerRegistration(); 54 55 for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) { 56 if (checkerOpts[i].isUnclaimed()) 57 diags.Report(diag::warn_unkwown_analyzer_checker) 58 << checkerOpts[i].getName(); 59 } 60 61 return checkerMgr.take(); 62} 63 64void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins) { 65 out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n"; 66 out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n"; 67 68 CheckerRegistry allCheckers; 69 registerCheckers(allCheckers, plugins); 70 allCheckers.printHelp(out); 71} 72