[cfe-commits] r38776 - in /cfe/cfe/trunk: Lex/MacroExpander.cpp include/clang/Lex/Preprocessor.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:31 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:31 2007
New Revision: 38776

URL: http://llvm.org/viewvc/llvm-project?rev=38776&view=rev
Log:
Implement support for __VA_ARGS__, allowing test/Preprocessor/macro_fn_varargs_iso.c
to pass.

Modified:
    cfe/cfe/trunk/Lex/MacroExpander.cpp
    cfe/cfe/trunk/include/clang/Lex/Preprocessor.h

Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=38776&r1=38775&r2=38776&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:24:31 2007
@@ -246,7 +246,7 @@
 
   // If this is a function-like macro, expand the arguments and change
   // MacroTokens to point to the expanded tokens.
-  if (Macro->isFunctionLike() && Macro->getNumArgs())
+  if (Macro->isFunctionLike() && Macro->getNumArgs() || Macro->isC99Varargs())
     ExpandFunctionArguments();
   
   // Mark the macro as currently disabled, so that it is not recursively
@@ -288,6 +288,8 @@
 void MacroExpander::ExpandFunctionArguments() {
   SmallVector<LexerToken, 128> ResultToks;
   
+  IdentifierInfo *VAARGSii = PP.get__VA_ARGS__Identifier();
+  
   // Loop through the MacroTokens tokens, expanding them into ResultToks.  Keep
   // track of whether we change anything.  If not, no need to keep them.  If so,
   // we install the newly expanded sequence as MacroTokens.
@@ -325,8 +327,14 @@
     IdentifierInfo *II = CurTok.getIdentifierInfo();
     int ArgNo = II ? Macro->getArgumentNum(II) : -1;
     if (ArgNo == -1) {
-      ResultToks.push_back(CurTok);
-      continue;
+      if (II != VAARGSii || !Macro->isC99Varargs()) {
+        // This isn't an argument and isn't __VA_ARGS__.  Just add it.
+        ResultToks.push_back(CurTok);
+        continue;
+      }
+      
+      // Otherwise, this *is* __VA_ARGS__.  Set ArgNo to the last argument.
+      ArgNo = Macro->getNumArgs();
     }
       
     // An argument is expanded somehow, the result is different than the

Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38776&r1=38775&r2=38776&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:24:31 2007
@@ -387,6 +387,12 @@
   SourceLocation CreateString(const char *Buf, unsigned Len,
                               SourceLocation SourceLoc = SourceLocation());
   
+  /// get__VA_ARGS__Identifier - Return the identifier info for the __VA_ARGS__
+  /// identifier.
+  IdentifierInfo *get__VA_ARGS__Identifier() const {
+    return Ident__VA_ARGS__;
+  }
+  
   /// DumpToken - Print the token to stderr, used for debugging.
   ///
   void DumpToken(const LexerToken &Tok, bool DumpFlags = false) const;





More information about the cfe-commits mailing list