comparison truffle/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/SlowPathEvent.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/SlowPathEvent.java@e8d2f3f95dcd
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2014, 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.dsl.internal;
26
27 import com.oracle.truffle.api.frame.*;
28 import com.oracle.truffle.api.nodes.*;
29
30 /**
31 * Lazy rewrite event that implements {@link CharSequence} to be provided as message in
32 * {@link Node#replace(Node, CharSequence)}.
33 */
34 abstract class SlowPathEvent implements CharSequence {
35
36 protected final SpecializationNode source;
37 protected final String reason;
38 protected final Frame frame;
39 private String message;
40
41 SlowPathEvent(SpecializationNode source, String reason, Frame frame) {
42 this.source = source;
43 this.reason = reason;
44 this.frame = frame;
45 }
46
47 public int length() {
48 return getMessage().length();
49 }
50
51 public char charAt(int index) {
52 return getMessage().charAt(index);
53 }
54
55 public CharSequence subSequence(int start, int end) {
56 return getMessage().subSequence(start, end);
57 }
58
59 @Override
60 public String toString() {
61 return getMessage();
62 }
63
64 private String getMessage() {
65 if (message == null) {
66 message = createMessage();
67 }
68 return message;
69 }
70
71 private String createMessage() {
72 StringBuilder builder = new StringBuilder();
73 builder.append(source);
74 builder.append(" ");
75 builder.append(reason);
76 Object[] values = getValues();
77 if (values.length > 0) {
78 builder.append(" with parameters (");
79 String sep = "";
80 for (Object value : values) {
81 builder.append(sep);
82 if (value == null) {
83 builder.append("null");
84 } else {
85 builder.append(value).append(" (").append(value.getClass().getSimpleName()).append(")");
86 }
87
88 sep = ", ";
89 }
90 builder.append(")");
91 }
92 return builder.toString();
93 }
94
95 public abstract Object[] getValues();
96
97 static class SlowPathEvent0 extends SlowPathEvent {
98
99 private static final Object[] EMPTY = new Object[0];
100
101 public SlowPathEvent0(SpecializationNode source, String reason, Frame frame) {
102 super(source, reason, frame);
103 }
104
105 @Override
106 public final Object[] getValues() {
107 return EMPTY;
108 }
109
110 }
111
112 static class SlowPathEvent1 extends SlowPathEvent {
113
114 protected final Object o1;
115
116 public SlowPathEvent1(SpecializationNode source, String reason, Frame frame, Object o1) {
117 super(source, reason, frame);
118 this.o1 = o1;
119 }
120
121 @Override
122 public final Object[] getValues() {
123 return new Object[]{o1};
124 }
125
126 }
127
128 static class SlowPathEvent2 extends SlowPathEvent {
129
130 protected final Object o1;
131 protected final Object o2;
132
133 public SlowPathEvent2(SpecializationNode source, String reason, Frame frame, Object o1, Object o2) {
134 super(source, reason, frame);
135 this.o1 = o1;
136 this.o2 = o2;
137 }
138
139 @Override
140 public final Object[] getValues() {
141 return new Object[]{o1, o2};
142 }
143
144 }
145
146 static class SlowPathEvent3 extends SlowPathEvent {
147
148 protected final Object o1;
149 protected final Object o2;
150 protected final Object o3;
151
152 public SlowPathEvent3(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3) {
153 super(source, reason, frame);
154 this.o1 = o1;
155 this.o2 = o2;
156 this.o3 = o3;
157 }
158
159 @Override
160 public final Object[] getValues() {
161 return new Object[]{o1, o2, o3};
162 }
163
164 }
165
166 static class SlowPathEvent4 extends SlowPathEvent {
167
168 protected final Object o1;
169 protected final Object o2;
170 protected final Object o3;
171 protected final Object o4;
172
173 public SlowPathEvent4(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) {
174 super(source, reason, frame);
175 this.o1 = o1;
176 this.o2 = o2;
177 this.o3 = o3;
178 this.o4 = o4;
179 }
180
181 @Override
182 public final Object[] getValues() {
183 return new Object[]{o1, o2, o3, o4};
184 }
185
186 }
187
188 static class SlowPathEvent5 extends SlowPathEvent {
189
190 protected final Object o1;
191 protected final Object o2;
192 protected final Object o3;
193 protected final Object o4;
194 protected final Object o5;
195
196 public SlowPathEvent5(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
197 super(source, reason, frame);
198 this.o1 = o1;
199 this.o2 = o2;
200 this.o3 = o3;
201 this.o4 = o4;
202 this.o5 = o5;
203 }
204
205 @Override
206 public final Object[] getValues() {
207 return new Object[]{o1, o2, o3, o4, o5};
208 }
209
210 }
211
212 static class SlowPathEventN extends SlowPathEvent {
213
214 protected final Object[] args;
215
216 public SlowPathEventN(SpecializationNode source, String reason, Frame frame, Object... args) {
217 super(source, reason, frame);
218 this.args = args;
219 }
220
221 @Override
222 public final Object[] getValues() {
223 return args;
224 }
225
226 }
227 }