[cfe-commits] r67864 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp

Chris Lattner sabre at nondot.org
Fri Mar 27 13:18:24 PDT 2009


Author: lattner
Date: Fri Mar 27 15:18:19 2009
New Revision: 67864

URL: http://llvm.org/viewvc/llvm-project?rev=67864&view=rev
Log:
minor cleanups: make getIdentifierNamespace() be a single load
instead of a load + large inlined switch.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Fri Mar 27 15:18:19 2009
@@ -144,6 +144,9 @@
   /// the implementation rather than explicitly written by the user.
   bool Implicit : 1;
 
+  /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
+  unsigned IdentifierNamespace : 5;
+  
 #ifndef NDEBUG
   void CheckAccessDeclContext() const;
 #else
@@ -160,7 +163,8 @@
     : NextDeclarator(0), NextDeclInScope(0), 
       DeclCtx(DC, 0), 
       Loc(L), DeclKind(DK), InvalidDecl(0),
-      HasAttrs(false), Implicit(false), Access(AS_none) {
+      HasAttrs(false), Implicit(false), 
+      IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) {
     if (Decl::CollectingStats()) addDeclKind(DK);
   }
 
@@ -224,57 +228,13 @@
   void setImplicit(bool I = true) { Implicit = I; }
   
   unsigned getIdentifierNamespace() const {
-    switch (DeclKind) {
-    default: 
-      if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast)
-        return IDNS_Ordinary;
-      assert(0 && "Unknown decl kind!");
-    case OverloadedFunction:
-    case Typedef:
-    case EnumConstant:
-    case Var:
-    case ImplicitParam:
-    case ParmVar:
-    case OriginalParmVar:
-    case NonTypeTemplateParm:
-    case ObjCMethod:
-    case ObjCContainer:
-    case ObjCCategory:
-    case ObjCInterface:
-    case ObjCCategoryImpl:
-    case ObjCProperty:
-    case ObjCCompatibleAlias:
-      return IDNS_Ordinary;
-
-    case ObjCProtocol:
-      return IDNS_Protocol;
-
-    case Field:
-    case ObjCAtDefsField:
-    case ObjCIvar:
-      return IDNS_Member;
-
-    case Record:
-    case CXXRecord:
-    case Enum:
-    case TemplateTypeParm:
-      return IDNS_Tag;
-
-    case Namespace:
-    case Template:
-    case FunctionTemplate:
-    case ClassTemplate:
-    case TemplateTemplateParm:
-      return IDNS_Tag | IDNS_Ordinary;
-
-    case ClassTemplateSpecialization:
-      return 0;
-    }
+    return IdentifierNamespace;
   }
-  
   bool isInIdentifierNamespace(unsigned NS) const {
     return getIdentifierNamespace() & NS;
   }
+  static unsigned getIdentifierNamespaceForKind(Kind DK);
+
   
   /// getLexicalDeclContext - The declaration context where this Decl was
   /// lexically declared (LexicalDC). May be different from
@@ -398,8 +358,7 @@
   /// in the 3 lowest-order bits and the upper bits are treated as a
   /// pointer to an array of NamedDecl pointers. If the context
   /// contains seven or more declarations, the upper bits are treated
-  /// as a pointer to a DenseMap<DeclarationName, std::vector<NamedDecl*>>.
-  /// FIXME: We need a better data structure for this.
+  /// as a pointer to a DenseMap<DeclarationName, StoredDeclsList>.
   llvm::PointerIntPair<void*, 3> LookupPtr;
 
   /// FirstDecl - The first declaration stored within this declaration

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

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Fri Mar 27 15:18:19 2009
@@ -117,6 +117,14 @@
 // Decl Implementation
 //===----------------------------------------------------------------------===//
 
+// Out-of-line virtual method providing a home for Decl.
+Decl::~Decl() {
+  if (isOutOfSemaDC())
+    delete getMultipleDC();
+  
+  assert(!HasAttrs && "attributes should have been freed by Destroy");
+}
+
 void Decl::setDeclContext(DeclContext *DC) {
   if (isOutOfSemaDC())
     delete getMultipleDC();
@@ -140,12 +148,66 @@
   }
 }
 
-// Out-of-line virtual method providing a home for Decl.
-Decl::~Decl() {
-  if (isOutOfSemaDC())
-    delete getMultipleDC();
-
-  assert(!HasAttrs && "attributes should have been freed by Destroy");
+unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
+  switch (DeclKind) {
+    default: 
+      if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast)
+        return IDNS_Ordinary;
+      assert(0 && "Unknown decl kind!");
+    case OverloadedFunction:
+    case Typedef:
+    case EnumConstant:
+    case Var:
+    case ImplicitParam:
+    case ParmVar:
+    case OriginalParmVar:
+    case NonTypeTemplateParm:
+    case ObjCMethod:
+    case ObjCContainer:
+    case ObjCCategory:
+    case ObjCInterface:
+    case ObjCCategoryImpl:
+    case ObjCProperty:
+    case ObjCCompatibleAlias:
+      return IDNS_Ordinary;
+      
+    case ObjCProtocol:
+      return IDNS_Protocol;
+      
+    case Field:
+    case ObjCAtDefsField:
+    case ObjCIvar:
+      return IDNS_Member;
+      
+    case Record:
+    case CXXRecord:
+    case Enum:
+    case TemplateTypeParm:
+      return IDNS_Tag;
+      
+    case Namespace:
+    case Template:
+    case FunctionTemplate:
+    case ClassTemplate:
+    case TemplateTemplateParm:
+      return IDNS_Tag | IDNS_Ordinary;
+    
+    // Never have names.
+    case LinkageSpec:
+    case FileScopeAsm:
+    case StaticAssert:
+    case ObjCClass:
+    case ObjCImplementation:
+    case ObjCPropertyImpl:
+    case ObjCForwardProtocol:
+    case Block:
+    case TranslationUnit:
+
+    // Aren't looked up?
+    case UsingDirective:
+    case ClassTemplateSpecialization:
+      return 0;
+  }
 }
 
 void Decl::addAttr(Attr *NewAttr) {
@@ -426,8 +488,7 @@
 typedef llvm::DenseMap<DeclarationName, StoredDeclsList> StoredDeclsMap;
 
 DeclContext::~DeclContext() {
-  unsigned Size = LookupPtr.getInt();
-  if (Size == LookupIsMap)
+  if (isLookupMap())
     delete static_cast<StoredDeclsMap*>(LookupPtr.getPointer());
   else
     delete [] static_cast<NamedDecl**>(LookupPtr.getPointer());





More information about the cfe-commits mailing list