annotate CodeAnalysis/ParseOrthancSDK.py @ 170:b49eeb36cd0d

removed generation of code model, now part of orthanc-java
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Jun 2024 14:26:59 +0200
parents 6fada29b6759
children 46a81ed6e843
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
140
b6835b7a7c0a code generation on Ubuntu 22.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 138
diff changeset
1 #!/usr/bin/env python3
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 ## Python plugin for Orthanc
166
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
5 ## Copyright (C) 2020-2023 Osimis S.A., Belgium
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
6 ## Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
155
71d305c29cfa updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 141
diff changeset
7 ## Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 ## This program is free software: you can redistribute it and/or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 ## modify it under the terms of the GNU Affero General Public License
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 ## as published by the Free Software Foundation, either version 3 of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 ## the License, or (at your option) any later version.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 ## This program is distributed in the hope that it will be useful, but
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 ## Affero General Public License for more details.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 ## You should have received a copy of the GNU Affero General Public License
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import argparse
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import clang.cindex
138
3e89d1c4f721 export the code model as json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
26 import json
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import os
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import pprint
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import pystache
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import sys
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 ROOT = os.path.dirname(os.path.realpath(sys.argv[0]))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ##
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
37 ## Configuration of the custom primitives that are manually
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
38 ## implemented (not autogenerated)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
39 ##
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
40
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
41 CUSTOM_FUNCTIONS = set([
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
42 'OrthancPluginCreateDicom',
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
43 'OrthancPluginCreateImageAccessor', # Replaced by "orthanc.CreateImageFromBuffer()"
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
44 'OrthancPluginFreeMemoryBuffer',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
45 'OrthancPluginFreeString',
66
6fc445793796 new wrapped function: orthanc.LookupDictionary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 65
diff changeset
46 'OrthancPluginLookupDictionary',
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
47 'OrthancPluginRegisterFindCallback',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
48 'OrthancPluginRegisterIncomingHttpRequestFilter', # Implemented through v2
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
49 'OrthancPluginRegisterIncomingHttpRequestFilter2',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
50 'OrthancPluginRegisterMoveCallback',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
51 'OrthancPluginRegisterOnChangeCallback',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
52 'OrthancPluginRegisterOnStoredInstanceCallback',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
53 'OrthancPluginRegisterRestCallback', # Implemented using OrthancPlugins::RegisterRestCallback
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
54 'OrthancPluginRegisterRestCallbackNoLock', # Implemented using OrthancPlugins::RegisterRestCallback
64
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
55 'OrthancPluginRegisterWorklistCallback',
96
627b8a19fb9f orthanc.RegisterIncomingCStoreInstanceFilter()
Alain Mazy <am@osimis.io>
parents: 66
diff changeset
56 'OrthancPluginRegisterIncomingCStoreInstanceFilter',
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
57 ])
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
58
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
59 CUSTOM_METHODS = [
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
60 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
61 'class_name' : 'OrthancPluginFindQuery',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
62 'method_name' : 'GetFindQueryTagGroup',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
63 'implementation' : 'GetFindQueryTagGroup',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
64 'sdk_function' : 'OrthancPluginGetFindQueryTag',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
65 },
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
66 {
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
67 'class_name' : 'OrthancPluginFindQuery',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
68 'method_name' : 'GetFindQueryTagElement',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
69 'implementation' : 'GetFindQueryTagElement',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
70 'sdk_function' : 'OrthancPluginGetFindQueryTag',
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
71 },
64
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
72 {
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
73 'class_name' : 'OrthancPluginWorklistAnswers',
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
74 'method_name' : 'WorklistAddAnswer',
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
75 'implementation' : 'WorklistAddAnswer',
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
76 'sdk_function' : 'OrthancPluginWorklistAddAnswer',
091fb1903bfc new wrapped function: orthanc.RegisterWorklistCallback() and orthanc.WorklistAnswers.WorklistAddAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
77 },
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
78 {
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
79 'class_name' : 'OrthancPluginDicomInstance',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
80 'method_name' : 'GetInstanceData',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
81 'implementation' : 'GetInstanceData',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
82 'sdk_function' : 'OrthancPluginGetInstanceData',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
83 },
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
84 {
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
85 'class_name' : 'OrthancPluginImage',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
86 'method_name' : 'GetImageBuffer',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
87 'implementation' : 'GetImageBuffer',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
88 'sdk_function' : 'OrthancPluginGetImageBuffer',
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
89 },
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
90 ]
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
91
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
92 for method in CUSTOM_METHODS:
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
93 CUSTOM_FUNCTIONS.add(method['sdk_function'])
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
94
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
95
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
96 ##
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ## Parse the command-line arguments
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ##
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 parser = argparse.ArgumentParser(description = 'Parse the Orthanc SDK.')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 parser.add_argument('--libclang',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 default = 'libclang-4.0.so.1',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 help = 'manually provides the path to the libclang shared library')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 parser.add_argument('--source',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 default = os.path.join(os.path.dirname(__file__),
108
2389ec6ec803 preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
106 '../Resources/Orthanc/Sdk-1.10.0/orthanc/OrthancCPlugin.h'),
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 help = 'Input C++ file')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 parser.add_argument('--target',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 default = os.path.join(os.path.dirname(__file__),
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 '../Sources/Autogenerated'),
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 help = 'Target folder')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 args = parser.parse_args()
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if len(args.libclang) != 0:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 clang.cindex.Config.set_library_file(args.libclang)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 index = clang.cindex.Index.create()
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 tu = index.parse(args.source, [ ])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 TARGET = os.path.realpath(args.target)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 def ToUpperCase(name):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 s = ''
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 for i in range(len(name)):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if name[i].isupper():
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 if len(s) == 0:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 s += name[i]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 elif name[i - 1].islower():
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 s += '_' + name[i]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 elif (i + 1 < len(name) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 name[i - 1].islower() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 name[i + 1].isupper()):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 s += '_' + name[i]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 s += name[i]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 s += name[i].upper()
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 return s
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 with open(os.path.join(ROOT, 'Enumeration.mustache'), 'r') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 TEMPLATE = f.read()
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 classes = {}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 enumerations = {}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 globalFunctions = []
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
155 countAllFunctions = 0
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
156 countSupportedFunctions = 0
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 def IsSourceStringType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 t.get_pointee().kind == clang.cindex.TypeKind.CHAR_S and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 t.get_pointee().is_const_qualified())
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 def IsTargetStaticStringType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 t.get_pointee().kind == clang.cindex.TypeKind.CHAR_S and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 t.get_pointee().is_const_qualified())
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 def IsTargetDynamicStringType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 t.get_pointee().kind == clang.cindex.TypeKind.CHAR_S and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 not t.get_pointee().is_const_qualified())
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 def IsIntegerType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 return (t.kind == clang.cindex.TypeKind.INT or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 t.spelling in [ 'int8_t', 'int16_t', 'int32_t', 'int64_t',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t'])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 def IsFloatType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return t.kind == clang.cindex.TypeKind.FLOAT
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 def IsEnumerationType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 return (t.kind == clang.cindex.TypeKind.TYPEDEF and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 t.spelling in enumerations)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 def IsTargetMemoryBufferType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 not t.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 t.get_pointee().spelling == 'OrthancPluginMemoryBuffer')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 def IsSourceMemoryBufferType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 t.get_pointee().kind == clang.cindex.TypeKind.VOID and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 t.get_pointee().is_const_qualified())
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 def IsClassType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 return (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ((t.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 t.get_pointee().spelling.startswith('const ') and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 t.get_pointee().spelling[len('const '):] in classes) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 (not t.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 t.get_pointee().spelling in classes)))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 def IsSimpleSourceType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 return (IsSourceStringType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 IsFloatType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 IsIntegerType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 IsEnumerationType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 IsSourceMemoryBufferType(t))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 def IsVoidType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 return t.kind == clang.cindex.TypeKind.VOID
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 def IsSupportedTargetType(t):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 return (IsVoidType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 IsIntegerType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 IsEnumerationType(t) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 # Constructor of a class
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 not t.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 t.get_pointee().spelling in classes) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 # "const char*" or "char*" outputs
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 (t.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 #not t.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 t.get_pointee().kind == clang.cindex.TypeKind.CHAR_S))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 def IsBytesArgument(args, index):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 return (index + 1 < len(args) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 args[index].type.kind == clang.cindex.TypeKind.POINTER and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 args[index].type.get_pointee().kind == clang.cindex.TypeKind.VOID and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 args[index].type.get_pointee().is_const_qualified() and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 args[index + 1].type.spelling == 'uint32_t')
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 def CheckOnlySupportedArguments(args):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 j = 0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 while j < len(args):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if IsBytesArgument(args, j):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 j += 2
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 elif IsSimpleSourceType(args[j].type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 j += 1
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 return False
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 return True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 ORTHANC_TO_PYTHON_NUMERIC_TYPES = {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 # https://docs.python.org/3/c-api/arg.html#numbers
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 'int' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 'type' : 'int',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 'format' : 'i',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 'uint8_t' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 'type' : 'unsigned char',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 'format' : 'b',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 'int32_t' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 'type' : 'long int',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 'format' : 'l',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 'uint16_t' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 'type' : 'unsigned short',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 'format' : 'H',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 'uint32_t' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 'type' : 'unsigned long',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 'format' : 'k',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 'uint64_t' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 'type' : 'unsigned long long',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 'format' : 'K',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 },
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 'float' : {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 'type' : 'float',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 'format' : 'f',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 def GenerateFunctionBodyTemplate(cFunction, result_type, args):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 if not cFunction.startswith('OrthancPlugin'):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 raise Exception()
140
b6835b7a7c0a code generation on Ubuntu 22.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 138
diff changeset
281
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 func = {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 'c_function' : cFunction,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 'short_name' : cFunction[len('OrthancPlugin'):],
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 'args' : [],
140
b6835b7a7c0a code generation on Ubuntu 22.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 138
diff changeset
286 'return_sdk_type' : result_type.spelling,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 if IsIntegerType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 func['return_long'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 elif IsTargetDynamicStringType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 func['return_dynamic_string'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 elif IsTargetStaticStringType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 func['return_static_string'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 elif IsVoidType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 func['return_void'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 elif result_type.spelling == 'OrthancPluginErrorCode':
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 func['return_error'] = True
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
299 func['return_sdk_type'] = 'enumeration'
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
300 func['return_sdk_enumeration'] = result_type.spelling
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 elif IsClassType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 func['return_object'] = result_type.get_pointee().spelling
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
303 func['return_sdk_type'] = 'object'
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
304 func['return_sdk_class'] = result_type.get_pointee().spelling
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 elif IsTargetMemoryBufferType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 func['return_bytes'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 elif IsEnumerationType(result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 func['return_enumeration'] = result_type.spelling
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
309 func['return_sdk_type'] = 'enumeration'
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
310 func['return_sdk_enumeration'] = result_type.spelling
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 raise Exception('Not supported: %s' % result_type.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 i = 0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 while i < len(args):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 a = {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 'name' : 'arg%d' % i,
140
b6835b7a7c0a code generation on Ubuntu 22.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 138
diff changeset
318 'sdk_type' : args[i].type.spelling,
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
319 'sdk_name' : args[i].spelling,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 if (IsIntegerType(args[i].type) or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 IsFloatType(args[i].type)):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 t = ORTHANC_TO_PYTHON_NUMERIC_TYPES[args[i].type.spelling]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 a['python_type'] = t['type']
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 a['python_format'] = t['format']
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 a['initialization'] = ' = 0'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 a['orthanc_cast'] = 'arg%d' % i
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 func['args'].append(a)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 elif IsSourceStringType(args[i].type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 a['python_type'] = 'const char*'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 a['python_format'] = 's'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 a['initialization'] = ' = NULL'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 a['orthanc_cast'] = 'arg%d' % i
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 func['args'].append(a)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 elif IsEnumerationType(args[i].type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 a['python_type'] = 'long int'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 a['python_format'] = 'l'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 a['initialization'] = ' = 0'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 a['orthanc_cast'] = 'static_cast<%s>(arg%d)' % (args[i].type.spelling, i)
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
341 a['sdk_type'] = 'enumeration'
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
342 a['sdk_enumeration'] = args[i].type.spelling
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 func['args'].append(a)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 elif IsBytesArgument(args, i):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 a['python_type'] = 'Py_buffer'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 # In theory, one should use "y*" (this is the recommended
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 # way to accept binary data). However, this is not
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 # available in Python 2.7
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 a['python_format'] = 's*'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 a['orthanc_cast'] = 'arg%d.buf, arg%d.len' % (i, i)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 a['release'] = 'PyBuffer_Release(&arg%d);' % i
141
3867cb23991d added information in the code model
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
352 a['sdk_type'] = 'const_void_pointer_with_size'
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 func['args'].append(a)
140
b6835b7a7c0a code generation on Ubuntu 22.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 138
diff changeset
354 i += 1 # Skip the size argument
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 elif IsSourceMemoryBufferType(args[i].type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 a['python_type'] = 'Py_buffer'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 a['python_format'] = 's*'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 a['orthanc_cast'] = 'arg%d.buf' % i
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 a['release'] = 'PyBuffer_Release(&arg%d);' % i
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 func['args'].append(a)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 raise Exception('Not supported: %s, %s' % (cFunction, args[i].spelling))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 i += 1
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 func['tuple_format'] = '"%s", %s' % (
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 ''.join(map(lambda x: x['python_format'], func['args'])),
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 ', '.join(map(lambda x: '&' + x['name'], func['args'])))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 if len(func['args']) > 0:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 func['count_args'] = len(func['args'])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 func['has_args'] = True
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 func['call_args'] = ', ' + ', '.join(map(lambda x: x['orthanc_cast'], func['args']))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 return func
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 for node in tu.cursor.get_children():
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 if node.kind == clang.cindex.CursorKind.ENUM_DECL:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 if node.type.spelling.startswith('OrthancPlugin'):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 name = node.type.spelling
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 values = []
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 for item in node.get_children():
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 if (item.kind == clang.cindex.CursorKind.ENUM_CONSTANT_DECL and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 item.spelling.startswith(name + '_')):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 values.append({
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 'key' : ToUpperCase(item.spelling[len(name)+1:]),
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 'value' : item.enum_value
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 })
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 path = 'sdk_%s.impl.h' % name
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 shortName = name[len('OrthancPlugin'):]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 with open(os.path.join(TARGET, path), 'w') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 f.write(pystache.render(TEMPLATE, {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 'name' : name,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 'short_name' : shortName,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 'values' : values,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 enumerations[name] = {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 'name' : name,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 'path' : path,
138
3e89d1c4f721 export the code model as json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
405 'values' : values,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 elif node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 if node.spelling.startswith('OrthancPlugin'):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 #if node.spelling != 'OrthancPluginWorklistGetDicomQuery':
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 # continue
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 shortName = node.spelling[len('OrthancPlugin'):]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 # Check that the first argument is the Orthanc context
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 args = list(filter(lambda x: x.kind == clang.cindex.CursorKind.PARM_DECL,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 node.get_children()))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 if (len(args) == 0 or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 args[0].type.kind != clang.cindex.TypeKind.POINTER or
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 args[0].type.get_pointee().spelling != 'OrthancPluginContext'):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 print('Not in the Orthanc SDK: %s()' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 continue
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 # Discard the context from the arguments
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
425 countAllFunctions += 1
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 args = args[1:]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
65
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
428 if node.spelling in CUSTOM_FUNCTIONS:
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
429 print('Ignoring custom function that is manually implemented: %s()' % node.spelling)
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
430 countSupportedFunctions += 1
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
431
4da5ce3468b4 new wrapped functions: CreateImageFromBuffer(), DicomInstance.GetInstanceData() and Image.GetImageBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 64
diff changeset
432 elif not IsSupportedTargetType(node.result_type):
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 print('*** UNSUPPORTED OUTPUT: %s' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 elif (len(args) == 1 and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 IsClassType(args[0].type) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 node.spelling.startswith('OrthancPluginFree')):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 print('Destructor: %s' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 className = args[0].type.get_pointee().spelling
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 classes[className]['destructor'] = node.spelling
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
441 countSupportedFunctions += 1
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 elif CheckOnlySupportedArguments(args):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 if IsClassType(node.result_type):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 print('Constructor: %s' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 print('Simple global function: %s => %s' % (node.spelling, node.result_type.spelling))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 body = GenerateFunctionBodyTemplate(node.spelling, node.result_type, args)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 globalFunctions.append(body)
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
451 countSupportedFunctions += 1
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 elif (len(args) >= 2 and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 IsTargetMemoryBufferType(args[0].type) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 CheckOnlySupportedArguments(args[1:])):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 print('Simple global function, returning bytes: %s' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 body = GenerateFunctionBodyTemplate(node.spelling, args[0].type, args[1:])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 globalFunctions.append(body)
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
460 countSupportedFunctions += 1
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 elif (IsClassType(args[0].type) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 CheckOnlySupportedArguments(args[1:])):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 className = args[0].type.get_pointee().spelling
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
466 print('Simple method of class %s: %s' % (className, node.spelling))
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
467 if node.spelling in CUSTOM_FUNCTIONS:
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
468 raise Exception('Cannot overwrite an autogenerated method: %s()' % node.spelling)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
469
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 if className.startswith('const '):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 className = className[len('const '):]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 method = GenerateFunctionBodyTemplate(node.spelling, node.result_type, args[1:])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 method['self'] = ', self->object_'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 classes[className]['methods'].append(method)
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
476 countSupportedFunctions += 1
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 elif (len(args) >= 2 and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 IsTargetMemoryBufferType(args[0].type) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 IsClassType(args[1].type) and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 CheckOnlySupportedArguments(args[2:])):
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
482 className = args[1].type.get_pointee().spelling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
483
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
484 print('Simple method of class %s, returning bytes: %s' % (className, node.spelling))
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
485 if node.spelling in CUSTOM_FUNCTIONS:
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
486 raise Exception('Cannot overwrite an autogenerated method: %s()' % node.spelling)
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
487
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
488 if className.startswith('const '):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
489 className = className[len('const '):]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
490
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 method = GenerateFunctionBodyTemplate(node.spelling, args[0].type, args[2:])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 method['self'] = ', self->object_'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 classes[className]['methods'].append(method)
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
494 countSupportedFunctions += 1
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
495
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 else:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 print('*** UNSUPPORTED INPUT: %s' % node.spelling)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 elif node.kind == clang.cindex.CursorKind.STRUCT_DECL:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 if (node.spelling.startswith('_OrthancPlugin') and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 node.spelling.endswith('_t') and
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 node.spelling != '_OrthancPluginContext_t'):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 name = node.spelling[len('_') : -len('_t')]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 classes[name] = {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 'class_name' : name,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 'short_name' : name[len('OrthancPlugin'):],
63
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
509 'methods' : [ ],
32de70a1e4c7 New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
510 'custom_methods' : [ ],
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 partials = {}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 with open(os.path.join(ROOT, 'FunctionBody.mustache'), 'r') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 partials['function_body'] = f.read()
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 renderer = pystache.Renderer(
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 escape = lambda u: u, # No escaping
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 partials = partials,
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 )
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 with open(os.path.join(ROOT, 'Class.mustache'), 'r') as f:
129
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
527 with open(os.path.join(ROOT, 'ClassMethods.mustache'), 'r') as g:
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
528 classDefinition = f.read()
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
529 classMethods = g.read()
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530
129
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
531 for method in CUSTOM_METHODS:
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
532 classes[method['class_name']]['custom_methods'].append(method)
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
533
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
534 for (key, value) in classes.items():
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
535 with open(os.path.join(TARGET, 'sdk_%s.impl.h' % value['class_name']), 'w') as h:
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
536 h.write(renderer.render(classDefinition, value))
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
537 with open(os.path.join(TARGET, 'sdk_%s.methods.h' % value['class_name']), 'w') as h:
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
538 h.write(renderer.render(classMethods, value))
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 def FlattenDictionary(source):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 result = []
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 for (key, value) in source.items():
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 result.append(value)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 return result
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
129
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
547
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
548 sortedClasses = sorted(FlattenDictionary(classes), key = lambda x: x['class_name'])
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
549 sortedEnumerations = sorted(FlattenDictionary(enumerations), key = lambda x: x['name'])
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
550 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function'])
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
551
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 h.write(renderer.render(f.read(), {
170
b49eeb36cd0d removed generation of code model, now part of orthanc-java
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
555 'global_functions' : sortedGlobalFunctions,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 h.write(renderer.render(f.read(), {
129
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
561 'classes' : sortedClasses,
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
562 'enumerations' : sortedEnumerations,
170
b49eeb36cd0d removed generation of code model, now part of orthanc-java
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
563 'global_functions' : sortedGlobalFunctions,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 }))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 h.write(renderer.render(f.read(), {
129
5643e97d9367 reproducible code generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
569 'classes' : sortedClasses,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 }))
2
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
571
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
572
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
573 print('')
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
574 print('Total functions in the SDK: %d' % countAllFunctions)
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
575 print('Total supported functions: %d' % countSupportedFunctions)
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
576 print('Coverage: %.0f%%' % (float(countSupportedFunctions) /
df7b4f8a0437 coverage statistics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
577 float(countAllFunctions) * 100.0))