working on class/method tables

This commit is contained in:
Krauß, Josefine 2024-05-08 12:48:56 +02:00
parent 3d246af387
commit a9101d2c12
5 changed files with 33 additions and 22 deletions

View File

@ -6,14 +6,17 @@ import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Program;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class FieldDecl extends AbstractType implements IClass{
private Program program;
private String identifier;
public FieldDecl(Program program){
this.program = program;
private HashMap<String, HashMap<String, String>> typeContext; // form class from program
public String type; // from parser
public String identifier; // from parser
public FieldDecl(HashMap<String, HashMap<String, String>> typeContext){
this.typeContext = typeContext;
}
public TypeCheckResult typeCheck(List<FieldDecl> classFieldsIdentifier) throws Exception {
TypeCheckResult result = new TypeCheckResult();

View File

@ -8,17 +8,20 @@ import java.util.List;
public class MethodDecl implements IClass {
private Program program;
private HashMap<String, HashMap<String, HashMap<String, String>>> methodContext;
private HashMap<String, HashMap<String, String>> typeContext;
private HashMap<String, String> localVars;
private HashMap<String, String> localVars; // (type, identifier) // add content here
public MethodDecl(Program program){
this.program = program;
public MethodDecl(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext){
this.methodContext = methodContext;
this.typeContext = typeContext;
}
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
// write localvars
// jede methode als block statement aufrufen
return null;
// write localvars
// write method table
}
}

View File

@ -14,22 +14,22 @@ public class RefType extends AbstractType implements IDatatype {
String name;
public List<FieldDecl> fieldDecls;
private HashMap<String, String> fieldsTable; // type, identifier
public List<MethodDecl> methodDecls;
private HashMap<String, String> methodsTable; // return type, method name without parameter
private Program program;
private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
private HashMap<String, HashMap<String, HashMap<String, String>>> methodContext; // (class, (returntype, (identifier, parameter)
private boolean hasMain;
public RefType(Program program){
this.program = program;
}
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
public RefType(List<FieldDecl> fieldDecls,
List<MethodDecl> methodDecls,
HashMap<String, HashMap<String, String>> typeContext,
HashMap<String, HashMap<String, HashMap<String, String>>> methodContext){
this.fieldDecls = fieldDecls;
this.methodDecls = methodDecls;
this.typeContext = typeContext;
this.methodContext = methodContext;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();

View File

@ -1,6 +1,7 @@
package abstractSyntaxTree;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Datatype.RefType;
import java.util.HashMap;
@ -9,10 +10,14 @@ import java.util.List;
public class Program {
public List<RefType> classes;
public HashMap<String, HashMap<String, String>> classTypeIndentifierTable; // (class, (type, identifier))
public HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
public HashMap<String, HashMap<String, HashMap<String, String>>> methodContext; // (class, (returntype, (identifier, parameter)))
public TypeCheckResult typeCheck() throws Exception{
for(RefType oneClass : classes){
HashMap<String, String> classVars = new HashMap<>();
for (FieldDecl fielsDecl: oneClass.fieldDecls)
classVars.put(fielsDecl.type, fielsDecl.identifier);
oneClass.typeCheck();
}
return null;

View File

@ -2,8 +2,6 @@ package abstractSyntaxTree.Statement;
import TypeCheck.TypeCheckResult;
import TypeCheck.AbstractType;
import abstractSyntaxTree.Expression.IExpression;
import org.objectweb.asm.MethodVisitor;
import java.util.HashMap;
import java.util.List;
@ -14,6 +12,8 @@ public class BlockStatement extends AbstractType implements IStatement{
HashMap<String, String > localVars;
HashMap<String, String > typeIndentifierTable; // from program
List<IStatement> statements;
// do we need expression, statementexpression
public BlockStatement(List<IStatement> statements, HashMap<String, String> localVars, HashMap<String, String> typeIndentifierTable){
this.statements = statements;