From 5ac19d7a5950ff326c83221d8b225f13c0f22128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Tue, 26 Apr 2016 16:15:53 +0200 Subject: [PATCH] - args_size bugfix --- BCEL/bcelifier/IfStatementCreator.java | 4 ++-- .../bytecode/DHBWInstructionFactory.java | 4 ++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 21 ++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/BCEL/bcelifier/IfStatementCreator.java b/BCEL/bcelifier/IfStatementCreator.java index 058ca8e9..88b43e39 100644 --- a/BCEL/bcelifier/IfStatementCreator.java +++ b/BCEL/bcelifier/IfStatementCreator.java @@ -13,7 +13,7 @@ import java.io.*; public class IfStatementCreator { private InstructionFactory _factory; private ConstantPoolGen _cp; - private ClassGen _cg; + private ClassGenerator _cg; public IfStatementCreator() { @@ -32,7 +32,7 @@ public class IfStatementCreator { private void createMethod_0() { InstructionList il = new InstructionList(); - MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "", "bcelifier.IfStatement", il, _cp); + MethodGen method = new MethodGenerator(0, Type.VOID, new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "", "bcelifier.IfStatement", il, _cp); InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0)); il.append(_factory.createInvoke("java.lang.Object", "", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index 6cf24c88..8b4b9929 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -139,7 +139,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ return new INVOKEDYNAMIC(index); } - public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { + public static LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { return InstructionFactory.createLoad(bytecodeType, getStoreIndex(variableName)); } @@ -147,7 +147,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ return InstructionFactory.createStore(bytecodeType, getStoreIndex(variableName)); } - public Integer getStoreIndex(String variableName) { + public static Integer getStoreIndex(String variableName) { if(storeIndexes.get(variableName) == null){ Integer index = storeIndexes.size()+1; storeIndexes.put(variableName, index); diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 3dcaf42a..56539df6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -1,6 +1,7 @@ // ino.module.Method.8564.package package de.dhbwstuttgart.syntaxtree; +import java.util.ArrayList; import java.util.Arrays; // ino.end // ino.module.Method.8564.import @@ -620,9 +621,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); - - org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS; - String[] argumentNames = new String[]{}; + + ArrayList argumentTypes = new ArrayList(); + ArrayList argumentNames = new ArrayList(); + if(this.parameterlist != null && this.parameterlist.size() > 0){ generateArgumentList(argumentTypes, argumentNames, cg, _factory, t); } @@ -632,22 +634,17 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable Type returnType = this.getType(); - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), getParentClass().name, il, _cp); + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.commons.bcel6.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp); cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); } - private void generateArgumentList(org.apache.commons.bcel6.generic.Type[] argumentTypes, String[] argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { - argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()]; - argumentNames = new String[this.parameterlist.size()]; - int i = 0; + private void generateArgumentList(ArrayList argumentTypes, ArrayList argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { for(FormalParameter parameter : this.parameterlist){ - argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); - argumentNames[i] = parameter.getIdentifier(); + argumentTypes.add(parameter.getType().getBytecodeType(cg, t)); + argumentNames.add(parameter.getIdentifier()); _factory.getStoreIndex(parameter.getIdentifier()); - - i++; } } }