jaxp/src/com/sun/org/apache/bcel/internal/generic/LocalVariableGen.java
author dfuchs
Fri, 17 May 2013 10:40:21 +0200
changeset 17538 d8d911c4e5d4
parent 12457 c348e06f0e82
permissions -rw-r--r--
8013900: More warnings compiling jaxp. Summary: Some internal implementation classes in Jaxp were redefining equals() without redefining hashCode(). This patch adds hashCode() methods that are consistent with equals(). Reviewed-by: chegar, joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
package com.sun.org.apache.bcel.internal.generic;
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
/* ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * 4. The names "Apache" and "Apache Software Foundation" and
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    "Apache BCEL" must not be used to endorse or promote products
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    derived from this software without prior written permission. For
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *    written permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    "Apache BCEL", nor may "Apache" appear in their name, without
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *    prior written permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * individuals on behalf of the Apache Software Foundation.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import com.sun.org.apache.bcel.internal.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import com.sun.org.apache.bcel.internal.classfile.*;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    63
import java.util.Objects;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * This class represents a local variable within a method. It contains its
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * scope, name and type. The generated LocalVariable object can be obtained
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * with getLocalVariable which needs the instruction list and the constant
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * pool as parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * @see     LocalVariable
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * @see     MethodGen
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
public class LocalVariableGen
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  implements InstructionTargeter, NamedAndTyped, Cloneable,
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
             java.io.Serializable
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
{
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    79
  private final int   index;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  private String      name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  private Type        type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
  private InstructionHandle start, end;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * Generate a local variable that with index `index'. Note that double and long
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * variables need two indexs. Index indices have to be provided by the user.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   * @param index index of local variable
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * @param name its name
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * @param type its type
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   * @param start from where the instruction is valid (null means from the start)
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * @param end until where the instruction is valid (null means to the end)
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  public LocalVariableGen(int index, String name, Type type,
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
                          InstructionHandle start, InstructionHandle end) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    if((index < 0) || (index > Constants.MAX_SHORT))
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
      throw new ClassGenException("Invalid index index: " + index);
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    this.name  = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    this.type  = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    this.index  = index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    setStart(start);
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    setEnd(end);
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * Get LocalVariable object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * This relies on that the instruction list has already been dumped to byte code or
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * or that the `setPositions' methods has been called for the instruction list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * Note that for local variables whose scope end at the last
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * instruction of the method's code, the JVM specification is ambiguous:
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * both a start_pc+length ending at the last instruction and
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * start_pc+length ending at first index beyond the end of the code are
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   * valid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   * @param il instruction list (byte code) which this variable belongs to
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
   * @param cp constant pool
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  public LocalVariable getLocalVariable(ConstantPoolGen cp) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    int start_pc        = start.getPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    int length          = end.getPosition() - start_pc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    if(length > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
      length += end.getInstruction().getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    int name_index      = cp.addUtf8(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    int signature_index = cp.addUtf8(type.getSignature());
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    return new LocalVariable(start_pc, length, name_index,
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                             signature_index, index, cp.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   135
  public int         getIndex()                  { return index; }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   136
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  public void        setName(String name)        { this.name = name; }
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   138
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  public String      getName()                   { return name; }
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   140
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
  public void        setType(Type type)          { this.type = type; }
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   142
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
  public Type        getType()                   { return type; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
  public InstructionHandle getStart()                  { return start; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  public InstructionHandle getEnd()                    { return end; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   148
  /**
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   149
   * Remove this from any known HashSet in which it might be registered.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   150
   */
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   151
  void notifyTargetChanging() {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   152
    // hashCode depends on 'index', 'start', and 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   153
    // Therefore before changing any of these values we
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   154
    // need to unregister 'this' from any HashSet where
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   155
    // this is registered, and then we need to add it
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   156
    // back...
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   157
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   158
    // Unregister 'this' from the HashSet held by 'start'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   159
    BranchInstruction.notifyTargetChanging(this.start, this);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   160
    if (this.end != this.start) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   161
        // Since hashCode() is going to change we need to unregister
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   162
        // 'this' both form 'start' and 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   163
        // Unregister 'this' from the HashSet held by 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   164
        BranchInstruction.notifyTargetChanging(this.end, this);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   165
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   168
  /**
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   169
   * Add back 'this' in all HashSet in which it should be registered.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   170
   **/
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   171
  void notifyTargetChanged() {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   172
    // hashCode depends on 'index', 'start', and 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   173
    // Therefore before changing any of these values we
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   174
    // need to unregister 'this' from any HashSet where
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   175
    // this is registered, and then we need to add it
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   176
    // back...
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   177
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   178
    // Register 'this' in the HashSet held by start.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   179
    BranchInstruction.notifyTargetChanged(this.start, this);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   180
    if (this.end != this.start) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   181
        // Since hashCode() has changed we need to register
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   182
        // 'this' again in 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   183
        // Add back 'this' in the HashSet held by 'end'.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   184
        BranchInstruction.notifyTargetChanged(this.end, this);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   185
    }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   186
  }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   187
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   188
  public final void setStart(InstructionHandle start) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   189
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   190
    // Call notifyTargetChanging *before* modifying this,
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   191
    // as the code triggered by notifyTargetChanging
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   192
    // depends on this pointing to the 'old' start.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   193
    notifyTargetChanging();
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   194
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   195
    this.start = start;
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   196
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   197
    // call notifyTargetChanged *after* modifying this,
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   198
    // as the code triggered by notifyTargetChanged
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   199
    // depends on this pointing to the 'new' start.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   200
    notifyTargetChanged();
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   201
  }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   202
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   203
  public final void setEnd(InstructionHandle end) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   204
    // call notifyTargetChanging *before* modifying this,
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   205
    // as the code triggered by notifyTargetChanging
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   206
    // depends on this pointing to the 'old' end.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   207
    // Unregister 'this' from the HashSet held by the 'old' end.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   208
    notifyTargetChanging();
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   209
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    this.end = end;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   211
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   212
    // call notifyTargetChanged *after* modifying this,
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   213
    // as the code triggered by notifyTargetChanged
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   214
    // depends on this pointing to the 'new' end.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   215
    // Register 'this' in the HashSet held by the 'new' end.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   216
    notifyTargetChanged();
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   217
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
   * @param old_ih old target, either start or end
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
   * @param new_ih new target
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   224
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
  public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    boolean targeted = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    if(start == old_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
      targeted = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
      setStart(new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    if(end == old_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
      targeted = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
      setEnd(new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    if(!targeted)
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
      throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                                  end + "}");
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
   * @return true, if ih is target of this variable
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   246
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
  public boolean containsTarget(InstructionHandle ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    return (start == ih) || (end == ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  /**
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   252
   * We consider two local variables to be equal, if they use the same index and
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   * are valid in the same range.
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   255
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  public boolean equals(Object o) {
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   257
    if (o==this)
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   258
      return true;
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   259
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    if(!(o instanceof LocalVariableGen))
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    LocalVariableGen l = (LocalVariableGen)o;
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    return (l.index == index) && (l.start == start) && (l.end == end);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   267
  @Override
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   268
  public int hashCode() {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   269
    int hash = 7;
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   270
    hash = 59 * hash + this.index;
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   271
    hash = 59 * hash + Objects.hashCode(this.start);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   272
    hash = 59 * hash + Objects.hashCode(this.end);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   273
    return hash;
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   274
  }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   275
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   276
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
  public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    return "LocalVariableGen(" + name +  ", " + type +  ", " + start + ", " + end + ")";
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   281
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
  public Object clone() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
      return super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    } catch(CloneNotSupportedException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
      System.err.println(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
}