AnalysisManager.cpp revision ef3643fbbbf66247c5e205497fae0f46e240c143
1//===-- AnalysisManager.cpp -------------------------------------*- 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#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
11#include "clang/Index/Entity.h"
12#include "clang/Index/Indexer.h"
13
14using namespace clang;
15using namespace ento;
16
17AnalysisManager::AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
18                                 const LangOptions &lang,
19                                 PathDiagnosticConsumer *pd,
20                                 StoreManagerCreator storemgr,
21                                 ConstraintManagerCreator constraintmgr,
22                                 CheckerManager *checkerMgr,
23                                 idx::Indexer *idxer,
24                                 unsigned maxnodes, unsigned maxvisit,
25                                 bool vizdot, bool vizubi, bool purge,
26                                 bool eager, bool trim,
27                                 bool inlinecall, bool useUnoptimizedCFG,
28                                 bool addImplicitDtors, bool addInitializers,
29                                 bool eagerlyTrimEGraph)
30  : AnaCtxMgr(useUnoptimizedCFG, addImplicitDtors, addInitializers),
31    Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
32    CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
33    CheckerMgr(checkerMgr), Idxer(idxer),
34    AScope(ScopeDecl), MaxNodes(maxnodes), MaxVisit(maxvisit),
35    VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
36    EagerlyAssume(eager), TrimGraph(trim), InlineCall(inlinecall),
37    EagerlyTrimEGraph(eagerlyTrimEGraph)
38{
39  AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
40}
41
42AnalysisContext *
43AnalysisManager::getAnalysisContextInAnotherTU(const Decl *D) {
44  idx::Entity Ent = idx::Entity::get(const_cast<Decl *>(D),
45                                     Idxer->getProgram());
46  FunctionDecl *FuncDef;
47  idx::TranslationUnit *TU;
48  llvm::tie(FuncDef, TU) = Idxer->getDefinitionFor(Ent);
49
50  if (FuncDef == 0)
51    return 0;
52
53  // This AnalysisContext wraps function definition in another translation unit.
54  // But it is still owned by the AnalysisManager associated with the current
55  // translation unit.
56  return AnaCtxMgr.getContext(FuncDef, TU);
57}
58