Mercurial > hg > truffle
annotate graal/com.oracle.graal.phases/src/com/oracle/graal/phases/LazyName.java @ 18408:2c3666f44855
Truffle: initial commit of object API implementation
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 18 Nov 2014 23:19:43 +0100 |
parents | f3510d0dcf67 |
children | b1530a6cce8c |
rev | line source |
---|---|
14586
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.phases; |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.graal.debug.*; |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 /** |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 * A name whose {@link String} value is computed only when it is needed. This is useful in |
14624
f3510d0dcf67
removed use of varargs from Debug.scope() API
Doug Simon <doug.simon@oracle.com>
parents:
14586
diff
changeset
|
29 * combination with debugging facilities such as {@link Debug#scope(Object)} where the |
f3510d0dcf67
removed use of varargs from Debug.scope() API
Doug Simon <doug.simon@oracle.com>
parents:
14586
diff
changeset
|
30 * {@link String} value of a name is only needed if debugging is enabled. |
14586
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 */ |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 public abstract class LazyName implements CharSequence { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 private String value; |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 public int length() { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 return toString().length(); |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 public char charAt(int index) { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 return toString().charAt(index); |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 public CharSequence subSequence(int start, int end) { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 return toString().subSequence(start, end); |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 @Override |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 public final String toString() { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 if (value == null) { |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 value = createString(); |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 return value; |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 /** |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 * Creates the {@link String} value of this name. |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 */ |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 protected abstract String createString(); |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 } |