3 # Copyright (C) 2022-2023 Free Software Foundation, Inc.
4 # This file is part of GCC.
6 # GCC is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GCC is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GCC; see the file COPYING3. If not see
18 # <http://www.gnu.org/licenses/>.
21 # Generate gcc source files:
22 # - the export description of the standard C++ library module
23 # - the gperf tables used to hint at actions to fix problems
24 # related to missing symbols in the std:: namespace
30 # The CSV file contains the following columns:
32 # 1 header file, including angle brackets
33 # 2 symbol name without std:: prefix
34 # 3 nonzero if to be exported
35 # 4 "no" if not to be added to the hint table else the appropriate enum cxx_dialect value
36 # 5 optional, a string used after #if in a line inserted first to enable conditional definitions
39 def print_condition(prev
, e
):
40 if len(e
) > 4 and e
[4] != '':
41 if not prev
or prev
!= e
[4]:
51 def export(script
, content
):
52 print("""// This file is auto-generated by {:s}.
53 #if __cplusplus <= 202002L
54 # if __cplusplus == 202002L
55 # ifdef __STRICT_ANSI__
56 # error "module `std' is only available before C++23 if using -std=gnu++20"
59 # error "module `std' is not available before C++23"
65 import <bits/stdc++.h>;
67 // new/delete operators in global namespace from <new>
68 export using ::operator new;
69 export using ::operator delete;
70 export using ::operator new[];
71 export using ::operator delete[];""".format(script
))
73 printed_header
= False
78 printed_header
= False
80 if not printed_header
:
84 print(f
'\n// {header}')
86 cond
= print_condition(cond
, e
)
87 print(f
'export using std::{e[1]};')
92 def hints(script
, content
):
93 print("""%language=C++
94 %define class-name std_name_hint_lookup
97 /* This file is auto-generated by {:s}. */
98 /* Copyright (C) {:s} Free Software Foundation, Inc.
100 This file is part of GCC.
102 GCC is free software; you can redistribute it and/or modify it under
103 the terms of the GNU General Public License as published by the Free
104 Software Foundation; either version 3, or (at your option) any later
107 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
108 WARRANTY; without even the implied warranty of MERCHANTABILITY or
109 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
112 You should have received a copy of the GNU General Public License
113 along with GCC; see the file COPYING3. If not see
114 <http://www.gnu.org/licenses/>. */
118 /* A name within "std::". */
121 /* The header name defining it within the C++ Standard Library
122 (with '<' and '>'). */
125 /* The dialect of C++ in which this was added. */
126 enum cxx_dialect min_dialect;
129 # The standard-defined types, functions, and options in the std:: namespace
130 # as defined in the C++ language specification. The result is used in the
131 # get_std_name_hint functions.
132 # throws an exception.
133 #""".format(script
, time
.strftime('%Y')))
135 printed_header
= False
139 printed_header
= False
141 if not printed_header
:
143 printed_header
= True
144 print(f
'{e[1]}, "{e[0]}", {e[3]}')
147 def remove_comment(f
):
161 print(f
'Usage: {script} [{"|".join(modes.keys())}] CSVFILE')
167 usage(argv
[0] if len(argv
) > 0 else '???')
173 if mode
not in modes
:
174 print(f
"{script}: unrecognized mode '{mode}'")
178 with
open(filename
, 'r') as csvfile
:
179 modes
[mode
](os
.path
.basename(script
), sorted(csv
.reader(remove_comment(csvfile
), delimiter
=',')))
180 except FileNotFoundError
:
181 print(f
"{script}: cannot find CSV file '{filename}'")
183 except PermissionError
:
184 print(f
"{script}: insufficient permission to read CSV file '{filename}'")
188 if __name__
== '__main__':