Add CompoundVal and CompoundValData for representing the value of InitListExpr.

llvm-svn: 58418
This commit is contained in:
Zhongxing Xu 2008-10-30 04:58:00 +00:00
parent 51ac923ca3
commit ef5f25a05f
4 changed files with 92 additions and 4 deletions

View File

@ -29,6 +29,23 @@ namespace clang {
class SVal; class SVal;
class CompoundValData : public llvm::FoldingSetNode {
QualType T;
unsigned NumVals;
SVal* Vals;
public:
CompoundValData(QualType t, const SVal* vals, unsigned n,
llvm::BumpPtrAllocator& A);
static void Profile(llvm::FoldingSetNodeID& ID, QualType T, unsigned N,
const SVal* Vals);
void Profile(llvm::FoldingSetNodeID& ID) {
Profile(ID, T, NumVals, Vals);
}
};
class BasicValueFactory { class BasicValueFactory {
typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<llvm::APSInt> > typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<llvm::APSInt> >
APSIntSetTy; APSIntSetTy;
@ -45,6 +62,8 @@ class BasicValueFactory {
void* PersistentSVals; void* PersistentSVals;
void* PersistentSValPairs; void* PersistentSValPairs;
llvm::FoldingSet<CompoundValData> CompoundValDataSet;
public: public:
BasicValueFactory(ASTContext& ctx, llvm::BumpPtrAllocator& Alloc) BasicValueFactory(ASTContext& ctx, llvm::BumpPtrAllocator& Alloc)
: Ctx(ctx), BPAlloc(Alloc), PersistentSVals(0), PersistentSValPairs(0) {} : Ctx(ctx), BPAlloc(Alloc), PersistentSVals(0), PersistentSValPairs(0) {}
@ -68,6 +87,9 @@ public:
const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op, const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
const llvm::APSInt& V); const llvm::APSInt& V);
const CompoundValData* getCompoundValData(QualType T, const SVal* Vals,
unsigned NumVals);
const llvm::APSInt* EvaluateAPSInt(BinaryOperator::Opcode Op, const llvm::APSInt* EvaluateAPSInt(BinaryOperator::Opcode Op,
const llvm::APSInt& V1, const llvm::APSInt& V1,
const llvm::APSInt& V2); const llvm::APSInt& V2);

View File

@ -45,6 +45,7 @@ protected:
: Data(D), Kind(k) {} : Data(D), Kind(k) {}
public: public:
SVal() : Data(0), Kind(0) {}
~SVal() {}; ~SVal() {};
/// BufferTy - A temporary buffer to hold a set of SVals. /// BufferTy - A temporary buffer to hold a set of SVals.
@ -169,6 +170,9 @@ public:
static NonLoc MakeIntTruthVal(BasicValueFactory& BasicVals, bool b); static NonLoc MakeIntTruthVal(BasicValueFactory& BasicVals, bool b);
static NonLoc MakeCompoundVal(QualType T, SVal* Vals, unsigned NumSVals,
BasicValueFactory& BasicVals);
// Implement isa<T> support. // Implement isa<T> support.
static inline bool classof(const SVal* V) { static inline bool classof(const SVal* V) {
return V->getBaseKind() == NonLocKind; return V->getBaseKind() == NonLocKind;
@ -210,7 +214,7 @@ public:
namespace nonloc { namespace nonloc {
enum Kind { ConcreteIntKind, SymbolValKind, SymIntConstraintValKind, enum Kind { ConcreteIntKind, SymbolValKind, SymIntConstraintValKind,
LocAsIntegerKind }; LocAsIntegerKind, CompoundValKind };
class SymbolVal : public NonLoc { class SymbolVal : public NonLoc {
public: public:
@ -314,6 +318,25 @@ public:
} }
}; };
class CompoundVal : public NonLoc {
friend class NonLoc;
CompoundVal(const CompoundValData* D) : NonLoc(CompoundValKind, D) {}
public:
const CompoundValData* getValue() {
return static_cast<CompoundValData*>(Data);
}
static bool classof(const SVal* V) {
return V->getBaseKind() == NonLocKind && V->getSubKind() == CompoundValKind;
}
static bool classof(const NonLoc* V) {
return V->getSubKind() == CompoundValKind;
}
};
} // end namespace clang::nonloc } // end namespace clang::nonloc
//==------------------------------------------------------------------------==// //==------------------------------------------------------------------------==//

View File

@ -18,6 +18,26 @@
using namespace clang; using namespace clang;
CompoundValData::CompoundValData(QualType t, const SVal* vals, unsigned n,
llvm::BumpPtrAllocator& A)
: T(t), NumVals(n) {
Vals = (SVal*) A.Allocate<SVal>(n);
new (Vals) SVal[n];
for (unsigned i = 0; i < n; ++i)
Vals[i] = vals[i];
}
void CompoundValData::Profile(llvm::FoldingSetNodeID& ID, QualType T,
unsigned N, const SVal* Vals) {
T.Profile(ID);
ID.AddInteger(N);
for (unsigned i = 0; i < N; ++i)
Vals[i].Profile(ID);
}
typedef std::pair<SVal, uintptr_t> SValData; typedef std::pair<SVal, uintptr_t> SValData;
typedef std::pair<SVal, SVal> SValPair; typedef std::pair<SVal, SVal> SValPair;
@ -106,6 +126,24 @@ BasicValueFactory::getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
return *C; return *C;
} }
const CompoundValData*
BasicValueFactory::getCompoundValData(QualType T, const SVal* Vals,
unsigned NumVals) {
llvm::FoldingSetNodeID ID;
CompoundValData::Profile(ID, T, NumVals, Vals);
void* InsertPos;
CompoundValData* D = CompoundValDataSet.FindNodeOrInsertPos(ID, InsertPos);
if (!D) {
D = (CompoundValData*) BPAlloc.Allocate<CompoundValData>();
new (D) CompoundValData(T, Vals, NumVals, BPAlloc);
CompoundValDataSet.InsertNode(D, InsertPos);
}
return D;
}
const llvm::APSInt* const llvm::APSInt*
BasicValueFactory::EvaluateAPSInt(BinaryOperator::Opcode Op, BasicValueFactory::EvaluateAPSInt(BinaryOperator::Opcode Op,
const llvm::APSInt& V1, const llvm::APSInt& V2) { const llvm::APSInt& V1, const llvm::APSInt& V2) {

View File

@ -245,6 +245,11 @@ NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
return nonloc::ConcreteInt(BasicVals.getTruthValue(b)); return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
} }
NonLoc NonLoc::MakeCompoundVal(QualType T, SVal* Vals, unsigned NumSVals,
BasicValueFactory& BasicVals) {
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals, NumSVals));
}
SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) { SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
QualType T = D->getType(); QualType T = D->getType();