[cfe-dev] Clang and MSVC11 headers

Leszek Świrski leszek at swirski.co.uk
Tue May 7 07:43:19 PDT 2013


On 2 May 2013 12:25, João Matos <ripzonetriton at gmail.com> wrote:
> My patch is probably an hack, and I don't know enough about the
preprocessor works to understand how to do the correct fix without spending
a lot of time researching it. Your explanation sounds interesting though.

Actually, having taken another look at your patch, it looks like it could
almost do the job. Rather than just ignoring all expanded commas, I've made
a change where all freshly expanded tokens are ignored by the lexer when
first passed over, which seems to be doing the job so far. The below patch
is a quick hack that doesn't check if we're running in ms-compatibility
mode yet, still testing if it's actually ms-compatibile.

Still a hack, but I suspect a non-hack ms-compatibilty for this would
involve some major reshuffling of the lexer.

--------

diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h
index bcbe9c9..d3a2118 100644
--- a/include/clang/Lex/Token.h
+++ b/include/clang/Lex/Token.h
@@ -77,7 +77,8 @@ public:
     NeedsCleaning = 0x08,  // Contained an escaped newline or trigraph.
     LeadingEmptyMacro = 0x10, // Empty macro exists before this token.
     HasUDSuffix = 0x20,    // This string or character literal has a
ud-suffix.
-    HasUCN = 0x40          // This identifier contains a UCN.
+    HasUCN = 0x40,         // This identifier contains a UCN.
+    FreshExpanded = 0x80   // This token was a recent macro expansion.
   };

   tok::TokenKind getKind() const { return (tok::TokenKind)Kind; }
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index 1678233..96980f6 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -450,6 +450,8 @@ MacroArgs
*Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
           EnterTokenStream(Toks, 1, true, true);
           break;
         }
+      } else if (Tok.getFlags() & Token::FreshExpanded) {
+          Tok.clearFlag(Token::FreshExpanded);
       } else if (Tok.is(tok::r_paren)) {
         // If we found the ) token, the macro arg list is done.
         if (NumParens-- == 0) {
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 07753c7..ae19b82 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -282,6 +282,7 @@ void TokenLexer::ExpandFunctionArguments() {
           Token &Tok = ResultToks[i];
           if (Tok.is(tok::hashhash))
             Tok.setKind(tok::unknown);
+          Tok.setFlag(Token::FreshExpanded);
         }

         if(ExpandLocStart.isValid()) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130507/07330304/attachment.html>


More information about the cfe-dev mailing list