[cfe-commits] r69659 - in /cfe/trunk: include/clang/Lex/MacroInfo.h lib/Lex/PPDirectives.cpp

Chris Lattner sabre at nondot.org
Mon Apr 20 21:46:33 PDT 2009


Author: lattner
Date: Mon Apr 20 23:46:33 2009
New Revision: 69659

URL: http://llvm.org/viewvc/llvm-project?rev=69659&view=rev
Log:
improve MacroInfo to track the source range of the macro definition,
patch by Alexei Svitkine!

Modified:
    cfe/trunk/include/clang/Lex/MacroInfo.h
    cfe/trunk/lib/Lex/PPDirectives.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Mon Apr 20 23:46:33 2009
@@ -31,6 +31,8 @@
 
   /// Location - This is the place the macro is defined.
   SourceLocation Location;
+  /// EndLocation - The location of the last token in the macro.
+  SourceLocation EndLocation;
 
   /// Arguments - The list of arguments for a function-like macro.  This can be
   /// empty, for, e.g. "#define X()".  In a C99-style variadic macro, this
@@ -98,7 +100,14 @@
   /// getDefinitionLoc - Return the location that the macro was defined at.
   ///
   SourceLocation getDefinitionLoc() const { return Location; }
-  
+
+  /// setDefinitionEndLoc - Set the location of the last token in the macro.
+  ///
+  void setDefinitionEndLoc(SourceLocation EndLoc) { EndLocation = EndLoc; }
+  /// getDefinitionEndLoc - Return the location of the last token in the macro.
+  ///
+  SourceLocation getDefinitionEndLoc() const { return EndLocation; }
+
   /// isIdenticalTo - Return true if the specified macro definition is equal to
   /// this macro in spelling, arguments, and whitespace.  This is used to emit
   /// duplicate definition warnings.  This implements the rules in C99 6.10.3.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=69659&r1=69658&r2=69659&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Apr 20 23:46:33 2009
@@ -1275,6 +1275,8 @@
   if (MacroNameTok.is(tok::eom))
     return;
 
+  Token LastTok = MacroNameTok;
+
   // If we are supposed to keep comments in #defines, reenable comment saving
   // mode.
   if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments);
@@ -1342,11 +1344,15 @@
     else
       Diag(Tok, diag::warn_missing_whitespace_after_macro_name);
   }
-  
+
+  if (!Tok.is(tok::eom))
+    LastTok = Tok;
+
   // Read the rest of the macro body.
   if (MI->isObjectLike()) {
     // Object-like macros are very simple, just read their body.
     while (Tok.isNot(tok::eom)) {
+      LastTok = Tok;
       MI->AddTokenToBody(Tok);
       // Get the next token of the macro.
       LexUnexpandedToken(Tok);
@@ -1356,6 +1362,7 @@
     // Otherwise, read the body of a function-like macro.  This has to validate
     // the # (stringize) operator.
     while (Tok.isNot(tok::eom)) {
+      LastTok = Tok;
       MI->AddTokenToBody(Tok);
 
       // Check C99 6.10.3.2p1: ensure that # operators are followed by macro
@@ -1412,6 +1419,8 @@
   // used yet.
   if (isInPrimaryFile())
     MI->setIsUsed(false);
+
+  MI->setDefinitionEndLoc(LastTok.getLocation());
   
   // Finally, if this identifier already had a macro defined for it, verify that
   // the macro bodies are identical and free the old definition.





More information about the cfe-commits mailing list