Skip to content

Commit d484264

Browse files
committed
Add -import-std and -include-std command line options
Closes #692, closes #693
1 parent b596d84 commit d484264

File tree

66 files changed

+129
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+129
-102
lines changed

include/cpp2util.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@
2121
#define CPP2_UTIL_H
2222

2323
// If this implementation doesn't support source_location yet, disable it
24-
// TODO: technically this test should have <version> included first, but GEFN
24+
#include <version>
2525
#if !defined(_MSC_VER) && !defined(__cpp_lib_source_location)
2626
#undef CPP2_USE_SOURCE_LOCATION
2727
#endif
2828

29-
// If the cppfront user requested -pure-cpp2, this will be set
30-
// and we should be using modules only
31-
#ifdef CPP2_USE_MODULES
29+
// If the cppfront user requested making the entire C++ standard library
30+
// available via module import or header include, do that
31+
#if defined(CPP2_IMPORT_STD) || defined(CPP2_INCLUDE_STD)
3232

33-
// If we have real modules, use those the best we can
34-
// as implementations are still underway
35-
#ifdef __cpp_modules
33+
// If C++23 'import std;' was requested and is available, use that
34+
#if defined(CPP2_IMPORT_STD) && defined(__cpp_modules)
3635

3736
#ifndef _MSC_VER
3837
// This is the ideal -- note that we just voted "import std;"
3938
// into draft C++23 in late July 2022, so implementers haven't
40-
// had time to catch up yet. As of this writing (September 2022)
41-
// no compiler will take this path yet, but they're on the way...
39+
// had time to catch up yet
4240
import std;
4341
#else // MSVC
4442
// Note: When C++23 "import std;" is available, we will switch to that here
4543
// In the meantime, this is what works on MSVC which is the only compiler
4644
// I've been able to get access to that implements modules enough to demo
4745
// (but we'll have more full-C++20 compilers soon!)
46+
#ifdef _MSC_VER
47+
#include "intrin.h"
48+
#endif
4849
import std.core;
49-
import std.regex;
5050
import std.filesystem;
5151
import std.memory;
52+
import std.regex;
5253
import std.threading;
5354

5455
// Suppress spurious MSVC modules warning
5556
#pragma warning(disable:5050)
5657
#endif
5758

58-
// Otherwise, "fake it till you make it"... include (nearly) all the
59-
// standard headers, with a feature test #ifdef for each header that
59+
// Otherwise, as a fallback if 'import std;' was requested, or else
60+
// because 'include all std' was requested, include all the standard
61+
// headers, with a feature test #ifdef for each header that
6062
// isn't yet supported by all of { VS 2022, g++-10, clang++-12 }
61-
// ... this should approximate "import std;" on those compilers
6263
#else
6364
#ifdef _MSC_VER
6465
#include "intrin.h"
6566
#endif
66-
#include <version>
6767
#include <algorithm>
6868
#include <any>
6969
#include <array>
@@ -85,10 +85,10 @@
8585
#include <clocale>
8686
#include <cmath>
8787
#include <codecvt>
88-
#include <condition_variable>
8988
#include <compare>
9089
#include <complex>
9190
#include <concepts>
91+
#include <condition_variable>
9292
#ifdef __cpp_lib_coroutine
9393
#include <coroutine>
9494
#endif
@@ -174,15 +174,15 @@
174174
#include <ranges>
175175
#include <ratio>
176176
#include <regex>
177-
#ifdef __cpp_lib_source_location
178-
#include <source_location>
179-
#endif
180177
#include <scoped_allocator>
181178
#ifdef __cpp_lib_semaphore
182179
#include <semaphore>
183180
#endif
184181
#include <set>
185182
#include <shared_mutex>
183+
#ifdef __cpp_lib_source_location
184+
#include <source_location>
185+
#endif
186186
#include <span>
187187
#ifdef __cpp_lib_spanstream
188188
#include <spanstream>
@@ -224,8 +224,7 @@
224224
#include <vector>
225225
#endif
226226

227-
// Otherwise, we're not in -pure-cpp2 and so just #include
228-
// what we need in this header to make this self-contained
227+
// Otherwise, just #include the facilities used in this header
229228
#else
230229
#ifdef _MSC_VER
231230
#include "intrin.h"

regression-tests/mixed-multiple-return-values.cpp2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ f: () -> (i: int, s: std::string) = {
1919
return;
2020
}
2121

22-
print: (name: std::string, value:_)
22+
do_print: (name: std::string, value:_)
2323
= std::cout << name << " is " << value << "\n";
2424

2525
int main() {
2626
auto [a,b] = f();
27-
print("a", a);
28-
print("b", b);
27+
do_print("a", a);
28+
do_print("b", b);
2929
}
3030

3131
bool flip_a_coin() {
3232
// Change std::mt19937 to std::random_device for non-deterministic PRNG
33-
static std::mt19937 rand;
33+
static std::mt19937 rand;
3434
return rand() % 2 == 0;
3535
}

regression-tests/test-results/mixed-multiple-return-values.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ struct f_ret { int i; std::string s; };
2020

2121

2222
#line 22 "mixed-multiple-return-values.cpp2"
23-
auto print(cpp2::in<std::string> name, auto const& value) -> void;
23+
auto do_print(cpp2::in<std::string> name, auto const& value) -> void;
2424

2525

2626
int main() {
2727
auto [a,b] = f();
28-
print("a", a);
29-
print("b", b);
28+
do_print("a", a);
29+
do_print("b", b);
3030
}
3131

3232
bool flip_a_coin() {
3333
// Change std::mt19937 to std::random_device for non-deterministic PRNG
34-
static std::mt19937 rand;
34+
static std::mt19937 rand;
3535
return rand() % 2 == 0;
3636
}
3737

@@ -59,6 +59,6 @@ bool flip_a_coin() {
5959
return { std::move(i.value()), std::move(s.value()) };
6060
}
6161

62-
auto print(cpp2::in<std::string> name, auto const& value) -> void {
62+
auto do_print(cpp2::in<std::string> name, auto const& value) -> void {
6363
std::cout << name << " is " << value << "\n"; }
6464

regression-tests/test-results/pure2-bounds-safety-span.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-break-continue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-max-munch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-memberwise-base-assignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-name-lookup-and-value-decoration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-non-local-function-expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-non-local-initialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-optional-template-argument-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-requires-clause-in-forward-declaration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-requires-clause-unbraced-function-initializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-template-argument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-bugfix-for-variable-template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-chained-comparisons.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-concept-definition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-defaulted-comparisons-and-final-types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-enum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-forward-return.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-function-multiple-forward-arguments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-hello.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-inspect-expression-in-generic-function-multiple-types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-inspect-expression-with-as-in-generic-function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-inspect-fallback-with-variant-any-optional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-inspect-generic-void-empty-with-variant-any-optional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-interpolation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-intro-example-hello-2022.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-intro-example-three-loops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-look-up-parameter-across-unnamed-function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-main-args.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-more-wildcards.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

regression-tests/test-results/pure2-raw-string-literal-and-interpolation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#define CPP2_USE_MODULES Yes
2+
#define CPP2_IMPORT_STD Yes
33

44
//=== Cpp2 type declarations ====================================================
55

0 commit comments

Comments
 (0)