diff OrthancFramework/Resources/CheckOrthancFrameworkSymbols.py @ 4520:f5cb0c0ffbed

added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Feb 2021 18:30:31 +0100
parents d9473bd5ed43
children 1de2fc0363cb
line wrap: on
line diff
--- a/OrthancFramework/Resources/CheckOrthancFrameworkSymbols.py	Mon Feb 22 16:51:23 2021 +0100
+++ b/OrthancFramework/Resources/CheckOrthancFrameworkSymbols.py	Mon Feb 22 18:30:31 2021 +0100
@@ -53,6 +53,9 @@
 parser.add_argument('--libclang',
                     default = '',
                     help = 'manually provides the path to the libclang shared library')
+parser.add_argument('--target-cpp-size',
+                    default = '',
+                    help = 'where to store C++ source to display the size of each public class')
 
 args = parser.parse_args()
 
@@ -107,6 +110,7 @@
 
 FILES = []
 COUNT = 0
+ALL_TYPES = []
 
 def ReportProblem(message, fqn, cursor):
     global FILES, COUNT
@@ -141,6 +145,9 @@
     if not visible:
         return
 
+    global ALL_TYPES
+    ALL_TYPES.append('::'.join(fqn))
+    
     
     ##
     ## Ignore pure abstract interfaces, by checking the following
@@ -206,6 +213,9 @@
     
     isPublic = (child.kind == clang.cindex.CursorKind.STRUCT_DECL)
 
+    membersCount = 0
+    membersSize = 0
+
     for i in child.get_children():
         if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR or    # "default"
             i.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER):  # base class
@@ -232,8 +242,7 @@
                     ReportProblem('Exported public method with an implementation', fqn, i)
 
         elif i.kind == clang.cindex.CursorKind.VAR_DECL:
-            if isPublic:
-                ReportProblem('Exported public member variable', fqn, i)
+            raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
 
         elif i.kind == clang.cindex.CursorKind.FUNCTION_TEMPLATE:
             # An inline function template is OK, as it is not added to
@@ -261,11 +270,19 @@
                      'operator<<(std::ostream &, const Orthanc::DicomTag &)',
                  ])):
                 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
+
+        elif i.kind == clang.cindex.CursorKind.FIELD_DECL:
+            # TODO
+            if i.type.get_size() > 0:
+                membersSize += i.type.get_size()
+            membersCount += 1
             
         else:
             if isPublic:
                 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
 
+    #print('Size of %s => (%d,%d)' % ('::'.join(fqn), membersCount, membersSize))
+
 
 def ExploreNamespace(node, namespace):
     for child in node.get_children():
@@ -301,6 +318,12 @@
         ExploreNamespace(node, [ 'Orthanc' ])
 
 
+if args.target_cpp_size != '':
+    with open(args.target_cpp_size, 'w') as f:
+        for t in sorted(ALL_TYPES):
+            f.write('  printf("sizeof(::%s) == %%d\\n", static_cast<int>(sizeof(::%s)));\n' % (t, t))
+
+
 print('\nTotal of possibly problematic methods: %d' % COUNT)
 
 print('\nProblematic files:\n')