]> granicus.if.org Git - clang/commitdiff
Rename FileVariable -> FileVar for consistency with its class name,
authorChris Lattner <sabre@nondot.org>
Mon, 8 Oct 2007 21:37:32 +0000 (21:37 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Oct 2007 21:37:32 +0000 (21:37 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42772 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e629e9c26e351f2b1d3fb32e0b57a177d3577229..20117795254b7a1977f0a08be07ed4d18908f69e 100644 (file)
@@ -45,12 +45,12 @@ const char *Decl::getDeclKindName() const {
     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 @@ void Decl::addDeclKind(const Kind k) {
     case Function:
       nFuncs++;
       break;
-    case BlockVariable:
+    case BlockVar:
       nBlockVars++;
       break;
-    case FileVariable:
+    case FileVar:
       nFileVars++;
       break;
-    case ParmVariable:
+    case ParmVar:
       nParmVars++;
       break;
     case EnumConstant:
index 6476074e97c7c018c9047ac952287f91b3c88a3e..410890c2a303c47dcfdc294f108b01c3acae2b61 100644 (file)
@@ -260,9 +260,9 @@ void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
   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;
index 031216ebebd53b0416db3c9894eee8475463e8fa..2af41272310e462edbcb1abf870cc1c6702202dd 100644 (file)
@@ -21,9 +21,9 @@ using namespace CodeGen;
 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 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
     // 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));
index e31c1e1c604544fb3b032673e28007f16350acdd..599f23b520b7ceff75f6df8c2aa2e2cdea2afab3 100644 (file)
@@ -31,14 +31,49 @@ class IdentifierInfo;
 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 @@ public:
     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 @@ public:
   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 @@ public:
   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 @@ public:
   
   // 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 @@ public:
   //  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 @@ public:
   //  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 @@ class BlockVarDecl : public VarDecl {
 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 @@ class FileVarDecl : public VarDecl {
 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 @@ class ParmVarDecl : public VarDecl {
 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 @@ public:
   
   // 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 @@ public:
   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 @@ protected:
 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 @@ public:
   
   // 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 @@ public:
   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 @@ public:
   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; }
 };
index b6f83322044fdafe2bc811f3aef13b26441a2293..21c91bbf9b184de309c2479471e7b9ccca8f8bd1 100644 (file)
@@ -138,9 +138,7 @@ public:
   /// 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 @@ public:
                            { 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 @@ public:
   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 @@ public:
     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 @@ public:
     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 @@ class ObjcCategoryImplDecl : public NamedDecl {
         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; }
 };
 
index b5858ebbb4a0cb54d4bc16c225496afcd10da2ca..0d97d6927f1dce3736dd55e536e5f4aa7576e9f6 100644 (file)
@@ -54,9 +54,9 @@ public:
   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?