-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert-msstl-files.rb
79 lines (71 loc) · 2.22 KB
/
convert-msstl-files.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'fileutils'
MSSTL = ARGV[0] || '../STL'
INC = File.join(MSSTL, 'stl', 'inc')
OUT = 'include/msstl/converted'
FileUtils.mkdir_p OUT
raise "#{MSSTL} is not recognized as clone of https://github.com/microsoft/STL" if !File.directory?(INC)
def comment_line(line)
'//~ ' + line
end
def convert_line(line)
ret = if line !~ /_chars\(/
line.gsub('unsigned long', 'ulong32')
else
line
end
ret.
gsub(/_STD|_CSTD/, 'std::').gsub('std:: to_chars', 'to_chars'). # we add std where needed but remove it from where its not needed
gsub('_NODISCARD', '[[nodiscard]]').
gsub('_NODISCARD_FRIEND', '[[nodiscard]] friend').
gsub('_STL_INTERNAL_STATIC_ASSERT', 'static_assert').
gsub('errc', 'std::errc').
gsub('_WIN64', 'MSCHARCONV_64_BIT').
gsub('_Adl_verify_range', 'MSCHARCONV_VERIFY_RANGE').
gsub('_STL_INTERNAL_CHECK', 'assert').
gsub('_STL_ASSERT', 'MSCHARCONV_ASSERT_MSG').
gsub('make_unsigned_t', 'std::make_unsigned_t').
gsub('is_signed_v', 'std::is_signed_v').
gsub('conditional_t', 'std::conditional_t').
gsub('is_same_v', 'std::is_same_v').
gsub('_Bit_cast', 'bit_cast').
gsub('__forceinline', 'MSCHARCONV_FORCE_INLINE').
gsub(' less{}', ' std::less{}').
gsub(' pair<', ' std::pair<').
gsub(/UL\b/, 'U')
end
def convert(filename)
out = ''
commenting_struct = false
File.readlines(File.join(INC, filename)).each do |line|
out += case line
when /^#pragma/, /^#include/, /^#undef/, /^_S/, /_STL_COMPILER_PREPROCESSOR/, /_BITMASK_OPS/
comment_line line
when /^#if !_HAS_CXX17/, /^#if _HAS_CXX20/
'#if 0 //~' + line
when /^#endif/, /^#else/
line
when /struct from_chars_result \{/
commenting_struct = true
comment_line line
when /\};/
if commenting_struct
commenting_struct = false
comment_line line
else
convert_line line
end
else
if commenting_struct
comment_line line
else
convert_line line
end
end
end
File.write(File.join(OUT, filename + '.inl'), out.encode(out.encoding, universal_newline: true))
end
convert('xbit_ops.h')
convert('xcharconv.h')
convert('xcharconv_ryu_tables.h')
convert('xcharconv_ryu.h')
convert('charconv')