[cfe-dev] Add attributes to Types (as found in Decl)

Nuno Lopes nunoplopes at sapo.pt
Fri Apr 25 12:04:42 PDT 2008


(Forwarding to cfe-dev, per Ted's advice)

----- Original Message -----
> 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());
>> +}
>> +
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits 




More information about the cfe-dev mailing list