Skip to content

Commit

Permalink
[analyzer][PlistMacroExpansion] Part 5.: Support for # and ##
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Szelethus committed Nov 30, 2018
1 parent 27b1e3b commit 5f9981f
Show file tree
Hide file tree
Showing 3 changed files with 439 additions and 76 deletions.
25 changes: 17 additions & 8 deletions clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5f9981f

Please sign in to comment.