Skip to content

Commit 04157fc

Browse files
authored
Simplify C++ stdlib header matcher in include order task (#220)
1 parent 87b4947 commit 04157fc

File tree

1 file changed

+5
-122
lines changed

1 file changed

+5
-122
lines changed

wpiformat/wpiformat/includeorder.py

Lines changed: 5 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -72,127 +72,10 @@ def __init__(self):
7272
self.c_sys_regex = regex.compile(r"<[a-z][A-Za-z0-9/_-]*\.h>")
7373

7474
# Header type 2: C++ standard library headers
75-
# List from https://en.cppreference.com/w/cpp/header
76-
self.cpp_std = [
77-
# Concepts library
78-
"concepts",
79-
# Coroutines library
80-
"coroutine",
81-
# Utilities library
82-
"any",
83-
"bitset",
84-
"chrono",
85-
"compare",
86-
"csetjmp",
87-
"csignal",
88-
"cstdarg",
89-
"cstddef",
90-
"cstdlib",
91-
"ctime",
92-
"functional",
93-
"initializer_list",
94-
"optional",
95-
"source_location",
96-
"stacktrace",
97-
"tuple",
98-
"type_traits",
99-
"typeindex",
100-
"typeinfo",
101-
"utility",
102-
"variant",
103-
"version",
104-
# Dynamic memory management
105-
"memory",
106-
"memory_resource",
107-
"new",
108-
"scoped_allocator",
109-
# Numeric limits
110-
"cfloat",
111-
"cinttypes",
112-
"climits",
113-
"cstdint",
114-
"limits",
115-
# Error handling
116-
"cassert",
117-
"cerrno",
118-
"exception",
119-
"stdexcept",
120-
"system_error",
121-
# Strings library
122-
"cctype",
123-
"charconv",
124-
"cstring",
125-
"cuchar",
126-
"cwchar",
127-
"cwctype",
128-
"format",
129-
"string",
130-
"string_view",
131-
# Containers library
132-
"array",
133-
"deque",
134-
"forward_list",
135-
"list",
136-
"map",
137-
"queue",
138-
"set",
139-
"span",
140-
"stack",
141-
"unordered_map",
142-
"unordered_set",
143-
"vector",
144-
# Iterators library
145-
"iterator",
146-
# Ranges library
147-
"ranges",
148-
# Algorithms library
149-
"algorithm",
150-
"execution",
151-
# Numerics library
152-
"bit",
153-
"cfenv",
154-
"cmath",
155-
"complex",
156-
"numbers",
157-
"numeric",
158-
"random",
159-
"ratio",
160-
"valarray",
161-
# Localization library
162-
"clocale",
163-
"codecvt",
164-
"locale",
165-
# Input/output library
166-
"cstdio",
167-
"fstream",
168-
"iomanip",
169-
"ios",
170-
"iosfwd",
171-
"iostream",
172-
"istream",
173-
"ostream",
174-
"spanstream",
175-
"sstream",
176-
"streambuf",
177-
"strstream",
178-
"syncstream",
179-
# Filesystem library
180-
"filesystem",
181-
# Regular Expressions library
182-
"regex",
183-
# Atomic Operations library
184-
"atomic",
185-
# Thread support library
186-
"barrier",
187-
"condition_variable",
188-
"future",
189-
"latch",
190-
"mutex",
191-
"semaphore",
192-
"shared_mutex",
193-
"stop_token",
194-
"thread"
195-
]
75+
# With the exception of a few C standard library headers above, they are
76+
# the only headers which use only lowercase and underscores, and don't
77+
# have a ".h" suffix
78+
self.cpp_std_regex = regex.compile(r"(<|\")[a-z0-9_]+(>|\")")
19679

19780
# Header type 3: Other library headers
19881
# They use angle brackets (open_bracket group is angle bracket)
@@ -242,7 +125,7 @@ def classify_header(self, config_file, include_line, file_name):
242125
return 1
243126
elif self.c_sys_regex.search(include_line.group("header")):
244127
return 1
245-
elif include_line.group("name") in self.cpp_std:
128+
elif self.cpp_std_regex.search(include_line.group("header")):
246129
return 2
247130
elif include_line.group("open_bracket") == "<":
248131
return 3

0 commit comments

Comments
 (0)