renamed files, some more attributes and some type check

This commit is contained in:
Krauß, Josefine 2024-05-02 15:31:31 +02:00
parent c712be94a4
commit 610c13d8a2
10 changed files with 92 additions and 24 deletions

View File

@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
public class BoolDatatype extends AbstractType implements IDatatype{
boolean value;
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
TypeCheckResult result = new TypeCheckResult();
result.type = "bool";
setTypeCheckResult(result);
return result;
}
}

View File

@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
public class CharDatatype extends AbstractType implements IDatatype{
char value;
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
TypeCheckResult result = new TypeCheckResult();
result.type = "char";
setTypeCheckResult(result);
return result;
}
}

View File

@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
public class IntDatatype extends AbstractType implements IDatatype{
int value;
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
TypeCheckResult result = new TypeCheckResult();
result.type = "int";
setTypeCheckResult(result);
return result;
}
}

View File

@ -8,14 +8,27 @@ import abstractSyntaxTree.Class.MethodDecl;
import java.util.List;
public class RefType extends AbstractType implements IDatatype {
public List<FieldDecl> fieldDecls;
public List<MethodDecl> methodDecls;
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
this.fieldDecls = fieldDecls;
this.methodDecls = methodDecls;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
TypeCheckResult result = new TypeCheckResult();
// for (FieldDecl fieldDecl : fieldDecls) {
// fieldDecl.typeCheck();
// }
//
// for (MethodDecl methodDecl : methodDecls) {
// methodDecl.typeCheck();
// }
//
// return result;
result.type = "class";
setTypeCheckResult(result);
return result;
}
List<FieldDecl> fieldDecls;
List<MethodDecl> methodDecls;
}

View File

@ -1,4 +0,0 @@
package abstractSyntaxTree.Expression;
public class FieldAccess implements IExpression{
}

View File

@ -1,4 +1,10 @@
package abstractSyntaxTree.Expression;
import TypeCheck.TypeCheckResult;
public class InstVarExpression implements IExpression{
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
}
}

View File

@ -1,4 +1,10 @@
package abstractSyntaxTree.Expression;
import TypeCheck.TypeCheckResult;
public class VarRefExpression implements IExpression{
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
}
}

View File

@ -8,7 +8,7 @@ import abstractSyntaxTree.Statement.IStatement;
import java.util.Objects;
public class AssignExpression extends AbstractType implements IExpression, IStatement {
public class AssignStatementExpression extends AbstractType implements IExpression, IStatement {
public String operator;
public IExpression left;
public IExpression right;

View File

@ -1,13 +0,0 @@
package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
public class MethodCall extends AbstractType implements IExpression, IStatement {
@Override
public TypeCheckResult typeCheck() throws Exception {
return null;
}
}

View File

@ -0,0 +1,42 @@
package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Datatype.RefType;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
import java.util.List;
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
String methodName;
List<IExpression> arguments;
RefType classThatHasTheMethodIfNotThis;
RefType thisClass;
public MethodCallStatementExpression(String methodName, List<IExpression> arguments) {
this.methodName = methodName;
this.arguments = arguments;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();
RefType searchMethodHere;
if(classThatHasTheMethodIfNotThis == null){
searchMethodHere = thisClass;
} else {
searchMethodHere = classThatHasTheMethodIfNotThis;
}
List<MethodDecl> methods = searchMethodHere.methodDecls;
if(!methods.contains(methodName)){
throw new Exception("method not found");
}
return result;
}
}