Skip to content

Commit 5f9981f

Browse files
committed
[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
1 parent 27b1e3b commit 5f9981f

File tree

3 files changed

+439
-76
lines changed

3 files changed

+439
-76
lines changed

clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,6 @@ static std::string getMacroNameAndPrintExpansion(TokenPrinter &Printer,
904904
continue;
905905
}
906906

907-
// TODO: Handle tok::hash and tok::hashhash.
908-
909907
// If control reached here, then this token isn't a macro identifier, nor an
910908
// unexpanded macro argument that we need to handle, print it.
911909
Printer.printToken(T);
@@ -1094,14 +1092,25 @@ void MacroArgMap::expandFromPrevMacro(const MacroArgMap &Super) {
10941092
}
10951093

10961094
void TokenPrinter::printToken(const Token &Tok) {
1097-
// If the tokens were already space separated, or if they must be to avoid
1098-
// them being implicitly pasted, add a space between them.
10991095
// If this is the first token to be printed, don't print space.
1100-
if (PrevTok.isNot(tok::unknown) && (Tok.hasLeadingSpace() ||
1101-
ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok)))
1102-
OS << ' ';
1096+
if (PrevTok.isNot(tok::unknown)) {
1097+
// If the tokens were already space separated, or if they must be to avoid
1098+
// them being implicitly pasted, add a space between them.
1099+
if(Tok.hasLeadingSpace() || ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok,
1100+
Tok)) {
1101+
// AvoidConcat doesn't check for ##, don't print a space around it.
1102+
if (PrevTok.isNot(tok::hashhash) && Tok.isNot(tok::hashhash)) {
1103+
OS << ' ';
1104+
}
1105+
}
1106+
}
11031107

1104-
OS << PP.getSpelling(Tok);
1108+
if (!Tok.isOneOf(tok::hash, tok::hashhash)) {
1109+
if (PrevTok.is(tok::hash))
1110+
OS << '\"' << PP.getSpelling(Tok) << '\"';
1111+
else
1112+
OS << PP.getSpelling(Tok);
1113+
}
11051114

11061115
PrevPrevTok = PrevTok;
11071116
PrevTok = Tok;

0 commit comments

Comments
 (0)