annotate CodeAnalysis/ParseOrthancSDK.py @ 155:71d305c29cfa

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