public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ Module keywords
@ 2020-12-01 19:46 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-12-01 19:46 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 724 bytes --]

This adds the module keywords.	These are special internal tokens
generated by the preprocessor's module-control-line token peeking
logic.	Spelling them with a space means that they turn	back into
regular tokens in preprocessor output (but do skew the column
numbering :()

         gcc/c-family/
         * c-common.c (module, import, export): New internal tokens (with
         trailing space).
         * c-common.h (RID__MODULE, RID__IMPORT & RID__EXPORT): Enumerate
         them.
         (D_CXX_MODULES, D_CXX_MODULES_FLAGS): Enable them.
         * c-cppbuiltins.c (c_cpp_builtins): Feature macro.
         gcc/cp/
         * lex.c (init_reswords): Maybe enable module keywords.

pushing to trunk

-- 
Nathan Sidwell

[-- Attachment #2: 14-family-keywords.diff --]
[-- Type: text/x-patch, Size: 2840 bytes --]

diff --git i/gcc/c-family/c-common.c w/gcc/c-family/c-common.c
index 5d1e4ef289c..cae883b5309 100644
--- i/gcc/c-family/c-common.c
+++ w/gcc/c-family/c-common.c
@@ -540,6 +540,12 @@ const struct c_common_resword c_common_reswords[] =
   { "concept",		RID_CONCEPT,	D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
   { "requires", 	RID_REQUIRES,	D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
 
+  /* Modules-related keywords, these are internal unspellable tokens,
+     created by the preprocessor.  */
+  { "module ",		RID__MODULE,	D_CXX_MODULES_FLAGS | D_CXXWARN },
+  { "import ",		RID__IMPORT,	D_CXX_MODULES_FLAGS | D_CXXWARN },
+  { "export ",		RID__EXPORT,	D_CXX_MODULES_FLAGS | D_CXXWARN },
+
   /* Coroutines-related keywords */
   { "co_await",		RID_CO_AWAIT,	D_CXX_COROUTINES_FLAGS | D_CXXWARN },
   { "co_yield",		RID_CO_YIELD,	D_CXX_COROUTINES_FLAGS | D_CXXWARN },
diff --git i/gcc/c-family/c-common.h w/gcc/c-family/c-common.h
index f413e8773f5..8c17067e63c 100644
--- i/gcc/c-family/c-common.h
+++ w/gcc/c-family/c-common.h
@@ -195,6 +195,9 @@ enum rid
   /* C++ concepts */
   RID_CONCEPT, RID_REQUIRES,
 
+  /* C++ modules.  */
+  RID__MODULE, RID__IMPORT, RID__EXPORT, /* Internal tokens.  */
+
   /* C++ coroutines */
   RID_CO_AWAIT, RID_CO_YIELD, RID_CO_RETURN,
 
@@ -449,9 +452,11 @@ extern machine_mode c_default_pointer_mode;
 #define D_CXX_CHAR8_T	0X1000	/* In C++, only with -fchar8_t.  */
 #define D_CXX20		0x2000  /* In C++, C++20 only.  */
 #define D_CXX_COROUTINES 0x4000  /* In C++, only with coroutines.  */
+#define D_CXX_MODULES	0x8000  /* In C++, only with modules.  */
 
 #define D_CXX_CONCEPTS_FLAGS D_CXXONLY | D_CXX_CONCEPTS
 #define D_CXX_CHAR8_T_FLAGS D_CXXONLY | D_CXX_CHAR8_T
+#define D_CXX_MODULES_FLAGS (D_CXXONLY | D_CXX_MODULES)
 #define D_CXX_COROUTINES_FLAGS (D_CXXONLY | D_CXX_COROUTINES)
 
 /* The reserved keyword table.  */
diff --git i/gcc/c-family/c-cppbuiltin.c w/gcc/c-family/c-cppbuiltin.c
index d35b087bdcc..41914f64874 100644
--- i/gcc/c-family/c-cppbuiltin.c
+++ w/gcc/c-family/c-cppbuiltin.c
@@ -1025,6 +1025,10 @@ c_cpp_builtins (cpp_reader *pfile)
           else
             cpp_define (pfile, "__cpp_concepts=201507L");
         }
+      if (flag_modules)
+	/* The std-defined value is 201907L, but I don't think we can
+	   claim victory yet.  201810 is the p1103 date. */
+	cpp_define (pfile, "__cpp_modules=201810L");
       if (flag_coroutines)
 	cpp_define (pfile, "__cpp_impl_coroutine=201902L"); /* n4861, DIS */
       if (flag_tm)
diff --git i/gcc/cp/lex.c w/gcc/cp/lex.c
index 8a69bc4f170..21e33d69c08 100644
--- i/gcc/cp/lex.c
+++ w/gcc/cp/lex.c
@@ -235,6 +235,8 @@ init_reswords (void)
     mask |= D_CXX_CONCEPTS;
   if (!flag_coroutines)
     mask |= D_CXX_COROUTINES;
+  if (!flag_modules)
+    mask |= D_CXX_MODULES;
   if (!flag_tm)
     mask |= D_TRANSMEM;
   if (!flag_char8_t)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-01 19:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 19:46 C++ Module keywords Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).