mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:28:04 +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) {
|
public static TypedProgram generateTypedASTFromAst(Program ast) {
|
||||||
TypedProgram typedAST = new TypedProgram(ast);
|
return new TypedProgram(ast);
|
||||||
return typedAST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) {
|
public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) {
|
||||||
@ -99,6 +98,6 @@ public class Compiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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;
|
package de.maishai.typedast.typedclass;
|
||||||
|
|
||||||
import de.maishai.ast.records.Program;
|
import de.maishai.ast.records.Program;
|
||||||
import de.maishai.typedast.ClassContext;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class TypedProgram {
|
public class TypedProgram {
|
||||||
private List<TypedClass> typedClasses = new ArrayList<>();
|
private List<TypedClass> typedClasses = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
public class ClassCanBeTyped {
|
public class ComplexClass {
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
ClassCanBeTyped b;
|
ComplexClass b;
|
||||||
ClassCanBeTyped c;
|
ComplexClass c;
|
||||||
public ClassCanBeTyped(int x) {
|
public ComplexClass(int x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
public ClassCanBeTyped(int x, int y) {
|
public ComplexClass(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
public ClassCanBeTyped initClassCanBeTyped(int x) {
|
public ComplexClass initComplexClass(int x) {
|
||||||
int a;
|
int a;
|
||||||
a = 10;
|
a = 10;
|
||||||
b = new ClassCanBeTyped(x);
|
b = new ComplexClass(x);
|
||||||
b.x = 10 + a;
|
b.x = 10 + a;
|
||||||
b.y = 20;
|
b.y = 20;
|
||||||
b.c.x = 20 + a;
|
b.c.x = 20 + a;
|
||||||
@ -22,17 +22,17 @@ public class ClassCanBeTyped {
|
|||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
public ClassCanBeTyped init(int x, int y) {
|
public ComplexClass init(int x, int y) {
|
||||||
return new ClassCanBeTyped(x, y);
|
return new ComplexClass(x, y);
|
||||||
}
|
}
|
||||||
public ClassCanBeTyped(int x) {
|
public ComplexClass(int x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
int i;
|
int i;
|
||||||
b = b.getX().c.getC();
|
b = b.getX().c.getC();
|
||||||
i = b.getX().c.getX();
|
i = b.getX().c.getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassCanBeTyped() {
|
public ComplexClass() {
|
||||||
this.x = 10;
|
this.x = 10;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (x + 1); i = i + 1) {
|
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.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public class ClassCanBeTyped {
|
|||||||
return this.x;
|
return this.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassCanBeTyped getC() {
|
public ComplexClass getC() {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
@ -20,8 +20,10 @@ import de.maishai.typedast.typedclass.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_ClassWithConstructor {
|
public class TypedAbstractSyntax_ClassWithConstructor {
|
||||||
public static TypedClass get() {
|
public static TypedProgram get() {
|
||||||
return new TypedClass(
|
return new TypedProgram(
|
||||||
|
List.of(
|
||||||
|
new TypedClass(
|
||||||
"ClassWithConstructor",
|
"ClassWithConstructor",
|
||||||
List.of(
|
List.of(
|
||||||
new TypedDeclaration(
|
new TypedDeclaration(
|
||||||
@ -30,27 +32,12 @@ public class TypedAbstractSyntax_ClassWithConstructor {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(
|
getConstructors(),
|
||||||
new TypedConstructor(
|
|
||||||
"ClassWithConstructor",
|
|
||||||
List.of(),
|
|
||||||
new TypedBlock(
|
|
||||||
List.of(),
|
|
||||||
List.of(),
|
|
||||||
Type.VOID
|
|
||||||
),
|
|
||||||
Type.VOID,
|
|
||||||
List.of(
|
|
||||||
new TypedLocalVariable(
|
|
||||||
"i",
|
|
||||||
Type.INT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Type.REFERENCE("ClassWithField")
|
Type.REFERENCE("ClassWithField")
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,10 @@ import de.maishai.typedast.typedclass.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_ClassWithField {
|
public class TypedAbstractSyntax_ClassWithField {
|
||||||
public static TypedClass get() {
|
public static TypedProgram get() {
|
||||||
return new TypedClass(
|
return new TypedProgram(
|
||||||
|
List.of(
|
||||||
|
new TypedClass(
|
||||||
"ClassWithField",
|
"ClassWithField",
|
||||||
List.of(
|
List.of(
|
||||||
new TypedDeclaration(
|
new TypedDeclaration(
|
||||||
@ -35,6 +37,8 @@ public class TypedAbstractSyntax_ClassWithField {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Type.REFERENCE("ClassWithField")
|
Type.REFERENCE("ClassWithField")
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,8 +7,10 @@ import de.maishai.typedast.typedclass.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_PublicClass {
|
public class TypedAbstractSyntax_PublicClass {
|
||||||
public static TypedClass get() {
|
public static TypedProgram get() {
|
||||||
return new TypedClass(
|
return new TypedProgram(
|
||||||
|
List.of(
|
||||||
|
new TypedClass(
|
||||||
"PublicClass",
|
"PublicClass",
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(),
|
List.of(),
|
||||||
@ -28,6 +30,8 @@ public class TypedAbstractSyntax_PublicClass {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
Type.REFERENCE("PublicClass")
|
Type.REFERENCE("PublicClass")
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,62 +1,64 @@
|
|||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Program;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class ScannerParserTests {
|
public class ScannerParserTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublicClass() {
|
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);
|
assertEquals(AbstractSyntax_PublicClass.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithField() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithField.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithConstructor() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithConstructor.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithMethod() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithMethod.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithConstructorWithCodeInComments() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithConstructorWithCodeInComments.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithConstructorWithParameters() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithMethodAndField() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithConstructorAndMethodCall() {
|
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);
|
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
// public void testClassCanBeTyped() {
|
public void testComplexClass() {
|
||||||
// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassCanBeTyped.java");
|
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java"));
|
||||||
// assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
import de.maishai.typedast.typedclass.TypedClass;
|
import de.maishai.typedast.typedclass.TypedProgram;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
@ -8,19 +8,19 @@ public class TypingTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublicClass() {
|
public void testPublicClass() {
|
||||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get());
|
||||||
assertEquals(TypedAbstractSyntax_PublicClass.get(), resultTypedAst);
|
assertEquals(TypedAbstractSyntax_PublicClass.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithField() {
|
public void testClassWithField() {
|
||||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get());
|
||||||
assertEquals(TypedAbstractSyntax_ClassWithField.get(), resultTypedAst);
|
assertEquals(TypedAbstractSyntax_ClassWithField.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassWithConstructor() {
|
public void testClassWithConstructor() {
|
||||||
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get());
|
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get());
|
||||||
assertEquals(TypedAbstractSyntax_ClassWithConstructor.get(), resultTypedAst);
|
assertEquals(TypedAbstractSyntax_ClassWithConstructor.get(), resultTypedAst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user