1 package org.simantics.scl.compiler.internal.parsing.translation;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
6 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
\r
7 import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst;
\r
8 import org.simantics.scl.compiler.internal.parsing.declarations.DRelationAst;
\r
10 import gnu.trove.map.hash.THashMap;
\r
12 public class RelationRepository {
\r
13 THashMap<String, ArrayList<DRelationAst>> relations =
\r
14 new THashMap<String, ArrayList<DRelationAst>>();
\r
15 THashMap<String, ArrayList<DAnnotationAst>> annotations =
\r
16 new THashMap<String, ArrayList<DAnnotationAst>>();
\r
18 public String add(DRelationAst relation) throws NotPatternException {
\r
19 String name = relation.lhs.getPatternHead().name;
\r
20 ArrayList<DRelationAst> vs = relations.get(name);
\r
22 vs = new ArrayList<DRelationAst>(2);
\r
23 relations.put(name, vs);
\r
29 public void addDefinitions(String name, ArrayList<DRelationAst> relationList) {
\r
30 ArrayList<DRelationAst> vs = relations.get(name);
\r
32 vs = new ArrayList<DRelationAst>(relationList.size());
\r
33 relations.put(name, vs);
\r
35 vs.addAll(relationList);
\r
38 public void addAnnotation(String name, DAnnotationAst annotation) {
\r
39 ArrayList<DAnnotationAst> as = annotations.get(name);
\r
41 as = new ArrayList<DAnnotationAst>(2);
\r
42 annotations.put(name, as);
\r
47 public void addAnnotations(String name, ArrayList<DAnnotationAst> annotationList) {
\r
48 ArrayList<DAnnotationAst> as = annotations.get(name);
\r
50 as = new ArrayList<DAnnotationAst>(annotationList.size());
\r
51 annotations.put(name, as);
\r
53 as.addAll(annotationList);
\r
56 public Collection<String> getRelationNames() {
\r
57 return relations.keySet();
\r
60 public ArrayList<DRelationAst> getDefinition(String name) {
\r
61 return relations.get(name);
\r
64 public ArrayList<DAnnotationAst> getAnnotations(String name) {
\r
65 return annotations.get(name);
\r
68 public void addFrom(RelationRepository repo, String oldName, String newName) {
\r
69 addDefinitions(newName, repo.getDefinition(oldName));
\r
71 ArrayList<DAnnotationAst> as = repo.getAnnotations(oldName);
\r
73 addAnnotations(newName, as);
\r