[cfe-commits] r68522 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/AST/DeclContextInternals.h include/clang/AST/DeclVisitor.h include/clang/AST/Stmt.h lib/AST/ASTContext.cpp lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 7 10:21:09 PDT 2009


Author: dgregor
Date: Tue Apr  7 12:20:56 2009
New Revision: 68522

URL: http://llvm.org/viewvc/llvm-project?rev=68522&view=rev
Log:
Move the internal DeclContext data structures into a separate header. 

Simplify the addition of a case statement to a switch.

Fix -print-stats for attribute-qualified types.


Added:
    cfe/trunk/include/clang/AST/DeclContextInternals.h   (with props)
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclVisitor.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Apr  7 12:20:56 2009
@@ -870,6 +870,9 @@
     : NamedDecl(DK, DC, L, Id), TypeForDecl(0) {}
 
 public:
+  // Low-level accessor
+  Type *getTypeForDecl() const { return TypeForDecl; }
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
     return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Apr  7 12:20:56 2009
@@ -375,10 +375,6 @@
   /// another pointer.
   Decl *LastDecl;
 
-  /// isLookupMap - Determine if the lookup structure is a
-  /// DenseMap. Othewise, it is an array.
-  bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; }
-
 protected:
    DeclContext(Decl::Kind K) 
      : DeclKind(K), LookupPtr(), FirstDecl(0), LastDecl(0) { }
@@ -761,6 +757,15 @@
     return getUsingDirectives().second;
   }
 
+  // Low-level accessors
+
+  /// \brief Determine if the lookup structure is a
+  /// DenseMap. Othewise, it is an array.
+  bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; }
+
+  /// \brief Retrieve the internal representation of the lookup structure.
+  llvm::PointerIntPair<void*, 3> getLookupPtr() const { return LookupPtr; }
+
   static bool classof(const Decl *D);
   static bool classof(const DeclContext *D) { return true; }
 #define DECL_CONTEXT(Name) \

Added: cfe/trunk/include/clang/AST/DeclContextInternals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclContextInternals.h?rev=68522&view=auto

==============================================================================
--- cfe/trunk/include/clang/AST/DeclContextInternals.h (added)
+++ cfe/trunk/include/clang/AST/DeclContextInternals.h Tue Apr  7 12:20:56 2009
@@ -0,0 +1,135 @@
+//===-- DeclContextInternals.h - DeclContext Representation -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the data structures used in the implementation
+//  of DeclContext.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H
+#define LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H
+
+#include "clang/AST/DeclBase.h"
+#include "clang/AST/DeclarationName.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+/// StoredDeclsList - This is an array of decls optimized a common case of only
+/// containing one entry.
+struct StoredDeclsList {
+  /// VectorTy - When in vector form, this is what the Data pointer points to.
+  typedef llvm::SmallVector<NamedDecl*, 4> VectorTy;
+
+  /// Data - Union of NamedDecl*/VectorTy*.
+  llvm::PointerUnion<NamedDecl*, VectorTy*> Data;
+public:
+  StoredDeclsList() {}
+  StoredDeclsList(const StoredDeclsList &RHS) : Data(RHS.Data) {
+    if (isVector())
+      Data = new VectorTy(*Data.get<VectorTy*>());
+  }
+  
+  ~StoredDeclsList() {
+    // If this is a vector-form, free the vector.
+    if (isVector())
+      delete Data.get<VectorTy*>();
+  }
+  
+  StoredDeclsList &operator=(const StoredDeclsList &RHS) {
+    if (isVector())
+      delete Data.get<VectorTy*>();
+    Data = RHS.Data;
+    if (isVector())
+      Data = new VectorTy(*Data.get<VectorTy*>());
+    return *this;
+  }
+  
+  bool isVector() const { return Data.is<VectorTy*>(); }
+  bool isInline() const { return Data.is<NamedDecl*>(); }
+  bool isNull() const { return Data.isNull(); }
+  
+  void setOnlyValue(NamedDecl *ND) {
+    assert(isInline() && "Not inline");
+    Data = ND;
+  }
+
+  /// getLookupResult - Return an array of all the decls that this list
+  /// represents.
+  DeclContext::lookup_result getLookupResult() {
+    // If we have a single inline unit, return it.
+    if (isInline()) {
+      assert(!isNull() && "Empty list isn't allowed");
+      
+      // Data is a raw pointer to a NamedDecl*, return it.
+      void *Ptr = &Data;
+      return DeclContext::lookup_result((NamedDecl**)Ptr, (NamedDecl**)Ptr+1);
+    }
+    
+    // Otherwise, we have a range result.
+    VectorTy &V = *Data.get<VectorTy*>();
+    return DeclContext::lookup_result(&V[0], &V[0]+V.size());
+  }
+  
+  /// HandleRedeclaration - If this is a redeclaration of an existing decl,
+  /// replace the old one with D and return true.  Otherwise return false.
+  bool HandleRedeclaration(NamedDecl *D) {
+    // Most decls only have one entry in their list, special case it.
+    if (isInline()) {
+      if (!D->declarationReplaces(Data.get<NamedDecl*>()))
+        return false;
+      setOnlyValue(D);
+      return true;
+    }
+    
+    // Determine if this declaration is actually a redeclaration.
+    VectorTy &Vec = *Data.get<VectorTy*>();
+    VectorTy::iterator RDI
+      = std::find_if(Vec.begin(), Vec.end(),
+                     std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
+                                  D));
+    if (RDI == Vec.end())
+      return false;
+    *RDI = D;
+    return true;
+  }
+  
+  /// AddSubsequentDecl - This is called on the second and later decl when it is
+  /// not a redeclaration to merge it into the appropriate place in our list.
+  /// 
+  void AddSubsequentDecl(NamedDecl *D) {
+    // If this is the second decl added to the list, convert this to vector
+    // form.
+    if (isInline()) {
+      NamedDecl *OldD = Data.get<NamedDecl*>();
+      VectorTy *VT = new VectorTy();
+      VT->push_back(OldD);
+      Data = VT;
+    }
+    
+    VectorTy &Vec = *Data.get<VectorTy*>();
+    if (isa<UsingDirectiveDecl>(D) ||
+        D->getIdentifierNamespace() == Decl::IDNS_Tag)
+      Vec.push_back(D);
+    else if (Vec.back()->getIdentifierNamespace() == Decl::IDNS_Tag) {
+      NamedDecl *TagD = Vec.back();
+      Vec.back() = D;
+      Vec.push_back(TagD);
+    } else
+      Vec.push_back(D);
+  }
+};
+
+typedef llvm::DenseMap<DeclarationName, StoredDeclsList> StoredDeclsMap;
+
+
+} // end namespace clang
+
+#endif 

