4 import libcxx
.header_information
11 def IWYU_mapping(header
: str) -> typing
.Optional
[typing
.List
[str]]:
17 "__utility/private_constructor_tag.h",
19 if any(re
.match(pattern
, header
) for pattern
in ignore
):
21 elif header
== "__bits":
23 elif header
in ("__bit_reference", "__fwd/bit_reference.h"):
24 return ["bitset", "vector"]
25 elif re
.match("__configuration/.+", header
) or header
== "__config":
27 elif header
== "__hash_table":
28 return ["unordered_map", "unordered_set"]
29 elif header
== "__locale":
31 elif re
.match("__locale_dir/.+", header
):
33 elif re
.match("__math/.+", header
):
35 elif header
== "__node_handle":
36 return ["map", "set", "unordered_map", "unordered_set"]
37 elif header
== "__split_buffer":
38 return ["deque", "vector"]
39 elif re
.match("(__thread/support[.]h)|(__thread/support/.+)", header
):
40 return ["atomic", "mutex", "semaphore", "thread"]
41 elif header
== "__tree":
43 elif header
== "__fwd/pair.h":
45 elif header
== "__fwd/subrange.h":
47 elif re
.match("__fwd/(fstream|ios|istream|ostream|sstream|streambuf)[.]h", header
):
49 # Handle remaining forward declaration headers
50 elif re
.match("__fwd/(.+)[.]h", header
):
51 return [re
.match("__fwd/(.+)[.]h", header
).group(1)]
52 # Handle detail headers for things like <__algorithm/foo.h>
53 elif re
.match("__(.+?)/.+", header
):
54 return [re
.match("__(.+?)/.+", header
).group(1)]
59 def main(argv
: typing
.List
[str]):
60 parser
= argparse
.ArgumentParser()
63 help="File to output the IWYU mappings into",
64 type=argparse
.FileType("w"),
68 args
= parser
.parse_args(argv
)
70 mappings
= [] # Pairs of (header, public_header)
71 for header
in libcxx
.header_information
.all_headers
:
72 public_headers
= IWYU_mapping(header
)
73 if public_headers
is not None:
74 mappings
.extend((header
, public
) for public
in public_headers
)
76 # Validate that we only have valid public header names -- otherwise the mapping above
77 # needs to be updated.
78 for header
, public
in mappings
:
79 if public
not in libcxx
.header_information
.public_headers
:
80 raise RuntimeError(f
"{header}: Header {public} is not a valid header")
82 args
.output
.write("[\n")
83 for header
, public
in sorted(mappings
):
85 f
' {{ include: [ "<{header}>", "private", "<{public}>", "public" ] }},\n'
87 args
.output
.write("]\n")
89 if __name__
== "__main__":