Dump the value calculated by a constant expression when dumping the AST to JSON.

llvm-svn: 363866
This commit is contained in:
Aaron Ballman 2019-06-19 19:12:22 +00:00
parent 9f42845187
commit 91f7265759
4 changed files with 13 additions and 0 deletions

View File

@ -250,6 +250,7 @@ public:
void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE);
void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
void VisitConstantExpr(const ConstantExpr *CE);
void VisitIntegerLiteral(const IntegerLiteral *IL);
void VisitCharacterLiteral(const CharacterLiteral *CL);

View File

@ -975,6 +975,15 @@ void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) {
}
}
void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) {
if (CE->getResultAPValueKind() != APValue::None) {
std::string Str;
llvm::raw_string_ostream OS(Str);
CE->getAPValueResult().printPretty(OS, Ctx, CE->getType());
JOS.attribute("value", OS.str());
}
}
void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
JOS.attribute("value",
IL->getValue().toString(

View File

@ -528,6 +528,7 @@ void func(int val) {
// CHECK-NEXT: "qualType": "bool"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "value": "true",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",

View File

@ -2951,6 +2951,7 @@ void TestIteration() {
// CHECK-NEXT: "qualType": "bool"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "value": "true",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
@ -3150,6 +3151,7 @@ void TestIteration() {
// CHECK-NEXT: "qualType": "bool"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "value": "true",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",