001: /*
002: Copyright (c) 2004, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.binding.classes;
030:
031: import org.apache.bcel.generic.InstructionHandle;
032:
033: /**
034: * Wrapper for branch target information. This preserves a snapshot of the stack
035: * state for the branch target, allowing it to be matched against the stack
036: * state for the branch source.
037: *
038: * @author Dennis M. Sosnoski
039: * @version 1.0
040: */
041:
042: public class BranchTarget {
043: /** Actual wrapped instruction handle. */
044: private final InstructionHandle m_targetHandle;
045:
046: /** Stack state for branch target. */
047: private final String[] m_stackTypes;
048:
049: /**
050: * Constructor.
051: *
052: * @param hand instruction handle
053: * @param types array of types of values on stack
054: */
055:
056: /*package*/BranchTarget(InstructionHandle hand, String[] types) {
057: m_targetHandle = hand;
058: m_stackTypes = types;
059: }
060:
061: /**
062: * Get actual target instruction.
063: *
064: * @return handle for target instruction
065: */
066:
067: /*package*/InstructionHandle getInstruction() {
068: return m_targetHandle;
069: }
070:
071: /**
072: * Get stack state information.
073: *
074: * @return array of type names on stack
075: */
076:
077: /*package*/String[] getStack() {
078: return m_stackTypes;
079: }
080:
081: /**
082: * Matches the branch target stack state against the supplied stack state.
083: *
084: * @param types array of types of values on stack
085: * @return <code>true</code> if stack states match, <code>false</code> if
086: * not
087: */
088:
089: /*package*/boolean matchStacks(String[] types) {
090:
091: // match stack states
092: if (types.length == m_stackTypes.length) {
093: for (int i = 0; i < types.length; i++) {
094: if (!types[i].equals(m_stackTypes[i])) {
095: return false;
096: }
097: }
098: return true;
099: } else {
100: return false;
101: }
102: }
103: }
|