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%2Ferrors%2FLocations.java;h=3a77cf3250d7c1f58bd17c2e2fcbd8ac164bb9db;hp=d22a69442625708d37b98e13f204574ef0666522;hb=d8e51c3b7d55403115dc83d0a9b2337378e91fb8;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java index d22a69442..3a77cf325 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java @@ -1,43 +1,51 @@ -package org.simantics.scl.compiler.errors; - -public class Locations { - - public static final long NO_LOCATION = 0x7fffffff80000000L; - - public static long location(int begin, int end) { - return (((long)begin) << 32) | (((long)end) ); - } - - public static int beginOf(long location) { - return (int)(location >>> 32); - } - - public static int endOf(long location) { - return (int)location; - } - - public static int length(long location) { - return endOf(location) - beginOf(location); - } - - - public static long combine(long a, long b) { - return location(Math.min(beginOf(a), beginOf(b)), Math.max(endOf(a), endOf(b))); - } - - public static int compare(long a, long b) { - if(a < b) - return -1; - if(a > b) - return 1; - return 0; - } - - public static String annotatate(String annotationBegin, String annotationEnd, String formula, long location) { - if(location == NO_LOCATION) - return annotationBegin + formula + annotationEnd; - int begin = beginOf(location); - int end = endOf(location); - return formula.substring(0, begin) + annotationBegin + formula.substring(begin, end) + annotationEnd + formula.substring(end); - } -} +package org.simantics.scl.compiler.errors; + +public class Locations { + + public static final long NO_LOCATION = 0x7fffffff80000000L; + + public static long location(int begin, int end) { + return (((long)begin) << 32) | (((long)end) ); + } + + public static int beginOf(long location) { + return (int)(location >>> 32); + } + + public static int endOf(long location) { + return (int)location; + } + + public static int length(long location) { + return endOf(location) - beginOf(location); + } + + + public static long combine(long a, long b) { + return location(Math.min(beginOf(a), beginOf(b)), Math.max(endOf(a), endOf(b))); + } + + public static int compare(long a, long b) { + if(a < b) + return -1; + if(a > b) + return 1; + return 0; + } + + public static String annotatate(String annotationBegin, String annotationEnd, String formula, long location) { + if(location == NO_LOCATION) + return annotationBegin + formula + annotationEnd; + int begin = beginOf(location); + int end = endOf(location); + return formula.substring(0, begin) + annotationBegin + formula.substring(begin, end) + annotationEnd + formula.substring(end); + } + + public static long sublocation(long location, int localBegin, int localEnd) { + int begin = beginOf(location); + int end = endOf(location); + if(localEnd > end-begin) + localEnd = begin-end; + return location(begin+localBegin, begin+localEnd); + } +}