comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Source.java @ 15630:2d63ce48d222

Truffle/Source Attribution: Replace direct creation of SourceSection objects with factory methods on Source; two of these greatly simplify source attribution by automatically computing either the row/column start location from a character offset or vice versa, depending on what?s made available from the parser. Minor API change on Visualizer.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 13 May 2014 18:28:33 -0700
parents c54f5fa05fd5
children ebdeb414d64c
comparison
equal deleted inserted replaced
15606:357e7202de5b 15630:2d63ce48d222
1 /* 1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
23 * questions. 23 * questions.
24 */ 24 */
25 package com.oracle.truffle.api; 25 package com.oracle.truffle.api;
26 26
27 import java.io.*; 27 import java.io.*;
28
29 import com.oracle.truffle.api.source.*;
28 30
29 /** 31 /**
30 * Represents a unit (typically a file) of guest language source code. 32 * Represents a unit (typically a file) of guest language source code.
31 */ 33 */
32 public interface Source { 34 public interface Source {
95 * The number of characters (not counting a possible terminating newline) in a (1-based) 97 * The number of characters (not counting a possible terminating newline) in a (1-based)
96 * numbered line. 98 * numbered line.
97 */ 99 */
98 int getLineLength(int lineNumber); 100 int getLineLength(int lineNumber);
99 101
102 /**
103 * Creates a representation of a contiguous region of text in the source. Computes the
104 * {@code (startLine, startColumn)} values by building a {@linkplain TextMap map} of lines in
105 * the source.
106 * <p>
107 * Checks the position arguments for consistency with the source.
108 * <p>
109 * The resulting representation defines hash/equality around equivalent location, presuming that
110 * {@link Source} representations are cannonical.
111 *
112 *
113 * @param identifier terse description of the region
114 * @param charIndex 0-based position of the first character in the section
115 * @param length the number of characters in the section
116 * @return newly created object representing the specified region
117 * @throws IllegalArgumentException if either of the arguments are outside the text of the
118 * source
119 * @throws IllegalStateException if the source is one of the "null" instances
120 */
121 SourceSection createSection(String identifier, int charIndex, int length) throws IllegalArgumentException, IllegalStateException;
122
123 /**
124 * Creates a representation of a contiguous region of text in the source. Computes the
125 * {@code charIndex} value by building a {@linkplain TextMap map} of lines in the source.
126 * <p>
127 * Checks the position arguments for consistency with the source.
128 * <p>
129 * The resulting representation defines hash/equality around equivalent location, presuming that
130 * {@link Source} representations are cannonical.
131 *
132 * @param identifier terse description of the region
133 * @param startLine 1-based line number of the first character in the section
134 * @param startColumn 1-based column number of the first character in the section
135 * @param length the number of characters in the section
136 * @return newly created object representing the specified region
137 * @throws IllegalArgumentException if arguments are outside the text of the source
138 * @throws IllegalStateException if the source is one of the "null" instances
139 */
140 SourceSection createSection(String identifier, int startLine, int startColumn, int length);
141
142 /**
143 * Creates a representation of a contiguous region of text in the source.
144 * <p>
145 * This method performs no checks on the validity of the arguments.
146 * <p>
147 * The resulting representation defines hash/equality around equivalent location, presuming that
148 * {@link Source} representations are cannonical.
149 *
150 * @param identifier terse description of the region
151 * @param startLine 1-based line number of the first character in the section
152 * @param startColumn 1-based column number of the first character in the section
153 * @param charIndex the 0-based index of the first character of the section
154 * @param length the number of characters in the section
155 * @return newly created object representing the specified region
156 */
157 SourceSection createSection(String identifier, int startLine, int startColumn, int charIndex, int length);
158
100 } 159 }