changeset 19688:33bdafbf285d

Truffle: SourceSection can now produce the line/column coordinates of its final character
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 03 Mar 2015 17:11:46 -0800
parents 787b5aa53401
children 9d2ff2e8360d
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java
diffstat 3 files changed, 32 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java	Tue Mar 03 16:54:43 2015 -0800
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java	Tue Mar 03 17:11:46 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -73,6 +73,14 @@
         throw new UnsupportedOperationException(this.toString());
     }
 
+    public int getEndLine() {
+        throw new UnsupportedOperationException(this.toString());
+    }
+
+    public int getEndColumn() {
+        throw new UnsupportedOperationException(this.toString());
+    }
+
     public final int getCharIndex() {
         throw new UnsupportedOperationException(this.toString());
     }
@@ -101,5 +109,4 @@
     public String toString() {
         return getShortDescription();
     }
-
 }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Tue Mar 03 16:54:43 2015 -0800
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Tue Mar 03 17:11:46 2015 -0800
@@ -851,6 +851,14 @@
             return startColumn;
         }
 
+        public int getEndLine() {
+            return source.getLineNumber(charIndex + charLength - 1);
+        }
+
+        public int getEndColumn() {
+            return source.getColumnNumber(charIndex + charLength - 1);
+        }
+
         @Override
         public int getCharIndex() {
             return charIndex;
@@ -939,7 +947,6 @@
             }
             return true;
         }
-
     }
 
     private static final class LineLocationImpl implements LineLocation {
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java	Tue Mar 03 16:54:43 2015 -0800
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java	Tue Mar 03 17:11:46 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -66,6 +66,20 @@
     int getStartColumn();
 
     /**
+     * Returns 1-based line number of the last character in this section (inclusive).
+     *
+     * @return the starting line number
+     */
+    int getEndLine();
+
+    /**
+     * Returns the 1-based column number of the last character in this section (inclusive).
+     *
+     * @return the starting column number
+     */
+    int getEndColumn();
+
+    /**
      * Returns the 0-based index of the first character in this section.
      *
      * @return the starting character index