diff options
Diffstat (limited to 'include/clang/Lex/LiteralSupport.h')
-rw-r--r-- | include/clang/Lex/LiteralSupport.h | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h index 8ee8ecf7359fe..97656f7d39d61 100644 --- a/include/clang/Lex/LiteralSupport.h +++ b/include/clang/Lex/LiteralSupport.h @@ -17,6 +17,7 @@ #include <string> #include "llvm/ADT/SmallString.h" +#include "llvm/Support/DataTypes.h" namespace llvm { class APInt; @@ -31,22 +32,22 @@ class Preprocessor; class Token; class SourceLocation; class TargetInfo; - + /// 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. class NumericLiteralParser { Preprocessor &PP; // needed for diagnostics - + const char *const ThisTokBegin; const char *const ThisTokEnd; const char *DigitsBegin, *SuffixBegin; // markers const char *s; // cursor - + unsigned radix; - + bool saw_exponent, saw_period; - + public: NumericLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP); @@ -56,8 +57,9 @@ public: bool isLongLong; bool isFloat; // 1.0f bool isImaginary; // 1.0i - - bool isIntegerLiteral() const { + bool isMicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64. + + bool isIntegerLiteral() const { return !saw_period && !saw_exponent; } bool isFloatingLiteral() const { @@ -66,27 +68,27 @@ public: bool hasSuffix() const { return SuffixBegin != ThisTokEnd; } - + unsigned getRadix() const { return radix; } - + /// 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. bool GetIntegerValue(llvm::APInt &Val); - + /// GetFloatValue - Convert this numeric literal to a floating value, using /// the specified APFloat fltSemantics (specifying float, double, etc). /// The optional bool isExact (passed-by-reference) has its value /// set to true if the returned APFloat can represent the number in the /// literal exactly, and false otherwise. - llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format, + llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format, bool* isExact = NULL); -private: - +private: + void ParseNumberStartingWithZero(SourceLocation TokLoc); - + /// SkipHexDigits - Read and skip over any hex digits, up to End. /// Return a pointer to the first non-hex digit or End. const char *SkipHexDigits(const char *ptr) { @@ -94,7 +96,7 @@ private: ptr++; return ptr; } - + /// SkipOctalDigits - Read and skip over any octal digits, up to End. /// Return a pointer to the first non-hex digit or End. const char *SkipOctalDigits(const char *ptr) { @@ -102,7 +104,7 @@ private: ptr++; return ptr; } - + /// SkipDigits - Read and skip over any digits, up to End. /// Return a pointer to the first non-hex digit or End. const char *SkipDigits(const char *ptr) { @@ -110,7 +112,7 @@ private: ptr++; return ptr; } - + /// SkipBinaryDigits - Read and skip over any binary digits, up to End. /// Return a pointer to the first non-binary digit or End. const char *SkipBinaryDigits(const char *ptr) { @@ -118,7 +120,7 @@ private: ptr++; return ptr; } - + }; /// CharLiteralParser - Perform interpretation and semantic analysis of a @@ -143,7 +145,7 @@ public: /// literals) (C99 5.1.1.2p1). class StringLiteralParser { Preprocessor &PP; - + unsigned MaxTokenLength; unsigned SizeBound; unsigned wchar_tByteWidth; @@ -155,7 +157,7 @@ public: bool hadError; bool AnyWide; bool Pascal; - + const char *GetString() { return &ResultBuf[0]; } unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; } @@ -163,14 +165,14 @@ public: if (AnyWide) return GetStringLength() / wchar_tByteWidth; return GetStringLength(); - } + } /// getOffsetOfStringByte - This function returns the offset of the /// specified byte of the string data represented by Token. This handles /// advancing over escape sequences in the string. static unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo, Preprocessor &PP); }; - + } // end namespace clang #endif |