Initial revision

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@62 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent a75ab0fb9f
commit f26415d787
  1. 86
      jode/jode/flow/CompleteSynchronized.java
  2. 97
      jode/jode/flow/SynchronizedBlock.java

@ -0,0 +1,86 @@
/*
* CompleteSynchronized (c) 1998 Jochen Hoenicke
*
* You may distribute under the terms of the GNU General Public License.
*
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* $Id$
*/
package jode.flow;
import jode.MonitorEnterOperator;
import jode.ComplexExpression;
import jode.LocalLoadOperator;
import jode.LocalStoreOperator;
import jode.Expression;
public class CompleteSynchronized implements Transformation {
/**
* This combines the monitorenter and the initial expression
* into a synchronized statement
* @param flow The FlowBlock that is transformed
*/
public boolean transform(FlowBlock flow) {
SynchronizedBlock synBlock;
try {
synBlock = (SynchronizedBlock) flow.lastModified;
SequentialBlock sequBlock =
(SequentialBlock) synBlock.outer;
ComplexExpression monenter = (ComplexExpression)
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (!(monenter.getOperator() instanceof MonitorEnterOperator)
|| ((LocalLoadOperator) monenter.getSubExpressions()[0]).
getLocalInfo() != synBlock.local.getLocalInfo())
return false;
} catch (ClassCastException ex) {
return false;
} catch (NullPointerException ex) {
return false;
}
if (jode.Decompiler.isVerbose)
System.err.print("f");
synBlock.isEntered = true;
synBlock.replace(synBlock.outer, synBlock);
Expression object;
try {
SequentialBlock sequBlock =
(SequentialBlock) synBlock.outer;
ComplexExpression assign = (ComplexExpression)
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (((LocalStoreOperator) assign.getOperator()).
getLocalInfo() != synBlock.local.getLocalInfo())
return true;
object = assign.getSubExpressions()[0];
} catch (ClassCastException ex) {
return true;
} catch (NullPointerException ex) {
return true;
}
synBlock.object = object;
synBlock.replace(synBlock.outer, synBlock);
return true;
}
}

@ -0,0 +1,97 @@
/* SynchronizedBlock - Copyright (C) 1997-1998 Jochen Hoenicke.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
*/
package jode.flow;
import jode.Instruction;
import jode.LocalInfo;
import jode.TabbedPrintWriter;
/**
* This class represents a synchronized structured block.
*
* @author Jochen Hoenicke
*/
public class SynchronizedBlock extends StructuredBlock {
Instruction object;
LocalInfo local;
boolean isEntered;
StructuredBlock bodyBlock;
public SynchronizedBlock(LocalInfo local) {
this.local = local;
}
/**
* Sets the body block.
*/
public void setBodyBlock(StructuredBlock body) {
bodyBlock = body;
body.outer = this;
body.setFlowBlock(flowBlock);
}
/**
* Returns all sub block of this structured block.
*/
public StructuredBlock[] getSubBlocks() {
return new StructuredBlock[] { bodyBlock };
}
/**
* Replaces the given sub block with a new block.
* @param oldBlock the old sub block.
* @param newBlock the new sub block.
* @return false, if oldBlock wasn't a direct sub block.
*/
public boolean replaceSubBlock(StructuredBlock oldBlock,
StructuredBlock newBlock) {
if (bodyBlock == oldBlock)
bodyBlock = newBlock;
else
return false;
return true;
}
public void dumpDeclaration(TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException
{
if (local.getLocalInfo() != this.local.getLocalInfo()
|| object == null)
super.dumpDeclaration(writer, local);
}
public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException
{
boolean needsBrace = bodyBlock.needsBraces();
if (!isEntered)
writer.print("/* missing monitorenter */");
writer.println("synchronized ("
+ (object != null
? object.simplify().toString()
: local.getName()) + ")"
+ (needsBrace ? " {" :""));
writer.tab();
bodyBlock.dumpSource(writer);
writer.untab();
if (needsBrace)
writer.println("}");
}
}
Loading…
Cancel
Save