4 import libcxx
.header_information
11 def IWYU_mapping(header
: str) -> typing
.Optional
[typing
.List
[str]]:
18 "__utility/private_constructor_tag.h",
20 if any(re
.match(pattern
, header
) for pattern
in ignore
):
22 elif header
== "__bits":
24 elif header
in ("__bit_reference", "__fwd/bit_reference.h"):
25 return ["bitset", "vector"]
26 elif re
.match("__configuration/.+", header
) or header
== "__config":
28 elif header
== "__hash_table":
29 return ["unordered_map", "unordered_set"]
30 elif header
== "__locale":
32 elif re
.match("__locale_dir/.+", header
):
34 elif re
.match("__math/.+", header
):
36 elif header
== "__node_handle":
37 return ["map", "set", "unordered_map", "unordered_set"]
38 elif header
== "__split_buffer":
39 return ["deque", "vector"]
40 elif re
.match("(__thread/support[.]h)|(__thread/support/.+)", header
):
41 return ["atomic", "mutex", "semaphore", "thread"]
42 elif header
== "__tree":
44 elif header
== "__fwd/byte.h":
46 elif header
== "__fwd/pair.h":
48 elif header
== "__fwd/subrange.h":
50 elif re
.match("__fwd/(fstream|ios|istream|ostream|sstream|streambuf)[.]h", header
):
52 # Handle remaining forward declaration headers
53 elif re
.match("__fwd/(.+)[.]h", header
):
54 return [re
.match("__fwd/(.+)[.]h", header
).group(1)]
55 # Handle detail headers for things like <__algorithm/foo.h>
56 elif re
.match("__(.+?)/.+", header
):
57 return [re
.match("__(.+?)/.+", header
).group(1)]
62 def main(argv
: typing
.List
[str]):
63 parser
= argparse
.ArgumentParser()
66 help="File to output the IWYU mappings into",
67 type=argparse
.FileType("w"),
71 args
= parser
.parse_args(argv
)
73 mappings
= [] # Pairs of (header, public_header)
74 for header
in libcxx
.header_information
.all_headers
:
75 public_headers
= IWYU_mapping(str(header
))
76 if public_headers
is not None:
77 mappings
.extend((header
, public
) for public
in public_headers
)
79 # Validate that we only have valid public header names -- otherwise the mapping above
80 # needs to be updated.
81 for header
, public
in mappings
:
82 if public
not in libcxx
.header_information
.public_headers
:
83 raise RuntimeError(f
"{header}: Header {public} is not a valid header")
85 args
.output
.write("[\n")
86 for header
, public
in sorted(mappings
):
88 f
' {{ include: [ "<{header}>", "private", "<{public}>", "public" ] }},\n'
90 args
.output
.write("]\n")
92 if __name__
== "__main__":