Skip to content
Snippets Groups Projects

Fix a bug in functor grammar

Merged Abhijit Mathad requested to merge AM_functor_grammer_fix into master
@@ -46,16 +46,23 @@ def make_sphinx_link_name(functor):
return doc
def python_to_cpp_str(obj):
def python_to_cpp_str(obj, in_container=False):
# Reduce complex Python types down to simple Python representations
if isinstance(obj, DataHandle):
obj = obj.location
# Convert simple Python types to C++ representations
if type(obj) == int:
return 'std::integral_constant<int, {}>{{}}'.format(obj)
if in_container:
return 'int{{{0}}}'.format(obj)
else:
return 'std::integral_constant<int, {}>{{}}'.format(obj)
elif type(obj) == bool:
return 'std::bool_constant<{}>{{}}'.format('true' if obj else 'false')
if in_container:
return 'bool{{{0}}}'.format('true' if obj else 'false')
else:
return 'std::bool_constant<{}>{{}}'.format(
'true' if obj else 'false')
elif type(obj) == float:
# check if it is Not a Number
if obj != obj: return 'std::numeric_limits<float>::quiet_NaN()'
@@ -72,7 +79,7 @@ def python_to_cpp_str(obj):
items.append('{ ' + key_code + ', ' + val_code + ' }')
return '{' + ', '.join(items) + '}'
elif (type(obj) == list or type(obj) == tuple):
items = [python_to_cpp_str(item) for item in obj]
items = [python_to_cpp_str(item, in_container=True) for item in obj]
# if all elements are string type then use std::vector, if not std::tuple
contains_same_type = all(
isinstance(item, type(obj[0])) for item in obj)
Loading