All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.jpattern.org.cojen.classfile.attribute.CodeAttr Maven / Gradle / Ivy

Go to download

This is a copy of the good Cojen project from http://cojen.sourceforge.net/ with package name changed

The newest version!
/*
 *  Copyright 2004-2010 Brian S O'Neill
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.googlecode.jpattern.org.cojen.classfile.attribute;

import java.util.ArrayList;
import java.util.List;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.googlecode.jpattern.org.cojen.classfile.Attribute;
import com.googlecode.jpattern.org.cojen.classfile.AttributeFactory;
import com.googlecode.jpattern.org.cojen.classfile.CodeBuffer;
import com.googlecode.jpattern.org.cojen.classfile.ConstantPool;
import com.googlecode.jpattern.org.cojen.classfile.ExceptionHandler;
import com.googlecode.jpattern.org.cojen.classfile.LocalVariable;
import com.googlecode.jpattern.org.cojen.classfile.Location;
import com.googlecode.jpattern.org.cojen.classfile.MethodInfo;

/**
 * This class corresponds to the Code_attribute structure as defined in
 * section 4.7.4 of The Java Virtual Machine Specification.
 * To make it easier to create bytecode for the CodeAttr, use the 
 * CodeBuilder.
 *
 * @author Brian S O'Neill
 * @see com.googlecode.jpattern.org.cojen.classfile.Opcode
 * @see com.googlecode.jpattern.org.cojen.classfile.CodeBuilder
 */
public class CodeAttr extends Attribute {

    private CodeBuffer mCodeBuffer;
    private List mAttributes = new ArrayList(2);
    
    private LineNumberTableAttr mLineNumberTable;
    private LocalVariableTableAttr mLocalVariableTable;

    private LineNumberTableAttr mOldLineNumberTable;
    private LocalVariableTableAttr mOldLocalVariableTable;

    private StackMapTableAttr mOldStackMapTable;
    private StackMapTableAttr mStackMapTable;

    public CodeAttr(ConstantPool cp) {
        super(cp, CODE);
    }

    public CodeAttr(ConstantPool cp, String name) {
        super(cp, name);
    }
    
    public CodeAttr(ConstantPool cp, String name, int length,
                    DataInput din, AttributeFactory attrFactory)
        throws IOException
    {
        super(cp, name);

        final int maxStackDepth = din.readUnsignedShort();
        final int maxLocals = din.readUnsignedShort();

        final byte[] byteCodes = new byte[din.readInt()];
        din.readFully(byteCodes);

        int exceptionHandlerCount = din.readUnsignedShort();
        final ExceptionHandler[] handlers = 
            new ExceptionHandler[exceptionHandlerCount];

        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy