[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:54:57 PDT 2008


Hi,

I was trying to implement the transparent_union type attribute, but I think 
we need some additional API to handle it. I think we should add the 
attribute API as found in Decl to Type (i.e. addAttr(), getAttrs(), ...). 
This could be used to implement this attribute and all the others type 
attributes 
(http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Type-Attributes.html).
Alternatively we could just add an ad-hoc field to the RecordType struct to 
record if it's a transparent union or not, which also makes sense.

Please give me some feedback.

Thanks,
Nuno


> 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
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 25 04:32:00 2008
> @@ -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());
> +}
> + 




More information about the cfe-commits mailing list