[cfe-commits] r42772 - in /cfe/trunk: AST/Decl.cpp AST/StmtDumper.cpp CodeGen/CGDecl.cpp include/clang/AST/Decl.h include/clang/AST/DeclObjC.h include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h

Chris Lattner sabre at nondot.org
Mon Oct 8 14:37:32 PDT 2007


Author: lattner
Date: Mon Oct  8 16:37:32 2007
New Revision: 42772

URL: http://llvm.org/viewvc/llvm-project?rev=42772&view=rev
Log:
Rename FileVariable -> FileVar for consistency with its class name, 
likewise block and param.  Reorder the layout of the Decl kind enum
so that the inheritance tree is reflected in the ordering.  This allows
trivial range comparisons to determine whether something is an instance
of some abstract class, making classof faster.


Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/AST/StmtDumper.cpp
    cfe/trunk/CodeGen/CGDecl.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=42772&r1=42771&r2=42772&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Mon Oct  8 16:37:32 2007
@@ -45,12 +45,12 @@
     return "Typedef";
   case Function:
     return "Function";
-  case BlockVariable:
-    return "BlockVariable";
-  case FileVariable:
-    return "FileVariable";
-  case ParmVariable:
-    return "ParmVariable";
+  case BlockVar:
+    return "BlockVar";
+  case FileVar:
+    return "FileVar";
+  case ParmVar:
+    return "ParmVar";
   case EnumConstant:
     return "EnumConstant";
   case ObjcInterface:
@@ -157,13 +157,13 @@
     case Function:
       nFuncs++;
       break;
-    case BlockVariable:
+    case BlockVar:
       nBlockVars++;
       break;
-    case FileVariable:
+    case FileVar:
       nFileVars++;
       break;
-    case ParmVariable:
+    case ParmVar:
       nParmVars++;
       break;
     case EnumConstant:

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=42772&r1=42771&r2=42772&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Mon Oct  8 16:37:32 2007
@@ -260,9 +260,9 @@
   fprintf(F, " ");
   switch (Node->getDecl()->getKind()) {
     case Decl::Function: fprintf(F,"FunctionDecl"); break;
-    case Decl::BlockVariable: fprintf(F,"BlockVariable"); break;
-    case Decl::FileVariable: fprintf(F,"FileVariable"); break;
-    case Decl::ParmVariable: fprintf(F,"ParmVariable"); break;
+    case Decl::BlockVar: fprintf(F,"BlockVar"); break;
+    case Decl::FileVar: fprintf(F,"FileVar"); break;
+    case Decl::ParmVar: fprintf(F,"ParmVar"); break;
     case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
     case Decl::Typedef: fprintf(F,"Typedef"); break;
     case Decl::Struct: fprintf(F,"Struct"); break;

Modified: cfe/trunk/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGDecl.cpp?rev=42772&r1=42771&r2=42772&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/CodeGen/CGDecl.cpp Mon Oct  8 16:37:32 2007
@@ -21,9 +21,9 @@
 void CodeGenFunction::EmitDecl(const Decl &D) {
   switch (D.getKind()) {
   default: assert(0 && "Unknown decl kind!");
-  case Decl::FileVariable:
+  case Decl::FileVar:
     assert(0 && "Should not see file-scope variables inside a function!");
-  case Decl::ParmVariable:
+  case Decl::ParmVar:
     assert(0 && "Parmdecls should not be in declstmts!");
   case Decl::Typedef:   // typedef int X;
   case Decl::Function:  // void X();
@@ -34,7 +34,7 @@
     // None of these decls require codegen support.
     return;
     
-  case Decl::BlockVariable:
+  case Decl::BlockVar:
     return EmitBlockVarDecl(cast<BlockVarDecl>(D));
   case Decl::EnumConstant:
     return EmitEnumConstantDecl(cast<EnumConstantDecl>(D));

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Oct  8 16:37:32 2007
@@ -31,14 +31,49 @@
 class Decl {
 public:
   enum Kind {
-    // Concrete sub-classes of ValueDecl
-    Function, BlockVariable, FileVariable, ParmVariable, EnumConstant,
-    // Concrete sub-classes of TypeDecl
-    Typedef, Struct, Union, Class, Enum, ObjcInterface, ObjcClass, ObjcMethod,
-    ObjcProtocol, ObjcForwardProtocol, ObjcCategory, ObjcCategoryImpl,
-    ObjcImplementation,
-    // Concrete sub-class of Decl
-    Field, ObjcIvar
+    // This lists the concrete classes of Decl in order of the inheritance
+    // hierarchy.  This allows us to do efficient classof tests based on the
+    // enums below.   The commented out names are abstract class names.
+    
+    // Decl
+    //   NamedDecl
+           Field,
+             ObjcIvar,
+           ObjcCategory,
+           ObjcCategoryImpl,
+           ObjcImplementation,
+    //     ScopedDecl
+             ObjcProtocol,
+    //       TypeDecl
+               ObjcInterface,
+               Typedef,
+    //         TagDecl
+                 Enum,
+    //           RecordDecl,
+                   Struct,
+                   Union,
+                   Class,
+    //       ValueDecl
+               EnumConstant,
+               Function,
+    //         VarDecl
+                 BlockVar,
+                 FileVar,
+                 ParmVar,
+         ObjcMethod,
+         ObjcClass,
+         ObjcForwardProtocol,
+  
+    // For each non-leaf class, we now define a mapping to the first/last member
+    // of the class, to allow efficient classof.
+    NamedFirst  = Field,         NamedLast  = ParmVar,
+    FieldFirst  = Field,         FieldLast  = ObjcIvar,
+    ScopedFirst = ObjcProtocol,  ScopedLast = ParmVar,
+    TypeFirst   = ObjcInterface, TypeLast   = Class,
+    TagFirst    = Enum         , TagLast    = Class,
+    RecordFirst = Struct       , RecordLast = Class,
+    ValueFirst  = EnumConstant , ValueLast  = ParmVar,
+    VarFirst    = BlockVar     , VarLast    = ParmVar
   };
 
   /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
@@ -87,9 +122,9 @@
     default: assert(0 && "Unknown decl kind!");
     case Typedef:
     case Function:
-    case BlockVariable:
-    case FileVariable:
-    case ParmVariable:
+    case BlockVar:
+    case FileVar:
+    case ParmVar:
     case EnumConstant:
     case ObjcInterface:
       return IDNS_Ordinary;
@@ -125,7 +160,9 @@
   const char *getName() const;
   
   
-  // FIXME: classof when the hierarchy is sorted out.
+  static bool classof(const Decl *D) {
+    return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
+  }
   static bool classof(const NamedDecl *D) { return true; }
 };
 
@@ -156,11 +193,9 @@
   const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
   void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
   
-  // Implement isa/cast/dyncast/etc - true for all ValueDecl's and TypeDecl's.
+  // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return (D->getKind() >= Function && D->getKind() <= EnumConstant) || 
-           (D->getKind() >= Typedef && D->getKind() <= Enum) ||
-           D->getKind() == ObjcProtocol || D->getKind() == ObjcInterface;
+    return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
   }
   static bool classof(const ScopedDecl *D) { return true; }
 };
@@ -180,7 +215,7 @@
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() >= Function && D->getKind() <= EnumConstant;
+    return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
   }
   static bool classof(const ValueDecl *D) { return true; }
 };
