Git Product home page Git Product logo

astcreator's People

Contributors

joey-coleman avatar lausdahl avatar ldcouto avatar peterwvj avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lausdahl

astcreator's Issues

Java doc warnings

The java doc comments in the generated code has errors.

Example from Overture:

--- maven-javadoc-plugin:2.9:jar (attach-javadocs) @ ast ---

8 warnings
Javadoc Warnings
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:55: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:62: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:69: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:76: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:83: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/intf/lex/ILexLocation.java:90: warning - @return tag has no arguments.
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/lex/LexNameToken.java:228: warning - Tag @link: reference not found: HackLexNameToken
/Users/kel/data/overture/overture-git/core/ast/src/main/java/org/overture/ast/lex/VDMToken.java:281: warning - @return tag has no arguments.

ASTCreator cannot handle lists of strings

Given the tree specification below:

Packages
base demo.ast;
analysis demo.analysis;

Tokens

java_String = 'java:java.lang.String';

Abstract Syntax Tree

Top {-> package='demo.ast.nodes'}
  = {test} [field]:java_String*
  ;

Aspect Declaration

The code produced by ASTCreator does not compile since there seems to be a problem with the way that the tool handles lists of strings. The compilation errors are:

[ERROR] /home/peter/dev/playground/string-bug/target/generated-sources/astCreator/demo/ast/nodes/ATestTop.java:[114,25] no suitable method found for cloneListExternal(java.util.List<capture#1 of ? extends java.lang.String>)
    method demo.ast.Node.<T>cloneListExternal(java.util.List<T>,java.util.Map<demo.ast.INode,demo.ast.INode>) is not applicable
      (cannot instantiate from arguments because actual and formal argument lists differ in length)
    method demo.ast.Node.<T>cloneListExternal(java.util.List<T>) is not applicable
      (inferred type does not conform to declared bound(s)
        inferred: capture#1 of ? extends java.lang.String
        bound(s): demo.ast.ExternalNode)
[ERROR] /home/peter/dev/playground/string-bug/target/generated-sources/astCreator/demo/ast/nodes/ATestTop.java:[146,25] no suitable method found for cloneListExternal(java.util.List<capture#2 of ? extends java.lang.String>,java.util.Map<demo.ast.INode,demo.ast.INode>)
    method demo.ast.Node.<T>cloneListExternal(java.util.List<T>,java.util.Map<demo.ast.INode,demo.ast.INode>) is not applicable
      (inferred type does not conform to declared bound(s)
        inferred: capture#2 of ? extends java.lang.String
        bound(s): demo.ast.ExternalNode)
    method demo.ast.Node.<T>cloneListExternal(java.util.List<T>) is not applicable
      (cannot instantiate from arguments because actual and formal argument lists differ in length)

ASTCreator crashes on missing .tostring file

Given a specification demo.ast. If demo.ast.tostring is missing then ASTCreator crashes brutally. See output below.

[INFO] ------------------------------------------------------------------------
[INFO] Building ASTCreator String Bug 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- astcreator-plugin:1.6.4:generate (java) @ stringbug ---
[INFO] Preparing for tree generation...
[INFO] Checking if generation required.
[INFO] Full AST generation needed
[INFO] Generating...
[INFO] Generator starting with input: /home/peter/dev/playground/string-bug/src/main/resources/demo.ast
[ERROR] 
java.io.FileNotFoundException: /home/peter/dev/playground/string-bug/src/main/resources/demo.ast.tostring (No such file or directory)
    at java.io.FileInputStream.open(Native Method) ~[na:1.7.0_79]
    at java.io.FileInputStream.<init>(FileInputStream.java:146) ~[na:1.7.0_79]
    at org.overture.tools.maven.astcreator.GenerateTree.generateSingleAst(GenerateTree.java:332) [astcreator-plugin-1.6.4.jar:na]
    at org.overture.tools.maven.astcreator.GenerateTree.execute(GenerateTree.java:153) [astcreator-plugin-1.6.4.jar:na]
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) [maven-core-3.3.3.jar:3.3.3]
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) [maven-core-3.3.3.jar:3.3.3]

Extension of leaf nodes not working

The test case SimpleExtendTest does not generate the expected output:

base

