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

Chris Lattner sabre at nondot.org
Sat Mar 8 18:07:50 PST 2008


Author: lattner
Date: Sat Mar  8 20:07:49 2008
New Revision: 48070

URL: http://llvm.org/viewvc/llvm-project?rev=48070&view=rev
Log:
rename MacroTokens -> Tokens.  When this is a token stream, there is no macro
involved.

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

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

==============================================================================
--- cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/trunk/Lex/MacroExpander.cpp Sat Mar  8 20:07:49 2008
@@ -245,12 +245,12 @@
   InstantiateLoc = Tok.getLocation();
   AtStartOfLine = Tok.isAtStartOfLine();
   HasLeadingSpace = Tok.hasLeadingSpace();
-  MacroTokens = &*Macro->tokens_begin();
-  OwnsMacroTokens = false;
-  NumMacroTokens = Macro->tokens_end()-Macro->tokens_begin();
+  Tokens = &*Macro->tokens_begin();
+  OwnsTokens = false;
+  NumTokens = Macro->tokens_end()-Macro->tokens_begin();
 
   // If this is a function-like macro, expand the arguments and change
-  // MacroTokens to point to the expanded tokens.
+  // Tokens to point to the expanded tokens.
   if (Macro->isFunctionLike() && Macro->getNumArgs())
     ExpandFunctionArguments();
   
@@ -271,9 +271,9 @@
   
   Macro = 0;
   ActualArgs = 0;
-  MacroTokens = TokArray;
-  OwnsMacroTokens = false;
-  NumMacroTokens = NumToks;
+  Tokens = TokArray;
+  OwnsTokens = false;
+  NumTokens = NumToks;
   CurToken = 0;
   InstantiateLoc = SourceLocation();
   AtStartOfLine = false;
@@ -291,9 +291,9 @@
 void MacroExpander::destroy() {
   // If this was a function-like macro that actually uses its arguments, delete
   // the expanded tokens.
-  if (OwnsMacroTokens) {
-    delete [] MacroTokens;
-    MacroTokens = 0;
+  if (OwnsTokens) {
+    delete [] Tokens;
+    Tokens = 0;
   }
   
   // MacroExpander owns its formal arguments.
@@ -301,13 +301,13 @@
 }
 
 /// Expand the arguments of a function-like macro so that we can quickly
-/// return preexpanded tokens from MacroTokens.
+/// return preexpanded tokens from Tokens.
 void MacroExpander::ExpandFunctionArguments() {
   llvm::SmallVector<Token, 128> ResultToks;
   
-  // Loop through the MacroTokens tokens, expanding them into ResultToks.  Keep
+  // Loop through '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.
+  // we install the newly expanded sequence as the new 'Tokens' list.
   bool MadeChange = false;
   
   // NextTokGetsSpace - When this is true, the next token appended to the
@@ -315,13 +315,13 @@
   // begin with or not.  This is used for placemarker support.
   bool NextTokGetsSpace = false;
   
-  for (unsigned i = 0, e = NumMacroTokens; i != e; ++i) {
+  for (unsigned i = 0, e = NumTokens; i != e; ++i) {
     // If we found the stringify operator, get the argument stringified.  The
     // preprocessor already verified that the following token is a macro name
     // when the #define was parsed.
-    const Token &CurTok = MacroTokens[i];
+    const Token &CurTok = Tokens[i];
     if (CurTok.is(tok::hash) || CurTok.is(tok::hashat)) {
-      int ArgNo = Macro->getArgumentNum(MacroTokens[i+1].getIdentifierInfo());
+      int ArgNo = Macro->getArgumentNum(Tokens[i+1].getIdentifierInfo());
       assert(ArgNo != -1 && "Token following # is not an argument?");
     
       Token Res;
@@ -367,7 +367,7 @@
     // (##) operator before or after the argument.
     bool PasteBefore = 
       !ResultToks.empty() && ResultToks.back().is(tok::hashhash);
-    bool PasteAfter = i+1 != e && MacroTokens[i+1].is(tok::hashhash);
+    bool PasteAfter = i+1 != e && Tokens[i+1].is(tok::hashhash);
     
     // If it is not the LHS/RHS of a ## operator, we must pre-expand the
     // argument and substitute the expanded tokens into the result.  This is
@@ -441,7 +441,7 @@
     if (PasteAfter) {
       // Discard the argument token and skip (don't copy to the expansion
       // buffer) the paste operator after it.
-      NextTokGetsSpace |= MacroTokens[i+1].hasLeadingSpace();
+      NextTokGetsSpace |= Tokens[i+1].hasLeadingSpace();
       ++i;
       continue;
     }
@@ -467,15 +467,15 @@
     continue;
   }
   
-  // If anything changed, install this as the new MacroTokens list.
+  // If anything changed, install this as the new Tokens list.
   if (MadeChange) {
     // This is deleted in the dtor.
-    NumMacroTokens = ResultToks.size();
+    NumTokens = ResultToks.size();
     Token *Res = new Token[ResultToks.size()];
-    if (NumMacroTokens)
-      memcpy(Res, &ResultToks[0], NumMacroTokens*sizeof(Token));
-    MacroTokens = Res;
-    OwnsMacroTokens = true;
+    if (NumTokens)
+      memcpy(Res, &ResultToks[0], NumTokens*sizeof(Token));
+    Tokens = Res;
+    OwnsTokens = true;
   }
 }
 
@@ -504,10 +504,10 @@
   bool isFirstToken = CurToken == 0;
   
   // Get the next token to return.
-  Tok = MacroTokens[CurToken++];
+  Tok = Tokens[CurToken++];
   
   // If this token is followed by a token paste (##) operator, paste the tokens!
-  if (!isAtEnd() && MacroTokens[CurToken].is(tok::hashhash))
+  if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash))
     if (PasteTokens(Tok)) {
       // When handling the microsoft /##/ extension, the final token is
       // returned by PasteTokens, not the pasted token.
@@ -547,12 +547,12 @@
   llvm::SmallVector<char, 128> Buffer;
   do {
     // Consume the ## operator.
-    SourceLocation PasteOpLoc = MacroTokens[CurToken].getLocation();
+    SourceLocation PasteOpLoc = Tokens[CurToken].getLocation();
     ++CurToken;
     assert(!isAtEnd() && "No token on the RHS of a paste operator!");
   
     // Get the RHS token.
-    const Token &RHS = MacroTokens[CurToken];
+    const Token &RHS = Tokens[CurToken];
   
     bool isInvalid = false;
 
@@ -652,7 +652,7 @@
     // Finally, replace LHS with the result, consume the RHS, and iterate.
     ++CurToken;
     Tok = Result;
-  } while (!isAtEnd() && MacroTokens[CurToken].is(tok::hashhash));
+  } while (!isAtEnd() && Tokens[CurToken].is(tok::hashhash));
   
   // Now that we got the result token, it will be subject to expansion.  Since
   // token pasting re-lexes the result token in raw mode, identifier information
@@ -672,7 +672,7 @@
   // Out of tokens?
   if (isAtEnd())
     return 2;
-  return MacroTokens[CurToken].is(tok::l_paren);
+  return Tokens[CurToken].is(tok::l_paren);
 }
 
 

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

