diff options
author | Andy Gibbs <andyg1001@hotmail.co.uk> | 2012-11-17 19:15:38 +0000 |
---|---|---|
committer | Andy Gibbs <andyg1001@hotmail.co.uk> | 2012-11-17 19:15:38 +0000 |
commit | 02a176871d91bba3004e4f94b2d4d588ae4b2122 (patch) | |
tree | 526b40ca59194f0bdb548e3ac2ae64983861c4c2 /lib/Lex/PPMacroExpansion.cpp | |
parent | b9971bada4eeae74883b61ba96fc6d983b6b0e7f (diff) |
Refactored duplicate string literal lexing code within Preprocessor, into a
common LexStringLiteral function. In doing so, some consistency problems have
been ironed out (e.g. where the first token in the string literal was lexed
with macro expansion, but subsequent ones were not) and also an erroneous
diagnostic has been corrected.
LexStringLiteral is complemented by a FinishLexStringLiteral function which
can be used in the situation where the first token of the string literal has
already been lexed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168266 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPMacroExpansion.cpp')
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 96 |
1 files changed, 36 insertions, 60 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 1f07a70d3a..9f962b027f 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -21,7 +21,7 @@ #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/ExternalPreprocessorSource.h" -#include "clang/Lex/LiteralSupport.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Config/llvm-config.h" @@ -1280,69 +1280,45 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { bool IsValid = false; bool Value = false; // Read the '('. - Lex(Tok); + LexUnexpandedToken(Tok); do { - if (Tok.is(tok::l_paren)) { - // Read the string. - Lex(Tok); - - // We need at least one string literal. - if (!Tok.is(tok::string_literal)) { - StartLoc = Tok.getLocation(); - IsValid = false; - // Eat tokens until ')'. - while (Tok.isNot(tok::r_paren) - && Tok.isNot(tok::eod) - && Tok.isNot(tok::eof)) - Lex(Tok); - break; - } - - // String concatenation allows multiple strings, which can even come - // from macro expansion. - SmallVector<Token, 4> StrToks; - while (Tok.is(tok::string_literal)) { - // Complain about, and drop, any ud-suffix. - if (Tok.hasUDSuffix()) - Diag(Tok, diag::err_invalid_string_udl); - StrToks.push_back(Tok); + if (Tok.isNot(tok::l_paren)) { + Diag(StartLoc, diag::err_warning_check_malformed); + break; + } + + LexUnexpandedToken(Tok); + std::string WarningName; + SourceLocation StrStartLoc = Tok.getLocation(); + if (!FinishLexStringLiteral(Tok, WarningName, /*MacroExpansion=*/false)) { + // Eat tokens until ')'. + while (Tok.isNot(tok::r_paren) + && Tok.isNot(tok::eod) + && Tok.isNot(tok::eof)) LexUnexpandedToken(Tok); - } - - // Is the end a ')'? - if (!(IsValid = Tok.is(tok::r_paren))) - break; - - // Concatenate and parse the strings. - StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this); - assert(Literal.isAscii() && "Didn't allow wide strings in"); - if (Literal.hadError) - break; - if (Literal.Pascal) { - Diag(Tok, diag::warn_pragma_diagnostic_invalid); - break; - } - - StringRef WarningName(Literal.GetString()); - - if (WarningName.size() < 3 || WarningName[0] != '-' || - WarningName[1] != 'W') { - Diag(StrToks[0].getLocation(), diag::warn_has_warning_invalid_option); - break; - } - - // Finally, check if the warning flags maps to a diagnostic group. - // We construct a SmallVector here to talk to getDiagnosticIDs(). - // Although we don't use the result, this isn't a hot path, and not - // worth special casing. - llvm::SmallVector<diag::kind, 10> Diags; - Value = !getDiagnostics().getDiagnosticIDs()-> - getDiagnosticsInGroup(WarningName.substr(2), Diags); + break; } + + // Is the end a ')'? + if (!(IsValid = Tok.is(tok::r_paren))) { + Diag(StartLoc, diag::err_warning_check_malformed); + break; + } + + if (WarningName.size() < 3 || WarningName[0] != '-' || + WarningName[1] != 'W') { + Diag(StrStartLoc, diag::warn_has_warning_invalid_option); + break; + } + + // Finally, check if the warning flags maps to a diagnostic group. + // We construct a SmallVector here to talk to getDiagnosticIDs(). + // Although we don't use the result, this isn't a hot path, and not + // worth special casing. + llvm::SmallVector<diag::kind, 10> Diags; + Value = !getDiagnostics().getDiagnosticIDs()-> + getDiagnosticsInGroup(WarningName.substr(2), Diags); } while (false); - - if (!IsValid) - Diag(StartLoc, diag::err_warning_check_malformed); OS << (int)Value; if (IsValid) |