annotate agent/src/share/classes/sun/jvm/hotspot/jdi/SDE.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.io.File;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 class SDE {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private static final int INIT_SIZE_FILE = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final int INIT_SIZE_LINE = 100;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int INIT_SIZE_STRATUM = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 static final String BASE_STRATUM_NAME = "Java";
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 /* for C capatibility */
a61af66fc99e Initial load
duke
parents:
diff changeset
40 static final String NullString = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private class FileTableRecord {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 int fileId;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 String sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 String sourcePath; // do not read - use accessor
a61af66fc99e Initial load
duke
parents:
diff changeset
46 boolean isConverted = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * Return the sourcePath, computing it if not set.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * If set, convert '/' in the sourcePath to the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * local file separator.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 String getSourcePath(ReferenceTypeImpl refType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (!isConverted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if (sourcePath == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 sourcePath = refType.baseSourceDir() + sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 for (int i = 0; i < sourcePath.length(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 char ch = sourcePath.charAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (ch == '/') {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 buf.append(File.separatorChar);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 buf.append(ch);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 sourcePath = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 isConverted = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return sourcePath;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 private class LineTableRecord {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int jplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int jplsEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int jplsLineInc;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 int njplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 int njplsEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int fileId;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 private class StratumTableRecord {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 String id;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int lineIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 class Stratum {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private final int sti; /* stratum index */
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private Stratum(int sti) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 this.sti = sti;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 String id() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return stratumTable[sti].id;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 boolean isJava() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return sti == baseStratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
106 * Return all the sourceNames for this stratum.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 * Look from our starting fileIndex upto the starting
a61af66fc99e Initial load
duke
parents:
diff changeset
108 * fileIndex of next stratum - can do this since there
a61af66fc99e Initial load
duke
parents:
diff changeset
109 * is always a terminator stratum.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 * Default sourceName (the first one) must be first.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 */
a61af66fc99e Initial load
duke
parents:
diff changeset
112 List sourceNames(ReferenceTypeImpl refType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 int fileIndexStart = stratumTable[sti].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 /* one past end */
a61af66fc99e Initial load
duke
parents:
diff changeset
116 int fileIndexEnd = stratumTable[sti+1].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 List result = new ArrayList(fileIndexEnd - fileIndexStart);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 for (i = fileIndexStart; i < fileIndexEnd; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 result.add(fileTable[i].sourceName);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
125 * Return all the sourcePaths for this stratum.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 * Look from our starting fileIndex upto the starting
a61af66fc99e Initial load
duke
parents:
diff changeset
127 * fileIndex of next stratum - can do this since there
a61af66fc99e Initial load
duke
parents:
diff changeset
128 * is always a terminator stratum.
a61af66fc99e Initial load
duke
parents:
diff changeset
129 * Default sourcePath (the first one) must be first.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 */
a61af66fc99e Initial load
duke
parents:
diff changeset
131 List sourcePaths(ReferenceTypeImpl refType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 int fileIndexStart = stratumTable[sti].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 /* one past end */
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int fileIndexEnd = stratumTable[sti+1].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 List result = new ArrayList(fileIndexEnd - fileIndexStart);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 for (i = fileIndexStart; i < fileIndexEnd; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 result.add(fileTable[i].getSourcePath(refType));
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 LineStratum lineStratum(ReferenceTypeImpl refType,
a61af66fc99e Initial load
duke
parents:
diff changeset
144 int jplsLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 int lti = stiLineTableIndex(sti, jplsLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (lti < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return new LineStratum(sti, lti, refType,
a61af66fc99e Initial load
duke
parents:
diff changeset
150 jplsLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 class LineStratum {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 private final int sti; /* stratum index */
a61af66fc99e Initial load
duke
parents:
diff changeset
157 private final int lti; /* line table index */
a61af66fc99e Initial load
duke
parents:
diff changeset
158 private final ReferenceTypeImpl refType;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 private final int jplsLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private String sourceName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 private String sourcePath = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 private LineStratum(int sti, int lti,
a61af66fc99e Initial load
duke
parents:
diff changeset
164 ReferenceTypeImpl refType,
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int jplsLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 this.sti = sti;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 this.lti = lti;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 this.refType = refType;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 this.jplsLine = jplsLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if ((obj != null) && (obj instanceof LineStratum)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 LineStratum other = (LineStratum)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return (lti == other.lti) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
176 (sti == other.sti) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
177 (lineNumber() == other.lineNumber()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
178 (refType.equals(other.refType));
a61af66fc99e Initial load
duke
parents:
diff changeset
179 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 int lineNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return stiLineNumber(sti, lti, jplsLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
189 * Fetch the source name and source path for
a61af66fc99e Initial load
duke
parents:
diff changeset
190 * this line, converting or constructing
a61af66fc99e Initial load
duke
parents:
diff changeset
191 * the source path if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
192 */
a61af66fc99e Initial load
duke
parents:
diff changeset
193 void getSourceInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (sourceName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // already done
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 int fti = stiFileTableIndex(sti, lti);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (fti == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 throw new InternalError(
a61af66fc99e Initial load
duke
parents:
diff changeset
201 "Bad SourceDebugExtension, no matching source id " +
a61af66fc99e Initial load
duke
parents:
diff changeset
202 lineTable[lti].fileId + " jplsLine: " + jplsLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 FileTableRecord ftr = fileTable[fti];
a61af66fc99e Initial load
duke
parents:
diff changeset
205 sourceName = ftr.sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 sourcePath = ftr.getSourcePath(refType);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 String sourceName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 getSourceInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 String sourcePath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 getSourceInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 return sourcePath;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 private FileTableRecord[] fileTable = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 private LineTableRecord[] lineTable = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 private StratumTableRecord[] stratumTable = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 private int fileIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 private int lineIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 private int stratumIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 private int currentFileId = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 private int defaultStratumIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 private int baseStratumIndex = -2; /* so as not to match -1 above */
a61af66fc99e Initial load
duke
parents:
diff changeset
231 private int sdePos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 final String sourceDebugExtension;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 String jplsFilename = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 String defaultStratumId = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 boolean isValid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 SDE(String sourceDebugExtension) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 this.sourceDebugExtension = sourceDebugExtension;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 decode();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 SDE() {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 this.sourceDebugExtension = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 createProxyForAbsentSDE();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 char sdePeek() {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (sdePos >= sourceDebugExtension.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 syntax();
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 return sourceDebugExtension.charAt(sdePos);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 char sdeRead() {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 if (sdePos >= sourceDebugExtension.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 syntax();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 return sourceDebugExtension.charAt(sdePos++);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 void sdeAdvance() {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 sdePos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 void syntax() {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 throw new InternalError("bad SourceDebugExtension syntax - position " +
a61af66fc99e Initial load
duke
parents:
diff changeset
268 sdePos);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void syntax(String msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 throw new InternalError("bad SourceDebugExtension syntax: " + msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 void assureLineTableSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 int len = lineTable == null? 0 : lineTable.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if (lineIndex >= len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 int newLen = len == 0? INIT_SIZE_LINE : len * 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 LineTableRecord[] newTable = new LineTableRecord[newLen];
a61af66fc99e Initial load
duke
parents:
diff changeset
281 for (i = 0; i < len; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 newTable[i] = lineTable[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 for (; i < newLen; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 newTable[i] = new LineTableRecord();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 lineTable = newTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 void assureFileTableSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 int len = fileTable == null? 0 : fileTable.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (fileIndex >= len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 int newLen = len == 0? INIT_SIZE_FILE : len * 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 FileTableRecord[] newTable = new FileTableRecord[newLen];
a61af66fc99e Initial load
duke
parents:
diff changeset
297 for (i = 0; i < len; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 newTable[i] = fileTable[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 for (; i < newLen; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 newTable[i] = new FileTableRecord();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 fileTable = newTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 void assureStratumTableSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 int len = stratumTable == null? 0 : stratumTable.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (stratumIndex >= len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 int newLen = len == 0? INIT_SIZE_STRATUM : len * 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 StratumTableRecord[] newTable = new StratumTableRecord[newLen];
a61af66fc99e Initial load
duke
parents:
diff changeset
313 for (i = 0; i < len; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 newTable[i] = stratumTable[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 for (; i < newLen; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 newTable[i] = new StratumTableRecord();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 stratumTable = newTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 String readLine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 StringBuffer sb = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 char ch;
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 ignoreWhite();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 sb.append((char)ch);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // check for CR LF
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if ((ch == '\r') && (sdePeek() == '\n')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 sdeRead();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 ignoreWhite(); // leading white
a61af66fc99e Initial load
duke
parents:
diff changeset
336 return sb.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 private int defaultStratumTableIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if ((defaultStratumIndex == -1) && (defaultStratumId != null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 defaultStratumIndex =
a61af66fc99e Initial load
duke
parents:
diff changeset
342 stratumTableIndex(defaultStratumId);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return defaultStratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 int stratumTableIndex(String stratumId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (stratumId == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 return defaultStratumTableIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 for (i = 0; i < (stratumIndex-1); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 if (stratumTable[i].id.equals(stratumId)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 return defaultStratumTableIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 Stratum stratum(String stratumID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 int sti = stratumTableIndex(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return new Stratum(sti);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 List availableStrata() {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 List strata = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369 for (int i = 0; i < (stratumIndex-1); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 StratumTableRecord rec = stratumTable[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
371 strata.add(rec.id);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return strata;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 /*****************************
a61af66fc99e Initial load
duke
parents:
diff changeset
377 * below functions/methods are written to compile under either Java or C
a61af66fc99e Initial load
duke
parents:
diff changeset
378 *
a61af66fc99e Initial load
duke
parents:
diff changeset
379 * Needed support functions:
a61af66fc99e Initial load
duke
parents:
diff changeset
380 * sdePeek()
a61af66fc99e Initial load
duke
parents:
diff changeset
381 * sdeRead()
a61af66fc99e Initial load
duke
parents:
diff changeset
382 * sdeAdvance()
a61af66fc99e Initial load
duke
parents:
diff changeset
383 * readLine()
a61af66fc99e Initial load
duke
parents:
diff changeset
384 * assureLineTableSize()
a61af66fc99e Initial load
duke
parents:
diff changeset
385 * assureFileTableSize()
a61af66fc99e Initial load
duke
parents:
diff changeset
386 * assureStratumTableSize()
a61af66fc99e Initial load
duke
parents:
diff changeset
387 * syntax()
a61af66fc99e Initial load
duke
parents:
diff changeset
388 *
a61af66fc99e Initial load
duke
parents:
diff changeset
389 * stratumTableIndex(String)
a61af66fc99e Initial load
duke
parents:
diff changeset
390 *
a61af66fc99e Initial load
duke
parents:
diff changeset
391 * Needed support variables:
a61af66fc99e Initial load
duke
parents:
diff changeset
392 * lineTable
a61af66fc99e Initial load
duke
parents:
diff changeset
393 * lineIndex
a61af66fc99e Initial load
duke
parents:
diff changeset
394 * fileTable
a61af66fc99e Initial load
duke
parents:
diff changeset
395 * fileIndex
a61af66fc99e Initial load
duke
parents:
diff changeset
396 * currentFileId
a61af66fc99e Initial load
duke
parents:
diff changeset
397 *
a61af66fc99e Initial load
duke
parents:
diff changeset
398 * Needed types:
a61af66fc99e Initial load
duke
parents:
diff changeset
399 * String
a61af66fc99e Initial load
duke
parents:
diff changeset
400 *
a61af66fc99e Initial load
duke
parents:
diff changeset
401 * Needed constants:
a61af66fc99e Initial load
duke
parents:
diff changeset
402 * NullString
a61af66fc99e Initial load
duke
parents:
diff changeset
403 */
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 void ignoreWhite() {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 char ch;
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 while (((ch = sdePeek()) == ' ') || (ch == '\t')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 void ignoreLine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 char ch;
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 /* check for CR LF */
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if ((ch == '\r') && (sdePeek() == '\n')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422 ignoreWhite(); /* leading white */
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 int readNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 int value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 char ch;
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 ignoreWhite();
a61af66fc99e Initial load
duke
parents:
diff changeset
430 while (((ch = sdePeek()) >= '0') && (ch <= '9')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
432 value = (value * 10) + ch - '0';
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434 ignoreWhite();
a61af66fc99e Initial load
duke
parents:
diff changeset
435 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 void storeFile(int fileId, String sourceName, String sourcePath) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 assureFileTableSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 fileTable[fileIndex].fileId = fileId;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 fileTable[fileIndex].sourceName = sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 fileTable[fileIndex].sourcePath = sourcePath;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 ++fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 void fileLine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 int hasAbsolute = 0; /* acts as boolean */
a61af66fc99e Initial load
duke
parents:
diff changeset
448 int fileId;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 String sourceName;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 String sourcePath = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 /* is there an absolute filename? */
a61af66fc99e Initial load
duke
parents:
diff changeset
453 if (sdePeek() == '+') {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
455 hasAbsolute = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 fileId = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
458 sourceName = readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if (hasAbsolute == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 sourcePath = readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 storeFile(fileId, sourceName, sourcePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 void storeLine(int jplsStart, int jplsEnd, int jplsLineInc,
a61af66fc99e Initial load
duke
parents:
diff changeset
467 int njplsStart, int njplsEnd, int fileId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 assureLineTableSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 lineTable[lineIndex].jplsStart = jplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
470 lineTable[lineIndex].jplsEnd = jplsEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 lineTable[lineIndex].jplsLineInc = jplsLineInc;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 lineTable[lineIndex].njplsStart = njplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
473 lineTable[lineIndex].njplsEnd = njplsEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 lineTable[lineIndex].fileId = fileId;
a61af66fc99e Initial load
duke
parents:
diff changeset
475 ++lineIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
477
a61af66fc99e Initial load
duke
parents:
diff changeset
478 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
479 * Parse line translation info. Syntax is
a61af66fc99e Initial load
duke
parents:
diff changeset
480 * <NJ-start-line> [ # <file-id> ] [ , <line-count> ] :
a61af66fc99e Initial load
duke
parents:
diff changeset
481 * <J-start-line> [ , <line-increment> ] CR
a61af66fc99e Initial load
duke
parents:
diff changeset
482 */
a61af66fc99e Initial load
duke
parents:
diff changeset
483 void lineLine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 int lineCount = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
485 int lineIncrement = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 int njplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 int jplsStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 njplsStart = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 /* is there a fileID? */
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (sdePeek() == '#') {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
494 currentFileId = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 /* is there a line count? */
a61af66fc99e Initial load
duke
parents:
diff changeset
498 if (sdePeek() == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
499 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
500 lineCount = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 if (sdeRead() != ':') {
a61af66fc99e Initial load
duke
parents:
diff changeset
504 syntax();
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 jplsStart = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (sdePeek() == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 sdeAdvance();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 lineIncrement = readNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
510 }
a61af66fc99e Initial load
duke
parents:
diff changeset
511 ignoreLine(); /* flush the rest */
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 storeLine(jplsStart,
a61af66fc99e Initial load
duke
parents:
diff changeset
514 jplsStart + (lineCount * lineIncrement) -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
515 lineIncrement,
a61af66fc99e Initial load
duke
parents:
diff changeset
516 njplsStart,
a61af66fc99e Initial load
duke
parents:
diff changeset
517 njplsStart + lineCount -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
518 currentFileId);
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
522 * Until the next stratum section, everything after this
a61af66fc99e Initial load
duke
parents:
diff changeset
523 * is in stratumId - so, store the current indicies.
a61af66fc99e Initial load
duke
parents:
diff changeset
524 */
a61af66fc99e Initial load
duke
parents:
diff changeset
525 void storeStratum(String stratumId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 /* remove redundant strata */
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (stratumIndex > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if ((stratumTable[stratumIndex-1].fileIndex
a61af66fc99e Initial load
duke
parents:
diff changeset
529 == fileIndex) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
530 (stratumTable[stratumIndex-1].lineIndex
a61af66fc99e Initial load
duke
parents:
diff changeset
531 == lineIndex)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 /* nothing changed overwrite it */
a61af66fc99e Initial load
duke
parents:
diff changeset
533 --stratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536 /* store the results */
a61af66fc99e Initial load
duke
parents:
diff changeset
537 assureStratumTableSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
538 stratumTable[stratumIndex].id = stratumId;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 stratumTable[stratumIndex].fileIndex = fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 stratumTable[stratumIndex].lineIndex = lineIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 ++stratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 currentFileId = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
546 * The beginning of a stratum's info
a61af66fc99e Initial load
duke
parents:
diff changeset
547 */
a61af66fc99e Initial load
duke
parents:
diff changeset
548 void stratumSection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 storeStratum(readLine());
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 void fileSection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 ignoreLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
554 while (sdePeek() != '*') {
a61af66fc99e Initial load
duke
parents:
diff changeset
555 fileLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557 }
a61af66fc99e Initial load
duke
parents:
diff changeset
558
a61af66fc99e Initial load
duke
parents:
diff changeset
559 void lineSection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 ignoreLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
561 while (sdePeek() != '*') {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 lineLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
567 * Ignore a section we don't know about.
a61af66fc99e Initial load
duke
parents:
diff changeset
568 */
a61af66fc99e Initial load
duke
parents:
diff changeset
569 void ignoreSection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 ignoreLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 while (sdePeek() != '*') {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 ignoreLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
573 }
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
577 * A base "Java" stratum is always available, though
a61af66fc99e Initial load
duke
parents:
diff changeset
578 * it is not in the SourceDebugExtension.
a61af66fc99e Initial load
duke
parents:
diff changeset
579 * Create the base stratum.
a61af66fc99e Initial load
duke
parents:
diff changeset
580 */
a61af66fc99e Initial load
duke
parents:
diff changeset
581 void createJavaStratum() {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 baseStratumIndex = stratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
583 storeStratum(BASE_STRATUM_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
584 storeFile(1, jplsFilename, NullString);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 /* JPL line numbers cannot exceed 65535 */
a61af66fc99e Initial load
duke
parents:
diff changeset
586 storeLine(1, 65536, 1, 1, 65536, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 storeStratum("Aux"); /* in case they don't declare */
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
591 * Decode a SourceDebugExtension which is in SourceMap format.
a61af66fc99e Initial load
duke
parents:
diff changeset
592 * This is the entry point into the recursive descent parser.
a61af66fc99e Initial load
duke
parents:
diff changeset
593 */
a61af66fc99e Initial load
duke
parents:
diff changeset
594 void decode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 /* check for "SMAP" - allow EOF if not ours */
a61af66fc99e Initial load
duke
parents:
diff changeset
596 if ((sourceDebugExtension.length() < 4) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
597 (sdeRead() != 'S') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
598 (sdeRead() != 'M') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
599 (sdeRead() != 'A') ||
a61af66fc99e Initial load
duke
parents:
diff changeset
600 (sdeRead() != 'P')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
601 return; /* not our info */
a61af66fc99e Initial load
duke
parents:
diff changeset
602 }
a61af66fc99e Initial load
duke
parents:
diff changeset
603 ignoreLine(); /* flush the rest */
a61af66fc99e Initial load
duke
parents:
diff changeset
604 jplsFilename = readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
605 defaultStratumId = readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
606 createJavaStratum();
a61af66fc99e Initial load
duke
parents:
diff changeset
607 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 if (sdeRead() != '*') {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 syntax();
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611 switch (sdeRead()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
613 stratumSection();
a61af66fc99e Initial load
duke
parents:
diff changeset
614 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
615 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
616 fileSection();
a61af66fc99e Initial load
duke
parents:
diff changeset
617 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
618 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
619 lineSection();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 case 'E':
a61af66fc99e Initial load
duke
parents:
diff changeset
622 /* set end points */
a61af66fc99e Initial load
duke
parents:
diff changeset
623 storeStratum("*terminator*");
a61af66fc99e Initial load
duke
parents:
diff changeset
624 isValid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
625 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
626 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
627 ignoreSection();
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 void createProxyForAbsentSDE() {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 jplsFilename = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 defaultStratumId = BASE_STRATUM_NAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
635 defaultStratumIndex = stratumIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
636 createJavaStratum();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 storeStratum("*terminator*");
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 /***************** query functions ***********************/
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 private int stiLineTableIndex(int sti, int jplsLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
644 int lineIndexStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
645 int lineIndexEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 lineIndexStart = stratumTable[sti].lineIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 /* one past end */
a61af66fc99e Initial load
duke
parents:
diff changeset
649 lineIndexEnd = stratumTable[sti+1].lineIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 for (i = lineIndexStart; i < lineIndexEnd; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
651 if ((jplsLine >= lineTable[i].jplsStart) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
652 (jplsLine <= lineTable[i].jplsEnd)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
658
a61af66fc99e Initial load
duke
parents:
diff changeset
659 private int stiLineNumber(int sti, int lti, int jplsLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 return lineTable[lti].njplsStart +
a61af66fc99e Initial load
duke
parents:
diff changeset
661 (((jplsLine - lineTable[lti].jplsStart) /
a61af66fc99e Initial load
duke
parents:
diff changeset
662 lineTable[lti].jplsLineInc));
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 private int fileTableIndex(int sti, int fileId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 int fileIndexStart = stratumTable[sti].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 /* one past end */
a61af66fc99e Initial load
duke
parents:
diff changeset
669 int fileIndexEnd = stratumTable[sti+1].fileIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 for (i = fileIndexStart; i < fileIndexEnd; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 if (fileTable[i].fileId == fileId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 private int stiFileTableIndex(int sti, int lti) {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 return fileTableIndex(sti, lineTable[lti].fileId);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 }
a61af66fc99e Initial load
duke
parents:
diff changeset
681
a61af66fc99e Initial load
duke
parents:
diff changeset
682 boolean isValid() {
a61af66fc99e Initial load
duke
parents:
diff changeset
683 return isValid;
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }