diff options
Diffstat (limited to 'subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java')
-rw-r--r-- | subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java | 119 |
1 files changed, 63 insertions, 56 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java index c2bca2a5..ccfb630f 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -8,20 +8,24 @@ package tools.refinery.language.semantics; | |||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import tools.refinery.language.library.BuiltinLibrary; | 9 | import tools.refinery.language.library.BuiltinLibrary; |
10 | import tools.refinery.language.model.problem.*; | 10 | import tools.refinery.language.model.problem.*; |
11 | import tools.refinery.language.scoping.imports.ImportAdapterProvider; | ||
11 | import tools.refinery.language.scoping.imports.ImportCollector; | 12 | import tools.refinery.language.scoping.imports.ImportCollector; |
12 | import tools.refinery.language.semantics.internal.MutableSeed; | 13 | import tools.refinery.language.semantics.internal.MutableSeed; |
13 | import tools.refinery.language.utils.BuiltinSymbols; | 14 | import tools.refinery.language.utils.BuiltinSymbols; |
14 | import tools.refinery.language.utils.ProblemDesugarer; | ||
15 | import tools.refinery.language.utils.ProblemUtil; | 15 | import tools.refinery.language.utils.ProblemUtil; |
16 | import tools.refinery.logic.Constraint; | ||
17 | import tools.refinery.logic.dnf.InvalidClauseException; | ||
18 | import tools.refinery.logic.dnf.Query; | ||
19 | import tools.refinery.logic.dnf.RelationalQuery; | ||
20 | import tools.refinery.logic.literal.*; | ||
21 | import tools.refinery.logic.term.NodeVariable; | ||
22 | import tools.refinery.logic.term.Variable; | ||
23 | import tools.refinery.logic.term.cardinalityinterval.CardinalityInterval; | ||
24 | import tools.refinery.logic.term.cardinalityinterval.CardinalityIntervals; | ||
25 | import tools.refinery.logic.term.truthvalue.TruthValue; | ||
26 | import tools.refinery.logic.term.uppercardinality.UpperCardinalities; | ||
16 | import tools.refinery.store.dse.propagation.PropagationBuilder; | 27 | import tools.refinery.store.dse.propagation.PropagationBuilder; |
17 | import tools.refinery.store.model.ModelStoreBuilder; | 28 | import tools.refinery.store.model.ModelStoreBuilder; |
18 | import tools.refinery.store.query.Constraint; | ||
19 | import tools.refinery.store.query.dnf.InvalidClauseException; | ||
20 | import tools.refinery.store.query.dnf.Query; | ||
21 | import tools.refinery.store.query.dnf.RelationalQuery; | ||
22 | import tools.refinery.store.query.literal.*; | ||
23 | import tools.refinery.store.query.term.NodeVariable; | ||
24 | import tools.refinery.store.query.term.Variable; | ||
25 | import tools.refinery.store.reasoning.ReasoningAdapter; | 29 | import tools.refinery.store.reasoning.ReasoningAdapter; |
26 | import tools.refinery.store.reasoning.representation.PartialRelation; | 30 | import tools.refinery.store.reasoning.representation.PartialRelation; |
27 | import tools.refinery.store.reasoning.scope.ScopePropagator; | 31 | import tools.refinery.store.reasoning.scope.ScopePropagator; |
@@ -29,25 +33,21 @@ import tools.refinery.store.reasoning.seed.ModelSeed; | |||
29 | import tools.refinery.store.reasoning.seed.Seed; | 33 | import tools.refinery.store.reasoning.seed.Seed; |
30 | import tools.refinery.store.reasoning.translator.TranslationException; | 34 | import tools.refinery.store.reasoning.translator.TranslationException; |
31 | import tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator; | 35 | import tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator; |
32 | import tools.refinery.store.reasoning.translator.metamodel.*; | 36 | import tools.refinery.store.reasoning.translator.metamodel.Metamodel; |
37 | import tools.refinery.store.reasoning.translator.metamodel.MetamodelBuilder; | ||
38 | import tools.refinery.store.reasoning.translator.metamodel.MetamodelTranslator; | ||
39 | import tools.refinery.store.reasoning.translator.metamodel.ReferenceInfo; | ||
33 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; | 40 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; |
34 | import tools.refinery.store.reasoning.translator.multiplicity.ConstrainedMultiplicity; | 41 | import tools.refinery.store.reasoning.translator.multiplicity.ConstrainedMultiplicity; |
35 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; | 42 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; |
36 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; | 43 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; |
37 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; | 44 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; |
38 | import tools.refinery.store.representation.TruthValue; | ||
39 | import tools.refinery.store.representation.cardinality.CardinalityInterval; | ||
40 | import tools.refinery.store.representation.cardinality.CardinalityIntervals; | ||
41 | import tools.refinery.store.representation.cardinality.UpperCardinalities; | ||
42 | import tools.refinery.store.tuple.Tuple; | 45 | import tools.refinery.store.tuple.Tuple; |
43 | 46 | ||
44 | import java.util.*; | 47 | import java.util.*; |
45 | 48 | ||
46 | public class ModelInitializer { | 49 | public class ModelInitializer { |
47 | @Inject | 50 | @Inject |
48 | private ProblemDesugarer desugarer; | ||
49 | |||
50 | @Inject | ||
51 | private SemanticsUtils semanticsUtils; | 51 | private SemanticsUtils semanticsUtils; |
52 | 52 | ||
53 | @Inject | 53 | @Inject |
@@ -56,6 +56,9 @@ public class ModelInitializer { | |||
56 | @Inject | 56 | @Inject |
57 | private ImportCollector importCollector; | 57 | private ImportCollector importCollector; |
58 | 58 | ||
59 | @Inject | ||
60 | private ImportAdapterProvider importAdapterProvider; | ||
61 | |||
59 | private Problem problem; | 62 | private Problem problem; |
60 | 63 | ||
61 | private final Set<Problem> importedProblems = new HashSet<>(); | 64 | private final Set<Problem> importedProblems = new HashSet<>(); |
@@ -93,8 +96,7 @@ public class ModelInitializer { | |||
93 | importedProblems.add(problem); | 96 | importedProblems.add(problem); |
94 | problemTrace.setProblem(problem); | 97 | problemTrace.setProblem(problem); |
95 | try { | 98 | try { |
96 | builtinSymbols = desugarer.getBuiltinSymbols(problem).orElseThrow(() -> new IllegalArgumentException( | 99 | builtinSymbols = importAdapterProvider.getBuiltinSymbols(problem); |
97 | "Problem has no builtin library")); | ||
98 | var nodeInfo = collectPartialRelation(builtinSymbols.node(), 1, TruthValue.TRUE, TruthValue.TRUE); | 100 | var nodeInfo = collectPartialRelation(builtinSymbols.node(), 1, TruthValue.TRUE, TruthValue.TRUE); |
99 | nodeRelation = nodeInfo.partialRelation(); | 101 | nodeRelation = nodeInfo.partialRelation(); |
100 | metamodelBuilder.type(nodeRelation); | 102 | metamodelBuilder.type(nodeRelation); |
@@ -202,20 +204,7 @@ public class ModelInitializer { | |||
202 | private void collectNodes() { | 204 | private void collectNodes() { |
203 | for (var importedProblem : importedProblems) { | 205 | for (var importedProblem : importedProblems) { |
204 | for (var statement : importedProblem.getStatements()) { | 206 | for (var statement : importedProblem.getStatements()) { |
205 | if (statement instanceof NodeDeclaration nodeDeclaration) { | 207 | collectNodes(statement); |
206 | for (var node : nodeDeclaration.getNodes()) { | ||
207 | collectNode(node); | ||
208 | } | ||
209 | } else if (statement instanceof ClassDeclaration classDeclaration) { | ||
210 | var newNode = classDeclaration.getNewNode(); | ||
211 | if (newNode != null) { | ||
212 | collectNode(newNode); | ||
213 | } | ||
214 | } else if (statement instanceof EnumDeclaration enumDeclaration) { | ||
215 | for (var literal : enumDeclaration.getLiterals()) { | ||
216 | collectNode(literal); | ||
217 | } | ||
218 | } | ||
219 | } | 208 | } |
220 | } | 209 | } |
221 | for (var node : problem.getNodes()) { | 210 | for (var node : problem.getNodes()) { |
@@ -223,6 +212,23 @@ public class ModelInitializer { | |||
223 | } | 212 | } |
224 | } | 213 | } |
225 | 214 | ||
215 | private void collectNodes(Statement statement) { | ||
216 | if (statement instanceof NodeDeclaration nodeDeclaration) { | ||
217 | for (var node : nodeDeclaration.getNodes()) { | ||
218 | collectNode(node); | ||
219 | } | ||
220 | } else if (statement instanceof ClassDeclaration classDeclaration) { | ||
221 | var newNode = classDeclaration.getNewNode(); | ||
222 | if (newNode != null) { | ||
223 | collectNode(newNode); | ||
224 | } | ||
225 | } else if (statement instanceof EnumDeclaration enumDeclaration) { | ||
226 | for (var literal : enumDeclaration.getLiterals()) { | ||
227 | collectNode(literal); | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | |||
226 | private void collectNode(Node node) { | 232 | private void collectNode(Node node) { |
227 | problemTrace.collectNode(node); | 233 | problemTrace.collectNode(node); |
228 | } | 234 | } |
@@ -243,15 +249,14 @@ public class ModelInitializer { | |||
243 | 249 | ||
244 | private void collectClassDeclarationSymbols(ClassDeclaration classDeclaration) { | 250 | private void collectClassDeclarationSymbols(ClassDeclaration classDeclaration) { |
245 | collectPartialRelation(classDeclaration, 1, null, TruthValue.UNKNOWN); | 251 | collectPartialRelation(classDeclaration, 1, null, TruthValue.UNKNOWN); |
246 | for (var featureDeclaration : classDeclaration.getFeatureDeclarations()) { | 252 | for (var referenceDeclaration : classDeclaration.getFeatureDeclarations()) { |
247 | if (featureDeclaration instanceof ReferenceDeclaration referenceDeclaration) { | 253 | if (referenceDeclaration.getReferenceType() instanceof DatatypeDeclaration) { |
248 | collectPartialRelation(referenceDeclaration, 2, null, TruthValue.UNKNOWN); | 254 | throw new TracedException(referenceDeclaration, "Attributes are not yet supported"); |
249 | var invalidMultiplicityConstraint = referenceDeclaration.getInvalidMultiplicity(); | 255 | } |
250 | if (invalidMultiplicityConstraint != null) { | 256 | collectPartialRelation(referenceDeclaration, 2, null, TruthValue.UNKNOWN); |
251 | collectPartialRelation(invalidMultiplicityConstraint, 1, TruthValue.FALSE, TruthValue.FALSE); | 257 | var invalidMultiplicityConstraint = referenceDeclaration.getInvalidMultiplicity(); |
252 | } | 258 | if (invalidMultiplicityConstraint != null) { |
253 | } else { | 259 | collectPartialRelation(invalidMultiplicityConstraint, 1, TruthValue.FALSE, TruthValue.FALSE); |
254 | throw new TracedException(featureDeclaration, "Unknown feature declaration"); | ||
255 | } | 260 | } |
256 | } | 261 | } |
257 | } | 262 | } |
@@ -319,10 +324,8 @@ public class ModelInitializer { | |||
319 | } catch (RuntimeException e) { | 324 | } catch (RuntimeException e) { |
320 | throw TracedException.addTrace(classDeclaration, e); | 325 | throw TracedException.addTrace(classDeclaration, e); |
321 | } | 326 | } |
322 | for (var featureDeclaration : classDeclaration.getFeatureDeclarations()) { | 327 | for (var referenceDeclaration : classDeclaration.getFeatureDeclarations()) { |
323 | if (featureDeclaration instanceof ReferenceDeclaration referenceDeclaration) { | 328 | collectReferenceDeclarationMetamodel(classDeclaration, referenceDeclaration); |
324 | collectReferenceDeclarationMetamodel(classDeclaration, referenceDeclaration); | ||
325 | } | ||
326 | } | 329 | } |
327 | } | 330 | } |
328 | 331 | ||
@@ -681,8 +684,8 @@ public class ModelInitializer { | |||
681 | var argumentList = toArgumentList(List.of(comparisonExpr.getLeft(), comparisonExpr.getRight()), | 684 | var argumentList = toArgumentList(List.of(comparisonExpr.getLeft(), comparisonExpr.getRight()), |
682 | localScope, literals); | 685 | localScope, literals); |
683 | boolean positive = switch (comparisonExpr.getOp()) { | 686 | boolean positive = switch (comparisonExpr.getOp()) { |
684 | case EQ -> true; | 687 | case NODE_EQ -> true; |
685 | case NOT_EQ -> false; | 688 | case NODE_NOT_EQ -> false; |
686 | default -> throw new TracedException( | 689 | default -> throw new TracedException( |
687 | comparisonExpr, "Unsupported operator"); | 690 | comparisonExpr, "Unsupported operator"); |
688 | }; | 691 | }; |
@@ -726,14 +729,18 @@ public class ModelInitializer { | |||
726 | private void collectScopes() { | 729 | private void collectScopes() { |
727 | for (var importedProblem : importedProblems) { | 730 | for (var importedProblem : importedProblems) { |
728 | for (var statement : importedProblem.getStatements()) { | 731 | for (var statement : importedProblem.getStatements()) { |
729 | if (statement instanceof ScopeDeclaration scopeDeclaration) { | 732 | collectScopes(statement); |
730 | for (var typeScope : scopeDeclaration.getTypeScopes()) { | 733 | } |
731 | if (typeScope.isIncrement()) { | 734 | } |
732 | collectTypeScopeIncrement(typeScope); | 735 | } |
733 | } else { | 736 | |
734 | collectTypeScope(typeScope); | 737 | private void collectScopes(Statement statement) { |
735 | } | 738 | if (statement instanceof ScopeDeclaration scopeDeclaration) { |
736 | } | 739 | for (var typeScope : scopeDeclaration.getTypeScopes()) { |
740 | if (typeScope.isIncrement()) { | ||
741 | collectTypeScopeIncrement(typeScope); | ||
742 | } else { | ||
743 | collectTypeScope(typeScope); | ||
737 | } | 744 | } |
738 | } | 745 | } |
739 | } | 746 | } |