X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftranslation%2FChildGraphTranslator.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftranslation%2FChildGraphTranslator.java;h=c543aa980658b70dbbdd2299d4e669e896899e9d;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/translation/ChildGraphTranslator.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/translation/ChildGraphTranslator.java new file mode 100644 index 000000000..c543aa980 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/translation/ChildGraphTranslator.java @@ -0,0 +1,35 @@ +package org.simantics.graph.compiler.internal.translation; + +import gnu.trove.list.array.TIntArrayList; + +import org.antlr.runtime.tree.Tree; +import org.simantics.graph.store.GraphStore; + +public class ChildGraphTranslator extends GraphTranslator { + + TIntArrayList correspondences = new TIntArrayList(); + GraphTranslator parent; + + public ChildGraphTranslator(GraphTranslator parent, GraphStore store) { + super(parent.paths, parent.problems, store); + this.parent = parent; + } + + @Override + public int getVariable(Tree place, String text) { + if(variables.containsKey(text)) + return variables.get(text); + else { + correspondences.add(parent.getVariable(place, text)); + int id = identities.newResource(); + correspondences.add(id); + variables.put(text, id); + locate(id, place); + return id; + } + } + + public int[] getCorrespondences() { + return correspondences.toArray(); + } +}