Test update
This commit is contained in:
parent
6948797001
commit
1dd405a00f
BIN
Fakultaet.class
BIN
Fakultaet.class
Binary file not shown.
@ -15,7 +15,7 @@ import java.util.Objects;
|
|||||||
public class BinaryExpression extends AbstractType implements IExpression{
|
public class BinaryExpression extends AbstractType implements IExpression{
|
||||||
|
|
||||||
public String operator;
|
public String operator;
|
||||||
public IExpression left;
|
public IExpression left; // This needs TypeCheckResult
|
||||||
public IExpression right;
|
public IExpression right;
|
||||||
|
|
||||||
public BinaryExpression(String operator, IExpression left, IExpression right) {
|
public BinaryExpression(String operator, IExpression left, IExpression right) {
|
||||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ReturnStatement extends AbstractType implements IStatement{
|
public class ReturnStatement extends AbstractType implements IStatement{
|
||||||
IExpression expression;
|
IExpression expression; // Needs typeCheckResult
|
||||||
public String thisClass;
|
public String thisClass;
|
||||||
|
|
||||||
public ReturnStatement(IExpression expression) {
|
public ReturnStatement(IExpression expression) {
|
||||||
|
@ -18,7 +18,7 @@ import java.util.*;
|
|||||||
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
|
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||||
String methodName;
|
String methodName;
|
||||||
List<IExpression> arguments;
|
List<IExpression> arguments;
|
||||||
Receiver receiver;
|
Receiver receiver; // Braucht typecheckResult
|
||||||
List<ReceivingMethod> receivingMethods;
|
List<ReceivingMethod> receivingMethods;
|
||||||
public String thisClass;
|
public String thisClass;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||||||
public class NewStatementExpression extends AbstractType implements IExpression, IStatement {
|
public class NewStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||||
|
|
||||||
private String className;
|
private String className;
|
||||||
private List<IExpression> arguments;
|
private List<IExpression> arguments; //These need to have a TypeCheckResult
|
||||||
|
|
||||||
public NewStatementExpression(String className, List<IExpression> arguments) {
|
public NewStatementExpression(String className, List<IExpression> arguments) {
|
||||||
this.className = className;
|
this.className = className;
|
||||||
|
@ -46,14 +46,14 @@ public class testAll {
|
|||||||
testAst(ast, pathToCode);
|
testAst(ast, pathToCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
public void testDivideByZero(){
|
public void testDivideByZero(){
|
||||||
Program ast = AssignWrongTypeAST.getProgram();
|
Program ast = DivideByZeroAST.getProgram();
|
||||||
String pathToCode = "failTests/DivideByzero.java";
|
String pathToCode = "failTests/DivideByzero.java";
|
||||||
testAst(ast, pathToCode);
|
testAst(ast, pathToCode);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testcharArgument(){
|
public void testcharArgument(){
|
||||||
Program ast = CharArgumentAST.getProgram();
|
Program ast = CharArgumentAST.getProgram();
|
||||||
|
@ -3,28 +3,48 @@ package ASTs;
|
|||||||
import abstractSyntaxTree.Class.FieldDecl;
|
import abstractSyntaxTree.Class.FieldDecl;
|
||||||
import abstractSyntaxTree.Class.MethodDecl;
|
import abstractSyntaxTree.Class.MethodDecl;
|
||||||
import abstractSyntaxTree.Class.RefType;
|
import abstractSyntaxTree.Class.RefType;
|
||||||
|
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||||
|
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||||
import abstractSyntaxTree.Parameter.Parameter;
|
import abstractSyntaxTree.Parameter.Parameter;
|
||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
|
import abstractSyntaxTree.Program;
|
||||||
import abstractSyntaxTree.Statement.BlockStatement;
|
import abstractSyntaxTree.Statement.BlockStatement;
|
||||||
|
import abstractSyntaxTree.Statement.IStatement;
|
||||||
|
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DivideByZeroAST {
|
public class DivideByZeroAST {
|
||||||
/*
|
|
||||||
|
public static Program getProgram() {
|
||||||
|
List<RefType> refTypeList = new ArrayList<>();
|
||||||
|
refTypeList.add(getRefType());
|
||||||
|
Program program = new Program(refTypeList);
|
||||||
|
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
public static RefType getRefType(){
|
public static RefType getRefType(){
|
||||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||||
RefType refType = new RefType("DivideByZero", fieldDeclList, methodDeclList, false);
|
methodDeclList.add(method0());
|
||||||
|
RefType refType = new RefType("DivideByZero", fieldDeclList, methodDeclList, true);
|
||||||
|
|
||||||
return refType;
|
return refType;
|
||||||
}
|
}
|
||||||
public static MethodDecl method0(){
|
public static MethodDecl method0(){
|
||||||
|
|
||||||
BlockStatement blockStatement = new BlockStatement();
|
BinaryExpression binaryExpression00 = new BinaryExpression("/", new IntConstantExpression(1), new IntConstantExpression(0));
|
||||||
List<Parameter> parameterList = new ArrayList<>();
|
LocalVarDecl localVarDecl00 = new LocalVarDecl("int", "a", binaryExpression00);
|
||||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
List<IStatement> iStatementList = new ArrayList<>();
|
||||||
MethodDecl methodDecl = new MethodDecl("DivideByZero", "int", "test",
|
iStatementList.add(localVarDecl00);
|
||||||
|
BlockStatement blockStatement = new BlockStatement(iStatementList, null);
|
||||||
|
|
||||||
|
MethodDecl methodDecl = new MethodDecl("DivideByZero", "void", "main",
|
||||||
|
new ParameterList(new ArrayList<>()), blockStatement
|
||||||
);
|
);
|
||||||
}*/
|
|
||||||
|
return methodDecl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,69 @@
|
|||||||
package ASTs;
|
package ASTs;
|
||||||
|
|
||||||
|
import TypeCheck.TypeCheckResult;
|
||||||
|
import Typecheck.TypingHelper;
|
||||||
|
import abstractSyntaxTree.Class.FieldDecl;
|
||||||
|
import abstractSyntaxTree.Class.MethodDecl;
|
||||||
|
import abstractSyntaxTree.Class.RefType;
|
||||||
|
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||||
|
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||||
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
|
import abstractSyntaxTree.Program;
|
||||||
|
import abstractSyntaxTree.Statement.BlockStatement;
|
||||||
|
import abstractSyntaxTree.Statement.IStatement;
|
||||||
|
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DivideByZeroASTTyped {
|
public class DivideByZeroASTTyped {
|
||||||
|
|
||||||
|
public static Program getProgram() {
|
||||||
|
List<RefType> refTypeList = new ArrayList<>();
|
||||||
|
refTypeList.add(getRefType());
|
||||||
|
Program program = new Program(refTypeList);
|
||||||
|
addTyping(program);
|
||||||
|
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RefType getRefType(){
|
||||||
|
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||||
|
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||||
|
methodDeclList.add(method0());
|
||||||
|
RefType refType = new RefType("DivideByZero", fieldDeclList, methodDeclList, true);
|
||||||
|
|
||||||
|
return refType;
|
||||||
|
}
|
||||||
|
public static MethodDecl method0(){
|
||||||
|
|
||||||
|
IntConstantExpression intConstantExpression0 = new IntConstantExpression(1);
|
||||||
|
intConstantExpression0.setTypeCheckResult(new TypeCheckResult("int"));
|
||||||
|
BinaryExpression binaryExpression00 = new BinaryExpression("/", intConstantExpression0, new IntConstantExpression(0));
|
||||||
|
LocalVarDecl localVarDecl00 = new LocalVarDecl("int", "a", binaryExpression00);
|
||||||
|
List<IStatement> iStatementList = new ArrayList<>();
|
||||||
|
iStatementList.add(localVarDecl00);
|
||||||
|
BlockStatement blockStatement = new BlockStatement(iStatementList, "void");
|
||||||
|
|
||||||
|
MethodDecl methodDecl = new MethodDecl("DivideByZero", "void", "main",
|
||||||
|
new ParameterList(new ArrayList<>()), blockStatement
|
||||||
|
);
|
||||||
|
|
||||||
|
return methodDecl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addTyping(Program program) {
|
||||||
|
//Type Context
|
||||||
|
TypingHelper.addTypeContext(program, "DivideByZero", new HashMap<>());
|
||||||
|
|
||||||
|
|
||||||
|
//Method Context
|
||||||
|
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||||
|
method0.put("void", new ParameterList(new ArrayList<>()));
|
||||||
|
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||||
|
methods.put("main", method0);
|
||||||
|
TypingHelper.addMethodContext(program, "DivideByZero", methods);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,18 +76,24 @@ public class FakultaetAST {
|
|||||||
|
|
||||||
iStmtList0.add(localVarExpr0);
|
iStmtList0.add(localVarExpr0);
|
||||||
// Expression 2
|
// Expression 2
|
||||||
IntConstantExpression intConst1 = new IntConstantExpression(0);
|
IntConstantExpression intConst1 = new IntConstantExpression(1);
|
||||||
LocalVarDecl localVarExpr1 = new LocalVarDecl("int", "i", intConst1);
|
LocalVarDecl localVarExpr1 = new LocalVarDecl("int", "i", intConst1);
|
||||||
|
|
||||||
iStmtList0.add(localVarExpr1);
|
iStmtList0.add(localVarExpr1);
|
||||||
|
|
||||||
//While Statement
|
//While Statement
|
||||||
BinaryExpression whileCondition = new BinaryExpression("<", new LocalVarIdentifier("i"), new LocalVarIdentifier("number"));
|
BinaryExpression whileCondition = new BinaryExpression("<=", new LocalVarIdentifier("i"), new LocalVarIdentifier("number"));
|
||||||
|
|
||||||
BinaryExpression whileBinExpr = new BinaryExpression("*", new LocalVarIdentifier("factorial"), new LocalVarIdentifier("i"));
|
BinaryExpression whileBinExpr = new BinaryExpression("*", new LocalVarIdentifier("factorial"), new LocalVarIdentifier("i"));
|
||||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", new LocalVarIdentifier("factorial"), whileBinExpr);
|
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", new LocalVarIdentifier("factorial"), whileBinExpr);
|
||||||
List<IStatement> whileBlockStmts = new ArrayList<>();
|
List<IStatement> whileBlockStmts = new ArrayList<>();
|
||||||
|
|
||||||
|
LocalVarIdentifier identifierI = new LocalVarIdentifier("i");
|
||||||
|
BinaryExpression rightAssign1 = new BinaryExpression("+", identifierI, new IntConstantExpression(1));
|
||||||
|
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierI, rightAssign1);
|
||||||
|
|
||||||
whileBlockStmts.add(assignStatementExpression0);
|
whileBlockStmts.add(assignStatementExpression0);
|
||||||
|
whileBlockStmts.add(assignStatementExpression1);
|
||||||
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, null);
|
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, null);
|
||||||
|
|
||||||
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
||||||
|
@ -61,8 +61,14 @@ public class FakultaetASTTyped {
|
|||||||
// If Statament
|
// If Statament
|
||||||
//condition
|
//condition
|
||||||
LocalVarIdentifier binExprIdentifier = new LocalVarIdentifier("number");
|
LocalVarIdentifier binExprIdentifier = new LocalVarIdentifier("number");
|
||||||
|
TypeCheckResult typeCheckResultbinExprIdentifier = new TypeCheckResult();
|
||||||
|
typeCheckResultbinExprIdentifier.type = "int";
|
||||||
|
binExprIdentifier.setTypeCheckResult(typeCheckResultbinExprIdentifier);
|
||||||
IntConstantExpression binExprIntConst = new IntConstantExpression(0);
|
IntConstantExpression binExprIntConst = new IntConstantExpression(0);
|
||||||
BinaryExpression binExpr = new BinaryExpression("<", binExprIdentifier, binExprIntConst);
|
BinaryExpression binExpr = new BinaryExpression("<", binExprIdentifier, binExprIntConst);
|
||||||
|
TypeCheckResult typeCheckResultbinExpr = new TypeCheckResult();
|
||||||
|
typeCheckResultbinExpr.type = "boolean";
|
||||||
|
binExpr.setTypeCheckResult(typeCheckResultbinExpr);
|
||||||
|
|
||||||
IntConstantExpression return0Expr0 = new IntConstantExpression(1);
|
IntConstantExpression return0Expr0 = new IntConstantExpression(1);
|
||||||
TypeCheckResult typeCheckResult1 = new TypeCheckResult();
|
TypeCheckResult typeCheckResult1 = new TypeCheckResult();
|
||||||
@ -88,12 +94,19 @@ public class FakultaetASTTyped {
|
|||||||
iStmtList0.add(localVarExpr1);
|
iStmtList0.add(localVarExpr1);
|
||||||
|
|
||||||
//While Statement
|
//While Statement
|
||||||
BinaryExpression whileCondition = new BinaryExpression("<", new LocalVarIdentifier("i"), new LocalVarIdentifier("number"));
|
BinaryExpression whileCondition = new BinaryExpression("<=", new LocalVarIdentifier("i"), new LocalVarIdentifier("number"));
|
||||||
|
whileCondition.setTypeCheckResult(new TypeCheckResult("void"));
|
||||||
|
|
||||||
BinaryExpression whileBinExpr = new BinaryExpression("*", new LocalVarIdentifier("factorial"), new LocalVarIdentifier("i"));
|
BinaryExpression whileBinExpr = new BinaryExpression("*", new LocalVarIdentifier("factorial"), new LocalVarIdentifier("i"));
|
||||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", new LocalVarIdentifier("factorial"), whileBinExpr);
|
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", new LocalVarIdentifier("factorial"), whileBinExpr);
|
||||||
List<IStatement> whileBlockStmts = new ArrayList<>();
|
List<IStatement> whileBlockStmts = new ArrayList<>();
|
||||||
|
|
||||||
|
LocalVarIdentifier identifierI = new LocalVarIdentifier("i");
|
||||||
|
BinaryExpression rightAssign1 = new BinaryExpression("+", identifierI, new IntConstantExpression(1));
|
||||||
|
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierI, rightAssign1);
|
||||||
|
|
||||||
whileBlockStmts.add(assignStatementExpression0);
|
whileBlockStmts.add(assignStatementExpression0);
|
||||||
|
whileBlockStmts.add(assignStatementExpression1);
|
||||||
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, "void");
|
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, "void");
|
||||||
|
|
||||||
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
||||||
|
@ -23,49 +23,32 @@ public class ByteCodeTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testByteCodeFromAst(String correctClassFilePath, Program abstractSyntaxTree, String className) {
|
public void testByteCodeFromAst(String correctClassFilePath, Program abstractSyntaxTree, String className) {
|
||||||
testClassFile(false, className, abstractSyntaxTree, correctClassFilePath, null);
|
typeCheckWithoutmain(abstractSyntaxTree);
|
||||||
|
generateCode(abstractSyntaxTree);
|
||||||
|
testAST(correctClassFilePath, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testByteCodeFromTypedAst(String correctClassFilePath, Program abstractSyntaxTree, String className) {
|
||||||
|
generateCode(abstractSyntaxTree);
|
||||||
|
testAST(correctClassFilePath, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassFileFromScratch(String correctClassFilePath, String fileToComparePath, String className) {
|
public void testClassFileFromScratch(String correctClassFilePath, String fileToComparePath, String className) {
|
||||||
testClassFile(true, className, null, correctClassFilePath, fileToComparePath);
|
Program abstractSyntaxTree = generateAST(fileToComparePath);
|
||||||
|
typeCheckWithoutmain(abstractSyntaxTree);
|
||||||
|
generateCode(abstractSyntaxTree);
|
||||||
|
testAST(correctClassFilePath, className);
|
||||||
}
|
}
|
||||||
public void testClassFile(boolean generateAST, String className, Program abstractSyntaxTree,
|
|
||||||
String correctClassFilePath, String fileToComparePath) {
|
|
||||||
|
|
||||||
if(generateAST){
|
private void typeCheckWithoutmain(Program abstractSyntaxTree){
|
||||||
String content = "";
|
try {
|
||||||
try {
|
abstractSyntaxTree.typeCheckWithoutMain();
|
||||||
System.out.println("Classpath: " + Path.of(fileToComparePath));
|
} catch (Exception e){
|
||||||
content = Files.readString(Path.of(fileToComparePath));
|
System.out.println("Le Exception in le type-check");
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("File not found!");
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
|
|
||||||
CharStream codeCharStream = CharStreams.fromString(content);
|
|
||||||
DecafLexer lexer = new DecafLexer(codeCharStream);
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
||||||
|
|
||||||
tokens.fill();
|
|
||||||
|
|
||||||
DecafParser parser = new DecafParser(tokens);
|
|
||||||
|
|
||||||
ParseTree tree = parser.program();
|
|
||||||
|
|
||||||
ASTGenerator generator = new ASTGenerator();
|
|
||||||
abstractSyntaxTree = (Program) generator.visit(tree);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(generateAST){
|
private void generateCode(Program abstractSyntaxTree){
|
||||||
try {
|
|
||||||
abstractSyntaxTree.typeCheckWithoutMain();
|
|
||||||
} catch (Exception e){
|
|
||||||
System.out.println("Le Exception in le type-check");
|
|
||||||
//fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
abstractSyntaxTree.codeGen();
|
abstractSyntaxTree.codeGen();
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
@ -73,7 +56,9 @@ public class ByteCodeTester {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testAST(String correctClassFilePath, String className) {
|
||||||
try {
|
try {
|
||||||
ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath);
|
ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath);
|
||||||
ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class");
|
ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class");
|
||||||
@ -89,6 +74,31 @@ public class ByteCodeTester {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private Program generateAST(String pathToJavaFile){
|
||||||
|
String content = "";
|
||||||
|
try {
|
||||||
|
System.out.println("Classpath: " + Path.of(pathToJavaFile));
|
||||||
|
content = Files.readString(Path.of(pathToJavaFile));
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("File not found!");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
CharStream codeCharStream = CharStreams.fromString(content);
|
||||||
|
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||||
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
|
tokens.fill();
|
||||||
|
|
||||||
|
DecafParser parser = new DecafParser(tokens);
|
||||||
|
|
||||||
|
ParseTree tree = parser.program();
|
||||||
|
|
||||||
|
ASTGenerator generator = new ASTGenerator();
|
||||||
|
Program abstractSyntaxTree = (Program) generator.visit(tree);
|
||||||
|
|
||||||
|
return abstractSyntaxTree;
|
||||||
|
}
|
||||||
|
|
||||||
public void compareJarFilesFromAST(Program abstractSyntaxTree, String jarPath, String[] classNames){
|
public void compareJarFilesFromAST(Program abstractSyntaxTree, String jarPath, String[] classNames){
|
||||||
try {
|
try {
|
||||||
|
@ -38,6 +38,14 @@ public class CompareByteCodeBehaviour {
|
|||||||
Method[] methods1 = class1.getDeclaredMethods();
|
Method[] methods1 = class1.getDeclaredMethods();
|
||||||
Method[] methods2 = class2.getDeclaredMethods();
|
Method[] methods2 = class2.getDeclaredMethods();
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(int i = 0; i < methods1.length; i++) {
|
||||||
|
System.out.println("Method1[" + i + "]: " + methods1[i]);
|
||||||
|
System.out.println("Method2[" + i + "]: " + methods2[i]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
for (Method method1 : methods1) {
|
for (Method method1 : methods1) {
|
||||||
for (Method method2 : methods2) {
|
for (Method method2 : methods2) {
|
||||||
if (compareMethod(method1, method2)) {
|
if (compareMethod(method1, method2)) {
|
||||||
@ -49,6 +57,12 @@ public class CompareByteCodeBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
for(int i = 0; i < this.methodArray1.size(); i++){
|
||||||
|
System.out.println("Method1[" + i + "]: " + methodArray1.get(i));
|
||||||
|
System.out.println("Method2[" + i + "]: " + methodArray2.get(i));
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compareMethodBehaviour(Class<?> class1, Class<?> class2){
|
public boolean compareMethodBehaviour(Class<?> class1, Class<?> class2){
|
||||||
@ -72,12 +86,23 @@ public class CompareByteCodeBehaviour {
|
|||||||
Method[] methods2 = new Method[this.methodArray2.size()];
|
Method[] methods2 = new Method[this.methodArray2.size()];
|
||||||
methods2 = this.methodArray2.toArray(methods2);
|
methods2 = this.methodArray2.toArray(methods2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(int i = 0; i < methods1.length; i++) {
|
||||||
|
System.out.println("MethodArray1 [" + i + "]: " + methods1[i]);
|
||||||
|
System.out.println("MethodArray2 [" + i + "]: " + methods2[i]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
System.out.println("length: " + methods1.length);
|
||||||
// Compare methods
|
// Compare methods
|
||||||
for (int i = 0; i < methods1.length; i++) {
|
for (int i = 0; i < methods1.length; i++) {
|
||||||
|
System.out.println("i: " + i);
|
||||||
Method method1 = methods1[i];
|
Method method1 = methods1[i];
|
||||||
Method method2 = methods2[i];
|
Method method2 = methods2[i];
|
||||||
|
|
||||||
|
System.out.println(method1);
|
||||||
|
System.out.println(method2);
|
||||||
|
|
||||||
method1.setAccessible(true);
|
method1.setAccessible(true);
|
||||||
method2.setAccessible(true);
|
method2.setAccessible(true);
|
||||||
|
|
||||||
@ -88,16 +113,19 @@ public class CompareByteCodeBehaviour {
|
|||||||
Object result1 = method1.invoke(obj1, testInputs);
|
Object result1 = method1.invoke(obj1, testInputs);
|
||||||
Object result2 = method2.invoke(obj2, testInputs);
|
Object result2 = method2.invoke(obj2, testInputs);
|
||||||
|
|
||||||
if( (result1 == null) && (result2 == null)) {
|
System.out.println("Result method 1: " + result1);
|
||||||
return true;
|
System.out.println("Result method 2: " + result2);
|
||||||
}
|
|
||||||
if(( result1 == null) || (result2 == null) ) {
|
if( !((result1 == null) && (result2 == null))) {
|
||||||
return false;
|
if(( result1 == null) || (result2 == null) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!result1.equals(result2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result1.equals(result2)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InstantiationException | IllegalAccessException |
|
} catch (InstantiationException | IllegalAccessException |
|
||||||
|
@ -18,18 +18,28 @@ public class TestAll {
|
|||||||
Program ast = emptyClassASTTyped.getEmptyProgramm();
|
Program ast = emptyClassASTTyped.getEmptyProgramm();
|
||||||
String className = "emptyClass";
|
String className = "emptyClass";
|
||||||
String javacode = "src/test/resources/basicClasses/emptyClass.java";
|
String javacode = "src/test/resources/basicClasses/emptyClass.java";
|
||||||
//byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyClassWithConstructor() {
|
||||||
|
String classPath = "src/test/resources/basicClasses/EmptyClassWithConstructor.class";
|
||||||
|
Program ast = EmptyClassWithConstructorASTTyped.getProgram();
|
||||||
|
String className = "EmptyClassWithConstructor";
|
||||||
|
String javacode = "src/test/resources/basicClasses/emptyClass.java";
|
||||||
|
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||||
|
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFakultaet() {
|
public void testFakultaet() {
|
||||||
String classPath = "src/test/resources/basicClasses/Fakultaet.class";
|
String classPath = "src/test/resources/basicClasses/Fakultaet.class";
|
||||||
Program ast = FakultaetASTTyped.getProgram();
|
Program ast = FakultaetAST.getProgram();
|
||||||
String className = "Fakultaet";
|
String className = "Fakultaet";
|
||||||
String javacode = "src/test/resources/basicClasses/Fakultaet.java";
|
String javacode = "src/test/resources/basicClasses/Fakultaet.java";
|
||||||
//byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -38,17 +48,17 @@ public class TestAll {
|
|||||||
Program ast = ClassWithMainASTTyped.getProgram();
|
Program ast = ClassWithMainASTTyped.getProgram();
|
||||||
String className = "classWithMain";
|
String className = "classWithMain";
|
||||||
String javacode = "src/test/resources/basicClasses/classWithMain.java";
|
String javacode = "src/test/resources/basicClasses/classWithMain.java";
|
||||||
//testByteCodeFromAst(classPath, ast ,className);
|
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCharArgument() {
|
public void testCharArgument() {
|
||||||
String classPath = "src/test/resources/SimpleTests/CharArgument.class";
|
String classPath = "src/test/resources/SimpleTests/CharArgument.class";
|
||||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
Program ast = CharArgumentAST.getProgram();
|
||||||
String className = "CharArgument";
|
String className = "CharArgument";
|
||||||
String javacode = "src/test/resources/SimpleTests/CharArgument.java";
|
String javacode = "src/test/resources/SimpleTests/CharArgument.java";
|
||||||
//testByteCodeFromAst(classPath, ast ,className);
|
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,14 @@ public class TestAll {
|
|||||||
testTypeCheck(fakultaet, correctAST, expectedResult);
|
testTypeCheck(fakultaet, correctAST, expectedResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDivideByZero(){
|
||||||
|
Program fakultaet = DivideByZeroAST.getProgram();
|
||||||
|
Program correctAST = DivideByZeroASTTyped.getProgram();
|
||||||
|
boolean expectedResult = true;
|
||||||
|
testTypeCheck(fakultaet, correctAST, expectedResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testTypeCheckWM(Program abstractSyntaxTree, Program correctAST, boolean expectedResult){
|
public void testTypeCheckWM(Program abstractSyntaxTree, Program correctAST, boolean expectedResult){
|
||||||
abstractSyntaxTree.classes.add(ClassWithMainASTTyped.getRefType());
|
abstractSyntaxTree.classes.add(ClassWithMainASTTyped.getRefType());
|
||||||
|
Binary file not shown.
@ -4,9 +4,10 @@ class Fakultaet {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int factorial = 1;
|
int factorial = 1;
|
||||||
int i = 0;
|
int i = 1;
|
||||||
while(i < number){
|
while(i <= number){
|
||||||
factorial = factorial * i;
|
factorial = factorial * i;
|
||||||
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return factorial;
|
return factorial;
|
||||||
|
Loading…
Reference in New Issue
Block a user