[cfe-dev] Enum parameters for a C++11 Attribute

LUIS MIGUEL SANCHEZ GARCIA luismiguel.sanchez at uc3m.es
Fri Dec 19 08:14:07 PST 2014


When I compile this sample:

int main()
{
    int a = 5;
    int b = 6;
    [[own::myattr(RED)]]
    auto j5 = 2*a ;
    return 0;
}

I have the following message:

$ clang++ test03.cpp  -std=c++11 -Xclang -ast-dump -fsyntax-only
*test03.cpp:7:19: error: use of undeclared identifier 'RED'*
*    [[own::myattr(RED)]]*
                  ^
Using:
def OWNMyattr : Attr {
  let Spellings = [CXX11<"own", "myattr">];
  let Args = [VariadicEnumArgument<"Color", "ColorType",
                           ["RED", "BLUE","GREEN"],
                           ["RED", "BLUE","GREEN"]>];
  let Documentation = [Undocumented];
}

However if I use *"RED*" instead *RED*, It compiles.


$clang++ test03.cpp  -std=c++11 -Xclang -ast-dump -fsyntax-only
TranslationUnitDecl 0x864a240 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x864a780 <<invalid sloc>> <invalid sloc> implicit __int128_t
'__int128'
|-TypedefDecl 0x864a7e0 <<invalid sloc>> <invalid sloc> implicit
__uint128_t 'unsigned __int128'
|-TypedefDecl 0x864aba0 <<invalid sloc>> <invalid sloc> implicit
__builtin_va_list '__va_list_tag [1]'
`-FunctionDecl 0x864ac40 <test03.cpp:3:1, line:10:1> line:3:5 main 'int
(void)'
  `-CompoundStmt 0x868e2c8 <line:4:1, line:10:1>
    |-DeclStmt 0x864adc8 <line:5:5, col:14>
    | `-VarDecl 0x864ad50 <col:5, col:13> col:9 used a 'int' cinit
    |   `-IntegerLiteral 0x864ada8 <col:13> 'int' 5
    |-DeclStmt 0x864ae68 <line:6:5, col:14>
    | `-VarDecl 0x864adf0 <col:5, col:13> col:9 b 'int' cinit
    |   `-IntegerLiteral 0x864ae48 <col:13> 'int' 6
    |-DeclStmt 0x868e270 <line:8:5, col:19>
    | `-VarDecl 0x868e080 <col:5, col:17> col:10 j5 'int':'int' cinit
    |   |-BinaryOperator 0x868e188 <col:15, col:17> 'int' '*'
    |   | |-IntegerLiteral 0x868e128 <col:15> 'int' 2
    |   | `-ImplicitCastExpr 0x868e170 <col:17> 'int' <LValueToRValue>
    |   |   `-DeclRefExpr 0x868e148 <col:17> 'int' lvalue Var 0x864ad50 'a'
'int'
    |   *`-OWNMyattrAttr 0x868e0e0 <line:7:7, col:24>*
    `-ReturnStmt 0x868e2a8 <line:9:5, col:12>
      `-IntegerLiteral 0x868e288 <col:12> 'int' 0


Regards,
Luis.



2014-12-19 16:10 GMT+01:00 Aaron Ballman <aaron at aaronballman.com>:
>
> On Fri, Dec 19, 2014 at 7:09 AM, LUIS MIGUEL SANCHEZ GARCIA
> <lmsanche at inf.uc3m.es> wrote:
> > It is something like that:
> >
> > file: include/clang/Basic/Attr.td
> >
> > def OWNmyattr : Attr {
> >   let Spellings = [CXX11<"own", "myattr">];
> >   let Args = [VariadicEnumArgument<"Color", "ColorType",
> >                            ["RED", "BLUE","GREEN"],
> >                            ["RED", "BLUE","GREEN"]>];
> >   let Documentation = [Undocumented];
> > }
>
> That definition looks reasonable to me; what problems are you running into?
>
> ~Aaron
> >
> >
> >
> >
> > Thanks,
> >
> > Regards,
> > Luis.
> >
> > 2014-12-18 22:19 GMT+01:00 Aaron Ballman <aaron at aaronballman.com>:
> >>
> >> On Thu, Dec 18, 2014 at 4:48 AM, LUIS MIGUEL SANCHEZ GARCIA
> >> <luismiguel.sanchez at uc3m.es> wrote:
> >> > I tried to include a variadic parameter into a c++11 attribute:
> >> >
> >> > Example:
> >> >
> >> > int main(){
> >> > ....
> >> > [[my::ownattr(RED, BLUE)]]
> >> > f();
> >> > ....
> >> > }
> >> >
> >> >
> >> >
> >> > being A and B values of an enumerate like:
> >> > enum class Color {RED, GREEN, BLUE};
> >> >
> >> > Any help?
> >>
> >> What does your attribute's table definition look like? What problems
> >> are you running into?
> >>
> >> ~Aaron
> >
> >
> >
> > --
> > --
> > --
> > --------------------------------------------------
> > Luis Miguel Sánchez García
> > Computer Architecture and Technology Area.
> > Office 2.2.B08
> > Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID
> > Universidad Carlos III de Madrid
> > Avda. de la Universidad, 30
> > 28911 Leganés - Madrid - Spain
> > e-mail: lmsan at arcos.inf.uc3m.es
> >         luismiguel.sanchez at uc3m.es
> >
> > Phone: (+34) 91 624 5951
> >
> > Linked-In: http://es.linkedin.com/in/lmsan
> > Twitter: http://twitter.com/lmsanchezgarcia
> > --------------------------------------------------
>


-- 
-- 
-- 
--------------------------------------------------
Luis Miguel Sánchez García
Computer Architecture and Technology Area.
Office 2.2.B08
Computer Science Department. UNIVERSIDAD CARLOS III DE MADRID
Universidad Carlos III de Madrid
Avda. de la Universidad, 30
28911 Leganés - Madrid - Spain
e-mail: lmsan at arcos.inf.uc3m.es
        luismiguel.sanchez at uc3m.es

Phone: (+34) 91 624 5951

Linked-In: http://es.linkedin.com/in/lmsan
Twitter: http://twitter.com/lmsanchezgarcia
--------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141219/300c869f/attachment.html>


More information about the cfe-dev mailing list