blob: b92eb24d7c98622e8d1686af8700d348d20b1560 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
//== AnalysisContext.cpp - Analysis context for Path Sens analysis -*- C++ -*-//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines AnalysisContext, a class that manages the analysis context
// data for path sensitive analysis.
//
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathSensitive/AnalysisContext.h"
#include "clang/Analysis/Analyses/LiveVariables.h"
#include "clang/Analysis/CFG.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ParentMap.h"
#include "llvm/Support/ErrorHandling.h"
using namespace clang;
AnalysisContext::~AnalysisContext() {
delete cfg;
delete liveness;
delete PM;
}
Stmt *AnalysisContext::getBody() {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
return FD->getBody();
else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
return MD->getBody();
llvm::llvm_unreachable("unknown code decl");
}
CFG *AnalysisContext::getCFG() {
if (!cfg)
cfg = CFG::buildCFG(getBody(), &D->getASTContext());
return cfg;
}
ParentMap &AnalysisContext::getParentMap() {
if (!PM)
PM = new ParentMap(getBody());
return *PM;
}
LiveVariables *AnalysisContext::getLiveVariables() {
if (!liveness) {
CFG *c = getCFG();
if (!c)
return 0;
liveness = new LiveVariables(D->getASTContext(), *c);
liveness->runOnCFG(*c);
liveness->runOnAllBlocks(*c, 0, true);
}
return liveness;
}
AnalysisContext *AnalysisContextManager::getContext(Decl *D) {
iterator I = Contexts.find(D);
if (I != Contexts.end())
return &(I->second);
AnalysisContext &Ctx = Contexts[D];
Ctx.setDecl(D);
return &Ctx;
}
|