c_wrapper_generator: Adjusted new-line logic

Signed-off-by: Minos Galanakis <[email protected]>
This commit is contained in:
Minos Galanakis
2024-07-05 09:35:41 +01:00
parent eefadcf929
commit 7d93badf4f
3 changed files with 17 additions and 15 deletions
@@ -80,14 +80,16 @@ class Base:
'',
'#ifdef __cplusplus',
'extern "C" {',
'#endif']
'#endif',
'']
for include in self._INCLUDES:
prologue.append('#include {}'.format(include))
# Make certain there is an empty line
if prologue[-1] != '':
prologue += (['', ''])
# Make certain there is an empty line at the end of this section.
for i in [-1, -2]:
if prologue[i] != '':
prologue.append('')
out.write('\n'.join(prologue))
@@ -96,8 +98,7 @@ class Base:
"""
epilogue = []
if header:
epilogue += ['',
'#ifdef __cplusplus',
epilogue += ['#ifdef __cplusplus',
'}',
'#endif',
'',
@@ -273,10 +274,8 @@ class Base:
wrapper = self._wrapper_info(function)
if wrapper is None:
return
out.write("""
/* Wrapper for {} */
"""
.format(function.name))
out.write('/* Wrapper for {} */\n'.format(function.name))
if wrapper.guard is not None:
out.write('#if {}\n'.format(wrapper.guard))
self._write_function_prototype(out, function, wrapper, False)
@@ -285,6 +284,7 @@ class Base:
out.write('}\n')
if wrapper.guard is not None:
out.write('#endif /* {} */\n'.format(wrapper.guard))
out.write('\n')
def _write_h_function_declaration(self, out: typing_util.Writable,
function: FunctionInfo,
@@ -316,13 +316,13 @@ class Base:
wrapper = self._wrapper_info(function)
if wrapper is None:
return
out.write('\n')
if wrapper.guard is not None:
out.write('#if {}\n'.format(wrapper.guard))
self._write_h_function_declaration(out, function, wrapper)
self._write_h_macro_definition(out, function, wrapper)
if wrapper.guard is not None:
out.write('#endif /* {} */\n'.format(wrapper.guard))
out.write('\n')
def write_c_file(self, filename: str) -> None:
"""Output a whole C file containing function wrapper definitions."""
@@ -31,7 +31,7 @@ class PSATestWrapper(PSAWrapper):
_WRAPPER_NAME_PREFIX = 'mbedtls_test_wrap_'
_WRAPPER_NAME_SUFFIX = ''
_PSA_WRAPPER_INCLUDES = ['<psa/crypto.h>',
_PSA_WRAPPER_INCLUDES = ['<psa/crypto.h>\n',
'<test/memory.h>',
'<test/psa_crypto_helpers.h>',
'<test/psa_test_wrappers.h>']
@@ -198,14 +198,16 @@ class PSAWrapper(c_wrapper_generator.Base):
for include in self._PSA_WRAPPER_INCLUDES:
prologue.append("#include {}".format(include))
if prologue[-1] != '':
prologue.append('')
# Make certain there is an empty line at the end of this section.
for i in [-1, -2]:
if prologue[i] != '':
prologue.append('')
out.write("\n".join(prologue))
def _write_epilogue(self, out: typing_util.Writable, header: bool) -> None:
if self._CPP_GUARDS:
out.write("\n#endif /* {} */\n".format(self._CPP_GUARDS))
out.write("#endif /* {} */\n\n".format(self._CPP_GUARDS))
super()._write_epilogue(out, header)
class PSALoggingWrapper(PSAWrapper, c_wrapper_generator.Logging):