Skip to content

Commit

Permalink
add @( argumentlist ) syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 9, 2012
1 parent 8f514c5 commit f5e5e6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/attrib.c
Expand Up @@ -1685,8 +1685,9 @@ void UserAttributeDeclaration::setScope(Scope *sc)

void UserAttributeDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writeByte('[');
buf->writestring("@(");
argsToCBuffer(buf, atts, hgs);
buf->writeByte(')');
AttribDeclaration::toCBuffer(buf, hgs);
}

Expand Down
12 changes: 11 additions & 1 deletion src/parse.c
Expand Up @@ -370,7 +370,17 @@ Dsymbols *Parser::parseDeclDefs(int once)
case TOKtls: stc = STCtls; goto Lstc;
case TOKgshared: stc = STCgshared; goto Lstc;
//case TOKmanifest: stc = STCmanifest; goto Lstc;
case TOKat: stc = parseAttribute(); goto Lstc;
case TOKat:
if (peek(&token)->value == TOKlparen) // @( ArgumentList )
{
nextToken();
Expressions *exps = parseArguments();
a = parseBlock();
s = new UserAttributeDeclaration(exps, a);
break;
}
stc = parseAttribute();
goto Lstc;
#endif

Lstc:
Expand Down
18 changes: 9 additions & 9 deletions test/runnable/uda.d
Expand Up @@ -9,9 +9,9 @@ template Tuple(T...)


enum EEE = 7;
["hello"] struct SSS { }
@("hello") struct SSS { }

[3] { [4][EEE][SSS] int foo; }
@(3) { @(4)@(EEE)@(SSS) int foo; }

pragma(msg, __traits(getAttributes, foo));

Expand All @@ -27,13 +27,13 @@ alias Tuple!(__traits(getAttributes, typeof(a))) TT;

pragma(msg, TT);

['c'] string s;
@('c') string s;
pragma(msg, __traits(getAttributes, s));

/************************************************/

enum FFF;
[FFF] int x1;
@(FFF) int x1;
pragma(msg, __traits(getAttributes, x1));

void test1()
Expand Down Expand Up @@ -66,8 +66,8 @@ void test3()

/************************************************/

[1] void foo4();
[2] void foo4(int x);
@(1) void foo4();
@(2) void foo4(int x);

void test4()
{
Expand All @@ -85,14 +85,14 @@ void test4()

pragma(msg, __traits(getAttributes, aa));
alias Tuple!(__traits(getAttributes, aa)) Taa;
[10] int aa;
@(10) int aa;

pragma(msg, __traits(getAttributes, bb));
alias Tuple!(__traits(getAttributes, bb)) Tbb;
[20] int bb;
@(20) int bb;
alias Tuple!(__traits(getAttributes, bb)) Tbbc;

[30] int cc;
@(30) int cc;
pragma(msg, __traits(getAttributes, cc));
alias Tuple!(__traits(getAttributes, cc)) Tcc;

Expand Down

0 comments on commit f5e5e6a

Please sign in to comment.