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 pycodegen/pystencils-sfg!18
parents e37859ff dd19905b
No related branches found
No related tags found
No related merge requests found
......@@ -154,7 +154,10 @@ class SfgFilePrinter:
return code
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]
code += "\n\n".join(vblocks_str)
code += "\n};\n"
......
......@@ -7,4 +7,7 @@ int main(void){
Point p { 3, 1, -4 };
assert(p.getX() == 3);
SpecialPoint q { 0, 1, 2 };
assert(q.getY() == 1);
}
......@@ -11,18 +11,19 @@ with SourceFileGenerator() as sfg:
sfg.klass("Point")(
sfg.public(
sfg.constructor(x, y, z)
.init(x_)(x)
.init(y_)(y)
.init(z_)(z),
sfg.constructor(x, y, z).init(x_)(x).init(y_)(y).init(z_)(z),
sfg.method("getX", returns="const int64_t", const=True, inline=True)(
"return this->x_;"
)
),
),
sfg.private(
x_,
y_,
z_
sfg.protected(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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment