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