iuwandbox_pp   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 157
dl 0
loc 189
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A WandboxPreprocessor.preprocess() 0 3 1
A WandboxPreprocessor.remove_empty_ppif() 0 2 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A main() 0 7 3
A default_pp() 0 12 1
1
#!/usr/bin/env python
2
#
3
# iuwandbox_pp.py
4
#
5
# Copyright (C) 2018, Takazumi Shirayanagi
6
# This software is released under the new BSD License,
7
# see LICENSE
8
#
9
10
import os
11
import sys
12
import codecs
13
from iutest_pp_strip import IutestPreprocessor
14
15
predefined_macros = {
16
    '__WANDBOX__': '1',
17
    'NULL': '0',
18
    'IUTEST_USE_GTEST': None,
19
    'IUTEST_BUILD_DOXYGEN': None,
20
    '_IUTEST_DEBUG': None,
21
    '__CYGWIN__': None,
22
    'IUTEST_OS_CYGWIN': None,
23
    '__MINGW__': None,
24
    '__MINGW32__': None,
25
    '__MINGW64__': None,
26
    '__arm__': None,
27
    'IUTEST_OS_ARM': None,
28
    '__ARMCC_VERSION': None,
29
    '__AVR32__': None,
30
    '__avr32__': None,
31
    'IUTEST_OS_AVR32': None,
32
    'ANDROID': None,
33
    '__ANDROID__': None,
34
    'IUTEST_OS_LINUX_ANDROID': None,
35
    '__APPLE__': None,
36
    'IUTEST_OS_IOS': None,
37
    'IUTEST_OS_MAC': None,
38
    '__INTEL_COMPILER': None,
39
    '__BORLANDC__': None,
40
    '__CUDACC__': None,
41
    '__IBMCPP__': None,
42
    'COMPILER_ICC': None,
43
    '_MSC_VER': None,
44
    '_MSC_FULL_VER': None,
45
    '_WIN32': None,
46
    'WIN32': None,
47
    '__WIN32__': None,
48
    'WINAPI_FAMILY': None,
49
    '__AFX_H__': None,
50
    '__MWERKS__': None,
51
    'IUTEST_OS_WINDOWS': None,
52
    'IUTEST_OS_WINDOWS_MINGW': None,
53
    'IUTEST_OS_WINDOWS_MOBILE': None,
54
    'IUTEST_OS_WINDOWS_PHONE': None,
55
    'IUTEST_OS_WINDOWS_RT': None,
56
    'IUTEST_OS_WINDOWS_WINE': None,
57
    'IUTEST_NO_UTIL_ASSERTION_GTEST_COMPATIBLE': '1',
58
    'IUTEST_NO_TWO_PHASE_NAME_LOOKUP': None,
59
    'IUTEST_NO_FUNCTION_TEMPLATE_ORDERING': None,
60
    'IUTEST_NO_INCLASS_MEMBER_INITIALIZATION': None,
61
    'IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS': None,
62
    'IUTEST_NO_SFINAE': None,
63
    'IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION': None,
64
    'IUTEST_NO_TEMPLATE_TEMPLATES': None,
65
    'IUTEST_NO_VOID_RETURNS': None,
66
    'IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP': None,
67
    'IUTEST_NO_PRIVATE_IN_AGGREGATE': None,
68
    'IUTEST_NO_VARIADIC_MACROS': None,
69
    'IUTEST_NO_UNITEST_AD_HOC_TEST_RESULT_ACCESSOR': None,
70
    'IUTEST_NO_TESTCASE_AD_HOC_TEST_RESULT_ACCESSOR': None,
71
    'IUTEST_NO_LAMBDA_SCOPE_RESOLUTION': None,
72
    'IUTEST_NO_GETENV': None,
73
    'IUTEST_NO_PUTENV': None,
74
    'IUTEST_NO_SETENV': None,
75
    'IUTEST_NO_GETCWD': None,
76
    'IUTEST_NOT_SUPPORT_STOPWATCH': None,
77
    'IUTEST_HAS_WANT_SECURE_LIB': '0',
78
    'IUTEST_HAS_MS_EXTENSIONS': '0',
79
    'IUTEST_HAS_MS_CXX_MODULE': '0',
80
    'MS_CPP_UNITTESTFRAMEWORK': None,
81
    'IUTEST_EXPLICIT_INSTANTIATION_ACCESS_PRIVATE_MEMBER_FUNCTION': '1',
82
    'IUTEST_EXPLICIT_INSTANTIATION_ACCESS_PRIVATE_STATIC_MEMBER_FUNCTION': '1',
83
    '__native_client__': None,
84
    'IUTEST_OS_NACL': None,
85
    'IUTEST_HAS_INVALID_PARAMETER_HANDLER': '0',
86
}
87
88
iutest_config_macro = {
89
    'IUTEST_HAS_LIB': '0',
90
    'IUTEST_HAS_TESTNAME_ALIAS_JP': '0',
91
    'IUTEST_HAS_IF_EXISTS': '0',
92
    'IUTEST_HAS_ANALYSIS_ASSUME': '0',
93
    'IUTEST_HAS_IGNORE_TEST': '0',
94
    'IUTEST_HAS_MINIDUMP': '0',
95
    'IUTEST_HAS_STRSTREAM': '0',
96
    'IUTEST_HAS_STRINGSTREAM': '1',
97
    'IUTEST_HAS_CLASS_MEMBER_TEMPLATE_SPECIALIZATION': '0',
98
    'IUTEST_HAS_GENERIC': '0',
99
    'IUTEST_HAS_MEMORY_SANITIZER': '0',
100
    'IUTEST_HAS_ADDRESS_SANITIZER': '0',
101
    'IUTEST_HAS_THREAD_SANITIZER': '0',
102
    'IUTEST_HAS_SEH': '0',
103
    'IUTEST_USE_OWN_LIST': '0',
104
}
105
106
expands_macros = [
107
    'IUTEST_IPP_INLINE',
108
    'IUTEST_ATTRIBUTE_DEPRECATED_',
109
    'IUTEST_ATTRIBUTE_PURE_',
110
    'IUTEST_ATTRIBUTE_INIT_PRIORITY_',
111
    'IUTEST_HAS_ATTRIBUTE_DEPRECATED',
112
    'IUTEST_CXX_MODULE_EXPORT',
113
    'IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY',
114
    'IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS',
115
    'IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD',
116
    'IUTEST_ATTRIBUTE_NO_SANITIZE_ALL',
117
]
118
119
# expand function macros
120
expand_function_macros = [
121
    'IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN',
122
    'IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END',
123
    'IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_BEGIN',
124
    'IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_END',
125
    'IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_BEGIN',
126
    'IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_END',
127
    'IUTEST_PRAGMA_MSC_WARN_PUSH',
128
    'IUTEST_PRAGMA_MSC_WARN_DISABLE',
129
    'IUTEST_PRAGMA_MSC_WARN_POP',
130
    'IUTEST_WORKAROUND_MSC_STLSTREAM_C4250',
131
    'IUTEST_EXPLICIT_TEMPLATE_TYPE_',
132
    'IUTEST_IF_EXISTS',
133
    'IUTEST_IF_NOT_EXISTS',
134
    'IUTEST_STATIC_EXISTS',
135
    'IUTEST_STATIC_ASSERT_IF_EXISTS',
136
    'IUTEST_STATIC_ASSERT_IF_NOT_EXISTS',
137
    'IUTEST_ANALYSIS_ASSUME',
138
]
139
140
#
141
has_features = {
142
}
143
144
has_include = {
145
}
146
147
debug = False
148
149
class WandboxPreprocessor:
150
    pp = IutestPreprocessor(predefined_macros
151
        , iutest_config_macro
152
        , expand_function_macros
153
        , expands_macros
154
        , has_features
155
        , has_include)
156
157
    def preprocess(self, code, add_macros):
158
        self.pp.set_debug_flag(debug)
159
        return self.pp.preprocess(code, add_macros)
160
161
    def remove_empty_ppif(self, code):
162
        return self.pp.remove_empty_ppif(code)
163
164
165
def default_pp():
166
    output_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../fused-src")
167
    output = "iutest.wandbox.min.hpp"
168
    f = codecs.open(os.path.join(output_dir, "iutest.min.hpp"), 'r', 'utf-8-sig')
169
    code = f.read()
170
    f.close()
171
    output_file = codecs.open(os.path.join(output_dir, output), 'w', 'utf-8-sig')
172
    pp = WandboxPreprocessor()
173
    code = pp.preprocess(code, None)
174
    code = pp.remove_empty_ppif(code)
175
    output_file.write(code)
176
    output_file.close()
177
178
179
def main():
180
    global debug
181
    argc = len(sys.argv)
182
    if argc == 2:
183
        if sys.argv[1] == 'debug':
184
            debug = True
185
    default_pp()
186
187
if __name__ == '__main__':
188
    main()
189