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

"H. S. Teoh" <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.