[dmd-internals] Why do AttribDeclarations exist?

Daniel Murphy yebblies at gmail.com
Fri Feb 17 01:49:44 PST 2012


Attributes don't always apply to everything inside them - eg a const
declaration doesn't make everything parsed inside it automatically
const, and this is sorted out during semantic as it should be.  And if
you pass it to the top-level declarations only, the same problem will
exist if you try and forward-reference sub-declarations.  Maybe this
could be done in a pre-semantic pass, though I'm not sure if it should
be.

I think the PendingAttribs approach might work for deprecated, but
will it for the others?  Being able to pass a bunch of attributes all
nested declarations without modifying semantic gives an easy way to
implement new attributes (even user-defined, if we ever go there) that
would simplify some things such as adding a message to deprecated.

On Fri, Feb 17, 2012 at 7:48 PM, Don Clugston <dclugston at googlemail.com> wrote:
> I found this why looking at bug 7482, and it seems to be a fundamental
> problem. Surely other people have hit this before.
>
> Something like:
> deprecated int x;
> is parsed as  StorageDeclaration( STCdeprecated, new VarDeclaration(x))
>
> note that the VarDeclaration is initially created without the
> 'deprecated' storage class.
> Then, when semantic is run on all the declarations in the module, it
> runs on StorageDeclaration, which then runs semanticNewSc on the
> VarDeclaration.
>
> The problem is, if 'x' is forward referenced, the storage declaration
> hasn't run yet. It gets found with the original, wrong storage class.
> I don't understand why these AttribDeclarations exist at all. Why
> isn't the whole thing dealt with in the parser?
>
> (ie, create a PendingAttribs struct, and pass it to all the children
> in a block).
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals


More information about the dmd-internals mailing list