Changed some missing parameters

This commit is contained in:
Jochen Seyfried 2024-05-09 14:20:55 +02:00
parent b8a8a094f4
commit 2b671c32db
9 changed files with 16 additions and 21 deletions

View File

@ -8,7 +8,7 @@ import java.util.List;
public class Compiler { public class Compiler {
public static void Main(String[] args) throws Exception{ public static void main(String[] args) throws Exception{
// get file // get file
@ -20,6 +20,5 @@ public class Compiler {
abstractSyntaxTree.typeCheck(); abstractSyntaxTree.typeCheck();
abstractSyntaxTree.codeGen(); abstractSyntaxTree.codeGen();
} }
} }

View File

@ -35,7 +35,7 @@ public class FieldDecl extends AbstractType implements IClass{
} }
@Override @Override
public TypeCheckResult typeCheck() throws Exception { public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
return null; return null;
} }

View File

@ -4,12 +4,13 @@ import TypeCheck.TypeCheckResult;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.TypeReference; import org.objectweb.asm.TypeReference;
import java.util.HashMap;
import java.util.List; import java.util.List;
public interface IClass { public interface IClass {
// visit method for code generation // visit method for code generation
TypeCheckResult typeCheck() throws Exception; TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception;
void codeGen(ClassWriter cw) throws Exception; void codeGen(ClassWriter cw) throws Exception;
} }

View File

@ -18,7 +18,7 @@ public class MethodDecl implements IClass {
//TODO: Move this into the typeCheck //TODO: Move this into the typeCheck
private HashMap<String, String> localVars; // (type, identifier) // add content here private HashMap<String, String> localVars; // (type, identifier) // add content here
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception { public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
// write localvars // write localvars

View File

@ -20,14 +20,13 @@ public class RefType extends AbstractType implements IClass {
public List<FieldDecl> fieldDecls; public List<FieldDecl> fieldDecls;
public List<MethodDecl> methodDecls; public List<MethodDecl> methodDecls;
private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier)) private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
private HashMap<String, HashMap<String, HashMap<String, String>>> methodContext; // (class, (returntype, (identifier, parameter) public HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext; // (class, (returntype, (identifier, parameter)))
private boolean hasMain; private boolean hasMain;
public RefType(List<FieldDecl> fieldDecls, public RefType(List<FieldDecl> fieldDecls,
List<MethodDecl> methodDecls, List<MethodDecl> methodDecls,
HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, String>> typeContext,
HashMap<String, HashMap<String, HashMap<String, String>>> methodContext){ HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext){
this.fieldDecls = fieldDecls; this.fieldDecls = fieldDecls;
this.methodDecls = methodDecls; this.methodDecls = methodDecls;
this.typeContext = typeContext; this.typeContext = typeContext;
@ -37,7 +36,7 @@ public class RefType extends AbstractType implements IClass {
@Override @Override
public TypeCheckResult typeCheck() throws Exception { public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, List<String>>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<MethodDecl> fieldsOrMethods) throws Exception {
TypeCheckResult result = new TypeCheckResult(); TypeCheckResult result = new TypeCheckResult();
for (FieldDecl fieldDecl : fieldDecls) { for (FieldDecl fieldDecl : fieldDecls) {

View File

@ -39,7 +39,7 @@ public class Program {
methodContext.put(oneClass.name, returnTypeAndMethod); methodContext.put(oneClass.name, returnTypeAndMethod);
oneClass.typeCheck(); oneClass.typeCheck(methodContext, typeContext, oneClass.methodDecls);
} }
return null; return null;
} }

View File

@ -33,9 +33,9 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
} }
@Override @Override
public void CodeGen(MethodVisitor mv) throws Exception { public void codeGen(MethodVisitor mv) throws Exception {
left.CodeGen(mv); left.codeGen(mv);
right.CodeGen(mv); right.codeGen(mv);
if (left instanceof VarRefExpression varRef) { if (left instanceof VarRefExpression varRef) {
//TODO: Implement the handling of a variable reference --> I need a list of local variables //TODO: Implement the handling of a variable reference --> I need a list of local variables

View File

@ -6,6 +6,7 @@ import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Class.RefType; import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Expression.IExpression; import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement; import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
@ -42,17 +43,12 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
return result; return result;
} }
@Override
public void codeGen(MethodVisitor mv) throws Exception {
}
//Errors occur due to the change in parameter in the RefType class //Errors occur due to the change in parameter in the RefType class
@Override @Override
public void CodeGen(MethodVisitor mv) throws Exception { public void codeGen(MethodVisitor mv) throws Exception {
//Generate Bytecode for the receiver //Generate Bytecode for the receiver
if(classThatHasTheMethodIfNotThis != null){ if(classThatHasTheMethodIfNotThis != null){
classThatHasTheMethodIfNotThis.codeGen(); classThatHasTheMethodIfNotThis.codeGen(new ClassWriter(ClassWriter.COMPUTE_FRAMES));
} else { } else {
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
} }

View File

@ -13,7 +13,7 @@ public class NewStatementExpression extends AbstractType implements IExpression,
} }
@Override @Override
public void CodeGen(MethodVisitor mv) throws Exception { public void codeGen(MethodVisitor mv) throws Exception {
throw new Exception("CodeGen not implemented for NewStatementExpression"); throw new Exception("CodeGen not implemented for NewStatementExpression");
} }
} }