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