From 92990e4042bba96e8edb79ec9fc68d98bc3f8883 Mon Sep 17 00:00:00 2001 From: Lucas <89882946+notbad3500@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:53:42 +0200 Subject: [PATCH] gemeinsame dc changes --- src/main/java/ast/literal/LiteralNode.java | 15 +- src/main/java/bytecode/ClassCodeGen.java | 2 +- src/main/java/main/Main.java | 8 +- src/main/resources/input/CompilerInput.java | 4 +- src/main/resources/output/output.jar | Bin 0 -> 211 bytes src/test/Makefile | 3 +- src/test/resources/trees/correctRefType.json | 70 --------- src/test/resources/trees/refTypeMismatch.json | 133 ------------------ src/test/resources/trees/test.json | 1 - 9 files changed, 17 insertions(+), 219 deletions(-) create mode 100644 src/main/resources/output/output.jar delete mode 100644 src/test/resources/trees/correctRefType.json delete mode 100644 src/test/resources/trees/refTypeMismatch.json delete mode 100644 src/test/resources/trees/test.json diff --git a/src/main/java/ast/literal/LiteralNode.java b/src/main/java/ast/literal/LiteralNode.java index b3cb896..e18ab7b 100644 --- a/src/main/java/ast/literal/LiteralNode.java +++ b/src/main/java/ast/literal/LiteralNode.java @@ -1,25 +1,24 @@ package ast.literal; - -import ast.expression.ExpressionNode; -import ast.type.TypeNode; +import ast.expressions.IExpressionNode; +import ast.type.type.ITypeNode; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -public class LiteralNode implements ExpressionNode { +public class LiteralNode implements IExpressionNode { public String value; - private TypeNode type; + private ITypeNode type; - public LiteralNode(String value, TypeNode type) { + public LiteralNode(String value, ITypeNode type) { this.value = value; this.type = type; } - public TypeNode getType() { + public ITypeNode getType() { return type; } - public void setType(TypeNode type) { + public void setType(ITypeNode type) { this.type = type; } diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index 3fec11a..84c8b92 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -46,8 +46,8 @@ public class ClassCodeGen implements ClassVisitor { } classWriter.visitEnd(); - writeToJar(classWriter.toByteArray(), classNode.identifier); printIntoClassFile(classWriter.toByteArray(), classNode.identifier, outputDirectory); + writeToJar(classWriter.toByteArray(), classNode.identifier); classWriter.visitEnd(); } diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index 7568d24..c365050 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -91,15 +91,15 @@ public class Main { /*------------------------- Semantic Analyzer -> typed AST -------------------------*/ // Use the SemanticAnalyzer to generate a typed AST - ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree); + //ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree); // Log the typed AST - RaupenLogger.logSemanticAnalyzer(typedAst); + RaupenLogger.logSemanticAnalyzer(abstractSyntaxTree); /*------------------------- Bytecode Generator -> Bytecode -------------------------*/ // Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath); - assert typedAst != null; - byteCodeGenerator.visit((ProgramNode) typedAst); + assert abstractSyntaxTree != null; + byteCodeGenerator.visit((ProgramNode) abstractSyntaxTree); // Log the bytecode generation RaupenLogger.logBytecodeGenerator(); } diff --git a/src/main/resources/input/CompilerInput.java b/src/main/resources/input/CompilerInput.java index 825490d..b27068a 100644 --- a/src/main/resources/input/CompilerInput.java +++ b/src/main/resources/input/CompilerInput.java @@ -2,13 +2,15 @@ public class Compiler { public int add(int i, int j) { return i+j; } + public static void main(String[] args) { + int a = 1; + } } public class Node { public void main() { Compiler compiler = new Compiler(); int i = compiler.add(5, 8); - return i; } } diff --git a/src/main/resources/output/output.jar b/src/main/resources/output/output.jar new file mode 100644 index 0000000000000000000000000000000000000000..5749e1bdd41b7eec182fc508e7cfebfb99fd14d5 GIT binary patch literal 211 zcmWIWW@Zs#;Nak3VA=ODf&mGLFt9NAx`sIFdiuHP`#So0y1532==r++JH^28+4sz8 zA8%c~i@e^tTIbH3-yCFc#rVO~Prhf)TrNH5siU_osNmdr-4ka#bss%_^puGqz?+@p sbea4cL!brvKpf!B$RxsmuozhmWHBnh<%|GtRyL4IMj&(p(&b=n0I9+?*#H0l literal 0 HcmV?d00001 diff --git a/src/test/Makefile b/src/test/Makefile index 883b79c..1464161 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -10,7 +10,7 @@ compile-javac: compile-raupenpiler: cd ../.. ; mvn -DskipTests install cd ../.. ; mvn exec:java -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' " - cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler + # cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler test: compile-javac compile-raupenpiler test-javac test-raupenpiler @@ -31,6 +31,7 @@ test-raupenpiler: clean: # clean output folders rm -f ../main/resources/output/*.class + rm -f ../main/resources/output/*.jar rm -f ./resources/output/javac/*.class rm -f ./resources/output/raupenpiler/*.class # clean logs diff --git a/src/test/resources/trees/correctRefType.json b/src/test/resources/trees/correctRefType.json deleted file mode 100644 index 7e67bbc..0000000 --- a/src/test/resources/trees/correctRefType.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "classes": [ - { - "identifier": "testClass1", - "accessType": { - "enumAccessTypeNode": "PUBLIC" - }, - "members": [ - { - "@type": "Field", - "accessTypeNode": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testVar1" - }, - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar1", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass1" - } - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": { - "@type": "Base", - "enumType": "INT" - } - } - } - ] - } - ], - "hasConstructor": false - } - ] -} \ No newline at end of file diff --git a/src/test/resources/trees/refTypeMismatch.json b/src/test/resources/trees/refTypeMismatch.json deleted file mode 100644 index e5ebcd3..0000000 --- a/src/test/resources/trees/refTypeMismatch.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "classes": [ - { - "identifier": "testClass1", - "accessType": { - "enumAccessTypeNode": "PUBLIC" - }, - "members": [ - { - "@type": "Field", - "accessTypeNode": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testVar1" - }, - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar1", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass1" - } - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": { - "@type": "Base", - "enumType": "BOOLEAN" - } - } - } - ] - } - ], - "hasConstructor": false, - "methods": [ - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar", - "expression": { - "@type": "InstVar", - "identifier": "testVar", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass2" - } - }, - "type": null - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": null - }, - "type": null - }, - { - "@type": "VariableDeclaration", - "type": { - "@type": "Base", - "enumType": "CHAR" - }, - "identifier": "objectVar", - "expression": { - "@type": "Literal", - "type": null - } - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/test/resources/trees/test.json b/src/test/resources/trees/test.json deleted file mode 100644 index 7acc30f..0000000 --- a/src/test/resources/trees/test.json +++ /dev/null @@ -1 +0,0 @@ -{"classes":[{"identifier":"testClass","accessType":{"enumAccessTypeNode":"PUBLIC"},"members":[{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar1"},{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"objectVar"},{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}],"hasConstructor":false,"methods":[{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}]}]} \ No newline at end of file