summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2018-11-30 19:21:35 +0000
committerKristof Umann <dkszelethus@gmail.com>2018-11-30 19:21:35 +0000
commit0f0125b9c59108b4f3a9fda07841b35b590b3a74 (patch)
treed4923cbf4fbdd11d7f3f577ceef9e4a12b7e1eaa /lib
parent1680262de178d4a2a8bdb944ad937846b68725a4 (diff)
downloadclang-0f0125b9c59108b4f3a9fda07841b35b590b3a74.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348025 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/StaticAnalyzer/Core/PlistDiagnostics.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 10480a2eb9..6ce42429db 100644
--- a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/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;