From 2f1c9388f51aa80d7299f980f9abe598bf91adda Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Mon, 8 Feb 2021 09:12:58 +0100 Subject: [PATCH] Generate static members initializers into the declaration instead of initialisin in the constructors --- code_generation/printer.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/code_generation/printer.cpp b/code_generation/printer.cpp index 765d777..41f25c5 100644 --- a/code_generation/printer.cpp +++ b/code_generation/printer.cpp @@ -267,9 +267,10 @@ QString Printer::Private::classHeader(const Class &classObject, bool publicMembe if (v.isStatic()) decl += "static "; - decl += formatType(v.type()); - - decl += v.name() + ';'; + if (!v.isStatic() && v.initializer().isEmpty()) + decl += v.name() + ';'; + else + decl += v.name() + " = " + v.initializer() + ';'; code += decl; } @@ -361,16 +362,6 @@ QString Printer::Private::classImplementation(const Class &classObject, bool nes && f.name() == classObject.name()) { inits.append(classObject.dPointerName() + "(new PrivateDPtr)"); } - if (!classObject.useDPointer() && f.name() == classObject.name() - && f.arguments().isEmpty()) { - // Default constructor: add initializers for variables - for (itV = vars.constBegin(); itV != vars.constEnd(); ++itV) { - const MemberVariable v = *itV; - if (!v.initializer().isEmpty()) { - inits.append(v.name() + '(' + v.initializer() + ')'); - } - } - } if (!inits.isEmpty()) { code.indent();