Index: cfe/trunk/include/clang/Basic/LangStandard.h =================================================================== --- cfe/trunk/include/clang/Basic/LangStandard.h +++ cfe/trunk/include/clang/Basic/LangStandard.h @@ -0,0 +1,136 @@ +//===--- LangStandard.h -----------------------------------------*- C++ -*-===// +// +// 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 LLVM_CLANG_BASIC_LANGSTANDARD_H +#define LLVM_CLANG_BASIC_LANGSTANDARD_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/StringRef.h" + +namespace clang { + +/// The language for the input, used to select and validate the language +/// standard and possible actions. +enum class Language : uint8_t { + Unknown, + + /// Assembly: we accept this only so that we can preprocess it. + Asm, + + /// LLVM IR: we accept this so that we can run the optimizer on it, + /// and compile it to assembly or object code. + LLVM_IR, + + ///@{ Languages that the frontend can parse and compile. + C, + CXX, + ObjC, + ObjCXX, + OpenCL, + CUDA, + RenderScript, + HIP, + ///@} +}; + +enum LangFeatures { + LineComment = (1 << 0), + C99 = (1 << 1), + C11 = (1 << 2), + C17 = (1 << 3), + C2x = (1 << 4), + CPlusPlus = (1 << 5), + CPlusPlus11 = (1 << 6), + CPlusPlus14 = (1 << 7), + CPlusPlus17 = (1 << 8), + CPlusPlus2a = (1 << 9), + Digraphs = (1 << 10), + GNUMode = (1 << 11), + HexFloat = (1 << 12), + ImplicitInt = (1 << 13), + OpenCL = (1 << 14) +}; + +/// LangStandard - Information about the properties of a particular language +/// standard. +struct LangStandard { + enum Kind { +#define LANGSTANDARD(id, name, lang, desc, features) \ + lang_##id, +#include "clang/Basic/LangStandards.def" + lang_unspecified + }; + + const char *ShortName; + const char *Description; + unsigned Flags; + clang::Language Language; + +public: + /// getName - Get the name of this standard. + const char *getName() const { return ShortName; } + + /// getDescription - Get the description of this standard. + const char *getDescription() const { return Description; } + + /// Get the language that this standard describes. + clang::Language getLanguage() const { return Language; } + + /// Language supports '//' comments. + bool hasLineComments() const { return Flags & LineComment; } + + /// isC99 - Language is a superset of C99. + bool isC99() const { return Flags & C99; } + + /// isC11 - Language is a superset of C11. + bool isC11() const { return Flags & C11; } + + /// isC17 - Language is a superset of C17. + bool isC17() const { return Flags & C17; } + + /// isC2x - Language is a superset of C2x. + bool isC2x() const { return Flags & C2x; } + + /// isCPlusPlus - Language is a C++ variant. + bool isCPlusPlus() const { return Flags & CPlusPlus; } + + /// isCPlusPlus11 - Language is a C++11 variant (or later). + bool isCPlusPlus11() const { return Flags & CPlusPlus11; } + + /// isCPlusPlus14 - Language is a C++14 variant (or later). + bool isCPlusPlus14() const { return Flags & CPlusPlus14; } + + /// isCPlusPlus17 - Language is a C++17 variant (or later). + bool isCPlusPlus17() const { return Flags & CPlusPlus17; } + + /// isCPlusPlus2a - Language is a post-C++17 variant (or later). + bool isCPlusPlus2a() const { return Flags & CPlusPlus2a; } + + /// hasDigraphs - Language supports digraphs. + bool hasDigraphs() const { return Flags & Digraphs; } + + /// isGNUMode - Language includes GNU extensions. + bool isGNUMode() const { return Flags & GNUMode; } + + /// hasHexFloats - Language supports hexadecimal float constants. + bool hasHexFloats() const { return Flags & HexFloat; } + + /// hasImplicitInt - Language allows variables to be typed as int implicitly. + bool hasImplicitInt() const { return Flags & ImplicitInt; } + + /// isOpenCL - Language is a OpenCL variant. + bool isOpenCL() const { return Flags & OpenCL; } + + static Kind getLangKind(StringRef Name); + static const LangStandard &getLangStandardForKind(Kind K); + static const LangStandard *getLangStandardForName(StringRef Name); +}; + +} // end namespace clang + +#endif Index: cfe/trunk/include/clang/Basic/LangStandards.def =================================================================== --- cfe/trunk/include/clang/Basic/LangStandards.def +++ cfe/trunk/include/clang/Basic/LangStandards.def @@ -0,0 +1,189 @@ +//===-- LangStandards.def - Language Standard Data --------------*- C++ -*-===// +// +// 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 LANGSTANDARD +#error "LANGSTANDARD must be defined before including this file" +#endif + +/// LANGSTANDARD(IDENT, NAME, LANG, DESC, FEATURES) +/// +/// \param IDENT - The name of the standard as a C++ identifier. +/// \param NAME - The name of the standard. +/// \param LANG - The Language for which this is a standard. +/// \param DESC - A short description of the standard. +/// \param FEATURES - The standard features as flags, these are enums from the +/// clang::frontend namespace, which is assumed to be be available. + +/// LANGSTANDARD_ALIAS(IDENT, ALIAS) +/// \param IDENT - The name of the standard as a C++ identifier. +/// \param ALIAS - The alias of the standard. + +/// LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS) +/// Same as LANGSTANDARD_ALIAS, but for a deprecated alias. + +#ifndef LANGSTANDARD_ALIAS +#define LANGSTANDARD_ALIAS(IDENT, ALIAS) +#endif + +#ifndef LANGSTANDARD_ALIAS_DEPR +#define LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS) LANGSTANDARD_ALIAS(IDENT, ALIAS) +#endif + +// C89-ish modes. +LANGSTANDARD(c89, "c89", + C, "ISO C 1990", + ImplicitInt) +LANGSTANDARD_ALIAS(c89, "c90") +LANGSTANDARD_ALIAS(c89, "iso9899:1990") + +LANGSTANDARD(c94, "iso9899:199409", + C, "ISO C 1990 with amendment 1", + Digraphs | ImplicitInt) + +LANGSTANDARD(gnu89, "gnu89", + C, "ISO C 1990 with GNU extensions", + LineComment | Digraphs | GNUMode | ImplicitInt) +LANGSTANDARD_ALIAS(gnu89, "gnu90") + +// C99-ish modes +LANGSTANDARD(c99, "c99", + C, "ISO C 1999", + LineComment | C99 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS(c99, "iso9899:1999") +LANGSTANDARD_ALIAS_DEPR(c99, "c9x") +LANGSTANDARD_ALIAS_DEPR(c99, "iso9899:199x") + +LANGSTANDARD(gnu99, "gnu99", + C, "ISO C 1999 with GNU extensions", + LineComment | C99 | Digraphs | GNUMode | HexFloat) +LANGSTANDARD_ALIAS_DEPR(gnu99, "gnu9x") + +// C11 modes +LANGSTANDARD(c11, "c11", + C, "ISO C 2011", + LineComment | C99 | C11 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS(c11, "iso9899:2011") +LANGSTANDARD_ALIAS_DEPR(c11, "c1x") +LANGSTANDARD_ALIAS_DEPR(c11, "iso9899:201x") + +LANGSTANDARD(gnu11, "gnu11", + C, "ISO C 2011 with GNU extensions", + LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat) +LANGSTANDARD_ALIAS_DEPR(gnu11, "gnu1x") + +// C17 modes +LANGSTANDARD(c17, "c17", + C, "ISO C 2017", + LineComment | C99 | C11 | C17 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS(c17, "iso9899:2017") +LANGSTANDARD_ALIAS(c17, "c18") +LANGSTANDARD_ALIAS(c17, "iso9899:2018") +LANGSTANDARD(gnu17, "gnu17", + C, "ISO C 2017 with GNU extensions", + LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat) +LANGSTANDARD_ALIAS(gnu17, "gnu18") + +// C2x modes +LANGSTANDARD(c2x, "c2x", + C, "Working Draft for ISO C2x", + LineComment | C99 | C11 | C17 | C2x | Digraphs | HexFloat) +LANGSTANDARD(gnu2x, "gnu2x", + C, "Working Draft for ISO C2x with GNU extensions", + LineComment | C99 | C11 | C17 | C2x | Digraphs | GNUMode | HexFloat) + +// C++ modes +LANGSTANDARD(cxx98, "c++98", + CXX, "ISO C++ 1998 with amendments", + LineComment | CPlusPlus | Digraphs) +LANGSTANDARD_ALIAS(cxx98, "c++03") + +LANGSTANDARD(gnucxx98, "gnu++98", + CXX, "ISO C++ 1998 with amendments and GNU extensions", + LineComment | CPlusPlus | Digraphs | GNUMode) +LANGSTANDARD_ALIAS(gnucxx98, "gnu++03") + +LANGSTANDARD(cxx11, "c++11", + CXX, "ISO C++ 2011 with amendments", + LineComment | CPlusPlus | CPlusPlus11 | Digraphs) +LANGSTANDARD_ALIAS_DEPR(cxx11, "c++0x") + +LANGSTANDARD(gnucxx11, "gnu++11", CXX, + "ISO C++ 2011 with amendments and GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | Digraphs | GNUMode) +LANGSTANDARD_ALIAS_DEPR(gnucxx11, "gnu++0x") + +LANGSTANDARD(cxx14, "c++14", + CXX, "ISO C++ 2014 with amendments", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs) +LANGSTANDARD_ALIAS_DEPR(cxx14, "c++1y") + +LANGSTANDARD(gnucxx14, "gnu++14", + CXX, "ISO C++ 2014 with amendments and GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | + GNUMode) +LANGSTANDARD_ALIAS_DEPR(gnucxx14, "gnu++1y") + +LANGSTANDARD(cxx17, "c++17", + CXX, "ISO C++ 2017 with amendments", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + Digraphs | HexFloat) +LANGSTANDARD_ALIAS_DEPR(cxx17, "c++1z") + +LANGSTANDARD(gnucxx17, "gnu++17", + CXX, "ISO C++ 2017 with amendments and GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + Digraphs | HexFloat | GNUMode) +LANGSTANDARD_ALIAS_DEPR(gnucxx17, "gnu++1z") + +LANGSTANDARD(cxx2a, "c++2a", + CXX, "Working draft for ISO C++ 2020", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus2a | Digraphs | HexFloat) + +LANGSTANDARD(gnucxx2a, "gnu++2a", + CXX, "Working draft for ISO C++ 2020 with GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus2a | Digraphs | HexFloat | GNUMode) + +// OpenCL +LANGSTANDARD(opencl10, "cl1.0", + OpenCL, "OpenCL 1.0", + LineComment | C99 | Digraphs | HexFloat | OpenCL) +LANGSTANDARD_ALIAS_DEPR(opencl10, "cl") + +LANGSTANDARD(opencl11, "cl1.1", + OpenCL, "OpenCL 1.1", + LineComment | C99 | Digraphs | HexFloat | OpenCL) +LANGSTANDARD(opencl12, "cl1.2", + OpenCL, "OpenCL 1.2", + LineComment | C99 | Digraphs | HexFloat | OpenCL) +LANGSTANDARD(opencl20, "cl2.0", + OpenCL, "OpenCL 2.0", + LineComment | C99 | Digraphs | HexFloat | OpenCL) +LANGSTANDARD(openclcpp, "c++", + OpenCL, "C++ for OpenCL", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + Digraphs | HexFloat | OpenCL) + +LANGSTANDARD_ALIAS_DEPR(opencl10, "CL") +LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1") +LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2") +LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0") +LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++") + +// CUDA +LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)", + LineComment | CPlusPlus | Digraphs) + +// HIP +LANGSTANDARD(hip, "hip", HIP, "HIP", + LineComment | CPlusPlus | Digraphs) + +#undef LANGSTANDARD +#undef LANGSTANDARD_ALIAS +#undef LANGSTANDARD_ALIAS_DEPR Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -2637,7 +2637,7 @@ const char *Values = #define LANGSTANDARD(id, name, lang, desc, features) name "," #define LANGSTANDARD_ALIAS(id, alias) alias "," - #include "clang/Frontend/LangStandards.def" + #include "clang/Basic/LangStandards.def" ; }]>; def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>, Index: cfe/trunk/include/clang/Frontend/CompilerInvocation.h =================================================================== --- cfe/trunk/include/clang/Frontend/CompilerInvocation.h +++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h @@ -14,9 +14,9 @@ #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/LangStandard.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/FrontendOptions.h" -#include "clang/Frontend/LangStandard.h" #include "clang/Frontend/MigratorOptions.h" #include "clang/Frontend/PreprocessorOutputOptions.h" #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" Index: cfe/trunk/include/clang/Frontend/FrontendOptions.h =================================================================== --- cfe/trunk/include/clang/Frontend/FrontendOptions.h +++ cfe/trunk/include/clang/Frontend/FrontendOptions.h @@ -10,15 +10,16 @@ #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H #include "clang/AST/ASTDumperUtils.h" +#include "clang/Basic/LangStandard.h" #include "clang/Frontend/CommandLineSourceLoc.h" -#include "clang/Serialization/ModuleFileExtension.h" #include "clang/Sema/CodeCompleteOptions.h" +#include "clang/Serialization/ModuleFileExtension.h" #include "llvm/ADT/StringRef.h" #include #include #include -#include #include +#include namespace llvm { @@ -143,35 +144,11 @@ /// The kind of a file that we've been handed as an input. class InputKind { private: - unsigned Lang : 4; + Language Lang; unsigned Fmt : 3; unsigned Preprocessed : 1; public: - /// The language for the input, used to select and validate the language - /// standard and possible actions. - enum Language { - Unknown, - - /// Assembly: we accept this only so that we can preprocess it. - Asm, - - /// LLVM IR: we accept this so that we can run the optimizer on it, - /// and compile it to assembly or object code. - LLVM_IR, - - ///@{ Languages that the frontend can parse and compile. - C, - CXX, - ObjC, - ObjCXX, - OpenCL, - CUDA, - RenderScript, - HIP, - ///@} - }; - /// The input file format. enum Format { Source, @@ -179,7 +156,7 @@ Precompiled }; - constexpr InputKind(Language L = Unknown, Format F = Source, + constexpr InputKind(Language L = Language::Unknown, Format F = Source, bool PP = false) : Lang(L), Fmt(F), Preprocessed(PP) {} @@ -188,10 +165,12 @@ bool isPreprocessed() const { return Preprocessed; } /// Is the input kind fully-unknown? - bool isUnknown() const { return Lang == Unknown && Fmt == Source; } + bool isUnknown() const { return Lang == Language::Unknown && Fmt == Source; } /// Is the language of the input some dialect of Objective-C? - bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; } + bool isObjectiveC() const { + return Lang == Language::ObjC || Lang == Language::ObjCXX; + } InputKind getPreprocessed() const { return InputKind(getLanguage(), getFormat(), true); @@ -467,9 +446,9 @@ IncludeTimestamps(true), TimeTraceGranularity(500) {} /// getInputKindForExtension - Return the appropriate input kind for a file - /// extension. For example, "c" would return InputKind::C. + /// extension. For example, "c" would return Language::C. /// - /// \return The input kind for the extension, or InputKind::Unknown if the + /// \return The input kind for the extension, or Language::Unknown if the /// extension is not recognized. static InputKind getInputKindForExtension(StringRef Extension); }; Index: cfe/trunk/include/clang/Frontend/LangStandard.h =================================================================== --- cfe/trunk/include/clang/Frontend/LangStandard.h +++ cfe/trunk/include/clang/Frontend/LangStandard.h @@ -1,117 +0,0 @@ -//===--- LangStandard.h -----------------------------------------*- C++ -*-===// -// -// 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 LLVM_CLANG_FRONTEND_LANGSTANDARD_H -#define LLVM_CLANG_FRONTEND_LANGSTANDARD_H - -#include "clang/Basic/LLVM.h" -#include "clang/Frontend/FrontendOptions.h" -#include "llvm/ADT/StringRef.h" - -namespace clang { - -namespace frontend { - -enum LangFeatures { - LineComment = (1 << 0), - C99 = (1 << 1), - C11 = (1 << 2), - C17 = (1 << 3), - C2x = (1 << 4), - CPlusPlus = (1 << 5), - CPlusPlus11 = (1 << 6), - CPlusPlus14 = (1 << 7), - CPlusPlus17 = (1 << 8), - CPlusPlus2a = (1 << 9), - Digraphs = (1 << 10), - GNUMode = (1 << 11), - HexFloat = (1 << 12), - ImplicitInt = (1 << 13), - OpenCL = (1 << 14) -}; - -} - -/// LangStandard - Information about the properties of a particular language -/// standard. -struct LangStandard { - enum Kind { -#define LANGSTANDARD(id, name, lang, desc, features) \ - lang_##id, -#include "clang/Frontend/LangStandards.def" - lang_unspecified - }; - - const char *ShortName; - const char *Description; - unsigned Flags; - InputKind::Language Language; - -public: - /// getName - Get the name of this standard. - const char *getName() const { return ShortName; } - - /// getDescription - Get the description of this standard. - const char *getDescription() const { return Description; } - - /// Get the language that this standard describes. - InputKind::Language getLanguage() const { return Language; } - - /// Language supports '//' comments. - bool hasLineComments() const { return Flags & frontend::LineComment; } - - /// isC99 - Language is a superset of C99. - bool isC99() const { return Flags & frontend::C99; } - - /// isC11 - Language is a superset of C11. - bool isC11() const { return Flags & frontend::C11; } - - /// isC17 - Language is a superset of C17. - bool isC17() const { return Flags & frontend::C17; } - - /// isC2x - Language is a superset of C2x. - bool isC2x() const { return Flags & frontend::C2x; } - - /// isCPlusPlus - Language is a C++ variant. - bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; } - - /// isCPlusPlus11 - Language is a C++11 variant (or later). - bool isCPlusPlus11() const { return Flags & frontend::CPlusPlus11; } - - /// isCPlusPlus14 - Language is a C++14 variant (or later). - bool isCPlusPlus14() const { return Flags & frontend::CPlusPlus14; } - - /// isCPlusPlus17 - Language is a C++17 variant (or later). - bool isCPlusPlus17() const { return Flags & frontend::CPlusPlus17; } - - /// isCPlusPlus2a - Language is a post-C++17 variant (or later). - bool isCPlusPlus2a() const { return Flags & frontend::CPlusPlus2a; } - - - /// hasDigraphs - Language supports digraphs. - bool hasDigraphs() const { return Flags & frontend::Digraphs; } - - /// isGNUMode - Language includes GNU extensions. - bool isGNUMode() const { return Flags & frontend::GNUMode; } - - /// hasHexFloats - Language supports hexadecimal float constants. - bool hasHexFloats() const { return Flags & frontend::HexFloat; } - - /// hasImplicitInt - Language allows variables to be typed as int implicitly. - bool hasImplicitInt() const { return Flags & frontend::ImplicitInt; } - - /// isOpenCL - Language is a OpenCL variant. - bool isOpenCL() const { return Flags & frontend::OpenCL; } - - static const LangStandard &getLangStandardForKind(Kind K); - static const LangStandard *getLangStandardForName(StringRef Name); -}; - -} // end namespace clang - -#endif Index: cfe/trunk/include/clang/Frontend/LangStandards.def =================================================================== --- cfe/trunk/include/clang/Frontend/LangStandards.def +++ cfe/trunk/include/clang/Frontend/LangStandards.def @@ -1,189 +0,0 @@ -//===-- LangStandards.def - Language Standard Data --------------*- C++ -*-===// -// -// 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 LANGSTANDARD -#error "LANGSTANDARD must be defined before including this file" -#endif - -/// LANGSTANDARD(IDENT, NAME, LANG, DESC, FEATURES) -/// -/// \param IDENT - The name of the standard as a C++ identifier. -/// \param NAME - The name of the standard. -/// \param LANG - The InputKind::Language for which this is a standard. -/// \param DESC - A short description of the standard. -/// \param FEATURES - The standard features as flags, these are enums from the -/// clang::frontend namespace, which is assumed to be be available. - -/// LANGSTANDARD_ALIAS(IDENT, ALIAS) -/// \param IDENT - The name of the standard as a C++ identifier. -/// \param ALIAS - The alias of the standard. - -/// LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS) -/// Same as LANGSTANDARD_ALIAS, but for a deprecated alias. - -#ifndef LANGSTANDARD_ALIAS -#define LANGSTANDARD_ALIAS(IDENT, ALIAS) -#endif - -#ifndef LANGSTANDARD_ALIAS_DEPR -#define LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS) LANGSTANDARD_ALIAS(IDENT, ALIAS) -#endif - -// C89-ish modes. -LANGSTANDARD(c89, "c89", - C, "ISO C 1990", - ImplicitInt) -LANGSTANDARD_ALIAS(c89, "c90") -LANGSTANDARD_ALIAS(c89, "iso9899:1990") - -LANGSTANDARD(c94, "iso9899:199409", - C, "ISO C 1990 with amendment 1", - Digraphs | ImplicitInt) - -LANGSTANDARD(gnu89, "gnu89", - C, "ISO C 1990 with GNU extensions", - LineComment | Digraphs | GNUMode | ImplicitInt) -LANGSTANDARD_ALIAS(gnu89, "gnu90") - -// C99-ish modes -LANGSTANDARD(c99, "c99", - C, "ISO C 1999", - LineComment | C99 | Digraphs | HexFloat) -LANGSTANDARD_ALIAS(c99, "iso9899:1999") -LANGSTANDARD_ALIAS_DEPR(c99, "c9x") -LANGSTANDARD_ALIAS_DEPR(c99, "iso9899:199x") - -LANGSTANDARD(gnu99, "gnu99", - C, "ISO C 1999 with GNU extensions", - LineComment | C99 | Digraphs | GNUMode | HexFloat) -LANGSTANDARD_ALIAS_DEPR(gnu99, "gnu9x") - -// C11 modes -LANGSTANDARD(c11, "c11", - C, "ISO C 2011", - LineComment | C99 | C11 | Digraphs | HexFloat) -LANGSTANDARD_ALIAS(c11, "iso9899:2011") -LANGSTANDARD_ALIAS_DEPR(c11, "c1x") -LANGSTANDARD_ALIAS_DEPR(c11, "iso9899:201x") - -LANGSTANDARD(gnu11, "gnu11", - C, "ISO C 2011 with GNU extensions", - LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat) -LANGSTANDARD_ALIAS_DEPR(gnu11, "gnu1x") - -// C17 modes -LANGSTANDARD(c17, "c17", - C, "ISO C 2017", - LineComment | C99 | C11 | C17 | Digraphs | HexFloat) -LANGSTANDARD_ALIAS(c17, "iso9899:2017") -LANGSTANDARD_ALIAS(c17, "c18") -LANGSTANDARD_ALIAS(c17, "iso9899:2018") -LANGSTANDARD(gnu17, "gnu17", - C, "ISO C 2017 with GNU extensions", - LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat) -LANGSTANDARD_ALIAS(gnu17, "gnu18") - -// C2x modes -LANGSTANDARD(c2x, "c2x", - C, "Working Draft for ISO C2x", - LineComment | C99 | C11 | C17 | C2x | Digraphs | HexFloat) -LANGSTANDARD(gnu2x, "gnu2x", - C, "Working Draft for ISO C2x with GNU extensions", - LineComment | C99 | C11 | C17 | C2x | Digraphs | GNUMode | HexFloat) - -// C++ modes -LANGSTANDARD(cxx98, "c++98", - CXX, "ISO C++ 1998 with amendments", - LineComment | CPlusPlus | Digraphs) -LANGSTANDARD_ALIAS(cxx98, "c++03") - -LANGSTANDARD(gnucxx98, "gnu++98", - CXX, "ISO C++ 1998 with amendments and GNU extensions", - LineComment | CPlusPlus | Digraphs | GNUMode) -LANGSTANDARD_ALIAS(gnucxx98, "gnu++03") - -LANGSTANDARD(cxx11, "c++11", - CXX, "ISO C++ 2011 with amendments", - LineComment | CPlusPlus | CPlusPlus11 | Digraphs) -LANGSTANDARD_ALIAS_DEPR(cxx11, "c++0x") - -LANGSTANDARD(gnucxx11, "gnu++11", CXX, - "ISO C++ 2011 with amendments and GNU extensions", - LineComment | CPlusPlus | CPlusPlus11 | Digraphs | GNUMode) -LANGSTANDARD_ALIAS_DEPR(gnucxx11, "gnu++0x") - -LANGSTANDARD(cxx14, "c++14", - CXX, "ISO C++ 2014 with amendments", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs) -LANGSTANDARD_ALIAS_DEPR(cxx14, "c++1y") - -LANGSTANDARD(gnucxx14, "gnu++14", - CXX, "ISO C++ 2014 with amendments and GNU extensions", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | - GNUMode) -LANGSTANDARD_ALIAS_DEPR(gnucxx14, "gnu++1y") - -LANGSTANDARD(cxx17, "c++17", - CXX, "ISO C++ 2017 with amendments", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | - Digraphs | HexFloat) -LANGSTANDARD_ALIAS_DEPR(cxx17, "c++1z") - -LANGSTANDARD(gnucxx17, "gnu++17", - CXX, "ISO C++ 2017 with amendments and GNU extensions", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | - Digraphs | HexFloat | GNUMode) -LANGSTANDARD_ALIAS_DEPR(gnucxx17, "gnu++1z") - -LANGSTANDARD(cxx2a, "c++2a", - CXX, "Working draft for ISO C++ 2020", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | - CPlusPlus2a | Digraphs | HexFloat) - -LANGSTANDARD(gnucxx2a, "gnu++2a", - CXX, "Working draft for ISO C++ 2020 with GNU extensions", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | - CPlusPlus2a | Digraphs | HexFloat | GNUMode) - -// OpenCL -LANGSTANDARD(opencl10, "cl1.0", - OpenCL, "OpenCL 1.0", - LineComment | C99 | Digraphs | HexFloat | OpenCL) -LANGSTANDARD_ALIAS_DEPR(opencl10, "cl") - -LANGSTANDARD(opencl11, "cl1.1", - OpenCL, "OpenCL 1.1", - LineComment | C99 | Digraphs | HexFloat | OpenCL) -LANGSTANDARD(opencl12, "cl1.2", - OpenCL, "OpenCL 1.2", - LineComment | C99 | Digraphs | HexFloat | OpenCL) -LANGSTANDARD(opencl20, "cl2.0", - OpenCL, "OpenCL 2.0", - LineComment | C99 | Digraphs | HexFloat | OpenCL) -LANGSTANDARD(openclcpp, "c++", - OpenCL, "C++ for OpenCL", - LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | - Digraphs | HexFloat | OpenCL) - -LANGSTANDARD_ALIAS_DEPR(opencl10, "CL") -LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1") -LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2") -LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0") -LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++") - -// CUDA -LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)", - LineComment | CPlusPlus | Digraphs) - -// HIP -LANGSTANDARD(hip, "hip", HIP, "HIP", - LineComment | CPlusPlus | Digraphs) - -#undef LANGSTANDARD -#undef LANGSTANDARD_ALIAS -#undef LANGSTANDARD_ALIAS_DEPR Index: cfe/trunk/include/clang/module.modulemap =================================================================== --- cfe/trunk/include/clang/module.modulemap +++ cfe/trunk/include/clang/module.modulemap @@ -100,7 +100,7 @@ requires cplusplus umbrella "Frontend" - textual header "Frontend/LangStandards.def" + textual header "Basic/LangStandards.def" module * { export * } } Index: cfe/trunk/lib/Basic/CMakeLists.txt =================================================================== --- cfe/trunk/lib/Basic/CMakeLists.txt +++ cfe/trunk/lib/Basic/CMakeLists.txt @@ -50,6 +50,7 @@ FixedPoint.cpp IdentifierTable.cpp LangOptions.cpp + LangStandards.cpp Module.cpp ObjCRuntime.cpp OpenMPKinds.cpp Index: cfe/trunk/lib/Basic/LangStandards.cpp =================================================================== --- cfe/trunk/lib/Basic/LangStandards.cpp +++ cfe/trunk/lib/Basic/LangStandards.cpp @@ -0,0 +1,45 @@ +//===--- LangStandards.cpp - Language Standard Definitions ----------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/LangStandard.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/ErrorHandling.h" +using namespace clang; + +#define LANGSTANDARD(id, name, lang, desc, features) \ + static const LangStandard Lang_##id = {name, desc, features, Language::lang}; +#include "clang/Basic/LangStandards.def" + +const LangStandard &LangStandard::getLangStandardForKind(Kind K) { + switch (K) { + case lang_unspecified: + llvm::report_fatal_error("getLangStandardForKind() on unspecified kind"); +#define LANGSTANDARD(id, name, lang, desc, features) \ + case lang_##id: return Lang_##id; +#include "clang/Basic/LangStandards.def" + } + llvm_unreachable("Invalid language kind!"); +} + +LangStandard::Kind LangStandard::getLangKind(StringRef Name) { + return llvm::StringSwitch(Name) +#define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id) +#define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id) +#include "clang/Basic/LangStandards.def" + .Default(lang_unspecified); +} + +const LangStandard *LangStandard::getLangStandardForName(StringRef Name) { + Kind K = getLangKind(Name); + if (K == lang_unspecified) + return nullptr; + + return &getLangStandardForKind(K); +} + + Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp @@ -15,6 +15,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclGroup.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/BackendUtil.h" @@ -1014,7 +1015,7 @@ void CodeGenAction::ExecuteAction() { // If this is an IR file, we have to treat it specially. - if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) { + if (getCurrentFileKind().getLanguage() == Language::LLVM_IR) { BackendAction BA = static_cast(Act); CompilerInstance &CI = getCompilerInstance(); std::unique_ptr OS = Index: cfe/trunk/lib/Frontend/ASTUnit.cpp =================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp +++ cfe/trunk/lib/Frontend/ASTUnit.cpp @@ -30,6 +30,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" @@ -1153,7 +1154,7 @@ InputKind::Source && "FIXME: AST inputs not yet supported here!"); assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != - InputKind::LLVM_IR && + Language::LLVM_IR && "IR inputs not support here!"); // Configure the various subsystems. @@ -1586,7 +1587,7 @@ InputKind::Source && "FIXME: AST inputs not yet supported here!"); assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != - InputKind::LLVM_IR && + Language::LLVM_IR && "IR inputs not support here!"); // Configure the various subsystems. @@ -2210,7 +2211,7 @@ InputKind::Source && "FIXME: AST inputs not yet supported here!"); assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != - InputKind::LLVM_IR && + Language::LLVM_IR && "IR inputs not support here!"); // Use the source and file managers that we were given. @@ -2667,17 +2668,17 @@ InputKind ASTUnit::getInputKind() const { auto &LangOpts = getLangOpts(); - InputKind::Language Lang; + Language Lang; if (LangOpts.OpenCL) - Lang = InputKind::OpenCL; + Lang = Language::OpenCL; else if (LangOpts.CUDA) - Lang = InputKind::CUDA; + Lang = Language::CUDA; else if (LangOpts.RenderScript) - Lang = InputKind::RenderScript; + Lang = Language::RenderScript; else if (LangOpts.CPlusPlus) - Lang = LangOpts.ObjC ? InputKind::ObjCXX : InputKind::CXX; + Lang = LangOpts.ObjC ? Language::ObjCXX : Language::CXX; else - Lang = LangOpts.ObjC ? InputKind::ObjC : InputKind::C; + Lang = LangOpts.ObjC ? Language::ObjC : Language::C; InputKind::Format Fmt = InputKind::Source; if (LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap) Index: cfe/trunk/lib/Frontend/CMakeLists.txt =================================================================== --- cfe/trunk/lib/Frontend/CMakeLists.txt +++ cfe/trunk/lib/Frontend/CMakeLists.txt @@ -32,7 +32,6 @@ HeaderIncludeGen.cpp InitHeaderSearch.cpp InitPreprocessor.cpp - LangStandards.cpp LayoutOverrideSource.cpp LogDiagnosticPrinter.cpp ModuleDependencyCollector.cpp Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInstance.cpp +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp @@ -13,6 +13,7 @@ #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Stack.h" #include "clang/Basic/TargetInfo.h" @@ -1002,14 +1003,14 @@ /// Determine the appropriate source input kind based on language /// options. -static InputKind::Language getLanguageFromOptions(const LangOptions &LangOpts) { +static Language getLanguageFromOptions(const LangOptions &LangOpts) { if (LangOpts.OpenCL) - return InputKind::OpenCL; + return Language::OpenCL; if (LangOpts.CUDA) - return InputKind::CUDA; + return Language::CUDA; if (LangOpts.ObjC) - return LangOpts.CPlusPlus ? InputKind::ObjCXX : InputKind::ObjC; - return LangOpts.CPlusPlus ? InputKind::CXX : InputKind::C; + return LangOpts.CPlusPlus ? Language::ObjCXX : Language::ObjC; + return LangOpts.CPlusPlus ? Language::CXX : Language::C; } /// Compile a module file for the given module, using the options Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -18,6 +18,7 @@ #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Sanitizers.h" #include "clang/Basic/SourceLocation.h" @@ -34,7 +35,6 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/FrontendPluginRegistry.h" -#include "clang/Frontend/LangStandard.h" #include "clang/Frontend/MigratorOptions.h" #include "clang/Frontend/PreprocessorOutputOptions.h" #include "clang/Frontend/Utils.h" @@ -122,7 +122,7 @@ static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, DiagnosticsEngine &Diags) { unsigned DefaultOpt = llvm::CodeGenOpt::None; - if (IK.getLanguage() == InputKind::OpenCL && !Args.hasArg(OPT_cl_opt_disable)) + if (IK.getLanguage() == Language::OpenCL && !Args.hasArg(OPT_cl_opt_disable)) DefaultOpt = llvm::CodeGenOpt::Default; if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { @@ -944,7 +944,7 @@ Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false); Opts.EnableSplitLTOUnit = Args.hasArg(OPT_fsplit_lto_unit); if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) { - if (IK.getLanguage() != InputKind::LLVM_IR) + if (IK.getLanguage() != Language::LLVM_IR) Diags.Report(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); @@ -1285,7 +1285,7 @@ if (Opts.DiagnosticsWithHotness && !UsingProfile && // An IR file will contain PGO as metadata - IK.getLanguage() != InputKind::LLVM_IR) + IK.getLanguage() != Language::LLVM_IR) Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo) << "-fdiagnostics-show-hotness"; @@ -1902,7 +1902,7 @@ << "ARC migration" << "ObjC migration"; } - InputKind DashX(InputKind::Unknown); + InputKind DashX(Language::Unknown); if (const Arg *A = Args.getLastArg(OPT_x)) { StringRef XValue = A->getValue(); @@ -1915,33 +1915,33 @@ // Principal languages. DashX = llvm::StringSwitch(XValue) - .Case("c", InputKind::C) - .Case("cl", InputKind::OpenCL) - .Case("cuda", InputKind::CUDA) - .Case("hip", InputKind::HIP) - .Case("c++", InputKind::CXX) - .Case("objective-c", InputKind::ObjC) - .Case("objective-c++", InputKind::ObjCXX) - .Case("renderscript", InputKind::RenderScript) - .Default(InputKind::Unknown); + .Case("c", Language::C) + .Case("cl", Language::OpenCL) + .Case("cuda", Language::CUDA) + .Case("hip", Language::HIP) + .Case("c++", Language::CXX) + .Case("objective-c", Language::ObjC) + .Case("objective-c++", Language::ObjCXX) + .Case("renderscript", Language::RenderScript) + .Default(Language::Unknown); // "objc[++]-cpp-output" is an acceptable synonym for // "objective-c[++]-cpp-output". if (DashX.isUnknown() && Preprocessed && !IsHeaderFile && !ModuleMap) DashX = llvm::StringSwitch(XValue) - .Case("objc", InputKind::ObjC) - .Case("objc++", InputKind::ObjCXX) - .Default(InputKind::Unknown); + .Case("objc", Language::ObjC) + .Case("objc++", Language::ObjCXX) + .Default(Language::Unknown); // Some special cases cannot be combined with suffixes. if (DashX.isUnknown() && !Preprocessed && !ModuleMap && !IsHeaderFile) DashX = llvm::StringSwitch(XValue) - .Case("cpp-output", InputKind(InputKind::C).getPreprocessed()) - .Case("assembler-with-cpp", InputKind::Asm) + .Case("cpp-output", InputKind(Language::C).getPreprocessed()) + .Case("assembler-with-cpp", Language::Asm) .Cases("ast", "pcm", - InputKind(InputKind::Unknown, InputKind::Precompiled)) - .Case("ir", InputKind::LLVM_IR) - .Default(InputKind::Unknown); + InputKind(Language::Unknown, InputKind::Precompiled)) + .Case("ir", Language::LLVM_IR) + .Default(Language::Unknown); if (DashX.isUnknown()) Diags.Report(diag::err_drv_invalid_value) @@ -1965,7 +1965,7 @@ StringRef(Inputs[i]).rsplit('.').second); // FIXME: Warn on this? if (IK.isUnknown()) - IK = InputKind::C; + IK = Language::C; // FIXME: Remove this hack. if (i == 0) DashX = IK; @@ -2139,7 +2139,7 @@ // FIXME: Perhaps a better model would be for a single source file to have // multiple language standards (C / C++ std, ObjC std, OpenCL std, OpenMP std) // simultaneously active? - if (IK.getLanguage() == InputKind::Asm) { + if (IK.getLanguage() == Language::Asm) { Opts.AsmPreprocessor = 1; } else if (IK.isObjectiveC()) { Opts.ObjC = 1; @@ -2148,17 +2148,17 @@ if (LangStd == LangStandard::lang_unspecified) { // Based on the base language, pick one. switch (IK.getLanguage()) { - case InputKind::Unknown: - case InputKind::LLVM_IR: + case Language::Unknown: + case Language::LLVM_IR: llvm_unreachable("Invalid input kind!"); - case InputKind::OpenCL: + case Language::OpenCL: LangStd = LangStandard::lang_opencl10; break; - case InputKind::CUDA: + case Language::CUDA: LangStd = LangStandard::lang_cuda; break; - case InputKind::Asm: - case InputKind::C: + case Language::Asm: + case Language::C: #if defined(CLANG_DEFAULT_STD_C) LangStd = CLANG_DEFAULT_STD_C; #else @@ -2169,25 +2169,25 @@ LangStd = LangStandard::lang_gnu11; #endif break; - case InputKind::ObjC: + case Language::ObjC: #if defined(CLANG_DEFAULT_STD_C) LangStd = CLANG_DEFAULT_STD_C; #else LangStd = LangStandard::lang_gnu11; #endif break; - case InputKind::CXX: - case InputKind::ObjCXX: + case Language::CXX: + case Language::ObjCXX: #if defined(CLANG_DEFAULT_STD_CXX) LangStd = CLANG_DEFAULT_STD_CXX; #else LangStd = LangStandard::lang_gnucxx14; #endif break; - case InputKind::RenderScript: + case Language::RenderScript: LangStd = LangStandard::lang_c99; break; - case InputKind::HIP: + case Language::HIP: LangStd = LangStandard::lang_hip; break; } @@ -2244,13 +2244,13 @@ } } - Opts.HIP = IK.getLanguage() == InputKind::HIP; - Opts.CUDA = IK.getLanguage() == InputKind::CUDA || Opts.HIP; + Opts.HIP = IK.getLanguage() == Language::HIP; + Opts.CUDA = IK.getLanguage() == Language::CUDA || Opts.HIP; if (Opts.CUDA) // Set default FP_CONTRACT to FAST. Opts.setDefaultFPContractMode(LangOptions::FPC_Fast); - Opts.RenderScript = IK.getLanguage() == InputKind::RenderScript; + Opts.RenderScript = IK.getLanguage() == Language::RenderScript; if (Opts.RenderScript) { Opts.NativeHalfType = 1; Opts.NativeHalfArgsAndReturns = 1; @@ -2298,32 +2298,31 @@ static bool IsInputCompatibleWithStandard(InputKind IK, const LangStandard &S) { switch (IK.getLanguage()) { - case InputKind::Unknown: - case InputKind::LLVM_IR: + case Language::Unknown: + case Language::LLVM_IR: llvm_unreachable("should not parse language flags for this input"); - case InputKind::C: - case InputKind::ObjC: - case InputKind::RenderScript: - return S.getLanguage() == InputKind::C; - - case InputKind::OpenCL: - return S.getLanguage() == InputKind::OpenCL; - - case InputKind::CXX: - case InputKind::ObjCXX: - return S.getLanguage() == InputKind::CXX; + case Language::C: + case Language::ObjC: + case Language::RenderScript: + return S.getLanguage() == Language::C; + + case Language::OpenCL: + return S.getLanguage() == Language::OpenCL; + + case Language::CXX: + case Language::ObjCXX: + return S.getLanguage() == Language::CXX; - case InputKind::CUDA: + case Language::CUDA: // FIXME: What -std= values should be permitted for CUDA compilations? - return S.getLanguage() == InputKind::CUDA || - S.getLanguage() == InputKind::CXX; + return S.getLanguage() == Language::CUDA || + S.getLanguage() == Language::CXX; - case InputKind::HIP: - return S.getLanguage() == InputKind::CXX || - S.getLanguage() == InputKind::HIP; + case Language::HIP: + return S.getLanguage() == Language::CXX || S.getLanguage() == Language::HIP; - case InputKind::Asm: + case Language::Asm: // Accept (and ignore) all -std= values. // FIXME: The -std= value is not ignored; it affects the tokenization // and preprocessing rules if we're preprocessing this asm input. @@ -2336,29 +2335,29 @@ /// Get language name for given input kind. static const StringRef GetInputKindName(InputKind IK) { switch (IK.getLanguage()) { - case InputKind::C: + case Language::C: return "C"; - case InputKind::ObjC: + case Language::ObjC: return "Objective-C"; - case InputKind::CXX: + case Language::CXX: return "C++"; - case InputKind::ObjCXX: + case Language::ObjCXX: return "Objective-C++"; - case InputKind::OpenCL: + case Language::OpenCL: return "OpenCL"; - case InputKind::CUDA: + case Language::CUDA: return "CUDA"; - case InputKind::RenderScript: + case Language::RenderScript: return "RenderScript"; - case InputKind::HIP: + case Language::HIP: return "HIP"; - case InputKind::Asm: + case Language::Asm: return "Asm"; - case InputKind::LLVM_IR: + case Language::LLVM_IR: return "LLVM IR"; - case InputKind::Unknown: + case Language::Unknown: break; } llvm_unreachable("unknown input language"); @@ -2371,13 +2370,7 @@ // FIXME: Cleanup per-file based stuff. LangStandard::Kind LangStd = LangStandard::lang_unspecified; if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { - LangStd = llvm::StringSwitch(A->getValue()) -#define LANGSTANDARD(id, name, lang, desc, features) \ - .Case(name, LangStandard::lang_##id) -#define LANGSTANDARD_ALIAS(id, alias) \ - .Case(alias, LangStandard::lang_##id) -#include "clang/Frontend/LangStandards.def" - .Default(LangStandard::lang_unspecified); + LangStd = LangStandard::getLangKind(A->getValue()); if (LangStd == LangStandard::lang_unspecified) { Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); @@ -2395,13 +2388,13 @@ #define LANGSTANDARD_ALIAS(id, alias) \ if (KindValue == LangStandard::lang_##id) ++NumAliases; #define LANGSTANDARD_ALIAS_DEPR(id, alias) -#include "clang/Frontend/LangStandards.def" +#include "clang/Basic/LangStandards.def" Diag << NumAliases; #define LANGSTANDARD(id, name, lang, desc, features) #define LANGSTANDARD_ALIAS(id, alias) \ if (KindValue == LangStandard::lang_##id) Diag << alias; #define LANGSTANDARD_ALIAS_DEPR(id, alias) -#include "clang/Frontend/LangStandards.def" +#include "clang/Basic/LangStandards.def" } } } else { @@ -3391,7 +3384,7 @@ Res.getFileSystemOpts().WorkingDir); llvm::Triple T(Res.getTargetOpts().Triple); if (DashX.getFormat() == InputKind::Precompiled || - DashX.getLanguage() == InputKind::LLVM_IR) { + DashX.getLanguage() == Language::LLVM_IR) { // ObjCAAutoRefCount and Sanitize LangOpts are used to setup the // PassManager in BackendUtil.cpp. They need to be initializd no matter // what the input type is. @@ -3405,7 +3398,7 @@ Diags, LangOpts.Sanitize); } else { // Other LangOpts are only initialized when the input is not AST or LLVM IR. - // FIXME: Should we really be calling this for an InputKind::Asm input? + // FIXME: Should we really be calling this for an Language::Asm input? ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(), Res.getPreprocessorOpts(), Diags); if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) Index: cfe/trunk/lib/Frontend/FrontendAction.cpp =================================================================== --- cfe/trunk/lib/Frontend/FrontendAction.cpp +++ cfe/trunk/lib/Frontend/FrontendAction.cpp @@ -10,6 +10,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclGroup.h" +#include "clang/Basic/LangStandard.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -683,7 +684,7 @@ CI.getSourceManager().setAllFilesAreTransient(true); // IR files bypass the rest of initialization. - if (Input.getKind().getLanguage() == InputKind::LLVM_IR) { + if (Input.getKind().getLanguage() == Language::LLVM_IR) { assert(hasIRSupport() && "This action does not have IR file support!"); Index: cfe/trunk/lib/Frontend/FrontendActions.cpp =================================================================== --- cfe/trunk/lib/Frontend/FrontendActions.cpp +++ cfe/trunk/lib/Frontend/FrontendActions.cpp @@ -9,6 +9,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/AST/ASTConsumer.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LangStandard.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -832,19 +833,19 @@ void PrintPreambleAction::ExecuteAction() { switch (getCurrentFileKind().getLanguage()) { - case InputKind::C: - case InputKind::CXX: - case InputKind::ObjC: - case InputKind::ObjCXX: - case InputKind::OpenCL: - case InputKind::CUDA: - case InputKind::HIP: + case Language::C: + case Language::CXX: + case Language::ObjC: + case Language::ObjCXX: + case Language::OpenCL: + case Language::CUDA: + case Language::HIP: break; - case InputKind::Unknown: - case InputKind::Asm: - case InputKind::LLVM_IR: - case InputKind::RenderScript: + case Language::Unknown: + case Language::Asm: + case Language::LLVM_IR: + case Language::RenderScript: // We can't do anything with these. return; } Index: cfe/trunk/lib/Frontend/FrontendOptions.cpp =================================================================== --- cfe/trunk/lib/Frontend/FrontendOptions.cpp +++ cfe/trunk/lib/Frontend/FrontendOptions.cpp @@ -7,28 +7,29 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/FrontendOptions.h" +#include "clang/Basic/LangStandard.h" #include "llvm/ADT/StringSwitch.h" using namespace clang; InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) { return llvm::StringSwitch(Extension) - .Cases("ast", "pcm", InputKind(InputKind::Unknown, InputKind::Precompiled)) - .Case("c", InputKind::C) - .Cases("S", "s", InputKind::Asm) - .Case("i", InputKind(InputKind::C).getPreprocessed()) - .Case("ii", InputKind(InputKind::CXX).getPreprocessed()) - .Case("cui", InputKind(InputKind::CUDA).getPreprocessed()) - .Case("m", InputKind::ObjC) - .Case("mi", InputKind(InputKind::ObjC).getPreprocessed()) - .Cases("mm", "M", InputKind::ObjCXX) - .Case("mii", InputKind(InputKind::ObjCXX).getPreprocessed()) - .Cases("C", "cc", "cp", InputKind::CXX) - .Cases("cpp", "CPP", "c++", "cxx", "hpp", InputKind::CXX) - .Case("cppm", InputKind::CXX) - .Case("iim", InputKind(InputKind::CXX).getPreprocessed()) - .Case("cl", InputKind::OpenCL) - .Case("cu", InputKind::CUDA) - .Cases("ll", "bc", InputKind::LLVM_IR) - .Default(InputKind::Unknown); + .Cases("ast", "pcm", InputKind(Language::Unknown, InputKind::Precompiled)) + .Case("c", Language::C) + .Cases("S", "s", Language::Asm) + .Case("i", InputKind(Language::C).getPreprocessed()) + .Case("ii", InputKind(Language::CXX).getPreprocessed()) + .Case("cui", InputKind(Language::CUDA).getPreprocessed()) + .Case("m", Language::ObjC) + .Case("mi", InputKind(Language::ObjC).getPreprocessed()) + .Cases("mm", "M", Language::ObjCXX) + .Case("mii", InputKind(Language::ObjCXX).getPreprocessed()) + .Cases("C", "cc", "cp", Language::CXX) + .Cases("cpp", "CPP", "c++", "cxx", "hpp", Language::CXX) + .Case("cppm", Language::CXX) + .Case("iim", InputKind(Language::CXX).getPreprocessed()) + .Case("cl", Language::OpenCL) + .Case("cu", Language::CUDA) + .Cases("ll", "bc", Language::LLVM_IR) + .Default(Language::Unknown); } Index: cfe/trunk/lib/Frontend/LangStandards.cpp =================================================================== --- cfe/trunk/lib/Frontend/LangStandards.cpp +++ cfe/trunk/lib/Frontend/LangStandards.cpp @@ -1,42 +0,0 @@ -//===--- LangStandards.cpp - Language Standard Definitions ----------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "clang/Frontend/LangStandard.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/Support/ErrorHandling.h" -using namespace clang; -using namespace clang::frontend; - -#define LANGSTANDARD(id, name, lang, desc, features) \ -static const LangStandard Lang_##id = { name, desc, features, InputKind::lang }; -#include "clang/Frontend/LangStandards.def" - -const LangStandard &LangStandard::getLangStandardForKind(Kind K) { - switch (K) { - case lang_unspecified: - llvm::report_fatal_error("getLangStandardForKind() on unspecified kind"); -#define LANGSTANDARD(id, name, lang, desc, features) \ - case lang_##id: return Lang_##id; -#include "clang/Frontend/LangStandards.def" - } - llvm_unreachable("Invalid language kind!"); -} - -const LangStandard *LangStandard::getLangStandardForName(StringRef Name) { - Kind K = llvm::StringSwitch(Name) -#define LANGSTANDARD(id, name, lang, desc, features) \ - .Case(name, lang_##id) -#include "clang/Frontend/LangStandards.def" - .Default(lang_unspecified); - if (K == lang_unspecified) - return nullptr; - - return &getLangStandardForKind(K); -} - - Index: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp +++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp @@ -12,6 +12,7 @@ #include "clang/Frontend/PrecompiledPreamble.h" #include "clang/AST/DeclObjC.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" @@ -303,7 +304,7 @@ Clang->getFrontendOpts().Inputs[0].getKind().getFormat() != InputKind::Source || Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() == - InputKind::LLVM_IR) { + Language::LLVM_IR) { return BuildPreambleError::BadInputs; } Index: cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp =================================================================== --- cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp +++ cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp @@ -9,6 +9,7 @@ #include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/AST/ASTConsumer.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/LangStandard.h" #include "clang/Config/config.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" @@ -250,7 +251,7 @@ Instance.getFrontendOpts().DisableFree = false; Instance.getFrontendOpts().Inputs.clear(); Instance.getFrontendOpts().Inputs.emplace_back( - Filename, InputKind(InputKind::Unknown, InputKind::Precompiled)); + Filename, InputKind(Language::Unknown, InputKind::Precompiled)); Instance.getFrontendOpts().ModuleFiles.clear(); Instance.getFrontendOpts().ModuleMapFiles.clear(); // Don't recursively rewrite imports. We handle them all at the top level. Index: cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp +++ cfe/trunk/lib/StaticAnalyzer/Frontend/ModelInjector.cpp @@ -9,6 +9,7 @@ #include "ModelInjector.h" #include "clang/AST/Decl.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LangStandard.h" #include "clang/Basic/Stack.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" @@ -65,7 +66,7 @@ auto Invocation = std::make_shared(CI.getInvocation()); FrontendOptions &FrontendOpts = Invocation->getFrontendOpts(); - InputKind IK = InputKind::CXX; // FIXME + InputKind IK = Language::CXX; // FIXME FrontendOpts.Inputs.clear(); FrontendOpts.Inputs.emplace_back(fileName, IK); FrontendOpts.DisableFree = true; Index: cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp =================================================================== --- cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp +++ cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp @@ -42,9 +42,9 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/LangStandard.h" #include "clang/Driver/Options.h" #include "clang/Driver/Types.h" -#include "clang/Frontend/LangStandard.h" #include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" @@ -249,15 +249,15 @@ } // Map the language from the --std flag to that of the -x flag. - static types::ID toType(InputKind::Language Lang) { + static types::ID toType(Language Lang) { switch (Lang) { - case InputKind::C: + case Language::C: return types::TY_C; - case InputKind::CXX: + case Language::CXX: return types::TY_CXX; - case InputKind::ObjC: + case Language::ObjC: return types::TY_ObjC; - case InputKind::ObjCXX: + case Language::ObjCXX: return types::TY_ObjCXX; default: return types::TY_INVALID; @@ -297,15 +297,8 @@ // Try to interpret the argument as '-std='. Optional tryParseStdArg(const llvm::opt::Arg &Arg) { using namespace driver::options; - if (Arg.getOption().matches(ClangCLMode ? OPT__SLASH_std : OPT_std_EQ)) { - return llvm::StringSwitch(Arg.getValue()) -#define LANGSTANDARD(id, name, lang, ...) .Case(name, LangStandard::lang_##id) -#define LANGSTANDARD_ALIAS(id, alias) .Case(alias, LangStandard::lang_##id) -#include "clang/Frontend/LangStandards.def" -#undef LANGSTANDARD_ALIAS -#undef LANGSTANDARD - .Default(LangStandard::lang_unspecified); - } + if (Arg.getOption().matches(ClangCLMode ? OPT__SLASH_std : OPT_std_EQ)) + return LangStandard::getLangKind(Arg.getValue()); return None; } }; Index: cfe/trunk/unittests/Frontend/CodeGenActionTest.cpp =================================================================== --- cfe/trunk/unittests/Frontend/CodeGenActionTest.cpp +++ cfe/trunk/unittests/Frontend/CodeGenActionTest.cpp @@ -10,8 +10,9 @@ // //===----------------------------------------------------------------------===// -#include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" +#include "clang/Basic/LangStandard.h" +#include "clang/CodeGen/BackendUtil.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" @@ -45,7 +46,7 @@ "test.cc", MemoryBuffer::getMemBuffer("").release()); Invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = EmitLLVM; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler; Index: cfe/trunk/unittests/Frontend/FrontendActionTest.cpp =================================================================== --- cfe/trunk/unittests/Frontend/FrontendActionTest.cpp +++ cfe/trunk/unittests/Frontend/FrontendActionTest.cpp @@ -10,6 +10,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/LangStandard.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" @@ -84,7 +85,7 @@ "test.cc", MemoryBuffer::getMemBuffer("int main() { float x; }").release()); invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; @@ -104,7 +105,7 @@ "test.cc", MemoryBuffer::getMemBuffer("int main() { float x; }").release()); invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; @@ -131,7 +132,7 @@ "};\n" "B c() { return B(); }\n").release()); invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; @@ -177,7 +178,7 @@ "test.cc", MemoryBuffer::getMemBuffer("int main() { float x; }").release()); Invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler; @@ -238,7 +239,7 @@ "int main() { foo(); }") .release()); Invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler; @@ -270,7 +271,7 @@ "test.h", MemoryBuffer::getMemBuffer("int foo(void) { return 1; }\n").release()); Invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.h", InputKind::C)); + FrontendInputFile("test.h", Language::C)); Invocation->getFrontendOpts().OutputFile = StringRef(PCHFilename); Invocation->getFrontendOpts().ProgramAction = frontend::GeneratePCH; Invocation->getTargetOpts().Triple = "x86_64-apple-darwin19.0.0"; Index: cfe/trunk/unittests/Frontend/OutputStreamTest.cpp =================================================================== --- cfe/trunk/unittests/Frontend/OutputStreamTest.cpp +++ cfe/trunk/unittests/Frontend/OutputStreamTest.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/LangStandard.h" #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/Frontend/CompilerInstance.h" @@ -24,7 +25,7 @@ Invocation->getPreprocessorOpts().addRemappedFile( "test.cc", MemoryBuffer::getMemBuffer("").release()); Invocation->getFrontendOpts().Inputs.push_back( - FrontendInputFile("test.cc", InputKind::CXX)); + FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = EmitBC; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler;