From eb7927ee8f2838e153c3002e94a6af9d18b76d92 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 22 Oct 2015 03:52:15 +0000 Subject: [PATCH] [coroutines] Add lexer support for co_await, co_yield, and co_return keywords. Add -fcoroutines flag (just for -cc1 for now) to enable the feature. Early indications are that this will be part of -std=c++1z. llvm-svn: 250980 --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/TokenKinds.def | 7 +++++++ clang/include/clang/Driver/CC1Options.td | 4 ++++ clang/lib/Basic/IdentifierTable.cpp | 4 +++- clang/lib/Frontend/CompilerInvocation.cpp | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 3c380f30019c..538ae480cf45 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -118,6 +118,7 @@ LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions") LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly") +LANGOPT(Coroutines , 1, 0, "C++ coroutines TS") BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers") LANGOPT(POSIXThreads , 1, 0, "POSIX thread support") diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 963e036b6d30..1e0ec117d07a 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -242,6 +242,8 @@ PUNCTUATOR(greatergreatergreater, ">>>") // KEYZVECTOR - This is a keyword for the System z vector extensions, // which are heavily based on AltiVec // KEYBORLAND - This is a keyword if Borland extensions are enabled +// KEYCOROUTINES - This is a keyword if support for the C++ coroutines +// TS is enabled // BOOLSUPPORT - This is a keyword if 'bool' is a built-in type // HALFSUPPORT - This is a keyword if 'half' is a built-in type // WCHARSUPPORT - This is a keyword if 'wchar_t' is a built-in type @@ -356,6 +358,11 @@ CXX11_KEYWORD(thread_local , 0) CONCEPTS_KEYWORD(concept) CONCEPTS_KEYWORD(requires) +// C++ coroutines TS keywords +KEYWORD(co_await , KEYCOROUTINES) +KEYWORD(co_return , KEYCOROUTINES) +KEYWORD(co_yield , KEYCOROUTINES) + // GNU Extensions (in impl-reserved namespace) KEYWORD(_Decimal32 , KEYALL) KEYWORD(_Decimal64 , KEYALL) diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 4f2dcdf7f220..dcd724d2451b 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -580,6 +580,10 @@ def fnative_half_type: Flag<["-"], "fnative-half-type">, def fallow_half_arguments_and_returns : Flag<["-"], "fallow-half-arguments-and-returns">, HelpText<"Allow function arguments and returns of type half">; +// C++ TSes. +def fcoroutines : Flag<["-"], "fcoroutines">, + HelpText<"Enable support for the C++ Coroutines TS">; + //===----------------------------------------------------------------------===// // Header Search Options //===----------------------------------------------------------------------===// diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 199815aa891b..67de1cb6fdaa 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -111,7 +111,8 @@ namespace { KEYCONCEPTS = 0x10000, KEYOBJC2 = 0x20000, KEYZVECTOR = 0x40000, - KEYALL = (0x7ffff & ~KEYNOMS18 & + KEYCOROUTINES = 0x80000, + KEYALL = (0xfffff & ~KEYNOMS18 & ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude. }; @@ -147,6 +148,7 @@ static KeywordStatus getKeywordStatus(const LangOptions &LangOpts, 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.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled; if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) return KS_Future; return KS_Disabled; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 7cece2b3dd90..71ee7e471495 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1536,6 +1536,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data); Opts.Blocks = Args.hasArg(OPT_fblocks); Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); + Opts.Coroutines = Args.hasArg(OPT_fcoroutines); Opts.Modules = Args.hasArg(OPT_fmodules); Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse); Opts.ModulesDeclUse =