diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2011-07-18 16:43:53 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2011-07-18 16:43:53 +0000 |
commit | 5b106a872d66f57522b1cc6d1b67f93704409114 (patch) | |
tree | 68e7b46278adbd776d869ef06595a4a00572d50c /lib/AST/APValue.cpp | |
parent | e9c0265d6e6b5bf865f4a0c2c00d00ac251e6437 (diff) |
Define DiagnosticBuilder<<APValue so it's easy to include APValues in
diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135398 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/APValue.cpp')
-rw-r--r-- | lib/AST/APValue.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/AST/APValue.cpp b/lib/AST/APValue.cpp index ebe99b12cd..86eec3b8bb 100644 --- a/lib/AST/APValue.cpp +++ b/lib/AST/APValue.cpp @@ -13,6 +13,8 @@ #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" using namespace clang; @@ -118,6 +120,49 @@ void APValue::print(llvm::raw_ostream &OS) const { } } +static void WriteShortAPValueToStream(llvm::raw_ostream& Out, + const APValue& V) { + switch (V.getKind()) { + default: assert(0 && "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; |