langtools/src/share/classes/com/sun/tools/javac/jvm/CRTable.java
author ohair
Tue, 25 May 2010 15:54:51 -0700
changeset 5520 86e4b9a9da40
parent 10 06bc494ca11e
child 5847 1908176fd6e3
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     2
 * Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/** This class contains the CharacterRangeTable for some method
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *  and the hashtable for mapping trees or lists of trees to their
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *  ending positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class CRTable
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
implements CRTFlags {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    private final boolean crtDebug = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /** The list of CRTable entries.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    private ListBuffer<CRTEntry> entries = new ListBuffer<CRTEntry>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** The hashtable for source positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    private Map<Object,SourceRange> positions = new HashMap<Object,SourceRange>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** The hashtable for ending positions stored in the parser.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    private Map<JCTree, Integer> endPositions;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /** The tree of the method this table is intended for.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     *  We should traverse this tree to get source ranges.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    JCTree.JCMethodDecl methodTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /** Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    public CRTable(JCTree.JCMethodDecl tree, Map<JCTree, Integer> endPositions) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        this.methodTree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        this.endPositions = endPositions;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /** Create a new CRTEntry and add it to the entries.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     *  @param tree     The tree or the list of trees for which
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     *                  we are storing the code pointers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     *  @param flags    The set of flags designating type of the entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *  @param startPc  The starting code position.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     *  @param endPc    The ending code position.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public void put(Object tree, int flags, int startPc, int endPc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        entries.append(new CRTEntry(tree, flags, startPc, endPc));
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /** Compute source positions and write CRT to the databuf.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     *  @param databuf  The buffer to write bytecodes to.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public int writeCRT(ByteBuffer databuf, Position.LineMap lineMap, Log log) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        int crtEntries = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        // compute source positions for the method
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        new SourceComputer().csp(methodTree);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        for (List<CRTEntry> l = entries.toList(); l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            CRTEntry entry = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            // eliminate entries that do not produce bytecodes:
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            // for example, empty blocks and statements
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            if (entry.startPc == entry.endPc)
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            SourceRange pos = positions.get(entry.tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            assert pos != null : "CRT: tree source positions are undefined";
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            if ((pos.startPos == Position.NOPOS) || (pos.endPos == Position.NOPOS))
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            if (crtDebug) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                System.out.println("Tree: " + entry.tree + ", type:" + getTypes(entry.flags));
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
                System.out.print("Start: pos = " + pos.startPos + ", pc = " + entry.startPc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            // encode startPos into line/column representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            int startPos = encodePosition(pos.startPos, lineMap, log);
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            if (startPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            if (crtDebug) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                System.out.print("End:   pos = " + pos.endPos + ", pc = " + (entry.endPc - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            // encode endPos into line/column representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            int endPos = encodePosition(pos.endPos, lineMap, log);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            if (endPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            // write attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            databuf.appendChar(entry.startPc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            // 'endPc - 1' because endPc actually points to start of the next command
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            databuf.appendChar(entry.endPc - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            databuf.appendInt(startPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            databuf.appendInt(endPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            databuf.appendChar(entry.flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            crtEntries++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        return crtEntries;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /** Return the number of the entries.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public int length() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        return entries.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /** Return string describing flags enabled.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    private String getTypes(int flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        String types = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        if ((flags & CRT_STATEMENT)       != 0) types += " CRT_STATEMENT";
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        if ((flags & CRT_BLOCK)           != 0) types += " CRT_BLOCK";
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        if ((flags & CRT_ASSIGNMENT)      != 0) types += " CRT_ASSIGNMENT";
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        if ((flags & CRT_FLOW_CONTROLLER) != 0) types += " CRT_FLOW_CONTROLLER";
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        if ((flags & CRT_FLOW_TARGET)     != 0) types += " CRT_FLOW_TARGET";
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        if ((flags & CRT_INVOKE)          != 0) types += " CRT_INVOKE";
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        if ((flags & CRT_CREATE)          != 0) types += " CRT_CREATE";
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        if ((flags & CRT_BRANCH_TRUE)     != 0) types += " CRT_BRANCH_TRUE";
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        if ((flags & CRT_BRANCH_FALSE)    != 0) types += " CRT_BRANCH_FALSE";
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /** Source file positions in CRT are integers in the format:
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     *  line-number << LINESHIFT + column-number
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     private int encodePosition(int pos, Position.LineMap lineMap, Log log) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
         int line = lineMap.getLineNumber(pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
         int col = lineMap.getColumnNumber(pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
         int new_pos = Position.encodePosition(line, col);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
         if (crtDebug) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
             System.out.println(", line = " + line + ", column = " + col +
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                                ", new_pos = " + new_pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
         }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
         if (new_pos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
             log.warning(pos, "position.overflow", line);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        return new_pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
 * Traversal methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *  This class contains methods to compute source positions for trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     *  Extends Tree.Visitor to traverse the abstract syntax tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    class SourceComputer extends JCTree.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        /** The result of the tree traversal methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        SourceRange result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        /** Visitor method: compute source positions for a single node.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        public SourceRange csp(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            if (tree == null) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            if (result != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                positions.put(tree, result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        /** Visitor method: compute source positions for a list of nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        public SourceRange csp(List<? extends JCTree> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            if ((trees == null) || !(trees.nonEmpty())) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            SourceRange list_sr = new SourceRange();
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                list_sr.mergeWith(csp(l.head));
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            positions.put(trees, list_sr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
            return list_sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        /**  Visitor method: compute source positions for
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
         *    a list of case blocks of switch statements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        public SourceRange cspCases(List<JCCase> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            if ((trees == null) || !(trees.nonEmpty())) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            SourceRange list_sr = new SourceRange();
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            for (List<JCCase> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                list_sr.mergeWith(csp(l.head));
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            positions.put(trees, list_sr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            return list_sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        /**  Visitor method: compute source positions for
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
         *   a list of catch clauses in try statements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        public SourceRange cspCatchers(List<JCCatch> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            if ((trees == null) || !(trees.nonEmpty())) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            SourceRange list_sr = new SourceRange();
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            for (List<JCCatch> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                list_sr.mergeWith(csp(l.head));
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            positions.put(trees, list_sr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            return list_sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            csp(tree.vartype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            sr.mergeWith(csp(tree.init));
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        public void visitSkip(JCSkip tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            // endPos is the same as startPos for the empty statement
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            SourceRange sr = new SourceRange(startPos(tree), startPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        public void visitBlock(JCBlock tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            csp(tree.stats);    // doesn't compare because block's ending position is defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        public void visitDoLoop(JCDoWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        public void visitWhileLoop(JCWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        public void visitForLoop(JCForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            sr.mergeWith(csp(tree.init));
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            sr.mergeWith(csp(tree.step));
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        public void visitForeachLoop(JCEnhancedForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            sr.mergeWith(csp(tree.var));
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        public void visitLabelled(JCLabeledStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        public void visitSwitch(JCSwitch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            sr.mergeWith(csp(tree.selector));
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            sr.mergeWith(cspCases(tree.cases));
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        public void visitCase(JCCase tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            sr.mergeWith(csp(tree.pat));
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            sr.mergeWith(csp(tree.stats));
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        public void visitSynchronized(JCSynchronized tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            sr.mergeWith(csp(tree.lock));
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        public void visitTry(JCTry tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            sr.mergeWith(cspCatchers(tree.catchers));
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            sr.mergeWith(csp(tree.finalizer));
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        public void visitCatch(JCCatch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            sr.mergeWith(csp(tree.param));
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        public void visitConditional(JCConditional tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            sr.mergeWith(csp(tree.truepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            sr.mergeWith(csp(tree.falsepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        public void visitIf(JCIf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            sr.mergeWith(csp(tree.thenpart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            sr.mergeWith(csp(tree.elsepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        public void visitExec(JCExpressionStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        public void visitBreak(JCBreak tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        public void visitContinue(JCContinue tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        public void visitReturn(JCReturn tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        public void visitThrow(JCThrow tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        public void visitAssert(JCAssert tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
            sr.mergeWith(csp(tree.detail));
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        public void visitApply(JCMethodInvocation tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
            sr.mergeWith(csp(tree.meth));
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            sr.mergeWith(csp(tree.args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        public void visitNewClass(JCNewClass tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            sr.mergeWith(csp(tree.encl));
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            sr.mergeWith(csp(tree.args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            sr.mergeWith(csp(tree.def));
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        public void visitNewArray(JCNewArray tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            sr.mergeWith(csp(tree.elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            sr.mergeWith(csp(tree.dims));
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            sr.mergeWith(csp(tree.elems));
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        public void visitParens(JCParens tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        public void visitAssign(JCAssign tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        public void visitAssignop(JCAssignOp tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        public void visitUnary(JCUnary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            sr.mergeWith(csp(tree.arg));
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        public void visitBinary(JCBinary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        public void visitTypeCast(JCTypeCast tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        public void visitTypeTest(JCInstanceOf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        public void visitIndexed(JCArrayAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            sr.mergeWith(csp(tree.indexed));
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
            sr.mergeWith(csp(tree.index));
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        public void visitSelect(JCFieldAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            sr.mergeWith(csp(tree.selected));
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        public void visitLiteral(JCLiteral tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        public void visitTypeIdent(JCPrimitiveTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        public void visitTypeArray(JCArrayTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
            sr.mergeWith(csp(tree.elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        public void visitTypeApply(JCTypeApply tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            sr.mergeWith(csp(tree.arguments));
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        public void visitTypeParameter(JCTypeParameter tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            sr.mergeWith(csp(tree.bounds));
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        public void visitWildcard(JCWildcard tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        public void visitErroneous(JCErroneous tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            assert false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        /** The start position of given tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        public int startPos(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            if (tree == null) return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            return tree.pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        /** The end position of given tree, if it has
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
         *  defined endpos, NOPOS otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        public int endPos(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            if (tree == null) return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            if (tree.getTag() == JCTree.BLOCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                return ((JCBlock) tree).endpos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            Integer endpos = endPositions.get(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            if (endpos != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                return endpos.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    /** This class contains a CharacterRangeTableEntry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
    static class CRTEntry {
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        /** A tree or a list of trees to obtain source positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        Object tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        /** The flags described in the CharacterRangeTable spec.
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        int flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        /** The starting code position of this entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        int startPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        /** The ending code position of this entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        int endPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        CRTEntry(Object tree, int flags, int startPc, int endPc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            this.tree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            this.flags = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            this.startPc = startPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
            this.endPc = endPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    /** This class contains source positions
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     *  for some tree or list of trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
    static class SourceRange {
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        /** The starting source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        int startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        /** The ending source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        int endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        SourceRange() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            startPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            endPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        SourceRange(int startPos, int endPos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            this.startPos = startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            this.endPos = endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        /** Compare the starting and the ending positions
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
         *  of the source range and combines them assigning
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
         *  the widest range to this.
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        SourceRange mergeWith(SourceRange sr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            if (sr == null) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            if (startPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
                startPos = sr.startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            else if (sr.startPos != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
                startPos = (startPos < sr.startPos ? startPos : sr.startPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            if (endPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                endPos = sr.endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
            else if (sr.endPos != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                endPos = (endPos > sr.endPos ? endPos : sr.endPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
}