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