From 828bd829ceb9642a939a100a46055aa75ce419c1 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 26 Jan 2024 12:29:01 -0500 Subject: [PATCH 1/2] some more cleaning of the runtime_parameters.py this silences some clang-tidy warnings about string initialization --- util/build_scripts/runtime_parameters.py | 35 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/util/build_scripts/runtime_parameters.py b/util/build_scripts/runtime_parameters.py index 6480376765..eb58fbac44 100755 --- a/util/build_scripts/runtime_parameters.py +++ b/util/build_scripts/runtime_parameters.py @@ -99,14 +99,20 @@ def get_struct_entry(self, indent=4): ostr = "" + val = self.default_format(debug=self.debug_default) + + # we can use an empty initialization list {} for empty strings + if self.dtype == "string" and val.strip() == '""': + val = "" + if not self.debug_default is None: ostr += "#ifdef AMREX_DEBUG\n" - ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++', debug=True)}}};\n" + ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n" ostr += "#else\n" - ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++')}}};\n" + ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n" ostr += "#endif\n" else: - ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++')}}};\n" + ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n" return ostr @@ -118,12 +124,12 @@ def get_default_string(self): if not self.debug_default is None: ostr += "#ifdef AMREX_DEBUG\n" - ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++', debug=True)};\n" + ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(debug=True)};\n" ostr += "#else\n" - ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++')};\n" + ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format()};\n" ostr += "#endif\n" else: - ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++')};\n" + ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format()};\n" return ostr @@ -137,7 +143,7 @@ def get_query_string(self): # we need to create an amrex::Vector to read and then # copy into our managed array ostr += "\n" - ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n" + ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format()});\n" ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n" ostr += f" for (int n = 0; n < {self.size}; n++) {{\n" ostr += f" {self.nm_pre}{self.cpp_var_name}[n] = {self.name}_tmp[n];\n" @@ -164,7 +170,7 @@ def get_query_struct_string(self, struct_name="params", class_name=None): # we need to create an amrex::Vector to read and then # copy into our managed array ostr += "\n" - ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n" + ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format()});\n" ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n" ostr += f" for (int n = 0; n < {self.size}; n++) {{\n" ostr += f" {cname}{struct_name}.{self.namespace}{self.namespace_suffix}.{self.cpp_var_name}[n] = {self.name}_tmp[n];\n" @@ -175,12 +181,16 @@ def get_query_struct_string(self, struct_name="params", class_name=None): return ostr - def default_format(self, lang="C++", debug=False): + def default_format(self, *, lang="C++", debug=False): """return the value of the parameter in a format that it can be recognized in C++ code--in particular, preserve the quotes for strings """ + + # note: lang is no longer used and will be removed once application + # codes have synced + if debug: val = self.debug_default else: @@ -188,11 +198,12 @@ def default_format(self, lang="C++", debug=False): if self.dtype == "string": return f'{val}' - if self.dtype in ["bool", "logical"] and lang == "C++": + if self.dtype in ["bool", "logical"]: + # this is deprecated -- we should just use int if val.lower() in [".true.", "true"]: return 1 return 0 - if self.dtype == "real" and lang == "C++": + if self.dtype == "real": if "d" in val: val = val.replace("d", "e") if not val.endswith("_rt"): @@ -202,7 +213,7 @@ def default_format(self, lang="C++", debug=False): def get_job_info_test(self): """this is the output in C++ in the job_info writing""" - value = self.default_format(lang="C++") + value = self.default_format() if self.dtype == "string" and value.strip() == '\"\"': test = f"{self.nm_pre}{self.cpp_var_name}.empty()" else: From 81a7e6e4d6ee6bcbfd45062f4885bc274b89da4a Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 26 Jan 2024 15:34:09 -0500 Subject: [PATCH 2/2] add some more clang-tidy checks --- .clang-tidy | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 16fdbb2c7d..132457337c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,7 +6,6 @@ Checks: > clang-diagnostic-*, cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, - -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-init-variables, @@ -16,11 +15,19 @@ Checks: > -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-*, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-non-private-member-variables-in-classes, + -misc-no-recursion, + -misc-use-anonymous-namespace, modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-use-using, performance-*, + -performance-avoid-endl, + portability-*, readability-*, -readability-avoid-const-params-in-decls, -readability-braces-around-statements,