@@ -203,8 +238,8 @@
   //  declared within a function that lack a storage keyword are
   //  implicitly "auto", but are represented internally with a storage
   //  class of None.
-  bool hasAutoStorage() {
-    return (SClass == Auto || (SClass == None && getKind() != FileVariable));
+  bool hasAutoStorage() const {
+    return SClass == Auto || (SClass == None && getKind() != FileVar);
   }
 
   // hasStaticStorage - Returns true if either the implicit or
@@ -212,22 +247,22 @@
   //  particular, variables declared within a file (outside of a
   //  function) that lack a storage keyword are implicitly "static,"
   //  but are represented internally with a storage class of "None".
-  bool hasStaticStorage() {
-    return (SClass == Static || (SClass == None && getKind() == FileVariable));
+  bool hasStaticStorage() const {
+    return SClass == Static || (SClass == None && getKind() == FileVar);
   }
       
   // hasLocalStorage - Returns true if a variable with function scope
   //  is a non-static local variable.
-  bool hasLocalStorage() { return (hasAutoStorage() || SClass == Register); }
+  bool hasLocalStorage() const { return hasAutoStorage() || SClass == Register;}
 
   // hasGlobalStorage - Returns true for all variables that do not
   //  have local storage.  This includs all global variables as well
   //  as static variables declared within a function.
-  bool hasGlobalStorage() { return !hasAutoStorage(); }
+  bool hasGlobalStorage() const { return !hasAutoStorage(); }
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { 
-    return D->getKind() >= BlockVariable && D->getKind() <= ParmVariable; 
+  static bool classof(const Decl *D) {
+    return D->getKind() >= VarFirst && D->getKind() <= VarLast;
   }
   static bool classof(const VarDecl *D) { return true; }
 protected:
@@ -244,10 +279,10 @@
 public:
   BlockVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
                ScopedDecl *PrevDecl)
-    : VarDecl(BlockVariable, L, Id, T, S, PrevDecl) {}
+    : VarDecl(BlockVar, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == BlockVariable; }
+  static bool classof(const Decl *D) { return D->getKind() == BlockVar; }
   static bool classof(const BlockVarDecl *D) { return true; }
 };
 
@@ -259,10 +294,10 @@
 public:
   FileVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
               ScopedDecl *PrevDecl)
-    : VarDecl(FileVariable, L, Id, T, S, PrevDecl) {}
+    : VarDecl(FileVar, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == FileVariable; }
+  static bool classof(const Decl *D) { return D->getKind() == FileVar; }
   static bool classof(const FileVarDecl *D) { return true; }
 };
 
