working on class/method tables
This commit is contained in:
parent
3d246af387
commit
a9101d2c12
@ -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();
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user