]> granicus.if.org Git - clang/commitdiff
initial support for recognizing __transparent_union__ attributes
authorNuno Lopes <nunoplopes@sapo.pt>
Fri, 25 Apr 2008 09:32:00 +0000 (09:32 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Fri, 25 Apr 2008 09:32:00 +0000 (09:32 +0000)
comments on the ML will follow

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

include/clang/AST/Attr.h
include/clang/Parse/AttributeList.h
lib/Parse/AttributeList.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp

index 72bc8a9ffaaf8f59fefd875555e554019b9f929f..abdcfb4b05040f6e3e48a31f297a35e342ec9d17 100644 (file)
@@ -36,7 +36,8 @@ public:
     Format,
     Visibility,
     FastCall,
-    StdCall
+    StdCall,
+    TransparentUnion
   };
     
 private:
@@ -218,6 +219,16 @@ public:
   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
index c71f8ff1f82280f01240ce82b80cea1e4823b005..418dc00ac9fcba5b460df558a59c9b7ddc9e5575 100644 (file)
@@ -64,6 +64,7 @@ public:
     AT_stdcall,
     AT_nothrow,
     AT_noinline,
+    AT_transparent_union,
     AT_warn_unused_result
   };
   
index c764085caadd20970213d12a3ad41248b2b150c6..2d8de97f3c0ffe015642a835c91d9ae9224a6be9 100644 (file)
@@ -90,6 +90,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
   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;
index 4b6722abc643767d165bba6afdee848ea562e919..33d3ce4ece3780a86e3ba99eff7c4d254e6b2e13 100644 (file)
@@ -323,6 +323,7 @@ private:
   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);
index c97ecc831313f1fa4f81c2ea7df056b7c357dbc2..373aaceb87fe7de0947ffe63c6d240f382ff3311 100644 (file)
@@ -2003,6 +2003,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
   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 @@ void Sema::HandleFormatAttribute(Decl *d, AttributeList *rawAttr) {
                             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) {