comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceLineLocation.java @ 13455:69d2e4baa215

Truffle: new infrastructure related to instrumentation, and in particular debugging: support for managing Source objects; framework for generalized "instrumentation proxy nodes" (to be inserted into ASTs with no runtime cost when inactive), and "probes" (which can be attached to proxy nodes to receive event notification); a rudimentary interface and abstract implementation for a "debug manager" (mostly a placeholder at this point); and the beginning of a language-agnostic ExecutionContext interface.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 17 Dec 2013 20:22:45 -0800
parents
children 35f637594acc
comparison
equal deleted inserted replaced
13306:dfb780080923 13455:69d2e4baa215
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.source;
26
27 import com.oracle.truffle.api.*;
28
29 /**
30 * A specification for a location in guest language source, expressed as a line number in a specific
31 * instance of {@link Source}, suitable for hash table keys with equality defined in terms of
32 * content.
33 */
34 public class SourceLineLocation implements Comparable {
35
36 private final Source source;
37 private final int line;
38
39 public SourceLineLocation(Source source, int line) {
40 assert source != null;
41 assert source != SourceSection.NULL;
42 this.source = source;
43 this.line = line;
44 }
45
46 public Source getSource() {
47 return source;
48 }
49
50 public int getLine() {
51 return line;
52 }
53
54 @Override
55 public String toString() {
56 return "SourceLine [" + source.getName() + ", " + line + "]";
57 }
58
59 @Override
60 public int hashCode() {
61 final int prime = 31;
62 int result = 1;
63 result = prime * result + line;
64 result = prime * result + source.hashCode();
65 return result;
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj == null) {
74 return false;
75 }
76 if (!(obj instanceof SourceLineLocation)) {
77 return false;
78 }
79 SourceLineLocation other = (SourceLineLocation) obj;
80 if (line != other.line) {
81 return false;
82 }
83 return source.equals(other.source);
84 }
85
86 @Override
87 public int compareTo(Object o) {
88 final SourceLineLocation other = (SourceLineLocation) o;
89 final int nameOrder = source.getName().compareTo(other.source.getName());
90 if (nameOrder != 0) {
91 return nameOrder;
92 }
93 return Integer.compare(line, other.line);
94 }
95
96 }