Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More clang tidy checks #1449

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
35 changes: 23 additions & 12 deletions util/build_scripts/runtime_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -175,24 +181,29 @@ 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:
val = self.default

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"):
Expand All @@ -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:
Expand Down
Loading