clang 20.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::NumericLiteralParser Class Reference

NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber, classifying it as either integer, floating, or erroneous, determines the radix of the value and can convert it to a useful value. More...

#include "clang/Lex/LiteralSupport.h"

Public Member Functions

 NumericLiteralParser (StringRef TokSpelling, SourceLocation TokLoc, const SourceManager &SM, const LangOptions &LangOpts, const TargetInfo &Target, DiagnosticsEngine &Diags)
 integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadecimal-constant integer-suffix binary-literal integer-suffix [GNU, C++1y] user-defined-integer-literal: [C++11 lex.ext] decimal-literal ud-suffix octal-literal ud-suffix hexadecimal-literal ud-suffix binary-literal ud-suffix [GNU, C++1y] decimal-constant: nonzero-digit decimal-constant digit octal-constant: 0 octal-constant octal-digit hexadecimal-constant: hexadecimal-prefix hexadecimal-digit hexadecimal-constant hexadecimal-digit hexadecimal-prefix: one of 0x 0X binary-literal: 0b binary-digit 0B binary-digit binary-literal binary-digit integer-suffix: unsigned-suffix [long-suffix] unsigned-suffix [long-long-suffix] long-suffix [unsigned-suffix] long-long-suffix [unsigned-sufix] nonzero-digit: 1 2 3 4 5 6 7 8 9 octal-digit: 0 1 2 3 4 5 6 7 hexadecimal-digit: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F binary-digit: 0 1 unsigned-suffix: one of u U long-suffix: one of l L long-long-suffix: one of ll LL
 
bool isFixedPointLiteral () const
 
bool isIntegerLiteral () const
 
bool isFloatingLiteral () const
 
bool hasUDSuffix () const
 
StringRef getUDSuffix () const
 
unsigned getUDSuffixOffset () const
 
unsigned getRadix () const
 
bool GetIntegerValue (llvm::APInt &Val)
 GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width.
 
llvm::APFloat::opStatus GetFloatValue (llvm::APFloat &Result, llvm::RoundingMode RM)
 Convert this numeric literal to a floating value, using the specified APFloat fltSemantics (specifying float, double, etc) and rounding mode.
 
bool GetFixedPointValue (llvm::APInt &StoreVal, unsigned Scale)
 GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this value.
 
StringRef getLiteralDigits () const
 Get the digits that comprise the literal.
 

Static Public Member Functions

static bool isValidUDSuffix (const LangOptions &LangOpts, StringRef Suffix)
 Determine whether a suffix is a valid ud-suffix.
 

Public Attributes

bool hadError: 1
 
bool isUnsigned: 1
 
bool isLong: 1
 
bool isLongLong: 1
 
bool isSizeT: 1
 
bool isHalf: 1
 
bool isFloat: 1
 
bool isImaginary: 1
 
bool isFloat16: 1
 
bool isFloat128: 1
 
bool isFract: 1
 
bool isAccum: 1
 
bool isBitInt: 1
 
uint8_t MicrosoftInteger
 

Detailed Description

NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber, classifying it as either integer, floating, or erroneous, determines the radix of the value and can convert it to a useful value.

Definition at line 51 of file LiteralSupport.h.

Constructor & Destructor Documentation

◆ NumericLiteralParser()

NumericLiteralParser::NumericLiteralParser ( StringRef  TokSpelling,
SourceLocation  TokLoc,
const SourceManager SM,
const LangOptions LangOpts,
const TargetInfo Target,
DiagnosticsEngine Diags 
)

integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadecimal-constant integer-suffix binary-literal integer-suffix [GNU, C++1y] user-defined-integer-literal: [C++11 lex.ext] decimal-literal ud-suffix octal-literal ud-suffix hexadecimal-literal ud-suffix binary-literal ud-suffix [GNU, C++1y] decimal-constant: nonzero-digit decimal-constant digit octal-constant: 0 octal-constant octal-digit hexadecimal-constant: hexadecimal-prefix hexadecimal-digit hexadecimal-constant hexadecimal-digit hexadecimal-prefix: one of 0x 0X binary-literal: 0b binary-digit 0B binary-digit binary-literal binary-digit integer-suffix: unsigned-suffix [long-suffix] unsigned-suffix [long-long-suffix] long-suffix [unsigned-suffix] long-long-suffix [unsigned-sufix] nonzero-digit: 1 2 3 4 5 6 7 8 9 octal-digit: 0 1 2 3 4 5 6 7 hexadecimal-digit: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F binary-digit: 0 1 unsigned-suffix: one of u U long-suffix: one of l L long-long-suffix: one of ll LL

floating-constant: [C99 6.4.4.2] TODO: add rules...

Definition at line 902 of file LiteralSupport.cpp.

References clang::Lexer::AdvanceToTokenCharacter(), c, clang::expandUCNs(), hadError, isAccum, isBitInt, isFixedPointLiteral(), isFloat, isFloat128, isFloat16, isFloatingLiteral(), isFract, isHalf, isImaginary, isIntegerLiteral(), isLong, isLongLong, clang::isPreprocessingNumberBody(), isSizeT, isUnsigned, isValidUDSuffix(), MicrosoftInteger, clang::DiagnosticsEngine::Report(), s, and SM.

