[cfe-commits] r50262 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Parse/AttributeList.h lib/Parse/AttributeList.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp

Nuno Lopes nunoplopes at sapo.pt
Fri Apr 25 02:32:01 PDT 2008


Author: nlopes
Date: Fri Apr 25 04:32:00 2008
New Revision: 50262

URL: http://llvm.org/viewvc/llvm-project?rev=50262&view=rev
Log:
initial support for recognizing __transparent_union__ attributes
comments on the ML will follow

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Parse/AttributeList.h
    cfe/trunk/lib/Parse/AttributeList.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Apr 25 04:32:00 2008
@@ -36,7 +36,8 @@
     Format,
     Visibility,
     FastCall,
-    StdCall
+    StdCall,
+    TransparentUnion
   };
     
 private:
@@ -218,6 +219,16 @@
   static bool classof(const StdCallAttr *A) { return true; }
 };
 
+class TransparentUnionAttr : public Attr {
+public:
+  TransparentUnionAttr() : Attr(TransparentUnion) {}
+
+  // Implement isa/cast/dyncast/etc.
+
+  static bool classof(const Attr *A) { return A->getKind() == TransparentUnion; }
+  static bool classof(const TransparentUnionAttr *A) { return true; }
+};
+
 }  // end namespace clang
 
 #endif

Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=50262&r1=50261&r2=50262&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Fri Apr 25 04:32:00 2008
@@ -64,6 +64,7 @@
     AT_stdcall,
     AT_nothrow,
     AT_noinline,
+    AT_transparent_union,
     AT_warn_unused_result
   };
   

Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=50262&r1=50261&r2=50262&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Fri Apr 25 04:32:00 2008
@@ -90,6 +90,9 @@
   case 15:
     if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
     break;
+  case 17:
+    if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
+    break;
   case 18:
     if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
     break;

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=50262&r1=50261&r2=50262&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Apr 25 04:32:00 2008
@@ -323,6 +323,7 @@
   void HandleFormatAttribute(Decl *d, AttributeList *rawAttr);
   void HandleStdCallAttribute(Decl *d, AttributeList *rawAttr);
   void HandleFastCallAttribute(Decl *d, AttributeList *rawAttr);
+  void HandleTransparentUnionAttribute(Decl *d, AttributeList *rawAttr);
   
   void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
                            bool &IncompleteImpl);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 25 04:32:00 2008
@@ -2003,6 +2003,9 @@
   case AttributeList::AT_format:
     HandleFormatAttribute(New, Attr);
     break;
+  case AttributeList::AT_transparent_union:
+    HandleTransparentUnionAttribute(New, Attr);
+    break;
   default:
 #if 0
     // TODO: when we have the full set of attributes, warn about unknown ones.
@@ -2419,6 +2422,29 @@
                             Idx.getZExtValue(), FirstArg.getZExtValue()));
 }
 
+void Sema::HandleTransparentUnionAttribute(Decl *d, AttributeList *rawAttr) {
+  // check the attribute arguments.
+  if (rawAttr->getNumArgs() != 0) {
+    Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
+         std::string("0"));
+    return;
+  }
+
+  TypeDecl *decl = dyn_cast<TypeDecl>(d);
+
+  if (!decl || !Context.getTypeDeclType(decl)->isUnionType()) {
+    Diag(rawAttr->getLoc(), diag::warn_attribute_wrong_decl_type,
+         "transparent_union", "union");
+    return;
+  }
+
+  QualType QTy = Context.getTypeDeclType(decl);
+  const RecordType *Ty = QTy->getAsUnionType();
+
+// FIXME
+// Ty->addAttr(new TransparentUnionAttr());
+}
+
 void Sema::HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr) {
   // check the attribute arguments.
   if (rawAttr->getNumArgs() != 1) {





More information about the cfe-commits mailing list