Conversation
wadoon
force-pushed
the
weigl/javaastgen
branch
2 times, most recently
from
July 18, 2026 19:29
b0ba757 to
b06d4d8
Compare
wadoon
force-pushed
the
weigl/javaastgen
branch
5 times, most recently
from
August 20, 2026 15:00
6ef3ac7 to
7ecc12e
Compare
wadoon
force-pushed
the
weigl/javaastgen
branch
from
September 26, 2026 18:00
7ecc12e to
184a5f4
Compare
wadoon
force-pushed
the
weigl/javaastgen
branch
from
September 26, 2026 18:50
184a5f4 to
42ab407
Compare
Fix the java-ast metamodel and the generator so :key.ncore.java:classes builds with zero errors (previously ~1250 unresolved-type/sealed/hierarchy errors; only MethodReference.java:137 surfaced because javac aborted on a syntax error). Metamodel (src/adt/java-ast.java): - declare missing types: JavaProgramElement, Operator, Name, Comment, AbstractIntegerLiteral, Branch (+Case/Default), Catch, JMLModifiers, ObserverFunction, JAbstractSortedOperator, JOperatorSV - import de.uka.ilkd.key.java.ast.abstraction.Type - make concrete-extends-concrete parents abstract so generator-emitted sealed interfaces stay valid: ClassDeclaration, MethodDeclaration, StatementBlock, VariableSpecification, VariableReference, FieldReference, ProgramElementName - Statement/Expression extend ProgramElement so ProgramTransformer.body getters in children override covariantly - strip duplicate FieldSpecification fields, fix ReattachLoopInvariant field typo, drop MethodReference list wildcard, remove dead Declaration/Expression methods and unused placeholder types - wire marker interfaces faithfully via abstract classes only (Statement, MemberDeclaration, TypeReference*, Reference*, ProgramPrefix, IProgramVariable, IProgramMethod, ProgramConstruct, ...) Generator (src/generator/...): - PostSteps.sealing: drop SEALED for types without permitted subtypes (IGuard, LoopInitializer, IExecutionContext, ... become plain interfaces) - NodeSteps.setPackage: merge declared implements into extends for converted interfaces (JavaParser prints invalid 'interface ... implements') - NodeSteps.addBuilder: unwrap wildcard element types in list-append methods - NodeSteps.addWiths: skip constant fields when building withXyz constructors - NodeSteps.addHashCode: emit 'return 0;' for classes without non-@EQEX fields - PostSteps visitors: correct generic accept helpers, generate only builder fields (skip @internal hashCode and leaf types), use ImmutableList.collector instead of removed RoList.collector Support: MatchHelper gets a generic Object fallback overload so match() type-checks fields of external types (Type, SchemaVariable, ...). Regenerated code in src/generated/java/org/key_project/java/ast/.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related Issue
This PR supersedes/continues the discussion from the KaKeY meeting on writing
KeY-Java-AST. No dedicated issue; tracking happens in this PR.
Intended Change
Writing the KeY Java AST by hand is tedious and error-prone (
ExtList/ImmutableArrayplumbing,
equals+hashCode+computeHashCodefor every node). This PR generates theAST node classes and the necessary visitor infrastructure from a single, small metamodel file
using JavaParser.
key.ncore.java(settings.gradle: include 'key.ncore.java'):src/adt/java-ast.java— the metamodel (declared style, ~180 types; imports referenceexisting KeY types like
KeyType,SchemaVariable, ...)src/generator/java/org/key_project/ncore/java/— the generator (5 files:Generator,PreSteps,NodeSteps,PostSteps,ReadAllHierarchy) and arunGeneratorGradle task that regenerates the ASTsrc/generated/java/org/key_project/java/ast/— the generated output (AST nodes,visitorpackage withVisitor/ArgVisitor/VoidVisitor/CopyVisitor/CopyOnWriteVisitor)src/main/java/org/key_project/java/ast/— small hand-written support types(
Matchable,Visitable,MatchHelper,Root,EqEx,Internal, ...)./gradlew :key.ncore.java:classesisBUILD SUCCESSFUL with 0 errors. (This was the current iteration's goal; it replaces
the previous state with ~1250 linker/type errors.)
Java AST features/decisions
String name();ImmutableListfromorg.key_project.util.collection.@Rootnode is the single abstract base classJavaSourceElement(
implements Visitable, Matchable); everything else is a (sealed) interface or aconcrete final class.
sealedfor pattern matching support. Marker types without anymetamodel subtype (e.g.
IGuard,LoopInitializer,IExecutionContext) are generated asplain (non-sealed) interfaces.
node.builder()...build(), pluswithXyzsetters).equals/hashCode/toStringand structuralmatch(...)are generated.Visitor<R>(with return value),VoidVisitor, visitor with default methods,ArgVisitor<R, A>,CopyVisitorandCopyOnWriteVisitor(structural copy,identity-preserving copy-on-write).
implementsclauses on abstract types are preserved (merged into theextendsclause of the generated sealed interfaces, since interfaces cannot haveimplements); concrete classes derive their implemented interfaces from the metamodelhierarchy.
Plan
:key.ncore.java:classes, 0 errors)faithfulness to the hand-written AST, dead code removal
key.ncore.javato the CI test matrix in.github/workflows/tests.ymlde.uka.ilkd.key.java.astusages onto the generated AST (follow-up, e.g. akey.core.javamodule feeding the same metamodel)Type of pull request
Ensuring quality
./gradlew :key.ncore.java:runGeneratorand./gradlew :key.ncore.java:classessucceed; generated code compiles with 0 errors.the generated AST is not yet wired into the prover).
Additional information and contact(s)
This is a DRAFT; the branch is
weigl/javaastgen. The metamodel is the single source oftruth and is also intended to feed the planned
key.core.javamodule (generator + supportclasses get copied there once the ncore variant is stable).
The contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.