X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fcontexts%2FTranslationContext.java;h=e0c256599195097c1e0a5d3650334deebebf4265;hb=46fc885dc95c6b0aa3c20f6e2c8379d7f0c4aefa;hp=535cc8c8b6cc1f17311945523447bc2f01c2da3b;hpb=fa65538fcc09cdf6e0db94cc4f88acade5b28b77;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java index 535cc8c8b..e0c256599 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java @@ -76,6 +76,8 @@ public class TranslationContext extends TypeTranslationContext implements Enviro TIntArrayList chrConstraintFrames = new TIntArrayList(); ArrayList chrConstraintEntries = new ArrayList(); + private THashSet expandedFromWildcard; + public CHRRuleset currentRuleset; public ModuleDebugInfo moduleDebugInfo; @@ -141,7 +143,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro variable = new Variable(name); variables.put(name, variable); existentialFrame.variables.add(name); - return new EVariable(variable); + return new EVariable(location, variable); } case '_': { if(name.length()==1) { @@ -192,16 +194,23 @@ public class TranslationContext extends TypeTranslationContext implements Enviro return -1; } + public SCLValue resolveSCLValue(long location, Namespace namespace, String name) throws AmbiguousNameException { + SCLValue value = namespace.getValue(name); + if(value == null) + return null; + String deprecatedDescription = value.isDeprecated(); + if(deprecatedDescription != null) + errorLog.logWarning(location, "Deprecated value " + value.getName().name + "." + (deprecatedDescription.isEmpty() ? "" : " " + deprecatedDescription)); + if(moduleDebugInfo != null) + moduleDebugInfo.symbolReferences.add(new SymbolReference(value.getName(), Name.create(compilationContext.module.getName(), definitionName), location)); + return value; + } + public Expression resolveValue(long location, Namespace namespace, String name) { try { - SCLValue value = namespace.getValue(name); + SCLValue value = resolveSCLValue(location, namespace, name); if(value == null) return null; - String deprecatedDescription = value.isDeprecated(); - if(deprecatedDescription != null) - errorLog.logWarning(location, "Deprecated value " + value.getName().name + "." + (deprecatedDescription.isEmpty() ? "" : " " + deprecatedDescription)); - if(moduleDebugInfo != null) - moduleDebugInfo.symbolReferences.add(new SymbolReference(value.getName(), Name.create(compilationContext.module.getName(), definitionName), location)); return new EConstant(location, value); } catch (AmbiguousNameException e) { if(SCLCompilerConfiguration.ALLOW_OVERLOADING) @@ -288,6 +297,25 @@ public class TranslationContext extends TypeTranslationContext implements Enviro return new EError(location); } + public SCLValue resolveRecordConstructor(long location, String name) throws AmbiguousNameException { + return resolveRecordConstructor(location, getEnvironment().getLocalNamespace(), name, 0); + } + + public SCLValue resolveRecordConstructor(long location, Namespace namespace, String name, int begin) throws AmbiguousNameException { + int end = findSeparator(name, begin); + String part = end == -1 ? (begin == 0 ? name : name.substring(begin)) : name.substring(begin, end); + + if(end != -1 && name.charAt(end) == '.') { + Namespace childNamespace = namespace.getNamespace(part); + if(childNamespace == null) + return null; + else + return resolveRecordConstructor(location, childNamespace, name, end+1); + } + else + return resolveSCLValue(location, namespace, part); + } + private void reportResolveFailure(long location, Namespace namespace, String name) { StringBuilder message = new StringBuilder(); message.append("Couldn't resolve ").append(name).append("."); @@ -401,7 +429,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro chrConstraintFrames.add(chrConstraintEntries.size()); } - public void popCHRConstraintFrame(ArrayList constraints) { + public void popCHRConstraintFrame(CHRRuleset ruleset) { int frame = chrConstraintFrames.removeAt(chrConstraintFrames.size()-1); int i = chrConstraintEntries.size(); while(i > frame) { @@ -413,7 +441,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro else newConstraint = chrConstraints.put(entry.name, entry.constraint); if(newConstraint.implicitlyDeclared) - constraints.add(newConstraint); + ruleset.addConstraint(newConstraint); } } @@ -557,7 +585,29 @@ public class TranslationContext extends TypeTranslationContext implements Enviro return Environments.getRuleset(environment, name); } + /** + * Tells that new existential variables are no longer allowed in this context. + */ public void disallowNewExistentials() { getCurrentExistentialFrame().disallowNewExistentials = true; } + + /** + * Marks that the expression is a result of expanding .. wildcard pattern in records. + */ + public void addExpandedFromWildcard(Expression expression) { + if(expandedFromWildcard == null) + expandedFromWildcard = new THashSet<>(); + expandedFromWildcard.add(expression); + } + + /** + * Asks if the expression is a result of expanding .. wildcard pattern in records. + */ + public boolean isExpandedFromWildcard(Expression expression) { + if(expandedFromWildcard == null) + return false; + else + return expandedFromWildcard.contains(expression); + } }