diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2011-10-20 21:14:49 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2011-10-20 21:14:49 +0000 |
commit | 36981b17ed939300f6f8fc2355a255f711fcef71 (patch) | |
tree | ee2483e98b09cac943dc93a6969d83ca737ff139 /lib/AST/APValue.cpp | |
parent | 180abc3db9ae3b4fc63cd65b15697e6ffcc8a657 (diff) | |
download | src-36981b17ed939300f6f8fc2355a255f711fcef71.tar.gz src-36981b17ed939300f6f8fc2355a255f711fcef71.zip |
Notes
Diffstat (limited to 'lib/AST/APValue.cpp')
-rw-r--r-- | lib/AST/APValue.cpp | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/lib/AST/APValue.cpp b/lib/AST/APValue.cpp index ebe99b12cdab..6f63a32dd2ed 100644 --- a/lib/AST/APValue.cpp +++ b/lib/AST/APValue.cpp @@ -13,7 +13,10 @@ #include "clang/AST/APValue.h" #include "clang/AST/CharUnits.h" +#include "clang/Basic/Diagnostic.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/ErrorHandling.h" using namespace clang; namespace { @@ -89,9 +92,9 @@ static double GetApproxValue(const llvm::APFloat &F) { return V.convertToDouble(); } -void APValue::print(llvm::raw_ostream &OS) const { +void APValue::print(raw_ostream &OS) const { switch (getKind()) { - default: assert(0 && "Unknown APValue kind!"); + default: llvm_unreachable("Unknown APValue kind!"); case Uninitialized: OS << "Uninitialized"; return; @@ -118,6 +121,49 @@ void APValue::print(llvm::raw_ostream &OS) const { } } +static void WriteShortAPValueToStream(raw_ostream& Out, + const APValue& V) { + switch (V.getKind()) { + default: llvm_unreachable("Unknown APValue kind!"); + case APValue::Uninitialized: + Out << "Uninitialized"; + break; + case APValue::Int: + Out << V.getInt(); + break; + case APValue::Float: + Out << GetApproxValue(V.getFloat()); + break; + case APValue::Vector: + Out << '['; + WriteShortAPValueToStream(Out, V.getVectorElt(0)); + for (unsigned i = 1; i != V.getVectorLength(); ++i) { + Out << ", "; + WriteShortAPValueToStream(Out, V.getVectorElt(i)); + } + Out << ']'; + break; + case APValue::ComplexInt: + Out << V.getComplexIntReal() << "+" << V.getComplexIntImag() << "i"; + break; + case APValue::ComplexFloat: + Out << GetApproxValue(V.getComplexFloatReal()) << "+" + << GetApproxValue(V.getComplexFloatImag()) << "i"; + break; + case APValue::LValue: + Out << "LValue: <todo>"; + break; + } +} + +const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, + const APValue &V) { + llvm::SmallString<64> Buffer; + llvm::raw_svector_ostream Out(Buffer); + WriteShortAPValueToStream(Out, V); + return DB << Out.str(); +} + const Expr* APValue::getLValueBase() const { assert(isLValue() && "Invalid accessor"); return ((const LV*)(const void*)Data)->Base; |