11#pragma once
22
3- #include < llvm/Support/raw_ostream.h>
4- #include < llvm/ADT/SmallString.h>
5- #include < llvm/ADT/ArrayRef.h>
63#include < clang/AST/APValue.h>
7- #include < clang/AST/Type.h>
84#include < clang/AST/ASTContext.h>
5+ #include < clang/AST/Type.h>
6+ #include < llvm/ADT/ArrayRef.h>
7+ #include < llvm/ADT/SmallString.h>
8+ #include < llvm/Support/raw_ostream.h>
99
1010namespace CppSharp { namespace CppParser {
1111 struct APValuePrinter
1212 {
13- clang::ASTContext & ctx;
14- clang::raw_ostream & out;
13+ clang::ASTContext& ctx;
14+ clang::raw_ostream& out;
1515
16- bool Print (clang::APValue & value, clang::QualType type)
16+ bool Print (clang::APValue& value, clang::QualType type)
1717 {
1818 using namespace clang ;
1919
2020 switch (value.getKind ())
2121 {
22- case APValue::Int:
23- if (type->isBooleanType ())
24- out << (value.getInt ().getBoolValue () ? " true" : " false" );
25- else
26- out << value.getInt ();
27- return true ;
28- case APValue::Float:
29- {
30- SmallString<50 > str;
31- value.getFloat ().toString (str);
32- out << str.str ().str ();
33- return true ;
34- }
35- case APValue::Vector:
36- {
37- out << ' {' ;
38- const auto elementType = type->castAs <clang::VectorType>()->getElementType ();
39- if (!Print (value.getVectorElt (0 ), elementType))
40- return false ;
41- for (unsigned i = 1 ; i != value.getVectorLength (); ++i)
22+ case APValue::Int:
23+ if (type->isBooleanType ())
24+ out << (value.getInt ().getBoolValue () ? " true" : " false" );
25+ else
26+ out << value.getInt ();
27+ return true ;
28+ case APValue::Float:
4229 {
43- out << " , " ;
44- Print (value.getVectorElt (i), elementType);
30+ SmallString<50 > str;
31+ value.getFloat ().toString (str);
32+ out << str.str ().str ();
33+ return true ;
4534 }
46- out << ' }' ;
47- return true ;
48- }
49- case APValue::Array:
50- {
51- const auto *arrayType = ctx.getAsArrayType (type);
52- const auto elementType = arrayType->getElementType ();
53- out << ' {' ;
54- if (unsigned n = value.getArrayInitializedElts ())
35+ case APValue::Vector:
5536 {
56- if (!Print (value.getArrayInitializedElt (0 ), elementType))
37+ out << ' {' ;
38+ const auto elementType = type->castAs <clang::VectorType>()->getElementType ();
39+ if (!Print (value.getVectorElt (0 ), elementType))
5740 return false ;
58- for (unsigned i = 1 ; i != n ; ++i)
41+ for (unsigned i = 1 ; i != value. getVectorLength () ; ++i)
5942 {
6043 out << " , " ;
61- Print (value.getArrayInitializedElt (i), elementType);
44+ Print (value.getVectorElt (i), elementType);
6245 }
46+ out << ' }' ;
47+ return true ;
6348 }
64- out << ' }' ;
65- return true ;
66- }
67- case APValue::LValue:
68- {
69- auto base = value.getLValueBase ();
70-
71- if (const ValueDecl *VD = base.dyn_cast <const ValueDecl *>())
49+ case APValue::Array:
7250 {
73- out << *VD;
51+ const auto * arrayType = ctx.getAsArrayType (type);
52+ const auto elementType = arrayType->getElementType ();
53+ out << ' {' ;
54+ if (unsigned n = value.getArrayInitializedElts ())
55+ {
56+ if (!Print (value.getArrayInitializedElt (0 ), elementType))
57+ return false ;
58+ for (unsigned i = 1 ; i != n; ++i)
59+ {
60+ out << " , " ;
61+ Print (value.getArrayInitializedElt (i), elementType);
62+ }
63+ }
64+ out << ' }' ;
7465 return true ;
7566 }
76- else if (TypeInfoLValue TI = base.dyn_cast <TypeInfoLValue>())
77- return false ;
78- else if (DynamicAllocLValue DA = base.dyn_cast <DynamicAllocLValue>())
79- return false ;
80- else
67+ case APValue::LValue:
8168 {
82- base.get <const clang::Expr *>()->printPretty (out, nullptr , ctx.getPrintingPolicy ());
83- return true ;
69+ auto base = value.getLValueBase ();
70+
71+ if (const ValueDecl* VD = base.dyn_cast <const ValueDecl*>())
72+ {
73+ out << *VD;
74+ return true ;
75+ }
76+ else if (TypeInfoLValue TI = base.dyn_cast <TypeInfoLValue>())
77+ return false ;
78+ else if (DynamicAllocLValue DA = base.dyn_cast <DynamicAllocLValue>())
79+ return false ;
80+ else
81+ {
82+ base.get <const clang::Expr*>()->printPretty (out, nullptr , ctx.getPrintingPolicy ());
83+ return true ;
84+ }
8485 }
8586 }
86- }
8787
8888 return false ;
8989 }
9090 };
91- } }
91+ }} // namespace CppSharp::CppParser
0 commit comments