]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/translation/ChildGraphTranslator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / translation / ChildGraphTranslator.java
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 (file)
index 0000000..c543aa9
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.graph.compiler.internal.translation;\r
+\r
+import gnu.trove.list.array.TIntArrayList;\r
+\r
+import org.antlr.runtime.tree.Tree;\r
+import org.simantics.graph.store.GraphStore;\r
+\r
+public class ChildGraphTranslator extends GraphTranslator {\r
+\r
+       TIntArrayList correspondences = new TIntArrayList();    \r
+       GraphTranslator parent;\r
+               \r
+       public ChildGraphTranslator(GraphTranslator parent, GraphStore store) {\r
+               super(parent.paths, parent.problems, store);\r
+               this.parent = parent;\r
+       }\r
+\r
+       @Override\r
+       public int getVariable(Tree place, String text) {\r
+               if(variables.containsKey(text))\r
+                       return variables.get(text);\r
+               else {\r
+                       correspondences.add(parent.getVariable(place, text));                   \r
+                       int id = identities.newResource();\r
+                       correspondences.add(id);\r
+                       variables.put(text, id);                \r
+                       locate(id, place);\r
+                       return id;\r
+               }\r
+       }       \r
+       \r
+       public int[] getCorrespondences() {\r
+               return correspondences.toArray();\r
+       }\r
+}\r