Skip to content
Snippets Groups Projects
Commit 09d4e4c3 authored by Christoph Alt's avatar Christoph Alt
Browse files

Merge branch 'fhennig/fix-base-classes-printing' into 'master'

quick-fix: print base classes

See merge request !18
parents e37859ff dd19905b
1 merge request!18quick-fix: print base classes
Pipeline #73997 passed with stages
in 2 minutes and 13 seconds
...@@ -154,7 +154,10 @@ class SfgFilePrinter: ...@@ -154,7 +154,10 @@ class SfgFilePrinter:
return code return code
case SfgClassBody(cls, vblocks): case SfgClassBody(cls, vblocks):
code = f"{cls.class_keyword} {cls.name} {{\n" code = f"{cls.class_keyword} {cls.name}"
if cls.base_classes:
code += " : " + ", ".join(cls.base_classes)
code += " {\n"
vblocks_str = [self._visibility_block(b) for b in vblocks] vblocks_str = [self._visibility_block(b) for b in vblocks]
code += "\n\n".join(vblocks_str) code += "\n\n".join(vblocks_str)
code += "\n};\n" code += "\n};\n"
......
...@@ -7,4 +7,7 @@ int main(void){ ...@@ -7,4 +7,7 @@ int main(void){
Point p { 3, 1, -4 }; Point p { 3, 1, -4 };
assert(p.getX() == 3); assert(p.getX() == 3);
SpecialPoint q { 0, 1, 2 };
assert(q.getY() == 1);
} }
...@@ -11,18 +11,19 @@ with SourceFileGenerator() as sfg: ...@@ -11,18 +11,19 @@ with SourceFileGenerator() as sfg:
sfg.klass("Point")( sfg.klass("Point")(
sfg.public( sfg.public(
sfg.constructor(x, y, z) sfg.constructor(x, y, z).init(x_)(x).init(y_)(y).init(z_)(z),
.init(x_)(x)
.init(y_)(y)
.init(z_)(z),
sfg.method("getX", returns="const int64_t", const=True, inline=True)( sfg.method("getX", returns="const int64_t", const=True, inline=True)(
"return this->x_;" "return this->x_;"
) ),
), ),
sfg.private( sfg.protected(x_, y_, z_),
x_, )
y_,
z_ sfg.klass("SpecialPoint", bases=["public Point"])(
sfg.public(
"using Point::Point;",
sfg.method("getY", returns="const int64_t", const=True, inline=True)(
"return this->y_;"
),
) )
) )
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment