Warning: Definition check of inherited attributes fails in cases with AST inheritance

Issue #235 invalid
Christoff Bürger created an issue

Assume the following AST grammar:

Program ::= ProcedureDecl*;

IdUse: Expr ::= <Name>;
abstract IdDecl: Stmt ::= <Name>;

ProcedureDecl: IdDecl ::= VariableDecl* Block;
VariableDecl: IdDecl ::= [Expr];

abstract Stmt;
Block: Stmt ::= Stmt*;
...

abstract Expr;
...

Assume the following definition of an lookup attribute for all AST nodes:

inh IdDecl ASTNode.lookup(String name);

eq Program.getProcedureDecl(int i).lookup(String name) {
    ... // some implementation
}

JastAdd complains with the following warning:

[jastadd] Warning at ...: missing inherited equation for attribute lookup in class Expr when being child of VariableDecl (path: Program->VariableDecl->Expr), and in class VariableDecl when being child of Program (path: Program->VariableDecl)

The AST Program->VariableDecl is not possible however! Thus, there is no need for such a definition. In fact, eq Program.getProcedureDecl(int i).lookup(String name) already defines lookup for all children.

If the equation is changed to:

eq Program.getChild(int i).lookup(String name) {
    ...
}

JastAdd does not throw any warning. Note, that this is still incorrect, since the root (Program) has no equation for lookup.

Comments (6)

  1. Christoff Bürger reporter

    Indeed, that it is; I forgot an introduced NTA. Still the issue, that the root itself has no definition remains.

  2. Niklas Fors

    Yes, declaring an inherited attribute on the type ASTNode will not force root nodes to have an equation. This is something that JastAdd currently is lacking. It would be good if it was possible to give an default equation when declaring an inherited attribute on ASTNode, which would then hold for the root nodes.

  3. Christoff Bürger reporter

    Thanks Niklas! I close this issue, as the original title and motivation is solved.

  4. Christoff Bürger reporter

    An introduced NTA caused the problems. JastAdd behaved correctly.

    Note: The problem that inherited attributes of ASTNode are undefined in case of roots and JastAdd does not complain about this remains.

  5. Jesper Öqvist

    This has been discussed already in issue #175 and I think most arguments for and against were brought up there.

    It would indeed be nice to have default values for inherited attributes, but we decided that in the current implementation the best we can do is to allow inherited attributes on root nodes and not generate a warning for that case.

  6. Log in to comment