clang 19.0.0git
Functions
LiteralSupport.cpp File Reference
#include "clang/Lex/LiteralSupport.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Unicode.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>

Go to the source code of this file.

Functions

static unsigned getCharWidth (tok::TokenKind kind, const TargetInfo &Target)
 
static unsigned getEncodingPrefixLen (tok::TokenKind kind)
 
static CharSourceRange MakeCharSourceRange (const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd)
 
static DiagnosticBuilder Diag (DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
 Produce a diagnostic highlighting some portion of a literal.
 
static bool IsEscapeValidInUnevaluatedStringLiteral (char Escape)
 
static unsigned ProcessCharEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, bool &HadError, FullSourceLoc Loc, unsigned CharWidth, DiagnosticsEngine *Diags, const LangOptions &Features, StringLiteralEvalMethod EvalMethod)
 ProcessCharEscape - Parse a standard C escape sequence, which can occur in either a character or a string literal.
 
static void appendCodePoint (unsigned Codepoint, llvm::SmallVectorImpl< char > &Str)
 
static bool ProcessNumericUCNEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, bool &Delimited, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features, bool in_char_string_literal=false)
 
static void DiagnoseInvalidUnicodeCharacterName (DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc Loc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, llvm::StringRef Name)
 
static bool ProcessNamedUCNEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features)
 
static bool ProcessUCNEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features, bool in_char_string_literal=false)
 ProcessUCNEscape - Read the Universal Character Name, check constraints and return the UTF32.
 
static int MeasureUCNEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, unsigned CharByteWidth, const LangOptions &Features, bool &HadError)
 MeasureUCNEscape - Determine the number of bytes within the resulting string which this UCN will occupy.
 
static void EncodeUCNEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, char *&ResultBuf, bool &HadError, FullSourceLoc Loc, unsigned CharByteWidth, DiagnosticsEngine *Diags, const LangOptions &Features)
 EncodeUCNEscape - Read the Universal Character Name, check constraints and convert the UTF32 to UTF8 or UTF16.
 
static bool alwaysFitsInto64Bits (unsigned Radix, unsigned NumDigits)
 
static bool IsExponentPart (char c, bool isHex)
 
static const char * resyncUTF8 (const char *Err, const char *End)
 

Function Documentation

◆ alwaysFitsInto64Bits()

static bool alwaysFitsInto64Bits ( unsigned  Radix,
unsigned  NumDigits 
)
static

◆ appendCodePoint()

static void appendCodePoint ( unsigned  Codepoint,
llvm::SmallVectorImpl< char > &  Str 
)
static

Definition at line 372 of file LiteralSupport.cpp.

Referenced by clang::expandUCNs().

◆ Diag()

static DiagnosticBuilder Diag ( DiagnosticsEngine Diags,
const LangOptions Features,
FullSourceLoc  TokLoc,
const char *  TokBegin,
const char *  TokRangeBegin,
const char *  TokRangeEnd,
unsigned  DiagID 
)
static

Produce a diagnostic highlighting some portion of a literal.

Emits the diagnostic DiagID, highlighting the range of characters from TokRangeBegin (inclusive) to TokRangeEnd (exclusive), which must be a substring of a spelling buffer for the token beginning at TokBegin.

Definition at line 99 of file LiteralSupport.cpp.

References clang::Lexer::AdvanceToTokenCharacter(), Begin, clang::FullSourceLoc::getManager(), MakeCharSourceRange(), and clang::DiagnosticsEngine::Report().

