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
15namespace llvm {
16class Triple;
17}
18
19namespace clang {
20
21/// The language for the input, used to select and validate the language
22/// standard and possible actions.
23enum 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,
41  RenderScript,
42  HIP,
43  HLSL,
44  ///@}
45};
46StringRef languageToString(Language L);
47
48enum LangFeatures {
49  LineComment = (1 << 0),
50  C99 = (1 << 1),
51  C11 = (1 << 2),
52  C17 = (1 << 3),
53  C23 = (1 << 4),
54  CPlusPlus = (1 << 5),
55  CPlusPlus11 = (1 << 6),
56  CPlusPlus14 = (1 << 7),
57  CPlusPlus17 = (1 << 8),
58  CPlusPlus20 = (1 << 9),
59  CPlusPlus23 = (1 << 10),
60  CPlusPlus26 = (1 << 11),
61  Digraphs = (1 << 12),
62  GNUMode = (1 << 13),
63  HexFloat = (1 << 14),
64  OpenCL = (1 << 15),
65  HLSL = (1 << 16)
66};
67
68/// LangStandard - Information about the properties of a particular language
69/// standard.
70struct LangStandard {
71  enum Kind {
72#define LANGSTANDARD(id, name, lang, desc, features) \
73    lang_##id,
74#include "clang/Basic/LangStandards.def"
75    lang_unspecified
76  };
77
78  const char *ShortName;
79  const char *Description;
80  unsigned Flags;
81  clang::Language Language;
82
83public:
84  /// getName - Get the name of this standard.
85  const char *getName() const { return ShortName; }
86
87  /// getDescription - Get the description of this standard.
88  const char *getDescription() const { return Description; }
89
90  /// Get the language that this standard describes.
91  clang::Language getLanguage() const { return Language; }
92
93  /// Language supports '//' comments.
94  bool hasLineComments() const { return Flags & LineComment; }
95
96  /// isC99 - Language is a superset of C99.
97  bool isC99() const { return Flags & C99; }
98
99  /// isC11 - Language is a superset of C11.
100  bool isC11() const { return Flags & C11; }
101
102  /// isC17 - Language is a superset of C17.
103  bool isC17() const { return Flags & C17; }
104
105  /// isC23 - Language is a superset of C23.
106  bool isC23() const { return Flags & C23; }
107
108  /// isCPlusPlus - Language is a C++ variant.
109  bool isCPlusPlus() const { return Flags & CPlusPlus; }
110
111  /// isCPlusPlus11 - Language is a C++11 variant (or later).
112  bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
113
114  /// isCPlusPlus14 - Language is a C++14 variant (or later).
115  bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
116
117  /// isCPlusPlus17 - Language is a C++17 variant (or later).
118  bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
119
120  /// isCPlusPlus20 - Language is a C++20 variant (or later).
121  bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
122
123  /// isCPlusPlus23 - Language is a post-C++23 variant (or later).
124  bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
125
126  /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
127  bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
128
129  /// hasDigraphs - Language supports digraphs.
130  bool hasDigraphs() const { return Flags & Digraphs; }
131
132  /// isGNUMode - Language includes GNU extensions.
133  bool isGNUMode() const { return Flags & GNUMode; }
134
135  /// hasHexFloats - Language supports hexadecimal float constants.
136  bool hasHexFloats() const { return Flags & HexFloat; }
137
138  /// isOpenCL - Language is a OpenCL variant.
139  bool isOpenCL() const { return Flags & OpenCL; }
140
141  static Kind getLangKind(StringRef Name);
142  static const LangStandard &getLangStandardForKind(Kind K);
143  static const LangStandard *getLangStandardForName(StringRef Name);
144};
145
146LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang,
147                                              const llvm::Triple &T);
148
149}  // end namespace clang
150
151#endif
152