2008-02-16 09:12:31 +08:00
|
|
|
//== SymbolManager.h - Management of Symbolic Values ------------*- C++ -*--==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-03-06 18:40:09 +08:00
|
|
|
// This file defines SymbolManager, a class that manages symbolic values
|
2008-02-16 09:12:31 +08:00
|
|
|
// created for use by GRExprEngine and related classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Analysis/PathSensitive/SymbolManager.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2008-12-05 10:27:51 +08:00
|
|
|
SymbolRef SymbolManager::getSymbol(VarDecl* D) {
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-08-13 11:28:04 +08:00
|
|
|
assert (isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D) ||
|
|
|
|
D->hasGlobalStorage());
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-03-12 09:21:45 +08:00
|
|
|
llvm::FoldingSetNodeID profile;
|
|
|
|
|
|
|
|
ParmVarDecl* PD = dyn_cast<ParmVarDecl>(D);
|
|
|
|
|
|
|
|
if (PD)
|
|
|
|
SymbolDataParmVar::Profile(profile, PD);
|
|
|
|
else
|
|
|
|
SymbolDataGlobalVar::Profile(profile, D);
|
|
|
|
|
|
|
|
void* InsertPos;
|
|
|
|
|
|
|
|
SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
|
|
|
|
|
|
|
|
if (SD)
|
|
|
|
return SD->getSymbol();
|
|
|
|
|
|
|
|
if (PD) {
|
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolDataParmVar>();
|
|
|
|
new (SD) SymbolDataParmVar(SymbolCounter, PD);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolDataGlobalVar>();
|
|
|
|
new (SD) SymbolDataGlobalVar(SymbolCounter, D);
|
2008-02-16 09:12:31 +08:00
|
|
|
}
|
|
|
|
|
2008-03-12 09:21:45 +08:00
|
|
|
DataSet.InsertNode(SD, InsertPos);
|
|
|
|
|
|
|
|
DataMap[SymbolCounter] = SD;
|
|
|
|
return SymbolCounter++;
|
2008-02-26 10:15:56 +08:00
|
|
|
}
|
2008-11-19 19:03:17 +08:00
|
|
|
|
2008-12-05 10:27:51 +08:00
|
|
|
SymbolRef SymbolManager::getElementSymbol(const MemRegion* R,
|
2008-11-19 19:03:17 +08:00
|
|
|
const llvm::APSInt* Idx){
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
SymbolDataElement::Profile(ID, R, Idx);
|
|
|
|
void* InsertPos;
|
|
|
|
SymbolData* SD = DataSet.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
|
|
|
|
if (SD)
|
|
|
|
return SD->getSymbol();
|
|
|
|
|
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolDataElement>();
|
|
|
|
new (SD) SymbolDataElement(SymbolCounter, R, Idx);
|
|
|
|
|
|
|
|
DataSet.InsertNode(SD, InsertPos);
|
|
|
|
DataMap[SymbolCounter] = SD;
|
|
|
|
return SymbolCounter++;
|
|
|
|
}
|
|
|
|
|
2008-12-05 10:27:51 +08:00
|
|
|
SymbolRef SymbolManager::getFieldSymbol(const MemRegion* R, const FieldDecl* D) {
|
2008-11-19 19:03:17 +08:00
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
SymbolDataField::Profile(ID, R, D);
|
|
|
|
void* InsertPos;
|
|
|
|
SymbolData* SD = DataSet.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
|
|
|
|
if (SD)
|
|
|
|
return SD->getSymbol();
|
|
|
|
|
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolDataField>();
|
|
|
|
new (SD) SymbolDataField(SymbolCounter, R, D);
|
|
|
|
|
|
|
|
DataSet.InsertNode(SD, InsertPos);
|
|
|
|
DataMap[SymbolCounter] = SD;
|
|
|
|
return SymbolCounter++;
|
|
|
|
}
|
2008-03-12 09:21:45 +08:00
|
|
|
|
2008-12-05 10:27:51 +08:00
|
|
|
SymbolRef SymbolManager::getConjuredSymbol(Stmt* E, QualType T, unsigned Count) {
|
2008-03-12 09:21:45 +08:00
|
|
|
|
|
|
|
llvm::FoldingSetNodeID profile;
|
2008-10-01 08:21:14 +08:00
|
|
|
SymbolConjured::Profile(profile, E, T, Count);
|
2008-03-12 09:21:45 +08:00
|
|
|
void* InsertPos;
|
|
|
|
|
|
|
|
SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
|
|
|
|
|
|
|
|
if (SD)
|
|
|
|
return SD->getSymbol();
|
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolConjured>();
|
2008-10-01 08:21:14 +08:00
|
|
|
new (SD) SymbolConjured(SymbolCounter, E, T, Count);
|
2008-03-12 09:21:45 +08:00
|
|
|
|
|
|
|
DataSet.InsertNode(SD, InsertPos);
|
|
|
|
DataMap[SymbolCounter] = SD;
|
|
|
|
|
|
|
|
return SymbolCounter++;
|
|
|
|
}
|
|
|
|
|
2008-12-05 10:27:51 +08:00
|
|
|
const SymbolData& SymbolManager::getSymbolData(SymbolRef Sym) const {
|
2008-03-12 09:21:45 +08:00
|
|
|
DataMapTy::const_iterator I = DataMap.find(Sym);
|
|
|
|
assert (I != DataMap.end());
|
|
|
|
return *I->second;
|
|
|
|
}
|
|
|
|
|
2008-02-16 09:12:31 +08:00
|
|
|
|
2008-02-20 04:51:40 +08:00
|
|
|
QualType SymbolData::getType(const SymbolManager& SymMgr) const {
|
2008-02-16 09:12:31 +08:00
|
|
|
switch (getKind()) {
|
|
|
|
default:
|
|
|
|
assert (false && "getType() not implemented for this symbol.");
|
|
|
|
|
|
|
|
case ParmKind:
|
|
|
|
return cast<SymbolDataParmVar>(this)->getDecl()->getType();
|
2008-02-26 10:15:56 +08:00
|
|
|
|
|
|
|
case GlobalKind:
|
|
|
|
return cast<SymbolDataGlobalVar>(this)->getDecl()->getType();
|
2008-12-05 09:31:31 +08:00
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
case ConjuredKind:
|
2008-10-01 08:21:14 +08:00
|
|
|
return cast<SymbolConjured>(this)->getType();
|
2008-02-16 09:12:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolManager::~SymbolManager() {}
|