mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 01:24:21 +01:00
Use switch instead if if-else for dependency and expression checks.
This commit is contained in:
parent
d61a4384d8
commit
b1c2d0f946
@ -427,16 +427,15 @@ def gen_dep_check(dep_id, dep):
|
|||||||
noT, dep = ('!', dep[1:]) if dep[0] == '!' else ('', dep)
|
noT, dep = ('!', dep[1:]) if dep[0] == '!' else ('', dep)
|
||||||
assert len(dep) > 0, "Dependency should not be an empty string."
|
assert len(dep) > 0, "Dependency should not be an empty string."
|
||||||
dep_check = '''
|
dep_check = '''
|
||||||
if ( dep_id == {id} )
|
case {id}:
|
||||||
{{
|
{{
|
||||||
#if {noT}defined({macro})
|
#if {noT}defined({macro})
|
||||||
return( DEPENDENCY_SUPPORTED );
|
ret = DEPENDENCY_SUPPORTED;
|
||||||
#else
|
#else
|
||||||
return( DEPENDENCY_NOT_SUPPORTED );
|
ret = DEPENDENCY_NOT_SUPPORTED;
|
||||||
#endif
|
#endif
|
||||||
}}
|
}}
|
||||||
else
|
break;'''.format(noT=noT, macro=dep, id=dep_id)
|
||||||
'''.format(noT=noT, macro=dep, id=dep_id)
|
|
||||||
return dep_check
|
return dep_check
|
||||||
|
|
||||||
|
|
||||||
@ -451,12 +450,11 @@ def gen_expression_check(exp_id, exp):
|
|||||||
assert exp_id > -1, "Expression Id should be a positive integer."
|
assert exp_id > -1, "Expression Id should be a positive integer."
|
||||||
assert len(exp) > 0, "Expression should not be an empty string."
|
assert len(exp) > 0, "Expression should not be an empty string."
|
||||||
exp_code = '''
|
exp_code = '''
|
||||||
if ( exp_id == {exp_id} )
|
case {exp_id}:
|
||||||
{{
|
{{
|
||||||
*out_value = {expression};
|
*out_value = {expression};
|
||||||
}}
|
}}
|
||||||
else
|
break;'''.format(exp_id=exp_id, expression=exp)
|
||||||
'''.format(exp_id=exp_id, expression=exp)
|
|
||||||
return exp_code
|
return exp_code
|
||||||
|
|
||||||
|
|
||||||
@ -527,28 +525,16 @@ def gen_suite_deps_checks(suite_deps, dep_check_code, expression_code):
|
|||||||
:param expression_code:
|
:param expression_code:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# void unused params
|
|
||||||
if len(dep_check_code) == 0:
|
|
||||||
dep_check_code = '(void) dep_id;\n'
|
|
||||||
if len(expression_code) == 0:
|
|
||||||
expression_code = '(void) exp_id;\n'
|
|
||||||
expression_code += '(void) out_value;\n'
|
|
||||||
|
|
||||||
if len(suite_deps):
|
if len(suite_deps):
|
||||||
ifdef = gen_deps_one_line(suite_deps)
|
ifdef = gen_deps_one_line(suite_deps)
|
||||||
dep_check_code = '''
|
dep_check_code = '''
|
||||||
{ifdef}
|
{ifdef}
|
||||||
{code}
|
{code}
|
||||||
#else
|
|
||||||
(void) dep_id;
|
|
||||||
#endif
|
#endif
|
||||||
'''.format(ifdef=ifdef, code=dep_check_code)
|
'''.format(ifdef=ifdef, code=dep_check_code)
|
||||||
expression_code = '''
|
expression_code = '''
|
||||||
{ifdef}
|
{ifdef}
|
||||||
{code}
|
{code}
|
||||||
#else
|
|
||||||
(void) exp_id;
|
|
||||||
(void) out_value;
|
|
||||||
#endif
|
#endif
|
||||||
'''.format(ifdef=ifdef, code=expression_code)
|
'''.format(ifdef=ifdef, code=expression_code)
|
||||||
return dep_check_code, expression_code
|
return dep_check_code, expression_code
|
||||||
|
@ -63,12 +63,22 @@
|
|||||||
*/
|
*/
|
||||||
int get_expression( int32_t exp_id, int32_t * out_value )
|
int get_expression( int32_t exp_id, int32_t * out_value )
|
||||||
{{
|
{{
|
||||||
|
int ret = KEY_VALUE_MAPPING_FOUND;
|
||||||
|
|
||||||
|
(void) exp_id;
|
||||||
|
(void) out_value;
|
||||||
|
|
||||||
|
switch( exp_id )
|
||||||
|
{{
|
||||||
{expression_code}
|
{expression_code}
|
||||||
#line {line_no} "suites/main_test.function"
|
#line {line_no} "suites/main_test.function"
|
||||||
{{
|
default:
|
||||||
return( KEY_VALUE_MAPPING_NOT_FOUND );
|
{{
|
||||||
|
ret = KEY_VALUE_MAPPING_NOT_FOUND;
|
||||||
|
}}
|
||||||
|
break;
|
||||||
}}
|
}}
|
||||||
return( KEY_VALUE_MAPPING_FOUND );
|
return( ret );
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
@ -85,11 +95,18 @@ int get_expression( int32_t exp_id, int32_t * out_value )
|
|||||||
*/
|
*/
|
||||||
int dep_check( int dep_id )
|
int dep_check( int dep_id )
|
||||||
{{
|
{{
|
||||||
|
int ret = DEPENDENCY_NOT_SUPPORTED;
|
||||||
|
|
||||||
|
(void) dep_id;
|
||||||
|
|
||||||
|
switch( dep_id )
|
||||||
|
{{
|
||||||
{dep_check_code}
|
{dep_check_code}
|
||||||
#line {line_no} "suites/main_test.function"
|
#line {line_no} "suites/main_test.function"
|
||||||
{{
|
default:
|
||||||
return( DEPENDENCY_NOT_SUPPORTED );
|
break;
|
||||||
}}
|
}}
|
||||||
|
return( ret );
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user