Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • D dumpAst
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

GitLab update scheduled for Friday, March 31st between 08:15 and 08:45 CEST. If unpleasant, please contact René or Martin.

  • JastAdd
  • dumpAst
  • Issues
  • #6
Closed
Open
Issue created Feb 20, 2022 by Johannes Mey@johannes.meyOwner

DumpAst Ast nodes without a constructor with parameters are not recognized as such

Problem:

AST nodes are not shown as such, when they do not have any children.

Example:

Grammar:

Root ::= SimpleNode;
SimpleNode;

Results in (slightly untested like this, I abstracted from my use case):

@startuml
scale 1.0

object "Root@2040495657" as node0 {
}

node0 *-- node1 : SimpleNode
@enduml

Analysis:

Currently, AST nodes are recognized based on their constructors: dumpAst/src/main/jastadd/GenerationBackend.jadd:413

  // --- isAstNode ---
  syn boolean DumpNode.isAstNode() {
    Class<?> clazz = getObject().getClass();
    for (java.lang.reflect.Constructor<?> constructor : clazz.getConstructors()) {
      for (java.lang.annotation.Annotation annotation : constructor.getAnnotations()) {
        if (annotation.annotationType().getCanonicalName().startsWith(astNodeAnnotationPrefix()) &&
              annotation.annotationType().getSimpleName().equals("Constructor")) {
          return true;
        }
      }
    }
    return false;
  }

However, the generated node only has one constructor without annotations:

  public SimpleNode() {
    super();
  }

Thoughts:

  • An AST node is a node that inherits from the ASTNode superclass.
  • We do not know the name of this class (it can be changed by JastAdd) and its package.
  • Assuming we know that the Dumper is called with an AST node argument, we maybe can figure this out, but it is still not trivial, since then we have to figure out which class in the superclass hierarchy is the ASTNode class.
  • Thus, I suggest a "Duck-Typing" approach, check for a method that any ASTNode has, but probably not that many other nodes.
  • For this, I suggest public void init$Children().

MR will follow.

Assignee
Assign to
Time tracking