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%2Felaboration%2Fcontexts%2FTranslationContext.java;h=d8346f41f5e889fbc66437a1f9be10a1a3ad803c;hp=b533e922d252d0bcd73c07324564b9e3cde8236a;hb=f62bab9b78e60b94e055d51db98a03141415323e;hpb=21b02764131815561cb6161837ad47e623b2cd37 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 b533e922d..d8346f41f 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 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; import org.simantics.scl.compiler.common.names.Name; -import org.simantics.scl.compiler.common.names.Names; import org.simantics.scl.compiler.common.precedence.Associativity; import org.simantics.scl.compiler.common.precedence.Precedence; import org.simantics.scl.compiler.compilation.CompilationContext; @@ -33,6 +32,8 @@ import org.simantics.scl.compiler.environment.Namespace; import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst; +import org.simantics.scl.compiler.module.debug.ModuleDebugInfo; +import org.simantics.scl.compiler.module.debug.SymbolReference; import org.simantics.scl.compiler.top.SCLCompilerConfiguration; import org.simantics.scl.compiler.types.Type; @@ -77,6 +78,10 @@ public class TranslationContext extends TypeTranslationContext implements Enviro public CHRRuleset currentRuleset; + public ModuleDebugInfo moduleDebugInfo; + + private String definitionName; + static class Entry { String name; Variable variable; @@ -104,15 +109,17 @@ public class TranslationContext extends TypeTranslationContext implements Enviro } } - public TranslationContext(CompilationContext compilationContext, LocalEnvironment localEnvironment) { + public TranslationContext(CompilationContext compilationContext, LocalEnvironment localEnvironment, String definitionName) { super(compilationContext); this.localEnvironment = localEnvironment; + this.moduleDebugInfo = compilationContext.moduleDebugInfo; + this.definitionName = definitionName; } public static boolean isConstructorName(String name) { int p = name.lastIndexOf('.'); char firstChar = name.charAt(p<0 ? 0 : p+1); - return Character.isUpperCase(firstChar); + return Character.isUpperCase(firstChar) || firstChar == '('; } /* Tries to resolve name as a local variable. It is assumed @@ -185,14 +192,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)); return new EConstant(location, value); } catch (AmbiguousNameException e) { if(SCLCompilerConfiguration.ALLOW_OVERLOADING) @@ -219,6 +235,8 @@ public class TranslationContext extends TypeTranslationContext implements Enviro public Expression realize() { EConstant expression = new EConstant(altValue); expression.location = location; + if(moduleDebugInfo != null) + moduleDebugInfo.symbolReferences.add(new SymbolReference(altValue.getName(), Name.create(compilationContext.module.getName(), definitionName), location)); return expression; } @@ -277,6 +295,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("."); @@ -390,7 +427,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) { @@ -402,7 +439,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); } } @@ -514,13 +551,6 @@ public class TranslationContext extends TypeTranslationContext implements Enviro Locations.combine(definitions.get(0).location, definitions.get(definitions.size()-1).location), cases); } - - public SCLValue getBindFunction() { - if(bindFunction == null) { - bindFunction = getEnvironment().getValue(Names.Prelude_bind); - } - return bindFunction; - } public SCLRelation resolveRelation(long location, String name) { SCLRelation relation = relations.get(name);