mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-10-22 00:17:55 +00:00
c_wrapper_generator: Adjusted new-line logic
Signed-off-by: Minos Galanakis <[email protected]>
This commit is contained in:
@@ -80,14 +80,16 @@ class Base:
|
|||||||
'',
|
'',
|
||||||
'#ifdef __cplusplus',
|
'#ifdef __cplusplus',
|
||||||
'extern "C" {',
|
'extern "C" {',
|
||||||
'#endif']
|
'#endif',
|
||||||
|
'']
|
||||||
|
|
||||||
for include in self._INCLUDES:
|
for include in self._INCLUDES:
|
||||||
prologue.append('#include {}'.format(include))
|
prologue.append('#include {}'.format(include))
|
||||||
|
|
||||||
# Make certain there is an empty line
|
# Make certain there is an empty line at the end of this section.
|
||||||
if prologue[-1] != '':
|
for i in [-1, -2]:
|
||||||
prologue += (['', ''])
|
if prologue[i] != '':
|
||||||
|
prologue.append('')
|
||||||
|
|
||||||
out.write('\n'.join(prologue))
|
out.write('\n'.join(prologue))
|
||||||
|
|
||||||
@@ -96,8 +98,7 @@ class Base:
|
|||||||
"""
|
"""
|
||||||
epilogue = []
|
epilogue = []
|
||||||
if header:
|
if header:
|
||||||
epilogue += ['',
|
epilogue += ['#ifdef __cplusplus',
|
||||||
'#ifdef __cplusplus',
|
|
||||||
'}',
|
'}',
|
||||||
'#endif',
|
'#endif',
|
||||||
'',
|
'',
|
||||||
@@ -273,10 +274,8 @@ class Base:
|
|||||||
wrapper = self._wrapper_info(function)
|
wrapper = self._wrapper_info(function)
|
||||||
if wrapper is None:
|
if wrapper is None:
|
||||||
return
|
return
|
||||||
out.write("""
|
out.write('/* Wrapper for {} */\n'.format(function.name))
|
||||||
/* Wrapper for {} */
|
|
||||||
"""
|
|
||||||
.format(function.name))
|
|
||||||
if wrapper.guard is not None:
|
if wrapper.guard is not None:
|
||||||
out.write('#if {}\n'.format(wrapper.guard))
|
out.write('#if {}\n'.format(wrapper.guard))
|
||||||
self._write_function_prototype(out, function, wrapper, False)
|
self._write_function_prototype(out, function, wrapper, False)
|
||||||
@@ -285,6 +284,7 @@ class Base:
|
|||||||
out.write('}\n')
|
out.write('}\n')
|
||||||
if wrapper.guard is not None:
|
if wrapper.guard is not None:
|
||||||
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
||||||
|
out.write('\n')
|
||||||
|
|
||||||
def _write_h_function_declaration(self, out: typing_util.Writable,
|
def _write_h_function_declaration(self, out: typing_util.Writable,
|
||||||
function: FunctionInfo,
|
function: FunctionInfo,
|
||||||
@@ -316,13 +316,13 @@ class Base:
|
|||||||
wrapper = self._wrapper_info(function)
|
wrapper = self._wrapper_info(function)
|
||||||
if wrapper is None:
|
if wrapper is None:
|
||||||
return
|
return
|
||||||
out.write('\n')
|
|
||||||
if wrapper.guard is not None:
|
if wrapper.guard is not None:
|
||||||
out.write('#if {}\n'.format(wrapper.guard))
|
out.write('#if {}\n'.format(wrapper.guard))
|
||||||
self._write_h_function_declaration(out, function, wrapper)
|
self._write_h_function_declaration(out, function, wrapper)
|
||||||
self._write_h_macro_definition(out, function, wrapper)
|
self._write_h_macro_definition(out, function, wrapper)
|
||||||
if wrapper.guard is not None:
|
if wrapper.guard is not None:
|
||||||
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
||||||
|
out.write('\n')
|
||||||
|
|
||||||
def write_c_file(self, filename: str) -> None:
|
def write_c_file(self, filename: str) -> None:
|
||||||
"""Output a whole C file containing function wrapper definitions."""
|
"""Output a whole C file containing function wrapper definitions."""
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class PSATestWrapper(PSAWrapper):
|
|||||||
_WRAPPER_NAME_PREFIX = 'mbedtls_test_wrap_'
|
_WRAPPER_NAME_PREFIX = 'mbedtls_test_wrap_'
|
||||||
_WRAPPER_NAME_SUFFIX = ''
|
_WRAPPER_NAME_SUFFIX = ''
|
||||||
|
|
||||||
_PSA_WRAPPER_INCLUDES = ['<psa/crypto.h>',
|
_PSA_WRAPPER_INCLUDES = ['<psa/crypto.h>\n',
|
||||||
'<test/memory.h>',
|
'<test/memory.h>',
|
||||||
'<test/psa_crypto_helpers.h>',
|
'<test/psa_crypto_helpers.h>',
|
||||||
'<test/psa_test_wrappers.h>']
|
'<test/psa_test_wrappers.h>']
|
||||||
|
|||||||
@@ -198,14 +198,16 @@ class PSAWrapper(c_wrapper_generator.Base):
|
|||||||
for include in self._PSA_WRAPPER_INCLUDES:
|
for include in self._PSA_WRAPPER_INCLUDES:
|
||||||
prologue.append("#include {}".format(include))
|
prologue.append("#include {}".format(include))
|
||||||
|
|
||||||
if prologue[-1] != '':
|
# Make certain there is an empty line at the end of this section.
|
||||||
prologue.append('')
|
for i in [-1, -2]:
|
||||||
|
if prologue[i] != '':
|
||||||
|
prologue.append('')
|
||||||
|
|
||||||
out.write("\n".join(prologue))
|
out.write("\n".join(prologue))
|
||||||
|
|
||||||
def _write_epilogue(self, out: typing_util.Writable, header: bool) -> None:
|
def _write_epilogue(self, out: typing_util.Writable, header: bool) -> None:
|
||||||
if self._CPP_GUARDS:
|
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)
|
super()._write_epilogue(out, header)
|
||||||
|
|
||||||
class PSALoggingWrapper(PSAWrapper, c_wrapper_generator.Logging):
|
class PSALoggingWrapper(PSAWrapper, c_wrapper_generator.Logging):
|
||||||
|
|||||||
Reference in New Issue
Block a user