]> granicus.if.org Git - icinga2/commitdiff
mkclass: Fix compiler warnings in auto-generated code
authorGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 13 Dec 2017 11:49:04 +0000 (12:49 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 14 Dec 2017 07:50:09 +0000 (08:50 +0100)
tools/mkclass/classcompiler.cpp

index 7d068bcd5d2dedff1236c5b60f1033e2b011a6f3..6da89cd562068ff43a091fc6c3e937481f9b58ea 100644 (file)
@@ -355,7 +355,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount();" << std::endl
                       << "\t" << "if (real_id < 0) { return " << klass.Parent << "::TypeInstance->GetFieldInfo(id); }" << std::endl;
 
-       if (klass.Fields.size() > 0) {
+       if (!klass.Fields.empty()) {
                m_Impl << "\t" << "switch (";
 
                if (!klass.Parent.empty())
@@ -387,7 +387,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
 
        m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
 
-       if (klass.Fields.size() > 0)
+       if (!klass.Fields.empty())
                m_Impl << "\t" << "}" << std::endl;
 
        m_Impl << "}" << std::endl << std::endl;
@@ -437,29 +437,34 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                m_Impl << "\t" << "int real_id = fieldId - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl
                       << "\t" << "if (real_id < 0) { " << klass.Parent << "::TypeInstance->RegisterAttributeHandler(fieldId, callback); return; }" << std::endl;
 
-       m_Impl << "\t" << "switch (";
+       if (!klass.Fields.empty()) {
+               m_Impl << "\t" << "switch (";
 
-       if (!klass.Parent.empty())
-               m_Impl << "real_id";
-       else
-               m_Impl << "fieldId";
+               if (!klass.Parent.empty())
+                       m_Impl << "real_id";
+               else
+                       m_Impl << "fieldId";
 
-       m_Impl << ") {" << std::endl;
+               m_Impl << ") {" << std::endl;
 
-       int num = 0;
-       for (const Field& field : klass.Fields) {
-               m_Impl << "\t\t" << "case " << num << ":" << std::endl
-                      << "\t\t\t" << "ObjectImpl<" << klass.Name << ">::On" << field.GetFriendlyName() << "Changed.connect(callback);" << std::endl
-                      << "\t\t\t" << "break;" << std::endl;
-               num++;
+               int num = 0;
+               for (const Field& field : klass.Fields) {
+                       m_Impl << "\t\t" << "case " << num << ":" << std::endl
+                              << "\t\t\t" << "ObjectImpl<" << klass.Name << ">::On" << field.GetFriendlyName() << "Changed.connect(callback);" << std::endl
+                              << "\t\t\t" << "break;" << std::endl;
+                       num++;
+               }
+
+               m_Impl << "\t\t" << "default:" << std::endl
+                      << "\t\t";
        }
+       m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
 
-       m_Impl << "\t\t" << "default:" << std::endl
-              << "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
-              << "\t" << "}" << std::endl;
+       if (!klass.Fields.empty())
+               m_Impl << "\t" << "}" << std::endl;
 
        m_Impl << "}" << std::endl << std::endl;
-               
+
        m_Header << "};" << std::endl << std::endl;
 
        m_Header << std::endl;
@@ -749,28 +754,43 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                        m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl
                               << "\t" << "if (real_id < 0) { return " << klass.Parent << "::NavigateField(id); }" << std::endl;
 
-               m_Impl << "\t" << "switch (";
+               bool haveNavigationFields = false;
 
-               if (!klass.Parent.empty())
-                       m_Impl << "real_id";
-               else
-                       m_Impl << "id";
-
-               m_Impl << ") {" << std::endl;
-
-               num = 0;
                for (const Field& field : klass.Fields) {
                        if (field.Attributes & FANavigation) {
-                               m_Impl << "\t\t" << "case " << num << ":" << std::endl
-                                      << "\t\t\t" << "return Navigate" << field.GetFriendlyName() << "();" << std::endl;
+                               haveNavigationFields = true;
+                               break;
                        }
+               }
 
-                       num++;
+               if (haveNavigationFields) {
+                       m_Impl << "\t" << "switch (";
+
+                       if (!klass.Parent.empty())
+                               m_Impl << "real_id";
+                       else
+                               m_Impl << "id";
+
+                       m_Impl << ") {" << std::endl;
+
+                       num = 0;
+                       for (const Field& field : klass.Fields) {
+                               if (field.Attributes & FANavigation) {
+                                       m_Impl << "\t\t" << "case " << num << ":" << std::endl
+                                              << "\t\t\t" << "return Navigate" << field.GetFriendlyName() << "();" << std::endl;
+                               }
+
+                               num++;
+                       }
+
+                       m_Impl << "\t\t" << "default:" << std::endl
+                              << "\t\t";
                }
 
-               m_Impl << "\t\t" << "default:" << std::endl
-                      << "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
-                      << "\t" << "}" << std::endl;
+               m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
+
+               if (haveNavigationFields)
+                       m_Impl << "\t" << "}" << std::endl;
 
                m_Impl << "}" << std::endl << std::endl;