@@ -271,10 +306,10 @@
 public:
   ParmVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
               ScopedDecl *PrevDecl)
-    : VarDecl(ParmVariable, L, Id, T, S, PrevDecl) {}
+    : VarDecl(ParmVar, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == ParmVariable; }
+  static bool classof(const Decl *D) { return D->getKind() == ParmVar; }
   static bool classof(const ParmVarDecl *D) { return true; }
 };
 
@@ -355,7 +390,7 @@
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() == Field || D->getKind() == ObjcIvar;
+    return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
   }
   static bool classof(const FieldDecl *D) { return true; }
 };
@@ -380,9 +415,7 @@
   void setInitVal(llvm::APSInt &V) { Val = V; }
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == EnumConstant;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
   static bool classof(const EnumConstantDecl *D) { return true; }
 };
 
@@ -401,7 +434,7 @@
 public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() >= Typedef && D->getKind() <= Enum;
+    return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
   }
   static bool classof(const TypeDecl *D) { return true; }
 };
@@ -452,8 +485,7 @@
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() == Struct || D->getKind() == Union ||
-           D->getKind() == Class || D->getKind() == Enum;
+    return D->getKind() >= TagFirst && D->getKind() <= TagLast;
   }
   static bool classof(const TagDecl *D) { return true; }
 protected:
@@ -497,9 +529,7 @@
   EnumConstantDecl *getEnumConstantList() { return ElementList; }
   const EnumConstantDecl *getEnumConstantList() const { return ElementList; }
   
-  static bool classof(const Decl *D) {
-    return D->getKind() == Enum;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == Enum; }
   static bool classof(const EnumDecl *D) { return true; }
 };
 
@@ -545,8 +575,7 @@
   FieldDecl *getMember(IdentifierInfo *name);
 
   static bool classof(const Decl *D) {
-    return D->getKind() == Struct || D->getKind() == Union ||
-           D->getKind() == Class;
+    return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
   }
   static bool classof(const RecordDecl *D) { return true; }
 };

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Oct  8 16:37:32 2007
@@ -138,9 +138,7 @@
   /// declaration without an @interface declaration.
   bool ImplicitInterfaceDecl() const { return getLocation().isInvalid(); }
   
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjcInterface;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcInterface; }
   static bool classof(const ObjcInterfaceDecl *D) { return true; }
 };
 
@@ -257,9 +255,7 @@
                            { return DeclImplementation; }
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { 
-    return D->getKind() == ObjcMethod; 
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcMethod; }
   static bool classof(const ObjcMethodDecl *D) { return true; }
 };
 
@@ -337,9 +333,7 @@
   bool isForwardDecl() const { return isForwardProtoDecl; }
   void setForwardDecl(bool val) { isForwardProtoDecl = val; }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjcProtocol;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcProtocol; }
   static bool classof(const ObjcProtocolDecl *D) { return true; }
 };
   
@@ -365,9 +359,7 @@
     assert(idx < NumForwardDecls && "index out of range");
     ForwardDecls[idx] = OID;
   }
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjcClass;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcClass; }
   static bool classof(const ObjcClassDecl *D) { return true; }
 };
 
@@ -492,9 +484,7 @@
     ClassInterface->setListCategories(this);
   }
   
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjcCategory;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcCategory; }
   static bool classof(const ObjcCategoryDecl *D) { return true; }
 };
 
@@ -534,9 +524,7 @@
         ObjcMethodDecl **insMethods, unsigned numInsMembers,
         ObjcMethodDecl **clsMethods, unsigned numClsMembers);
   
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjcCategoryImpl;
-  }
+  static bool classof(const Decl *D) { return D->getKind() == ObjcCategoryImpl;}
   static bool classof(const ObjcCategoryImplDecl *D) { return true; }
 };
 

Modified: cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h?rev=42772&r1=42771&r2=42772&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h Mon Oct  8 16:37:32 2007
@@ -54,9 +54,9 @@
   void VisitScopedDecl(ScopedDecl* D) {
     switch (D->getKind()) {
         DISPATCH_CASE(Function,FunctionDecl)
-        DISPATCH_CASE(BlockVariable,BlockVarDecl) // FIXME:Refine. VisitVarDecl?
-        DISPATCH_CASE(FileVariable,FileVarDecl)   // FIXME: (same)
-        DISPATCH_CASE(ParmVariable,ParmVarDecl)       // FIXME: (same)
+        DISPATCH_CASE(BlockVar,BlockVarDecl) // FIXME:Refine. VisitVarDecl?
+        DISPATCH_CASE(FileVar,FileVarDecl)   // FIXME: (same)
+        DISPATCH_CASE(ParmVar,ParmVarDecl)       // FIXME: (same)
         DISPATCH_CASE(EnumConstant,EnumConstantDecl)
         DISPATCH_CASE(Typedef,TypedefDecl)
         DISPATCH_CASE(Struct,RecordDecl)    // FIXME: Refine.  VisitStructDecl?





More information about the cfe-commits mailing list