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=757aca8b5e272880e7c6526048f1b20837709f82;hb=131be5c413e1f9dc652b6b46c763625b30ad8350;hpb=e3cd3cd49bc2585f57d030a8743f9012f6161a92 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 757aca8b5..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 @@ -192,16 +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)); - 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 +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(".");