clang 24.0.0git
TextEncoding.h
Go to the documentation of this file.
1//===-- clang/Lex/TextEncoding.h - Text Encoding Conversion ------*- 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_LEX_TEXTENCODING_H
10#define LLVM_CLANG_LEX_TEXTENCODING_H
11
13#include "llvm/ADT/StringRef.h"
14
15namespace llvm {
16class TextEncodingConverter;
17} // namespace llvm
18
19namespace clang {
20class TargetInfo;
21
24 CA_ToLiteralEncodingForAsm, // IBM-1047 on z/OS, UTF-8 on other platforms
26};
27
29 llvm::StringRef LiteralEncoding;
30 std::unique_ptr<llvm::TextEncodingConverter> ToLiteralEncodingConverter;
31 std::unique_ptr<llvm::TextEncodingConverter> FromLiteralEncodingConverter;
32
33 // Only non-null on z/OS, where the system default encoding is IBM-1047.
34 // This converts UTF-8 to IBM-1047 for asm string literals so that
35 // octal/hex escape sequences are interpreted as IBM-1047 code points,
36 // regardless of -fexec-charset.
37 std::unique_ptr<llvm::TextEncodingConverter> ToIBM1047Converter;
38 std::unique_ptr<llvm::TextEncodingConverter> FromIBM1047Converter;
39
40public:
41 llvm::TextEncodingConverter *getConverter(ConversionAction Action) const;
42
43 /// Returns the converter from the literal encoding (-fexec-charset) to UTF-8,
44 /// or nullptr if the literal encoding is UTF-8.
45 llvm::TextEncodingConverter *getFromLiteralEncodingConverter() const {
46 return FromLiteralEncodingConverter.get();
47 }
48
49 /// Returns the converter from IBM-1047 to UTF-8, or nullptr if not on z/OS.
50 llvm::TextEncodingConverter *getzOSFromAsmLiteralEncodingConverter() const {
51 return FromIBM1047Converter.get();
52 }
53
54 static std::error_code
56 TargetInfo &TInfo);
57
58 llvm::StringRef getLiteralEncoding() { return LiteralEncoding; }
59};
60} // namespace clang
61#endif
Defines the clang::LangOptions interface.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Exposes information about the current target.
Definition TargetInfo.h:228
llvm::TextEncodingConverter * getzOSFromAsmLiteralEncodingConverter() const
Returns the converter from IBM-1047 to UTF-8, or nullptr if not on z/OS.
llvm::StringRef getLiteralEncoding()
static std::error_code setConvertersFromOptions(TextEncoding &TE, const clang::LangOptions &Opts, TargetInfo &TInfo)
llvm::TextEncodingConverter * getConverter(ConversionAction Action) const
llvm::TextEncodingConverter * getFromLiteralEncodingConverter() const
Returns the converter from the literal encoding (-fexec-charset) to UTF-8, or nullptr if the literal ...
Top level wrappers for InstallAPI frontend operations.
ConversionAction
@ CA_ToLiteralEncodingForAsm
@ CA_NoConversion
@ CA_ToLiteralEncoding
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30