Skip to content

Commit 6607008

Browse files
committed
CodeGen v2: Finish polymorphic inheritance support
1 parent e7d7c18 commit 6607008

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ workflows:
2020
- build-gcc
2121
oid_test_args: "-ftype-graph"
2222
tests_regex: "OidIntegration\\..*"
23-
exclude_regex: ".*inheritance_polymorphic.*"
2423
- test:
2524
name: test-typed-data-segment-gcc
2625
requires:
@@ -57,7 +56,7 @@ workflows:
5756
oid_test_args: "-ftype-graph"
5857
tests_regex: "OidIntegration\\..*"
5958
# Tests disabled due to bad DWARF generated by the old clang compiler in CI
60-
exclude_regex: ".*inheritance_polymorphic.*|.*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_a"
59+
exclude_regex: ".*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_a"
6160

6261
executors:
6362
ubuntu-docker:

oi/CodeGen.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,15 @@ void addStandardGetSizeFuncDefs(std::string& code) {
366366
}
367367
)";
368368
}
369+
} // namespace
369370

370-
void getClassSizeFuncDecl(const Class& c, std::string& code) {
371+
void CodeGen::getClassSizeFuncDecl(const Class& c, std::string& code) const {
372+
if (config_.features[Feature::PolymorphicInheritance] && c.isDynamic()) {
373+
code += "void getSizeTypeConcrete(const " + c.name() +
374+
" &t, size_t &returnArg);\n";
375+
}
371376
code += "void getSizeType(const " + c.name() + " &t, size_t &returnArg);\n";
372377
}
373-
} // namespace
374378

375379
/*
376380
* Generates a getSizeType function for the given concrete class.
@@ -421,7 +425,7 @@ void CodeGen::getClassSizeFuncConcrete(std::string_view funcName,
421425
code += "}\n";
422426
}
423427

424-
void CodeGen::getClassSizeFuncDef(const Class& c, std::string& code) {
428+
void CodeGen::getClassSizeFuncDef(const Class& c, std::string& code) const {
425429
if (!config_.features[Feature::PolymorphicInheritance] || !c.isDynamic()) {
426430
// Just directly use the concrete size function as this class' getSizeType()
427431
getClassSizeFuncConcrete("getSizeType", c, code);
@@ -438,9 +442,7 @@ void CodeGen::getClassSizeFuncDef(const Class& c, std::string& code) {
438442
if (childClass == nullptr) {
439443
abort(); // TODO
440444
}
441-
// TODO:
442-
// auto fqChildName = *fullyQualifiedName(child);
443-
auto fqChildName = "TODO - implement me";
445+
auto fqChildName = childClass->fqName();
444446

445447
// We must split this assignment and append because the C++ standard lacks
446448
// an operator for concatenating std::string and std::string_view...
@@ -511,8 +513,10 @@ void getContainerSizeFuncDef(std::unordered_set<const ContainerInfo*>& used,
511513
boost::format(c.containerInfo_.codegen.func) % c.containerInfo_.typeName;
512514
code += fmt.str();
513515
}
516+
} // namespace
514517

515-
void addGetSizeFuncDecls(const TypeGraph& typeGraph, std::string& code) {
518+
void CodeGen::addGetSizeFuncDecls(const TypeGraph& typeGraph,
519+
std::string& code) const {
516520
for (const Type& t : typeGraph.finalTypes) {
517521
if (const auto* c = dynamic_cast<const Class*>(&t)) {
518522
getClassSizeFuncDecl(*c, code);
@@ -522,8 +526,6 @@ void addGetSizeFuncDecls(const TypeGraph& typeGraph, std::string& code) {
522526
}
523527
}
524528

525-
} // namespace
526-
527529
void CodeGen::addGetSizeFuncDefs(const TypeGraph& typeGraph,
528530
std::string& code) {
529531
for (const Type& t : typeGraph.finalTypes) {

oi/CodeGen.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ class CodeGen {
6666
thriftIssetMembers_;
6767

6868
void genDefsThrift(const type_graph::TypeGraph& typeGraph, std::string& code);
69+
void addGetSizeFuncDecls(const type_graph::TypeGraph& typeGraph,
70+
std::string& code) const;
71+
void getClassSizeFuncDecl(const type_graph::Class& c,
72+
std::string& code) const;
6973
void addGetSizeFuncDefs(const type_graph::TypeGraph& typeGraph,
7074
std::string& code);
71-
void getClassSizeFuncDef(const type_graph::Class& c, std::string& code);
75+
void getClassSizeFuncDef(const type_graph::Class& c, std::string& code) const;
7276
void getClassSizeFuncConcrete(std::string_view funcName,
7377
const type_graph::Class& c,
7478
std::string& code) const;

0 commit comments

Comments
 (0)