1 package org.simantics.scl.compiler.errors;
3 public class Locations {
5 public static final long NO_LOCATION = 0x7fffffff80000000L;
7 public static long location(int begin, int end) {
8 return (((long)begin) << 32) | (((long)end) );
11 public static int beginOf(long location) {
12 return (int)(location >>> 32);
15 public static int endOf(long location) {
19 public static int length(long location) {
20 return endOf(location) - beginOf(location);
24 public static long combine(long a, long b) {
25 return location(Math.min(beginOf(a), beginOf(b)), Math.max(endOf(a), endOf(b)));
28 public static int compare(long a, long b) {
36 public static String annotatate(String annotationBegin, String annotationEnd, String formula, long location) {
37 if(location == NO_LOCATION)
38 return annotationBegin + formula + annotationEnd;
39 int begin = beginOf(location);
40 int end = endOf(location);
41 return formula.substring(0, begin) + annotationBegin + formula.substring(begin, end) + annotationEnd + formula.substring(end);
44 public static long sublocation(long location, int localBegin, int localEnd) {
45 int begin = beginOf(location);
46 int end = endOf(location);
47 if(localEnd > end-begin)
49 return location(begin+localBegin, begin+localEnd);
52 public static String toString(long location) {
53 if(location == NO_LOCATION)
56 return beginOf(location) + "-" + endOf(location);