Skip to content

Commit e587300

Browse files
authored
some more cleaning of the runtime_parameters.py (#1448)
this silences some clang-tidy warnings about string initialization
1 parent 8fc4cfe commit e587300

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

util/build_scripts/runtime_parameters.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ def get_struct_entry(self, indent=4):
9999

100100
ostr = ""
101101

102+
val = self.default_format(debug=self.debug_default)
103+
104+
# we can use an empty initialization list {} for empty strings
105+
if self.dtype == "string" and val.strip() == '""':
106+
val = ""
107+
102108
if not self.debug_default is None:
103109
ostr += "#ifdef AMREX_DEBUG\n"
104-
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++', debug=True)}}};\n"
110+
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n"
105111
ostr += "#else\n"
106-
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++')}}};\n"
112+
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n"
107113
ostr += "#endif\n"
108114
else:
109-
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++')}}};\n"
115+
ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{val}}};\n"
110116

111117
return ostr
112118

@@ -118,12 +124,12 @@ def get_default_string(self):
118124

119125
if not self.debug_default is None:
120126
ostr += "#ifdef AMREX_DEBUG\n"
121-
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++', debug=True)};\n"
127+
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(debug=True)};\n"
122128
ostr += "#else\n"
123-
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++')};\n"
129+
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format()};\n"
124130
ostr += "#endif\n"
125131
else:
126-
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format(lang='C++')};\n"
132+
ostr += f"{self.nm_pre}{self.cpp_var_name} = {self.default_format()};\n"
127133

128134
return ostr
129135

@@ -137,7 +143,7 @@ def get_query_string(self):
137143
# we need to create an amrex::Vector to read and then
138144
# copy into our managed array
139145
ostr += "\n"
140-
ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n"
146+
ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format()});\n"
141147
ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n"
142148
ostr += f" for (int n = 0; n < {self.size}; n++) {{\n"
143149
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):
164170
# we need to create an amrex::Vector to read and then
165171
# copy into our managed array
166172
ostr += "\n"
167-
ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n"
173+
ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format()});\n"
168174
ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n"
169175
ostr += f" for (int n = 0; n < {self.size}; n++) {{\n"
170176
ostr += f" {cname}{struct_name}.{self.namespace}{self.namespace_suffix}.{self.cpp_var_name}[n] = {self.name}_tmp[n];\n"
@@ -175,24 +181,29 @@ def get_query_struct_string(self, struct_name="params", class_name=None):
175181

176182
return ostr
177183

178-
def default_format(self, lang="C++", debug=False):
184+
def default_format(self, *, lang="C++", debug=False):
179185
"""return the value of the parameter in a format that it can be
180186
recognized in C++ code--in particular, preserve the quotes for
181187
strings
182188
183189
"""
190+
191+
# note: lang is no longer used and will be removed once application
192+
# codes have synced
193+
184194
if debug:
185195
val = self.debug_default
186196
else:
187197
val = self.default
188198

189199
if self.dtype == "string":
190200
return f'{val}'
191-
if self.dtype in ["bool", "logical"] and lang == "C++":
201+
if self.dtype in ["bool", "logical"]:
202+
# this is deprecated -- we should just use int
192203
if val.lower() in [".true.", "true"]:
193204
return 1
194205
return 0
195-
if self.dtype == "real" and lang == "C++":
206+
if self.dtype == "real":
196207
if "d" in val:
197208
val = val.replace("d", "e")
198209
if not val.endswith("_rt"):
@@ -202,7 +213,7 @@ def default_format(self, lang="C++", debug=False):
202213
def get_job_info_test(self):
203214
"""this is the output in C++ in the job_info writing"""
204215

205-
value = self.default_format(lang="C++")
216+
value = self.default_format()
206217
if self.dtype == "string" and value.strip() == '\"\"':
207218
test = f"{self.nm_pre}{self.cpp_var_name}.empty()"
208219
else:

0 commit comments

Comments
 (0)