-package org.simantics.scl.compiler.internal.parsing.translation;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.scl.compiler.elaboration.errors.NotPatternException;\r
-import org.simantics.scl.compiler.elaboration.expressions.EVar;\r
-import org.simantics.scl.compiler.errors.Locations;\r
-import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst;\r
-import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst;\r
-\r
-import gnu.trove.impl.Constants;\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.map.hash.TObjectLongHashMap;\r
-\r
-public class ValueRepository {\r
- THashMap<String, ArrayList<DValueAst>> values = \r
- new THashMap<String, ArrayList<DValueAst>>();\r
- THashMap<String, ArrayList<DAnnotationAst>> annotations = \r
- new THashMap<String, ArrayList<DAnnotationAst>>();\r
- TObjectLongHashMap<String> locations = new TObjectLongHashMap<String>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR,\r
- Locations.NO_LOCATION); \r
- \r
- public String add(DValueAst value) throws NotPatternException {\r
- EVar name = value.lhs.getPatternHead();\r
- ArrayList<DValueAst> vs = values.get(name.name);\r
- if(vs == null) {\r
- vs = new ArrayList<DValueAst>(2);\r
- values.put(name.name, vs);\r
- }\r
- long oldLocation = locations.get(name.name);\r
- if(oldLocation == Locations.NO_LOCATION || name.location < oldLocation)\r
- locations.put(name.name, name.location);\r
- vs.add(value);\r
- return name.name;\r
- }\r
- \r
- public void addDefinitions(String name, ArrayList<DValueAst> valueList) {\r
- ArrayList<DValueAst> vs = values.get(name);\r
- if(vs == null) {\r
- vs = new ArrayList<DValueAst>(valueList.size());\r
- values.put(name, vs);\r
- }\r
- vs.addAll(valueList);\r
- }\r
- \r
- public void addAnnotation(String name, DAnnotationAst annotation) {\r
- ArrayList<DAnnotationAst> as = annotations.get(name);\r
- if(as == null) {\r
- as = new ArrayList<DAnnotationAst>(2);\r
- annotations.put(name, as);\r
- }\r
- as.add(annotation);\r
- }\r
- \r
- public void addAnnotations(String name, ArrayList<DAnnotationAst> annotationList) {\r
- ArrayList<DAnnotationAst> as = annotations.get(name);\r
- if(as == null) {\r
- as = new ArrayList<DAnnotationAst>(annotationList.size());\r
- annotations.put(name, as);\r
- }\r
- as.addAll(annotationList);\r
- }\r
- \r
- public Collection<String> getValueNames() {\r
- return values.keySet();\r
- }\r
-\r
- public ArrayList<DValueAst> getDefinition(String name) {\r
- return values.get(name);\r
- }\r
-\r
- public ArrayList<DAnnotationAst> getAnnotations(String name) {\r
- return annotations.get(name);\r
- }\r
-\r
- public void addFrom(ValueRepository repo, String oldName, String newName) {\r
- addDefinitions(newName, repo.getDefinition(oldName));\r
- \r
- ArrayList<DAnnotationAst> as = repo.getAnnotations(oldName);\r
- if(as != null)\r
- addAnnotations(newName, as);\r
- }\r
-\r
- public long getLocation(String name) {\r
- return locations.get(name);\r
- }\r
-}\r
+package org.simantics.scl.compiler.internal.parsing.translation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
+import org.simantics.scl.compiler.elaboration.expressions.EVar;
+import org.simantics.scl.compiler.errors.Locations;
+import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst;
+import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst;
+
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectLongHashMap;
+import gnu.trove.set.hash.THashSet;
+
+public class ValueRepository {
+ THashMap<String, ArrayList<DValueAst>> values =
+ new THashMap<String, ArrayList<DValueAst>>();
+ THashMap<String, ArrayList<DAnnotationAst>> annotations =
+ new THashMap<String, ArrayList<DAnnotationAst>>();
+ THashSet<String> derived = new THashSet<String>();
+ TObjectLongHashMap<String> locations = new TObjectLongHashMap<String>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR,
+ Locations.NO_LOCATION);
+
+ public String add(DValueAst value) throws NotPatternException {
+ EVar name = value.lhs.getPatternHead();
+ ArrayList<DValueAst> vs = values.get(name.name);
+ if(vs == null) {
+ vs = new ArrayList<DValueAst>(2);
+ values.put(name.name, vs);
+ }
+ long oldLocation = locations.get(name.name);
+ if(oldLocation == Locations.NO_LOCATION || name.location < oldLocation)
+ locations.put(name.name, name.location);
+ vs.add(value);
+ return name.name;
+ }
+
+ public void addDefinitions(String name, ArrayList<DValueAst> valueList) {
+ ArrayList<DValueAst> vs = values.get(name);
+ if(vs == null) {
+ vs = new ArrayList<DValueAst>(valueList.size());
+ values.put(name, vs);
+ }
+ vs.addAll(valueList);
+ }
+
+ public void addAnnotation(String name, DAnnotationAst annotation) {
+ ArrayList<DAnnotationAst> as = annotations.get(name);
+ if(as == null) {
+ as = new ArrayList<DAnnotationAst>(2);
+ annotations.put(name, as);
+ }
+ as.add(annotation);
+ }
+
+ public void addAnnotations(String name, ArrayList<DAnnotationAst> annotationList) {
+ ArrayList<DAnnotationAst> as = annotations.get(name);
+ if(as == null) {
+ as = new ArrayList<DAnnotationAst>(annotationList.size());
+ annotations.put(name, as);
+ }
+ as.addAll(annotationList);
+ }
+
+ public Collection<String> getValueNames() {
+ return values.keySet();
+ }
+
+ public ArrayList<DValueAst> getDefinition(String name) {
+ return values.get(name);
+ }
+
+ public ArrayList<DAnnotationAst> getAnnotations(String name) {
+ return annotations.get(name);
+ }
+
+ public void addFrom(ValueRepository repo, String oldName, String newName) {
+ addDefinitions(newName, repo.getDefinition(oldName));
+
+ ArrayList<DAnnotationAst> as = repo.getAnnotations(oldName);
+ if(as != null)
+ addAnnotations(newName, as);
+ }
+
+ public long getLocation(String name) {
+ return locations.get(name);
+ }
+
+ public boolean isDerived(String name) {
+ return derived.contains(name);
+ }
+
+ public void setDerived(String name) {
+ derived.add(name);
+ }
+}