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

Daniel Dunbar daniel at zuster.org
Sat Oct 4 12:17:46 PDT 2008


Author: ddunbar
Date: Sat Oct  4 14:17:46 2008
New Revision: 57065

URL: http://llvm.org/viewvc/llvm-project?rev=57065&view=rev
Log:
Add Preprocessor::RemovePragmaHandler.
 - No functionality change.

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

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Pragma.h (original)
+++ cfe/trunk/include/clang/Lex/Pragma.h Sat Oct  4 14:17:46 2008
@@ -71,6 +71,14 @@
     Handlers.push_back(Handler);
   }
 
+  /// RemovePragmaHandler - Remove the given handler from the
+  /// namespace.
+  void RemovePragmaHandler(PragmaHandler *Handler);
+
+  bool IsEmpty() { 
+    return Handlers.empty(); 
+  }
+
   virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
   
   virtual PragmaNamespace *getIfNamespace() { return this; }

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Oct  4 14:17:46 2008
@@ -242,6 +242,12 @@
   /// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
   void AddPragmaHandler(const char *Namespace, PragmaHandler *Handler);
 
+  /// RemovePragmaHandler - Remove the specific pragma handler from
+  /// the preprocessor. If \arg Namespace is non-null, then it should
+  /// be the namespace that \arg Handler was added to. It is an error
+  /// to remove a handler that has not been registered.
+  void RemovePragmaHandler(const char *Namespace, PragmaHandler *Handler);
+
   /// EnterMainSourceFile - Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();  

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

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sat Oct  4 14:17:46 2008
@@ -51,6 +51,17 @@
   return IgnoreNull ? 0 : NullHandler;
 }
 
+void PragmaNamespace::RemovePragmaHandler(PragmaHandler *Handler) {
+  for (unsigned i = 0, e = Handlers.size(); i != e; ++i) {
+    if (Handlers[i] == Handler) {
+      Handlers[i] = Handlers.back();
+      Handlers.pop_back();
+      return;
+    }
+  }
+  assert(0 && "Handler not registered in this namespace");
+}
+
 void PragmaNamespace::HandlePragma(Preprocessor &PP, Token &Tok) {
   // Read the 'namespace' that the directive is in, e.g. STDC.  Do not macro
   // expand it, the user can have a STDC #define, that should not affect this.
@@ -325,6 +336,32 @@
   InsertNS->AddPragma(Handler);
 }
 
+/// RemovePragmaHandler - Remove the specific pragma handler from the
+/// preprocessor. If \arg Namespace is non-null, then it should be the
+/// namespace that \arg Handler was added to. It is an error to remove
+/// a handler that has not been registered.
+void Preprocessor::RemovePragmaHandler(const char *Namespace,
+                                       PragmaHandler *Handler) {
+  PragmaNamespace *NS = PragmaHandlers;
+  
+  // If this is specified to be in a namespace, step down into it.
+  if (Namespace) {
+    IdentifierInfo *NSID = getIdentifierInfo(Namespace);
+    PragmaHandler *Existing = PragmaHandlers->FindHandler(NSID);
+    assert(Existing && "Namespace containing handler does not exist!");
+
+    NS = Existing->getIfNamespace();
+    assert(NS && "Invalid namespace, registered as a regular pragma handler!");
+  }
+
+  NS->RemovePragmaHandler(Handler);
+  
+  // If this is a non-default namespace and it is now empty, remove
+  // it.
+  if (NS != PragmaHandlers && NS->IsEmpty())
+    PragmaHandlers->RemovePragmaHandler(NS);
+}
+
 namespace {
 /// PragmaOnceHandler - "#pragma once" marks the file as atomically included.
 struct PragmaOnceHandler : public PragmaHandler {





More information about the cfe-commits mailing list