From 9ae609fe2b08ad710a0f1f36fd576359f2831ff8 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 23 Jul 2016 02:32:21 +0000 Subject: [PATCH] Add -fmodules-ts flag to cc1 for the provisional C++ modules TS, and mark 'module' and 'import' as keywords when the flag is specified. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276508 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/LangOptions.def | 1 + include/clang/Basic/TokenKinds.def | 9 +++++++++ include/clang/Driver/CC1Options.td | 2 ++ lib/Basic/IdentifierTable.cpp | 6 ++++-- lib/Frontend/CompilerInvocation.cpp | 5 +++-- test/Lexer/modules-ts.cpp | 11 +++++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/Lexer/modules-ts.cpp diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 03561961dd..7a2bf24d3a 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -142,6 +142,7 @@ BENIGN_LANGOPT(EmitAllDecls , 1, 0, "emitting all declarations") LANGOPT(MathErrno , 1, 1, "errno in math functions") BENIGN_LANGOPT(HeinousExtensions , 1, 0, "extensions that we really don't like and may be ripped out at any time") LANGOPT(Modules , 1, 0, "modules extension to C") +LANGOPT(ModulesTS , 1, 0, "C++ Modules TS") BENIGN_LANGOPT(CompilingModule, 1, 0, "compiling a module interface") COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses") BENIGN_LANGOPT(ModulesSearchAll , 1, 1, "searching even non-imported modules to find unresolved references") diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index 882c6e4cac..82cb6c21f9 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -30,6 +30,9 @@ #ifndef CONCEPTS_KEYWORD #define CONCEPTS_KEYWORD(X) KEYWORD(X,KEYCONCEPTS) #endif +#ifndef MODULES_KEYWORD +#define MODULES_KEYWORD(X) KEYWORD(X,KEYMODULES) +#endif #ifndef TYPE_TRAIT #define TYPE_TRAIT(N,I,K) KEYWORD(I,K) #endif @@ -235,6 +238,8 @@ PUNCTUATOR(caretcaret, "^^") // KEYCXX11 - This is a C++ keyword introduced to C++ in C++11 // KEYCONCEPTS - This is a keyword if the C++ extensions for concepts // are enabled. +// KEYMODULES - This is a keyword if the C++ extensions for modules +// are enabled. // KEYGNU - This is a keyword if GNU extensions are enabled // KEYMS - This is a keyword if Microsoft extensions are enabled // KEYNOMS18 - This is a keyword that must never be enabled under @@ -366,6 +371,10 @@ KEYWORD(co_await , KEYCOROUTINES) KEYWORD(co_return , KEYCOROUTINES) KEYWORD(co_yield , KEYCOROUTINES) +// C++ modules TS keywords +MODULES_KEYWORD(module) +MODULES_KEYWORD(import) + // GNU Extensions (in impl-reserved namespace) KEYWORD(_Decimal32 , KEYALL) KEYWORD(_Decimal64 , KEYALL) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 1401984c2a..aa8352204b 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -388,6 +388,8 @@ def ast_dump_filter : Separate<["-"], "ast-dump-filter">, HelpText<"Use with -ast-dump or -ast-print to dump/print only AST declaration" " nodes having a certain substring in a qualified name. Use" " -ast-list to list all filterable declaration node names.">; +def fmodules_ts : Flag <["-"], "fmodules-ts">, Group, + HelpText<"Enable support for the C++ Modules TS">; def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">, HelpText<"Do not automatically generate or update the global module index">; def fno_modules_error_recovery : Flag<["-"], "fno-modules-error-recovery">, diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp index d6ad0f5c91..537a2b702d 100644 --- a/lib/Basic/IdentifierTable.cpp +++ b/lib/Basic/IdentifierTable.cpp @@ -113,7 +113,8 @@ namespace { KEYOBJC2 = 0x20000, KEYZVECTOR = 0x40000, KEYCOROUTINES = 0x80000, - KEYALL = (0xfffff & ~KEYNOMS18 & + KEYMODULES = 0x100000, + KEYALL = (0x1fffff & ~KEYNOMS18 & ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude. }; @@ -147,9 +148,10 @@ static KeywordStatus getKeywordStatus(const LangOptions &LangOpts, // We treat bridge casts as objective-C keywords so we can warn on them // in non-arc mode. if (LangOpts.ObjC2 && (Flags & KEYARC)) return KS_Enabled; - if (LangOpts.ConceptsTS && (Flags & KEYCONCEPTS)) return KS_Enabled; if (LangOpts.ObjC2 && (Flags & KEYOBJC2)) return KS_Enabled; + if (LangOpts.ConceptsTS && (Flags & KEYCONCEPTS)) return KS_Enabled; if (LangOpts.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled; + if (LangOpts.ModulesTS && (Flags & KEYMODULES)) return KS_Enabled; if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) return KS_Future; return KS_Disabled; } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index eacba7d4e0..98eb4bb377 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1873,12 +1873,13 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, && Opts.OpenCLVersion >= 200); Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); Opts.Coroutines = Args.hasArg(OPT_fcoroutines); - Opts.Modules = Args.hasArg(OPT_fmodules); + Opts.ModulesTS = Args.hasArg(OPT_fmodules_ts); + Opts.Modules = Args.hasArg(OPT_fmodules) || Opts.ModulesTS; Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse); Opts.ModulesDeclUse = Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse; Opts.ModulesLocalVisibility = - Args.hasArg(OPT_fmodules_local_submodule_visibility); + Args.hasArg(OPT_fmodules_local_submodule_visibility) || Opts.ModulesTS; Opts.ModulesSearchAll = Opts.Modules && !Args.hasArg(OPT_fno_modules_search_all) && Args.hasArg(OPT_fmodules_search_all); diff --git a/test/Lexer/modules-ts.cpp b/test/Lexer/modules-ts.cpp new file mode 100644 index 0000000000..06be17c536 --- /dev/null +++ b/test/Lexer/modules-ts.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fmodules-ts -DMODULES -fsyntax-only %s + +#ifdef MODULES +#define MODULES_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME) +#else +#define MODULES_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME) +#endif + +MODULES_KEYWORD(import); +MODULES_KEYWORD(module); -- 2.40.0