Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update standard headers #248

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions scripts/extract_std_headers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/usr/bin/env python3

"""
Given a file containing the text of https://en.cppreference.com/w/cpp/header create a list of std headers
We are interested in the following headers:
C++ - https://en.cppreference.com/w/cpp/header
C - https://en.cppreference.com/w/c/header
POSIX C - https://en.wikipedia.org/wiki/C_POSIX_library

Go to each site and copy the content into a file. This file then reads the file and prints a list we can use in the
python file containing the standard header list for DWYU to lookup.
"""

import re
from pathlib import Path

INPUT_FILE = Path("content_of_cppreference.txt")

with INPUT_FILE.open(encoding="utf-8") as fin:
with Path("input.txt").open(encoding="utf-8") as fin:
headers = []
for line in fin.readlines():
include = re.findall("^<(.+)>$", line)
if len(include) == 1:
print(f'"{include[0]}",') # noqa: T201
headers.extend(re.findall(r"<([a-z/.]+)>", line))
print("\n".join(f'"{h}",' for h in sorted(set(headers)))) # noqa: T201
282 changes: 158 additions & 124 deletions src/analyze_includes/std_header.py
Original file line number Diff line number Diff line change
@@ -1,167 +1,201 @@
"""
List is based on https://en.cppreference.com/w/cpp/header.
The content of the website has been copied into a file (plain ctrl + c)
and then extract_std_headers.py has been executed on the file.
List is based on:
C++ - https://en.cppreference.com/w/cpp/header
C - https://en.cppreference.com/w/c/header
POSIX C - https://en.wikipedia.org/wiki/C_POSIX_library

The list is a superset of all headers, no matter in which standard they have been introduced
or if they are already removed. If you require a list tailored to a specific standard,
you have to define it yourself and provide it to the tool through the CLI.
The list is a superset of all headers, no matter in which standard they have been introduced or if they are already
removed. If you require a list tailored to a specific standard, you have to define it yourself and provide it to DWYU
via the 'ignored_includes' aspect option.
"""

# extracted 2022.01.03
# extracted 2024.05.03
STD_HEADER = {
# concepts
"concepts",
# coroutines
"coroutine",
# utilities - generic
"aio.h",
"algorithm",
"any",
"arpa/inet.h",
"array",
"assert.h",
"atomic",
"barrier",
"bit",
"bitset",
"cassert",
"ccomplex",
"cctype",
"cerrno",
"cfenv",
"cfloat",
"charconv",
"chrono",
"cinttypes",
"climits",
"clocale",
"cmath",
"codecvt",
"compare",
"complex",
"complex.h",
"concepts",
"coroutine",
"cpio.h",
"csetjmp",
"csignal",
"cstdalign",
"cstdarg",
"cstdatomic",
"cstdbool",
"cstddef",
"cstdlib",
"ctime",
"functional",
"initializer_list",
"optional",
"source_location",
"stacktrace",
"tuple",
"type_traits",
"typeindex",
"typeinfo",
"utility",
"variant",
"version",
# utilities - dynamic memory management
"memory",
"memory_resource",
"new",
"scoped_allocator",
# utilities - numeric limits
"cfloat",
"cinttypes",
"climits",
"cstdint",
"limits",
# utilities - error handling
"cassert",
"cerrno",
"exception",
"stdexcept",
"system_error",
# strings
"cctype",
"charconv",
"cstdio",
"cstdlib",
"cstring",
"ctgmath",
"ctime",
"ctype.h",
"cuchar",
"cwchar",
"cwctype",
"format",
"string",
"string_view",
# containers
"array",
"debugging",
"deque",
"forward_list",
"list",
"map",
"queue",
"set",
"span",
"stack",
"unordered_map",
"unordered_set",
"vector",
# iterators
"iterator",
# ranges
"ranges",
# algorithms
"algorithm",
"dirent.h",
"dlfcn.h",
"errno.h",
"exception",
"execution",
# numerics
"bit",
"cfenv",
"cmath",
"complex",
"numbers",
"numeric",
"random",
"ratio",
"valarray",
# localization
"clocale",
"codecvt",
"locale",
# input/output
"cstdio",
"expected",
"fcntl.h",
"fenv.h",
"filesystem",
"float.h",
"fmtmsg.h",
"fnmatch.h",
"format",
"fstream",
"ftw.h",
"functional",
"future",
"generator",
"glob.h",
"grp.h",
"iconv.h",
"inttypes.h",
"iomanip",
"ios",
"iosfwd",
"iostream",
"istream",
"ostream",
"spanstream",
"sstream",
"streambuf",
"strstream",
"syncstream",
# filesystem
"filesystem",
# regular expression
"regex",
# atomic operations
"atomic",
# thread support
"barrier",
"condition_variable",
"future",
"iterator",
"langinfo.h",
"latch",
"mutex",
"semaphore",
"shared_mutex",
"stop_token",
"thread",
# C compatibility headers
"assert.h",
"ctype.h",
"errno.h",
"fenv.h",
"float.h",
"inttypes.h",
"libgen.h",
"limits",
"limits.h",
"linalg",
"list",
"locale",
"locale.h",
"map",
"math.h",
"mdspan",
"memory",
"monetary.h",
"mqueue.h",
"mutex",
"ndbm.h",
"net/if.h",
"netdb.h",
"netinet/in.h",
"netinet/tcp.h",
"new",
"numbers",
"numeric",
"optional",
"ostream",
"poll.h",
"print",
"pthread.h",
"pwd.h",
"queue",
"random",
"ranges",
"ratio",
"rcu",
"regex",
"regex.h",
"sched.h",
"search.h",
"semaphore",
"semaphore.h",
"set",
"setjmp.h",
"signal.h",
"span",
"spanstream",
"spawn.h",
"sstream",
"stack",
"stacktrace",
"stdalign.h",
"stdarg.h",
"stdatomic.h",
"stdbit.h",
"stdbool.h",
"stdckdint.h",
"stddef.h",
"stdexcept",
"stdfloat",
"stdint.h",
"stdio.h",
"stdlib.h",
"stdnoreturn.h",
"streambuf",
"string",
"string.h",
"strings.h",
"stropts.h",
"strstream",
"syncstream",
"sys/ipc.h",
"sys/mman.h",
"sys/msg.h",
"sys/resource.h",
"sys/select.h",
"sys/sem.h",
"sys/shm.h",
"sys/socket.h",
"sys/stat.h",
"sys/statvfs.h",
"sys/time.h",
"sys/times.h",
"sys/types.h",
"sys/uio.h",
"sys/un.h",
"sys/utsname.h",
"sys/wait.h",
"syslog.h",
"tar.h",
"termios.h",
"tgmath.h",
"thread",
"threads.h",
"time.h",
"trace.h",
"tuple",
"typeindex",
"typeinfo",
"uchar.h",
"ulimit.h",
"unistd.h",
"utility",
"utime.h",
"utmpx.h",
"valarray",
"variant",
"vector",
"version",
"wchar.h",
"wctype.h",
# special C compatibility headers
"stdatomic.h",
# Empty C headers
"ccomplex",
"complex.h",
"ctgmath",
"tgmath.h",
# Meaningless C headers
"ciso646",
"cstdalign",
"cstdbool",
"iso646.h",
"stdalign.h",
"stdbool.h",
"wordexp.h",
}