X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fparsing%2Ftranslation%2FValueRepository.java;h=a0d5702222c5a157eb10a49169872f8f18ff7b08;hp=45e8057614f26cd40fc2ebd627205638ea567d72;hb=fad36d463b75c3a9944d875fc627c3533f6da74d;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java index 45e805761..a0d570222 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/translation/ValueRepository.java @@ -1,88 +1,98 @@ -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; - -public class ValueRepository { - THashMap> values = - new THashMap>(); - THashMap> annotations = - new THashMap>(); - TObjectLongHashMap locations = new TObjectLongHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, - Locations.NO_LOCATION); - - public String add(DValueAst value) throws NotPatternException { - EVar name = value.lhs.getPatternHead(); - ArrayList vs = values.get(name.name); - if(vs == null) { - vs = new ArrayList(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 valueList) { - ArrayList vs = values.get(name); - if(vs == null) { - vs = new ArrayList(valueList.size()); - values.put(name, vs); - } - vs.addAll(valueList); - } - - public void addAnnotation(String name, DAnnotationAst annotation) { - ArrayList as = annotations.get(name); - if(as == null) { - as = new ArrayList(2); - annotations.put(name, as); - } - as.add(annotation); - } - - public void addAnnotations(String name, ArrayList annotationList) { - ArrayList as = annotations.get(name); - if(as == null) { - as = new ArrayList(annotationList.size()); - annotations.put(name, as); - } - as.addAll(annotationList); - } - - public Collection getValueNames() { - return values.keySet(); - } - - public ArrayList getDefinition(String name) { - return values.get(name); - } - - public ArrayList getAnnotations(String name) { - return annotations.get(name); - } - - public void addFrom(ValueRepository repo, String oldName, String newName) { - addDefinitions(newName, repo.getDefinition(oldName)); - - ArrayList as = repo.getAnnotations(oldName); - if(as != null) - addAnnotations(newName, as); - } - - public long getLocation(String name) { - return locations.get(name); - } -} +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> values = + new THashMap>(); + THashMap> annotations = + new THashMap>(); + THashSet derived = new THashSet(); + TObjectLongHashMap locations = new TObjectLongHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, + Locations.NO_LOCATION); + + public String add(DValueAst value) throws NotPatternException { + EVar name = value.lhs.getPatternHead(); + ArrayList vs = values.get(name.name); + if(vs == null) { + vs = new ArrayList(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 valueList) { + ArrayList vs = values.get(name); + if(vs == null) { + vs = new ArrayList(valueList.size()); + values.put(name, vs); + } + vs.addAll(valueList); + } + + public void addAnnotation(String name, DAnnotationAst annotation) { + ArrayList as = annotations.get(name); + if(as == null) { + as = new ArrayList(2); + annotations.put(name, as); + } + as.add(annotation); + } + + public void addAnnotations(String name, ArrayList annotationList) { + ArrayList as = annotations.get(name); + if(as == null) { + as = new ArrayList(annotationList.size()); + annotations.put(name, as); + } + as.addAll(annotationList); + } + + public Collection getValueNames() { + return values.keySet(); + } + + public ArrayList getDefinition(String name) { + return values.get(name); + } + + public ArrayList getAnnotations(String name) { + return annotations.get(name); + } + + public void addFrom(ValueRepository repo, String oldName, String newName) { + addDefinitions(newName, repo.getDefinition(oldName)); + + ArrayList 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); + } +}