From 8a24e588d73f9890c7acb100e19d8cdc44c8e929 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 16 Jan 2009 18:51:42 +0000 Subject: [PATCH] minor cleanups to StringLiteralParser: no need to pass target info into its ctor. Also, make it handle validity checking of pascal strings instead of making clients do it. llvm-svn: 62332 --- clang/include/clang/Lex/LiteralSupport.h | 3 +-- clang/lib/Lex/LiteralSupport.cpp | 16 ++++++++++++---- clang/lib/Sema/SemaExpr.cpp | 8 +------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Lex/LiteralSupport.h b/clang/include/clang/Lex/LiteralSupport.h index 78f320fc64d3..06068bad7b97 100644 --- a/clang/include/clang/Lex/LiteralSupport.h +++ b/clang/include/clang/Lex/LiteralSupport.h @@ -141,7 +141,6 @@ public: /// literals) (C99 5.1.1.2p1). class StringLiteralParser { Preprocessor &PP; - TargetInfo &Target; unsigned MaxTokenLength; unsigned SizeBound; @@ -150,7 +149,7 @@ class StringLiteralParser { char *ResultPtr; // cursor public: StringLiteralParser(const Token *StringToks, unsigned NumStringToks, - Preprocessor &PP, TargetInfo &T); + Preprocessor &PP); bool hadError; bool AnyWide; bool Pascal; diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index fbd2c326ea77..76c90e4ed063 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -647,8 +647,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, /// StringLiteralParser:: StringLiteralParser(const Token *StringToks, unsigned NumStringToks, - Preprocessor &pp, TargetInfo &t) - : PP(pp), Target(t) { + Preprocessor &pp) : PP(pp) { // Scan all of the string portions, remember the max individual token length, // computing a bound on the concatenated string length, and see whether any // piece is a wide-string. If any of the string portions is a wide-string @@ -684,7 +683,7 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks, // query the target. As such, wchar_tByteWidth is only valid if AnyWide=true. wchar_tByteWidth = ~0U; if (AnyWide) { - wchar_tByteWidth = Target.getWCharWidth(); + wchar_tByteWidth = PP.getTargetInfo().getWCharWidth(); assert((wchar_tByteWidth & 7) == 0 && "Assumes wchar_t is byte multiple!"); wchar_tByteWidth /= 8; } @@ -787,6 +786,15 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks, *ResultPtr++ = 0; } - if (Pascal) + if (Pascal) { ResultBuf[0] = ResultPtr-&ResultBuf[0]-1; + + // Verify that pascal strings aren't too large. + if (GetStringLength() > 256) + PP.Diag(StringToks[0].getLocation(), diag::err_pascal_string_too_long) + << SourceRange(StringToks[0].getLocation(), + StringToks[NumStringToks-1].getLocation()); + hadError = 1; + return; + } } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 820326f77a6e..652397939c0f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -295,7 +295,7 @@ Action::ExprResult Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { assert(NumStringToks && "Must have at least one string!"); - StringLiteralParser Literal(StringToks, NumStringToks, PP, Context.Target); + StringLiteralParser Literal(StringToks, NumStringToks, PP); if (Literal.hadError) return ExprResult(true); @@ -303,12 +303,6 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { for (unsigned i = 0; i != NumStringToks; ++i) StringTokLocs.push_back(StringToks[i].getLocation()); - // Verify that pascal strings aren't too large. - if (Literal.Pascal && Literal.GetStringLength() > 256) - return Diag(StringToks[0].getLocation(), diag::err_pascal_string_too_long) - << SourceRange(StringToks[0].getLocation(), - StringToks[NumStringToks-1].getLocation()); - QualType StrTy = Context.CharTy; if (Literal.AnyWide) StrTy = Context.getWCharType(); if (Literal.Pascal) StrTy = Context.UnsignedCharTy;