[cfe-commits] r39299 - in /cfe/cfe/trunk: AST/Decl.cpp AST/SemaDecl.cpp Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/Basic/DiagnosticKinds.def

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:42:41 PDT 2007


Author: sabre
Date: Wed Jul 11 11:42:41 2007
New Revision: 39299

URL: http://llvm.org/viewvc/llvm-project?rev=39299&view=rev
Log:
Add EnumDecl, warn about forward references to enums:

t.c:2:6: warning: ISO C forbids forward references to 'enum' types
enum foo22* X;
     ^

Modified:
    cfe/cfe/trunk/AST/Decl.cpp
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/include/clang/AST/Decl.h
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

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

==============================================================================
--- cfe/cfe/trunk/AST/Decl.cpp (original)
+++ cfe/cfe/trunk/AST/Decl.cpp Wed Jul 11 11:42:41 2007
@@ -50,12 +50,12 @@
 /// defineBody - When created, RecordDecl's correspond to a forward declared
 /// record.  This method is used to mark the decl as being defined, with the
 /// specified contents.
-void RecordDecl::defineBody(Decl **fields, unsigned numFields) {
+void RecordDecl::defineBody(Decl **members, unsigned numMembers) {
   assert(!isDefinition() && "Cannot redefine record!");
   setDefinition(true);
-  NumFields = numFields;
-  if (numFields) {
-    Fields = new Decl*[numFields];
-    memcpy(Fields, fields, numFields*sizeof(Decl*));
+  NumMembers = numMembers;
+  if (numMembers) {
+    Members = new Decl*[numMembers];
+    memcpy(Members, members, numMembers*sizeof(Decl*));
   }
 }

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39299&r1=39298&r2=39299&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:41 2007
@@ -334,7 +334,12 @@
   TagDecl *New;
   switch (Kind) {
   default: assert(0 && "Unknown tag kind!");
-  case Decl::Enum: assert(0 && "Enum tags not implemented yet!");
+  case Decl::Enum:
+    New = new EnumDecl(Loc, Name);
+    // If this is an undefined enum, warn.
+    if (TK != TK_Definition)
+      Diag(Loc, diag::ext_forward_ref_enum);
+    break;
   case Decl::Union:
   case Decl::Struct:
   case Decl::Class:
@@ -342,9 +347,6 @@
     break;
   }    
   
-  //if (TK == TK_Definition)
-  //  New->setDefinition(true);
-  
   // If this has an identifier, add it to the scope stack.
   if (Name) {
     New->setNext(Name->getFETokenInfo<Decl>());

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:41 2007
@@ -334,7 +334,12 @@
   TagDecl *New;
   switch (Kind) {
   default: assert(0 && "Unknown tag kind!");
-  case Decl::Enum: assert(0 && "Enum tags not implemented yet!");
+  case Decl::Enum:
+    New = new EnumDecl(Loc, Name);
+    // If this is an undefined enum, warn.
+    if (TK != TK_Definition)
+      Diag(Loc, diag::ext_forward_ref_enum);
+    break;
   case Decl::Union:
   case Decl::Struct:
   case Decl::Class:
@@ -342,9 +347,6 @@
     break;
   }    
   
-  //if (TK == TK_Definition)
-  //  New->setDefinition(true);
-  
   // If this has an identifier, add it to the scope stack.
   if (Name) {
     New->setNext(Name->getFETokenInfo<Decl>());

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:42:41 2007
@@ -237,6 +237,30 @@
   void setDefinition(bool V) { IsDefinition = V; }
 };
 
+/// EnumDecl - Represents an enum.  As an extension, we allow forward-declared
+/// enums.
+class EnumDecl : public TagDecl {
+  /// Fields/NumFields - This is a new[]'d array of pointers to Decls.
+  //Decl **Fields;   // Null if not defined.
+  //int NumFields;   // -1 if not defined.
+public:
+  EnumDecl(SourceLocation L, IdentifierInfo *Id) : TagDecl(Enum, L, Id) {
+    //Fields = 0;
+    //NumFields = -1;
+  }
+  
+  /// defineBody - When created, RecordDecl's correspond to a forward declared
+  /// record.  This method is used to mark the decl as being defined, with the
+  /// specified contents.
+  //void defineBody(Decl **fields, unsigned numFields);
+  
+  static bool classof(const Decl *D) {
+    return D->getKind() == Enum;
+  }
+  static bool classof(const EnumDecl *D) { return true; }
+};
+
+
 /// RecordDecl - Represents a struct/union/class.
 class RecordDecl : public TagDecl {
   /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
@@ -244,15 +268,15 @@
   /// If so, this cannot be contained in arrays or other structs as a member.
   bool HasFlexibleArrayMember : 1;
 
-  /// Fields/NumFields - This is a new[]'d array of pointers to FieldDecls.
-  Decl **Fields;   // Null if not defined.
-  int NumFields;   // -1 if not defined.
+  /// Members/NumMembers - This is a new[]'d array of pointers to Decls.
+  Decl **Members;   // Null if not defined.
+  int NumMembers;   // -1 if not defined.
 public:
   RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id) :TagDecl(DK, L, Id){
     HasFlexibleArrayMember = false;
     assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
-    Fields = 0;
-    NumFields = -1;
+    Members = 0;
+    NumMembers = -1;
   }
   
   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
@@ -261,7 +285,7 @@
   /// defineBody - When created, RecordDecl's correspond to a forward declared
   /// record.  This method is used to mark the decl as being defined, with the
   /// specified contents.
-  void defineBody(Decl **fields, unsigned numFields);
+  void defineBody(Decl **Members, unsigned numMembers);
   
   static bool classof(const Decl *D) {
     return D->getKind() == Struct || D->getKind() == Union ||

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39299&r1=39298&r2=39299&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:42:41 2007
@@ -431,6 +431,8 @@
      "nested redefinition of '%s'")
 DIAG(err_use_with_wrong_tag, ERROR,
      "use of '%s' with tag type that does not match previous declaration")
+DIAG(ext_forward_ref_enum, EXTENSION,
+     "ISO C forbids forward references to 'enum' types")
 
 DIAG(warn_implicit_function_decl, WARNING,
      "implicit declaration of function '%s'")





More information about the cfe-commits mailing list