Propchange: cfe/trunk/include/clang/AST/DeclContextInternals.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/include/clang/AST/DeclContextInternals.h

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/include/clang/AST/DeclContextInternals.h

------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cfe/trunk/include/clang/AST/DeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclVisitor.h?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DeclVisitor.h Tue Apr  7 12:20:56 2009
@@ -13,6 +13,9 @@
 #ifndef LLVM_CLANG_AST_DECLVISITOR_H
 #define LLVM_CLANG_AST_DECLVISITOR_H
 
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 
 namespace clang {

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Apr  7 12:20:56 2009
@@ -587,9 +587,8 @@
     SwitchLoc = SL;
   }  
   void addSwitchCase(SwitchCase *SC) {
-    if (FirstCase)
-      SC->setNextSwitchCase(FirstCase);
-
+    assert(!SC->getNextSwitchCase() && "case/default already added to a switch");
+    SC->setNextSwitchCase(FirstCase);
     FirstCase = SC;
   }
   virtual SourceRange getSourceRange() const { 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Apr  7 12:20:56 2009
@@ -103,7 +103,8 @@
   unsigned NumObjCInterfaces = 0, NumObjCQualifiedInterfaces = 0;
   unsigned NumObjCQualifiedIds = 0;
   unsigned NumTypeOfTypes = 0, NumTypeOfExprTypes = 0;
-  
+  unsigned NumExtQual = 0;
+
   for (unsigned i = 0, e = Types.size(); i != e; ++i) {
     Type *T = Types[i];
     if (isa<BuiltinType>(T))
@@ -149,6 +150,8 @@
       ++NumTypeOfTypes;
     else if (isa<TypeOfExprType>(T))
       ++NumTypeOfExprTypes;
+    else if (isa<ExtQualType>(T))
+      ++NumExtQual;
     else {
       QualType(T, 0).dump();
       assert(0 && "Unknown type!");
@@ -179,6 +182,7 @@
           NumObjCQualifiedIds);
   fprintf(stderr, "    %d typeof types\n", NumTypeOfTypes);
   fprintf(stderr, "    %d typeof exprs\n", NumTypeOfExprTypes);
+  fprintf(stderr, "    %d attribute-qualified types\n", NumExtQual);
 
   fprintf(stderr, "Total bytes = %d\n", int(NumBuiltin*sizeof(BuiltinType)+
     NumPointer*sizeof(PointerType)+NumArray*sizeof(ArrayType)+
@@ -189,7 +193,8 @@
     NumFunctionP*sizeof(FunctionProtoType)+
     NumFunctionNP*sizeof(FunctionNoProtoType)+
     NumTypeName*sizeof(TypedefType)+NumTagged*sizeof(TagType)+
-    NumTypeOfTypes*sizeof(TypeOfType)+NumTypeOfExprTypes*sizeof(TypeOfExprType)));
+    NumTypeOfTypes*sizeof(TypeOfType)+NumTypeOfExprTypes*sizeof(TypeOfExprType)+
+    NumExtQual*sizeof(ExtQualType)));
 }
 
 

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=68522&r1=68521&r2=68522&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Apr  7 12:20:56 2009
@@ -13,6 +13,7 @@
 
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclContextInternals.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -363,115 +364,6 @@
   }
 }
 
