From 36981b17ed939300f6f8fc2355a255f711fcef71 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Thu, 20 Oct 2011 21:14:49 +0000 Subject: Vendor import of clang release_30 branch r142614: http://llvm.org/svn/llvm-project/cfe/branches/release_30@142614 --- lib/AST/APValue.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'lib/AST/APValue.cpp') 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: "; + 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; -- cgit v1.2.3