Skip to content

Commit

Permalink
[libc++] Adds more forward declaration headers.
Browse files Browse the repository at this point in the history
The module validation script of D144994 validate whether the contents of
an include match its module. An include is the set of files matching the
pattern:
- foo
- foo/*.
- __fwd/foo.h

Several declarations of the stream headers are in the header iosfwd.
This gives issue using the validation script. Adding iosfwd to the set
of matching files gives too many declarations. For example when
validating the fstream header it will pull in declarations of the
istream header. Instead if writing a set of filters the headers are
granularized into smaller headers containing the expected declarations.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D148927
  • Loading branch information
mordante committed Apr 27, 2023
1 parent 77ac365 commit 9d16cbc
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 108 deletions.
6 changes: 6 additions & 0 deletions libcxx/include/CMakeLists.txt
Expand Up @@ -385,11 +385,17 @@ set(files
__functional/unwrap_ref.h
__functional/weak_result_type.h
__fwd/array.h
__fwd/fstream.h
__fwd/get.h
__fwd/hash.h
__fwd/ios.h
__fwd/istream.h
__fwd/memory_resource.h
__fwd/ostream.h
__fwd/pair.h
__fwd/span.h
__fwd/sstream.h
__fwd/streambuf.h
__fwd/string.h
__fwd/string_view.h
__fwd/subrange.h
Expand Down
53 changes: 53 additions & 0 deletions libcxx/include/__fwd/fstream.h
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_FSTREAM_H
#define _LIBCPP___FWD_FSTREAM_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_filebuf;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ifstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ofstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_fstream;

typedef basic_filebuf<char> filebuf;
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
typedef basic_fstream<char> fstream;

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_filebuf<wchar_t> wfilebuf;
typedef basic_ifstream<wchar_t> wifstream;
typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
#endif

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(filebuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfilebuf)) basic_filebuf;
template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(ifstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wifstream)) basic_ifstream;
template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(ofstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wofstream)) basic_ofstream;
template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(fstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wfstream)) basic_fstream;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_FSTREAM_H
41 changes: 41 additions & 0 deletions libcxx/include/__fwd/ios.h
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_IOS_H
#define _LIBCPP___FWD_IOS_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ios;

typedef basic_ios<char> ios;
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_ios<wchar_t> wios;
#endif

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios;

#if defined(_NEWLIB_VERSION)
// On newlib, off_t is 'long int'
typedef long int streamoff; // for char_traits in <string>
#else
typedef long long streamoff; // for char_traits in <string>
#endif

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_IOS_H
43 changes: 43 additions & 0 deletions libcxx/include/__fwd/istream.h
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_ISTREAM_H
#define _LIBCPP___FWD_ISTREAM_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_istream;

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_iostream;

typedef basic_istream<char> istream;
typedef basic_iostream<char> iostream;

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_istream<wchar_t> wistream;
typedef basic_iostream<wchar_t> wiostream;
#endif

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(istream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistream)) basic_istream;

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(iostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wiostream)) basic_iostream;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_ISTREAM_H
35 changes: 35 additions & 0 deletions libcxx/include/__fwd/ostream.h
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_OSTREAM_H
#define _LIBCPP___FWD_OSTREAM_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ostream;

typedef basic_ostream<char> ostream;

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_ostream<wchar_t> wostream;
#endif

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(ostream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostream)) basic_ostream;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_OSTREAM_H
58 changes: 58 additions & 0 deletions libcxx/include/__fwd/sstream.h
@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_SSTREAM_H
#define _LIBCPP___FWD_SSTREAM_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_stringbuf;

template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_istringstream;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ostringstream;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_stringstream;

typedef basic_stringbuf<char> stringbuf;
typedef basic_istringstream<char> istringstream;
typedef basic_ostringstream<char> ostringstream;
typedef basic_stringstream<char> stringstream;

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_stringbuf<wchar_t> wstringbuf;
typedef basic_istringstream<wchar_t> wistringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
typedef basic_stringstream<wchar_t> wstringstream;
#endif

template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_PREFERRED_NAME(stringbuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringbuf)) basic_stringbuf;
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_PREFERRED_NAME(istringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wistringstream)) basic_istringstream;
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_PREFERRED_NAME(ostringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wostringstream)) basic_ostringstream;
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_PREFERRED_NAME(stringstream) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstringstream)) basic_stringstream;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_SSTREAM_H
35 changes: 35 additions & 0 deletions libcxx/include/__fwd/streambuf.h
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_STREAMBUF_H
#define _LIBCPP___FWD_STREAMBUF_H

#include <__config>
#include <__fwd/string.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_streambuf;

typedef basic_streambuf<char> streambuf;

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
typedef basic_streambuf<wchar_t> wstreambuf;
#endif

template <class _CharT, class _Traits>
class _LIBCPP_PREFERRED_NAME(streambuf) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstreambuf)) basic_streambuf;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_STREAMBUF_H
1 change: 1 addition & 0 deletions libcxx/include/fstream
Expand Up @@ -183,6 +183,7 @@ typedef basic_fstream<wchar_t> wfstream;
#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__fwd/fstream.h>
#include <__locale>
#include <__utility/move.h>
#include <__utility/swap.h>
Expand Down
1 change: 1 addition & 0 deletions libcxx/include/ios
Expand Up @@ -217,6 +217,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
#endif

#include <__assert> // all public C++ headers provide the assertion handler
#include <__fwd/ios.h>
#include <__ios/fpos.h>
#include <__locale>
#include <__system_error/error_category.h>
Expand Down

0 comments on commit 9d16cbc

Please sign in to comment.