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

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:20 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:20 2007
New Revision: 38627

URL: http://llvm.org/viewvc/llvm-project?rev=38627&view=rev
Log:
Fix test/Preprocessor/macro_defined.c, factor some code.

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

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38627&r1=38626&r2=38627&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:20 2007
@@ -808,8 +808,10 @@
 
 /// ReadMacroName - Lex and validate a macro name, which occurs after a
 /// #define or #undef.  This sets the token kind to eom and discards the rest
-/// of the macro line if the macro name is invalid.
-void Preprocessor::ReadMacroName(LexerToken &MacroNameTok) {
+/// of the macro line if the macro name is invalid.  isDefineUndef is true if
+/// this is due to a a #define or #undef directive, false if it is something
+/// else (e.g. #ifdef).
+void Preprocessor::ReadMacroName(LexerToken &MacroNameTok, bool isDefineUndef) {
   // Read the token, don't allow macro expansion on it.
   LexUnexpandedToken(MacroNameTok);
   
@@ -824,17 +826,19 @@
   } else if (0) {
     // FIXME: C++.  Error if defining a C++ named operator.
     
-  } else if (ITI->getName()[0] == 'd' &&      // defined
+  } else if (isDefineUndef && ITI->getName()[0] == 'd' &&      // defined
              !strcmp(ITI->getName()+1, "efined")) {
-    // Error if defining "defined": C99 6.10.8.4.  Predefined macros (like
-    // __LINE__) are handled in the undef/define handlers.
+    // Error if defining "defined": C99 6.10.8.4.
     Diag(MacroNameTok, diag::err_defined_macro_name);
+  } else if (isDefineUndef && ITI->getMacroInfo() &&
+             ITI->getMacroInfo()->isBuiltinMacro()) {
+    // Error if defining "__LINE__" and other builtins: C99 6.10.8.4.
+    Diag(MacroNameTok, diag::pp_undef_builtin_macro);
   } else {
     // Okay, we got a good identifier node.  Return it.
     return;
   }
   
-  
   // Invalid macro name, read and discard the rest of the line.  Then set the
   // token kind to tok::eom.
   MacroNameTok.SetKind(tok::eom);
@@ -1255,7 +1259,7 @@
 void Preprocessor::HandleDefineDirective(LexerToken &DefineTok) {
   ++NumDefined;
   LexerToken MacroNameTok;
-  ReadMacroName(MacroNameTok);
+  ReadMacroName(MacroNameTok, true);
   
   // Error reading macro name?  If so, diagnostic already issued.
   if (MacroNameTok.getKind() == tok::eom)
@@ -1301,9 +1305,6 @@
   // Finally, if this identifier already had a macro defined for it, verify that
   // the macro bodies are identical and free the old definition.
   if (MacroInfo *OtherMI = MacroNameTok.getIdentifierInfo()->getMacroInfo()) {
-    if (OtherMI->isBuiltinMacro())       // C99 6.10.8.4
-      Diag(MacroNameTok, diag::pp_redef_builtin_macro);
-    
     
     // FIXME: Verify the definition is the same.
     // Macros must be identical.  This means all tokes and whitespace separation
@@ -1320,7 +1321,7 @@
 void Preprocessor::HandleUndefDirective(LexerToken &UndefTok) {
   ++NumUndefined;
   LexerToken MacroNameTok;
-  ReadMacroName(MacroNameTok);
+  ReadMacroName(MacroNameTok, true);
   
   // Error reading macro name?  If so, diagnostic already issued.
   if (MacroNameTok.getKind() == tok::eom)
@@ -1335,9 +1336,6 @@
   // If the macro is not defined, this is a noop undef, just return.
   if (MI == 0) return;
 
-  if (MI->isBuiltinMacro())       // C99 6.10.8.4
-    Diag(MacroNameTok, diag::pp_undef_builtin_macro);
-  
 #if 0 // FIXME: implement warn_unused_macros.
   if (CPP_OPTION (pfile, warn_unused_macros))
     _cpp_warn_if_unused_macro (pfile, node, NULL);

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=38627&r1=38626&r2=38627&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:20 2007
@@ -394,7 +394,7 @@
   /// ReadMacroName - Lex and validate a macro name, which occurs after a
   /// #define or #undef.  This emits a diagnostic, sets the token kind to eom,
   /// and discards the rest of the macro line if the macro name is invalid.
-  void ReadMacroName(LexerToken &MacroNameTok);
+  void ReadMacroName(LexerToken &MacroNameTok, bool isDefineUndef = false);
   
   /// SkipExcludedConditionalBlock - We just read a #if or related directive and
   /// decided that the subsequent tokens are in the #if'd out portion of the





More information about the cfe-commits mailing list