==============================================================================
--- cfe/trunk/include/clang/Lex/MacroExpander.h (original)
+++ cfe/trunk/include/clang/Lex/MacroExpander.h Sat Mar  8 20:07:49 2008
@@ -115,14 +115,14 @@
   ///
   Preprocessor &PP;
 
-  /// MacroTokens - This is the pointer to an array of tokens that the macro is
+  /// Tokens - This is the pointer to an array of tokens that the macro is
   /// defined to, with arguments expanded for function-like macros.  If this is
   /// a token stream, these are the tokens we are returning.
-  const Token *MacroTokens;
+  const Token *Tokens;
   
-  /// NumMacroTokens - This is the length of the MacroTokens array.
+  /// NumTokens - This is the length of the Tokens array.
   ///
-  unsigned NumMacroTokens;
+  unsigned NumTokens;
   
   /// CurToken - This is the next token that Lex will return.
   ///
@@ -137,9 +137,11 @@
   bool AtStartOfLine : 1;
   bool HasLeadingSpace : 1;
   
-  /// OwnsMacroTokens - This is true if this macroexpander allocated the
-  /// MacroTokens array, and thus needs to free it when destroyed.
-  bool OwnsMacroTokens : 1;
+  /// OwnsTokens - This is true if this MacroExpander allocated the Tokens
+  /// array, and thus needs to free it when destroyed.  For simple object-like
+  /// macros (for example) we just point into the token buffer of the macro
+  /// definition, we don't make a copy of it.
+  bool OwnsTokens : 1;
   
   MacroExpander(const MacroExpander&);  // DO NOT IMPLEMENT
   void operator=(const MacroExpander&); // DO NOT IMPLEMENT
@@ -147,7 +149,7 @@
   /// Create a macro expander for the specified macro with the specified actual
   /// arguments.  Note that this ctor takes ownership of the ActualArgs pointer.
   MacroExpander(Token &Tok, MacroArgs *ActualArgs, Preprocessor &pp)
-    : Macro(0), ActualArgs(0), PP(pp), OwnsMacroTokens(false) {
+    : Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
     Init(Tok, ActualArgs);
   }
   
@@ -159,7 +161,7 @@
   /// Create a macro expander for the specified token stream.  This does not
   /// take ownership of the specified token vector.
   MacroExpander(const Token *TokArray, unsigned NumToks, Preprocessor &pp)
-    : Macro(0), ActualArgs(0), PP(pp), OwnsMacroTokens(false) {
+    : Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
     Init(TokArray, NumToks);
   }
   
@@ -183,7 +185,7 @@
   /// isAtEnd - Return true if the next lex call will pop this macro off the
   /// include stack.
   bool isAtEnd() const {
-    return CurToken == NumMacroTokens;
+    return CurToken == NumTokens;
   }
   
   /// PasteTokens - Tok is the LHS of a ## operator, and CurToken is the ##
@@ -194,7 +196,7 @@
   bool PasteTokens(Token &Tok);
   
   /// Expand the arguments of a function-like macro so that we can quickly
-  /// return preexpanded tokens from MacroTokens.
+  /// return preexpanded tokens from Tokens.
   void ExpandFunctionArguments();
   
   /// HandleMicrosoftCommentPaste - In microsoft compatibility mode, /##/ pastes





More information about the cfe-commits mailing list