langtools/src/share/classes/com/sun/tools/javac/jvm/CRTable.java
author jjg
Mon, 10 Jan 2011 15:08:31 -0800
changeset 8032 e1aa25ccdabb
parent 7681 1f0819a3341f
child 10950 e87b50888909
permissions -rw-r--r--
6396503: javac should not require assertions enabled Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
     2
 * Copyright (c) 2001, 2011, 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
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    40
 *  If you write code that depends on this, you do so at your own risk.
10
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);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   104
            Assert.checkNonNull(pos, "CRT: tree source positions are undefined");
10
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));
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   328
            sr.mergeWith(csp(tree.resources));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            sr.mergeWith(cspCatchers(tree.catchers));
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            sr.mergeWith(csp(tree.finalizer));
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        public void visitCatch(JCCatch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            sr.mergeWith(csp(tree.param));
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            sr.mergeWith(csp(tree.body));
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        public void visitConditional(JCConditional tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            sr.mergeWith(csp(tree.truepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            sr.mergeWith(csp(tree.falsepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        public void visitIf(JCIf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            sr.mergeWith(csp(tree.thenpart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            sr.mergeWith(csp(tree.elsepart));
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        public void visitExec(JCExpressionStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        public void visitBreak(JCBreak tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        public void visitContinue(JCContinue tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        public void visitReturn(JCReturn tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        public void visitThrow(JCThrow tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        public void visitAssert(JCAssert tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
            sr.mergeWith(csp(tree.cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            sr.mergeWith(csp(tree.detail));
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        public void visitApply(JCMethodInvocation tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            sr.mergeWith(csp(tree.meth));
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            sr.mergeWith(csp(tree.args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        public void visitNewClass(JCNewClass tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            sr.mergeWith(csp(tree.encl));
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            sr.mergeWith(csp(tree.args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            sr.mergeWith(csp(tree.def));
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        public void visitNewArray(JCNewArray tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            sr.mergeWith(csp(tree.elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            sr.mergeWith(csp(tree.dims));
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            sr.mergeWith(csp(tree.elems));
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        public void visitParens(JCParens tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        public void visitAssign(JCAssign tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        public void visitAssignop(JCAssignOp tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        public void visitUnary(JCUnary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
            sr.mergeWith(csp(tree.arg));
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        public void visitBinary(JCBinary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            sr.mergeWith(csp(tree.lhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            sr.mergeWith(csp(tree.rhs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        public void visitTypeCast(JCTypeCast tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        public void visitTypeTest(JCInstanceOf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            sr.mergeWith(csp(tree.expr));
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        public void visitIndexed(JCArrayAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
            sr.mergeWith(csp(tree.indexed));
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
            sr.mergeWith(csp(tree.index));
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        public void visitSelect(JCFieldAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
            sr.mergeWith(csp(tree.selected));
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        public void visitLiteral(JCLiteral tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        public void visitTypeIdent(JCPrimitiveTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        public void visitTypeArray(JCArrayTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
            sr.mergeWith(csp(tree.elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        public void visitTypeApply(JCTypeApply tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            sr.mergeWith(csp(tree.clazz));
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
            sr.mergeWith(csp(tree.arguments));
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        public void visitTypeParameter(JCTypeParameter tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            sr.mergeWith(csp(tree.bounds));
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
            result = sr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        public void visitWildcard(JCWildcard tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        public void visitErroneous(JCErroneous tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        public void visitTree(JCTree tree) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   520
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        /** The start position of given tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        public int startPos(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            if (tree == null) return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            return tree.pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        /** The end position of given tree, if it has
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
         *  defined endpos, NOPOS otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        public int endPos(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            if (tree == null) return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            if (tree.getTag() == JCTree.BLOCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                return ((JCBlock) tree).endpos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            Integer endpos = endPositions.get(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            if (endpos != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                return endpos.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            return Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
    /** This class contains a CharacterRangeTableEntry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
    static class CRTEntry {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        /** A tree or a list of trees to obtain source positions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        Object tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        /** The flags described in the CharacterRangeTable spec.
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        int flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        /** The starting code position of this entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        int startPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        /** The ending code position of this entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        int endPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        CRTEntry(Object tree, int flags, int startPc, int endPc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            this.tree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            this.flags = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
            this.startPc = startPc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            this.endPc = endPc;
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
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
    /** This class contains source positions
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     *  for some tree or list of trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
    static class SourceRange {
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        /** The starting source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        int startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        /** The ending source position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        int endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        SourceRange() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            startPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            endPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        /** Constructor */
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        SourceRange(int startPos, int endPos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            this.startPos = startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            this.endPos = endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        /** Compare the starting and the ending positions
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
         *  of the source range and combines them assigning
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
         *  the widest range to this.
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        SourceRange mergeWith(SourceRange sr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            if (sr == null) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            if (startPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
                startPos = sr.startPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            else if (sr.startPos != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
                startPos = (startPos < sr.startPos ? startPos : sr.startPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            if (endPos == Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                endPos = sr.endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
            else if (sr.endPos != Position.NOPOS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                endPos = (endPos > sr.endPos ? endPos : sr.endPos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
}