Referenced by addConstraintSatisfaction(), clang::interp::State::addNotes(), applyEditsToTemp(), clang::Sema::BuildCallToMemberFunction(), clang::Sema::BuildCXXMemberCallExpr(), clang::Sema::BuildOverloadedArrowExpr(), clang::interp::State::CCEDiag(), checkAttributeNumArgsImpl(), clang::checkAttrMutualExclusion(), checkAVX512ParamFeature(), checkAVXParam(), checkAVXParamFeature(), CheckCXX98CompatAccessibleCopy(), checkIntToPointerCast(), clang::Sema::CheckMemberPointerConversion(), checkMoreSpecializedThanPrimary(), checkNewAttributesAfterDef(), checkObjCPointerIntrospection(), clang::Sema::CheckPointerConversion(), CheckTautologicalComparison(), CheckTemplateSpecializationScope(), clang::ASTUnit::CodeComplete(), collectModuleHeaderIncludes(), clang::computeDependence(), ComputeSelectedDestructor(), clang::Sema::CreateOverloadedBinOp(), createResult(), createThreadFlows(), clang::DeductionFailureInfo::Destroy(), clang::Sema::diagnoseEquivalentInternalLinkageDeclarations(), clang::Sema::DiagnoseImmediateEscalatingReason(), diagnoseInstanceReference(), DiagnoseInvalidUnicodeCharacterName(), clang::ODRDiagsEmitter::diagnoseMismatch(), clang::Sema::DiagnoseMultipleUserDefinedConversion(), DiagnoseSelfAssignment(), diagnoseUnsatisfiedConstraintExpr(), clang::SARIFDiagnostic::emitDiagnosticMessage(), emitNullabilityConsistencyWarning(), clang::DiagnosticRenderer::emitStoredDiagnostic(), clang::Sema::EvaluateConvertedConstantExpression(), EvaluateFeatureLikeBuiltinMacro(), clang::Expr::EvaluateKnownConstInt(), clang::Expr::EvaluateKnownConstIntCheckOverflow(), clang::interp::State::FFDiag(), fixItNullability(), clang::TextDiagnosticBuffer::FlushDiagnostics(), clang::arcmt::FileRemapper::flushToDisk(), clang::arcmt::FileRemapper::flushToFile(), clang::Diagnostic::FormatDiagnostic(), clang::SrcMgr::ContentCache::getBufferOrNone(), clang::DiagnosticIDs::getDiagnosticFlags(), GetFullTypeForDeclarator(), clang::SourceManager::getLineNumber(), clang::SourceManager::getPresumedLoc(), clang::SourceMgrAdapter::handleDiag(), clang::arcmt::FileRemapper::initFromDisk(), clang::arcmt::FileRemapper::initFromFile(), clang::MakeDeductionFailureInfo(), clang::Sema::NoteOverloadCandidate(), clang::SourceManager::noteSLocAddressSpaceUsage(), clang::Rewriter::overwriteChangedFiles(), clang::arcmt::FileRemapper::overwriteOriginal(), clang::Sema::PerformContextuallyConvertToBool(), clang::Sema::PerformImplicitObjectArgumentInitialization(), printDiagnostic(), ProcessCharEscape(), ProcessNamedUCNEscape(), ProcessNumericUCNEscape(), ProcessUCNEscape(), clang::ASTReader::ReadPragmaDiagnosticMappings(), rejectConstNotMutableType(), reportDiag(), clang::Sema::ResolveAndFixSingleFunctionTemplateSpecialization(), clang::Sema::ResolveSingleFunctionTemplateSpecialization(), clang::runWithSufficientStackSpace(), clang::runWithSufficientStackSpaceSlow(), SelectPropertyForSynthesisFromProtocols(), clang::DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(), clang::DiagnosticsEngine::setDiagnosticGroupWarningAsError(), clang::DiagnosticsEngine::setSeverity(), clang::DiagnosticsEngine::setSeverityForAll(), clang::DiagnosticsEngine::setSeverityForGroup(), clang::SourceManager::translateLineCol(), TryReinterpretCast(), and clang::ento::PathDiagnosticConsumer::~PathDiagnosticConsumer().

◆ DiagnoseInvalidUnicodeCharacterName()

static void DiagnoseInvalidUnicodeCharacterName ( DiagnosticsEngine Diags,
const LangOptions Features,
FullSourceLoc  Loc,
const char *  TokBegin,
const char *  TokRangeBegin,
const char *  TokRangeEnd,
llvm::StringRef  Name 
)
static

◆ EncodeUCNEscape()

static void EncodeUCNEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
char *&  ResultBuf,
bool HadError,
FullSourceLoc  Loc,
unsigned  CharByteWidth,
DiagnosticsEngine Diags,
const LangOptions Features 
)
static

EncodeUCNEscape - Read the Universal Character Name, check constraints and convert the UTF32 to UTF8 or UTF16.

