/* * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* for C capatibility */ staticfinal String NullString = null;
privatestaticclass FileTableRecord { int fileId;
String sourceName;
String sourcePath; // do not read - use accessor boolean isConverted = false;
/** * Return the sourcePath, computing it if not set. * If set, convert '/' in the sourcePath to the * local file separator.
*/
String getSourcePath(ReferenceTypeImpl refType) { if (!isConverted) { if (sourcePath == null) {
sourcePath = refType.baseSourceDir() + sourceName;
} else {
StringBuilder sb = new StringBuilder(); for (int i = 0; i < sourcePath.length(); ++i) { char ch = sourcePath.charAt(i); if (ch == '/') {
sb.append(File.separatorChar);
} else {
sb.append(ch);
}
}
sourcePath = sb.toString();
}
isConverted = true;
} return sourcePath;
}
}
privatestaticclass LineTableRecord { int jplsStart; int jplsEnd; int jplsLineInc; int njplsStart;
@SuppressWarnings("unused") int njplsEnd; int fileId;
}
privatestaticclass StratumTableRecord {
String id; int fileIndex; int lineIndex;
}
class Stratum { privatefinalint sti; /* stratum index */
private Stratum(int sti) { this.sti = sti;
}
String id() { return stratumTable[sti].id;
}
boolean isJava() { return sti == baseStratumIndex;
}
/** * Return all the sourceNames for this stratum. * Look from our starting fileIndex up to the starting * fileIndex of next stratum - can do this since there * is always a terminator stratum. * Default sourceName (the first one) must be first.
*/
List<String> sourceNames(ReferenceTypeImpl refType) { int i; int fileIndexStart = stratumTable[sti].fileIndex; /* one past end */ int fileIndexEnd = stratumTable[sti+1].fileIndex;
List<String> result = new ArrayList<>(fileIndexEnd - fileIndexStart); for (i = fileIndexStart; i < fileIndexEnd; ++i) {
result.add(fileTable[i].sourceName);
} return result;
}
/** * Return all the sourcePaths for this stratum. * Look from our starting fileIndex up to the starting * fileIndex of next stratum - can do this since there * is always a terminator stratum. * Default sourcePath (the first one) must be first.
*/
List<String> sourcePaths(ReferenceTypeImpl refType) { int i; int fileIndexStart = stratumTable[sti].fileIndex; /* one past end */ int fileIndexEnd = stratumTable[sti+1].fileIndex;
List<String> result = new ArrayList<>(fileIndexEnd - fileIndexStart); for (i = fileIndexStart; i < fileIndexEnd; ++i) {
result.add(fileTable[i].getSourcePath(refType));
} return result;
}
LineStratum lineStratum(ReferenceTypeImpl refType, int jplsLine) { int lti = stiLineTableIndex(sti, jplsLine); if (lti < 0) { returnnull;
} else { returnnew LineStratum(sti, lti, refType,
jplsLine);
}
}
}
class LineStratum { privatefinalint sti; /* stratum index */ privatefinalint lti; /* line table index */ privatefinal ReferenceTypeImpl refType; privatefinalint jplsLine; private String sourceName = null; private String sourcePath = null;
void assureLineTableSize() { int len = lineTable == null? 0 : lineTable.length; if (lineIndex >= len) { int i; int newLen = len == 0? INIT_SIZE_LINE : len * 2;
LineTableRecord[] newTable = new LineTableRecord[newLen]; for (i = 0; i < len; ++i) {
newTable[i] = lineTable[i];
} for (; i < newLen; ++i) {
newTable[i] = new LineTableRecord();
}
lineTable = newTable;
}
}
void assureFileTableSize() { int len = fileTable == null? 0 : fileTable.length; if (fileIndex >= len) { int i; int newLen = len == 0? INIT_SIZE_FILE : len * 2;
FileTableRecord[] newTable = new FileTableRecord[newLen]; for (i = 0; i < len; ++i) {
newTable[i] = fileTable[i];
} for (; i < newLen; ++i) {
newTable[i] = new FileTableRecord();
}
fileTable = newTable;
}
}
void assureStratumTableSize() { int len = stratumTable == null? 0 : stratumTable.length; if (stratumIndex >= len) { int i; int newLen = len == 0? INIT_SIZE_STRATUM : len * 2;
StratumTableRecord[] newTable = new StratumTableRecord[newLen]; for (i = 0; i < len; ++i) {
newTable[i] = stratumTable[i];
} for (; i < newLen; ++i) {
newTable[i] = new StratumTableRecord();
}
stratumTable = newTable;
}
}
String readLine() {
StringBuilder sb = new StringBuilder(); char ch;
ignoreWhite(); while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
sb.append(ch);
} // check for CR LF if ((ch == '\r') && (sdePeek() == '\n')) {
sdeRead();
}
ignoreWhite(); // leading white return sb.toString();
}
/** * Until the next stratum section, everything after this * is in stratumId - so, store the current indices.
*/ void storeStratum(String stratumId) { /* remove redundant strata */ if (stratumIndex > 0) { if ((stratumTable[stratumIndex-1].fileIndex
== fileIndex) &&
(stratumTable[stratumIndex-1].lineIndex
== lineIndex)) { /* nothing changed overwrite it */
--stratumIndex;
}
} /* store the results */
assureStratumTableSize();
stratumTable[stratumIndex].id = stratumId;
stratumTable[stratumIndex].fileIndex = fileIndex;
stratumTable[stratumIndex].lineIndex = lineIndex;
++stratumIndex;
currentFileId = 0;
}
/** * The beginning of a stratum's info
*/ void stratumSection() {
storeStratum(readLine());
}
/** * Ignore a section we don't know about.
*/ void ignoreSection() {
ignoreLine(); while (sdePeek() != '*') {
ignoreLine();
}
}
/** * A base "Java" stratum is always available, though * it is not in the SourceDebugExtension. * Create the base stratum.
*/ void createJavaStratum() {
baseStratumIndex = stratumIndex;
storeStratum(BASE_STRATUM_NAME);
storeFile(1, jplsFilename, NullString); /* JPL line numbers cannot exceed 65535 */
storeLine(1, 65536, 1, 1, 65536, 1);
storeStratum("Aux"); /* in case they don't declare */
}
/** * Decode a SourceDebugExtension which is in SourceMap format. * This is the entry point into the recursive descent parser.
*/ void decode() { /* check for "SMAP" - allow EOF if not ours */ if ((sourceDebugExtension.length() < 4) ||
(sdeRead() != 'S') ||
(sdeRead() != 'M') ||
(sdeRead() != 'A') ||
(sdeRead() != 'P')) { return; /* not our info */
}
ignoreLine(); /* flush the rest */
jplsFilename = readLine();
defaultStratumId = readLine();
createJavaStratum(); while (true) { if (sdeRead() != '*') {
syntax();
} switch (sdeRead()) { case'S':
stratumSection(); break; case'F':
fileSection(); break; case'L':
lineSection(); break; case'E': /* set end points */
storeStratum("*terminator*");
isValid = true; return; default:
ignoreSection();
}
}
}
privateint stiLineTableIndex(int sti, int jplsLine) { int i; int lineIndexStart; int lineIndexEnd;
lineIndexStart = stratumTable[sti].lineIndex; /* one past end */
lineIndexEnd = stratumTable[sti+1].lineIndex; for (i = lineIndexStart; i < lineIndexEnd; ++i) { if ((jplsLine >= lineTable[i].jplsStart) &&
(jplsLine <= lineTable[i].jplsEnd)) { return i;
}
} return -1;
}
privateint stiLineNumber(int sti, int lti, int jplsLine) { return lineTable[lti].njplsStart +
(((jplsLine - lineTable[lti].jplsStart) /
lineTable[lti].jplsLineInc));
}
privateint fileTableIndex(int sti, int fileId) { int i; int fileIndexStart = stratumTable[sti].fileIndex; /* one past end */ int fileIndexEnd = stratumTable[sti+1].fileIndex; for (i = fileIndexStart; i < fileIndexEnd; ++i) { if (fileTable[i].fileId == fileId) { return i;
}
} return -1;
}
privateint stiFileTableIndex(int sti, int lti) { return fileTableIndex(sti, lineTable[lti].fileId);
}
boolean isValid() { return isValid;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.