shithub: aubio

Download patch

ref: 6cbf34b5e4d05e358d66818e373f4740e4720eed
parent: b1f93c4f28870a164c7bd9c665b810b73d3e3e8a
author: Martin Hermant <martin.hermant@gmail.com>
date: Mon May 29 14:28:40 EDT 2017

gen_external :
	 add function get_all_func_names_from_lib
	analyze_c_declarations -> generate_lib_from_c_declarations

--- a/python/lib/gen_external.py
+++ b/python/lib/gen_external.py
@@ -135,7 +135,37 @@
     cpp_objects = [a.split()[3][:-1] for a in typedefs]
     return cpp_objects
 
-def analyze_c_declarations(cpp_objects, c_declarations):
+
+def get_all_func_names_from_lib(lib, depth=0):
+    ''' return flat string of all function used in lib
+    '''
+    res = []
+    indent = " " * depth
+    for k, v in lib.items():
+        if isinstance(v, dict):
+            res += get_all_func_names_from_lib(v, depth + 1)
+        elif isinstance(v, list):
+            for elem in v:
+                e = elem.split('(')
+                if len(e) < 2:
+                    continue  # not a function
+                fname_part = e[0].strip().split(' ')
+                fname = fname_part[-1]
+                if fname:
+                    res += [fname]
+                else:
+                    raise NameError('gen_lib : weird function: ' + str(e))
+
+    return res
+
+
+def generate_lib_from_c_declarations(cpp_objects, c_declarations):
+    ''' returns a lib from given cpp_object names
+
+    a lib is a dict grouping functions by family (onset,pitch...)
+        each eement is itself a dict of functions grouped by puposes as : 
+        struct, new, del, do, get, set and other
+    '''
     lib = {}
 
     for o in cpp_objects:
@@ -205,7 +235,7 @@
     c_declarations = get_c_declarations(header, usedouble=usedouble)
     cpp_objects = get_cpp_objects_from_c_declarations(c_declarations)
 
-    lib = analyze_c_declarations(cpp_objects, c_declarations)
+    lib = generate_lib_from_c_declarations(cpp_objects, c_declarations)
     # print_c_declarations_results(lib, c_declarations)
 
     sources_list = []