Skip to content

Commit 56b5873

Browse files
committed
TypeGraph: Rename visit(Type) functions to accept(Type)
visit(Type&) and visit(Type*) were helper functions than did cycle detection and provided nicer syntax for the type.accept(*this) calls. However, because they overloaded the visit() function, it was easy to accidentally call a concrete visit method (e.g. visit(Class&)) instead of the virtual-dispatching visit(Type&). By changing the name of this wrapper, it will make it much more obvious when code is introduced which bypasses the cycle detection.
1 parent 8cb0823 commit 56b5873

17 files changed

+69
-69
lines changed

oi/type_graph/AddChildren.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Pass AddChildren::createPass(DrgnParser& drgnParser, SymbolService& symbols) {
3636
AddChildren pass(typeGraph, drgnParser);
3737
pass.enumerateChildClasses(symbols);
3838
for (auto& type : typeGraph.rootTypes()) {
39-
pass.visit(type);
39+
pass.accept(type);
4040
}
4141
};
4242

4343
return Pass("AddChildren", fn);
4444
}
4545

46-
void AddChildren::visit(Type& type) {
46+
void AddChildren::accept(Type& type) {
4747
if (visited_.count(&type) != 0)
4848
return;
4949

@@ -53,10 +53,10 @@ void AddChildren::visit(Type& type) {
5353

5454
void AddChildren::visit(Class& c) {
5555
for (auto& param : c.templateParams) {
56-
visit(param.type());
56+
accept(param.type());
5757
}
5858
for (auto& member : c.members) {
59-
visit(member.type());
59+
accept(member.type());
6060
}
6161

6262
if (!c.isDynamic()) {
@@ -82,8 +82,8 @@ void AddChildren::visit(Class& c) {
8282
}
8383

8484
// Recurse to find children-of-children
85-
for (auto& child : c.children) {
86-
visit(child);
85+
for (const auto& child : c.children) {
86+
accept(child);
8787
}
8888
}
8989

oi/type_graph/AddChildren.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class AddChildren final : public RecursiveVisitor {
4646
: typeGraph_(typeGraph), drgnParser_(drgnParser) {
4747
}
4848

49-
using RecursiveVisitor::visit;
49+
using RecursiveVisitor::accept;
5050

51-
void visit(Type& type) override;
51+
void accept(Type& type) override;
5252
void visit(Class& c) override;
5353

5454
private:

oi/type_graph/AddPadding.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ Pass AddPadding::createPass(FeatureSet features) {
3232
auto fn = [features](TypeGraph& typeGraph) {
3333
AddPadding pass(typeGraph, features);
3434
for (auto& type : typeGraph.rootTypes()) {
35-
pass.visit(type);
35+
pass.accept(type);
3636
}
3737
};
3838

3939
return Pass("AddPadding", fn);
4040
}
4141

42-
void AddPadding::visit(Type& type) {
42+
void AddPadding::accept(Type& type) {
4343
if (visited_.count(&type) != 0)
4444
return;
4545

@@ -54,10 +54,10 @@ void AddPadding::visit(Class& c) {
5454
assert(c.parents.empty());
5555

5656
for (auto& param : c.templateParams) {
57-
visit(param.type());
57+
accept(param.type());
5858
}
5959
for (auto& member : c.members) {
60-
visit(member.type());
60+
accept(member.type());
6161
}
6262

6363
if (c.kind() == Class::Kind::Union) {
@@ -94,7 +94,7 @@ void AddPadding::visit(Class& c) {
9494
c.members = std::move(paddedMembers);
9595

9696
for (const auto& child : c.children) {
97-
visit(child);
97+
accept(child);
9898
}
9999
}
100100

oi/type_graph/AddPadding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class AddPadding final : public RecursiveVisitor {
4343
: typeGraph_(typeGraph), features_(features) {
4444
}
4545

46-
using RecursiveVisitor::visit;
46+
using RecursiveVisitor::accept;
4747

48-
void visit(Type& type) override;
48+
void accept(Type& type) override;
4949
void visit(Class& c) override;
5050

5151
static const inline std::string MemberPrefix = "__oi_padding";

oi/type_graph/AlignmentCalc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Pass AlignmentCalc::createPass() {
3535

3636
void AlignmentCalc::calculateAlignments(const std::vector<ref<Type>>& types) {
3737
for (auto& type : types) {
38-
visit(type);
38+
accept(type);
3939
}
4040
};
4141

42-
void AlignmentCalc::visit(Type& type) {
42+
void AlignmentCalc::accept(Type& type) {
4343
if (visited_.count(&type) != 0)
4444
return;
4545

@@ -58,7 +58,7 @@ void AlignmentCalc::visit(Class& c) {
5858
if (member.align == 0) {
5959
// If the member does not have an explicit alignment, calculate it from
6060
// the member's type.
61-
visit(member.type());
61+
accept(member.type());
6262
member.align = member.type().align();
6363
}
6464
alignment = std::max(alignment, member.align);

oi/type_graph/AlignmentCalc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class AlignmentCalc final : public RecursiveVisitor {
3737
void calculateAlignments(
3838
const std::vector<std::reference_wrapper<Type>>& types);
3939

40-
using RecursiveVisitor::visit;
40+
using RecursiveVisitor::accept;
4141

42-
void visit(Type& type) override;
42+
void accept(Type& type) override;
4343
void visit(Class& c) override;
4444

4545
private:

oi/type_graph/Flattener.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ Pass Flattener::createPass() {
3333

3434
void Flattener::flatten(std::vector<std::reference_wrapper<Type>>& types) {
3535
for (auto& type : types) {
36-
visit(type);
36+
accept(type);
3737
}
3838
}
3939

40-
void Flattener::visit(Type& type) {
40+
void Flattener::accept(Type& type) {
4141
if (visited_.count(&type) != 0)
4242
return;
4343

@@ -146,13 +146,13 @@ void Flattener::visit(Class& c) {
146146

147147
// Flatten types referenced by template params, parents and members
148148
for (const auto& param : c.templateParams) {
149-
visit(param.type());
149+
accept(param.type());
150150
}
151151
for (const auto& parent : c.parents) {
152-
visit(parent.type());
152+
accept(parent.type());
153153
}
154154
for (const auto& member : c.members) {
155-
visit(member.type());
155+
accept(member.type());
156156
}
157157

158158
// Pull in functions from flattened parents
@@ -203,15 +203,15 @@ void Flattener::visit(Class& c) {
203203
// This must be run after flattening the current class in order to respect
204204
// the changes we have made here.
205205
for (const auto& child : c.children) {
206-
visit(child);
206+
accept(child);
207207
}
208208
}
209209

210210
void Flattener::visit(Container& c) {
211211
// Containers themselves don't need to be flattened, but their template
212212
// parameters might need to be
213213
for (const auto& templateParam : c.templateParams) {
214-
visit(templateParam.type());
214+
accept(templateParam.type());
215215
}
216216
}
217217

oi/type_graph/Flattener.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Flattener : public RecursiveVisitor {
3737

3838
void flatten(std::vector<std::reference_wrapper<Type>>& types);
3939

40-
using RecursiveVisitor::visit;
40+
using RecursiveVisitor::accept;
4141

42-
void visit(Type& type) override;
42+
void accept(Type& type) override;
4343
void visit(Class& c) override;
4444
void visit(Container& c) override;
4545

oi/type_graph/NameGen.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ Pass NameGen::createPass() {
3333

3434
void NameGen::generateNames(const std::vector<ref<Type>>& types) {
3535
for (auto& type : types) {
36-
visit(type);
36+
accept(type);
3737
}
3838
};
3939

40-
void NameGen::visit(Type& type) {
40+
void NameGen::accept(Type& type) {
4141
if (visited_.count(&type) != 0)
4242
return;
4343

@@ -69,16 +69,16 @@ void NameGen::visit(Class& c) {
6969
}
7070

7171
for (const auto& param : c.templateParams) {
72-
visit(param.type());
72+
accept(param.type());
7373
}
7474
for (const auto& parent : c.parents) {
75-
visit(parent.type());
75+
accept(parent.type());
7676
}
7777
for (const auto& member : c.members) {
78-
visit(member.type());
78+
accept(member.type());
7979
}
8080
for (const auto& child : c.children) {
81-
visit(child);
81+
accept(child);
8282
}
8383
}
8484

@@ -88,7 +88,7 @@ void NameGen::visit(Container& c) {
8888
}
8989

9090
for (const auto& template_param : c.templateParams) {
91-
visit(template_param.type());
91+
accept(template_param.type());
9292
}
9393

9494
std::string name = c.name();
@@ -130,7 +130,7 @@ void NameGen::visit(Typedef& td) {
130130
// Append an incrementing number to ensure we don't get duplicates
131131
td.setName(name + "_" + std::to_string(n++));
132132

133-
visit(td.underlyingType());
133+
accept(td.underlyingType());
134134
}
135135

136136
} // namespace type_graph

oi/type_graph/NameGen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class NameGen final : public RecursiveVisitor {
3232

3333
void generateNames(const std::vector<std::reference_wrapper<Type>>& types);
3434

35-
using RecursiveVisitor::visit;
35+
using RecursiveVisitor::accept;
3636

3737
void visit(Class& c) override;
3838
void visit(Container& c) override;
3939
void visit(Typedef& td) override;
4040

4141
private:
42-
void visit(Type& type) override;
42+
void accept(Type& type) override;
4343
void removeTemplateParams(std::string& name);
4444

4545
std::unordered_set<Type*> visited_;

0 commit comments

Comments
 (0)