825N/A/*
825N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
825N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
825N/A *
825N/A * This code is free software; you can redistribute it and/or modify it
825N/A * under the terms of the GNU General Public License version 2 only, as
825N/A * published by the Free Software Foundation. Oracle designates this
825N/A * particular file as subject to the "Classpath" exception as provided
825N/A * by Oracle in the LICENSE file that accompanied this code.
825N/A *
825N/A * This code is distributed in the hope that it will be useful, but WITHOUT
825N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
825N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
825N/A * version 2 for more details (a copy is included in the LICENSE file that
825N/A * accompanied this code).
825N/A *
825N/A * You should have received a copy of the GNU General Public License version
825N/A * 2 along with this work; if not, write to the Free Software Foundation,
825N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
825N/A *
825N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
825N/A * or visit www.oracle.com if you need additional information or have any
825N/A * questions.
825N/A */
825N/A
825N/Apackage com.sun.tools.classfile;
825N/A
825N/Aimport java.io.IOException;
825N/A
825N/A/**
971N/A * See JVMS <TBD>
825N/A * http://cr.openjdk.java.net/~jrose/pres/indy-javadoc-mlvm/
825N/A *
825N/A * <p><b>This is NOT part of any supported API.
825N/A * If you write code that depends on this, you do so at your own risk.
825N/A * This code and its internal interfaces are subject to change or
825N/A * deletion without notice.</b>
825N/A */
825N/Apublic class BootstrapMethods_attribute extends Attribute {
825N/A public final BootstrapMethodSpecifier[] bootstrap_method_specifiers;
825N/A
825N/A BootstrapMethods_attribute(ClassReader cr, int name_index, int length)
825N/A throws IOException, AttributeException {
825N/A super(name_index, length);
825N/A int bootstrap_method_count = cr.readUnsignedShort();
825N/A bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count];
825N/A for (int i = 0; i < bootstrap_method_specifiers.length; i++)
825N/A bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr);
825N/A }
825N/A
825N/A public BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
825N/A super(name_index, length(bootstrap_method_specifiers));
825N/A this.bootstrap_method_specifiers = bootstrap_method_specifiers;
825N/A }
825N/A
825N/A public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
825N/A int n = 2;
825N/A for (BootstrapMethodSpecifier b : bootstrap_method_specifiers)
825N/A n += b.length();
825N/A return n;
825N/A }
825N/A
825N/A @Override
825N/A public <R, P> R accept(Visitor<R, P> visitor, P p) {
825N/A return visitor.visitBootstrapMethods(this, p);
825N/A }
825N/A
825N/A public static class BootstrapMethodSpecifier {
825N/A public int bootstrap_method_ref;
825N/A public int[] bootstrap_arguments;
825N/A
825N/A public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) {
825N/A this.bootstrap_method_ref = bootstrap_method_ref;
825N/A this.bootstrap_arguments = bootstrap_arguments;
825N/A }
825N/A BootstrapMethodSpecifier(ClassReader cr) throws IOException {
825N/A bootstrap_method_ref = cr.readUnsignedShort();
825N/A int method_count = cr.readUnsignedShort();
825N/A bootstrap_arguments = new int[method_count];
825N/A for (int i = 0; i < bootstrap_arguments.length; i++) {
825N/A bootstrap_arguments[i] = cr.readUnsignedShort();
825N/A }
825N/A }
825N/A
825N/A int length() {
825N/A // u2 (method_ref) + u2 (argc) + u2 * argc
825N/A return 2 + 2 + (bootstrap_arguments.length * 2);
825N/A }
825N/A }
825N/A}