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