Faulty code generation with --concurrent option

Issue #299 resolved
Joachim Wedin
created an issue

When an NTA is abstractly declared on an abstract class it causes incorrect code generation for the abstract class.

For example

Test.ast:
abstract A ::= /D*/
D;
B : A;

Test.jrag:
// .options: concurrent
// .result: COMPILE_PASS
aspect Test {
    syn lazy List A.getDList() {
        List l = new List();
        l.add(new D());
        l.add(new D());
        return l;
        }
}

The above code results in the following faulty generated code:

A.java:
...
  public List getDList() {
    ASTState state = state();
    Object cached_value = getDList_value.get();
    if (cached_value != AttributeValue.NONE) {
      List _value = (List) cached_value;
      return _value;
    }
    state().enterLazyAttribute();
    List _result = getDList_compute();
    List _value = _result;
    _result.setParent(this);
    if (!getDList_value.compareAndSet(AttributeValue.NONE, _value)) {
      _result = (List) getDList_value.get();
    }
    state().leaveLazyAttribute();
    List node = (List) this.getChild(getDListChildPosition());
    return node;
  }
...

ASTNode.java:
...
  public T getChild(int i) {
    ASTNode child = getChildNoTransform(i);
    return (T) child;
  }

  public T getChildNoTransform(int i) {
    return getChildNoTransformBase(i);
  }

  public T getChildNoTransformBase(int i) {
    if (children == null) {
      return null;
    }
    T child = (T) children[i];
    return child;
  }
...

This is incorrect because the method getDlist calls getChild which ultimately accesses the child array instead of using getDList_value.get() which would be the correct way of obtaining the list. As a consequence the returned list from getDList is empty but it should have two elements.

When not using the older syntax for NTAs the problem is no longer present.

Comments (2)

  1. Jesper Öqvist

    Fix error in NTA child storage for concurrent mode

    When there was not an equation for some NTA on an AST class, but the NTA hand an equation in some superclass, the NTA was incorrectly accessed through the child vector instead of having a special accessor through getChildNoTransform(). This error was just caused by not looking for NTA equations in superclasses in ASTDecl.hasSynEq().

    fixes #299 (bitbucket)

    → <<cset 1ed8d15d5006>>

  2. Log in to comment