diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java')
-rw-r--r-- | subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java deleted file mode 100644 index dc288ba0..00000000 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Zoltan Ujhelyi, Istvan Rath and Daniel Varro | ||
3 | * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/> | ||
4 | * This program and the accompanying materials are made available under the | ||
5 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
6 | * http://www.eclipse.org/legal/epl-v20.html. | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.store.query.viatra.internal.pquery.rewriter; | ||
10 | |||
11 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | ||
12 | import org.eclipse.viatra.query.runtime.matchers.context.surrogate.SurrogateQueryRegistry; | ||
13 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
14 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyCopier; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PDisjunctionRewriter; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
23 | |||
24 | import java.util.LinkedHashSet; | ||
25 | import java.util.Set; | ||
26 | |||
27 | public class RefinerySurrogateQueryRewriter extends PDisjunctionRewriter { | ||
28 | @Override | ||
29 | public PDisjunction rewrite(PDisjunction disjunction) { | ||
30 | Set<PBody> replacedBodies = new LinkedHashSet<>(); | ||
31 | for (PBody body : disjunction.getBodies()) { | ||
32 | PBodyCopier copier = new RefineryPBodyCopier(body, getTraceCollector()) { | ||
33 | |||
34 | @Override | ||
35 | protected void copyTypeConstraint(TypeConstraint typeConstraint) { | ||
36 | PVariable[] mappedVariables = extractMappedVariables(typeConstraint); | ||
37 | Tuple variablesTuple = Tuples.flatTupleOf((Object[]) mappedVariables); | ||
38 | final IInputKey supplierKey = typeConstraint.getSupplierKey(); | ||
39 | if (SurrogateQueryRegistry.instance().hasSurrogateQueryFQN(supplierKey)) { | ||
40 | PQuery surrogateQuery = SurrogateQueryRegistry.instance().getSurrogateQuery(supplierKey); | ||
41 | if (surrogateQuery == null) { | ||
42 | throw new IllegalStateException("Surrogate query for feature %s not found" | ||
43 | .formatted(supplierKey.getPrettyPrintableName())); | ||
44 | } | ||
45 | addTrace(typeConstraint, new PositivePatternCall(getCopiedBody(), variablesTuple, | ||
46 | surrogateQuery)); | ||
47 | } else { | ||
48 | addTrace(typeConstraint, new TypeConstraint(getCopiedBody(), variablesTuple, supplierKey)); | ||
49 | } | ||
50 | } | ||
51 | }; | ||
52 | PBody modifiedBody = copier.getCopiedBody(); | ||
53 | replacedBodies.add(modifiedBody); | ||
54 | modifiedBody.setStatus(PQuery.PQueryStatus.OK); | ||
55 | } | ||
56 | return new PDisjunction(replacedBodies); | ||
57 | } | ||
58 | } | ||