This is a subroutine of StringLiteralParser. When we decide to implement UCN's for identifiers, we will likely rework our support for UCN's.

Definition at line 755 of file LiteralSupport.cpp.

References Loc, ProcessUCNEscape(), clang::UTF32, and clang::UTF8.

◆ getCharWidth()

static unsigned getCharWidth ( tok::TokenKind  kind,
const TargetInfo Target 
)
static

◆ getEncodingPrefixLen()

static unsigned getEncodingPrefixLen ( tok::TokenKind  kind)
static

Definition at line 60 of file LiteralSupport.cpp.

◆ IsEscapeValidInUnevaluatedStringLiteral()

static bool IsEscapeValidInUnevaluatedStringLiteral ( char  Escape)
static

Definition at line 110 of file LiteralSupport.cpp.

Referenced by ProcessCharEscape().

◆ IsExponentPart()

static bool IsExponentPart ( char  c,
bool  isHex 
)
inlinestatic

Definition at line 1545 of file LiteralSupport.cpp.

References c.

Referenced by clang::NumericLiteralParser::GetFixedPointValue().

◆ MakeCharSourceRange()

static CharSourceRange MakeCharSourceRange ( const LangOptions Features,
FullSourceLoc  TokLoc,
const char *  TokBegin,
const char *  TokRangeBegin,
const char *  TokRangeEnd 
)
static

◆ MeasureUCNEscape()

static int MeasureUCNEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
unsigned  CharByteWidth,
const LangOptions Features,
bool HadError 
)
static

MeasureUCNEscape - Determine the number of bytes within the resulting string which this UCN will occupy.

Definition at line 720 of file LiteralSupport.cpp.

References Loc, and ProcessUCNEscape().

Referenced by clang::StringLiteralParser::getOffsetOfStringByte().

◆ ProcessCharEscape()

static unsigned ProcessCharEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
bool HadError,
FullSourceLoc  Loc,
unsigned  CharWidth,
DiagnosticsEngine Diags,
const LangOptions Features,
StringLiteralEvalMethod  EvalMethod 
)
static

ProcessCharEscape - Parse a standard C escape sequence, which can occur in either a character or a string literal.

Definition at line 130 of file LiteralSupport.cpp.

References Diag(), IsEscapeValidInUnevaluatedStringLiteral(), clang::isHexDigit(), clang::isPrintable(), and Loc.

Referenced by clang::CharLiteralParser::CharLiteralParser(), and clang::StringLiteralParser::getOffsetOfStringByte().

◆ ProcessNamedUCNEscape()

static bool ProcessNamedUCNEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
uint32_t &  UcnVal,
unsigned short &  UcnLen,
FullSourceLoc  Loc,
DiagnosticsEngine Diags,
const LangOptions Features 
)
static

◆ ProcessNumericUCNEscape()

static bool ProcessNumericUCNEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
uint32_t &  UcnVal,
unsigned short &  UcnLen,
bool Delimited,
FullSourceLoc  Loc,
DiagnosticsEngine Diags,
const LangOptions Features,
bool  in_char_string_literal = false 
)
static

Definition at line 455 of file LiteralSupport.cpp.

References Diag(), clang::isHexDigit(), and Loc.

Referenced by ProcessUCNEscape().

◆ ProcessUCNEscape()

static bool ProcessUCNEscape ( const char *  ThisTokBegin,
const char *&  ThisTokBuf,
const char *  ThisTokEnd,
uint32_t &  UcnVal,
unsigned short &  UcnLen,
FullSourceLoc  Loc,
DiagnosticsEngine Diags,
const LangOptions Features,
bool  in_char_string_literal = false 
)
static

ProcessUCNEscape - Read the Universal Character Name, check constraints and return the UTF32.

Definition at line 645 of file LiteralSupport.cpp.

References Diag(), Loc, ProcessNamedUCNEscape(), and ProcessNumericUCNEscape().

Referenced by clang::CharLiteralParser::CharLiteralParser(), EncodeUCNEscape(), and MeasureUCNEscape().

◆ resyncUTF8()

static const char * resyncUTF8 ( const char *  Err,
const char *  End 
)
static

Definition at line 2283 of file LiteralSupport.cpp.