diff --git a/gcc.libc.imp b/gcc.libc.imp index 9d175df..d6a7e69 100644 --- a/gcc.libc.imp +++ b/gcc.libc.imp @@ -198,40 +198,4 @@ { include: [ "", private, "", public ] }, # PATH_MAX { include: [ "", private, "", public ] }, { include: [ "", private, "", public ] }, - # Allow the C++ wrappers around C files. Without these mappings, - # if you #include , iwyu will tell you to replace it with - # , which is where the symbols are actually defined. We - # inhibit that behavior to keep the alone. Note this is a - # public-to-public mapping: we don't want to *replace* - # with , we just want to avoid suggesting changing - # back to . (If you *did* want to replace - # assert.h with cassert, you'd change it to a public->private - # mapping.) Here is how I identified the files to map: - # $ for i in /usr/include/c++/4.4/c* ; do ls /usr/include/`basename $i | cut -b2-`.h /usr/lib/gcc/*/4.4/include/`basename $i | cut -b2-`.h 2>/dev/null ; done - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, - { include: [ "", public, "", public ] }, ] diff --git a/iwyu.gcc.imp b/iwyu.gcc.imp index 6c17093..2889e77 100644 --- a/iwyu.gcc.imp +++ b/iwyu.gcc.imp @@ -3,5 +3,6 @@ { ref: gcc.libc.imp }, { ref: gcc.symbols.imp }, { ref: gcc.stl.headers.imp }, + { ref: stl.c.headers.imp }, { ref: third_party.imp } ] diff --git a/iwyu_include_picker.cc b/iwyu_include_picker.cc index 0c4da30..f2366d7 100644 --- a/iwyu_include_picker.cc +++ b/iwyu_include_picker.cc @@ -429,6 +429,9 @@ const IncludeMapEntry libc_include_map[] = { { "", kPrivate, "", kPublic }, // PATH_MAX { "", kPrivate, "", kPublic }, { "", kPrivate, "", kPublic }, +}; + +const IncludeMapEntry stdlib_c_include_map[] = { // Allow the C++ wrappers around C files. Without these mappings, // if you #include , iwyu will tell you to replace it with // , which is where the symbols are actually defined. We @@ -439,6 +442,10 @@ const IncludeMapEntry libc_include_map[] = { // assert.h with cassert, you'd change it to a public->private // mapping.) Here is how I identified the files to map: // $ for i in /usr/include/c++/4.4/c* ; do ls /usr/include/`basename $i | cut -b2-`.h /usr/lib/gcc/*/4.4/include/`basename $i | cut -b2-`.h 2>/dev/null ; done + // + // These headers are defined in C++14 [headers]p3. You can get them with + // $ sed -n '/begin{floattable}.*{tab:cpp.c.headers}/,/end{floattable}/p' lib-intro.tex | grep tcode | perl -nle 'm/tcode{}/ && print qq@ { "<$1.h>", kPublic, "", kPublic },@' | sort + // on https://github.com/cplusplus/draft/blob/master/source/lib-intro.tex { "", kPublic, "", kPublic }, { "", kPublic, "", kPublic }, { "", kPublic, "", kPublic }, @@ -467,6 +474,65 @@ const IncludeMapEntry libc_include_map[] = { { "", kPublic, "", kPublic }, }; +const char* stdlib_cpp_public_headers[] = { + // These headers are defined in C++14 [headers]p2. You can get them with + // $ sed -n '/begin{floattable}.*{tab:cpp.library.headers}/,/end{floattable}/p' lib-intro.tex | grep tcode | perl -nle 'm/tcode{(.*)}/ && print qq@ "$1",@' | sort + // on https://github.com/cplusplus/draft/blob/master/source/lib-intro.tex + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", +}; + // Private -> public include mappings for GNU libstdc++ const IncludeMapEntry libstdcpp_include_map[] = { // ( cd /usr/crosstool/v12/gcc-4.3.1-glibc-2.3.6-grte/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/4.3.1 && grep '^ *# *include' {ext/,tr1/,}* | perl -nle 'm/^([^:]+).*<([^>]+)>/ && print qq@ { "<$2>", kPrivate, "<$1>", kPublic },@' | grep -e bits/ -e tr1_impl/ | sort -u) @@ -890,8 +956,13 @@ void IncludePicker::AddDefaultMappings() { AddIncludeMappings(libc_include_map, IWYU_ARRAYSIZE(libc_include_map)); + AddIncludeMappings(stdlib_c_include_map, + IWYU_ARRAYSIZE(stdlib_c_include_map)); AddIncludeMappings(libstdcpp_include_map, IWYU_ARRAYSIZE(libstdcpp_include_map)); + + AddPublicIncludes(stdlib_cpp_public_headers, + IWYU_ARRAYSIZE(stdlib_cpp_public_headers)); } void IncludePicker::MarkVisibility( @@ -1005,6 +1076,13 @@ void IncludePicker::AddSymbolMappings(const IncludeMapEntry* entries, } } +void IncludePicker::AddPublicIncludes(const char** includes, size_t count) { + for (size_t i = 0; i < count; ++i) { + const char* include = includes[i]; + MarkVisibility(include, kPublic); + } +} + void IncludePicker::MarkIncludeAsPrivate( const string& quoted_filepath_pattern) { CHECK_(!has_called_finalize_added_include_lines_ && "Can't mutate anymore"); diff --git a/iwyu_include_picker.h b/iwyu_include_picker.h index df86c70..ed40a16 100644 --- a/iwyu_include_picker.h +++ b/iwyu_include_picker.h @@ -173,6 +173,8 @@ class IncludePicker { void AddIncludeMappings(const IncludeMapEntry* entries, size_t count); void AddSymbolMappings(const IncludeMapEntry* entries, size_t count); + void AddPublicIncludes(const char** includes, size_t count); + // Expands the regex keys in filepath_include_map_ and // friend_to_headers_map_ by matching them against all source files // seen by iwyu. diff --git a/stl.c.headers.imp b/stl.c.headers.imp new file mode 100644 index 0000000..59a238d --- /dev/null +++ b/stl.c.headers.imp @@ -0,0 +1,42 @@ +[ + # Allow the C++ wrappers around C files. Without these mappings, + # if you #include , iwyu will tell you to replace it with + # , which is where the symbols are actually defined. We + # inhibit that behavior to keep the alone. Note this is a + # public-to-public mapping: we don't want to *replace* + # with , we just want to avoid suggesting changing + # back to . (If you *did* want to replace + # assert.h with cassert, you'd change it to a public->private + # mapping.) Here is how I identified the files to map: + # $ for i in /usr/include/c++/4.4/c* ; do ls /usr/include/`basename $i | cut -b2-`.h /usr/lib/gcc/*/4.4/include/`basename $i | cut -b2-`.h 2>/dev/null ; done + # + # These headers are defined in C++14 [headers]p3. You can get them with + # $ sed -n '/begin{floattable}.*{tab:cpp.c.headers}/,/end{floattable}/p' lib-intro.tex | grep tcode | perl -nle 'm/tcode{}/ && print qq@ { include: [ "<$1.h>", public, "", public ] },@' | sort + # on https://github.com/cplusplus/draft/blob/master/source/lib-intro.tex + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, + { include: [ "", public, "", public ] }, +]