exp {-> package='org.overture.ast.expressions'}
    =   {aa} [type]:stm.st1
    ;

extention

exp {-> package='org.overture.interpreter.ast.expressions'}
    =   {aa}  [ee]:stm.st2
    ;

We would expect the extended tree to include an extended AAaExp (extended) which extends AAaExp (base), having the following fields:

type
ee

and the analysis to include analysis for this new class as well where the depth first visitor takes inherited fields into account.

The node is skipped in the extended generation in ExtensionGenerator2.includeClassesFromExtension where willGenerateExtensionFor excluded it.

hack to include it:

private static void includeClassesFromExtension(Environment result,
            Environment ext, Environment base)
    {
        for (IClassDefinition cDef : ext.getClasses())
        {
            if (!willGenerateExtensionFor(cDef, base))
            {
                if (!isUtilityOrTemplateClass(cDef, ext))
                {
                    cDef.setIsExtTree(true);
                    result.getClasses().add(cDef);
                }
            }

            if(cDef.getName().toString().startsWith("AAaExp"))
            {
                cDef.setIsExtTree(true);
                result.getClasses().add(cDef);
            }
        }
    }

AST Error don't fail Maven

When there is a problem with AST creator (such as parse error or path not found) the Maven build doesn't stop.

So you end up getting a LOT of compilation errors and it makes it harder to figure out what's up.

Please report ASTCreator errors to Maven so the build fails sooner. This is done by throwing a MojoException, I think

Constructor dublication when using externally defined nodes as graph fields

It's not possibly to declare externally defined types as graph fields. The problem can be demonstrated using the AST specification below:

Packages
base demo.ast;
analysis demo.analysis;

Tokens

  MyClass = 'java:demo.code.MyClass';

java_String = 'java:java.lang.String';

Abstract Syntax Tree

Top {-> package='demo.ast.nodes'}
  = {test} (field):MyClass
  ;

Aspect Declaration

You get the following compilation error:

[INFO] Compiling 26 source files to /home/peter/dev/playground/string-bug/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/peter/dev/playground/string-bug/target/generated-sources/astCreator/demo/ast/nodes/ATestTop.java:[84,16] constructor ATestTop() is already defined in class demo.ast.nodes.ATestTop
[INFO] 1 error

Field of generated node does not have appropriate cloning method

The specification below

...
| {myNode} [strs]:java_String*

..Leads to the follow compilation errors in the clone method of the generated node:

Bound mismatch: The generic method cloneListExternal(List<T>, Map<INode,INode>) of type Node is not applicable for the arguments (List<capture#4-of ? extends String>, Map<INode,INode>). The inferred type capture#4-of ? extends String is not a valid substitute for the bounded parameter <T extends ExternalNode>

Changing the names of base nodes and visitors

Overture uses ASTCreator to specify the VDM AST, but it also uses ASTCreator to specify the IR or the code generation AST. Some of the classes in the Overture code base both process nodes from the VDM AST and the IR, which requires either the VDM INode class or the IR INode class to be fully qualified in order to be able to distinguish between the two INode classes.

So it would be useful to be able to set the name of the top node via the AST specification file in order to avoid referring to the types using their fully qualified names. A similar issue occurs for the names of the visitor base classes.

The generated code includes java warnings

The generated code sometimes contains too many includes e.g. Eclipse to show warnings for the unused includes.

Consider to add @SuppressWarnings("all") to the classes.

Confusing null reference exception when run in Maven without referenced base tree

When building an Overture code generation project with AstCreator, using maven.

AstCreator prints out "Extension base artifact found - exstracting base tree definition files" indicating that the extension base artifact has been found and then if no such artifact is specified a null pointer exception is thrown.

The problem occurs in: maven/src/main/java/org/overture/tools/maven/astcreator/GenerateTree.java in line 80.

To cause the issue a maven pom.xml which defines the plugin in the build. As in the Overture/vdm2c project, but not including an artifact dependeny providing the artifact indicated in extendedAstArtifactId.

To solve the issue I would propose adding before line 79 of maven/src/main/java/org/overture/tools/maven/astcreator/GenerateTree.java with along the lines of:

if(baseArtifact == null)
{
getLog().error("Base artifact not found. Are you missing an artifact dependency?");
return;
}

Error generating graph field

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.