www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - alias syntax

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
what is the purpose of the syntax

alias StorageClasses Declarator

?

(I just noticed my parser doesn't support it, but I don't see any reason to)
Aug 01 2009
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sat, Aug 1, 2009 at 8:31 PM, Ellery
Newcomer<ellery-newcomer utulsa.edu> wrote:
 what is the purpose of the syntax

 alias StorageClasses Declarator

 ?
I don't know where you're getting that grammar. Is that from the D spec?
Aug 01 2009
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
Jarrett Billingsley wrote:
 On Sat, Aug 1, 2009 at 8:31 PM, Ellery
 Newcomer<ellery-newcomer utulsa.edu> wrote:
 what is the purpose of the syntax

 alias StorageClasses Declarator

 ?
I don't know where you're getting that grammar. Is that from the D spec?
um, yeah. Declaration: typedef Decl alias Decl Decl Decl: StorageClasses Decl BasicType Declarators ; BasicType Declarator FunctionBody AutoDeclaration Never mind that's wrong. but it looks like it should be alias StorageClasses BasicType Declarator plus some change. my mistake. emphasis on StorageClasses, not what comes after it. Looking through declaration.c, I noticed that semantic disallows specifically alias const {blah blah blah} but not the others. ???!!!!!
Aug 01 2009
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sat, Aug 1, 2009 at 11:13 PM, Ellery
Newcomer<ellery-newcomer utulsa.edu> wrote:

 um, yeah.

 Declaration:
 =A0 =A0 =A0 =A0typedef Decl
 =A0 =A0 =A0 =A0alias Decl
 =A0 =A0 =A0 =A0Decl

 Decl:
 =A0 =A0 =A0 =A0StorageClasses Decl
 =A0 =A0 =A0 =A0BasicType Declarators ;
 =A0 =A0 =A0 =A0BasicType Declarator FunctionBody
 =A0 =A0 =A0 =A0AutoDeclaration


 Never mind that's wrong.

 but it looks like it should be

 alias StorageClasses BasicType Declarator
'Decl' is recursive. So: alias Decl can expand to: alias StorageClasses Decl which expands to: alias StorageClasses BasicType Declarators ; But is this not what you're pointing out? Are you instead taking issue with the fact that the grammar accepts something like "alias int foo() {}" whereas the compiler doesn't?
 Looking through declaration.c, I noticed that semantic disallows
 specifically

 alias const {blah blah blah}

 but not the others.
You mean how the compiler rejects "alias const int x;" but not "alias static int x;"? That is strange..
Aug 01 2009
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
 You mean how the compiler rejects "alias const int x;" but not "alias
 static int x;"?  That is strange..
I want to know why alias static int x; is allowed in the first place
Aug 01 2009
parent reply Zarathustra <adam.chrapkowski gmail.com> writes:
Ellery Newcomer Wrote:

 You mean how the compiler rejects "alias const int x;" but not "alias
 static int x;"?  That is strange..
I want to know why alias static int x; is allowed in the first place
d.grammar accepts: alias const int a; but compiler no (it is ok). d.grammar accepts: alias static int a; and compiler too It is compiler fault or compiler just ignore this cases which seem haven't sense. It is a grammar rule, in D there is much unnecessary (senseless ) notations. For example: void main(){ alias static int a; // compiler will ignore alias final static int b; // compiler will ignore final alias final int b; // compiler will ignore alias and final } ---------------------------------------------------------- class A{ final int a; // final field doesn't have a sense scope int a; // A is still not-scope class } ---------------------------------------------------------- module A; private class AA{ } module B; import A; void main(){ AA aa = new AA; // class AA is not private } ---------------------------------------------------------- As to your question: class K{ alias static int B; B b; // b is non-static } ----------------------------------------------------------
Aug 05 2009
parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
 ----------------------------------------------------------
 As to your question:
 class K{
   alias static int B;
   B b; // b is non-static
 }
 ----------------------------------------------------------
 
Curious. I didn't actually test the example, but I did for deprecated, and it doesn't get ignored. Further investigation shows that scope also isn't ignored, but the rest are. Also note that const is okay in a typedef, but not in an alias. And going over into D2 land, alias const(int) I; //is permitted, and alias immutable int I; //is permitted, but alias const int I; // bombs due to that one weird semantic rule Oh well. I guess I'll just parse it and flag any use of it as an error.
Aug 05 2009