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=b533e922d252d0bcd73c07324564b9e3cde8236a;hb=e83a15c556c27b56e856dc26fa4e2d792cf959be;hp=75090ae3833f9f07c2643874bf95fdc9c6bd41c2;hpb=9a17c7c202c7104631fa5d899a4583a0cc2ad6ac;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 75090ae38..b533e922d 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 @@ -46,7 +46,15 @@ public class TranslationContext extends TypeTranslationContext implements Enviro public static class ExistentialFrame { THashSet variables = new THashSet(4); ArrayList blanks = new ArrayList(2); - boolean disallowNewExistentials; + public boolean disallowNewExistentials; + + public EVariable createBlank(long location) { + Variable variable = new Variable("_"); + blanks.add(variable); + EVariable result = new EVariable(variable); + result.location = location; + return result; + } } THashMap variables = new THashMap(); @@ -67,6 +75,8 @@ public class TranslationContext extends TypeTranslationContext implements Enviro TIntArrayList chrConstraintFrames = new TIntArrayList(); ArrayList chrConstraintEntries = new ArrayList(); + public CHRRuleset currentRuleset; + static class Entry { String name; Variable variable; @@ -128,14 +138,12 @@ public class TranslationContext extends TypeTranslationContext implements Enviro } case '_': { if(name.length()==1) { - variable = new Variable("_"); ExistentialFrame existentialFrame = getCurrentExistentialFrame(); if(existentialFrame == null || existentialFrame.disallowNewExistentials) { errorLog.log(location, "Blank variables can be used only in queries."); return new EError(location); } - existentialFrame.blanks.add(variable); - return new EVariable(variable); + return existentialFrame.createBlank(location); } break; } @@ -143,7 +151,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro return null; } - private ExistentialFrame getCurrentExistentialFrame() { + public ExistentialFrame getCurrentExistentialFrame() { int size = existentialFrames.size(); if(size == 0) return null; @@ -151,13 +159,16 @@ public class TranslationContext extends TypeTranslationContext implements Enviro return existentialFrames.get(size-1); } - private Expression resolveFieldAccess(Expression base, int pos, String name) { + private Expression resolveFieldAccess(long location, Expression base, int pos, String name) { while(pos != -1) { int p = findSeparator(name, pos+1); + int endPos = p==-1 ? name.length() : p; FieldAccessor accessor = new IdAccessor( name.charAt(pos), - name.substring(pos+1, p==-1 ? name.length() : p-1)); + name.substring(pos+1, endPos)); + accessor.location = Locations.sublocation(location, pos+1, endPos); base = new EFieldAccess(base, accessor); + base.location = Locations.sublocation(location, 0, endPos); pos = p; } return base; @@ -229,7 +240,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro if(begin == 0) { Expression result = resolveLocalVariable(location, part); if(result != null) - return end == -1 ? result : resolveFieldAccess(result, end, name); + return end == -1 ? result : resolveFieldAccess(location, result, end, name); // FIXME.. support for records if(localEnvironment != null) { @@ -260,7 +271,7 @@ public class TranslationContext extends TypeTranslationContext implements Enviro if(result == null) result = resolveValue(location, namespace, part); if(result != null) - return end == -1 ? result : resolveFieldAccess(result, end, name); + return end == -1 ? result : resolveFieldAccess(location, result, end, name); } reportResolveFailure(location, namespace, part); return new EError(location);