clang  15.0.0git
LangStandard.h
Go to the documentation of this file.
1 //===--- LangStandard.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_BASIC_LANGSTANDARD_H
10 #define LLVM_CLANG_BASIC_LANGSTANDARD_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 
15 namespace llvm {
16 class Triple;
17 }
18 
19 namespace clang {
20 
21 /// The language for the input, used to select and validate the language
22 /// standard and possible actions.
23 enum class Language : uint8_t {
24  Unknown,
25 
26  /// Assembly: we accept this only so that we can preprocess it.
27  Asm,
28 
29  /// LLVM IR: we accept this so that we can run the optimizer on it,
30  /// and compile it to assembly or object code.
31  LLVM_IR,
32 
33  ///@{ Languages that the frontend can parse and compile.
34  C,
35  CXX,
36  ObjC,
37  ObjCXX,
38  OpenCL,
39  OpenCLCXX,
40  CUDA,
42  HIP,
43  HLSL,
44  ///@}
45 };
46 
48  LineComment = (1 << 0),
49  C99 = (1 << 1),
50  C11 = (1 << 2),
51  C17 = (1 << 3),
52  C2x = (1 << 4),
53  CPlusPlus = (1 << 5),
54  CPlusPlus11 = (1 << 6),
55  CPlusPlus14 = (1 << 7),
56  CPlusPlus17 = (1 << 8),
57  CPlusPlus20 = (1 << 9),
58  CPlusPlus2b = (1 << 10),
59  Digraphs = (1 << 11),
60  GNUMode = (1 << 12),
61  HexFloat = (1 << 13),
62  OpenCL = (1 << 14),
63  HLSL = (1 << 15)
64 };
65 
66 /// LangStandard - Information about the properties of a particular language
67 /// standard.
68 struct LangStandard {
69  enum Kind {
70 #define LANGSTANDARD(id, name, lang, desc, features) \
71  lang_##id,
72 #include "clang/Basic/LangStandards.def"
74  };
75 
76  const char *ShortName;
77  const char *Description;
78  unsigned Flags;
80 
81 public:
82  /// getName - Get the name of this standard.
83  const char *getName() const { return ShortName; }
84 
85  /// getDescription - Get the description of this standard.
86  const char *getDescription() const { return Description; }
87 
88  /// Get the language that this standard describes.
89  clang::Language getLanguage() const { return Language; }
90 
91  /// Language supports '//' comments.
92  bool hasLineComments() const { return Flags & LineComment; }
93 
94  /// isC99 - Language is a superset of C99.
95  bool isC99() const { return Flags & C99; }
96 
97  /// isC11 - Language is a superset of C11.
98  bool isC11() const { return Flags & C11; }
99 
100  /// isC17 - Language is a superset of C17.
101  bool isC17() const { return Flags & C17; }
102 
103  /// isC2x - Language is a superset of C2x.
104  bool isC2x() const { return Flags & C2x; }
105 
106  /// isCPlusPlus - Language is a C++ variant.
107  bool isCPlusPlus() const { return Flags & CPlusPlus; }
108 
109  /// isCPlusPlus11 - Language is a C++11 variant (or later).
110  bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
111 
112  /// isCPlusPlus14 - Language is a C++14 variant (or later).
113  bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
114 
115  /// isCPlusPlus17 - Language is a C++17 variant (or later).
116  bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
117 
118  /// isCPlusPlus20 - Language is a C++20 variant (or later).
119  bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
120 
121  /// isCPlusPlus2b - Language is a post-C++20 variant (or later).
122  bool isCPlusPlus2b() const { return Flags & CPlusPlus2b; }
123 
124  /// hasDigraphs - Language supports digraphs.
125  bool hasDigraphs() const { return Flags & Digraphs; }
126 
127  /// isGNUMode - Language includes GNU extensions.
128  bool isGNUMode() const { return Flags & GNUMode; }
129 
130  /// hasHexFloats - Language supports hexadecimal float constants.
131  bool hasHexFloats() const { return Flags & HexFloat; }
132 
133  /// isOpenCL - Language is a OpenCL variant.
134  bool isOpenCL() const { return Flags & OpenCL; }
135 
136  static Kind getLangKind(StringRef Name);
137  static const LangStandard &getLangStandardForKind(Kind K);
138  static const LangStandard *getLangStandardForName(StringRef Name);
139 };
140 
142  const llvm::Triple &T);
143 
144 } // end namespace clang
145 
146 #endif
clang::OpenCL
@ OpenCL
Definition: LangStandard.h:62
clang::Language::CUDA
@ CUDA
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::LangStandard::isC99
bool isC99() const
isC99 - Language is a superset of C99.
Definition: LangStandard.h:95
clang::LangStandard::isCPlusPlus14
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
Definition: LangStandard.h:113
clang::LangStandard::hasDigraphs
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
Definition: LangStandard.h:125
clang::Language::OpenCLCXX
@ OpenCLCXX
clang::C99
@ C99
Definition: LangStandard.h:49
clang::CPlusPlus14
@ CPlusPlus14
Definition: LangStandard.h:55
clang::Language::Asm
@ Asm
Assembly: we accept this only so that we can preprocess it.
clang::LangStandard::isOpenCL
bool isOpenCL() const
isOpenCL - Language is a OpenCL variant.
Definition: LangStandard.h:134
clang::LangStandard::isCPlusPlus2b
bool isCPlusPlus2b() const
isCPlusPlus2b - Language is a post-C++20 variant (or later).
Definition: LangStandard.h:122
clang::LangStandard::Flags
unsigned Flags
Definition: LangStandard.h:78
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:56
clang::Digraphs
@ Digraphs
Definition: LangStandard.h:59
clang::LangStandard::Kind
Kind
Definition: LangStandard.h:69
clang::LangStandard::getLangKind
static Kind getLangKind(StringRef Name)
Definition: LangStandards.cpp:31
clang::Language::RenderScript
@ RenderScript
clang::LangStandard::getName
const char * getName() const
getName - Get the name of this standard.
Definition: LangStandard.h:83
clang::C11
@ C11
Definition: LangStandard.h:50
clang::LangStandard::hasLineComments
bool hasLineComments() const
Language supports '//' comments.
Definition: LangStandard.h:92
clang::HexFloat
@ HexFloat
Definition: LangStandard.h:61
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::LangStandard::hasHexFloats
bool hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
Definition: LangStandard.h:131
clang::LangStandard::isCPlusPlus
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
Definition: LangStandard.h:107
clang::CPlusPlus20
@ CPlusPlus20
Definition: LangStandard.h:57
clang::Language::C
@ C
Languages that the frontend can parse and compile.
clang::LangStandard::isCPlusPlus20
bool isCPlusPlus20() const
isCPlusPlus20 - Language is a C++20 variant (or later).
Definition: LangStandard.h:119
clang::CPlusPlus2b
@ CPlusPlus2b
Definition: LangStandard.h:58
clang::LangStandard::ShortName
const char * ShortName
Definition: LangStandard.h:76
clang::LangStandard::isC2x
bool isC2x() const
isC2x - Language is a superset of C2x.
Definition: LangStandard.h:104
clang::Language
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
clang::LangStandard::isCPlusPlus11
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
Definition: LangStandard.h:110
clang::LangStandard::isC11
bool isC11() const
isC11 - Language is a superset of C11.
Definition: LangStandard.h:98
clang::LangStandard::getLanguage
clang::Language getLanguage() const
Get the language that this standard describes.
Definition: LangStandard.h:89
clang::Language::CXX
@ CXX
clang::C2x
@ C2x
Definition: LangStandard.h:52
clang::Language::ObjCXX
@ ObjCXX
clang::Language::LLVM_IR
@ LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
clang::LangStandard::getLangStandardForName
static const LangStandard * getLangStandardForName(StringRef Name)
Definition: LangStandards.cpp:39
LLVM.h
clang::Language::ObjC
@ ObjC
clang::LangStandard::lang_unspecified
@ lang_unspecified
Definition: LangStandard.h:73
clang::LangStandard::isC17
bool isC17() const
isC17 - Language is a superset of C17.
Definition: LangStandard.h:101
clang::LangStandard
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:68
clang::LangFeatures
LangFeatures
Definition: LangStandard.h:47
clang
Definition: CalledOnceCheck.h:17
clang::LangStandard::Description
const char * Description
Definition: LangStandard.h:77
clang::getDefaultLanguageStandard
LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, const llvm::Triple &T)
Definition: LangStandards.cpp:47
clang::CPlusPlus11
@ CPlusPlus11
Definition: LangStandard.h:54
clang::Language::Unknown
@ Unknown
clang::Language::HIP
@ HIP
clang::LangStandard::Language
clang::Language Language
Definition: LangStandard.h:79
clang::GNUMode
@ GNUMode
Definition: LangStandard.h:60
clang::HLSL
@ HLSL
Definition: LangStandard.h:63
clang::LineComment
@ LineComment
Definition: LangStandard.h:48
clang::C17
@ C17
Definition: LangStandard.h:51
clang::LangStandard::isCPlusPlus17
bool isCPlusPlus17() const
isCPlusPlus17 - Language is a C++17 variant (or later).
Definition: LangStandard.h:116
clang::LangStandard::isGNUMode
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
Definition: LangStandard.h:128
clang::LangStandard::getDescription
const char * getDescription() const
getDescription - Get the description of this standard.
Definition: LangStandard.h:86
clang::LangStandard::getLangStandardForKind
static const LangStandard & getLangStandardForKind(Kind K)
Definition: LangStandards.cpp:20
clang::OpenCL
@ OpenCL