bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for Dlang support 1/2] d: create the Parser.Context class


From: H. S. Teoh
Subject: Re: [PATCH for Dlang support 1/2] d: create the Parser.Context class
Date: Tue, 27 Oct 2020 09:55:26 -0700

On Tue, Oct 27, 2020 at 07:38:46AM +0100, Akim Demaille wrote:
[...]
> > +  /**
> > +   * Information needed to get the list of expected tokens and to forge
> > +   * a syntax error diagnostic.
> > +   */
> > +  public static final class Context
> > +  {
> > +
> > +    private YYStack yystack;
> 
> Is this a copy of the stack?  It does not look like a
> reference/pointer to the this.  We must not copy it, it's big, and
> readonly here.  It should be "const", but I don't know how that is
> spelled in D.
[...]

Is YYStack a struct or class? Or an array? If it's an array or class,
it's a reference type by default.

W.r.t. const, there are several ways to spell it, depending on the
intended semantics.  If it should be an immutable reference, then you
could write it as:

        private const(YYStack) yystack;

In this case, the variable cannot be reassigned after initialization,
and if it's a reference type, it cannot be rebound.  Also, any elements
you retrieve from it will be const (const in D is transitive).

If it's an array, you can optionally have a mutable slice of immutable
elements (i.e., a view that can change, but the underlying elements are
not changeable):

        private const(E)[] yystack;     // where E is the element type of 
YYStack


T

-- 
Never trust an operating system you don't have source for! -- Martin Schulze



reply via email to

[Prev in Thread] Current Thread [Next in Thread]