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 static void Main(String[] args) throws Exception{
public static void main(String[] args) throws Exception{
// get file
@ -20,6 +20,5 @@ public class Compiler {
abstractSyntaxTree.typeCheck();
abstractSyntaxTree.codeGen();
}
}

View File

@ -35,7 +35,7 @@ public class FieldDecl extends AbstractType implements IClass{
}
@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;
}

View File

@ -4,12 +4,13 @@ import TypeCheck.TypeCheckResult;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.TypeReference;
import java.util.HashMap;
import java.util.List;
public interface IClass {
// 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;
}

View File

@ -18,7 +18,7 @@ public class MethodDecl implements IClass {
//TODO: Move this into the typeCheck
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

View File

@ -20,14 +20,13 @@ public class RefType extends AbstractType implements IClass {
public List<FieldDecl> fieldDecls;
public List<MethodDecl> methodDecls;
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;
public RefType(List<FieldDecl> fieldDecls,
List<MethodDecl> methodDecls,
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.methodDecls = methodDecls;
this.typeContext = typeContext;
@ -37,7 +36,7 @@ public class RefType extends AbstractType implements IClass {
@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();
for (FieldDecl fieldDecl : fieldDecls) {

View File

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

View File

@ -33,9 +33,9 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
}
@Override
public void CodeGen(MethodVisitor mv) throws Exception {
left.CodeGen(mv);
right.CodeGen(mv);
public void codeGen(MethodVisitor mv) throws Exception {
left.codeGen(mv);
right.codeGen(mv);
if (left instanceof VarRefExpression varRef) {
//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.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@ -42,17 +43,12 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
return result;
}
@Override
public void codeGen(MethodVisitor mv) throws Exception {
}
//Errors occur due to the change in parameter in the RefType class
@Override
public void CodeGen(MethodVisitor mv) throws Exception {
public void codeGen(MethodVisitor mv) throws Exception {
//Generate Bytecode for the receiver
if(classThatHasTheMethodIfNotThis != null){
classThatHasTheMethodIfNotThis.codeGen();
classThatHasTheMethodIfNotThis.codeGen(new ClassWriter(ClassWriter.COMPUTE_FRAMES));
} else {
mv.visitVarInsn(Opcodes.ALOAD, 0);
}

View File

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