mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:18:03 +00:00
fixed program instead of classes and did some renaming etc
This commit is contained in:
parent
131264d27e
commit
f5cc94316e
@ -47,8 +47,7 @@ public class Compiler {
|
||||
}
|
||||
|
||||
public static TypedProgram generateTypedASTFromAst(Program ast) {
|
||||
TypedProgram typedAST = new TypedProgram(ast);
|
||||
return typedAST;
|
||||
return new TypedProgram(ast);
|
||||
}
|
||||
|
||||
public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) {
|
||||
@ -99,6 +98,6 @@ public class Compiler {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassCanBeTyped.java"), List.of("ClassCanBeTyped"));
|
||||
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java"), List.of("ComplexClass"));
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package de.maishai.typedast.typedclass;
|
||||
|
||||
import de.maishai.ast.records.Program;
|
||||
import de.maishai.typedast.ClassContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TypedProgram {
|
||||
private List<TypedClass> typedClasses = new ArrayList<>();
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
public class ClassCanBeTyped {
|
||||
public class ComplexClass {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
ClassCanBeTyped b;
|
||||
ClassCanBeTyped c;
|
||||
public ClassCanBeTyped(int x) {
|
||||
ComplexClass b;
|
||||
ComplexClass c;
|
||||
public ComplexClass(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
public ClassCanBeTyped(int x, int y) {
|
||||
public ComplexClass(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
public ClassCanBeTyped initClassCanBeTyped(int x) {
|
||||
public ComplexClass initComplexClass(int x) {
|
||||
int a;
|
||||
a = 10;
|
||||
b = new ClassCanBeTyped(x);
|
||||
b = new ComplexClass(x);
|
||||
b.x = 10 + a;
|
||||
b.y = 20;
|
||||
b.c.x = 20 + a;
|
||||
@ -22,17 +22,17 @@ public class ClassCanBeTyped {
|
||||
|
||||
return b;
|
||||
}
|
||||
public ClassCanBeTyped init(int x, int y) {
|
||||
return new ClassCanBeTyped(x, y);
|
||||
public ComplexClass init(int x, int y) {
|
||||
return new ComplexClass(x, y);
|
||||
}
|
||||
public ClassCanBeTyped(int x) {
|
||||
public ComplexClass(int x) {
|
||||
this.x = x;
|
||||
int i;
|
||||
b = b.getX().c.getC();
|
||||
i = b.getX().c.getX();
|
||||
}
|
||||
|
||||
public ClassCanBeTyped() {
|
||||
public ComplexClass() {
|
||||
this.x = 10;
|
||||
int i;
|
||||
for (i = 0; i < (x + 1); i = i + 1) {
|
||||
@ -56,7 +56,7 @@ public class ClassCanBeTyped {
|
||||
|
||||
}
|
||||
|
||||
public ClassCanBeTyped(int x, int y, char z) {
|
||||
public ComplexClass(int x, int y, char z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class ClassCanBeTyped {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public ClassCanBeTyped getC() {
|
||||
public ComplexClass getC() {
|
||||
return c;
|
||||
}
|
||||
|
@ -20,37 +20,24 @@ import de.maishai.typedast.typedclass.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TypedAbstractSyntax_ClassWithConstructor {
|
||||
public static TypedClass get() {
|
||||
return new TypedClass(
|
||||
"ClassWithConstructor",
|
||||
public static TypedProgram get() {
|
||||
return new TypedProgram(
|
||||
List.of(
|
||||
new TypedDeclaration(
|
||||
"x",
|
||||
Type.INT
|
||||
)
|
||||
),
|
||||
List.of(),
|
||||
List.of(
|
||||
new TypedConstructor(
|
||||
new TypedClass(
|
||||
"ClassWithConstructor",
|
||||
List.of(),
|
||||
new TypedBlock(
|
||||
List.of(),
|
||||
List.of(),
|
||||
Type.VOID
|
||||
),
|
||||
Type.VOID,
|
||||
List.of(
|
||||
new TypedLocalVariable(
|
||||
"i",
|
||||
new TypedDeclaration(
|
||||
"x",
|
||||
Type.INT
|
||||
)
|
||||
)
|
||||
),
|
||||
List.of(),
|
||||
getConstructors(),
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("ClassWithField")
|
||||
)
|
||||
),
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("ClassWithField")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -9,32 +9,36 @@ import de.maishai.typedast.typedclass.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TypedAbstractSyntax_ClassWithField {
|
||||
public static TypedClass get() {
|
||||
return new TypedClass(
|
||||
"ClassWithField",
|
||||
List.of(
|
||||
new TypedDeclaration(
|
||||
"x",
|
||||
Type.INT
|
||||
)
|
||||
),
|
||||
List.of(),
|
||||
List.of(
|
||||
new TypedConstructor(
|
||||
"ClassWithField",
|
||||
List.of(),
|
||||
new TypedBlock(
|
||||
List.of(),
|
||||
List.of(),
|
||||
Type.VOID
|
||||
),
|
||||
Type.VOID,
|
||||
List.of()
|
||||
)
|
||||
),
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("ClassWithField")
|
||||
public static TypedProgram get() {
|
||||
return new TypedProgram(
|
||||
List.of(
|
||||
new TypedClass(
|
||||
"ClassWithField",
|
||||
List.of(
|
||||
new TypedDeclaration(
|
||||
"x",
|
||||
Type.INT
|
||||
)
|
||||
),
|
||||
List.of(),
|
||||
List.of(
|
||||
new TypedConstructor(
|
||||
"ClassWithField",
|
||||
List.of(),
|
||||
new TypedBlock(
|
||||
List.of(),
|
||||
List.of(),
|
||||
Type.VOID
|
||||
),
|
||||
Type.VOID,
|
||||
List.of()
|
||||
)
|
||||
),
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("ClassWithField")
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -7,27 +7,31 @@ import de.maishai.typedast.typedclass.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TypedAbstractSyntax_PublicClass {
|
||||
public static TypedClass get() {
|
||||
return new TypedClass(
|
||||
"PublicClass",
|
||||
List.of(),
|
||||
List.of(),
|
||||
public static TypedProgram get() {
|
||||
return new TypedProgram(
|
||||
List.of(
|
||||
new TypedConstructor(
|
||||
new TypedClass(
|
||||
"PublicClass",
|
||||
List.of(),
|
||||
new TypedBlock(
|
||||
List.of(),
|
||||
List.of(),
|
||||
Type.VOID
|
||||
List.of(),
|
||||
List.of(
|
||||
new TypedConstructor(
|
||||
"PublicClass",
|
||||
List.of(),
|
||||
new TypedBlock(
|
||||
List.of(),
|
||||
List.of(),
|
||||
Type.VOID
|
||||
),
|
||||
Type.VOID,
|
||||
List.of()
|
||||
)
|
||||
),
|
||||
Type.VOID,
|
||||
List.of()
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("PublicClass")
|
||||
)
|
||||
),
|
||||
null,
|
||||
null,
|
||||
Type.REFERENCE("PublicClass")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,62 +1,64 @@
|
||||
import de.maishai.Compiler;
|
||||
import de.maishai.ast.records.Class;
|
||||
import de.maishai.ast.records.Program;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ScannerParserTests {
|
||||
|
||||
@Test
|
||||
public void testPublicClass() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/PublicClass.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/PublicClass.java"));
|
||||
assertEquals(AbstractSyntax_PublicClass.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithField() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithField.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithField.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithField.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithConstructor() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructor.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithConstructor.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithConstructor.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithMethod() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithMethod.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethod.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithMethod.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithConstructorWithCodeInComments() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorWithCodeInComments.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithConstructorWithCodeInComments.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithConstructorWithCodeInComments.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithConstructorWithParameters() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorWithParameters.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithConstructorWithParameters.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithMethodAndField() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithConstructorAndMethodCall() {
|
||||
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java");
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testClassCanBeTyped() {
|
||||
// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassCanBeTyped.java");
|
||||
// assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||
// }
|
||||
@Test
|
||||
public void testComplexClass() {
|
||||
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java"));
|
||||
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import de.maishai.Compiler;
|
||||
import de.maishai.typedast.typedclass.TypedClass;
|
||||
import de.maishai.typedast.typedclass.TypedProgram;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -8,19 +8,19 @@ public class TypingTests {
|
||||
|
||||
@Test
|
||||
public void testPublicClass() {
|
||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get());
|
||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get());
|
||||
assertEquals(TypedAbstractSyntax_PublicClass.get(), resultTypedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithField() {
|
||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get());
|
||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get());
|
||||
assertEquals(TypedAbstractSyntax_ClassWithField.get(), resultTypedAst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithConstructor() {
|
||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get());
|
||||
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get());
|
||||
assertEquals(TypedAbstractSyntax_ClassWithConstructor.get(), resultTypedAst);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user