[cfe-commits] r41548 - in /cfe/trunk: AST/ASTContext.cpp CodeGen/CodeGenTypes.cpp Sema/SemaDecl.cpp include/clang/AST/ASTContext.h include/clang/AST/Decl.h include/clang/Basic/TargetInfo.h

Chris Lattner sabre at nondot.org
Tue Aug 28 11:24:31 PDT 2007


Author: lattner
Date: Tue Aug 28 13:24:31 2007
New Revision: 41548

URL: http://llvm.org/viewvc/llvm-project?rev=41548&view=rev
Log:
Change EnumDecl to store its corresponding integer type 
directly in it.  Remove TargetInfo::getEnumPolicy, as there is only
one policy that we support right now.

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/CodeGen/CodeGenTypes.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Basic/TargetInfo.h

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

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Aug 28 13:24:31 2007
@@ -233,7 +233,7 @@
       Size = Layout.getSize();
       Align = Layout.getAlignment();
     } else if (EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) {
-      return getTypeInfo(getEnumDeclIntegerType(ED), L);
+      return getTypeInfo(ED->getIntegerType(), L);
     } else {
       assert(0 && "Unimplemented type sizes!");
     }
@@ -312,23 +312,6 @@
   return *NewEntry;
 }
 
-/// getEnumDeclIntegerType - returns the integer type compatible with the
-/// given enum type.
-QualType ASTContext::getEnumDeclIntegerType(const EnumDecl *ED) const {
-  if (const EnumConstantDecl *C = ED->getEnumConstantList())
-    return C->getType();
-
-  // If the enum list is empty, it is typed as if it contained a single zero 
-  // element [C++ dcl.enum] and is illegal in C (as an extension, we treat it 
-  // the same as C++ does).
-  switch (Target.getEnumTypePolicy(ED->getLocation())) {
-  default: assert(0 && "Unknown enum layout policy");
-  case TargetInfo::AlwaysInt:    return UnsignedIntTy;   // 0 -> unsigned
-  case TargetInfo::ShortestType: return UnsignedCharTy;  // 0 -> unsigned char
-  }
-}
-
-
 //===----------------------------------------------------------------------===//
 //                   Type creation/memoization methods
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=41548&r1=41547&r2=41548&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Tue Aug 28 13:24:31 2007
@@ -146,7 +146,7 @@
     if (!TD->isDefinition()) {
       ResultType = llvm::OpaqueType::get();  
     } else if (TD->getKind() == Decl::Enum) {
-      return ConvertType(Context.getEnumDeclIntegerType(cast<EnumDecl>(TD)));
+      return ConvertType(cast<EnumDecl>(TD)->getIntegerType());
     } else if (TD->getKind() == Decl::Struct) {
       const RecordDecl *RD = cast<const RecordDecl>(TD);
       std::vector<const llvm::Type*> Fields;

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41548&r1=41547&r2=41548&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Aug 28 13:24:31 2007
@@ -1069,7 +1069,7 @@
   
   // FIXME: Install type in Enum and constant values.
   
-  Enum->defineElements(EltList);
+  Enum->defineElements(EltList, BestType);
 }
 
 void Sema::AddTopLevelDecl(Decl *current, Decl *last) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Aug 28 13:24:31 2007
@@ -147,10 +147,6 @@
   /// position information.
   const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L);
   
-  /// getEnumDeclIntegerType - returns the integer type compatible with the
-  /// given enum type.
-  QualType getEnumDeclIntegerType(const EnumDecl *ED) const;
-  
   //===--------------------------------------------------------------------===//
   //                            Type Operators
   //===--------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Aug 28 13:24:31 2007
@@ -412,6 +412,11 @@
   /// ElementList - this is a linked list of EnumConstantDecl's which are linked
   /// together through their getNextDeclarator pointers.
   EnumConstantDecl *ElementList;
+  
+  /// IntegerType - This represent the integer type that the enum corresponds
+  /// to for code generation purposes.  Note that the enumerator constants may
+  /// have a different type than this does.
+  QualType IntegerType;
 public:
   EnumDecl(SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
     : TagDecl(Enum, L, Id, PrevDecl) {
@@ -421,12 +426,18 @@
   /// defineElements - When created, EnumDecl correspond to a forward declared
   /// enum.  This method is used to mark the decl as being defined, with the
   /// specified list of enums.
-  void defineElements(EnumConstantDecl *ListHead) {
+  void defineElements(EnumConstantDecl *ListHead, QualType NewType) {
     assert(!isDefinition() && "Cannot redefine enums!");
     ElementList = ListHead;
     setDefinition(true);
+    
+    IntegerType = NewType;
   }
   
+  /// getIntegerType - Return the integer type this enum decl corresponds to.
+  /// This returns a null qualtype for an enum forward definition.
+  QualType getIntegerType() const { return IntegerType; }
+  
   /// getEnumConstantList - Return the first EnumConstantDecl in the enum.
   ///
   EnumConstantDecl *getEnumConstantList() { return ElementList; }

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=41548&r1=41547&r2=41548&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Aug 28 13:24:31 2007
@@ -172,20 +172,6 @@
     Align = WCharAlign;
   }
   
-  /// EnumTypePolicy - This enum value contains a list of the various policies
-  /// that a target can have about how enums are converted to integer types.
-  enum EnumTypePolicy {
-    AlwaysInt,      // 'int' or 'unsigned'
-    ShortestType    // -fshort-enums
-  };
-  
-  /// getEnumTypePolicy - get the target's policy for what type an enum should
-  /// be compatible with.
-  EnumTypePolicy getEnumTypePolicy(SourceLocation Loc) {
-    // FIXME: implement correctly
-    return AlwaysInt;
-  }
-  
   /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
   /// target, in bits.  
   unsigned getIntMaxTWidth(SourceLocation Loc) {





More information about the cfe-commits mailing list