diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-09-27 18:20:22 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-09-27 18:20:22 +0000 |
commit | aead1539e7481fde73725d8eadeea82087982bf3 (patch) | |
tree | 191915a4021fdda4d8cc8035c86bf0f8abc1d43b /include/clang/Analysis/ExprDeclBitVector.h | |
parent | 271f1a6373c3fe8fa457fe1ca6c0c908416110fd (diff) |
Created new "ExprDeclBitVector" type bundle for dataflow analyses that need boolean
values associated with ScopedDecls and CFGBlock-level Exprs. This is the common
boilerplate needed by UninitializedValues and LiveVariables.
Refactored UninitializedValues to use ExprDeclBitVector.
Shortened the string diagnostic for UninitializedValues.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42408 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Analysis/ExprDeclBitVector.h')
-rw-r--r-- | include/clang/Analysis/ExprDeclBitVector.h | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/include/clang/Analysis/ExprDeclBitVector.h b/include/clang/Analysis/ExprDeclBitVector.h new file mode 100644 index 0000000000..9a79bbe0b2 --- /dev/null +++ b/include/clang/Analysis/ExprDeclBitVector.h @@ -0,0 +1,149 @@ +//=- ExprDeclBitVector.h - Dataflow types for Bitvector Analysis --*- C++ --*-// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Ted Kremenek and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides definition of dataflow types used by analyses such +// as LiveVariables and UninitializedValues. The underlying dataflow values +// are implemented as bitvectors, but the definitions in this file include +// the necessary boilerplate to use with our dataflow framework. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_EXPRDECLBVDVAL_H +#define LLVM_CLANG_EXPRDECLBVDVAL_H + +#include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseMap.h" + +namespace clang { + + class Expr; + class ScopedDecl; + +struct ExprDeclBitVector_Types { + + //===--------------------------------------------------------------------===// + // AnalysisDataTy - Whole-function meta data. + //===--------------------------------------------------------------------===// + + class AnalysisDataTy { + typedef llvm::DenseMap<const ScopedDecl*, unsigned > DMapTy; + typedef llvm::DenseMap<const Expr*, unsigned > EMapTy; + + EMapTy EMap; + DMapTy DMap; + unsigned NDecls; + unsigned NExprs; + + public: + + AnalysisDataTy() : NDecls(0), NExprs(0) {} + virtual ~AnalysisDataTy() {} + + bool isTracked(const ScopedDecl* SD) { return DMap.find(SD) != DMap.end(); } + bool isTracked(const Expr* E) { return EMap.find(E) != EMap.end(); } + + unsigned operator[](const ScopedDecl* SD) const { + DMapTy::const_iterator I = DMap.find(SD); + assert (I != DMap.end()); + return I->second; + } + + unsigned operator[](const Expr* E) const { + EMapTy::const_iterator I = EMap.find(E); + assert (I != EMap.end()); + return I->second; + } + + unsigned getNumDecls() const { return NDecls; } + unsigned getNumExprs() const { return NExprs; } + + void Register(const ScopedDecl* SD) { + if (!isTracked(SD)) DMap[SD] = NDecls++; + } + + void Register(const Expr* E) { + if (!isTracked(E)) EMap[E] = NExprs++; + } + }; + + //===--------------------------------------------------------------------===// + // ValTy - Dataflow value. + //===--------------------------------------------------------------------===// + + class ValTy { + llvm::BitVector DeclBV; + llvm::BitVector ExprBV; + public: + + void resetValues(AnalysisDataTy& AD) { + DeclBV.resize(AD.getNumDecls()); + DeclBV.reset(); + ExprBV.resize(AD.getNumExprs()); + ExprBV.reset(); + } + + bool operator==(const ValTy& RHS) const { + assert (sizesEqual(RHS)); + return DeclBV == RHS.DeclBV && ExprBV == RHS.ExprBV; + } + + void copyValues(const ValTy& RHS) { + DeclBV = RHS.DeclBV; + ExprBV = RHS.ExprBV; + } + + llvm::BitVector::reference + operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) { + return DeclBV[AD[SD]]; + } + const llvm::BitVector::reference + operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) const { + return const_cast<ValTy&>(*this)(SD,AD); + } + + llvm::BitVector::reference + operator()(const Expr* E, const AnalysisDataTy& AD) { + return ExprBV[AD[E]]; + } + const llvm::BitVector::reference + operator()(const Expr* E, const AnalysisDataTy& AD) const { + return const_cast<ValTy&>(*this)(E,AD); + } + + ValTy& operator|=(const ValTy& RHS) { + assert (sizesEqual(RHS)); + DeclBV |= RHS.DeclBV; + ExprBV |= RHS.ExprBV; + return *this; + } + + ValTy& operator&=(const ValTy& RHS) { + assert (sizesEqual(RHS)); + DeclBV &= RHS.DeclBV; + ExprBV &= RHS.ExprBV; + return *this; + } + + bool sizesEqual(const ValTy& RHS) const { + return DeclBV.size() == RHS.DeclBV.size() + && ExprBV.size() == RHS.ExprBV.size(); + } + }; + + //===--------------------------------------------------------------------===// + // Some useful merge operations. + //===--------------------------------------------------------------------===// + + struct Union { void operator()(ValTy& Dst, ValTy& Src) { Dst |= Src; } }; + struct Intersect { void operator()(ValTy& Dst, ValTy& Src) { Dst &= Src; } }; + +}; +} // end namespace clang + +#endif |