added some e2e tests for CodeGenFiles with reflections

This commit is contained in:
JonathanFleischmann 2024-06-27 22:05:22 +02:00
parent c823894eb2
commit 3e2368d13c
7 changed files with 747 additions and 854 deletions

View File

@ -120,27 +120,18 @@ public class BytecodeTestUtil {
} }
public Object getFieldValue(String fieldName) throws Exception { public Object getFieldValue(String fieldName) throws Exception {
return clazz.getField(fieldName).get(instance); try {
return clazz.getField(fieldName).get(instance);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} }
public void setFieldValue(String fieldName, Object value) throws Exception { public void setFieldValue(String fieldName, Object value) throws Exception {
clazz.getField(fieldName).set(instance, value); clazz.getField(fieldName).set(instance, value);
} }
public Object getFieldValueAfterMethodInvocation(String fieldName, String methodName, Class<?>[] parameterTypes, Object... args) throws Exception {
Object instance = clazz.getDeclaredConstructor().newInstance();
// Methode aufrufen
Method method = clazz.getMethod(methodName, parameterTypes);
method.invoke(instance, args);
// Wert des Feldes nach dem Methodenaufruf abrufen
return clazz.getField(fieldName).get(instance);
}
public Object getFieldValueOfObject(Object obj, String fieldName) { public Object getFieldValueOfObject(Object obj, String fieldName) {
try { try {
Field field = obj.getClass().getField(fieldName); Field field = obj.getClass().getField(fieldName);
@ -153,25 +144,4 @@ public class BytecodeTestUtil {
return null; return null;
} }
} }
private Class<?>[] toClassArray(Object... args) {
return java.util.Arrays.stream(args)
.map(Object::getClass)
.toArray(Class<?>[]::new);
}
public Object getValueOfFieldInObject(Object instance, String fieldName) {
try {
Field field = instance.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(instance);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
} }

View File

@ -64,6 +64,7 @@ public class ByteCode_Break {
@Test @Test
public void testMethodParameters() { public void testMethodParameters() {
try { try {
Assertions.assertEquals(1, util.getMethodParameterCount("breakMethod", new Class<?>[]{boolean.class}));
Assertions.assertEquals("boolean", util.getMethodParameterTypes("breakMethod", new Class<?>[]{boolean.class}).get(0)); Assertions.assertEquals("boolean", util.getMethodParameterTypes("breakMethod", new Class<?>[]{boolean.class}).get(0));
} catch (Exception e) { } catch (Exception e) {
Assertions.fail(); Assertions.fail();

View File

@ -62,13 +62,98 @@ public class ByteCode_Field {
} }
} }
// @Test @Test
// public void testFieldCount() { public void testMethodParameters() {
// Assertions.assertEquals(2, util.getFieldCount()); try {
// } Assertions.assertEquals(0, util.getMethodParameterCount("fieldAccess", new Class<?>[]{}));
// Assertions.assertEquals(1, util.getMethodParameterCount("setX", new Class<?>[]{int.class}));
// @Test Assertions.assertEquals("int", util.getMethodParameterTypes("setX", new Class<?>[]{int.class}).get(0));
// public void testFieldCount() { Assertions.assertEquals(1, util.getMethodParameterCount("setC", new Class<?>[]{char.class}));
// Assertions.assertEquals(2, util.getFieldCount()); Assertions.assertEquals("char", util.getMethodParameterTypes("setC", new Class<?>[]{char.class}).get(0));
// } } catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testFieldCount() {
Assertions.assertEquals(2, util.getFieldCount());
}
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("x"));
Assertions.assertTrue(util.getFieldNames().contains("c"));
}
@Test
public void testFieldTypes() {
try {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
Assertions.assertEquals("char", util.getFieldTypes().get(1));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testFieldValues() {
try {
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('\u0000', util.getFieldValue("c"));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeDefaultConstructor() {
try {
Object instance = util.invokeConstructor(new Class<?>[]{}, null);
Assertions.assertEquals(instance.getClass().getName(), "Field");
Assertions.assertEquals(0, util.getFieldValueOfObject(instance, "x"));
Assertions.assertEquals('\u0000', util.getFieldValueOfObject(instance, "c"));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeFieldAccess() {
try {
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('\u0000', util.getFieldValue("c"));
util.invokeMethod("fieldAccess", new Class<?>[]{}, new Object[]{});
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('a', util.getFieldValue("c"));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeSetXWith5() {
try {
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('\u0000', util.getFieldValue("c"));
util.invokeMethod("setX", new Class<?>[]{int.class}, new Object[]{5});
Assertions.assertEquals(5, util.getFieldValue("x"));
Assertions.assertEquals('\u0000', util.getFieldValue("c"));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeSetCWithH() {
try {
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('\u0000', util.getFieldValue("c"));
util.invokeMethod("setC", new Class<?>[]{char.class}, new Object[]{'h'});
Assertions.assertEquals(0, util.getFieldValue("x"));
Assertions.assertEquals('h', util.getFieldValue("c"));
} catch (Exception e) {
Assertions.fail();
}
}
} }

View File

@ -3,174 +3,120 @@ package testResources.CodeGen.Features;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import testResources.CodeGen.BytecodeTestUtil;
import java.util.List; import java.util.List;
public class ByteCode_For { public class ByteCode_For {
public static TypedProgram get() {
return new TypedProgram( private BytecodeTestUtil util;
List.of(
new TypedClass( @BeforeEach
"For", public void setUp() {
List.of(), try {
List.of( util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/For.java"), "For");
new TypedMethod( } catch (Exception e) {
"testFor", throw new RuntimeException(e);
Type.VOID, }
List.of(), }
List.of(),
new TypedBlock( @Test
List.of( public void testConstructorCount() {
new TypedLocalVariable( Assertions.assertEquals(1, util.getConstructorCount());
"i", // default constructor
Type.INT }
),
new TypedLocalVariable( @Test
"j", public void testDefaultConstructor() {
Type.INT Assertions.assertEquals("For", util.getConstructorNames().get(0));
) Assertions.assertEquals(0, util.getConstructorParameterCount(0));
), try {
List.of( Assertions.assertEquals("For", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
new TypedFor( } catch (Exception e) {
new TypedAssignment( throw new RuntimeException(e);
new TypedIntLiteral( }
0, }
Type.INT
), @Test
new TypedFieldVarAccess( public void testMethodCount() {
false, Assertions.assertEquals(1, util.getMethodCount());
null, }
"i",
Type.INT @Test
), public void testMethodNames() {
Type.INT Assertions.assertTrue(util.getMethodNames().contains("testFor"));
), }
new TypedBinary(
new TypedFieldVarAccess( @Test
false, public void testMethodReturnType() {
null, try {
"i", Assertions.assertEquals("void", util.getMethodReturnType("testFor", new Class<?>[]{}));
Type.INT } catch (Exception e) {
), Assertions.fail();
Operator.LT, }
new TypedIntLiteral( }
10,
Type.INT @Test
), public void testMethodParameters() {
Type.BOOL try {
), Assertions.assertEquals(0, util.getMethodParameterCount("testFor"));
new TypedAssignment( } catch (Exception e) {
new TypedBinary( Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"i", @Test
Type.INT public void testFieldCount() {
), Assertions.assertEquals(2, util.getFieldCount());
Operator.ADD, }
new TypedIntLiteral(
1, @Test
Type.INT public void testFieldNames() {
), Assertions.assertTrue(util.getFieldNames().contains("repetitionsFirstFor"));
Type.INT Assertions.assertTrue(util.getFieldNames().contains("repetitionsSecondFor"));
), }
new TypedFieldVarAccess(
false, @Test
null, public void testFieldTypes() {
"i", Assertions.assertEquals("int", util.getFieldTypes().get(0));
Type.INT Assertions.assertEquals("int", util.getFieldTypes().get(1));
), }
Type.INT
), @Test
new TypedBlock( public void testFieldValues() {
List.of(), try {
List.of(), Assertions.assertEquals(0, util.getFieldValue("repetitionsFirstFor"));
Type.VOID Assertions.assertEquals(0, util.getFieldValue("repetitionsSecondFor"));
), } catch (Exception e) {
Type.VOID Assertions.fail();
), }
new TypedFor( }
new TypedAssignment(
new TypedIntLiteral( @Test
0, public void testInvokeDefaultConstructor() {
Type.INT try {
), Object instance = util.invokeConstructor(new Class<?>[]{}, null);
new TypedFieldVarAccess( Assertions.assertEquals(instance.getClass().getName(), "For");
false, Assertions.assertEquals(0, util.getFieldValueOfObject(instance, "repetitionsFirstFor"));
null, Assertions.assertEquals(0, util.getFieldValueOfObject(instance, "repetitionsSecondFor"));
"j", } catch (Exception e) {
Type.INT Assertions.fail();
), }
Type.INT }
),
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeMethod() {
false, try {
null, Assertions.assertEquals(0, util.getFieldValue("repetitionsFirstFor"));
"j", Assertions.assertEquals(0, util.getFieldValue("repetitionsSecondFor"));
Type.INT util.invokeMethod("testFor", new Class<?>[]{}, new Object[]{});
), Assertions.assertEquals(45, util.getFieldValue("repetitionsFirstFor"));
Operator.LT, Assertions.assertEquals(45, util.getFieldValue("repetitionsSecondFor"));
new TypedIntLiteral( } catch (Exception e) {
10, Assertions.fail();
Type.INT }
),
Type.BOOL
),
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"j",
Type.INT
),
Type.INT
),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID
)
)
)
)
),
List.of(
new TypedConstructor(
"For",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
null,
Type.REFERENCE("For")
)
),
null
);
} }
} }

View File

@ -2,85 +2,133 @@ package testResources.CodeGen.Features;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import testResources.CodeGen.BytecodeTestUtil;
import java.util.List; import java.util.List;
public class ByteCode_If { public class ByteCode_If {
public static TypedProgram get() {
return new TypedProgram( private BytecodeTestUtil util;
List.of(
new TypedClass( @BeforeEach
"If", public void setUp() {
List.of(), try {
List.of( util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/If.java"), "If");
new TypedMethod( } catch (Exception e) {
"ifMethod", throw new RuntimeException(e);
Type.VOID, }
List.of(), }
List.of(),
new TypedBlock( @Test
List.of(), public void testConstructorCount() {
List.of( Assertions.assertEquals(1, util.getConstructorCount());
new TypedIfElse( // default constructor
new TypedBoolLiteral( }
false,
Type.BOOL @Test
), public void testDefaultConstructor() {
new TypedBlock( Assertions.assertEquals("If", util.getConstructorNames().get(0));
List.of(), Assertions.assertEquals(0, util.getConstructorParameterCount(0));
List.of(), try {
Type.VOID Assertions.assertEquals("If", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
), } catch (Exception e) {
new TypedBlock( throw new RuntimeException(e);
List.of(), }
List.of( }
new TypedIfElse(
new TypedBoolLiteral( @Test
true, public void testMethodCount() {
Type.BOOL Assertions.assertEquals(1, util.getMethodCount());
), }
new TypedBlock(
List.of(), @Test
List.of(), public void testMethodNames() {
Type.VOID Assertions.assertTrue(util.getMethodNames().contains("ifMethod"));
), }
new TypedBlock(
List.of(), @Test
List.of(), public void testMethodReturnType() {
Type.VOID try {
), Assertions.assertEquals("int",
Type.VOID util.getMethodReturnType("ifMethod", new Class<?>[]{boolean.class, boolean.class}));
) } catch (Exception e) {
), Assertions.fail();
Type.VOID }
), }
Type.VOID
) @Test
), public void testMethodParameters() {
Type.VOID try {
) Assertions.assertEquals(2,
) util.getMethodParameterCount("ifMethod", new Class<?>[]{boolean.class, boolean.class}));
), Assertions.assertEquals("boolean",
List.of( util.getMethodParameterTypes("ifMethod", new Class<?>[]{boolean.class, boolean.class}).get(0));
new TypedConstructor( Assertions.assertEquals("boolean",
"If", util.getMethodParameterTypes("ifMethod", new Class<?>[]{boolean.class, boolean.class}).get(1));
List.of(), } catch (Exception e) {
new TypedBlock( Assertions.fail();
List.of(), }
List.of(), }
Type.VOID
), @Test
Type.VOID, public void testFieldCount() {
List.of() Assertions.assertEquals(0, util.getFieldCount());
) }
),
null, @Test
null, public void testInvokeDefaultConstructor() {
null, try {
Type.REFERENCE("If") Object instance = util.invokeConstructor(new Class<?>[]{}, null);
) Assertions.assertEquals(instance.getClass().getName(), "If");
), } catch (Exception e) {
null Assertions.fail();
); }
}
@Test
public void testInvokeIfMethodWithTrueTrue() {
try {
int returnValue = (int) util.invokeMethod("ifMethod",
new Class<?>[]{boolean.class, boolean.class}, true, true);
Assertions.assertEquals(1, returnValue);
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeIfMethodWithTrueFalse() {
try {
int returnValue = (int) util.invokeMethod("ifMethod",
new Class<?>[]{boolean.class, boolean.class}, true, false);
Assertions.assertEquals(1, returnValue);
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeIfMethodWithFalseTrue() {
try {
int returnValue = (int) util.invokeMethod("ifMethod",
new Class<?>[]{boolean.class, boolean.class}, false, true);
Assertions.assertEquals(2, returnValue);
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeIfMethodWithFalseFalse() {
try {
int returnValue = (int) util.invokeMethod("ifMethod",
new Class<?>[]{boolean.class, boolean.class}, false, false);
Assertions.assertEquals(3, returnValue);
} catch (Exception e) {
Assertions.fail();
}
} }
} }

View File

@ -3,566 +3,414 @@ package testResources.CodeGen.Features;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import testResources.CodeGen.BytecodeTestUtil;
import java.util.List; import java.util.List;
public class ByteCode_LogicExpr { public class ByteCode_LogicExpr {
public static TypedProgram get() {
return new TypedProgram( private BytecodeTestUtil util;
List.of(
new TypedClass( @BeforeEach
"LogicExpr", public void setUp() {
List.of(), try {
List.of( util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/LogicExpr.java"), "LogicExpr");
new TypedMethod( } catch (Exception e) {
"test", throw new RuntimeException(e);
Type.BOOL, }
List.of(), }
List.of(),
new TypedBlock( @Test
List.of( public void testConstructorCount() {
new TypedLocalVariable( Assertions.assertEquals(1, util.getConstructorCount());
"x", // default constructor
Type.INT }
),
new TypedLocalVariable( @Test
"y", public void testDefaultConstructor() {
Type.INT Assertions.assertEquals("LogicExpr", util.getConstructorNames().get(0));
) Assertions.assertEquals(0, util.getConstructorParameterCount(0));
), try {
List.of( Assertions.assertEquals("LogicExpr", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
new TypedAssignment( } catch (Exception e) {
new TypedIntLiteral( throw new RuntimeException(e);
10, }
Type.INT }
),
new TypedFieldVarAccess( @Test
false, public void testMethodCount() {
null, Assertions.assertEquals(8, util.getMethodCount());
"x", }
Type.INT
), @Test
Type.INT public void testMethodNames() {
), Assertions.assertTrue(util.getMethodNames().contains("testSmaller"));
new TypedAssignment( Assertions.assertTrue(util.getMethodNames().contains("testLarger"));
new TypedIntLiteral( Assertions.assertTrue(util.getMethodNames().contains("testEqual"));
20, Assertions.assertTrue(util.getMethodNames().contains("testNotEqual"));
Type.INT Assertions.assertTrue(util.getMethodNames().contains("testSmallerEqual"));
), Assertions.assertTrue(util.getMethodNames().contains("testLargerEqual"));
new TypedFieldVarAccess( Assertions.assertTrue(util.getMethodNames().contains("testAND"));
false, Assertions.assertTrue(util.getMethodNames().contains("testOR"));
null, }
"y",
Type.INT @Test
), public void testMethodReturnType() {
Type.INT try {
), Assertions.assertEquals(1, util.getMethodParameterCount("testSmaller", new Class<?>[]{int.class, int.class}));
new TypedReturn( Assertions.assertEquals("boolean", util.getMethodReturnType("testSmaller", new Class<?>[]{int.class, int.class}));
new TypedBinary( Assertions.assertEquals(1, util.getMethodParameterCount("testLarger", new Class<?>[]{int.class, int.class}));
new TypedFieldVarAccess( Assertions.assertEquals("boolean", util.getMethodReturnType("testLarger", new Class<?>[]{int.class, int.class}));
false, Assertions.assertEquals(1, util.getMethodParameterCount("testEqual", new Class<?>[]{int.class, int.class}));
null, Assertions.assertEquals("boolean", util.getMethodReturnType("testEqual", new Class<?>[]{int.class, int.class}));
"x", Assertions.assertEquals(1, util.getMethodParameterCount("testNotEqual", new Class<?>[]{int.class, int.class}));
Type.INT Assertions.assertEquals("boolean", util.getMethodReturnType("testNotEqual", new Class<?>[]{int.class, int.class}));
), Assertions.assertEquals(1, util.getMethodParameterCount("testSmallerEqual", new Class<?>[]{int.class, int.class}));
Operator.LT, Assertions.assertEquals("boolean", util.getMethodReturnType("testSmallerEqual", new Class<?>[]{int.class, int.class}));
new TypedFieldVarAccess( Assertions.assertEquals(1, util.getMethodParameterCount("testLargerEqual", new Class<?>[]{int.class, int.class}));
false, Assertions.assertEquals("boolean", util.getMethodReturnType("testLargerEqual", new Class<?>[]{int.class, int.class}));
null, Assertions.assertEquals(1, util.getMethodParameterCount("testAND", new Class<?>[]{boolean.class, boolean.class}));
"y", Assertions.assertEquals("boolean", util.getMethodReturnType("testAND", new Class<?>[]{boolean.class, boolean.class}));
Type.INT Assertions.assertEquals(1, util.getMethodParameterCount("testOR", new Class<?>[]{boolean.class, boolean.class}));
), Assertions.assertEquals("boolean", util.getMethodReturnType("testOR", new Class<?>[]{boolean.class, boolean.class}));
Type.BOOL } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
) }
),
Type.BOOL @Test
) public void testMethodParameters() {
), try {
new TypedMethod( Assertions.assertEquals(2, util.getMethodParameterCount("testSmaller", new Class<?>[]{int.class, int.class}));
"test2", Assertions.assertEquals("int", util.getMethodParameterTypes("testSmaller", new Class<?>[]{int.class, int.class}).get(0));
Type.BOOL, Assertions.assertEquals("int", util.getMethodParameterTypes("testSmaller", new Class<?>[]{int.class, int.class}).get(1));
List.of(), Assertions.assertEquals(2, util.getMethodParameterCount("testLarger", new Class<?>[]{int.class, int.class}));
List.of(), Assertions.assertEquals("int", util.getMethodParameterTypes("testLarger", new Class<?>[]{int.class, int.class}).get(0));
new TypedBlock( Assertions.assertEquals("int", util.getMethodParameterTypes("testLarger", new Class<?>[]{int.class, int.class}).get(1));
List.of( Assertions.assertEquals(2, util.getMethodParameterCount("testEqual", new Class<?>[]{int.class, int.class}));
new TypedLocalVariable( Assertions.assertEquals("int", util.getMethodParameterTypes("testEqual", new Class<?>[]{int.class, int.class}).get(0));
"x", Assertions.assertEquals("int", util.getMethodParameterTypes("testEqual", new Class<?>[]{int.class, int.class}).get(1));
Type.INT Assertions.assertEquals(2, util.getMethodParameterCount("testNotEqual", new Class<?>[]{int.class, int.class}));
), Assertions.assertEquals("int", util.getMethodParameterTypes("testNotEqual", new Class<?>[]{int.class, int.class}).get(0));
new TypedLocalVariable( Assertions.assertEquals("int", util.getMethodParameterTypes("testNotEqual", new Class<?>[]{int.class, int.class}).get(1));
"y", Assertions.assertEquals(2, util.getMethodParameterCount("testSmallerEqual", new Class<?>[]{int.class, int.class}));
Type.INT Assertions.assertEquals("int", util.getMethodParameterTypes("testSmallerEqual", new Class<?>[]{int.class, int.class}).get(0));
) Assertions.assertEquals("int", util.getMethodParameterTypes("testSmallerEqual", new Class<?>[]{int.class, int.class}).get(1));
), Assertions.assertEquals(2, util.getMethodParameterCount("testLargerEqual", new Class<?>[]{int.class, int.class}));
List.of( Assertions.assertEquals("int", util.getMethodParameterTypes("testLargerEqual", new Class<?>[]{int.class, int.class}).get(0));
new TypedAssignment( Assertions.assertEquals("int", util.getMethodParameterTypes("testLargerEqual", new Class<?>[]{int.class, int.class}).get(1));
new TypedIntLiteral( Assertions.assertEquals(2, util.getMethodParameterCount("testAND", new Class<?>[]{boolean.class, boolean.class}));
10, Assertions.assertEquals("boolean", util.getMethodParameterTypes("testAND", new Class<?>[]{boolean.class, boolean.class}).get(0));
Type.INT Assertions.assertEquals("boolean", util.getMethodParameterTypes("testAND", new Class<?>[]{boolean.class, boolean.class}).get(1));
), Assertions.assertEquals(2, util.getMethodParameterCount("testOR", new Class<?>[]{boolean.class, boolean.class}));
new TypedFieldVarAccess( Assertions.assertEquals("boolean", util.getMethodParameterTypes("testOR", new Class<?>[]{boolean.class, boolean.class}).get(0));
false, Assertions.assertEquals("boolean", util.getMethodParameterTypes("testOR", new Class<?>[]{boolean.class, boolean.class}).get(1));
null, } catch (Exception e) {
"x", Assertions.fail();
Type.INT }
), }
Type.INT
), @Test
new TypedAssignment( public void testFieldCount() {
new TypedIntLiteral( Assertions.assertEquals(0, util.getFieldCount());
20, }
Type.INT
), @Test
new TypedFieldVarAccess( public void testInvokeDefaultConstructor() {
false, try {
null, Object instance = util.invokeConstructor(new Class<?>[]{}, null);
"y", Assertions.assertEquals(instance.getClass().getName(), "LogicExpr");
Type.INT } catch (Exception e) {
), Assertions.fail();
Type.INT }
), }
new TypedReturn(
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeSmallerWith4And5() {
false, try {
null, boolean returnValue = (boolean) util.invokeMethod(
"x", "testSmaller", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
Type.INT Assertions.assertTrue(returnValue);
), } catch (Exception e) {
Operator.GT, Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"y", @Test
Type.INT public void testInvokeSmallerWith5And4() {
), try {
Type.BOOL boolean returnValue = (boolean) util.invokeMethod(
), "testSmaller", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
Type.BOOL Assertions.assertFalse(returnValue);
) } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
) }
),
new TypedMethod( @Test
"test3", public void testInvokeSmallerWith4And4() {
Type.BOOL, try {
List.of(), boolean returnValue = (boolean) util.invokeMethod(
List.of(), "testSmaller", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
new TypedBlock( Assertions.assertFalse(returnValue);
List.of( } catch (Exception e) {
new TypedLocalVariable( Assertions.fail();
"x", }
Type.INT }
),
new TypedLocalVariable( @Test
"y", public void testInvokeLargerWith4And5() {
Type.INT try {
) boolean returnValue = (boolean) util.invokeMethod(
), "testLarger", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
List.of( Assertions.assertFalse(returnValue);
new TypedAssignment( } catch (Exception e) {
new TypedIntLiteral( Assertions.fail();
10, }
Type.INT }
),
new TypedFieldVarAccess( @Test
false, public void testInvokeLargerWith5And4() {
null, try {
"x", boolean returnValue = (boolean) util.invokeMethod(
Type.INT "testLarger", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
), Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
new TypedAssignment( }
new TypedIntLiteral( }
20,
Type.INT @Test
), public void testInvokeLargerWith4And4() {
new TypedFieldVarAccess( try {
false, boolean returnValue = (boolean) util.invokeMethod(
null, "testLarger", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
"y", Assertions.assertFalse(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
Type.INT }
), }
new TypedReturn(
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeEqualWith4And5() {
false, try {
null, boolean returnValue = (boolean) util.invokeMethod(
"x", "testEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
Type.INT Assertions.assertFalse(returnValue);
), } catch (Exception e) {
Operator.EQ, Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"y", @Test
Type.INT public void testInvokeEqualWith5And4() {
), try {
Type.BOOL boolean returnValue = (boolean) util.invokeMethod(
), "testEqual", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
Type.BOOL Assertions.assertFalse(returnValue);
) } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
) }
),
new TypedMethod( @Test
"test4", public void testInvokeEqualWith4And4() {
Type.BOOL, try {
List.of(), boolean returnValue = (boolean) util.invokeMethod(
List.of(), "testEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
new TypedBlock( Assertions.assertTrue(returnValue);
List.of( } catch (Exception e) {
new TypedLocalVariable( Assertions.fail();
"x", }
Type.INT }
),
new TypedLocalVariable( @Test
"y", public void testInvokeNotEqualWith4And5() {
Type.INT try {
) boolean returnValue = (boolean) util.invokeMethod(
), "testNotEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
List.of( Assertions.assertTrue(returnValue);
new TypedAssignment( } catch (Exception e) {
new TypedIntLiteral( Assertions.fail();
10, }
Type.INT }
),
new TypedFieldVarAccess( @Test
false, public void testInvokeNotEqualWith5And4() {
null, try {
"x", boolean returnValue = (boolean) util.invokeMethod(
Type.INT "testNotEqual", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
), Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
new TypedAssignment( }
new TypedIntLiteral( }
20,
Type.INT @Test
), public void testInvokeNotEqualWith4And4() {
new TypedFieldVarAccess( try {
false, boolean returnValue = (boolean) util.invokeMethod(
null, "testNotEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
"y", Assertions.assertFalse(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
Type.INT }
), }
new TypedReturn(
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeSmallerEqualWith4And5() {
false, try {
null, boolean returnValue = (boolean) util.invokeMethod(
"x", "testSmallerEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
Type.INT Assertions.assertTrue(returnValue);
), } catch (Exception e) {
Operator.NE, Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"y", @Test
Type.INT public void testInvokeSmallerEqualWith5And4() {
), try {
Type.BOOL boolean returnValue = (boolean) util.invokeMethod(
), "testSmallerEqual", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
Type.BOOL Assertions.assertFalse(returnValue);
) } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
) }
),
new TypedMethod( @Test
"test5", public void testInvokeSmallerEqualWith4And4() {
Type.BOOL, try {
List.of(), boolean returnValue = (boolean) util.invokeMethod(
List.of(), "testSmallerEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
new TypedBlock( Assertions.assertTrue(returnValue);
List.of( } catch (Exception e) {
new TypedLocalVariable( Assertions.fail();
"x", }
Type.INT }
),
new TypedLocalVariable( @Test
"y", public void testInvokeLargerEqualWith4And5() {
Type.INT try {
) boolean returnValue = (boolean) util.invokeMethod(
), "testLargerEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 5});
List.of( Assertions.assertFalse(returnValue);
new TypedAssignment( } catch (Exception e) {
new TypedIntLiteral( Assertions.fail();
10, }
Type.INT }
),
new TypedFieldVarAccess( @Test
false, public void testInvokeLargerEqualWith5And4() {
null, try {
"x", boolean returnValue = (boolean) util.invokeMethod(
Type.INT "testLargerEqual", new Class<?>[]{int.class, int.class}, new Object[]{5, 4});
), Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
new TypedAssignment( }
new TypedIntLiteral( }
20,
Type.INT @Test
), public void testInvokeLargerEqualWith4And4() {
new TypedFieldVarAccess( try {
false, boolean returnValue = (boolean) util.invokeMethod(
null, "testLargerEqual", new Class<?>[]{int.class, int.class}, new Object[]{4, 4});
"y", Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
Type.INT }
), }
new TypedReturn(
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeANDWithTrueAndTrue() {
false, try {
null, boolean returnValue = (boolean) util.invokeMethod(
"x", "testAND", new Class<?>[]{boolean.class, boolean.class}, new Object[]{true, true});
Type.INT Assertions.assertTrue(returnValue);
), } catch (Exception e) {
Operator.LE, Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"y", @Test
Type.INT public void testInvokeANDWithTrueAndFalse() {
), try {
Type.BOOL boolean returnValue = (boolean) util.invokeMethod(
), "testAND", new Class<?>[]{boolean.class, boolean.class}, new Object[]{true, false});
Type.BOOL Assertions.assertFalse(returnValue);
) } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
) }
),
new TypedMethod( @Test
"test6", public void testInvokeANDWithFalseAndTrue() {
Type.BOOL, try {
List.of(), boolean returnValue = (boolean) util.invokeMethod(
List.of(), "testAND", new Class<?>[]{boolean.class, boolean.class}, new Object[]{false, true});
new TypedBlock( Assertions.assertFalse(returnValue);
List.of( } catch (Exception e) {
new TypedLocalVariable( Assertions.fail();
"x", }
Type.INT }
),
new TypedLocalVariable( @Test
"y", public void testInvokeANDWithFalseAndFalse() {
Type.INT try {
) boolean returnValue = (boolean) util.invokeMethod(
), "testAND", new Class<?>[]{boolean.class, boolean.class}, new Object[]{false, false});
List.of( Assertions.assertFalse(returnValue);
new TypedAssignment( } catch (Exception e) {
new TypedIntLiteral( Assertions.fail();
10, }
Type.INT }
),
new TypedFieldVarAccess( @Test
false, public void testInvokeORWithTrueAndTrue() {
null, try {
"x", boolean returnValue = (boolean) util.invokeMethod(
Type.INT "testOR", new Class<?>[]{boolean.class, boolean.class}, new Object[]{true, true});
), Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
new TypedAssignment( }
new TypedIntLiteral( }
20,
Type.INT @Test
), public void testInvokeORWithTrueAndFalse() {
new TypedFieldVarAccess( try {
false, boolean returnValue = (boolean) util.invokeMethod(
null, "testOR", new Class<?>[]{boolean.class, boolean.class}, new Object[]{true, false});
"y", Assertions.assertTrue(returnValue);
Type.INT } catch (Exception e) {
), Assertions.fail();
Type.INT }
), }
new TypedReturn(
new TypedBinary( @Test
new TypedFieldVarAccess( public void testInvokeORWithFalseAndTrue() {
false, try {
null, boolean returnValue = (boolean) util.invokeMethod(
"x", "testOR", new Class<?>[]{boolean.class, boolean.class}, new Object[]{false, true});
Type.INT Assertions.assertTrue(returnValue);
), } catch (Exception e) {
Operator.GE, Assertions.fail();
new TypedFieldVarAccess( }
false, }
null,
"y", @Test
Type.INT public void testInvokeORWithFalseAndFalse() {
), try {
Type.BOOL boolean returnValue = (boolean) util.invokeMethod(
), "testOR", new Class<?>[]{boolean.class, boolean.class}, new Object[]{false, false});
Type.BOOL Assertions.assertFalse(returnValue);
) } catch (Exception e) {
), Assertions.fail();
Type.BOOL }
)
),
new TypedMethod(
"test7",
Type.BOOL,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"x",
Type.BOOL
),
new TypedLocalVariable(
"y",
Type.BOOL
)
),
List.of(
new TypedAssignment(
new TypedBoolLiteral(
true,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"x",
Type.BOOL
),
Type.BOOL
),
new TypedAssignment(
new TypedBoolLiteral(
false,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.BOOL
),
Type.BOOL
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"x",
Type.BOOL
),
Operator.AND,
new TypedFieldVarAccess(
false,
null,
"y",
Type.BOOL
),
Type.BOOL
),
Type.BOOL
)
),
Type.BOOL
)
),
new TypedMethod(
"test8",
Type.BOOL,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"x",
Type.BOOL
),
new TypedLocalVariable(
"y",
Type.BOOL
)
),
List.of(
new TypedAssignment(
new TypedBoolLiteral(
true,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"x",
Type.BOOL
),
Type.BOOL
),
new TypedAssignment(
new TypedBoolLiteral(
false,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"y",
Type.BOOL
),
Type.BOOL
),
new TypedReturn(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"x",
Type.BOOL
),
Operator.OR,
new TypedFieldVarAccess(
false,
null,
"y",
Type.BOOL
),
Type.BOOL
),
Type.BOOL
)
),
Type.BOOL
)
)
),
List.of(
new TypedConstructor(
"LogicExpr",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
null,
Type.REFERENCE("LogicExpr")
)
),
null
);
} }
} }

View File

@ -1,21 +1,16 @@
public class For { public class For {
int repititionsFirtsFor; int repetitionsFirstFor;
int repititionsSecondFor; int repetitionsSecondFor;
public For() {
this.repititionsFirtsFor = 0;
this.repititionsSecondFor = 0;
}
public void testFor() { public void testFor() {
this.repititionsFirtsFor = 0; this.repetitionsFirstFor = 0;
for (int i = 0; i < 10; i = i+1) { for (int i = 0; i < 10; i = i+1) {
this.repititionsFirtsFor = this.repititionsFirtsFor + i; this.repetitionsFirstFor = this.repetitionsFirstFor + i;
} }
this.repititionsSecondFor = 0; this.repetitionsSecondFor = 0;
int j; int j;
for (j = 0; j < 10; j += 1) { for (j = 0; j < 10; j += 1) {
this.repititionsSecondFor = this.repititionsSecondFor + j; this.repetitionsSecondFor = this.repetitionsSecondFor + j;
} }
} }
} }