From ac92d829111bc19d1cc97cd85c3c04bc39b969d1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 22 Nov 2008 07:23:31 +0000 Subject: [PATCH] remove the NumericLiteralParser::Diag helper method, inlining it into its call sites. This makes it more explicit when the hasError flag is getting set and removes a confusing difference in behavior between PP.Diag and Diag in this code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59863 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/LiteralSupport.h | 4 +- lib/Lex/LiteralSupport.cpp | 61 ++++++++++++++++-------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h index 834bb074e8..78f320fc64 100644 --- a/include/clang/Lex/LiteralSupport.h +++ b/include/clang/Lex/LiteralSupport.h @@ -84,9 +84,7 @@ public: bool* isExact = NULL); private: - void Diag(SourceLocation Loc, unsigned DiagID, - const std::string &M = std::string()); - + void ParseNumberStartingWithZero(SourceLocation TokLoc); /// SkipHexDigits - Read and skip over any hex digits, up to End. diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 93e9524ee4..6a1fad52bf 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -141,11 +141,10 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf, } // FALL THROUGH. default: - if (isgraph(ThisTokBuf[0])) { + if (isgraph(ThisTokBuf[0])) PP.Diag(Loc, diag::ext_unknown_escape) << std::string()+(char)ResultChar; - } else { + else PP.Diag(Loc, diag::ext_unknown_escape) << "x"+llvm::utohexstr(ResultChar); - } break; } @@ -225,8 +224,9 @@ NumericLiteralParser(const char *begin, const char *end, if (s == ThisTokEnd) { // Done. } else if (isxdigit(*s) && !(*s == 'e' || *s == 'E')) { - Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin), - diag::err_invalid_decimal_digit, std::string(s, s+1)); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin), + diag::err_invalid_decimal_digit) << std::string(s, s+1); + hadError = true; return; } else if (*s == '.') { s++; @@ -242,8 +242,9 @@ NumericLiteralParser(const char *begin, const char *end, if (first_non_digit != s) { s = first_non_digit; } else { - Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-begin), - diag::err_exponent_has_no_digits); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-begin), + diag::err_exponent_has_no_digits); + hadError = true; return; } } @@ -330,10 +331,11 @@ NumericLiteralParser(const char *begin, const char *end, // Report an error if there are any. if (s != ThisTokEnd) { - Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin), - isFPConstant ? diag::err_invalid_suffix_float_constant : - diag::err_invalid_suffix_integer_constant, - std::string(SuffixBegin, ThisTokEnd)); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin), + isFPConstant ? diag::err_invalid_suffix_float_constant : + diag::err_invalid_suffix_integer_constant) + << std::string(SuffixBegin, ThisTokEnd); + hadError = true; return; } } @@ -369,17 +371,21 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { if (*s == '+' || *s == '-') s++; // sign const char *first_non_digit = SkipDigits(s); if (first_non_digit == s) { - Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), - diag::err_exponent_has_no_digits); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), + diag::err_exponent_has_no_digits); + hadError = true; return; } s = first_non_digit; - if (!PP.getLangOptions().HexFloats) - Diag(TokLoc, diag::ext_hexconstant_invalid); + if (!PP.getLangOptions().HexFloats) { + PP.Diag(TokLoc, diag::ext_hexconstant_invalid); + hadError = true; + } } else if (saw_period) { - Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_hexconstant_requires_exponent); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), + diag::err_hexconstant_requires_exponent); + hadError = true; } return; } @@ -395,8 +401,9 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { if (s == ThisTokEnd) { // Done. } else if (isxdigit(*s)) { - Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_invalid_binary_digit, std::string(s, s+1)); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), + diag::err_invalid_binary_digit) << std::string(s, s+1); + hadError = true; } // Other suffixes will be diagnosed by the caller. return; @@ -424,8 +431,9 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { // If we have a hex digit other than 'e' (which denotes a FP exponent) then // the code is using an incorrect base. if (isxdigit(*s) && *s != 'e' && *s != 'E') { - Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_invalid_octal_digit, std::string(s, s+1)); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), + diag::err_invalid_octal_digit) << std::string(s, s+1); + hadError = true; return; } @@ -445,8 +453,9 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { if (first_non_digit != s) { s = first_non_digit; } else { - Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), - diag::err_exponent_has_no_digits); + PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), + diag::err_exponent_has_no_digits); + hadError = true; return; } } @@ -530,12 +539,6 @@ GetFloatValue(const llvm::fltSemantics &Format, bool* isExact) { return V; } -void NumericLiteralParser::Diag(SourceLocation Loc, unsigned DiagID, - const std::string &M) { - PP.Diag(Loc, DiagID) << M; - hadError = true; -} - CharLiteralParser::CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP) { -- 2.40.0