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-02-26 10:15:56 +08:00
|
|
|
SymbolID SymbolManager::getSymbol(VarDecl* D) {
|
|
|
|
|
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-02-16 09:12:31 +08:00
|
|
|
SymbolID SymbolManager::getContentsOfSymbol(SymbolID sym) {
|
|
|
|
|
2008-03-12 09:21:45 +08:00
|
|
|
llvm::FoldingSetNodeID profile;
|
|
|
|
SymbolDataContentsOf::Profile(profile, sym);
|
|
|
|
void* InsertPos;
|
|
|
|
|
|
|
|
SymbolData* SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
|
|
|
|
|
|
|
|
if (SD)
|
|
|
|
return SD->getSymbol();
|
|
|
|
|
|
|
|
SD = (SymbolData*) BPAlloc.Allocate<SymbolDataContentsOf>();
|
|
|
|
new (SD) SymbolDataContentsOf(SymbolCounter, sym);
|
|
|
|
|
|
|
|
|
|
|
|
DataSet.InsertNode(SD, InsertPos);
|
|
|
|
DataMap[SymbolCounter] = SD;
|
2008-02-16 09:12:31 +08:00
|
|
|
|
2008-03-12 09:21:45 +08:00
|
|
|
return SymbolCounter++;
|
2008-02-16 09:12:31 +08:00
|
|
|
}
|
2008-03-12 09:21:45 +08:00
|
|
|
|
2008-11-13 03:22:47 +08:00
|
|
|
SymbolID 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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SymbolData& SymbolManager::getSymbolData(SymbolID Sym) const {
|
|
|
|
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-02-16 09:12:31 +08:00
|
|
|
|
2008-02-20 04:51:40 +08:00
|
|
|
case ContentsOfKind: {
|
2008-03-12 09:21:45 +08:00
|
|
|
SymbolID x = cast<SymbolDataContentsOf>(this)->getContainerSymbol();
|
2008-02-20 04:51:40 +08:00
|
|
|
QualType T = SymMgr.getSymbolData(x).getType(SymMgr);
|
|
|
|
return T->getAsPointerType()->getPointeeType();
|
|
|
|
}
|
2008-03-12 09:21:45 +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() {}
|