fix: faithful ==/nested-arithmetic codegen in scope/export expression translation (follow-up to #1405)#1436
Draft
joaodinissf wants to merge 2 commits into
Draft
Conversation
The com.avaloq.tools.ddk.xtext.scope plugin compiled the embedded Expression DSL to Java through expression.generator.CodeGenerationX / CompilationContext, whose type system is the legacy classic Xtend runtime (org.eclipse.xtend.expression.*, org.eclipse.xtend.typesystem.emf.*). That was the only reason the plugin required those bundles. This PR replaces the IGenerator2-based ScopeGenerator with an Xbase JvmModelInferrer, introduces a self-contained (Xtend-free) expression-translation layer, deletes the classic-Xtend execution context, and removes org.eclipse.xtend and org.eclipse.xtend.typesystem.emf from the scope plugin. Key decisions Scope generation moves to a JvmModelInferrer + Xbase JvmModelGenerator Same pattern as Format/Check; lets the standard XbaseCompiler emit the provider classes. The *ScopeProvider/*ScopeNameProvider are now inferred JVM types rather than hand-templated .java. Hybrid expression backend: an Xbase translator + a string compiler fallback String + concatenation (very common in .scope) has no operator_plus in xbase.lib — Xbase special-cases it in its compiler — so it can't be pre-linked as an XExpression tree. We translate to Xbase what maps cleanly and fall back to a faithful port of the legacy string output for +, arithmetic and relational operators. Model-type names resolve via imported EPackages, not the classpath In real sources, (Cast)x / typeSelect(T) / T.isInstance(x) name EMF model types (FormDef, ILogicalTable, intfdef::AlternatingGroup), not Java FQNs. javaType resolves them through the model's imported EPackages → GenModelUtilX.instanceClassName, exactly as the legacy EmfRegistryMetaModel did. findDeclaredType would fail on these. .ext (JAVA extension) support dropped Scope sources no longer reference Xtend extension files; removed the .ext-reading validation and the isJavaExtensionCall/isExtension generator branches. factory becomes a direct Xbase static call Must be written Type.method(args); the generator resolves the type to a JvmDeclaredType.qualifiedName and emits the static call. Bare factory foo() is no longer supported. Downstream projects need to adapt their .scope/.ext sources.
…rt expression translation Follow-up to dsldevkit#1405 (does NOT touch its commits): restores two behaviours the Xbase migration silently changed in the scope/export expression code generators. 1. ==/!= reference equality. The translator linked == / != to ObjectExtensions.operator_equals/notEquals, which Xbase inlines to Objects.equals(a, b) (null-safe VALUE equality). The legacy generator - and this PR's own string fallback compiler - emit Java reference equality (a == b). Since the inferrer prefers the translated XExpression, the value-equality path won, silently changing cross-reference resolution semantics for EObject operands. Fix: leave == / != untranslated so they fall through to the faithful string compiler (raw a == b). The relational operators < > <= >= were already left untranslated, so this also makes the operator family consistent. 2. Nested arithmetic. isNumber() delegated to resolveType(), which returns null for an OperationCall operand, so a nested arithmetic operand (e.g. the (a + b) in (a + b) * c) was not "numeric"; the outer operator then missed the arithmetic branch and was emitted as operator-as-method, e.g. *(a + b, c) - non-compilable Java. Fix: isNumber() now recognises an arithmetic OperationCall as numeric, restoring (a + b) * c. Applied symmetrically to scope and export; removes the now-unused ObjectExtensions import. A scope.test module with a CodeGenerationXTest-style regression test (re-introducing the coverage dsldevkit#1405 dropped) follows in the next commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Restores two behaviours the Xbase migration (#1405) silently changed in the scope/export expression code generators. Both are latent (no in-repo
.scope/.exportinstance hits them; the only generated providers in the repo are expression-free), which is precisely why CI didn't catch them — #1405 also deletedCodeGenerationXTest, the test that pinned this.==/!=reference equality. The translator linked==/!=toObjectExtensions.operator_equals/notEquals→ Xbase inlines toObjects.equals(a, b)(null-safe value equality). The legacy generator — and this PR's own string fallback compiler — emit Java reference equalitya == b. The inferrer prefers the translatedXExpression, so value-equality won, silently changing cross-reference-resolution semantics forEObjectoperands. Fix: leave==/!=untranslated so they fall to the faithful string compiler (rawa == b). The relational operators< > <= >=were already left untranslated, so this also makes the operator family consistent.Nested arithmetic.
isNumber()delegated toresolveType(), which returnsnullfor anOperationCalloperand, so a nested arithmetic operand (the(a + b)in(a + b) * c) wasn't "numeric"; the outer operator missed the arithmetic branch and emitted operator-as-method —*(a + b, c), non-compilable. Fix:isNumber()now recognises an arithmeticOperationCallas numeric, restoring(a + b) * c.Applied symmetrically to scope and export; removes the now-unused
ObjectExtensionsimport.Evidence
A standalone replica of the compiler's classification/emission confirms the change red→green:
(4 + 2) * 3goes from*(4 + 2, 3)(malformed) →(4 + 2) * 3, and1 == 2emits raw1 == 2. Next commit: a newscope.testmodule with aCodeGenerationXTest-style regression test (re-introducing the coverage #1405 dropped) so this is guarded in CI.🤖 Generated with Claude Code