diff options
Diffstat (limited to 'src/kconfig_compiler')
| -rw-r--r-- | src/kconfig_compiler/KConfigCodeGeneratorBase.cpp | 26 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigHeaderGenerator.cpp | 27 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.cpp | 26 | ||||
| -rw-r--r-- | src/kconfig_compiler/kconfig_compiler.cpp | 16 | 
4 files changed, 44 insertions, 51 deletions
| diff --git a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp index 6bcd2911..3f308cbb 100644 --- a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp +++ b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp @@ -108,7 +108,7 @@ void KConfigCodeGeneratorBase::start()  void KConfigCodeGeneratorBase::addHeaders(const QStringList &headerList)  { -    for (auto include : qAsConst(headerList)) { +    for (const auto &include : headerList) {          if (include.startsWith(QLatin1Char('"'))) {              m_stream << "#include " << include << '\n';          } else { @@ -122,7 +122,8 @@ void KConfigCodeGeneratorBase::addHeaders(const QStringList &headerList)  void KConfigCodeGeneratorBase::beginNamespaces()  {      if (!m_cfg.nameSpace.isEmpty()) { -        for (const QString &ns : m_cfg.nameSpace.split(QStringLiteral("::"))) { +        const auto nameSpaceList = m_cfg.nameSpace.split(QStringLiteral("::")); +        for (const QString &ns : nameSpaceList) {              m_stream << "namespace " << ns << " {\n";          }          m_stream << '\n'; @@ -171,9 +172,6 @@ QString KConfigCodeGeneratorBase::memberAccessorBody(const CfgEntry *e, bool glo  void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globalEnums)  { -    QString n = e->name; -    QString t = e->type; -      stream() << whitespace() << "return " << m_this << "isImmutable( QStringLiteral( \"";      if (!e->param.isEmpty()) {          stream() << QString(e->paramName).replace(QLatin1String("$(") + e->param + QLatin1Char(')'), QLatin1String("%1")) << "\" ).arg( "; @@ -192,15 +190,13 @@ void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globa          }          stream() << " )";      } else { -        stream() << n << "\" )"; +        stream() << e->name << "\" )";      }      stream() << " );\n";  }  void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression)  { -    const QString n = e->name; -    const QString t = e->type;      const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties;      m_stream << whitespace() << "if ("; @@ -208,7 +204,7 @@ void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString          m_stream << "v != " << varExpression << " && ";      } -    const auto immutablefunction = immutableFunction(n, m_cfg.dpointer ? m_cfg.className : QString()); +    const auto immutablefunction = immutableFunction(e->name, m_cfg.dpointer ? m_cfg.className : QString{});      m_stream << "!" << m_this << immutablefunction << "(";      if (!e->param.isEmpty()) {          m_stream << " i "; @@ -218,15 +214,14 @@ void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString  void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e)  { -    QString n = e->name; -    QString t = e->type;      // HACK: Don't open '{' manually, use startScope / endScope to automatically handle whitespace indentation.      if (!e->min.isEmpty()) { -        if (e->min != QLatin1String("0") || !isUnsigned(t)) { // skip writing "if uint<0" (#187579) +        if (e->min != QLatin1String("0") || !isUnsigned(e->type)) { // skip writing "if uint<0" (#187579)              m_stream << whitespace() << "if (v < " << e->min << ")\n";              m_stream << whitespace() << "{\n"; -            m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n); +            m_stream << whitespace(); +            addDebugMethod(m_stream, m_cfg, e->name);              m_stream << ": value \" << v << \" is less than the minimum value of " << e->min << "\";\n";              m_stream << whitespace() << "  v = " << e->min << ";\n";              m_stream << whitespace() << "}\n"; @@ -237,13 +232,14 @@ void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e)          m_stream << '\n';          m_stream << whitespace() << "if (v > " << e->max << ")\n";          m_stream << whitespace() << "{\n"; -        m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n); +        m_stream << whitespace(); +        addDebugMethod(m_stream, m_cfg, e->name);          m_stream << ": value \" << v << \" is greater than the maximum value of " << e->max << "\";\n";          m_stream << whitespace() << "  v = " << e->max << ";\n";          m_stream << whitespace() << "}\n\n";      } -    const QString varExpression = m_this + varPath(n, m_cfg) + (e->param.isEmpty() ? QString() : QStringLiteral("[i]")); +    const QString varExpression = m_this + varPath(e->name, m_cfg) + (e->param.isEmpty() ? QString{} : QStringLiteral("[i]"));      // TODO: Remove this `hasBody` logic, always use an '{' for the if.      const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties; diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp index 43a80a60..7829ab67 100644 --- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -56,13 +56,8 @@ void KConfigHeaderGenerator::doClassDefinition()      createConstructor();      createDestructor(); -    for (auto *entry : parseResult.entries) { -        const QString n = entry->name; -        const QString t = entry->type; - -        const QString returnType = (cfg().useEnumTypes && t == QLatin1String("Enum")) -            ? enumType(entry, cfg().globalEnums) -            : cppType(t); +    for (const auto *entry : qAsConst(parseResult.entries)) { +        const QString returnType = (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) ? enumType(entry, cfg().globalEnums) : cppType(entry->type);          createSetters(entry);          createProperties(entry, returnType); @@ -90,7 +85,7 @@ void KConfigHeaderGenerator::doClassDefinition()      }      // Class Parameters -    for (const auto ¶meter : parseResult.parameters) { +    for (const auto ¶meter : qAsConst(parseResult.parameters)) {          stream() << whitespace() << "" << cppType(parameter.type) << " mParam" << parameter.name << ";\n";      } @@ -135,7 +130,7 @@ void KConfigHeaderGenerator::startHeaderGuards()  {      const bool hasNamespace = !cfg().nameSpace.isEmpty();      const QString namespaceName = QString(QString(cfg().nameSpace).replace(QLatin1String("::"), QLatin1String("_"))).toUpper(); -    const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QStringLiteral(""); +    const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QString{};      const QString defineName = namespaceStr + cfg().className.toUpper() + QStringLiteral("_H");      stream() << "#ifndef " << defineName << '\n'; @@ -210,7 +205,7 @@ void KConfigHeaderGenerator::implementEnums()          return;      } -    for (const auto entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          const CfgEntry::Choices &choices = entry->choices;          const QStringList values = entry->paramValues; @@ -259,7 +254,7 @@ void KConfigHeaderGenerator::createSignals()               << "\n\n";      stream() << "  Q_SIGNALS:"; -    for (const Signal &signal : parseResult.signalList) { +    for (const Signal &signal : qAsConst(parseResult.signalList)) {          stream() << '\n';          if (!signal.label.isEmpty()) {              stream() << whitespace() << "/**\n"; @@ -272,7 +267,7 @@ void KConfigHeaderGenerator::createSignals()              Param argument = *it;              QString type = param(argument.type);              if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { -                for (auto *entry : parseResult.entries) { +                for (const auto *entry : qAsConst(parseResult.entries)) {                      if (entry->name == argument.name) {                          type = enumType(entry, cfg().globalEnums);                          break; @@ -301,7 +296,7 @@ void KConfigHeaderGenerator::createDPointer()      // use a private class for both member variables and items      stream() << "  private:\n"; -    for (const auto &entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          if (cfg().allDefaultGetters || cfg().defaultGetters.contains(entry->name)) {              stream() << whitespace() << "";              if (cfg().staticAccessors) { @@ -337,7 +332,7 @@ void KConfigHeaderGenerator::createConstructor()      }      bool first = true; -    for (const auto parameter : parseResult.parameters) { +    for (const auto ¶meter : qAsConst(parseResult.parameters)) {          if (first) {              first = false;          } else { @@ -601,7 +596,7 @@ void KConfigHeaderGenerator::createNonDPointerHelpers()      }      QString group; -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          if (entry->group != group) {              group = entry->group;              stream() << '\n'; @@ -628,7 +623,7 @@ void KConfigHeaderGenerator::createNonDPointerHelpers()      stream() << "\n  private:\n";      if (cfg().itemAccessors) { -        for (auto *entry : parseResult.entries) { +        for (const auto *entry : qAsConst(parseResult.entries)) {              stream() << whitespace() << "Item" << itemType(entry->type) << " *" << itemVar(entry, cfg());              if (!entry->param.isEmpty()) {                  stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index 97db81ba..663a138f 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -15,12 +15,8 @@  #include <QRegularExpression> -KConfigSourceGenerator::KConfigSourceGenerator( -    const QString &inputFile, -    const QString &baseDir, -    const KConfigParameters &cfg, -    ParseResult &result) -    : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, result) +KConfigSourceGenerator::KConfigSourceGenerator(const QString &inputFile, const QString &baseDir, const KConfigParameters &cfg, ParseResult &parseResult) +    : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, parseResult)  {  } @@ -96,7 +92,7 @@ void KConfigSourceGenerator::createPrivateDPointerImplementation()      stream() << "  public:\n";      // Create Members -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          if (entry->group != group) {              group = entry->group;              stream() << '\n'; @@ -111,7 +107,7 @@ void KConfigSourceGenerator::createPrivateDPointerImplementation()      stream() << "\n    // items\n";      // Create Items. -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          const QString declType = entry->signalList.isEmpty()                  ? QString(cfg().inherits + QStringLiteral("::Item") + itemType(entry->type))                  : QStringLiteral("KConfigCompilerSignallingItem"); @@ -192,7 +188,7 @@ void KConfigSourceGenerator::createSingletonImplementation()  void KConfigSourceGenerator::createPreamble()  {      QString cppPreamble; -    for (const auto entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          if (entry->paramValues.isEmpty()) {              continue;          } @@ -257,7 +253,7 @@ void KConfigSourceGenerator::createParentConstructorCall()  void KConfigSourceGenerator::createInitializerList()  { -    for (const auto ¶meter : parseResult.parameters) { +    for (const auto ¶meter : qAsConst(parseResult.parameters)) {          stream() << "  , mParam" << parameter.name << "(" << parameter.name << ")\n";      } @@ -480,7 +476,7 @@ void KConfigSourceGenerator::doConstructor()          stream() << '\n';      } -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          handleCurrentGroupChange(entry);          const QString key = paramString(entry->key, parseResult.parameters); @@ -591,7 +587,7 @@ void KConfigSourceGenerator::doGetterSetterDPointerMode()      }      // setters and getters go in Cpp if in dpointer mode -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          createSetterDPointerMode(entry);          createGetterDPointerMode(entry);          createImmutableGetterDPointerMode(entry); @@ -603,7 +599,7 @@ void KConfigSourceGenerator::doGetterSetterDPointerMode()  void KConfigSourceGenerator::createDefaultValueGetterSetter()  {      // default value getters always go in Cpp -    for (auto *entry : parseResult.entries) { +    for (const auto *entry : qAsConst(parseResult.entries)) {          QString n = entry->name;          QString t = entry->type; @@ -645,7 +641,7 @@ void KConfigSourceGenerator::createNonModifyingSignalsHelper()      startScope();      stream() << "  const bool res = " << cfg().inherits << "::usrSave();\n";      stream() << "  if (!res) return false;\n\n"; -    for (const Signal &signal : parseResult.signalList) { +    for (const Signal &signal : qAsConst(parseResult.signalList)) {          if (signal.modify) {              continue;          } @@ -696,7 +692,7 @@ void KConfigSourceGenerator::createSignalFlagsHandler()      if (!parseResult.signalList.isEmpty())          stream() << '\n'; -    for (const Signal &signal : parseResult.signalList) { +    for (const Signal &signal : qAsConst(parseResult.signalList)) {          if (signal.modify) {              stream() << "  if ( flags & " << signalEnumName(signal.name) << " ) {\n";              stream() << "    Q_EMIT " << signal.name << "();\n"; diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 4f9fa3f2..a7ecd83e 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -371,20 +371,26 @@ QString defaultValue(const QString &t)  QString itemType(const QString &type)  { -    QString t; +    if (type.isEmpty()) { +        return QString{}; +    } -    t = type; -    t.replace(0, 1, t.left(1).toUpper()); +    QString str = type; +    str[0] = str.at(0).toUpper(); -    return t; +    return str;  }  QString itemDeclaration(const CfgEntry *e, const KConfigParameters &cfg)  { +    if (e->name.isEmpty()) { +        return QString{}; +    } +      const QString type = cfg.inherits + "::Item" + itemType(e->type);      QString fCap = e->name; -    fCap[0] = fCap[0].toUpper(); +    fCap[0] = fCap.at(0).toUpper();      const QString argSuffix = (!e->param.isEmpty()) ? (QStringLiteral("[%1]").arg(e->paramMax + 1)) : QString();      QString result; | 
