Remove the error: "multiple tree roots to search for contributions"

Issue #294 resolved
Alfred Åkesson created an issue

The proposal is to remove the error: "multiple tree roots to search for contributions" and instead let the root in the tree you calling the collection attribute on be the root for the collecting.

This is useful when writing reusable collection attributes and you do not know the roots of the abstract grammar.

Comments (3)

  1. Jesper Öqvist

    This error only occurs when using an implicit collection root, i.e. when you omit the root X part of the collection attribute declaration.

    Intuitively one would think that the actual root node of the current tree could be used as the collection root. The only problem is that the generated code for finding the root node searches for a specific root type. Here is the relevant template code:

    while (node != null && !(node instanceof #rootType)) {    
      node = node.getParent();       
    #rootType root = (#rootType) node;

    If the collection root is implicit, then we could instead set #rootType to ASTNode and use this:

    while (node.getParent() != null) {    
      node = node.getParent();       
    #rootType root = (#rootType) node;

    However having rootType = ASTNode would not be good for cache memory usage as there are a couple fields generated on the root type for memoizing the collection attribute survey phase.

    The root type could be the grammar root type if there is one and otherwise ASTNode.

  2. Jesper Öqvist

    Generalize handling of implicit collection roots

    Allow implicit root type for collection attributes when the grammar has multiple root types.

    If there are multiple roots in the grammar, the collection root type is set to ASTNode.

    Factored out root finding in collection attribute templates.

    fixes #294 (bitbucket)

    → <<cset 83593f2315c8>>

  3. Log in to comment