Skip to content

Commit fb00fa5

Browse files
authored
[clang] Implement dump() for MemberPointer APValues (#136130)
Print the member pointer decl and the path.
1 parent 47f4f39 commit fb00fa5

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

clang/lib/AST/TextNodeDumper.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,21 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
829829

830830
return;
831831
}
832-
case APValue::MemberPointer:
833-
OS << "MemberPointer <todo>";
832+
case APValue::MemberPointer: {
833+
OS << "MemberPointer ";
834+
auto Path = Value.getMemberPointerPath();
835+
for (const CXXRecordDecl *D : Path) {
836+
{
837+
ColorScope Color(OS, ShowColors, DeclNameColor);
838+
OS << D->getDeclName();
839+
}
840+
OS << "::";
841+
}
842+
843+
ColorScope Color(OS, ShowColors, DeclNameColor);
844+
OS << Value.getMemberPointerDecl()->getDeclName();
834845
return;
846+
}
835847
case APValue::AddrLabelDiff:
836848
OS << "AddrLabelDiff <todo>";
837849
return;

clang/test/AST/ast-dump-APValue-lvalue.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ namespace std {
2727
class type_info;
2828
}
2929

30+
struct P {
31+
int x;
32+
};
33+
struct Q {
34+
float m;
35+
};
36+
struct MP : P, Q {
37+
int i;
38+
};
39+
3040
void Test(int (&arr)[10]) {
3141
constexpr int *pi = &i;
3242
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pi 'int *const' constexpr cinit
@@ -53,6 +63,10 @@ void Test(int (&arr)[10]) {
5363
// CHECK-NEXT: | |-value: LValue Base=null, Null=1, Offset=0, HasPath=1, PathLength=0, Path=()
5464

5565
constexpr const std::type_info* pti = &typeid(int);
56-
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
57-
// CHECK-NEXT: |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
66+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pti 'const std::type_info *const' constexpr cinit
67+
// CHECK-NEXT: | |-value: LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
68+
69+
constexpr int(MP::*pmi) = (int MP::*)&P::x;
70+
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} pmi 'int (MP::*const)' constexpr cinit
71+
// CHECK-NEXT: |-value: MemberPointer MP::x
5872
}

clang/test/AST/ast-dump-APValue-todo.cpp

-22
This file was deleted.

0 commit comments

Comments
 (0)