annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4349
diff changeset
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public License
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # as published by the Free Software Foundation, either version 3 of
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # the License, or (at your option) any later version.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful, but
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # Lesser General Public License for more details.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # License along with this program. If not, see
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # <http://www.gnu.org/licenses/>.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 ## This maintenance script detects all the public methods in the
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 ## Orthanc framework that come with an inlined implementation in the
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 ## header file. Such methods can break the ABI of the shared library,
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 ## as the actual implementation might change over versions.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 # Ubuntu 20.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 # sudo apt-get install python-clang-6.0
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # ./ParseWebAssemblyExports.py --libclang=libclang-6.0.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # Ubuntu 18.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 # sudo apt-get install python-clang-4.0
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 # ./ParseWebAssemblyExports.py --libclang=libclang-4.0.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 # Ubuntu 14.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 # ./ParseWebAssemblyExports.py --libclang=libclang-3.6.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 import os
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 import sys
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 import clang.cindex
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 import argparse
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ## Parse the command-line arguments
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 parser = argparse.ArgumentParser(description = 'Parse WebAssembly C++ source file, and create a basic JavaScript wrapper.')
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 parser.add_argument('--libclang',
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 default = '',
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 help = 'manually provides the path to the libclang shared library')
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
56 parser.add_argument('--target-cpp-size',
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
57 default = '',
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
58 help = 'where to store C++ source to display the size of each public class')
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 args = parser.parse_args()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if len(args.libclang) != 0:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 clang.cindex.Config.set_library_file(args.libclang)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 index = clang.cindex.Index.create()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ROOT = os.path.abspath(os.path.dirname(sys.argv[0]))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 SOURCES = []
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 for root, dirs, files in os.walk(os.path.join(ROOT, '..', 'Sources')):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 for name in files:
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
74 if (os.path.splitext(name)[1] == '.h' and
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
75 name != 'Enumerations_TransferSyntaxes.impl.h'):
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 SOURCES.append(os.path.join(root, name))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 AMALGAMATION = '/tmp/CheckOrthancFrameworkSymbols.cpp'
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 with open(AMALGAMATION, 'w') as f:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 f.write('#include "%s"\n' % os.path.join(ROOT, '..', 'Sources', 'OrthancFramework.h'))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 for source in SOURCES:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 f.write('#include "%s"\n' % source)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
86 tu = index.parse(AMALGAMATION, [
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
87 '-DORTHANC_BUILDING_FRAMEWORK_LIBRARY=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
88 '-DORTHANC_BUILD_UNIT_TESTS=0',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
89 '-DORTHANC_ENABLE_BASE64=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
90 '-DORTHANC_ENABLE_CIVETWEB=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
91 '-DORTHANC_ENABLE_CURL=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
92 '-DORTHANC_ENABLE_DCMTK=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
93 '-DORTHANC_ENABLE_DCMTK_JPEG=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
94 '-DORTHANC_ENABLE_DCMTK_NETWORKING=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
95 '-DORTHANC_ENABLE_DCMTK_TRANSCODING=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
96 '-DORTHANC_ENABLE_JPEG=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
97 '-DORTHANC_ENABLE_LOCALE=1',
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
98 '-DORTHANC_ENABLE_LOGGING=1',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
99 '-DORTHANC_ENABLE_LOGGING_STDIO=0',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
100 '-DORTHANC_ENABLE_LUA=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
101 '-DORTHANC_ENABLE_MD5=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
102 '-DORTHANC_ENABLE_PKCS11=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
103 '-DORTHANC_ENABLE_PNG=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
104 '-DORTHANC_ENABLE_PUGIXML=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
105 '-DORTHANC_ENABLE_SSL=1',
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
106 '-DORTHANC_SANDBOXED=0',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
107 '-DORTHANC_SQLITE_STANDALONE=0',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
108 ])
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
111 FILES = []
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
112 COUNT = 0
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113 ALL_TYPES = []
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
115 def ReportProblem(message, fqn, cursor):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
116 global FILES, COUNT
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
117 FILES.append(os.path.normpath(str(cursor.location.file)))
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
118 COUNT += 1
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
119
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
120 print('%s: %s::%s()' % (message, '::'.join(fqn), cursor.spelling))
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
121
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
122
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
123 def ExploreClass(child, fqn):
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
124 # Safety check
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
125 if (child.kind != clang.cindex.CursorKind.CLASS_DECL and
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
126 child.kind != clang.cindex.CursorKind.STRUCT_DECL):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
127 raise Exception()
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
128
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
129 # Ignore forward declaration of classes
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
130 if not child.is_definition():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
131 return
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
132
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
133
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
134 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
135 ## Verify that the class is publicly exported (its visibility must
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
136 ## be "default")
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
137 ##
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
138 visible = False
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
139
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
140 for i in child.get_children():
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
141 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR and
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
142 i.spelling == 'default'):
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
143 visible = True
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
144
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
145 if not visible:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
146 return
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
147
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
148 global ALL_TYPES
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
149 ALL_TYPES.append('::'.join(fqn))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
151
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
152 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
153 ## Ignore pure abstract interfaces, by checking the following
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
154 ## criteria:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
155 ## - It must be a C++ class (not a struct)
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
156 ## - It must start with "I"
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
157 ## - All its methods must be pure virtual (abstract) and public
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
158 ## - Its destructor must be public, virtual, and must do nothing
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
159 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
160
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
161 if (child.kind == clang.cindex.CursorKind.CLASS_DECL and
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
162 child.spelling[0] == 'I' and
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
163 child.spelling[1].isupper()):
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
164 abstract = True
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
165 isPublic = False
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
166
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
167 for i in child.get_children():
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
168 if i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR: # "default"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
169 pass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
170 elif i.kind == clang.cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
171 isPublic = (i.access_specifier == clang.cindex.AccessSpecifier.PUBLIC)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
172 elif i.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
173 if i.spelling != 'boost::noncopyable':
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
174 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
175 elif isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
176 if i.kind == clang.cindex.CursorKind.CXX_METHOD:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
177 if i.is_pure_virtual_method():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
178 pass # pure virtual is ok
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
179 elif i.is_static_method():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
180 # static method without an inline implementation is ok
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
181 for j in i.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
182 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
183 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
184 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
185 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
186 elif (i.kind == clang.cindex.CursorKind.DESTRUCTOR and
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
187 i.is_virtual_method()):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
188 # The destructor must be virtual, and must do nothing
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
189 c = list(i.get_children())
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
190 if (len(c) != 1 or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
191 c[0].kind != clang.cindex.CursorKind.COMPOUND_STMT or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
192 len(list(c[0].get_children())) != 0):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
193 abstract = False
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
194 elif i.kind == clang.cindex.CursorKind.CLASS_DECL:
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
195 ExploreClass(i, fqn + [ i.spelling ])
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
196 elif (i.kind == clang.cindex.CursorKind.TYPEDEF_DECL or # Allow "typedef"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
197 i.kind == clang.cindex.CursorKind.ENUM_DECL): # Allow enums
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
198 pass
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
199 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
200 abstract = False
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
201
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
202 if abstract:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
203 print('Detected a pure interface (this is fine): %s' % ('::'.join(fqn)))
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
204 else:
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
205 ReportProblem('Not a pure interface', fqn, child)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
206
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
207 return
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
208
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
209
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
210 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
211 ## We are facing a standard C++ class or struct
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
212 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
213
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
214 isPublic = (child.kind == clang.cindex.CursorKind.STRUCT_DECL)
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
215
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
216 membersCount = 0
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
217 membersSize = 0
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
218
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
219 for i in child.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
220 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR or # "default"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
221 i.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER): # base class
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
222 pass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
223
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
224 elif i.kind == clang.cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
225 isPublic = (i.access_specifier == clang.cindex.AccessSpecifier.PUBLIC)
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
226
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
227 elif i.kind == clang.cindex.CursorKind.CLASS_DECL:
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
228 # This is a subclass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
229 if isPublic:
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
230 ExploreClass(i, fqn + [ i.spelling ])
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
231
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
232 elif (i.kind == clang.cindex.CursorKind.CXX_METHOD or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
233 i.kind == clang.cindex.CursorKind.CONSTRUCTOR or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
234 i.kind == clang.cindex.CursorKind.DESTRUCTOR):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
235 if isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
236 hasImplementation = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
237 for j in i.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
238 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
239 hasImplementation = True
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
240
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
241 if hasImplementation:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
242 ReportProblem('Exported public method with an implementation', fqn, i)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
243
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
244 elif i.kind == clang.cindex.CursorKind.VAR_DECL:
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
245 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
246
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
247 elif i.kind == clang.cindex.CursorKind.FUNCTION_TEMPLATE:
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
248 # An inline function template is OK, as it is not added to
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
249 # a shared library, but compiled by the client of the library
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
250 if isPublic:
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
251 print('Detected a template function (this is fine, but avoid it as much as possible): %s' % ('::'.join(fqn + [ i.spelling ])))
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
252 hasImplementation = False
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
253 for j in i.get_children():
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
254 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
255 hasImplementation = True
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
256
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
257 if not hasImplementation:
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
258 ReportProblem('Exported template function without an inline implementation', fqn, i)
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
259
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
260 elif (i.kind == clang.cindex.CursorKind.TYPEDEF_DECL or # Allow "typedef"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
261 i.kind == clang.cindex.CursorKind.ENUM_DECL): # Allow enums
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
262 pass
4349
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
263
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
264 elif i.kind == clang.cindex.CursorKind.FRIEND_DECL:
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
265 children = list(i.get_children())
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
266 if (isPublic and
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
267 (len(children) != 1 or
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
268 not children[0].displayname in [
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
269 # This is supported for ABI compatibility with Orthanc <= 1.8.0
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
270 'operator<<(std::ostream &, const Orthanc::DicomTag &)',
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
271 ])):
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
272 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
273
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
274 elif i.kind == clang.cindex.CursorKind.FIELD_DECL:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
275 # TODO
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
276 if i.type.get_size() > 0:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
277 membersSize += i.type.get_size()
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
278 membersCount += 1
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
279
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
280 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
281 if isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
282 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
283
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
284 #print('Size of %s => (%d,%d)' % ('::'.join(fqn), membersCount, membersSize))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
285
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
286
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 def ExploreNamespace(node, namespace):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 for child in node.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 fqn = namespace + [ child.spelling ]
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 if child.kind == clang.cindex.CursorKind.NAMESPACE:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 ExploreNamespace(child, fqn)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 elif (child.kind == clang.cindex.CursorKind.CLASS_DECL or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 child.kind == clang.cindex.CursorKind.STRUCT_DECL):
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
296 ExploreClass(child, fqn)
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
298 elif child.kind == clang.cindex.CursorKind.FUNCTION_DECL:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
299 visible = False
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
300 hasImplementation = False
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
301 for i in child.get_children():
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
302 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR and
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
303 i.spelling == 'default'):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
304 visible = True
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
305 elif i.kind == clang.cindex.CursorKind.COMPOUND_STMT:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
306 hasImplementation = True
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
307
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
308 if visible and hasImplementation:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
309 ReportProblem('Exported public function with an implementation', fqn, i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
310
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
311
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
312
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
313 print('')
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
314
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 for node in tu.cursor.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 if (node.kind == clang.cindex.CursorKind.NAMESPACE and
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 node.spelling == 'Orthanc'):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ExploreNamespace(node, [ 'Orthanc' ])
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
319
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
320
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
321 if args.target_cpp_size != '':
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
322 with open(args.target_cpp_size, 'w') as f:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
323 for t in sorted(ALL_TYPES):
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
324 f.write(' printf("sizeof(::%s) == %%d\\n", static_cast<int>(sizeof(::%s)));\n' % (t, t))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
325
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
326
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
327 print('\nTotal of possibly problematic methods: %d' % COUNT)
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
328
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
329 print('\nProblematic files:\n')
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
330 for i in sorted(list(set(FILES))):
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
331 print(i)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
332
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
333 print('')