Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3d246af387
@ -3,12 +3,12 @@ grammar Decaf;
|
||||
program: classdecl+;
|
||||
|
||||
//class identifier{...}
|
||||
classdecl: (AccessModifierPrivate|AccessModifierPublic|AccessModifierProtected)? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)* ClosedCurlyBracket;
|
||||
constuctorDecl: (AccessModifierPrivate|AccessModifierPublic|AccessModifierProtected)? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Maybe not needed
|
||||
classdecl: AccessModifierPublic? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)* ClosedCurlyBracket;
|
||||
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Maybe not needed
|
||||
|
||||
//Method and FieldVar
|
||||
methodDecl: MainMethodDecl block | (AccessModifierPrivate|AccessModifierPublic|AccessModifierProtected)? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
||||
fieldDecl: (AccessModifierPrivate|AccessModifierPublic|AccessModifierProtected)? type Identifier Semicolon;
|
||||
methodDecl: MainMethodDecl block | AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
||||
fieldDecl: AccessModifierPublic? type Identifier Semicolon;
|
||||
|
||||
//Parameters
|
||||
parameterList: parameter(Comma parameter)*;
|
||||
@ -57,8 +57,6 @@ value: IntValue | BooleanValue | CharValue | NullValue;
|
||||
|
||||
//Access modifier
|
||||
AccessModifierPublic : 'public' ;
|
||||
AccessModifierPrivate : 'private';
|
||||
AccessModifierProtected : 'protected';
|
||||
MainMethodDecl : 'public static void main(String[] args)';
|
||||
|
||||
//Types
|
||||
|
@ -38,7 +38,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
right.CodeGen(mv);
|
||||
|
||||
if (left instanceof VarRefExpression varRef) {
|
||||
//TODO: Implement the handling of a variable reference --> I need a lis of local variables
|
||||
//TODO: Implement the handling of a variable reference --> I need a list of local variables
|
||||
// for that to determine if the variable is a local or field variable
|
||||
} else if (left instanceof InstVarExpression instVar) {
|
||||
mv.visitInsn(Opcodes.DUP_X1);
|
||||
|
@ -0,0 +1,10 @@
|
||||
package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import java.util.List;
|
||||
|
||||
public class SuperStatementExpression extends MethodCallStatementExpression{
|
||||
public SuperStatementExpression(String methodName, List<IExpression> arguments) {
|
||||
super(methodName, arguments);
|
||||
}
|
||||
}
|
273
src/test/java/AST/TestRunner.java
Normal file
273
src/test/java/AST/TestRunner.java
Normal file
@ -0,0 +1,273 @@
|
||||
package AST;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import Helper.MockGenerator;
|
||||
import Helper.Resources;
|
||||
import common.AccessModifier;
|
||||
import common.BaseType;
|
||||
import common.Compiler;
|
||||
import common.Primitives;
|
||||
import common.PrintableVector;
|
||||
import syntaxtree.structure.ClassDecl;
|
||||
import syntaxtree.structure.ConstructorDecl;
|
||||
import syntaxtree.structure.FieldDecl;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
@DisplayName("Abstract Syntax Tree Generation")
|
||||
public class TestRunner {
|
||||
|
||||
@Test
|
||||
@DisplayName("Control Test")
|
||||
void controlTest() {
|
||||
var first = MockGenerator.getConstructorParameterAst();
|
||||
var second = MockGenerator.getConstructorParameterAst();
|
||||
|
||||
assertEquals(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty Class")
|
||||
void emptyClass() {
|
||||
InputStream file = Resources.getFileAsStream("SimpleTests/EmptyClass.java");
|
||||
Program ast = Compiler.getFactory().getAstAdapter().getAst(file);
|
||||
PrintableVector<ConstructorDecl> constructors = new PrintableVector<>();
|
||||
constructors.add(new ConstructorDecl());
|
||||
ClassDecl classDecl = new ClassDecl("EmptyClass", new PrintableVector<>(), constructors,
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(classDecl);
|
||||
var generatedAst = new Program(classDecls);
|
||||
|
||||
assertEquals(generatedAst, ast);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EmptyClassWithConstructor")
|
||||
void emptyClassWithConstructor() {
|
||||
InputStream file = Resources.getFileAsStream("SimpleTests/EmptyClassWithConstructor.java");
|
||||
Program generatedAst = Compiler.getFactory().getAstAdapter().getAst(file);
|
||||
|
||||
PrintableVector<ConstructorDecl> constructors = new PrintableVector<>();
|
||||
constructors.add(new ConstructorDecl());
|
||||
ClassDecl classDecl = new ClassDecl("EmptyClassWithConstructor", new PrintableVector<>(), constructors,
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(classDecl);
|
||||
var ast = new Program(classDecls);
|
||||
assertEquals(ast, generatedAst);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields")
|
||||
void classFields() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ClassFields.java");
|
||||
|
||||
Program expectedAst = MockGenerator.getClassFieldsAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassField without AccessModifier")
|
||||
void classFieldWithoutAccessModifier() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/AutoAccessModifierField.java");
|
||||
|
||||
Program expectedAst = MockGenerator.getAutoClassFieldAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Comments")
|
||||
void commentTest() {
|
||||
InputStream file = Resources.getFileAsStream("SimpleTests/Comments.java");
|
||||
Program generatedAst = Compiler.getFactory().getAstAdapter().getAst(file);
|
||||
|
||||
PrintableVector<ConstructorDecl> constructors = new PrintableVector<>();
|
||||
constructors.add(new ConstructorDecl());
|
||||
PrintableVector<FieldDecl> fields = new PrintableVector<>();
|
||||
|
||||
FieldDecl lorem = new FieldDecl("lorem", AccessModifier.PRIVATE);
|
||||
lorem.setType(new BaseType(Primitives.INT));
|
||||
fields.add(lorem);
|
||||
|
||||
FieldDecl ipsum = new FieldDecl("ipsum", AccessModifier.PRIVATE);
|
||||
ipsum.setType(new BaseType(Primitives.BOOL));
|
||||
fields.add(ipsum);
|
||||
|
||||
ClassDecl classDecl = new ClassDecl("Comments", fields, constructors, new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(classDecl);
|
||||
var expectedAst = new Program(classDecls);
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With Parameters")
|
||||
void constructorWithParameters() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ConstructorParams.java");
|
||||
Program expectedAst = MockGenerator.getConstructorParameterAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With this. assign body")
|
||||
void constructorWithThisAssignBody() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ConstructorThisDot.java");
|
||||
Program expectedAst = MockGenerator.getConstructorThisDotAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("VoidMethod")
|
||||
void voidMethod() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/VoidMethod.java");
|
||||
Program expectedAst = MockGenerator.getVoidMethodAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("RealConstructor")
|
||||
void realConstructor() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/RealConstructor.java");
|
||||
Program expectedAst = MockGenerator.getRealConstructorAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MethodCall")
|
||||
void methodCall() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/MethodCall.java");
|
||||
Program expectedAst = MockGenerator.getMethodCallAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ThisDotMethodCall")
|
||||
void thisDotMethodCall() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ThisDotMethodCall.java");
|
||||
Program expectedAst = MockGenerator.getThisDotMethodCallAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MethodCallWithParameters")
|
||||
void methodCallWithParameters() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/MethodCallParams.java");
|
||||
Program expectedAst = MockGenerator.getMethodCallWithParameterAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("GetterFunction")
|
||||
void getterFunction() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/GetterFunction.java");
|
||||
Program expectedAst = MockGenerator.getGetterFunctionAst();
|
||||
|
||||
System.out.println(generatedAst);
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("CharArgument")
|
||||
void charArgument() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/CharArgument.java");
|
||||
Program expectedAst = MockGenerator.getCharArgumentAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ExplicitNullAssign")
|
||||
void explicitNullAssign() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ExplicitNullAssign.java");
|
||||
Program expectedAst = MockGenerator.getExplicitNullAssignAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SelfReference")
|
||||
void selfReference() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/SelfReference.java");
|
||||
Program expectedAst = MockGenerator.getSelfReferenceAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ValueAdapterTests")
|
||||
void valueAdapterTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ValueAdapterTests.java");
|
||||
Program expectedAst = MockGenerator.getValueAdapterTestAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("System.out.println Test")
|
||||
void systemOutPrintlnTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/SystemOutPrintln.java");
|
||||
Program expectedAst = MockGenerator.getSystemOutPrintlnAst();
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("System.out.print-String Test")
|
||||
void systemOutPrintStringTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/SystemOutPrintlnString.java");
|
||||
Program expectedAst = MockGenerator.getSystemOutPrintStringAst();
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MainMethodTest")
|
||||
void mainMethodTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/MainMethodTest.java");
|
||||
Program expectedAst = MockGenerator.getMainMethodTestAst();
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ForTest")
|
||||
void forTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/ForTest.java");
|
||||
Program expectedAst = MockGenerator.getForTestAst();
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("IncTest")
|
||||
void incTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/IncTest.java");
|
||||
Program expectedAst = MockGenerator.getIncTestAst();
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("DecTest")
|
||||
void decTest() {
|
||||
Program generatedAst = Resources.getProgram("SimpleTests/DecTest.java");
|
||||
Program expectedAst = MockGenerator.getDecTestAst();
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
}
|
1254
src/test/java/All/TestRunner.java
Normal file
1254
src/test/java/All/TestRunner.java
Normal file
File diff suppressed because it is too large
Load Diff
356
src/test/java/CodeGen/TestRunner.java
Normal file
356
src/test/java/CodeGen/TestRunner.java
Normal file
@ -0,0 +1,356 @@
|
||||
package CodeGen;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import Helper.MockGenerator;
|
||||
import Helper.ReflectLoader;
|
||||
import Helper.Resources;
|
||||
import common.Compiler;
|
||||
import common.PrintableVector;
|
||||
import syntaxtree.structure.ClassDecl;
|
||||
import syntaxtree.structure.ConstructorDecl;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
@DisplayName("Bytecode Generation")
|
||||
public class TestRunner {
|
||||
|
||||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||
private final PrintStream originalOut = System.out;
|
||||
private final PrintStream originalErr = System.err;
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty Class")
|
||||
void main() {
|
||||
ClassDecl emptyClass = new ClassDecl("EmptyClass", new PrintableVector<>(), new PrintableVector<>(),
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(emptyClass);
|
||||
|
||||
var tast = new Program(classDecls);
|
||||
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("EmptyClass");
|
||||
Object o;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
assertEquals(o.getClass().getName(), "EmptyClass");
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EmptyClassWithConstructor")
|
||||
void emptyClassWithConstructor() {
|
||||
PrintableVector<ConstructorDecl> constructors = new PrintableVector<>();
|
||||
constructors.add(new ConstructorDecl());
|
||||
ClassDecl classDecl = new ClassDecl("EmptyClassWithConstructor", new PrintableVector<>(), constructors,
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(classDecl);
|
||||
var tast = new Program(classDecls);
|
||||
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("EmptyClassWithConstructor");
|
||||
Object o;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
assertEquals(o.getClass().getName(), "EmptyClassWithConstructor");
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With Parameters")
|
||||
void constructorWithParameters() {
|
||||
Program tast = MockGenerator.getConstructorParameterTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("ConstructorParams");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor(int.class).newInstance(1);
|
||||
assertEquals(o.getClass().getName(), "ConstructorParams");
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With this. assign body")
|
||||
void constructorWithThisAssignBody() {
|
||||
Program tast = MockGenerator.getConstructorThisDotTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("ConstructorThisDot");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var i = loader.getField("ConstructorThisDot", "i");
|
||||
var ivalue = i.get(o);
|
||||
assertEquals(5, ivalue);
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields - autoAccess")
|
||||
void classFieldsAuto() {
|
||||
Program tast = MockGenerator.getAutoClassFieldAst();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
try {
|
||||
var autoAccess = loader.getField("AutoAccessModifierField", "autoAccess");
|
||||
System.out.println(autoAccess.getModifiers());
|
||||
assertEquals(0, autoAccess.getModifiers());
|
||||
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields - privateAccess")
|
||||
void classFieldsPrivate() {
|
||||
Program tast = MockGenerator.getClassFieldsTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
try {
|
||||
var autoAccess = loader.getField("ClassFields", "privateAccess");
|
||||
assertEquals(Modifier.PRIVATE, autoAccess.getModifiers());
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields - publicAccess")
|
||||
void classFieldsPublic() {
|
||||
Program tast = MockGenerator.getClassFieldsTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
try {
|
||||
var autoAccess = loader.getField("ClassFields", "publicAccess");
|
||||
assertEquals(Modifier.PUBLIC, autoAccess.getModifiers());
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields - protectedAccess")
|
||||
void classFieldsProtected() {
|
||||
Program tast = MockGenerator.getClassFieldsTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
try {
|
||||
var autoAccess = loader.getField("ClassFields", "protectedAccess");
|
||||
|
||||
assertEquals(Modifier.PROTECTED, autoAccess.getModifiers());
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("VoidMethod")
|
||||
void voidMethod() {
|
||||
Program tast = MockGenerator.getVoidMethodTast();
|
||||
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("VoidMethod");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var m = loader.getMethod("VoidMethod", "foo");
|
||||
m.invoke(o);
|
||||
assertEquals("foo", m.getName());
|
||||
} catch (Exception e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("RealConstructor")
|
||||
void realConstructor() {
|
||||
Program tast = MockGenerator.getRealConstructorTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("RealConstructor");
|
||||
try {
|
||||
int randomI = 2;
|
||||
var constructor = c.getDeclaredConstructor(int.class);
|
||||
Object o = constructor.newInstance(randomI);
|
||||
var i = loader.getField("RealConstructor", "i");
|
||||
int ivalue = (int) i.get(o);
|
||||
assertEquals(randomI, ivalue);
|
||||
} catch (NoSuchFieldException e) {
|
||||
fail("No such field");
|
||||
} catch (Exception e) {
|
||||
fail(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MethodCall")
|
||||
void methodCall() {
|
||||
Program tast = MockGenerator.getMethodCallTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("MethodCall");
|
||||
Object o = null;
|
||||
int value = 1;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var i = loader.getField("MethodCall", "i");
|
||||
int ivalue = (int) i.get(o);
|
||||
assertEquals(value, ivalue);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MiniLinkedList")
|
||||
void miniLinkedList() {
|
||||
Program program = Resources.getProgram("SimpleTests/MiniLinkedList.java");
|
||||
|
||||
System.out.println(program);
|
||||
Program tast = Compiler.getFactory().getTastAdapter().getTast(program);
|
||||
Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SystemOutPrintln Test")
|
||||
void systemOutPrintlnTest() {
|
||||
Program tast = MockGenerator.getSystemOutPrintlnTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("SystemOutPrintln");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var m = loader.getMethod("SystemOutPrintln", "foo");
|
||||
m.invoke(o);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SystemOutPrintlnString Test")
|
||||
void systemOutPrintlnStringTest() {
|
||||
Program tast = MockGenerator.getSystemOutPrintStringTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("SystemOutPrintlnString");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var m = loader.getMethod("SystemOutPrintlnString", "foo");
|
||||
m.invoke(o);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MainMethodTest")
|
||||
void mainMethodTest() {
|
||||
Program tast = MockGenerator.getMainMethodTestTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("MainMethodTest");
|
||||
try {
|
||||
var m = c.getMethod("main", String[].class);
|
||||
m.invoke(null, new Object[] { new String[] {} });
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("IncTest")
|
||||
void incTest() {
|
||||
Program tast = MockGenerator.getIncTestTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("IncTest");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var foo = loader.getMethod("IncTest", "foo");
|
||||
var bar = loader.getMethod("IncTest", "bar");
|
||||
foo.invoke(o);
|
||||
bar.invoke(o);
|
||||
System.setOut(new PrintStream(outContent));
|
||||
foo.invoke(o);
|
||||
var expected = new String("0123456789").replaceAll("\\p{C}", "");
|
||||
var actual = new String(outContent.toByteArray()).replaceAll("\\p{C}", "");
|
||||
outContent.reset();
|
||||
assertEquals(expected, actual);
|
||||
bar.invoke(o);
|
||||
actual = new String(outContent.toByteArray()).replaceAll("\\p{C}", "");
|
||||
assertEquals(expected, actual);
|
||||
System.setOut(originalOut);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("DecTest")
|
||||
void decTest() {
|
||||
Program tast = MockGenerator.getDecTestTast();
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
ReflectLoader loader = new ReflectLoader(bc);
|
||||
Class<?> c = loader.findClass("DecTest");
|
||||
Object o = null;
|
||||
try {
|
||||
o = c.getDeclaredConstructor().newInstance();
|
||||
var foo = loader.getMethod("DecTest", "foo");
|
||||
var bar = loader.getMethod("DecTest", "bar");
|
||||
foo.invoke(o);
|
||||
bar.invoke(o);
|
||||
System.setOut(new PrintStream(outContent));
|
||||
foo.invoke(o);
|
||||
var expected = new String("10987654321").replaceAll("\\p{C}", "");
|
||||
var actual = new String(outContent.toByteArray()).replaceAll("\\p{C}", "");
|
||||
outContent.reset();
|
||||
assertEquals(expected, actual);
|
||||
bar.invoke(o);
|
||||
actual = new String(outContent.toByteArray()).replaceAll("\\p{C}", "");
|
||||
assertEquals(expected, actual);
|
||||
System.setOut(originalOut);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
965
src/test/java/Helper/MockGenerator.java
Normal file
965
src/test/java/Helper/MockGenerator.java
Normal file
@ -0,0 +1,965 @@
|
||||
package Helper;
|
||||
|
||||
import common.AccessModifier;
|
||||
import common.BaseType;
|
||||
import common.Operator;
|
||||
import common.Primitives;
|
||||
import common.PrintableVector;
|
||||
import common.ReferenceType;
|
||||
import syntaxtree.expressions.Binary;
|
||||
import syntaxtree.expressions.BoolExpr;
|
||||
import syntaxtree.expressions.CharExpr;
|
||||
import syntaxtree.expressions.IExpression;
|
||||
import syntaxtree.expressions.InstVar;
|
||||
import syntaxtree.expressions.IntegerExpr;
|
||||
import syntaxtree.expressions.LocalOrFieldVar;
|
||||
import syntaxtree.expressions.Null;
|
||||
import syntaxtree.expressions.StringExpr;
|
||||
import syntaxtree.expressions.This;
|
||||
import syntaxtree.statementexpression.Assign;
|
||||
import syntaxtree.statementexpression.CrementStmtExpr;
|
||||
import syntaxtree.statementexpression.MethodCall;
|
||||
import syntaxtree.statementexpression.NewDecl;
|
||||
import syntaxtree.statements.Block;
|
||||
import syntaxtree.statements.ForStmt;
|
||||
import syntaxtree.statements.IStatement;
|
||||
import syntaxtree.statements.LocalVarDecl;
|
||||
import syntaxtree.statements.ReturnStmt;
|
||||
import syntaxtree.structure.ClassDecl;
|
||||
import syntaxtree.structure.ConstructorDecl;
|
||||
import syntaxtree.structure.FieldDecl;
|
||||
import syntaxtree.structure.MainMethodDecl;
|
||||
import syntaxtree.structure.MethodDecl;
|
||||
import syntaxtree.structure.MethodParameter;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
public abstract class MockGenerator {
|
||||
|
||||
/**
|
||||
* @param className
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getEmptyProgram(String className) {
|
||||
|
||||
PrintableVector<ClassDecl> classes = new PrintableVector<>();
|
||||
classes.add(getEmptyClass(className));
|
||||
|
||||
return new Program(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return ClassDecl
|
||||
*/
|
||||
public static ClassDecl getEmptyClass(String id) {
|
||||
return new ClassDecl(id, new PrintableVector<>(), new PrintableVector<>(), new PrintableVector<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expressions
|
||||
* @return Block
|
||||
*/
|
||||
public static Block getBlock(IStatement... expressions) {
|
||||
PrintableVector<IStatement> expressionsVector = new PrintableVector<>();
|
||||
for (IStatement expression : expressions) {
|
||||
expressionsVector.add(expression);
|
||||
}
|
||||
return new Block(expressionsVector);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public static Block getEmptyBlock() {
|
||||
return new Block();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expressions
|
||||
* @return PrintableVector<IExpression>
|
||||
*/
|
||||
public static PrintableVector<IExpression> getArguments(IExpression... expressions) {
|
||||
PrintableVector<IExpression> arguments = new PrintableVector<>();
|
||||
for (IExpression expression : expressions) {
|
||||
arguments.add(expression);
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param constructors
|
||||
* @return PrintableVector<ConstructorDecl>
|
||||
*/
|
||||
public static PrintableVector<ConstructorDecl> getConstructors(ConstructorDecl... constructors) {
|
||||
PrintableVector<ConstructorDecl> cons = new PrintableVector<>();
|
||||
if (constructors.length == 0)
|
||||
cons.add(new ConstructorDecl());
|
||||
for (ConstructorDecl constructor : constructors) {
|
||||
cons.add(constructor);
|
||||
}
|
||||
return cons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PrintableVector<MethodParameter>
|
||||
*/
|
||||
public static PrintableVector<MethodParameter> getEmptyParameters() {
|
||||
return new PrintableVector<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameters
|
||||
* @return PrintableVector<MethodParameter>
|
||||
*/
|
||||
public static PrintableVector<MethodParameter> getParameters(MethodParameter... parameters) {
|
||||
PrintableVector<MethodParameter> parametersVector = new PrintableVector<>();
|
||||
for (MethodParameter parameter : parameters) {
|
||||
parametersVector.add(parameter);
|
||||
}
|
||||
return parametersVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getClassFieldsTast() {
|
||||
return getClassFieldsAst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getClassFieldsAst() {
|
||||
Program expectedAst = getEmptyProgram("ClassFields");
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
FieldDecl privateField = new FieldDecl("privateAccess", AccessModifier.PRIVATE);
|
||||
privateField.setType(new BaseType(Primitives.INT));
|
||||
FieldDecl publicField = new FieldDecl("publicAccess", AccessModifier.PUBLIC);
|
||||
publicField.setType(new BaseType(Primitives.INT));
|
||||
FieldDecl protectedField = new FieldDecl("protectedAccess", AccessModifier.PROTECTED);
|
||||
protectedField.setType(new BaseType(Primitives.INT));
|
||||
|
||||
PrintableVector<FieldDecl> fields = expectedAst.getClasses().firstElement().getFieldDelcarations();
|
||||
fields.add(privateField);
|
||||
fields.add(publicField);
|
||||
fields.add(protectedField);
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getAutoClassFieldAst() {
|
||||
Program expectedAst = getEmptyProgram("AutoAccessModifierField");
|
||||
|
||||
FieldDecl autoField = new FieldDecl(new BaseType(Primitives.INT), "autoAccess");
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
PrintableVector<FieldDecl> fields = expectedAst.getClasses().firstElement().getFieldDelcarations();
|
||||
fields.add(autoField);
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getAutoClassFieldTast() {
|
||||
return getAutoClassFieldAst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getConstructorParameterTast() {
|
||||
return getConstructorParameterAst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getConstructorParameterAst() {
|
||||
Program expectedAst = getEmptyProgram("ConstructorParams");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Primitives.INT, "i");
|
||||
|
||||
PrintableVector<MethodParameter> parameters = new PrintableVector<>();
|
||||
parameters.add(parameter);
|
||||
|
||||
classDecl.getConstructorDeclarations()
|
||||
.add(new ConstructorDecl(AccessModifier.PUBLIC, parameters, getEmptyBlock()));
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getConstructorThisDotAst() {
|
||||
|
||||
Program expectedAst = getEmptyProgram("ConstructorThisDot");
|
||||
|
||||
FieldDecl i = new FieldDecl("i", AccessModifier.PUBLIC);
|
||||
i.setType(new BaseType(Primitives.INT));
|
||||
|
||||
PrintableVector<FieldDecl> fields = expectedAst.getClasses().firstElement().getFieldDelcarations();
|
||||
fields.add(i);
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
Block block = getEmptyBlock();
|
||||
|
||||
Assign assign = new Assign(new InstVar("i", new This()), new IntegerExpr(5));
|
||||
block.getStatements().add(assign);
|
||||
|
||||
classDecl.getConstructorDeclarations()
|
||||
.add(new ConstructorDecl(AccessModifier.PUBLIC, getParameters(), block));
|
||||
System.out.println(classDecl);
|
||||
return expectedAst;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getConstructorThisDotTast() {
|
||||
Program expectedTast = getEmptyProgram("ConstructorThisDot");
|
||||
|
||||
FieldDecl i = new FieldDecl("i", AccessModifier.PUBLIC);
|
||||
i.setType(new BaseType(Primitives.INT));
|
||||
|
||||
PrintableVector<FieldDecl> fields = expectedTast.getClasses().firstElement().getFieldDelcarations();
|
||||
fields.add(i);
|
||||
|
||||
ClassDecl classDecl = expectedTast.getClasses().firstElement();
|
||||
|
||||
Block block = getEmptyBlock();
|
||||
|
||||
var thisi = new InstVar("i", new This("ConstructorThisDot"));
|
||||
thisi.setType(Primitives.INT);
|
||||
|
||||
Assign assign = new Assign(thisi, new IntegerExpr(5));
|
||||
assign.setType(Primitives.INT);
|
||||
block.getStatements().add(assign);
|
||||
|
||||
classDecl.getConstructorDeclarations()
|
||||
.add(new ConstructorDecl(AccessModifier.PUBLIC, getEmptyParameters(), block));
|
||||
|
||||
return expectedTast;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getVoidMethodAst() {
|
||||
Program expectedAst = getEmptyProgram("VoidMethod");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
MethodDecl foo = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(),
|
||||
getEmptyBlock());
|
||||
methods.add(foo);
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getVoidMethodTast() {
|
||||
return getVoidMethodAst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getRealMethodAst() {
|
||||
Program expectedAst = getEmptyProgram("RealMethod");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
Block block = getEmptyBlock();
|
||||
ReturnStmt returnStmt = new ReturnStmt(new LocalOrFieldVar("i"));
|
||||
block.getStatements().add(returnStmt);
|
||||
|
||||
var parameters = getEmptyParameters();
|
||||
parameters.add(new MethodParameter(Primitives.INT, "i"));
|
||||
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
MethodDecl foo = new MethodDecl(new BaseType(Primitives.INT), "foo", parameters, block);
|
||||
methods.add(foo);
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getRealConstructorAst() {
|
||||
Program expectedAst = getEmptyProgram("RealConstructor");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PRIVATE, new BaseType(Primitives.INT), "i");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
Assign assignStmt = new Assign(new InstVar(new This(), "i"), new LocalOrFieldVar("i"));
|
||||
Block block = getBlock(assignStmt);
|
||||
|
||||
var parameters = getParameters(new MethodParameter(Primitives.INT, "i"));
|
||||
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
ConstructorDecl constructor = new ConstructorDecl(AccessModifier.PUBLIC, parameters, block);
|
||||
constructors.add(constructor);
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getRealConstructorTast() {
|
||||
String className = "RealConstructor";
|
||||
Program expectedTast = getEmptyProgram(className);
|
||||
|
||||
ClassDecl classDecl = expectedTast.getClasses().firstElement();
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PRIVATE, new BaseType(Primitives.INT), "i");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
Assign assignStmt = new Assign(new InstVar(new BaseType(Primitives.INT), new This(
|
||||
className), "i"), new LocalOrFieldVar(new BaseType(Primitives.INT), "i"));
|
||||
|
||||
assignStmt.setType(new BaseType(Primitives.INT));
|
||||
|
||||
Block block = getBlock(assignStmt);
|
||||
|
||||
var parameters = getParameters(new MethodParameter(Primitives.INT, "i"));
|
||||
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
ConstructorDecl constructor = new ConstructorDecl(AccessModifier.PUBLIC, parameters, block);
|
||||
constructors.add(constructor);
|
||||
|
||||
return expectedTast;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getMethodCallAst() {
|
||||
Program expectedAst = getEmptyProgram("MethodCall");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
var fields = classDecl.getFieldDelcarations();
|
||||
fields.add(new FieldDecl(new BaseType(Primitives.INT), "i"));
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
|
||||
Block block = getBlock(
|
||||
new Assign(new InstVar(new This(), "i"),
|
||||
new MethodCall(new This(), "foo", getArguments())));
|
||||
constructors.add(new ConstructorDecl(AccessModifier.PUBLIC, getParameters(), block));
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new IntegerExpr(1)));
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
methods.add(new MethodDecl(new BaseType(Primitives.INT), "foo", getEmptyParameters(), fooBlock));
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getMethodCallTast() {
|
||||
Program expectedTast = getEmptyProgram("MethodCall");
|
||||
|
||||
ClassDecl classDecl = expectedTast.getClasses().firstElement();
|
||||
var fields = classDecl.getFieldDelcarations();
|
||||
fields.add(new FieldDecl(new BaseType(Primitives.INT), "i"));
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
|
||||
Block block = getBlock(
|
||||
new Assign(new BaseType(
|
||||
Primitives.INT),
|
||||
new InstVar(new BaseType(Primitives.INT), new This("MethodCall"), "i"),
|
||||
new MethodCall(new BaseType(Primitives.INT), new This("MethodCall"),
|
||||
"foo", getArguments())));
|
||||
constructors.add(new ConstructorDecl(AccessModifier.PUBLIC, getParameters(), block));
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new BaseType(Primitives.INT), new IntegerExpr(1)));
|
||||
fooBlock.setType(Primitives.INT);
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
methods.add(new MethodDecl(new BaseType(Primitives.INT), "foo", getEmptyParameters(), fooBlock));
|
||||
|
||||
return expectedTast;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getMethodCallWithParameterAst() {
|
||||
Program expectedAst = getEmptyProgram("MethodCallParams");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
var fields = classDecl.getFieldDelcarations();
|
||||
fields.add(new FieldDecl(new BaseType(Primitives.INT), "i"));
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
|
||||
Block block = getBlock(
|
||||
new Assign(new InstVar(new This(), "i"),
|
||||
new MethodCall(new This(), "foo",
|
||||
getArguments(new LocalOrFieldVar("i")))));
|
||||
constructors.add(new ConstructorDecl(AccessModifier.PUBLIC,
|
||||
getParameters(new MethodParameter(Primitives.INT, "i")), block));
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new LocalOrFieldVar("i")));
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
methods.add(new MethodDecl(new BaseType(Primitives.INT), "foo",
|
||||
getParameters(new MethodParameter(Primitives.INT, "i")), fooBlock));
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getCharArgumentAst() {
|
||||
Program expectedAst = getEmptyProgram("CharArgument");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
var fields = classDecl.getFieldDelcarations();
|
||||
fields.add(new FieldDecl(new BaseType(Primitives.CHAR), "c"));
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
|
||||
Block block = getBlock(
|
||||
new Assign(new InstVar(new This(), "c"),
|
||||
new MethodCall(new This(), "foo", getArguments(new CharExpr('a')))));
|
||||
constructors.add(new ConstructorDecl(AccessModifier.PUBLIC,
|
||||
getParameters(), block));
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new LocalOrFieldVar("c")));
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
methods.add(new MethodDecl(new BaseType(Primitives.CHAR), "foo",
|
||||
getParameters(new MethodParameter(Primitives.CHAR, "c")), fooBlock));
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getGetterFunctionAst() {
|
||||
Program expectedAst = getEmptyProgram("GetterFunction");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PRIVATE, new BaseType(Primitives.INT), "i");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
Assign assignStmt = new Assign(new InstVar(new This(), "i"), new LocalOrFieldVar("i"));
|
||||
Block block = getBlock(assignStmt);
|
||||
|
||||
var parameters = getParameters(new MethodParameter(Primitives.INT, "i"));
|
||||
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
ConstructorDecl constructor = new ConstructorDecl(AccessModifier.PUBLIC, parameters, block);
|
||||
constructors.add(constructor);
|
||||
|
||||
var getI = new MethodDecl(AccessModifier.PUBLIC, new BaseType(Primitives.INT), "getI", getParameters(),
|
||||
getBlock(new ReturnStmt(new InstVar(new This(), "i"))));
|
||||
|
||||
classDecl.getMethodDeclarations().add(getI);
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getExplicitNullAssignAst() {
|
||||
Program expectedAst = getEmptyProgram("ExplicitNullAssign");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PACKAGE_PRIVATE, new ReferenceType("ExplicitNullAssign"),
|
||||
"e");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
|
||||
var test = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.VOID), "test",
|
||||
getParameters(),
|
||||
getBlock(new Assign(new LocalOrFieldVar("e"), new Null())));
|
||||
|
||||
classDecl.getMethodDeclarations().add(test);
|
||||
|
||||
classDecl.getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getSelfReferenceAst() {
|
||||
Program expectedAst = getEmptyProgram("SelfReference");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PACKAGE_PRIVATE, new ReferenceType("SelfReference"),
|
||||
"selfRef");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
|
||||
var foo = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "foo",
|
||||
getParameters(),
|
||||
getBlock(new ReturnStmt(new MethodCall(new This(), "baz", getArguments()))));
|
||||
|
||||
var baz = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "baz",
|
||||
getParameters(),
|
||||
getBlock(new ReturnStmt(new IntegerExpr(10))));
|
||||
|
||||
var bar = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "bar",
|
||||
getParameters(),
|
||||
getBlock(
|
||||
new LocalVarDecl(new ReferenceType("SelfReference"), "self",
|
||||
new NewDecl("SelfReference", getArguments())),
|
||||
new ReturnStmt(new MethodCall(
|
||||
new InstVar(new LocalOrFieldVar("self"), "selfRef"),
|
||||
"foo",
|
||||
getArguments()))));
|
||||
|
||||
classDecl.getMethodDeclarations().add(foo);
|
||||
classDecl.getMethodDeclarations().add(baz);
|
||||
classDecl.getMethodDeclarations().add(bar);
|
||||
|
||||
classDecl.getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getSelfReferenceTast() {
|
||||
Program expectedAst = getEmptyProgram("SelfReference");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
|
||||
FieldDecl i = new FieldDecl(AccessModifier.PACKAGE_PRIVATE, new ReferenceType("SelfReference"),
|
||||
"selfRef");
|
||||
|
||||
classDecl.getFieldDelcarations().add(i);
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new BaseType(Primitives.INT),
|
||||
new MethodCall(new BaseType(Primitives.INT), new This("SelfReference"), "baz",
|
||||
getArguments())));
|
||||
fooBlock.setType(new BaseType(Primitives.INT));
|
||||
|
||||
Block bazBlock = getBlock(new ReturnStmt(new BaseType(Primitives.INT), new IntegerExpr(10)));
|
||||
bazBlock.setType(new BaseType(Primitives.INT));
|
||||
|
||||
Block barBlock = getBlock(
|
||||
new LocalVarDecl(new ReferenceType("SelfReference"), "self",
|
||||
new NewDecl("SelfReference", getArguments())),
|
||||
new ReturnStmt(new BaseType(Primitives.INT),
|
||||
new MethodCall(new BaseType(Primitives.INT),
|
||||
new InstVar(new ReferenceType("SelfReference"),
|
||||
new LocalOrFieldVar(new ReferenceType(
|
||||
"SelfReference"),
|
||||
"self"),
|
||||
"selfRef"),
|
||||
"foo",
|
||||
getArguments())));
|
||||
|
||||
barBlock.setType(new BaseType(Primitives.INT));
|
||||
|
||||
var foo = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "foo",
|
||||
getParameters(), fooBlock);
|
||||
|
||||
var baz = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "baz",
|
||||
getParameters(), bazBlock);
|
||||
|
||||
var bar = new MethodDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT), "bar",
|
||||
getParameters(),
|
||||
barBlock);
|
||||
|
||||
classDecl.getMethodDeclarations().add(foo);
|
||||
classDecl.getMethodDeclarations().add(baz);
|
||||
classDecl.getMethodDeclarations().add(bar);
|
||||
|
||||
classDecl.getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getThisDotMethodCallAst() {
|
||||
Program expectedAst = getEmptyProgram("ThisDotMethodCall");
|
||||
|
||||
ClassDecl classDecl = expectedAst.getClasses().firstElement();
|
||||
var fields = classDecl.getFieldDelcarations();
|
||||
fields.add(new FieldDecl(new BaseType(Primitives.INT), "i"));
|
||||
PrintableVector<ConstructorDecl> constructors = classDecl.getConstructorDeclarations();
|
||||
|
||||
Block block = getBlock(
|
||||
new Assign(new InstVar(new This(), "i"),
|
||||
new MethodCall(new This(), "foo", getArguments())));
|
||||
constructors.add(new ConstructorDecl(AccessModifier.PUBLIC, getParameters(), block));
|
||||
|
||||
Block fooBlock = getBlock(new ReturnStmt(new IntegerExpr(1)));
|
||||
PrintableVector<MethodDecl> methods = classDecl.getMethodDeclarations();
|
||||
methods.add(new MethodDecl(new BaseType(Primitives.INT), "foo", getEmptyParameters(), fooBlock));
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getValueAdapterTestAst() {
|
||||
Program expectedAst = getEmptyProgram("ValueAdapterTests");
|
||||
|
||||
Block readsTrueBlock = getBlock(new ReturnStmt(new BoolExpr(true)));
|
||||
|
||||
Block readsFalseBlock = getBlock(new ReturnStmt(new BoolExpr(false)));
|
||||
|
||||
Block readsTrueAndFalseBlock = getBlock(new ReturnStmt(new Binary(new BoolExpr(true),
|
||||
Operator.AND, new BoolExpr(false))));
|
||||
|
||||
Block readsIntBlock = getBlock(new ReturnStmt(new IntegerExpr(1)));
|
||||
|
||||
Block readsIntAndIntBlock = getBlock(new ReturnStmt(new Binary(new IntegerExpr(1),
|
||||
Operator.PLUS, new IntegerExpr(1))));
|
||||
|
||||
Block readsCharBlock = getBlock(new ReturnStmt(new CharExpr('a')));
|
||||
|
||||
MethodDecl readsTrue = new MethodDecl(new BaseType(Primitives.BOOL), "readsTrue", getEmptyParameters(),
|
||||
readsTrueBlock);
|
||||
|
||||
MethodDecl readsFalse = new MethodDecl(new BaseType(Primitives.BOOL), "readsFalse",
|
||||
getEmptyParameters(),
|
||||
readsFalseBlock);
|
||||
|
||||
MethodDecl readsTrueAndFalse = new MethodDecl(new BaseType(Primitives.BOOL), "readsTrueAndFalse",
|
||||
getEmptyParameters(), readsTrueAndFalseBlock);
|
||||
|
||||
MethodDecl readsInt = new MethodDecl(new BaseType(Primitives.INT), "readsInt", getEmptyParameters(),
|
||||
readsIntBlock);
|
||||
|
||||
MethodDecl readsIntAndInt = new MethodDecl(new BaseType(Primitives.INT), "readsIntAndInt",
|
||||
getEmptyParameters(),
|
||||
readsIntAndIntBlock);
|
||||
|
||||
MethodDecl readsChar = new MethodDecl(new BaseType(Primitives.CHAR), "readsChar", getEmptyParameters(),
|
||||
readsCharBlock);
|
||||
|
||||
var methods = expectedAst.getClasses().firstElement().getMethodDeclarations();
|
||||
|
||||
methods.add(readsTrue);
|
||||
methods.add(readsFalse);
|
||||
methods.add(readsTrueAndFalse);
|
||||
methods.add(readsInt);
|
||||
methods.add(readsIntAndInt);
|
||||
methods.add(readsChar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
|
||||
}
|
||||
|
||||
public static Program getSystemOutPrintlnTast() {
|
||||
Program expectedAst = getEmptyProgram("SystemOutPrintln");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block block = getBlock(
|
||||
new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new IntegerExpr(1))));
|
||||
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getSystemOutPrintlnAst() {
|
||||
Program expectedAst = getEmptyProgram("SystemOutPrintln");
|
||||
|
||||
Block block = getBlock(
|
||||
new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new IntegerExpr(1))));
|
||||
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getSystemOutPrintStringAst() {
|
||||
Program expectedAst = getEmptyProgram("SystemOutPrintlnString");
|
||||
|
||||
Block block = getBlock(
|
||||
new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new StringExpr("Das ist ein String"))));
|
||||
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getSystemOutPrintStringTast() {
|
||||
Program expectedAst = getEmptyProgram("SystemOutPrintlnString");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block block = getBlock(
|
||||
new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new StringExpr("Das ist ein String"))));
|
||||
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getMainMethodTestAst() {
|
||||
Program expectedAst = getEmptyProgram("MainMethodTest");
|
||||
Block block = getBlock(
|
||||
new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new StringExpr("maintest"))));
|
||||
|
||||
var method = new MainMethodDecl(block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getMainMethodTestTast() {
|
||||
Program expectedAst = getEmptyProgram("MainMethodTest");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block block = getBlock(
|
||||
new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new StringExpr("maintest"))));
|
||||
|
||||
var method = new MainMethodDecl(block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getForTestAst() {
|
||||
Program expectedAst = getEmptyProgram("ForTest");
|
||||
Block forBlock = getBlock(new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new LocalOrFieldVar("i"))));
|
||||
Block block = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new Assign(new LocalOrFieldVar("i"),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(1),
|
||||
Operator.PLUS)),
|
||||
forBlock));
|
||||
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getForTestTast() {
|
||||
Program expectedAst = getEmptyProgram("ForTest");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block forBlock = getBlock(new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new LocalOrFieldVar(new BaseType(Primitives.INT), "i"))));
|
||||
Block block = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new BaseType(Primitives.BOOL),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new Assign(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new Binary(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(
|
||||
Primitives.INT), "i"),
|
||||
new IntegerExpr(1),
|
||||
Operator.PLUS)),
|
||||
forBlock));
|
||||
var method = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), block);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(method);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getIncTestAst() {
|
||||
Program expectedAst = getEmptyProgram("IncTest");
|
||||
Block forBlock = getBlock(new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new LocalOrFieldVar("i"))));
|
||||
Block blockfoo = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new CrementStmtExpr(new LocalOrFieldVar("i"), Operator.INCSUF),
|
||||
forBlock));
|
||||
|
||||
Block blockbar = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new CrementStmtExpr(new LocalOrFieldVar("i"), Operator.INCPRE),
|
||||
forBlock));
|
||||
|
||||
var foo = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), blockfoo);
|
||||
|
||||
var bar = new MethodDecl(new BaseType(Primitives.VOID), "bar", getEmptyParameters(), blockbar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(foo);
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(bar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getIncTestTast() {
|
||||
Program expectedAst = getEmptyProgram("IncTest");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block forBlock = getBlock(new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new LocalOrFieldVar(new BaseType(Primitives.INT), "i"))));
|
||||
Block fooblock = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new BaseType(Primitives.BOOL),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new CrementStmtExpr(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
Operator.INCSUF),
|
||||
forBlock));
|
||||
Block barblock = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(0)),
|
||||
new Binary(new BaseType(Primitives.BOOL),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new IntegerExpr(10),
|
||||
Operator.LESS),
|
||||
new CrementStmtExpr(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
Operator.INCPRE),
|
||||
forBlock));
|
||||
var foo = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), fooblock);
|
||||
var bar = new MethodDecl(new BaseType(Primitives.VOID), "bar", getEmptyParameters(), barblock);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(foo);
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(bar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getDecTestAst() {
|
||||
Program expectedAst = getEmptyProgram("DecTest");
|
||||
Block forBlock = getBlock(new MethodCall(new InstVar(new LocalOrFieldVar("System"), "out"), "println",
|
||||
getArguments(new LocalOrFieldVar("i"))));
|
||||
Block blockfoo = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(10)),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(0),
|
||||
Operator.GREATER),
|
||||
new CrementStmtExpr(new LocalOrFieldVar("i"), Operator.DECSUF),
|
||||
forBlock));
|
||||
|
||||
Block blockbar = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(10)),
|
||||
new Binary(new LocalOrFieldVar("i"), new IntegerExpr(0),
|
||||
Operator.GREATER),
|
||||
new CrementStmtExpr(new LocalOrFieldVar("i"), Operator.DECPRE),
|
||||
forBlock));
|
||||
|
||||
var foo = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), blockfoo);
|
||||
|
||||
var bar = new MethodDecl(new BaseType(Primitives.VOID), "bar", getEmptyParameters(), blockbar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(foo);
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(bar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
public static Program getDecTestTast() {
|
||||
Program expectedAst = getEmptyProgram("DecTest");
|
||||
var iv = new InstVar(new ReferenceType("java/io/PrintStream"),
|
||||
new LocalOrFieldVar(new ReferenceType("java/lang/System"), "System"), "out");
|
||||
iv.setAccessModifier(AccessModifier.PUBLIC_STATIC);
|
||||
Block forBlock = getBlock(new MethodCall(new BaseType(Primitives.VOID),
|
||||
iv,
|
||||
"println",
|
||||
getArguments(new LocalOrFieldVar(new BaseType(Primitives.INT), "i"))));
|
||||
Block fooblock = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(10)),
|
||||
new Binary(new BaseType(Primitives.BOOL),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new IntegerExpr(0),
|
||||
Operator.GREATER),
|
||||
new CrementStmtExpr(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
Operator.DECSUF),
|
||||
forBlock));
|
||||
Block barblock = getBlock(
|
||||
new ForStmt(new LocalVarDecl(new BaseType(Primitives.INT), "i", new IntegerExpr(10)),
|
||||
new Binary(new BaseType(Primitives.BOOL),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
new IntegerExpr(0),
|
||||
Operator.GREATER),
|
||||
new CrementStmtExpr(new BaseType(Primitives.INT),
|
||||
new LocalOrFieldVar(new BaseType(Primitives.INT), "i"),
|
||||
Operator.DECPRE),
|
||||
forBlock));
|
||||
var foo = new MethodDecl(new BaseType(Primitives.VOID), "foo", getEmptyParameters(), fooblock);
|
||||
var bar = new MethodDecl(new BaseType(Primitives.VOID), "bar", getEmptyParameters(), barblock);
|
||||
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(foo);
|
||||
expectedAst.getClasses().firstElement().getMethodDeclarations().add(bar);
|
||||
|
||||
expectedAst.getClasses().firstElement().getConstructorDeclarations().add(new ConstructorDecl());
|
||||
|
||||
return expectedAst;
|
||||
}
|
||||
|
||||
}
|
104
src/test/java/Helper/ReflectLoader.java
Normal file
104
src/test/java/Helper/ReflectLoader.java
Normal file
@ -0,0 +1,104 @@
|
||||
package Helper;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import common.Compiler;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
public class ReflectLoader extends ClassLoader {
|
||||
private byte[] byteCode;
|
||||
private Map<String, byte[]> byteCodes;
|
||||
private Map<String, Class<?>> classes = new HashMap<>();
|
||||
|
||||
public ReflectLoader(byte[] byteCode) {
|
||||
byteCodes = new HashMap<>();
|
||||
this.byteCode = byteCode;
|
||||
}
|
||||
|
||||
public ReflectLoader(String fileName) {
|
||||
Program program = Resources.getProgram(fileName);
|
||||
Program tast = Compiler.getFactory().getTastAdapter().getTast(program);
|
||||
var bc = Compiler.getFactory().getProgramGenerator().generateBytecode(tast);
|
||||
this.byteCodes = bc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* @param className
|
||||
* @return Class<?>
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Class<?> getClass(String fileName, String className) throws Exception {
|
||||
ReflectLoader loader = new ReflectLoader(fileName);
|
||||
return loader.findClass(className);
|
||||
}
|
||||
|
||||
public ReflectLoader(Map<String, byte[]> byteCodes) {
|
||||
this.byteCodes = byteCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return Class<?>
|
||||
*/
|
||||
@Override
|
||||
public Class<?> findClass(String name) {
|
||||
if (!byteCodes.containsKey(name)) {
|
||||
if (byteCode != null) {
|
||||
byteCodes.put(name, byteCode);
|
||||
byteCode = null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (classes.containsKey(name)) {
|
||||
return classes.get(name);
|
||||
} else {
|
||||
Class<?> clazz = defineClass(name, byteCodes.get(name), 0, byteCodes.get(name).length);
|
||||
classes.put(name, clazz);
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className
|
||||
* @param method
|
||||
* @param parameterTypes
|
||||
* @return Method
|
||||
* @throws NoSuchMethodException
|
||||
*/
|
||||
public Method getMethod(String className, String method, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Method method1 = findClass(className).getDeclaredMethod(method, parameterTypes);
|
||||
method1.setAccessible(true);
|
||||
return method1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className
|
||||
* @param field
|
||||
* @return Field
|
||||
* @throws NoSuchFieldException
|
||||
*/
|
||||
public Field getField(String className, String field) throws NoSuchFieldException {
|
||||
Field field1 = findClass(className).getDeclaredField(field);
|
||||
field1.setAccessible(true);
|
||||
return field1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param classname
|
||||
* @param parameterTyped
|
||||
* @return Constructor<?>
|
||||
* @throws NoSuchMethodException
|
||||
*/
|
||||
public Constructor<?> getConstructor(String classname, Class<?>... parameterTyped) throws NoSuchMethodException {
|
||||
Constructor<?> constructor = findClass(classname).getDeclaredConstructor(parameterTyped);
|
||||
constructor.setAccessible(true);
|
||||
return constructor;
|
||||
}
|
||||
|
||||
}
|
42
src/test/java/Helper/Resources.java
Normal file
42
src/test/java/Helper/Resources.java
Normal file
@ -0,0 +1,42 @@
|
||||
package Helper;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import common.Compiler;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
public class Resources {
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* @return Program
|
||||
*/
|
||||
public static Program getProgram(String fileName) {
|
||||
return Compiler.getFactory().getAstAdapter().getAst(getFileAsStream(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* @return InputStream
|
||||
*/
|
||||
public static InputStream getFileAsStream(String fileName) {
|
||||
ClassLoader classLoader = Resources.class.getClassLoader();
|
||||
File file = new File(classLoader.getResource(fileName).getFile());
|
||||
assertNotNull(file);
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
324
src/test/java/TAST/TestRunner.java
Normal file
324
src/test/java/TAST/TestRunner.java
Normal file
@ -0,0 +1,324 @@
|
||||
package TAST;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import Helper.MockGenerator;
|
||||
import Helper.Resources;
|
||||
import common.AccessModifier;
|
||||
import common.BaseType;
|
||||
import common.Compiler;
|
||||
import common.Primitives;
|
||||
import common.PrintableVector;
|
||||
import semantic.exceptions.SemanticError;
|
||||
import syntaxtree.structure.ClassDecl;
|
||||
import syntaxtree.structure.ConstructorDecl;
|
||||
import syntaxtree.structure.FieldDecl;
|
||||
import syntaxtree.structure.Program;
|
||||
|
||||
@DisplayName("Typed Abstract Syntax Generation")
|
||||
public class TestRunner {
|
||||
|
||||
/**
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("EmptyClass")
|
||||
void emptyClass() throws FileNotFoundException {
|
||||
|
||||
ClassDecl emptyClass = new ClassDecl("EmptyClass", new PrintableVector<>(), new PrintableVector<>(),
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(emptyClass);
|
||||
var ast = new Program(classDecls);
|
||||
var tast = ast;
|
||||
|
||||
var generatedTast = Compiler.getFactory().getTastAdapter().getTast(ast);
|
||||
|
||||
assertEquals(tast, generatedTast);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassFields")
|
||||
void classFields() {
|
||||
|
||||
Program expectedAst = MockGenerator.getEmptyProgram("ClassFields");
|
||||
|
||||
FieldDecl autoAccess = new FieldDecl(AccessModifier.PACKAGE_PRIVATE, new BaseType(Primitives.INT),
|
||||
"autoAccess");
|
||||
FieldDecl privateField = new FieldDecl(AccessModifier.PRIVATE, new BaseType(Primitives.INT), "private");
|
||||
FieldDecl publicField = new FieldDecl(AccessModifier.PUBLIC, new BaseType(Primitives.INT), "public");
|
||||
FieldDecl protectedField = new FieldDecl(AccessModifier.PROTECTED, new BaseType(Primitives.INT), "protected");
|
||||
|
||||
PrintableVector<FieldDecl> fields = expectedAst.getClasses().firstElement().getFieldDelcarations();
|
||||
fields.add(autoAccess);
|
||||
fields.add(privateField);
|
||||
fields.add(publicField);
|
||||
fields.add(protectedField);
|
||||
|
||||
var generatedAst = Compiler.getFactory().getTastAdapter().getTast(expectedAst);
|
||||
|
||||
assertEquals(expectedAst, generatedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ClassField without AccessModifier")
|
||||
void classFieldWithoutAccessModifier() {
|
||||
|
||||
Program expectedTast = MockGenerator.getAutoClassFieldTast();
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(expectedTast);
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EmptyClassWithConstructor")
|
||||
void emptyClassWithConstructor() {
|
||||
PrintableVector<ConstructorDecl> constructors = new PrintableVector<>();
|
||||
constructors.add(new ConstructorDecl());
|
||||
ClassDecl classDecl = new ClassDecl("EmptyClassWithConstructor", new PrintableVector<>(), constructors,
|
||||
new PrintableVector<>());
|
||||
PrintableVector<ClassDecl> classDecls = new PrintableVector<>();
|
||||
classDecls.add(classDecl);
|
||||
var ast = new Program(classDecls);
|
||||
|
||||
var generatedTast = Compiler.getFactory().getTastAdapter().getTast(ast);
|
||||
var tast = ast;
|
||||
assertEquals(tast, generatedTast);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With Parameters")
|
||||
void constructorWithParameters() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter()
|
||||
.getTast(MockGenerator.getConstructorParameterAst());
|
||||
Program expectedTast = MockGenerator.getConstructorParameterTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor With this. assign body")
|
||||
void constructorWithThisAssignBody() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter()
|
||||
.getTast(MockGenerator.getConstructorThisDotAst());
|
||||
Program expectedTast = MockGenerator.getConstructorThisDotTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("VoidMethod")
|
||||
void voidMethod() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getVoidMethodAst());
|
||||
|
||||
Program expectedTast = MockGenerator.getVoidMethodTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("RealConstructor")
|
||||
void realConstructor() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getRealConstructorAst());
|
||||
|
||||
Program expectedTast = MockGenerator.getRealConstructorTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MethodCall")
|
||||
void methodCall() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getMethodCallAst());
|
||||
|
||||
Program expectedTast = MockGenerator.getMethodCallTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MultipleFields")
|
||||
@Tag("expectfail")
|
||||
void multipleFields() {
|
||||
Program program = Resources.getProgram("FailTests/MultiFieldDecl.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MismatchingReturnType")
|
||||
@Tag("expectfail")
|
||||
void mismatchingReturnType() {
|
||||
Program program = Resources.getProgram("FailTests/MismatchingReturnType.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("WhileTest")
|
||||
void whileTest() {
|
||||
Program program = Resources.getProgram("SimpleTests/WhileTest.java");
|
||||
Compiler.getFactory().getTastAdapter().getTast(program);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("WhileFailTest")
|
||||
void whileFailTest() {
|
||||
Program program = Resources.getProgram("FailTests/WhileBool.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ScopeFailTest")
|
||||
void scopeFailTest() {
|
||||
Program program = Resources.getProgram("FailTests/ScopeTest.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("AssignFailTest")
|
||||
void assignFailTest() {
|
||||
Program program = Resources.getProgram("FailTests/AssignWrongType.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("LocalVarDeclaration with wrong init-Type")
|
||||
void localVarDeclInitFail() {
|
||||
Program program = Resources.getProgram("FailTests/LocalVarWrongInit.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ExplicitNullAssign")
|
||||
void explicitNullAssign() {
|
||||
Program program = Resources.getProgram("SimpleTests/ExplicitNullAssign.java");
|
||||
Compiler.getFactory().getTastAdapter().getTast(program);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SelfReference")
|
||||
void selfReference() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getSelfReferenceAst());
|
||||
|
||||
Program expectedTast = MockGenerator.getSelfReferenceTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SystemOutPrintln-Test")
|
||||
void systemOutPrintlnTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getSystemOutPrintlnAst());
|
||||
Program expectedTast = MockGenerator.getSystemOutPrintlnTast();
|
||||
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("FieldAccessTests")
|
||||
void fieldAccessTests() {
|
||||
Program program = Resources.getProgram("FailTests/FieldAccessTests.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MethodAccessTests")
|
||||
void methodAccessTests() {
|
||||
Program program = Resources.getProgram("FailTests/MethodAccessTests.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("DuplicateMethod")
|
||||
void duplicateMethod() {
|
||||
Program program = Resources.getProgram("FailTests/DuplicateMethod.java");
|
||||
System.err.print(assertThrows(
|
||||
SemanticError.class,
|
||||
() -> Compiler.getFactory().getTastAdapter().getTast(program),
|
||||
"Expected SemanticError to be thrown").getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SystemOutPrintln-String-Test")
|
||||
void systemOutPrintlnStringTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter()
|
||||
.getTast(MockGenerator.getSystemOutPrintStringAst());
|
||||
Program expectedTast = MockGenerator.getSystemOutPrintStringTast();
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MainMethodTest")
|
||||
void mainMethodTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getMainMethodTestAst());
|
||||
Program expectedTast = MockGenerator.getMainMethodTestTast();
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ForLoopTest")
|
||||
void forLoopTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getForTestAst());
|
||||
Program expectedTast = MockGenerator.getForTestTast();
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("IncTest")
|
||||
void incTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getIncTestAst());
|
||||
Program expectedTast = MockGenerator.getIncTestTast();
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("DecTest")
|
||||
void decTest() {
|
||||
Program generatedTast = Compiler.getFactory().getTastAdapter().getTast(MockGenerator.getDecTestAst());
|
||||
Program expectedTast = MockGenerator.getDecTestTast();
|
||||
assertEquals(expectedTast, generatedTast);
|
||||
}
|
||||
|
||||
}
|
10
src/test/java/TestSuite.java
Normal file
10
src/test/java/TestSuite.java
Normal file
@ -0,0 +1,10 @@
|
||||
import org.junit.platform.suite.api.SelectClasses;
|
||||
import org.junit.platform.suite.api.Suite;
|
||||
import org.junit.platform.suite.api.SuiteDisplayName;
|
||||
|
||||
@SelectClasses({AST.TestRunner.class, TAST.TestRunner.class, CodeGen.TestRunner.class, All.TestRunner.class})
|
||||
|
||||
@Suite
|
||||
@SuiteDisplayName("House of Compiler")
|
||||
public class TestSuite {
|
||||
}
|
12
src/test/java/initialTest/initialTest.java
Normal file
12
src/test/java/initialTest/initialTest.java
Normal file
@ -0,0 +1,12 @@
|
||||
package initialTest;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class initialTest {
|
||||
|
||||
@Test
|
||||
public void testSomething() {
|
||||
//MyClass myClass = new MyClass();
|
||||
assertEquals(1, 1);
|
||||
}
|
||||
}
|
19
src/test/resources/Comments.java
Normal file
19
src/test/resources/Comments.java
Normal file
@ -0,0 +1,19 @@
|
||||
class Comments{
|
||||
|
||||
private int lorem;
|
||||
|
||||
// One Line Comment!!!!! IGNORE THAT
|
||||
|
||||
private boolean ipsum;
|
||||
|
||||
/*
|
||||
MULT-LINE COMMENT! IGNORE THIS
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Should be ignored
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
7
src/test/resources/EmptyClassWithConstructor.java
Normal file
7
src/test/resources/EmptyClassWithConstructor.java
Normal file
@ -0,0 +1,7 @@
|
||||
class EmptyClassWithConstructor{
|
||||
|
||||
public EmptyClassWithConstructor(){
|
||||
|
||||
}
|
||||
|
||||
}
|
1
src/test/resources/EmtpyClass.java
Normal file
1
src/test/resources/EmtpyClass.java
Normal file
@ -0,0 +1 @@
|
||||
class EmptyClass{}
|
11
src/test/resources/FailTests/AssignWrongType.java
Normal file
11
src/test/resources/FailTests/AssignWrongType.java
Normal file
@ -0,0 +1,11 @@
|
||||
package FailTests;
|
||||
|
||||
class AssignWrongType {
|
||||
|
||||
int test() {
|
||||
int x = 1;
|
||||
x = true;
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/FailTests/BoolAssignedInt.java
Normal file
9
src/test/resources/FailTests/BoolAssignedInt.java
Normal file
@ -0,0 +1,9 @@
|
||||
package FailTests;
|
||||
|
||||
class BoolAssignedInt {
|
||||
|
||||
void foo() {
|
||||
boolean bool = 10;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/FailTests/DivideByZero.java
Normal file
9
src/test/resources/FailTests/DivideByZero.java
Normal file
@ -0,0 +1,9 @@
|
||||
package FailTests;
|
||||
|
||||
class DivideByZero {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a = 1 / 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package FailTests;
|
||||
|
||||
class DuplicateFieldDeclaration {
|
||||
char i;
|
||||
int i;
|
||||
}
|
9
src/test/resources/FailTests/DuplicateMethod.java
Normal file
9
src/test/resources/FailTests/DuplicateMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package FailTests;
|
||||
|
||||
class DuplicateMethod {
|
||||
|
||||
public void test() { }
|
||||
|
||||
public void test() { }
|
||||
|
||||
}
|
11
src/test/resources/FailTests/FaultyForLoop.java
Normal file
11
src/test/resources/FailTests/FaultyForLoop.java
Normal file
@ -0,0 +1,11 @@
|
||||
package FailTests;
|
||||
|
||||
class FaultyForLoop {
|
||||
int foo() {
|
||||
int x;
|
||||
for (x == true; ;) {
|
||||
return 4324;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
18
src/test/resources/FailTests/MethodAccessTests.java
Normal file
18
src/test/resources/FailTests/MethodAccessTests.java
Normal file
@ -0,0 +1,18 @@
|
||||
package FailTests;
|
||||
|
||||
class MethodAccessTests {
|
||||
|
||||
void MethodAccesTestMethod() {
|
||||
DontTouchMe clazz = new DontTouchMe();
|
||||
DontTouchMeMethod();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DontTouchMe {
|
||||
|
||||
public void DontTouchMeMethod() {
|
||||
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/FailTests/MismatchingReturnType.java
Normal file
9
src/test/resources/FailTests/MismatchingReturnType.java
Normal file
@ -0,0 +1,9 @@
|
||||
package FailTests;
|
||||
|
||||
class MismatchingReturnType {
|
||||
|
||||
char foo(){
|
||||
return 69;
|
||||
}
|
||||
|
||||
}
|
23
src/test/resources/FailTests/ScopeTest.java
Normal file
23
src/test/resources/FailTests/ScopeTest.java
Normal file
@ -0,0 +1,23 @@
|
||||
package FailTests;
|
||||
|
||||
class ScopeTest {
|
||||
|
||||
int returnDoesntExist() {
|
||||
int x = 1;
|
||||
{
|
||||
int y = 1;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
int varInMethodDoesntExist() {
|
||||
int x = 1;
|
||||
{
|
||||
int y = 1;
|
||||
int x = 2;
|
||||
}
|
||||
int y = 1;
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
20
src/test/resources/IntegerWrapper.java
Normal file
20
src/test/resources/IntegerWrapper.java
Normal file
@ -0,0 +1,20 @@
|
||||
class IntegerWrapper{
|
||||
|
||||
public int i;
|
||||
|
||||
public IntegerWrapper(){
|
||||
this.i = 0;
|
||||
}
|
||||
|
||||
public IntegerWrapper(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public IntegerWrapper add(IntegerWrapper j){ return new IntegerWrapper(j.i+this.i);}
|
||||
|
||||
public IntegerWrapper sub(IntegerWrapper j){ return new IntegerWrapper(j.i-this.i);}
|
||||
|
||||
public boolean equals(IntegerWrapper j){return j.i == this.i;}
|
||||
|
||||
|
||||
}
|
366
src/test/resources/Integration/Dijkstra.java
Normal file
366
src/test/resources/Integration/Dijkstra.java
Normal file
@ -0,0 +1,366 @@
|
||||
package Integration;
|
||||
|
||||
class Dijkstra {
|
||||
|
||||
void main() {
|
||||
Vertex v1 = new Vertex(1);
|
||||
Graph g = new Graph(v1);
|
||||
Vertex v2 = new Vertex(2);
|
||||
Vertex v3 = new Vertex(3);
|
||||
Vertex v4 = new Vertex(4);
|
||||
Vertex v5 = new Vertex(5);
|
||||
Vertex v6 = new Vertex(6);
|
||||
Vertex v7 = new Vertex(7);
|
||||
Vertex v8 = new Vertex(8);
|
||||
Vertex v9 = new Vertex(9);
|
||||
Vertex v10 = new Vertex(10);
|
||||
Vertex v11 = new Vertex(11);
|
||||
Vertex v12 = new Vertex(12);
|
||||
|
||||
g.addVertex(v2);
|
||||
g.addVertex(v4);
|
||||
g.addVertex(v3);
|
||||
g.addVertex(v5);
|
||||
g.addVertex(v6);
|
||||
g.addVertex(v7);
|
||||
g.addVertex(v8);
|
||||
g.addVertex(v9);
|
||||
g.addVertex(v10);
|
||||
g.addVertex(v11);
|
||||
g.addVertex(v12);
|
||||
|
||||
g.addEdge(v1, v2); // A-B
|
||||
g.addEdge(v1, v5); // A-E
|
||||
g.addEdge(v1, v10); // A-J
|
||||
|
||||
g.addEdge(v2, v3); // B
|
||||
g.addEdge(v2, v7);
|
||||
|
||||
g.addEdge(v3, v4); // C
|
||||
g.addEdge(v3, v5);
|
||||
|
||||
g.addEdge(v4, v8); // D
|
||||
|
||||
g.addEdge(v5, v6); // E
|
||||
g.addEdge(v5, v9);
|
||||
|
||||
g.addEdge(v6, v7); // F
|
||||
|
||||
g.addEdge(v7, v8); // G
|
||||
|
||||
g.addEdge(v8, v12); // H
|
||||
g.addEdge(v8, v10);
|
||||
|
||||
g.addEdge(v9, v10); // I
|
||||
|
||||
g.addEdge(v10, v11); // J
|
||||
|
||||
g.addEdge(v11, v12); // K
|
||||
|
||||
g.getShortestPath(v1, v8);
|
||||
g.getShortestPath(v1, v12);
|
||||
g.getShortestPath(v4, v12);
|
||||
g.getShortestPath(v4, v9);
|
||||
g.getShortestPath(v6, v9);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Graph {
|
||||
|
||||
private VertexSet vertexList;
|
||||
|
||||
public Graph(VertexSet vertexList) {
|
||||
this.vertexList = vertexList;
|
||||
}
|
||||
|
||||
public Graph(Vertex v1) {
|
||||
this.vertexList = new VertexSet(v1);
|
||||
}
|
||||
|
||||
public VertexSet getVertexSet() {
|
||||
return vertexList;
|
||||
}
|
||||
|
||||
public void addVertex(Vertex vertex) {
|
||||
vertexList.add(vertex);
|
||||
}
|
||||
|
||||
public void addEdge(Vertex vertex1, Vertex vertex2) {
|
||||
vertex1.addAdjancey(vertex2);
|
||||
vertex2.addAdjancey(vertex1);
|
||||
}
|
||||
|
||||
public void getShortestPath(Vertex source, Vertex destination) {
|
||||
VertexSet calcList = vertexList.copy();
|
||||
calcList.get(source.id).setDistance(0);
|
||||
calcList.get(source.id).setPrevious(null);
|
||||
Vertex current = calcList.get(source.id);
|
||||
|
||||
// Fill the list with the distances
|
||||
while (current != null) {
|
||||
current.setVisited(true);
|
||||
// Search for every adjacent vertex
|
||||
VertexSet currentAdjanceyList = current.getAdjanceyList();
|
||||
if (currentAdjanceyList != null) {
|
||||
for (int i = 0; i < currentAdjanceyList.size(); i = i + 1) {
|
||||
Vertex adjancey = currentAdjanceyList.getFromIndex(i);
|
||||
adjancey = calcList.get(adjancey.id);
|
||||
if ((adjancey != null) && !adjancey.isVisited()) {
|
||||
int distance = current.getDistance() + 1;
|
||||
if (distance < adjancey.getDistance()) {
|
||||
adjancey.setDistance(distance);
|
||||
adjancey.setPrevious(current);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
}
|
||||
current = calcList.getNextSmallestUnvisited();
|
||||
}
|
||||
Vertex previous = calcList.get(destination.id);
|
||||
if (previous == null) {
|
||||
|
||||
return;
|
||||
}
|
||||
IntStack path = new IntStack(previous.id);
|
||||
previous = previous.getPrevious();
|
||||
while (previous != null) {
|
||||
path.push(previous.id);
|
||||
previous = previous.getPrevious();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Vertex {
|
||||
|
||||
public int id;
|
||||
public VertexSet adjanceyList;
|
||||
public int distance;
|
||||
public Vertex previous;
|
||||
public boolean visited;
|
||||
|
||||
public Vertex(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public void setPrevious(Vertex previous) {
|
||||
this.previous = previous;
|
||||
}
|
||||
|
||||
public void setVisited(boolean visited) {
|
||||
this.visited = visited;
|
||||
}
|
||||
|
||||
public int getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public VertexSet getAdjanceyList() {
|
||||
return adjanceyList;
|
||||
}
|
||||
|
||||
public Vertex getPrevious() {
|
||||
return previous;
|
||||
}
|
||||
|
||||
public boolean isVisited() {
|
||||
return visited;
|
||||
}
|
||||
|
||||
public Vertex(Vertex vertex) {
|
||||
this.id = vertex.id;
|
||||
this.adjanceyList = vertex.adjanceyList;
|
||||
this.distance = 10000; // No infinity so...
|
||||
this.previous = null;
|
||||
this.visited = false;
|
||||
}
|
||||
|
||||
public void addAdjancey(Vertex v) {
|
||||
if (adjanceyList == null) {
|
||||
adjanceyList = new VertexSet(v);
|
||||
} else {
|
||||
adjanceyList.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
public Vertex copy() {
|
||||
return new Vertex(this);
|
||||
}
|
||||
|
||||
public boolean isDirect(Vertex v) {
|
||||
return adjanceyList.contains(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class VertexSet {
|
||||
|
||||
private Vertex vertex;
|
||||
private VertexSet next;
|
||||
|
||||
public VertexSet(Vertex vertex) {
|
||||
this.vertex = vertex;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int size = 1;
|
||||
VertexSet v = next;
|
||||
while (v != null) {
|
||||
size = size + 1;
|
||||
v = v.next;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public VertexSet(VertexSet vertexList) {
|
||||
this.vertex = vertexList.vertex.copy();
|
||||
if (vertexList.next != null) {
|
||||
this.next = vertexList.next.copy();
|
||||
} else {
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Vertex getNextSmallestUnvisited() {
|
||||
VertexSet v = this.getUnvisited();
|
||||
if (v == null) {
|
||||
return null;
|
||||
} else {
|
||||
return v.getSmallestDistance();
|
||||
}
|
||||
}
|
||||
|
||||
public Vertex getSmallestDistance() {
|
||||
Vertex smallest = vertex;
|
||||
VertexSet v = next;
|
||||
while (v != null) {
|
||||
if (v.vertex.getDistance() < smallest.getDistance()) {
|
||||
smallest = v.vertex;
|
||||
}
|
||||
v = v.next;
|
||||
}
|
||||
return smallest;
|
||||
}
|
||||
|
||||
public VertexSet getUnvisited() {
|
||||
VertexSet unvisited = null;
|
||||
|
||||
VertexSet current = this;
|
||||
while (current != null) {
|
||||
if (!current.vertex.isVisited()) {
|
||||
if (unvisited == null) {
|
||||
unvisited = new VertexSet(current.vertex);
|
||||
} else {
|
||||
unvisited.add(current.vertex);
|
||||
}
|
||||
}
|
||||
current = current.next;
|
||||
}
|
||||
|
||||
return unvisited;
|
||||
}
|
||||
|
||||
public Vertex getFromIndex(int i) {
|
||||
if (i == 0) {
|
||||
return vertex;
|
||||
} else {
|
||||
return next.getFromIndex(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Vertex v) {
|
||||
if (vertex.id == v.id) {
|
||||
vertex = next.vertex;
|
||||
next = next.next;
|
||||
} else {
|
||||
if (next != null) {
|
||||
next.remove(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnvisited() {
|
||||
if (next != null) {
|
||||
return next.hasUnvisited();
|
||||
} else {
|
||||
return vertex.isVisited();
|
||||
}
|
||||
}
|
||||
|
||||
public VertexSet copy() {
|
||||
return new VertexSet(this);
|
||||
}
|
||||
|
||||
public boolean contains(Vertex v) {
|
||||
if (vertex.id == v.id) {
|
||||
return true;
|
||||
}
|
||||
if (next == null) {
|
||||
return false;
|
||||
}
|
||||
return next.contains(v);
|
||||
}
|
||||
|
||||
public void add(Vertex vertex) {
|
||||
if (this.next == null) {
|
||||
this.next = new VertexSet(vertex);
|
||||
} else {
|
||||
this.next.add(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
public Vertex get(int index) {
|
||||
if ((vertex == null)) {
|
||||
return null;
|
||||
} else if (vertex.id == index) {
|
||||
return this.vertex;
|
||||
} else if (next != null) {
|
||||
return this.next.get(index);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class IntStack {
|
||||
|
||||
public int c;
|
||||
public IntStack next;
|
||||
public int size;
|
||||
|
||||
public IntStack(int c) {
|
||||
this.size = 1;
|
||||
this.c = c;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
public void push(int c) {
|
||||
size = size + 1;
|
||||
if (this.next == null) {
|
||||
this.next = new IntStack(c);
|
||||
} else {
|
||||
this.next.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
public int pop() {
|
||||
size = size - 1;
|
||||
if (this.next.next == null) {
|
||||
int temp = this.next.c;
|
||||
this.next = null;
|
||||
return temp;
|
||||
} else {
|
||||
return this.next.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/test/resources/Integration/LOFOI.java
Normal file
23
src/test/resources/Integration/LOFOI.java
Normal file
@ -0,0 +1,23 @@
|
||||
package Integration;
|
||||
|
||||
// Local or Field or Imported var Test
|
||||
class LOFOI {
|
||||
|
||||
// This test is to determine wheter the order of finding the vars is correct
|
||||
|
||||
int System;
|
||||
|
||||
public LOFOI() {
|
||||
System = 10;
|
||||
}
|
||||
|
||||
public int foo() {
|
||||
int System = 20;
|
||||
return System;
|
||||
}
|
||||
|
||||
public int bar() {
|
||||
return System;
|
||||
}
|
||||
|
||||
}
|
80
src/test/resources/Integration/LinkedList.java
Normal file
80
src/test/resources/Integration/LinkedList.java
Normal file
@ -0,0 +1,80 @@
|
||||
package Integration;
|
||||
|
||||
class LinkedList {
|
||||
|
||||
public int value;
|
||||
public LinkedList next;
|
||||
public int size;
|
||||
|
||||
public LinkedList(int value) {
|
||||
this.value = value;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void set(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public LinkedList getNode(int i) {
|
||||
if (i == 0) {
|
||||
return this;
|
||||
} else {
|
||||
return this.next.getNode(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void swap(int i, int j) {
|
||||
int temp = getNode(i).get();
|
||||
getNode(i).set(getNode(j).get());
|
||||
getNode(j).set(temp);
|
||||
}
|
||||
|
||||
public void add(int value) {
|
||||
size = size + 1;
|
||||
if (this.next == null) {
|
||||
this.next = new LinkedList(value);
|
||||
|
||||
} else {
|
||||
this.next.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Executer {
|
||||
|
||||
void foo() {
|
||||
LinkedList list = new LinkedList(3);
|
||||
list.add(2);
|
||||
list.add(7);
|
||||
list.add(5);
|
||||
list.add(1);
|
||||
list.add(8);
|
||||
list.add(6);
|
||||
list.add(4);
|
||||
}
|
||||
|
||||
LinkedList sort(LinkedList list) {
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i < list.size - 1) {
|
||||
j = 0;
|
||||
while (j < list.size - 1) {
|
||||
if (list.getNode(j).get() > list.getNode(j + 1).get()) {
|
||||
list.swap(j, j + 1);
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
}
|
55
src/test/resources/Integration/Stack.java
Normal file
55
src/test/resources/Integration/Stack.java
Normal file
@ -0,0 +1,55 @@
|
||||
package Integration;
|
||||
|
||||
class Stack {
|
||||
|
||||
private int value;
|
||||
private Stack next;
|
||||
public int size;
|
||||
|
||||
public Stack(int value) {
|
||||
this.value = value;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
public int peek(int i) {
|
||||
if (i == 0) {
|
||||
return this.value;
|
||||
} else {
|
||||
return this.next.peek(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void push(int value) {
|
||||
size = size + 1;
|
||||
if (this.next == null) {
|
||||
this.next = new Stack(value);
|
||||
|
||||
} else {
|
||||
this.next.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
public int pop() {
|
||||
size = size - 1;
|
||||
if (this.next == null) {
|
||||
return this.value;
|
||||
} else {
|
||||
return this.next.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Executer {
|
||||
|
||||
void foo() {
|
||||
Stack stack = new Stack(1);
|
||||
stack.push(2);
|
||||
stack.push(3);
|
||||
stack.push(4);
|
||||
stack.push(5);
|
||||
stack.push(6);
|
||||
|
||||
}
|
||||
|
||||
}
|
48
src/test/resources/Integration/StringList.java
Normal file
48
src/test/resources/Integration/StringList.java
Normal file
@ -0,0 +1,48 @@
|
||||
package Integration;
|
||||
|
||||
class StringList {
|
||||
|
||||
private char value;
|
||||
private StringList next;
|
||||
|
||||
public StringList() {
|
||||
}
|
||||
|
||||
public StringList(char c) {
|
||||
this.value = c;
|
||||
}
|
||||
|
||||
public char get(int i) {
|
||||
if (i == 0) {
|
||||
return this.value;
|
||||
} else {
|
||||
return next.get(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(char value) {
|
||||
if (next == null) {
|
||||
next = new StringList(value);
|
||||
} else {
|
||||
next.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public int length() {
|
||||
if (this.next == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return 1 + next.length();
|
||||
}
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.print(this.value);
|
||||
if (this.next != null) {
|
||||
next.print();
|
||||
} else {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
src/test/resources/NotTested/BinaryTests.java
Normal file
31
src/test/resources/NotTested/BinaryTests.java
Normal file
@ -0,0 +1,31 @@
|
||||
package NotTested;
|
||||
|
||||
class BinaryTests{
|
||||
|
||||
private int a,b,c;
|
||||
|
||||
public int pvs() {
|
||||
return a+b*c;
|
||||
}
|
||||
|
||||
public int klammern() {
|
||||
return a * (b+c);
|
||||
}
|
||||
|
||||
public int modulo(){
|
||||
return a%b;
|
||||
}
|
||||
|
||||
public boolean avo() {
|
||||
return a || b && c;
|
||||
}
|
||||
|
||||
public boolean binary() {
|
||||
return a == b && !c;
|
||||
}
|
||||
|
||||
public int endBoss() {
|
||||
return (a%c) + b / (a * a) * a + a - (c-b/a) && b-c;
|
||||
}
|
||||
|
||||
}
|
19
src/test/resources/NotTested/CharWrapper.java
Normal file
19
src/test/resources/NotTested/CharWrapper.java
Normal file
@ -0,0 +1,19 @@
|
||||
package NotTested;
|
||||
|
||||
class CharWrapper{
|
||||
|
||||
private char c;
|
||||
|
||||
public CharWrapper(char c){
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public void setChar(char c){
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public char getChar(){
|
||||
return this.c;
|
||||
}
|
||||
|
||||
}
|
33
src/test/resources/NotTested/ClassStress.java
Normal file
33
src/test/resources/NotTested/ClassStress.java
Normal file
@ -0,0 +1,33 @@
|
||||
package NotTested;
|
||||
|
||||
class ClassStress{
|
||||
|
||||
private int x = 100;
|
||||
|
||||
public ClassStress(int x){
|
||||
this.x = x*2%2+x/10 % 100*x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ClassStress2{
|
||||
|
||||
private int x = 2;
|
||||
private boolean b = true;
|
||||
private ClassStress cd = new ClassStress(3);
|
||||
|
||||
public ClassStress2(int x, ClassStress cs, boolean b){
|
||||
this.x = x;
|
||||
this.b = b;
|
||||
this.cs = cs
|
||||
}
|
||||
|
||||
public ClassStress2(int x){
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public foo(){
|
||||
return new ClassStress2(1, new ClassStress(this.cd.x), this.b);
|
||||
}
|
||||
|
||||
}
|
16
src/test/resources/NotTested/Fib.java
Normal file
16
src/test/resources/NotTested/Fib.java
Normal file
@ -0,0 +1,16 @@
|
||||
package NotTested;
|
||||
|
||||
public class Fibonacci
|
||||
{
|
||||
public int fibonacci(int n)
|
||||
{
|
||||
if (n <= 1)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return fibonacci(n-1) + fibonacci(n-2);
|
||||
}
|
||||
}
|
||||
}
|
37
src/test/resources/NotTested/FibIntegerWrapper.java
Normal file
37
src/test/resources/NotTested/FibIntegerWrapper.java
Normal file
@ -0,0 +1,37 @@
|
||||
package NotTested;
|
||||
|
||||
class IntegerWrapper{
|
||||
|
||||
public int i;
|
||||
|
||||
public IntegerWrapper(int i){
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public IntegerWrapper(){
|
||||
this.i = 0;
|
||||
}
|
||||
|
||||
public IntegerWrapper Add(IntegerWrapper j){ return new IntegerWrapper(j.i+this.i)}
|
||||
|
||||
public IntegerWrapper Sub(IntegerWrapper j){ return new IntegerWrapper(j.i-this.i)}
|
||||
|
||||
public boolean equals(IntegerWrapper j){return j.i == this.i}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Fibonacci
|
||||
{
|
||||
public IntegerWrapper fibonacci(IntegerWrapper n)
|
||||
{
|
||||
if (n.LessThan(new IntegerWrapper(2)))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return fibonacci(n.Sub(new IntegerWrapper(1))).Add(fibonacci(n.Sub(new IntegerWrapper(2))));
|
||||
}
|
||||
}
|
||||
}
|
30
src/test/resources/NotTested/IfTest.java
Normal file
30
src/test/resources/NotTested/IfTest.java
Normal file
@ -0,0 +1,30 @@
|
||||
package NotTested;
|
||||
|
||||
class IfTest{
|
||||
|
||||
public int ifTest(){
|
||||
if(true){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int ifElseTest(){
|
||||
if(true){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int ifElseIfTest(){
|
||||
if(false){
|
||||
return 0;
|
||||
}else if(true){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/NotTested/TwoClasses.java
Normal file
9
src/test/resources/NotTested/TwoClasses.java
Normal file
@ -0,0 +1,9 @@
|
||||
package NotTested;
|
||||
|
||||
class TwoClasses{
|
||||
|
||||
}
|
||||
|
||||
class TwoClasses{
|
||||
|
||||
}
|
27
src/test/resources/NotTested/TwoClassesReferences.java
Normal file
27
src/test/resources/NotTested/TwoClassesReferences.java
Normal file
@ -0,0 +1,27 @@
|
||||
package NotTested;
|
||||
|
||||
class TwoClassesFilled{
|
||||
|
||||
private int i;
|
||||
public int a = 4;
|
||||
|
||||
public TwoClassesFilled(int i){
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class TwoClassesFilled2{
|
||||
|
||||
private TwoClassesFilled a;
|
||||
|
||||
public TwoClassesFilled2(int a){
|
||||
this.a = new TwoClassesFilled(a);
|
||||
}
|
||||
|
||||
public int get(){
|
||||
return this.a.a;
|
||||
}
|
||||
|
||||
}
|
10
src/test/resources/NotTested/VoidMethod.java
Normal file
10
src/test/resources/NotTested/VoidMethod.java
Normal file
@ -0,0 +1,10 @@
|
||||
package NotTested;
|
||||
|
||||
class VoidMethod{
|
||||
|
||||
|
||||
public void test(){
|
||||
|
||||
}
|
||||
|
||||
}
|
10
src/test/resources/NotTested/VoidMethodReturn.java
Normal file
10
src/test/resources/NotTested/VoidMethodReturn.java
Normal file
@ -0,0 +1,10 @@
|
||||
package NotTested;
|
||||
|
||||
class VoidMethodReturn{
|
||||
|
||||
|
||||
public void test(){
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
19
src/test/resources/NotTested/WhileTest.java
Normal file
19
src/test/resources/NotTested/WhileTest.java
Normal file
@ -0,0 +1,19 @@
|
||||
package NotTested;
|
||||
|
||||
class WhileTest{
|
||||
|
||||
public void infinite(){
|
||||
while(true){}
|
||||
}
|
||||
|
||||
public int ten(){
|
||||
int i = 0;
|
||||
int counter = 10;
|
||||
while(counter>0){
|
||||
i = i+1;
|
||||
counter = counter - 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
25
src/test/resources/NotTested/ggt.java
Normal file
25
src/test/resources/NotTested/ggt.java
Normal file
@ -0,0 +1,25 @@
|
||||
package NotTested;
|
||||
|
||||
class ggt{
|
||||
|
||||
private int a;
|
||||
private int b;
|
||||
|
||||
public ggt(int a, int b){
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int calculate(){
|
||||
int c;
|
||||
int a = this.a;
|
||||
int b = this.b;
|
||||
while ( b != 0) {
|
||||
c = a % b;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
}
|
13
src/test/resources/SimpleTests/AndVorOr.java
Normal file
13
src/test/resources/SimpleTests/AndVorOr.java
Normal file
@ -0,0 +1,13 @@
|
||||
package SimpleTests;
|
||||
|
||||
class AndVorOr {
|
||||
|
||||
boolean foo(boolean a, boolean b, boolean c) {
|
||||
return a && b || c && b;
|
||||
}
|
||||
|
||||
boolean bar(boolean a, boolean b, boolean c) {
|
||||
return a || b && c || b && c;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class AutoAccessModifierField {
|
||||
|
||||
int autoAccess;
|
||||
|
||||
}
|
15
src/test/resources/SimpleTests/CharArgument.java
Normal file
15
src/test/resources/SimpleTests/CharArgument.java
Normal file
@ -0,0 +1,15 @@
|
||||
package SimpleTests;
|
||||
|
||||
class CharArgument {
|
||||
|
||||
char c;
|
||||
|
||||
public CharArgument() {
|
||||
this.c = foo('a');
|
||||
}
|
||||
|
||||
char foo(char c) {
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/ClassFields.java
Normal file
9
src/test/resources/SimpleTests/ClassFields.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ClassFields {
|
||||
|
||||
private int privateAccess;
|
||||
public int publicAccess;
|
||||
protected int protectedAccess;
|
||||
|
||||
}
|
21
src/test/resources/SimpleTests/Comments.java
Normal file
21
src/test/resources/SimpleTests/Comments.java
Normal file
@ -0,0 +1,21 @@
|
||||
package SimpleTests;
|
||||
|
||||
class Comments{
|
||||
|
||||
private int lorem;
|
||||
|
||||
// One Line Comment!!!!! IGNORE THAT
|
||||
|
||||
private boolean ipsum;
|
||||
|
||||
/*
|
||||
MULT-LINE COMMENT! IGNORE THIS
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Should be ignored
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
16
src/test/resources/SimpleTests/ConditionalEvaluation.java
Normal file
16
src/test/resources/SimpleTests/ConditionalEvaluation.java
Normal file
@ -0,0 +1,16 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ConditionalEvaluation {
|
||||
|
||||
boolean foo() {
|
||||
System.out.println("foo");
|
||||
return true || bar();
|
||||
}
|
||||
|
||||
boolean bar() {
|
||||
System.out.println("bar");
|
||||
|
||||
return true && foo();
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/ConstructorParams.java
Normal file
9
src/test/resources/SimpleTests/ConstructorParams.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ConstructorParams {
|
||||
|
||||
public ConstructorParams(int i) {
|
||||
|
||||
}
|
||||
|
||||
}
|
11
src/test/resources/SimpleTests/ConstructorThisDot.java
Normal file
11
src/test/resources/SimpleTests/ConstructorThisDot.java
Normal file
@ -0,0 +1,11 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ConstructorThisDot{
|
||||
|
||||
public int i;
|
||||
|
||||
public ConstructorThisDot(){
|
||||
this.i = 5;
|
||||
}
|
||||
|
||||
}
|
17
src/test/resources/SimpleTests/DecTest.java
Normal file
17
src/test/resources/SimpleTests/DecTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package SimpleTests;
|
||||
|
||||
class DecTest {
|
||||
|
||||
void foo() {
|
||||
for (int i = 10; i > 0; i--) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
void bar() {
|
||||
for (int i = 10; i > 0; --i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/DivMethod.java
Normal file
9
src/test/resources/SimpleTests/DivMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class DivMethod {
|
||||
|
||||
int foo(int i){
|
||||
return i/i;
|
||||
}
|
||||
|
||||
}
|
3
src/test/resources/SimpleTests/EmptyClass.java
Normal file
3
src/test/resources/SimpleTests/EmptyClass.java
Normal file
@ -0,0 +1,3 @@
|
||||
package SimpleTests;
|
||||
|
||||
class EmptyClass{}
|
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class EmptyClassWithConstructor{
|
||||
|
||||
public EmptyClassWithConstructor(){
|
||||
|
||||
}
|
||||
|
||||
}
|
10
src/test/resources/SimpleTests/ExplicitNullAssign.java
Normal file
10
src/test/resources/SimpleTests/ExplicitNullAssign.java
Normal file
@ -0,0 +1,10 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ExplicitNullAssign {
|
||||
|
||||
ExplicitNullAssign e;
|
||||
|
||||
void test() {
|
||||
e = null;
|
||||
}
|
||||
}
|
18
src/test/resources/SimpleTests/ExtendedNotTest.java
Normal file
18
src/test/resources/SimpleTests/ExtendedNotTest.java
Normal file
@ -0,0 +1,18 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ExtendedNotTest {
|
||||
|
||||
boolean notequal(int a, int b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
boolean multiple(boolean a, boolean b) {
|
||||
return !(!a || b);
|
||||
}
|
||||
|
||||
boolean notWithAssigns(boolean a) {
|
||||
boolean b = !a;
|
||||
return !b;
|
||||
}
|
||||
|
||||
}
|
7
src/test/resources/SimpleTests/FieldWithExpr.java
Normal file
7
src/test/resources/SimpleTests/FieldWithExpr.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class FieldWithExpr {
|
||||
|
||||
public int x = 5;
|
||||
|
||||
}
|
11
src/test/resources/SimpleTests/ForTest.java
Normal file
11
src/test/resources/SimpleTests/ForTest.java
Normal file
@ -0,0 +1,11 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ForTest {
|
||||
|
||||
void foo() {
|
||||
for (int i = 0; i < 10; i = i + 1) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
63
src/test/resources/SimpleTests/FourClasses.java
Normal file
63
src/test/resources/SimpleTests/FourClasses.java
Normal file
@ -0,0 +1,63 @@
|
||||
package SimpleTests;
|
||||
|
||||
class FourClasses {
|
||||
|
||||
public int main(int i) {
|
||||
Test t = new Test(i);
|
||||
Test2 t2 = new Test2(t.y);
|
||||
return t2.test.test3.getX();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
private int x;
|
||||
public int y;
|
||||
public Test3 test3;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
this.y = 10;
|
||||
this.test3 = new Test3(i * 2);
|
||||
}
|
||||
|
||||
public Test3 getTest3() {
|
||||
return this.test3;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
public Test test;
|
||||
|
||||
public Test2(int i) {
|
||||
this.test = new Test(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
public int x;
|
||||
|
||||
private int y;
|
||||
|
||||
public Test3(int i) {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
64
src/test/resources/SimpleTests/FourClassesFieldAssign.java
Normal file
64
src/test/resources/SimpleTests/FourClassesFieldAssign.java
Normal file
@ -0,0 +1,64 @@
|
||||
package SimpleTests;
|
||||
|
||||
class FourClassesFieldAssign {
|
||||
|
||||
public int fieldAssign(int i) {
|
||||
Test t = new Test(i);
|
||||
Test2 t2 = new Test2(t.y);
|
||||
t2.test.test3.x = i;
|
||||
return t2.test.test3.getX();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
private int x;
|
||||
public int y;
|
||||
public Test3 test3;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
this.y = 10;
|
||||
this.test3 = new Test3(i * 2);
|
||||
}
|
||||
|
||||
public Test3 getTest3() {
|
||||
return this.test3;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
public Test test;
|
||||
|
||||
public Test2(int i) {
|
||||
this.test = new Test(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
public int x;
|
||||
|
||||
private int y;
|
||||
|
||||
public Test3(int i) {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
65
src/test/resources/SimpleTests/FourClassesSetter.java
Normal file
65
src/test/resources/SimpleTests/FourClassesSetter.java
Normal file
@ -0,0 +1,65 @@
|
||||
package SimpleTests;
|
||||
|
||||
class FourClassesSetter {
|
||||
|
||||
public int setFieldTest(int i) {
|
||||
Test t = new Test(i);
|
||||
Test2 t2 = new Test2(t.y);
|
||||
t2.test.test3.setY(i);
|
||||
|
||||
return t2.test.test3.getY();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
private int x;
|
||||
public int y;
|
||||
public Test3 test3;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
this.y = 10;
|
||||
this.test3 = new Test3(i * 2);
|
||||
}
|
||||
|
||||
public Test3 getTest3() {
|
||||
return this.test3;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
public Test test;
|
||||
|
||||
public Test2(int i) {
|
||||
this.test = new Test(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
public int x;
|
||||
|
||||
private int y;
|
||||
|
||||
public Test3(int i) {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
15
src/test/resources/SimpleTests/GetterFunction.java
Normal file
15
src/test/resources/SimpleTests/GetterFunction.java
Normal file
@ -0,0 +1,15 @@
|
||||
package SimpleTests;
|
||||
|
||||
class GetterFunction {
|
||||
|
||||
private int i;
|
||||
|
||||
public GetterFunction(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getI() {
|
||||
return this.i;
|
||||
}
|
||||
|
||||
}
|
11
src/test/resources/SimpleTests/IfConstructor.java
Normal file
11
src/test/resources/SimpleTests/IfConstructor.java
Normal file
@ -0,0 +1,11 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfConstructor {
|
||||
|
||||
int i;
|
||||
|
||||
public IfConstructor() {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
}
|
15
src/test/resources/SimpleTests/IfElseIfStatement.java
Normal file
15
src/test/resources/SimpleTests/IfElseIfStatement.java
Normal file
@ -0,0 +1,15 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfElseIfStatement {
|
||||
|
||||
int foo(int i) {
|
||||
if (i == 1) {
|
||||
return 10;
|
||||
} else if (i == 2) {
|
||||
return 40000;
|
||||
} else {
|
||||
return 42000;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfElseIfStatementWithOneReturn {
|
||||
|
||||
int foo(int i) {
|
||||
int result = 0;
|
||||
if (i == 1) {
|
||||
result = 10;
|
||||
} else if (i == 2) {
|
||||
return 20;
|
||||
} else {
|
||||
result = 30;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfElseIfStatementWithoutReturn {
|
||||
|
||||
int foo(int i) {
|
||||
int result;
|
||||
if (i == 1) {
|
||||
result = 10;
|
||||
} else if (i == 2) {
|
||||
result = 20;
|
||||
} else {
|
||||
result = 30;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
13
src/test/resources/SimpleTests/IfElseStatement.java
Normal file
13
src/test/resources/SimpleTests/IfElseStatement.java
Normal file
@ -0,0 +1,13 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfElseStatement {
|
||||
|
||||
int foo(int i) {
|
||||
if (i == 1) {
|
||||
return 10;
|
||||
} else {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
src/test/resources/SimpleTests/IfStatement.java
Normal file
12
src/test/resources/SimpleTests/IfStatement.java
Normal file
@ -0,0 +1,12 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IfStatement {
|
||||
|
||||
int foo(int i) {
|
||||
if (i == 1) {
|
||||
return 10;
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
}
|
26
src/test/resources/SimpleTests/IncDecStressTest.java
Normal file
26
src/test/resources/SimpleTests/IncDecStressTest.java
Normal file
@ -0,0 +1,26 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IncDecStressTest {
|
||||
|
||||
int incrementThenReturn(int i) {
|
||||
return ++i;
|
||||
}
|
||||
|
||||
int returnThenIncrement(int i) {
|
||||
return i++;
|
||||
}
|
||||
|
||||
int decrementThenReturn(int i) {
|
||||
return --i;
|
||||
}
|
||||
|
||||
int returnThenDecrement(int i) {
|
||||
return i--;
|
||||
}
|
||||
|
||||
int callInline(int i) {
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
17
src/test/resources/SimpleTests/IncTest.java
Normal file
17
src/test/resources/SimpleTests/IncTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IncTest {
|
||||
|
||||
void foo() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
void bar() {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/IntCompare.java
Normal file
9
src/test/resources/SimpleTests/IntCompare.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IntCompare {
|
||||
|
||||
boolean eq(int a, int b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/IntMethod.java
Normal file
9
src/test/resources/SimpleTests/IntMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class IntMethod {
|
||||
|
||||
int foo(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/KlammerVorPunkt.java
Normal file
9
src/test/resources/SimpleTests/KlammerVorPunkt.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class KlammerVorPunkt {
|
||||
|
||||
int foo(int a, int b, int c) {
|
||||
return (b + c) * a;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/MainMethodTest.java
Normal file
9
src/test/resources/SimpleTests/MainMethodTest.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MainMethodTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("maintest");
|
||||
}
|
||||
|
||||
}
|
15
src/test/resources/SimpleTests/MethodCall.java
Normal file
15
src/test/resources/SimpleTests/MethodCall.java
Normal file
@ -0,0 +1,15 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MethodCall {
|
||||
|
||||
int i;
|
||||
|
||||
public MethodCall() {
|
||||
this.i = foo();
|
||||
}
|
||||
|
||||
int foo() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
15
src/test/resources/SimpleTests/MethodCallParams.java
Normal file
15
src/test/resources/SimpleTests/MethodCallParams.java
Normal file
@ -0,0 +1,15 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MethodCallParams {
|
||||
|
||||
int i;
|
||||
|
||||
public MethodCallParams(int i) {
|
||||
this.i = foo(i);
|
||||
}
|
||||
|
||||
int foo(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
34
src/test/resources/SimpleTests/MethodCallStressTest.java
Normal file
34
src/test/resources/SimpleTests/MethodCallStressTest.java
Normal file
@ -0,0 +1,34 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MethodCallStressTest {
|
||||
|
||||
void foo() {
|
||||
int i = baz();
|
||||
while (i < 10) {
|
||||
baz();
|
||||
bar();
|
||||
i = i + baz();
|
||||
}
|
||||
|
||||
i = baz() - baz();
|
||||
i = baz() + baz();
|
||||
|
||||
if (boo()) {
|
||||
i = baz();
|
||||
} else {
|
||||
i = baz();
|
||||
}
|
||||
}
|
||||
|
||||
void bar() {
|
||||
}
|
||||
|
||||
int baz() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean boo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
23
src/test/resources/SimpleTests/MethodCallsInWhile.java
Normal file
23
src/test/resources/SimpleTests/MethodCallsInWhile.java
Normal file
@ -0,0 +1,23 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MethodCallsInWhile {
|
||||
|
||||
void main() {
|
||||
int i = 0;
|
||||
Test t = new Test();
|
||||
t.foo();
|
||||
while (i < 10) {
|
||||
i = i + t.foo();
|
||||
t.foo(); // <-- This is causing the error
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
|
||||
int foo() {
|
||||
return 1;
|
||||
}
|
||||
}
|
25
src/test/resources/SimpleTests/MiniLinkedList.java
Normal file
25
src/test/resources/SimpleTests/MiniLinkedList.java
Normal file
@ -0,0 +1,25 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MiniLinkedList {
|
||||
|
||||
int main() {
|
||||
LinkedList list = new LinkedList(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LinkedList {
|
||||
|
||||
int x;
|
||||
private LinkedList next;
|
||||
|
||||
public LinkedList(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
void add(int x) {
|
||||
next = new LinkedList(x);
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/MinusMethod.java
Normal file
9
src/test/resources/SimpleTests/MinusMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MinusMethod {
|
||||
|
||||
int foo(int i){
|
||||
return i-i;
|
||||
}
|
||||
|
||||
}
|
7
src/test/resources/SimpleTests/ModMethod.java
Normal file
7
src/test/resources/SimpleTests/ModMethod.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ModMethod {
|
||||
int foo(int i, int j) {
|
||||
return i % j;
|
||||
}
|
||||
}
|
9
src/test/resources/SimpleTests/MulMethod.java
Normal file
9
src/test/resources/SimpleTests/MulMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MulMethod {
|
||||
|
||||
int foo(int i){
|
||||
return i*i;
|
||||
}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/MultClasses.java
Normal file
9
src/test/resources/SimpleTests/MultClasses.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MultClasses1 {
|
||||
|
||||
}
|
||||
|
||||
class MultClasses2 {
|
||||
|
||||
}
|
26
src/test/resources/SimpleTests/MultClassesReference.java
Normal file
26
src/test/resources/SimpleTests/MultClassesReference.java
Normal file
@ -0,0 +1,26 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MultClassesReference1 {
|
||||
|
||||
public int i;
|
||||
|
||||
public MultClassesReference1(int i){
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MultClassesReference2 {
|
||||
|
||||
public MultClassesReference1 bar;
|
||||
|
||||
public MultClassesReference2(int i){
|
||||
this.bar = new MultClassesReference1(i);
|
||||
}
|
||||
|
||||
int test(){
|
||||
return this.bar.i;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MultipleClassesMethodCalls {
|
||||
|
||||
public int main(int i) {
|
||||
Test t = new Test(i);
|
||||
return t.getX();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
public int x;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
24
src/test/resources/SimpleTests/MultipleClassesStress.java
Normal file
24
src/test/resources/SimpleTests/MultipleClassesStress.java
Normal file
@ -0,0 +1,24 @@
|
||||
package SimpleTests;
|
||||
|
||||
class MultipleClassesStress {
|
||||
|
||||
public int main(int i) {
|
||||
Test t = new Test(i);
|
||||
return t.getX() + t.y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
private int x;
|
||||
public int y;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
this.y = 10;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
7
src/test/resources/SimpleTests/NotMethod.java
Normal file
7
src/test/resources/SimpleTests/NotMethod.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class NotMethod {
|
||||
boolean foo(boolean i) {
|
||||
return !i;
|
||||
}
|
||||
}
|
21
src/test/resources/SimpleTests/OperatorStacking.java
Normal file
21
src/test/resources/SimpleTests/OperatorStacking.java
Normal file
@ -0,0 +1,21 @@
|
||||
package SimpleTests;
|
||||
|
||||
class OperatorStacking {
|
||||
|
||||
boolean foo() {
|
||||
return true && false || true && true; // Should return true
|
||||
}
|
||||
|
||||
int bar() {
|
||||
return 1 + 2 * 3 - 4 % 6; // Should return 3
|
||||
}
|
||||
// 1 + 6 - 4 % 6
|
||||
// 7 - 4 % 6
|
||||
// 3 % 6 = 3
|
||||
|
||||
// 1 + 6 - 4 % 6
|
||||
// 1 + 6 - 4
|
||||
// 7-4
|
||||
// 3
|
||||
|
||||
}
|
86
src/test/resources/SimpleTests/OperatorTest.java
Normal file
86
src/test/resources/SimpleTests/OperatorTest.java
Normal file
@ -0,0 +1,86 @@
|
||||
package SimpleTests;
|
||||
|
||||
class OperatorTest {
|
||||
|
||||
public OperatorTest() {
|
||||
}
|
||||
|
||||
public int assign(int i) {
|
||||
int returnValue;
|
||||
returnValue = i;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public int plus(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
public int minus(int x, int y) {
|
||||
return x - y;
|
||||
}
|
||||
|
||||
public int mult(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
public int div(int x, int y) {
|
||||
return x / y;
|
||||
}
|
||||
|
||||
public int mod(int x, int y) {
|
||||
return x % y;
|
||||
}
|
||||
|
||||
public boolean gt(int x, int y) {
|
||||
return x > y;
|
||||
}
|
||||
|
||||
public boolean lt(int x, int y) {
|
||||
return x < y;
|
||||
}
|
||||
|
||||
public boolean lte(int x, int y) {
|
||||
return x <= y;
|
||||
}
|
||||
|
||||
public boolean gte(int x, int y) {
|
||||
return x >= y;
|
||||
}
|
||||
|
||||
public boolean eq(int x, int y) {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public boolean neq(int x, int y) {
|
||||
return x != y;
|
||||
}
|
||||
|
||||
public boolean beq(boolean x, boolean y) {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public boolean bneq(boolean x, boolean y) {
|
||||
return x != y;
|
||||
}
|
||||
|
||||
public boolean and(boolean x, boolean y) {
|
||||
return x && y;
|
||||
}
|
||||
|
||||
public boolean or(boolean x, boolean y) {
|
||||
return x || y;
|
||||
}
|
||||
|
||||
public boolean not(boolean x) {
|
||||
return !x;
|
||||
}
|
||||
|
||||
public boolean icEq(int x, char y) {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public boolean icLt(int x, char y) {
|
||||
return x < y;
|
||||
}
|
||||
|
||||
}
|
32
src/test/resources/SimpleTests/OverridingTest.java
Normal file
32
src/test/resources/SimpleTests/OverridingTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package SimpleTests;
|
||||
|
||||
class OverridingTest {
|
||||
|
||||
// Test is used to determine wheter the Right method with the right types is
|
||||
// called
|
||||
|
||||
public int foo(int i) {
|
||||
if (i < 5) {
|
||||
return test();
|
||||
} else if (i < 10) {
|
||||
return test(i);
|
||||
} else {
|
||||
return test(this);
|
||||
}
|
||||
}
|
||||
|
||||
public int test() {
|
||||
System.out.println(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int test(int i) {
|
||||
System.out.println(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
public int test(OverridingTest o) {
|
||||
return 1337;
|
||||
}
|
||||
|
||||
}
|
35
src/test/resources/SimpleTests/OverridingTestNull.java
Normal file
35
src/test/resources/SimpleTests/OverridingTestNull.java
Normal file
@ -0,0 +1,35 @@
|
||||
package SimpleTests;
|
||||
|
||||
class OverridingTestNull {
|
||||
|
||||
// Test is used to determine wheter the Right method with the right types is
|
||||
// called
|
||||
|
||||
public int foo(int i) {
|
||||
if (i < 5) {
|
||||
return test();
|
||||
} else if (i < 10) {
|
||||
return test(i);
|
||||
} else if (i < 20) {
|
||||
return test(this);
|
||||
} else {
|
||||
return test(null);
|
||||
}
|
||||
}
|
||||
|
||||
public int test() {
|
||||
System.out.println(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int test(int i) {
|
||||
System.out.println(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
public int test(OverridingTestNull o) {
|
||||
System.out.println(1337);
|
||||
return 1337;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package SimpleTests;
|
||||
|
||||
class OverridingTestNullMultiple {
|
||||
|
||||
// Test is used to determine wheter the Right method with the right types is
|
||||
// called
|
||||
|
||||
public int foo(int i) {
|
||||
if (i < 5) {
|
||||
return test();
|
||||
} else if (i < 10) {
|
||||
return test(i);
|
||||
} else if (i < 20) {
|
||||
return test(this, null);
|
||||
} else if (i < 30) {
|
||||
return test(null, null);
|
||||
} else {
|
||||
return test(this, this);
|
||||
}
|
||||
}
|
||||
|
||||
public int test() {
|
||||
System.out.println(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int test(int i) {
|
||||
System.out.println(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
public int test(OverridingTestNullMultiple o, OverridingTestNullMultiple b) {
|
||||
System.out.println(1337);
|
||||
return 1337;
|
||||
}
|
||||
|
||||
}
|
7
src/test/resources/SimpleTests/ParamMethod.java
Normal file
7
src/test/resources/SimpleTests/ParamMethod.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class ParamMethod {
|
||||
|
||||
void foo(int i){}
|
||||
|
||||
}
|
9
src/test/resources/SimpleTests/PlusMethod.java
Normal file
9
src/test/resources/SimpleTests/PlusMethod.java
Normal file
@ -0,0 +1,9 @@
|
||||
package SimpleTests;
|
||||
|
||||
class PlusMethod {
|
||||
|
||||
int foo(int i){
|
||||
return i+i;
|
||||
}
|
||||
|
||||
}
|
13
src/test/resources/SimpleTests/PunktVorStrich.java
Normal file
13
src/test/resources/SimpleTests/PunktVorStrich.java
Normal file
@ -0,0 +1,13 @@
|
||||
package SimpleTests;
|
||||
|
||||
class PunktVorStrich {
|
||||
|
||||
int foo(int a, int b, int c) {
|
||||
return a * b + c;
|
||||
}
|
||||
|
||||
int bar(int a, int b, int c) {
|
||||
return a + b * c;
|
||||
}
|
||||
|
||||
}
|
11
src/test/resources/SimpleTests/RealConstructor.java
Normal file
11
src/test/resources/SimpleTests/RealConstructor.java
Normal file
@ -0,0 +1,11 @@
|
||||
package SimpleTests;
|
||||
|
||||
class RealConstructor {
|
||||
|
||||
private int i;
|
||||
|
||||
public RealConstructor(int i){
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
}
|
7
src/test/resources/SimpleTests/RealMethod.java
Normal file
7
src/test/resources/SimpleTests/RealMethod.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SimpleTests;
|
||||
|
||||
class RealMethod {
|
||||
int foo(int i){
|
||||
return i;
|
||||
}
|
||||
}
|
14
src/test/resources/SimpleTests/RealWhile.java
Normal file
14
src/test/resources/SimpleTests/RealWhile.java
Normal file
@ -0,0 +1,14 @@
|
||||
package SimpleTests;
|
||||
|
||||
class RealWhile {
|
||||
|
||||
int foo(int i) {
|
||||
int result = 0;
|
||||
while (i > 0) {
|
||||
result = result + 2;
|
||||
i = i - 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
20
src/test/resources/SimpleTests/SelfReference.java
Normal file
20
src/test/resources/SimpleTests/SelfReference.java
Normal file
@ -0,0 +1,20 @@
|
||||
package SimpleTests;
|
||||
|
||||
class SelfReference {
|
||||
|
||||
SelfReference selfRef;
|
||||
|
||||
int foo() {
|
||||
return this.baz();
|
||||
}
|
||||
|
||||
int baz() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
int bar() {
|
||||
SelfReference self = new SelfReference();
|
||||
return self.selfRef.foo();
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user