-/// StoredDeclsList - This is an array of decls optimized a common case of only
-/// containing one entry.
-struct StoredDeclsList {
-  /// VectorTy - When in vector form, this is what the Data pointer points to.
-  typedef llvm::SmallVector<NamedDecl*, 4> VectorTy;
-
-  /// Data - Union of NamedDecl*/VectorTy*.
-  llvm::PointerUnion<NamedDecl*, VectorTy*> Data;
-public:
-  StoredDeclsList() {}
-  StoredDeclsList(const StoredDeclsList &RHS) : Data(RHS.Data) {
-    if (isVector())
-      Data = new VectorTy(*Data.get<VectorTy*>());
-  }
-  
-  ~StoredDeclsList() {
-    // If this is a vector-form, free the vector.
-    if (isVector())
-      delete Data.get<VectorTy*>();
-  }
-  
-  StoredDeclsList &operator=(const StoredDeclsList &RHS) {
-    if (isVector())
-      delete Data.get<VectorTy*>();
-    Data = RHS.Data;
-    if (isVector())
-      Data = new VectorTy(*Data.get<VectorTy*>());
-    return *this;
-  }
-  
-  bool isVector() const { return Data.is<VectorTy*>(); }
-  bool isInline() const { return Data.is<NamedDecl*>(); }
-  bool isNull() const { return Data.isNull(); }
-  
-  void setOnlyValue(NamedDecl *ND) {
-    assert(isInline() && "Not inline");
-    Data = ND;
-  }
-
-  /// getLookupResult - Return an array of all the decls that this list
-  /// represents.
-  DeclContext::lookup_result getLookupResult() {
-    // If we have a single inline unit, return it.
-    if (isInline()) {
-      assert(!isNull() && "Empty list isn't allowed");
-      
-      // Data is a raw pointer to a NamedDecl*, return it.
-      void *Ptr = &Data;
-      return DeclContext::lookup_result((NamedDecl**)Ptr, (NamedDecl**)Ptr+1);
-    }
-    
-    // Otherwise, we have a range result.
-    VectorTy &V = *Data.get<VectorTy*>();
-    return DeclContext::lookup_result(&V[0], &V[0]+V.size());
-  }
-  
-  /// HandleRedeclaration - If this is a redeclaration of an existing decl,
-  /// replace the old one with D and return true.  Otherwise return false.
-  bool HandleRedeclaration(NamedDecl *D) {
-    // Most decls only have one entry in their list, special case it.
-    if (isInline()) {
-      if (!D->declarationReplaces(Data.get<NamedDecl*>()))
-        return false;
-      setOnlyValue(D);
-      return true;
-    }
-    
-    // Determine if this declaration is actually a redeclaration.
-    VectorTy &Vec = *Data.get<VectorTy*>();
-    VectorTy::iterator RDI
-      = std::find_if(Vec.begin(), Vec.end(),
-                     std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
-                                  D));
-    if (RDI == Vec.end())
-      return false;
-    *RDI = D;
-    return true;
-  }
-  
-  /// AddSubsequentDecl - This is called on the second and later decl when it is
-  /// not a redeclaration to merge it into the appropriate place in our list.
-  /// 
-  void AddSubsequentDecl(NamedDecl *D) {
-    // If this is the second decl added to the list, convert this to vector
-    // form.
-    if (isInline()) {
-      NamedDecl *OldD = Data.get<NamedDecl*>();
-      VectorTy *VT = new VectorTy();
-      VT->push_back(OldD);
-      Data = VT;
-    }
-    
-    VectorTy &Vec = *Data.get<VectorTy*>();
-    if (isa<UsingDirectiveDecl>(D) ||
-        D->getIdentifierNamespace() == Decl::IDNS_Tag)
-      Vec.push_back(D);
-    else if (Vec.back()->getIdentifierNamespace() == Decl::IDNS_Tag) {
-      NamedDecl *TagD = Vec.back();
-      Vec.back() = D;
-      Vec.push_back(TagD);
-    } else
-      Vec.push_back(D);
-  }
-};
-
-
-
-typedef llvm::DenseMap<DeclarationName, StoredDeclsList> StoredDeclsMap;
-
 DeclContext::~DeclContext() {
   if (isLookupMap())
     delete static_cast<StoredDeclsMap*>(LookupPtr.getPointer());





More information about the cfe-commits mailing list