CheckerRegistration.cpp revision 08b86531ade68727c56918f162816075b87c864a
143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===--- CheckerRegistration.cpp - Registration for the Analyzer Checkers -===//
243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//                     The LLVM Compiler Infrastructure
443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source
643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// License. See LICENSE.TXT for details.
743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===----------------------------------------------------------------------===//
943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
1043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis// Defines the registration function for the analyzer checkers.
1143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//
1243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis//===----------------------------------------------------------------------===//
1343dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
1427af04bcca46f8a3374586be1301477f9123f5e1Argyrios Kyrtzidis#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
15116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
1608b86531ade68727c56918f162816075b87c864aJordy Rose#include "clang/StaticAnalyzer/Checkers/ClangCheckers.h"
1743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/StaticAnalyzer/Core/CheckerManager.h"
1808b86531ade68727c56918f162816075b87c864aJordy Rose#include "clang/StaticAnalyzer/Core/CheckerOptInfo.h"
1908b86531ade68727c56918f162816075b87c864aJordy Rose#include "clang/StaticAnalyzer/Core/CheckerRegistry.h"
2043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Frontend/AnalyzerOptions.h"
2143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Frontend/FrontendDiagnostic.h"
2243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "clang/Basic/Diagnostic.h"
23116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis#include "llvm/Support/raw_ostream.h"
2443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "llvm/ADT/OwningPtr.h"
2543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis#include "llvm/ADT/SmallVector.h"
2643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
2743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidisusing namespace clang;
2843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidisusing namespace ento;
2943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
3008b86531ade68727c56918f162816075b87c864aJordy Rosestatic void registerCheckers(CheckerRegistry &registry,
3108b86531ade68727c56918f162816075b87c864aJordy Rose                             ArrayRef<std::string> plugins) {
3208b86531ade68727c56918f162816075b87c864aJordy Rose  registerBuiltinCheckers(registry);
3308b86531ade68727c56918f162816075b87c864aJordy Rose
3408b86531ade68727c56918f162816075b87c864aJordy Rose  // FIXME: register plugins.
3508b86531ade68727c56918f162816075b87c864aJordy Rose}
3608b86531ade68727c56918f162816075b87c864aJordy Rose
3708b86531ade68727c56918f162816075b87c864aJordy RoseCheckerManager *ento::createCheckerManager(const AnalyzerOptions &opts,
3808b86531ade68727c56918f162816075b87c864aJordy Rose                                           const LangOptions &langOpts,
3908b86531ade68727c56918f162816075b87c864aJordy Rose                                           ArrayRef<std::string> plugins,
4008b86531ade68727c56918f162816075b87c864aJordy Rose                                           Diagnostic &diags) {
412e471a3e476396be1ddca4ab8b9df721bcfc9437Argyrios Kyrtzidis  llvm::OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts));
4243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
435f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  SmallVector<CheckerOptInfo, 8> checkerOpts;
4443dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
4543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
4643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
4743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  }
4843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
4908b86531ade68727c56918f162816075b87c864aJordy Rose  CheckerRegistry allCheckers;
5008b86531ade68727c56918f162816075b87c864aJordy Rose  registerCheckers(allCheckers, plugins);
5108b86531ade68727c56918f162816075b87c864aJordy Rose  allCheckers.initializeManager(*checkerMgr, checkerOpts);
5243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
53deb6447d0029bdb122397fafb5fa2a4e76f2e555Argyrios Kyrtzidis  checkerMgr->finishedCheckerRegistration();
54deb6447d0029bdb122397fafb5fa2a4e76f2e555Argyrios Kyrtzidis
5543dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
5643dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis    if (checkerOpts[i].isUnclaimed())
5743dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis      diags.Report(diag::warn_unkwown_analyzer_checker)
5843dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis          << checkerOpts[i].getName();
5943dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  }
6043dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis
6143dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis  return checkerMgr.take();
6243dee220252ef0b42c5f8a3bb1eca97f84f2565fArgyrios Kyrtzidis}
63116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis
6408b86531ade68727c56918f162816075b87c864aJordy Rosevoid ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins) {
6508b86531ade68727c56918f162816075b87c864aJordy Rose  out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
6608b86531ade68727c56918f162816075b87c864aJordy Rose  out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
67116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis
6808b86531ade68727c56918f162816075b87c864aJordy Rose  CheckerRegistry allCheckers;
6908b86531ade68727c56918f162816075b87c864aJordy Rose  registerCheckers(allCheckers, plugins);
7008b86531ade68727c56918f162816075b87c864aJordy Rose  allCheckers.printHelp(out);
71116f3640daee424dfcdbe55e80be5a67476be4b0Argyrios Kyrtzidis}
72