Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SyncScope.h"
#include "clang/Basic/TypeTraits.h"
#include "clang/Lex/LiteralConverter.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -2063,6 +2064,11 @@ class PredefinedExpr final
return getIdentKindName(getIdentKind());
}

static std::string
ComputeNameAndTranslate(PredefinedIdentKind IK, const Decl *CurrentDecl,
LiteralConverter &LiteralConv,
bool ForceElaboratedPrinting = false);

static std::string ComputeName(PredefinedIdentKind IK,
const Decl *CurrentDecl,
bool ForceElaboratedPrinting = false);
Expand Down
13 changes: 7 additions & 6 deletions clang/include/clang/AST/FormatString.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define LLVM_CLANG_AST_FORMATSTRING_H

#include "clang/AST/CanonicalType.h"
#include "llvm/Support/TextEncoding.h"
#include <optional>

namespace clang {
Expand Down Expand Up @@ -744,9 +745,9 @@ class FormatStringHandler {
// Printf-specific handlers.

virtual bool HandleInvalidPrintfConversionSpecifier(
const analyze_printf::PrintfSpecifier &FS,
const char *startSpecifier,
unsigned specifierLen) {
const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
unsigned specifierLen,
const llvm::TextEncodingConverter &FormatStrConverter) {
return true;
}

Expand All @@ -763,9 +764,9 @@ class FormatStringHandler {
// Scanf-specific handlers.

virtual bool HandleInvalidScanfConversionSpecifier(
const analyze_scanf::ScanfSpecifier &FS,
const char *startSpecifier,
unsigned specifierLen) {
const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier,
unsigned specifierLen,
const llvm::TextEncodingConverter &FormatStrConverter) {
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "llvm/IR/DerivedTypes.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/TextEncoding.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/TargetParser/Triple.h"
#include <cassert>
Expand Down Expand Up @@ -320,6 +321,8 @@ class TargetInfo : public TransferrableTargetInfo,

virtual ~TargetInfo();

llvm::TextEncodingConverter *FormatStrConverter;

/// Retrieve the target options.
TargetOptions &getTargetOpts() const {
assert(TargetOpts && "Missing target options");
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/LiteralConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LiteralConverter {
static std::error_code
setConvertersFromOptions(LiteralConverter &LiteralConv,
const clang::LangOptions &Opts,
const clang::TargetInfo &TInfo);
clang::TargetInfo &TInfo);
};

#endif
1 change: 1 addition & 0 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5633,6 +5633,7 @@ class Parser : public CodeCompletionHandler {
bool Finished;
};
ObjCImplParsingDataRAII *CurParsedObjCImpl;
ConversionAction ParserConversionAction;

/// StashAwayMethodOrFunctionBodyTokens - Consume the tokens and store them
/// for later parsing.
Expand Down
8 changes: 6 additions & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/TypeTraits.h"
#include "clang/Lex/LiteralConverter.h"
#include "clang/Sema/AnalysisBasedWarnings.h"
#include "clang/Sema/Attr.h"
#include "clang/Sema/CleanupInfo.h"
Expand Down Expand Up @@ -7272,9 +7273,12 @@ class Sema final : public SemaBase {
/// from multiple tokens. However, the common case is that StringToks points
/// to one string.
ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
Scope *UDLScope = nullptr);
Scope *UDLScope = nullptr,
ConversionAction Action = CA_ToExecEncoding);

ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks);
ExprResult
ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks,
ConversionAction Action = CA_ToExecEncoding);

/// ControllingExprOrType is either an opaque pointer coming out of a
/// ParsedType or an Expr *. FIXME: it'd be better to split this interface
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,21 @@ StringRef PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) {
llvm_unreachable("Unknown ident kind for PredefinedExpr");
}

std::string PredefinedExpr::ComputeNameAndTranslate(
PredefinedIdentKind IK, const Decl *CurrentDecl,
LiteralConverter &LiteralConv, bool ForceElaboratedPrinting) {
using namespace clang::charinfo;
std::string Result = ComputeName(IK, CurrentDecl, ForceElaboratedPrinting);
llvm::TextEncodingConverter *Converter =
LiteralConv.getConverter(CA_ToExecEncoding);
if (Converter) {
SmallString<128> Converted;
Converter->convert(Result, Converted);
Result = std::string(Converted);
}
return Result;
}

// FIXME: Maybe this should use DeclPrinter with a special "print predefined
// expr" policy instead.
std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
Expand Down
Loading