From 5f9981f8a5a7acf044b347438d16fe46af97c1c0 Mon Sep 17 00:00:00 2001 From: Kristof Umann Date: Fri, 30 Nov 2018 19:21:35 +0000 Subject: [analyzer][PlistMacroExpansion] Part 5.: Support for # and ## From what I can see, this should be the last patch needed to replicate macro argument expansions. Differential Revision: https://reviews.llvm.org/D52988 llvm-svn: 348025 --- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core') diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index 10480a2eb9d..6ce42429dbf 100644 --- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -904,8 +904,6 @@ static std::string getMacroNameAndPrintExpansion(TokenPrinter &Printer, continue; } - // TODO: Handle tok::hash and tok::hashhash. - // If control reached here, then this token isn't a macro identifier, nor an // unexpanded macro argument that we need to handle, print it. Printer.printToken(T); @@ -1094,14 +1092,25 @@ void MacroArgMap::expandFromPrevMacro(const MacroArgMap &Super) { } void TokenPrinter::printToken(const Token &Tok) { - // If the tokens were already space separated, or if they must be to avoid - // them being implicitly pasted, add a space between them. // If this is the first token to be printed, don't print space. - if (PrevTok.isNot(tok::unknown) && (Tok.hasLeadingSpace() || - ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok))) - OS << ' '; + if (PrevTok.isNot(tok::unknown)) { + // If the tokens were already space separated, or if they must be to avoid + // them being implicitly pasted, add a space between them. + if(Tok.hasLeadingSpace() || ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, + Tok)) { + // AvoidConcat doesn't check for ##, don't print a space around it. + if (PrevTok.isNot(tok::hashhash) && Tok.isNot(tok::hashhash)) { + OS << ' '; + } + } + } - OS << PP.getSpelling(Tok); + if (!Tok.isOneOf(tok::hash, tok::hashhash)) { + if (PrevTok.is(tok::hash)) + OS << '\"' << PP.getSpelling(Tok) << '\"'; + else + OS << PP.getSpelling(Tok); + } PrevPrevTok = PrevTok; PrevTok = Tok; -- cgit v1.2.3