Member Function Documentation

◆ GetFixedPointValue()

bool NumericLiteralParser::GetFixedPointValue ( llvm::APInt &  StoreVal,
unsigned  Scale 
)

GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this value.

Returns true if an overflow occurred when calculating the integral part of the scaled integer or calculating the digit sequence of the exponent.

Definition at line 1553 of file LiteralSupport.cpp.

References alwaysFitsInto64Bits(), clang::C, and IsExponentPart().

◆ GetFloatValue()

llvm::APFloat::opStatus NumericLiteralParser::GetFloatValue ( llvm::APFloat &  Result,
llvm::RoundingMode  RM 
)

Convert this numeric literal to a floating value, using the specified APFloat fltSemantics (specifying float, double, etc) and rounding mode.

Definition at line 1526 of file LiteralSupport.cpp.

References clang::Result.

◆ GetIntegerValue()

bool NumericLiteralParser::GetIntegerValue ( llvm::APInt &  Val)

GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width.

If there is an overflow (i.e., if the unsigned value read is larger than the APInt's bits will hold), set Val to the low bits of the result and return true. Otherwise, return false.

If there is an overflow, set Val to the low bits of the result and return true. Otherwise, return false.

Definition at line 1468 of file LiteralSupport.cpp.

References alwaysFitsInto64Bits(), and clang::C.

◆ getLiteralDigits()

StringRef clang::NumericLiteralParser::getLiteralDigits ( ) const
inline

Get the digits that comprise the literal.

This excludes any prefix or suffix associated with the literal.

Definition at line 134 of file LiteralSupport.h.

References hadError.

◆ getRadix()

unsigned clang::NumericLiteralParser::getRadix ( ) const
inline

Definition at line 113 of file LiteralSupport.h.

◆ getUDSuffix()

StringRef clang::NumericLiteralParser::getUDSuffix ( ) const
inline

Definition at line 102 of file LiteralSupport.h.

◆ getUDSuffixOffset()

unsigned clang::NumericLiteralParser::getUDSuffixOffset ( ) const
inline

Definition at line 106 of file LiteralSupport.h.

◆ hasUDSuffix()

bool clang::NumericLiteralParser::hasUDSuffix ( ) const
inline

Definition at line 99 of file LiteralSupport.h.

◆ isFixedPointLiteral()

bool clang::NumericLiteralParser::isFixedPointLiteral ( ) const
inline

Definition at line 88 of file LiteralSupport.h.

Referenced by isFloatingLiteral(), isIntegerLiteral(), and NumericLiteralParser().

◆ isFloatingLiteral()

bool clang::NumericLiteralParser::isFloatingLiteral ( ) const
inline

Definition at line 95 of file LiteralSupport.h.

References isFixedPointLiteral().

Referenced by NumericLiteralParser().

◆ isIntegerLiteral()

bool clang::NumericLiteralParser::isIntegerLiteral ( ) const
inline

Definition at line 92 of file LiteralSupport.h.

References isFixedPointLiteral().

Referenced by NumericLiteralParser().

◆ isValidUDSuffix()

bool NumericLiteralParser::isValidUDSuffix ( const LangOptions LangOpts,
StringRef  Suffix 
)
static

Determine whether a suffix is a valid ud-suffix.

We avoid treating reserved suffixes as ud-suffixes, because the diagnostic experience is better if we treat it as an invalid suffix.

Definition at line 1267 of file LiteralSupport.cpp.

Referenced by clang::StringLiteralParser::isValidUDSuffix(), and NumericLiteralParser().

Member Data Documentation

◆ hadError

bool clang::NumericLiteralParser::hadError

Definition at line 71 of file LiteralSupport.h.

Referenced by getLiteralDigits(), and NumericLiteralParser().

◆ isAccum

bool clang::NumericLiteralParser::isAccum

Definition at line 82 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isBitInt

bool clang::NumericLiteralParser::isBitInt

Definition at line 83 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isFloat

bool clang::NumericLiteralParser::isFloat

Definition at line 77 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isFloat128

bool clang::NumericLiteralParser::isFloat128

Definition at line 80 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isFloat16

bool clang::NumericLiteralParser::isFloat16

Definition at line 79 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isFract

bool clang::NumericLiteralParser::isFract

Definition at line 81 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isHalf

bool clang::NumericLiteralParser::isHalf

Definition at line 76 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isImaginary

bool clang::NumericLiteralParser::isImaginary

Definition at line 78 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isLong

bool clang::NumericLiteralParser::isLong

Definition at line 73 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isLongLong

bool clang::NumericLiteralParser::isLongLong

Definition at line 74 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isSizeT

bool clang::NumericLiteralParser::isSizeT

Definition at line 75 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ isUnsigned

bool clang::NumericLiteralParser::isUnsigned

Definition at line 72 of file LiteralSupport.h.

Referenced by NumericLiteralParser().

◆ MicrosoftInteger

uint8_t clang::NumericLiteralParser::MicrosoftInteger

Definition at line 85 of file LiteralSupport.h.

Referenced by NumericLiteralParser().


The documentation for this class was generated from the following files: