-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate IR definitions by annotation processor - 1st step (#11770)
The overall description is the same as in #11267, but this approach tries to generate super classes as suggested in https://github.com/enso-org/enso/pull/11267/files#r1869342527 # Important Notes Apart from the annotation processor implementation and tests, [CallArgument.Specified](https://github.com/enso-org/enso/blob/80509a1f2420e97b3879fc8e925a9a863373826d/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/CallArgument.java) was migrated to the new approach from Scala case class. I uploaded its generated class code in [this gist](https://gist.github.com/Akirathan/0e43de77fe91da399406c1ee7ac2cecd) so you can see it without compilation.
- Loading branch information
Showing
48 changed files
with
3,995 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module org.enso.runtime.parser.dsl { | ||
exports org.enso.runtime.parser.dsl; | ||
} |
51 changes: 51 additions & 0 deletions
51
engine/runtime-parser-dsl/src/main/java/org/enso/runtime/parser/dsl/GenerateFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.enso.runtime.parser.dsl; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Parameters of the constructor annotated with this annotation will be scanned by the IR processor | ||
* and <b>fields</b>will be generated for them. There can be only a single constructor with this | ||
* annotation in a class. The enclosing class must be annotated with {@link GenerateIR}. | ||
* | ||
* <h2>Fields</h2> | ||
* | ||
* The generated class will contain 4 <b>meta</b> fields that are required to be present inside | ||
* every IR element: | ||
* | ||
* <ul> | ||
* <li>{@code private DiagnosticStorage diagnostics} | ||
* <li>{@code private MetadataStorage passData} | ||
* <li>{@code private IdentifiedLocation location} | ||
* <li>{@code private UUID id} | ||
* </ul> | ||
* | ||
* Apart from these <b>meta</b> fields, the generated class will also contain <b>user-defined</b> | ||
* fields. User-defined fields are inferred from all the parameters of the constructor annotated | ||
* with {@link GenerateFields}. The parameter of the constructor can be one of the following: | ||
* | ||
* <ul> | ||
* <li>Any reference, or primitive type annotated with {@link IRField} | ||
* <li>A subtype of {@code org.enso.compiler.ir.IR} annotated with {@link IRChild} | ||
* <li>One of the <emph>meta</emph> types mentioned above | ||
* </ul> | ||
* | ||
* <p>A user-defined field generated out of constructor parameter annotated with {@link IRChild} is | ||
* a child element of this IR element. That means that it will be included in generated | ||
* implementation of IR methods that iterate over the IR tree. For example {@code mapExpressions} or | ||
* {@code children}. | ||
* | ||
* <p>A user-defined field generated out of constructor parameter annotated with {@link IRField} | ||
* will be a field with generated getters. Such field however, will not be part of the IR tree | ||
* traversal methods. | ||
* | ||
* <p>For a constructor parameter of a meta type, there will be no user-defined field generated, as | ||
* the meta fields are always generated. | ||
* | ||
* <p>Other types of constructor parameters are forbidden. | ||
*/ | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target(ElementType.CONSTRUCTOR) | ||
public @interface GenerateFields {} |
32 changes: 32 additions & 0 deletions
32
engine/runtime-parser-dsl/src/main/java/org/enso/runtime/parser/dsl/GenerateIR.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.enso.runtime.parser.dsl; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A class annotated with this annotation will be processed by the IR processor. The processor will | ||
* generate a super class from the {@code extends} clause of the annotated class. If the annotated | ||
* class does not have {@code extends} clause, an error is generated. Moreover, if the class in the | ||
* {@code extends} clause already exists, an error is generated. | ||
* | ||
* <p>The generated class will have the same package as the annotated class. Majority of the methods | ||
* in the generated class will be either private or package-private, so that they are not accessible | ||
* from the outside. | ||
* | ||
* <p>The class can be enclosed (nested inside) an interface. | ||
* | ||
* <p>The class must contain a single constructor annotated with {@link GenerateFields}. | ||
*/ | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target(ElementType.TYPE) | ||
public @interface GenerateIR { | ||
|
||
/** | ||
* Interfaces that the generated superclass will implement. The list of the interfaces will simply | ||
* be put inside the {@code implements} clause of the generated class. All the generated classes | ||
* implement {@code org.enso.compiler.core.IR} by default. | ||
*/ | ||
Class[] interfaces() default {}; | ||
} |
19 changes: 19 additions & 0 deletions
19
engine/runtime-parser-dsl/src/main/java/org/enso/runtime/parser/dsl/IRChild.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.enso.runtime.parser.dsl; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Constructor parameter annotated with this annotation will be represented as a child field in the | ||
* generated super class. Children of IR elements form a tree. A child will be part of the methods | ||
* traversing the tree, like {@code mapExpression} and {@code children}. The parameter type must be | ||
* a subtype of {@code org.enso.compiler.ir.IR}. | ||
*/ | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target(ElementType.PARAMETER) | ||
public @interface IRChild { | ||
/** If true, the child will always be non-null. Otherwise, it can be null. */ | ||
boolean required() default true; | ||
} |
19 changes: 19 additions & 0 deletions
19
engine/runtime-parser-dsl/src/main/java/org/enso/runtime/parser/dsl/IRField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.enso.runtime.parser.dsl; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A constructor parameter annotated with this annotation will have a corresponding user-defined | ||
* field generated in the super class (See {@link GenerateFields} for docs about fields). | ||
* | ||
* <p>There is no restriction on the type of the parameter. | ||
*/ | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target(ElementType.PARAMETER) | ||
public @interface IRField { | ||
/** If true, the field will always be non-null. Otherwise, it can be null. */ | ||
boolean required() default true; | ||
} |
Oops, something went wrong.