Re: [Jastadd] NTAs + fullCopy()

From: Jesper Öqvist <jesper.oqvist_at_cs.lth.se>
Date: Fri, 19 Oct 2012 11:45:42 +0200

Hi Jesper,

I have committed a fix for the issue with fullCopy copying NTA children.
This was not an intended behaviour. The fix is currently being tested
and will hopefully be released in a bugfix release of JastAdd next week.

Regarding the NTA syntax there are two supported ways of declaring NTAs:

1. /NTA/ - NTA declared in AST definition and equation provided in
aspect file
2. syn nta - NTA declared in aspect file

If you declare the NTA in an AST definition, e.g.,

Node ::= /X*/;

You should only use this syntax to provide the equation for the NTA:

syn lazy List Node.getXList() = ...;

JastAdd does not currently support the combination of using an AST
definition and

syn nta ...

Ideally we should probably change this behaviour, so that JastAdd can
accept using "syn nta" together with the AST definition, but at the
moment this does not work. The keyword lazy should also be compatible
with nta definitions since after all NTAs should always be cached.

The question of which syntax to use of alternatives 1 and 2 above
depends on what you need to use the NTA for.

Alternative 1 requires the NTA equation to be declared lazy if it should
be cached and final if it is safe to cache during rewrite. NTA equations
in alternative 2 are implicitly cached even if the parent is non-final
(being rewritten).

Alternative 1 ensures that a method for accessing individual list
elements is generated, but this can also be provided with an attribute
if you choose to use alternative 2:

syn nta List Node.getXList() = ...;
syn X Node.getX(int i) = (X) getXList().getChild(i);

Inherited attribute equations can not be defined for NTA children
declared using alternative 2. Support for this is also something that
could be added to JastAdd, but at the moment it is not implemented.

The advantages of syntax alternative 2 are that you can declare
parameterized NTAs, and that it provides a modular way of adding NTA
children, since this alternative does not require changing AST definitions.

/Jesper


On 08/23/2012 04:12 PM, Jesper Mattsson wrote:
>
> Hi
>
> I'm having some problems with using fullCopy() on a node that has an
> NTA (a List). The problem is that the NTA is copied as well (with
> fullCopy()), but the _calculated flag is set to false (in clone()).
> Thus copying the NTA is wasted work, since it will be recalculated on
> next access anyway. Also, we would prefer it not being copied.
>
> It might simply be that I have declared the NTA in the wrong way --
> how should they be declared with JastAdd 2? From reading the manual, I
> can see 3 possibilities, and the way we have done it in JModelica.org
> earlier isn't one of them. Each of these ways seems to have some
> problems (adding a list of X in examples below):
>
> 1."/X*/" in .ast file + "syn nta List getXList()" in .jrag: both
> _completed and _value fields are added, **and** the NTA is added to
> children array
>
> 2.Nothing in .ast file + "syn nta List getXList()" in .jrag:
> _completed/_value are added, but other traversal methods are not
> added, e.g. getNumX()
>
> 3."/X*/" in .ast file + "syn List getXList()" in .jrag: no fields are
> generated, NTA is recalculated at each access
>
> 4."/X*/" in .ast file + "syn lazy List getXList()" in .jrag: same as
> 1, except that the value of the NTA is not saved unless the parent is
> final
>
> What syntax for NTAs should we use?
>
> Is it intended that the NTA values are copied by fullCopy()?
>
> Jesper
>
> *Jesper MATTSSON, MSc*
>
> Software Developer & IT Administrator
>
> Phone direct: +46 73 324 5909
>
> Email: jesper.mattsson_at_modelon.com <mailto:jesper.mattsson_at_modelon.com>
>
>
> Description: Description: Description: Modelon_2011_Gradient_RGB_400
>
> ------------------------------------------------------------------------
>
> Modelon AB
> Ideon Science Park
> SE-223 70 Lund, Sweden
>
>
>
> Phone: +46 46 286 2200
> Fax: +46 46 286 2201
>
>
>
>
> Web: http://www.modelon.com <http://www.modelon.com/>
>
> This email and any attachments are intended solely for the use of the
> individual or entity to whom it is addressed and may be confidential
> and/or privileged. If you are not one of the named recipients or have
> received this email in error, (i) you should not read, disclose, or
> copy it, (ii) please notify sender of your receipt by reply email and
> delete this email and all attachments, (iii) Modelon does not accept
> or assume any liability or responsibility for any use of or reliance
> on this email.
>
>
> _______________________________________________
> JastAdd mailing list
> JastAdd_at_cs.lth.se
> https://mail1.cs.lth.se/cgi-bin/mailman/listinfo/jastadd
Received on Fri Oct 19 2012 - 11:45:38 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 16 2014 - 17:19:06 CEST