Merge remote-tracking branch 'origin/master'

This commit is contained in:
David Mueller 2024-05-08 10:33:39 +02:00
commit 34b33d7353
5 changed files with 54 additions and 11 deletions

View File

@ -1,4 +1,23 @@
package abstractSyntaxTree.Class;
import TypeCheck.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class FieldDecl implements IClass {
private String type;
private String identifier;
public TypeCheckResult typeCheck(List<FieldDecl> classFieldsIdentifier) throws Exception {
TypeCheckResult result = new TypeCheckResult();
if (classFieldsIdentifier.contains(this.identifier)){
throw new Exception("field already defined");
} else {
classFieldsIdentifier.add(this);
}
result.type = this.type;
return result;
}
}

View File

@ -1,7 +1,9 @@
package abstractSyntaxTree.Class;
public interface IClass {
// not type or type check
import TypeCheck.TypeCheckResult;
import java.util.List;
public interface IClass {
// visit method for code generation
}

View File

@ -1,4 +1,12 @@
package abstractSyntaxTree.Class;
import TypeCheck.TypeCheckResult;
import java.util.List;
public class MethodDecl implements IClass {
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
return null;
}
}

View File

@ -20,15 +20,14 @@ public class RefType extends AbstractType implements IDatatype {
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();
// for (FieldDecl fieldDecl : fieldDecls) {
// fieldDecl.typeCheck();
// }
//
// for (MethodDecl methodDecl : methodDecls) {
// methodDecl.typeCheck();
// }
//
// return result;
for (FieldDecl fieldDecl : fieldDecls) {
fieldDecl.typeCheck(fieldDecls);
}
for (MethodDecl methodDecl : methodDecls) {
methodDecl.typeCheck(methodDecls);
}
result.type = "class";
setTypeCheckResult(result);
return result;

View File

@ -0,0 +1,15 @@
package abstractSyntaxTree;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Datatype.RefType;
import java.util.List;
public class Program {
public List<RefType> classes;
public TypeCheckResult typeCheck() throws Exception{
return null;
}
}