jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMap.java
author joehw
Mon, 17 Apr 2017 16:24:10 -0700
changeset 44797 8b3b3b911b8a
parent 25868 686eef1e7a79
child 46174 5611d2529b49
permissions -rw-r--r--
8162572: Update License Header for all JAXP sources Reviewed-by: lancea
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
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
/*
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    14
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    18
 * See the License for the specific language governing permissions and
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    19
 * limitations under the License.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    20
 */
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.bcel.internal.classfile;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import  com.sun.org.apache.bcel.internal.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import  java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * This class represents a stack map attribute used for
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * preverification of Java classes for the <a
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * href="http://java.sun.com/j2me/"> Java 2 Micro Edition</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * (J2ME). This attribute is used by the <a
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * href="http://java.sun.com/products/cldc/">KVM</a> and contained
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * within the Code attribute of a method. See CLDC specification
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * 5.3.1.2
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * @see     Code
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * @see     StackMapEntry
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * @see     StackMapType
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
public final class StackMap extends Attribute implements Node {
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  private int             map_length;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
  private StackMapEntry[] map; // Table of stack map entries
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  /*
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   * @param name_index Index of name
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * @param length Content length in bytes
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * @param map Table of stack map entries
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * @param constant_pool Array of constants
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  public StackMap(int name_index, int length,  StackMapEntry[] map,
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
                  ConstantPool constant_pool)
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    setStackMap(map);
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * Construct object from file stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   * @param name_index Index of name
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * @param length Content length in bytes
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   * @param file Input stream
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
   * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * @param constant_pool Array of constants
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  StackMap(int name_index, int length, DataInputStream file,
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
           ConstantPool constant_pool) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    this(name_index, length, (StackMapEntry[])null, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    map_length = file.readUnsignedShort();
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    map = new StackMapEntry[map_length];
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    for(int i=0; i < map_length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
      map[i] = new StackMapEntry(file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * Dump line number table attribute to file stream in binary format.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * @param file Output file stream
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  public final void dump(DataOutputStream file) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    super.dump(file);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    file.writeShort(map_length);
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    for(int i=0; i < map_length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
      map[i].dump(file);
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * @return Array of stack map entries
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  public final StackMapEntry[] getStackMap() { return map; }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * @param map Array of stack map entries
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
  public final void setStackMap(StackMapEntry[] map) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    this.map = map;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    map_length = (map == null)? 0 : map.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @return String representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  public final String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    StringBuffer buf = new StringBuffer("StackMap(");
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    for(int i=0; i < map_length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
      buf.append(map[i].toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
      if(i < map_length - 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        buf.append(", ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    buf.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    return buf.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * @return deep copy of this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  public Attribute copy(ConstantPool constant_pool) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    StackMap c = (StackMap)clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    c.map = new StackMapEntry[map_length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    for(int i=0; i < map_length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
      c.map[i] = map[i].copy();
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    c.constant_pool = constant_pool;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    return c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * Called by objects that are traversing the nodes of the tree implicitely
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * defined by the contents of a Java class. I.e., the hierarchy of methods,
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * fields, attributes, etc. spawns a tree of objects.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   * @param v Visitor object
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   public void accept(Visitor v) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     v.visitStackMap(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  public final int getMapLength() { return map_length; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
}