43
43
44
44
found_includes = []
45
45
46
+ current_implementation = ''
46
47
47
48
def doinclude (fid , file , line ):
48
49
p = os .path .join (AMALGAMATE_INCLUDE_PATH , file )
@@ -75,12 +76,15 @@ def doinclude(fid, file, line):
75
76
76
77
77
78
def dofile (fid , prepath , filename ):
79
+ global current_implementation
78
80
# print(f"// dofile: invoked with prepath={prepath}, filename={filename}",file=fid)
79
81
file = os .path .join (prepath , filename )
80
82
RELFILE = os .path .relpath (file , PROJECTPATH )
81
83
# Last lines are always ignored. Files should end by an empty lines.
82
84
print (f"/* begin file { RELFILE } */" , file = fid )
83
85
includepattern = re .compile ('^#include "(.*)"' )
86
+ redefines_simdjson_implementation = re .compile ('^#define SIMDJSON_IMPLEMENTATION (.*)' )
87
+ uses_simdjson_implementation = re .compile ('SIMDJSON_IMPLEMENTATION([^_a-zA-Z0-9]|$)' )
84
88
with open (file , 'r' ) as fid2 :
85
89
for line in fid2 :
86
90
line = line .rstrip ('\n ' )
@@ -97,8 +101,14 @@ def dofile(fid, prepath, filename):
97
101
# we explicitly include simdjson headers, one time each (unless they are generic, in which case multiple times is fine)
98
102
doinclude (fid , includedfile , line )
99
103
else :
100
- # Otherwise we simply copy the line
101
- print (line , file = fid )
104
+ # does it contain a redefinition of SIMDJSON_IMPLEMENTATION ?
105
+ s = redefines_simdjson_implementation .search (line )
106
+ if s :
107
+ current_implementation = s .group (1 )
108
+ print (f"// redefining SIMDJSON_IMPLEMENTATION to \" { current_implementation } \" \n // { line } " , file = fid )
109
+ else :
110
+ # copy the line, with SIMDJSON_IMPLEMENTATION replace to what it is currently defined to
111
+ print (uses_simdjson_implementation .sub (current_implementation + "\\ 1" ,line ), file = fid )
102
112
print (f"/* end file { RELFILE } */" , file = fid )
103
113
104
114
0 commit comments