clang  6.0.0svn
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/ErrorHandling.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
Include dependency graph for LiteralSupport.cpp:

Go to the source code of this file.

Functions

static unsigned getCharWidth (tok::TokenKind kind, const TargetInfo &Target)
 
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. More...
 
static unsigned ProcessCharEscape (const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, bool &HadError, FullSourceLoc Loc, unsigned CharWidth, DiagnosticsEngine *Diags, const LangOptions &Features)
 ProcessCharEscape - Parse a standard C escape sequence, which can occur in either a character or a string literal. More...
 
static void appendCodePoint (unsigned Codepoint, llvm::SmallVectorImpl< char > &Str)
 
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. More...
 
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. More...
 
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. More...
 
static bool alwaysFitsInto64Bits (unsigned Radix, unsigned NumDigits)
 
static const char * resyncUTF8 (const char *Err, const char *End)
 

Function Documentation

◆ alwaysFitsInto64Bits()

static bool alwaysFitsInto64Bits ( unsigned  Radix,
unsigned  NumDigits 
)
static

Definition at line 916 of file LiteralSupport.cpp.

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

◆ appendCodePoint()

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

Definition at line 230 of file LiteralSupport.cpp.

◆ 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 78 of file LiteralSupport.cpp.

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

Referenced by clang::Sema::ActOnBaseSpecifier(), clang::Sema::ActOnBlockStmtExpr(), clang::Sema::ActOnCallExpr(), clang::Sema::ActOnCaseStmt(), clang::Sema::ActOnCastExpr(), clang::Sema::ActOnClassPropertyRefExpr(), clang::Sema::ActOnCompoundStmt(), clang::Sema::ActOnCXXConditionDeclaration(), clang::Sema::ActOnCXXFoldExpr(), clang::Sema::ActOnCXXForRangeDecl(), clang::Sema::ActOnCXXTryBlock(), clang::Sema::ActOnCXXTypeid(), clang::Sema::ActOnDefaultStmt(), clang::Sema::ActOnDependentMemberExpr(), clang::Sema::ActOnDesignatedInitializer(), clang::Sema::ActOnFinishCXXMemberSpecification(), clang::Sema::ActOnFinishFunctionBody(), clang::Sema::ActOnFinishSwitchStmt(), clang::Sema::ActOnForEachDeclStmt(), clang::Sema::ActOnForStmt(), clang::Sema::ActOnFriendFunctionDecl(), clang::Sema::ActOnFriendTypeDecl(), clang::Sema::ActOnLabelStmt(), clang::Sema::ActOnMemberAccessExpr(), clang::Sema::ActOnMemInitializers(), clang::Sema::ActOnModuleDecl(), clang::Sema::ActOnModuleImport(), clang::Sema::ActOnNamespaceAliasDef(), clang::Sema::ActOnObjCAtSynchronizedOperand(), clang::Sema::ActOnObjCAtThrowStmt(), clang::Sema::ActOnObjCAtTryStmt(), clang::Sema::ActOnObjCForCollectionStmt(), clang::Sema::ActOnOpenMPAlignedClause(), clang::Sema::ActOnOpenMPAtomicDirective(), clang::Sema::ActOnOpenMPCancelDirective(), clang::Sema::ActOnOpenMPCancellationPointDirective(), clang::Sema::ActOnOpenMPCopyinClause(), clang::Sema::ActOnOpenMPCopyprivateClause(), clang::Sema::ActOnOpenMPCriticalDirective(), clang::Sema::ActOnOpenMPDeclareReductionType(), clang::Sema::ActOnOpenMPDeclareSimdDirective(), clang::Sema::ActOnOpenMPDeclareTargetName(), clang::Sema::ActOnOpenMPDefaultClause(), clang::Sema::ActOnOpenMPDefaultmapClause(), clang::Sema::ActOnOpenMPDependClause(), clang::Sema::ActOnOpenMPDistScheduleClause(), clang::Sema::ActOnOpenMPIdExpression(), clang::Sema::ActOnOpenMPIsDevicePtrClause(), clang::Sema::ActOnOpenMPLastprivateClause(), clang::Sema::ActOnOpenMPLinearClause(), clang::Sema::ActOnOpenMPOrderedDirective(), clang::Sema::ActOnOpenMPParallelSectionsDirective(), clang::Sema::ActOnOpenMPPrivateClause(), clang::Sema::ActOnOpenMPProcBindClause(), clang::Sema::ActOnOpenMPRegionEnd(), clang::Sema::ActOnOpenMPScheduleClause(), clang::Sema::ActOnOpenMPSectionsDirective(), clang::Sema::ActOnOpenMPSharedClause(), clang::Sema::ActOnOpenMPSingleDirective(), clang::Sema::ActOnOpenMPTargetDataDirective(), clang::Sema::ActOnOpenMPTargetEnterDataDirective(), clang::Sema::ActOnOpenMPTargetExitDataDirective(), clang::Sema::ActOnOpenMPTargetUpdateDirective(), clang::Sema::ActOnOpenMPUseDevicePtrClause(), clang::Sema::ActOnPackExpansion(), clang::Sema::ActOnParamDefaultArgument(), clang::Sema::ActOnPureSpecifier(), clang::Sema::ActOnSEHExceptBlock(), clang::Sema::ActOnSEHLeaveStmt(), clang::Sema::ActOnSEHTryBlock(), clang::Sema::ActOnStartLinkageSpecification(), clang::Sema::ActOnStartNamespaceDef(), clang::Sema::ActOnStartOfFunctionDef(), clang::Sema::ActOnStartOpenMPDeclareTargetDirective(), clang::Sema::ActOnTemplateIdType(), clang::Sema::ActOnTemplateParameterList(), clang::Sema::ActOnTypenameType(), clang::Sema::ActOnUninitializedDecl(), clang::Sema::ActOnUsingDirective(), clang::Sema::AddInitializerToDecl(), clang::Sema::AddNSConsumedAttr(), clang::Sema::AddParameterABIAttr(), clang::FixItRewriter::buffer_end(), clang::Sema::BuildAddressSpaceAttr(), clang::Sema::BuildAnonymousStructUnionMemberReference(), clang::Sema::BuildArrayType(), clang::Sema::BuildBaseInitializer(), clang::Sema::BuildBlockPointerType(), clang::Sema::BuildBuiltinOffsetOf(), clang::Sema::BuildClassMessage(), clang::Sema::BuildCXXThrow(), clang::Sema::BuildCXXUuidof(), clang::Sema::BuildDeclarationNameExpr(), clang::Sema::BuildDelegatingInitializer(), clang::Sema::BuildExtVectorType(), clang::Sema::BuildInstanceMessage(), clang::Sema::BuildLiteralOperatorCall(), clang::Sema::BuildMemberPointerType(), clang::Sema::BuildMemberReferenceExpr(), clang::Sema::BuildMemInitializer(), clang::Sema::BuildObjCAtThrowStmt(), clang::Sema::BuildObjCBridgedCast(), clang::Sema::BuildPointerType(), clang::Sema::BuildPredefinedExpr(), clang::Sema::BuildQualifiedDeclarationNameExpr(), clang::Sema::BuildQualifiedTemplateIdExpr(), clang::Sema::BuildQualifiedType(), clang::Sema::BuildResolvedCallExpr(), clang::Sema::BuildReturnStmt(), clang::Sema::BuildStaticAssertDeclaration(), clang::Sema::BuildUnaryTransformType(), clang::Sema::CheckAssignmentOperands(), clang::Sema::CheckBaseSpecifier(), checkBuiltinArgument(), clang::Sema::CheckCompletedCoroutineBody(), clang::Sema::CheckCompletedCXXClass(), clang::Sema::CheckCompleteVariableDeclaration(), clang::Sema::CheckConditionalOperands(), clang::Sema::CheckConstexprFunctionBody(), clang::Sema::CheckConstexprFunctionDecl(), clang::Sema::CheckConstructorDeclarator(), clang::Sema::CheckConversionDeclarator(), CheckCXX98CompatAccessibleCopy(), clang::Sema::CheckCXXDefaultArgExpr(), clang::Sema::CheckCXXDefaultArguments(), clang::Sema::checkDeclIsAllowedInOpenMPTarget(), clang::Sema::CheckDeductionGuideDeclarator(), clang::Sema::CheckDestructor(), clang::Sema::CheckDestructorDeclarator(), clang::Sema::CheckEnumRedeclaration(), clang::Sema::CheckEnumUnderlyingType(), clang::Sema::CheckExplicitlyDefaultedSpecialMember(), clang::Sema::CheckExtraCXXDefaultArguments(), clang::Sema::CheckForFunctionRedefinition(), clang::Sema::CheckFriendTypeDecl(), clang::Sema::CheckFunctionReturnType(), clang::Sema::CheckIfOverriddenFunctionIsMarkedFinal(), clang::Sema::CheckInheritingConstructorUsingDecl(), checkIntToPointerCast(), clang::Sema::CheckLiteralOperatorDeclaration(), clang::Sema::CheckMain(), clang::Sema::CheckMessageArgumentTypes(), checkMoreSpecializedThanPrimary(), clang::Sema::checkMSInheritanceAttrOnDefinition(), clang::Sema::CheckMSVCRTEntryPoint(), clang::Sema::CheckNonTypeTemplateParameterType(), clang::Sema::checkNSReturnsRetainedReturnType(), clang::Sema::checkNullabilityTypeSpecifier(), clang::Sema::checkObjCBridgeRelatedComponents(), clang::Sema::CheckObjCBridgeRelatedConversions(), clang::Sema::CheckObjCConversion(), clang::Sema::CheckObjCForCollectionOperand(), checkObjCPointerIntrospection(), clang::Sema::CheckOpenMPLinearDecl(), clang::Sema::CheckOpenMPLinearModifier(), clang::Sema::CheckOverloadedOperatorDeclaration(), clang::Sema::CheckOverrideControl(), clang::Sema::CheckPackExpansion(), clang::Sema::CheckParmsForFunctionDef(), clang::Sema::CheckPureMethod(), clang::Sema::CheckRedeclarationModuleOwnership(), clang::Sema::CheckSpecializationInstantiationRedecl(), clang::Sema::checkStringLiteralArgumentAttr(), clang::Sema::CheckSubscriptingKind(), clang::Sema::checkTargetAttr(), clang::Sema::CheckTemplateArgument(), clang::Sema::CheckTemplateDeclScope(), CheckTemplateSpecializationScope(), clang::Sema::checkUnsafeExprAssigns(), clang::Sema::CheckUsingDeclQualifier(), clang::Sema::CheckUsingDeclRedeclaration(), clang::Sema::CheckUsingShadowDecl(), clang::Sema::checkVarDeclRedefinition(), clang::Sema::CheckVariableDeclarationType(), checkVAStartIsInVariadicFunction(), collectAllSubModulesWithUmbrellaHeader(), computeKeyFunction(), clang::SrcMgr::ContentCache::ContentCache(), clang::Sema::ConversionToObjCStringLiteralCheck(), clang::Sema::CreateBuiltinBinOp(), clang::Sema::DeduceAutoType(), clang::Sema::DeduceFunctionTypeFromReturnExpr(), clang::Sema::DeduceReturnType(), clang::Sema::DeduceTemplateSpecializationFromInitializer(), clang::DeductionFailureInfo::Destroy(), clang::Sema::Diag(), clang::ASTReader::Diag(), clang::Sema::DiagnoseAbsenceOfOverrideControl(), clang::Sema::DiagnoseAbstractType(), clang::Sema::DiagnoseAlwaysNonNullPointer(), clang::Sema::DiagnoseAutoDeductionFailure(), clang::Sema::DiagnoseCommaOperator(), clang::Sema::DiagnoseEmptyLoopBody(), clang::Sema::DiagnoseEmptyStmtBody(), clang::Sema::diagnoseEquivalentInternalLinkageDeclarations(), clang::Sema::DiagnoseFunctionSpecifiers(), clang::Sema::DiagnoseHiddenVirtualMethods(), clang::Sema::diagnoseMissingImport(), clang::Sema::DiagnoseMultipleUserDefinedConversion(), clang::Sema::DiagnoseSelfMove(), clang::Sema::DiagnoseSentinelCalls(), clang::Sema::DiagnoseShadowingLambdaDecls(), clang::Sema::DiagnoseTemplateParameterShadow(), clang::Sema::diagnoseTypo(), clang::Sema::DiagnoseUnusedLambdaCapture(), clang::Sema::DiagnoseUnusedParameters(), clang::Sema::DiagnoseUseOfDecl(), clang::Sema::DiagRuntimeBehavior(), emitNullabilityConsistencyWarning(), clang::DiagnosticRenderer::emitStoredDiagnostic(), clang::DiagnosticRenderer::endDiagnostic(), clang::Preprocessor::EnterSourceFile(), EvaluateDirectiveSubExpr(), clang::Expr::EvaluateKnownConstInt(), clang::Sema::FinalizeVarWithDestructor(), clang::Sema::FindInstantiatedDecl(), clang::arcmt::FileRemapper::flushToFile(), clang::Diagnostic::FormatDiagnostic(), clang::Lexer::getBuffer(), clang::DiagnosticIDs::getCategoryNumberForDiag(), clang::Sema::getDestructorTypeForDecltype(), clang::SourceManager::getDiagnostics(), clang::Sema::GetFormatStringType(), clang::Sema::getMostSpecialized(), getMSPropertyAttr(), clang::DiagnosticIDs::getNearestOption(), GetNSSetArgumentIndex(), getPaddingDiagFromTagKind(), clang::ASTReader::getSuggestedPredefines(), HandleConstructorCall(), clang::Preprocessor::HandleEndOfFile(), clang::Sema::HandleExprPropertyRefExpr(), clang::Sema::HandleMSProperty(), clang::PragmaNamespace::HandlePragma(), clang::Preprocessor::HandlePragmaDependency(), clang::Preprocessor::HandlePragmaIncludeAlias(), clang::Preprocessor::HandlePragmaModuleBuild(), clang::Preprocessor::HandlePragmaOnce(), clang::Preprocessor::HandlePragmaPoison(), clang::Preprocessor::HandlePragmaPopMacro(), clang::Preprocessor::HandlePragmaSystemHeader(), clang::DiagnosticsEngine::hasAllExtensionsSilenced(), clang::Sema::inferObjCARCLifetime(), clang::Sema::InstantiateExceptionSpec(), clang::Sema::InstantiateFunctionDefinition(), clang::Sema::InstantiateVariableDefinition(), clang::Sema::InvalidLogicalVectorOperands(), clang::Sema::InvalidOperands(), isGCCAsmStatement(), isValidOrderingForOp(), clang::Preprocessor::LexOnOffSwitch(), clang::Sema::LookupInObjCMethod(), clang::Sema::MaybeSuggestAddingStaticToDecl(), clang::Sema::mergeAlwaysInlineAttr(), clang::Sema::mergeAvailabilityAttr(), clang::Sema::mergeDLLExportAttr(), clang::Sema::mergeDLLImportAttr(), clang::Sema::mergeInternalLinkageAttr(), clang::Sema::mergeMinSizeAttr(), clang::Sema::mergeMSInheritanceAttr(), clang::Sema::mergeOptimizeNoneAttr(), clang::Sema::mergeUuidAttr(), clang::Sema::MergeVarDecl(), clang::Sema::NoteDeletedFunction(), clang::Sema::NoteHiddenVirtualMethods(), clang::Sema::NoteOverloadCandidate(), clang::Sema::notePreviousDefinition(), parseDeclareSimdClauses(), ParseLangArgs(), clang::Sema::ParseObjCProtocolExpression(), clang::Sema::ParseObjCSelectorExpression(), clang::Parser::ParseOpenMPParensExpr(), clang::Parser::ParseOpenMPVarList(), clang::Preprocessor::ParsePragmaPushOrPopMacro(), clang::Sema::PopExpressionEvaluationContext(), PragmaLoopHintString(), clang::Sema::ProcessAccessDeclAttributeList(), ProcessCharEscape(), ProcessUCNEscape(), clang::Sema::propagateDLLAttrToBaseClassTemplate(), clang::serialization::reader::ASTDeclContextNameLookupTrait::ReadDataInto(), roundUpSizeToCharAlignment(), SemaBuiltinCpuIs(), clang::Sema::SemaBuiltinShuffleVector(), clang::Sema::SemaConvertVectorExpr(), clang::Sema::SetDeclDefaulted(), clang::Sema::SetDeclDeleted(), clang::DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(), clang::DiagnosticsEngine::setDiagnosticGroupWarningAsError(), clang::Sema::SetMemberAccessSpecifier(), clang::DiagnosticsEngine::setSeverityForAll(), clang::DiagnosticsEngine::setSeverityForGroup(), clang::Sema::ShouldDeleteSpecialMember(), clang::Sema::SpecialMemberIsTrivial(), clang::Sema::tryCaptureVariable(), and clang::Sema::VerifyBitField().

◆ 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 381 of file LiteralSupport.cpp.

References ProcessUCNEscape().

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

◆ getCharWidth()

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

◆ 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 346 of file LiteralSupport.cpp.

References 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 
)
static

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

Definition at line 91 of file LiteralSupport.cpp.

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

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

◆ 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 274 of file LiteralSupport.cpp.

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

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

◆ resyncUTF8()

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