diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-04-20 05:24:46 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-04-20 05:24:46 +0000 |
commit | 369f447eded97e6048ced02c0c2be3842f61fc1c (patch) | |
tree | 54b9a91bb2c1d4438eaea591715cad10e09a1357 /lib/Analysis/SVals.cpp | |
parent | 5c3074f3cd4c33e30c55e851a3ecf21ebec0769e (diff) |
get a CodeTextRegion when visiting FunctionDecl reference.
get FunctionDecl with more general utility method.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69570 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/SVals.cpp')
-rw-r--r-- | lib/Analysis/SVals.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index 240280f68a..875fd36747 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -30,9 +30,25 @@ using llvm::APSInt; // Utility methods. //===----------------------------------------------------------------------===// +const FunctionDecl* SVal::getAsFunctionDecl() const { + if (const loc::FuncVal* FV = dyn_cast<loc::FuncVal>(this)) { + return FV->getDecl(); + } + + if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(this)) { + const MemRegion* R = X->getRegion(); + if (const CodeTextRegion* CTR = dyn_cast<CodeTextRegion>(R)) { + if (CTR->isDeclared()) + return CTR->getDecl(); + } + } + + return 0; +} + /// getAsLocSymbol - If this SVal is a location (subclasses Loc) and -/// wraps a symbol, return that SymbolRef. Otherwise return a SymbolRef -/// where 'isValid()' returns false. +/// wraps a symbol, return that SymbolRef. Otherwise return 0. +// FIXME: should we consider SymbolRef wrapped in CodeTextRegion? SymbolRef SVal::getAsLocSymbol() const { if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) { const MemRegion *R = X->getRegion(); @@ -55,7 +71,8 @@ SymbolRef SVal::getAsLocSymbol() const { } /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef. -/// Otherwise return a SymbolRef where 'isValid()' returns false. +/// Otherwise return 0. +// FIXME: should we consider SymbolRef wrapped in CodeTextRegion? SymbolRef SVal::getAsSymbol() const { if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this)) return X->getSymbol(); |