-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate IR definitions by annotation processor - 1st step #11770
Merged
Merged
Changes from all commits
Commits
Show all changes
201 commits
Select commit
Hold shift + click to select a range
6e33120
Add parser-dsl and parser-processor projects
Akirathan 69f9247
Add JModule
Akirathan 0e4ceb0
Fix module declaration - no compiler module dependency
Akirathan 9891eb7
Add annotation processor testing.
Akirathan a3bf203
Rewrite some IR elements to IRNode annotated interfaces
Akirathan 08b0571
IRProcessor does some sanity checks
Akirathan 51796ba
IRNode does not have name parameter
Akirathan 3ea7a90
IRProcessor generates source file for record
Akirathan f6bf733
Add imports and overriden IR methods to generated record
Akirathan 1870ef2
Add field processing
Akirathan 826245d
IRProcessor generates classes, not records
Akirathan fc89b3d
IRProcessor generates overrides for user-defined parameterless methods
Akirathan 1fc0497
Add Field.isExpression method
Akirathan d2bb8c3
sbt picks up Scala case classes generated by Java annotation processor
Akirathan 68a070b
IRProcessor generates Scala classes.
Akirathan cf08781
Revert "sbt picks up Scala case classes generated by Java annotation …
Akirathan f930e53
Revert "IRProcessor generates Scala classes."
Akirathan 298c883
IRProcessor handles primitive fields
Akirathan bc1e9c9
Remove unused methods
Akirathan ef05c64
IRProcessor fails fast
Akirathan aa0a5b6
IRProcessor can collect fields from super interfaces
Akirathan c6def78
Fix collecting fields from super interfaces.
Akirathan 8cea491
Prepare IRNodeProcessor for processing multiple nested interfaces
Akirathan f5cb331
IRNodeProcessor handles multiple nested interfaces
Akirathan 2393e18
runtime-parser-processor does not depend on runtime-parser
Akirathan cf1d079
Move parser processor tests to a separate project
Akirathan f63bda1
runtime-parser-processor does not depend on runtime-parser
Akirathan 158a4f1
runtime-parser depends on runtime-parser-processor
Akirathan 1289374
IRProcessor adds package
Akirathan 73a9d31
ParserDependenciesTest ensures that IRNodeProcessor is on class path
Akirathan be4396c
runtime-parser-processor module provides annotation processor service
Akirathan 3665232
Fix getSimpleTypeName in ReferenceField
Akirathan 260d11d
No nested @IRNode annotation
Akirathan df95a4e
JModule extends IR
Akirathan 7918fd2
IRNodeProcessor handles parametrized List child
Akirathan 9ae8e3f
runtime-parser-processor-tests runs with enabled assertions
Akirathan cf264cf
Test IRNode with List of children
Akirathan 0f21885
All IR interfaces use scala list, not java.util.List
Akirathan 18b2d10
Do not process already overriden methods
Akirathan 26239a3
Enable IRProcessor in runtime-parser
Akirathan 9c3a580
Ensure that only fields from current interface and its super interfac…
Akirathan c6b1987
Implement passData, location and diagnostics methods
Akirathan 399ca43
Override duplicate method
Akirathan 7a97c61
Fix duplicate method generation
Akirathan 8acfa30
Move duplicate method generation to a separate class
Akirathan 7988276
Duplicate method duplicates also non-child fields
Akirathan c84ebb7
Simplify tests
Akirathan 8a778f0
During runtime-parser-processor-test compilation, IRNodeProcessor runs
Akirathan 86d1b0e
docs
Akirathan 8aa64bd
Add some IR interfaces to the testing code
Akirathan e91f09e
test generated list children
Akirathan dd34e5d
DuplicateMethodGenerator duplicates also meta fields
Akirathan 2a2b6d3
Builder allows setting meta fields
Akirathan 7def7b1
Add tests for duplicated metadata
Akirathan 66aba89
Add runtime-parser-processor-tests to the enso aggregate
Akirathan f6b75ed
Add IRCopyMethod annotation
Akirathan 9bccf1c
Iteration over super interfaces is handled only via SuperInterfaceVis…
Akirathan f027307
Simplify super interface iteration
Akirathan 687d0e1
Builder has a copy constructor
Akirathan bd9b7e4
Implement CopyMethodGenerator
Akirathan 98f4743
Fix all tests
Akirathan 92d9004
Test copy method generation
Akirathan 69728be
Do not try to override static or default methods
Akirathan 7709597
docs
Akirathan 7d012fe
Allow multiple copy methods
Akirathan cb06f03
CopyMethodGenerator generates copy method with correct order of param…
Akirathan c08c035
Test valid parameter names for copy method
Akirathan 43ed045
More tests
Akirathan 69258cf
Generate mapExpressions method
Akirathan f888cee
Add mock definition of JCallArgument
Akirathan 57c5bff
Use qualified type names in mapExpressions method
Akirathan be2d374
Implement JBlank.create factory method
Akirathan b828603
JExpression overrides duplicate and mapExpressions
Akirathan 814d031
Merge branch 'develop' into wip/akirathan/java-ir
Akirathan 419dca0
Remove unused import
Akirathan c8cbc98
Move all the sample `JXyz` interfaces to tests
Akirathan fd6ad5b
Generate identifiedLocation method override
Akirathan e066374
Fix compilation after the move
Akirathan 68389f4
Move sample `JXyz` interfaces to a dedicated test package
Akirathan 1b7a120
Add sample definition of JEmpty
Akirathan aa345ed
Replace Scala Empty with Java Empty annotated with @IRNode
Akirathan fa26144
Refactor Utils.findMethod
Akirathan c4a669e
Fix test after merge of develop
Akirathan e4222f0
Fix TestIRProcessorInline after `J*` classes were moved to test dir
Akirathan 4d5b214
Implement SetLocationMethodGenerator
Akirathan 5ef1bde
fmt
Akirathan 9b48ed4
Ensure only a single IR interface is extended
Akirathan 5ac716a
Fix compilation after Refactoring Empty to an interface with @IRNode
Akirathan 4a0ea14
Empty extends Expression
Akirathan 9b5f1b2
Override equals and hashCode
Akirathan e294877
Explicitly list all the processor classes in javacOptions
Akirathan 00ad5f6
Refactor field class to field package
Akirathan e6c7609
Refactor method generation classes to methodgen package
Akirathan c8b7e34
Introduce utils package
Akirathan fadf973
Add GenerateIR annotation
Akirathan b549bf7
Remove tests using the IRNode annotation
Akirathan f6f0e4d
Revert "Empty extends Expression"
Akirathan 70deaca
Revert "Fix compilation after Refactoring Empty to an interface with …
Akirathan f02b645
Revert "Replace Scala Empty with Java Empty annotated with @IRNode"
Akirathan 088b614
Remove all test interfaces using IRNode annotation
Akirathan 3a3cc14
Remove TestGeneratedIR
Akirathan 11d2a25
Update TestIRPRocessorInline.
Akirathan e6205f1
GenerateIR uses IR as the default interface
Akirathan ea17b2f
Skeleton of implementation
Akirathan d978592
Remove IRNode
Akirathan 54d9c25
Better error msg in FieldCollector
Akirathan 7507065
Add import in test
Akirathan e026c77
Ensure GenerateIR.interfaces is subtype of IR
Akirathan f66ded2
Add import in test
Akirathan 363a838
Fix generic type introspection from VariableElement
Akirathan b8f6b8f
Fix imports in rest of the tests.
Akirathan a42d236
Generated constructor is protected
Akirathan 6587692
Generate second constructor - with user fields
Akirathan 3ea1bb3
style - add new line
Akirathan d61eca7
Add docs to the generated ctors.
Akirathan 0ea630d
Add sample JExpression to tests
Akirathan 006406f
fmt
Akirathan 4973bb8
Add java docs to the generated class
Akirathan 00cae90
Remove unused IRCopyMethod
Akirathan 3cb8424
Replace scala Empty with generated IR
Akirathan 371071b
Support scala.Option field
Akirathan a94a954
Add nl
Akirathan 4368bd1
Add JCallArgument to tests
Akirathan 6222615
Merge branch 'develop' into wip/akirathan/java-ir-superclass
Akirathan 8f699f9
Test that annotated constructor can have meta parameter
Akirathan 51420df
Constructor parameters must be annotated
Akirathan db713a7
Constructor parameters can be meta type
Akirathan f33af6e
Generated super class is abstract
Akirathan 30f14d9
Annotated class must extend the generated super class
Akirathan ba602c4
Fix tests - annotated class must extend the generated super class
Akirathan 9bae261
Use specific IRProcessingException.
Akirathan 1b069ed
setLocation returns subclass type
Akirathan b3e262b
Reorder generated fields in JCallArgument
Akirathan 1a87899
mapExpressions returns subclass type
Akirathan e7dc725
Add scala tests to runtime-parser-processor-tests
Akirathan 0a1f5a8
[WIP] Demonstrate implementation of unapply
Akirathan 83fe023
Revert "[WIP] Demonstrate implementation of unapply"
Akirathan c6d66c3
Merge branch 'develop' into wip/akirathan/java-ir-superclass
Akirathan 2ae6a59
Improve error message in IRProcessor
Akirathan d8160b5
Fix check of super class
Akirathan 0edd832
Generated classes are compiled with -parameters
Akirathan e54fdb9
GenerateIR.interfaces is of type Class[]
Akirathan 9da9394
Can specify multiple GenerateIR.interfaces to implement
Akirathan bdd73c3
Generated super class can have arbitrary name
Akirathan ac0d78b
Fix typo in docs
Akirathan b3ce704
Rename DiagnosticStorage.empty to createEmpty
Akirathan b82d7cf
Fix build
Akirathan 94c40d0
Duplicate method has specific return type
Akirathan aaad0c7
Generate also parameterless duplicate method
Akirathan c062b90
Generated class can already exist - will be rewritten
Akirathan 140d7b5
Generate diagnosticsCopy.
Akirathan a5420c1
Replace CallArgument Scala code with the generated class.
Akirathan 0708535
Fix duplicate method - passData and diagnostics are copied.
Akirathan e2c3c3b
Generate toString method
Akirathan 3086f52
Fix expected error message
Akirathan 24b28ad
FIx ensureExtendsGeneratedSuperclass
Akirathan 7479925
Fix NPE in duplicate
Akirathan f8c9e12
mapExpressions duplicates this iff one of the mapped children changed
Akirathan 198ce88
mapExpressions do not recurse on Expression children
Akirathan 70b1be3
Specified.copy only copies if parameter is different
Akirathan a25ad6f
Pass null to meta field in super ctor
Akirathan 80509a1
Fix whitespaces in formatting of generated classes
Akirathan df0a001
No "copy constructor" for Builder
Akirathan bd4b0b2
imports are sorted
Akirathan 412d466
Replace Supplier with private method
Akirathan 3d865b9
Add docs
Akirathan fab106f
fix typos
Akirathan fe0a378
Rename minus to diff
Akirathan 42a988f
Introduce constants
Akirathan cbaa6f7
passData is never null
Akirathan 6ad9e23
Field uses TypeMirror instead of TypeElement
Akirathan 79364fc
More constant in Utils
Akirathan d22bf6d
Move ClassField out of GeneratedClassContext.
Akirathan f36220a
duplicate method compares fqn type names
Akirathan c872739
ClassField.canBeNull must be specified in builder
Akirathan 0b8715e
Generate validateConstructor method
Akirathan 832f47d
Prefer simple type names in generated source
Akirathan bdf0258
Fix test: passData is never null
Akirathan 597edac
Fix Utils.simpleTypeName
Akirathan 2cd3946
Field is abstract class.
Akirathan e443619
Prefer simple type names
Akirathan 1ceabfe
Generate copy method
Akirathan 0e15bef
Generate just a single constructor matching subtype
Akirathan 6451745
Implement Specified.showCode
Akirathan 6fa233a
passData is never null
Akirathan 7076c8a
Generated toString method returns one-line string
Akirathan 2586bbe
Update changelog
Akirathan 4226c2e
Add generated sources to runtime-parser/Compile/doc/sources.
Akirathan 98476fa
Do not link duplicate method in javadoc.
Akirathan 291e593
Run sbt clean before publishing M2
Akirathan dd5efcd
[WIP] Print sbt config
Akirathan cdcdb48
Revert "[WIP] Print sbt config"
Akirathan e0f0537
Revert "Run sbt clean before publishing M2"
Akirathan 65701c1
Revert "Add generated sources to runtime-parser/Compile/doc/sources."
Akirathan 5de98f3
Don't publish doc and src jars to M2
Akirathan 1762929
Add common settings to the projects published to local Maven repo
Akirathan 9d16b2e
Merge branch 'develop' into wip/akirathan/java-ir-superclass
Akirathan 4437f78
toStringMethod converts return value to single line
Akirathan 3a9b098
fix: toStringMethod converts return value to single line
Akirathan 328960f
Merge branch 'develop' into wip/akirathan/java-ir-superclass
Akirathan c203ea9
Merge branch 'develop' into wip/akirathan/java-ir-superclass
Akirathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}. | ||
Akirathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having shared
publishLocalSetting
is a good idea. SuppressingpackageDoc/publishArtifact
is a neat trick! We wouldn't be allowed to upload the artifact to Maven central repository without sources and javadoc, but for local deployment - it should be good enough solution.