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

Chris Lattner clattner at apple.com
Tue Apr 29 08:08:01 PDT 2008


On Apr 25, 2008, at 12:04 PM, Nuno Lopes wrote:
>> 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.

Hi Nuno,

I think this is possible to do.  The 'problem' with this is that types  
are uniqued, so we have to think carefully about how attributes mix  
with this.  I think the only sane solution is to have some canonical  
ordering of attribute lists and have the attribute list be part of the  
type.

What do you think?

-Chris

>>
>>
>> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list