1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-13 11:29:51 +03:00

Revert "Now datacopy.cpp will be automatically generated to avoid the latest issue"

This reverts commit 5ce63b6d
This commit is contained in:
3djc 2019-11-16 09:09:20 +01:00
parent 8b6d158c07
commit f74658a165
3 changed files with 387 additions and 28 deletions

View file

@ -22,7 +22,6 @@ if sys.platform == "linux2":
structs = []
extrastructs = []
def build_struct(cursor, anonymousUnion=False):
if not anonymousUnion:
structs.append(cursor.spelling)
@ -33,7 +32,7 @@ def build_struct(cursor, anonymousUnion=False):
if c.spelling:
raise "Cannot handle non anonymous unions"
copied_union_member = False
copiedUnionMember = False
for uc in c.get_children():
if not uc.spelling or uc.kind == clang.cindex.CursorKind.PACKED_ATTR:
# Ignore
@ -41,11 +40,11 @@ def build_struct(cursor, anonymousUnion=False):
else:
# per default we copy only the first member of a union and warn if there are more
# members (declare the other members NOBACKUP)
if copied_union_member:
print("Warning more than one union member (%s) in anynomous union inside struct %s, consider NOBACKUP statements" % (uc.spelling, cursor.spelling), file=sys.stderr)
if copiedUnionMember:
print ("Warning more than one union member (%s) in anynomous union inside struct %s, consider NOBACKUP statements" % (uc.spelling, cursor.spelling), file=sys.stderr)
else:
copy_decl(uc, uc.spelling)
copied_union_member = True
copiedUnionMember = True
elif c.kind == clang.cindex.CursorKind.FIELD_DECL:
copy_decl(c, c.spelling)
@ -53,7 +52,6 @@ def build_struct(cursor, anonymousUnion=False):
if not anonymousUnion:
print("}\n")
def build(cursor):
result = []
for c in cursor.get_children():
@ -63,13 +61,13 @@ def build(cursor):
for c, spelling in extrastructs:
print("template <class A, class B>\nvoid copy%s(A * dest, B * src)\n{" % spelling)
build_struct(c, True)
print("}\n")
print ("}\n")
return result
def copy_decl(c, spelling):
children = [ch for ch in c.get_children()]
childs = [ch for ch in c.get_children()]
if c.type.get_array_size() > 0:
if c.type.get_array_element_type().spelling in structs:
print(" for (int i=0; i<%d; i++) {" % c.type.get_array_size())
@ -77,15 +75,16 @@ def copy_decl(c, spelling):
print(" }")
else:
print(" memcpy(dest->%s, src->%s, sizeof(dest->%s));" % (spelling, spelling, spelling))
elif len(children) == 1 and children[0].kind == clang.cindex.CursorKind.STRUCT_DECL and not children[0].spelling:
elif len(childs)==1 and childs[0].kind == clang.cindex.CursorKind.STRUCT_DECL and not childs[0].spelling:
# inline declared structs
if c.semantic_parent.spelling:
spelling_func = c.semantic_parent.spelling + "_" + spelling
spellingFunc = c.semantic_parent.spelling + "_" + spelling
else:
spelling_func = c.semantic_parent.semantic_parent.spelling + "_" + spelling
spellingFunc = c.semantic_parent.semantic_parent.spelling + "_" + spelling
extrastructs.append((childs[0], spellingFunc))
print(" copy%s(&dest->%s, &src->%s);" % (spellingFunc, spelling, spelling))
extrastructs.append((children[0], spelling_func))
print(" copy%s(&dest->%s, &src->%s);" % (spelling_func, spelling, spelling))
elif c.type.get_declaration().spelling in structs:
print(" copy%s(&dest->%s, &src->%s);" % (c.type.get_declaration().spelling, spelling, spelling))
else:
@ -93,8 +92,7 @@ def copy_decl(c, spelling):
def header():
print("// This file was auto-generated by %s script on %s. Do not edit this file!\n\n\n" % (os.path.basename(sys.argv[0]), time.asctime()))
print("//This file was auto-generated by %s script on %s. Do not edit this file!\n\n\n" % (os.path.basename(sys.argv[0]), time.asctime()))
index = clang.cindex.Index.create()
translation_unit = index.parse(sys.argv[1], ['-x', 'c++', '-std=c++11'] + sys.argv[2:])