overturetool/astcreator

Error generating graph field

lausdahl opened this issue · 2 comments

The issues is discovered during development of vdm2c using this main tree:

https://github.com/overturetool/overture/blob/pvj/main/core/codegen/ir/src/main/resources/cg.astv2
from this commit
overturetool/overture@b4ac6ee

and this extension:

Packages

base org.overture.cgc.extast.node;
analysis org.overture.cgc.extast.analysis;

Tokens

Abstract Syntax Tree

CG = #decl
    ;


#decl {-> package='org.overture.cgc.extast.declarations'}
       = {classHeader}
        [name]:java_String
        (originalDef):CG.#decl.#Class
        [flattenedSupers]:CG.#decl.classHeader*
        [state]:CG.#decl.classState
        [methods]:CG.#decl.method*
        | {classState} [fields]:CG.#decl.field* //not sure why it cannot compile as a graph field
       ;

COMPILATION ERROR : 
-------------------------------------------------------------
/Users/kel/data/overture/overture-vdm2c/target/generated-sources/astCreator/org/overture/cgc/extast/declarations/AClassStateDeclCG.java:[67,31] type argument org.overture.codegen.cgast.declarations.AFieldDeclCG is not within bounds of type-variable E
/Users/kel/data/overture/overture-vdm2c/target/generated-sources/astCreator/org/overture/cgc/extast/declarations/AClassStateDeclCG.java:[67,73] type argument org.overture.codegen.cgast.declarations.AFieldDeclCG is not within bounds of type-variable E
/Users/kel/data/overture/overture-vdm2c/target/generated-sources/astCreator/org/overture/cgc/extast/declarations/AClassStateDeclCG.java:[67,55] no suitable constructor found for GraphNodeList(org.overture.cgc.extast.declarations.AClassStateDeclCG)
    constructor org.overture.ast.node.GraphNodeList.GraphNodeList(org.overture.ast.node.INode,java.util.Collection<? extends org.overture.codegen.cgast.declarations.AFieldDeclCG>) is not applicable
      (actual and formal argument lists differ in length)
    constructor org.overture.ast.node.GraphNodeList.GraphNodeList(org.overture.ast.node.INode) is not applicable
      (actual argument org.overture.cgc.extast.declarations.AClassStateDeclCG cannot be converted to org.overture.ast.node.INode by method invocation conversion)
    constructor org.overture.ast.node.GraphNodeList.GraphNodeList() is not applicable
      (actual and formal argument lists differ in length)

the node is:

public class AClassStateDeclCG extends SCDeclDeclBase
{
    private static final long serialVersionUID = 1L;

    /**
    * Graph field, parent will not be removed when added and parent 
    *  of this field may not be this node. Also excluded for visitor.
    */
    private GraphNodeList<AFieldDeclCG> _fields = new GraphNodeList<AFieldDeclCG>(this);

Ok the issue here is as follows:

  • Node lists. Here the import generated is import org.overture.codegen.cgast.NodeList;
  • Graph lists. Here the import generated is import org.overture.ast.node.GraphNodeList;

As a result no extended nodes can be graph nodes. It is also unclean what will happen for node lists if two fields are specified one of base tree nodes and one with extended nodes

I updated vdm2c to use this fix and it works