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 abstractSyntaxTree.Program;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FieldDecl extends AbstractType implements IClass{
|
public class FieldDecl extends AbstractType implements IClass{
|
||||||
private Program program;
|
|
||||||
private String identifier;
|
|
||||||
|
|
||||||
public FieldDecl(Program program){
|
private HashMap<String, HashMap<String, String>> typeContext; // form class from program
|
||||||
this.program = 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 {
|
public TypeCheckResult typeCheck(List<FieldDecl> classFieldsIdentifier) throws Exception {
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
@ -8,17 +8,20 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MethodDecl implements IClass {
|
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){
|
public MethodDecl(HashMap<String, HashMap<String, HashMap<String, String>>> methodContext, HashMap<String, HashMap<String, String>> typeContext){
|
||||||
this.program = program;
|
this.methodContext = methodContext;
|
||||||
|
this.typeContext = typeContext;
|
||||||
}
|
}
|
||||||
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
|
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
|
||||||
|
// write localvars
|
||||||
|
|
||||||
|
// jede methode als block statement aufrufen
|
||||||
return null;
|
return null;
|
||||||
// write localvars
|
|
||||||
// write method table
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,22 +14,22 @@ public class RefType extends AbstractType implements IDatatype {
|
|||||||
|
|
||||||
String name;
|
String name;
|
||||||
public List<FieldDecl> fieldDecls;
|
public List<FieldDecl> fieldDecls;
|
||||||
|
|
||||||
private HashMap<String, String> fieldsTable; // type, identifier
|
|
||||||
public List<MethodDecl> methodDecls;
|
public List<MethodDecl> methodDecls;
|
||||||
private HashMap<String, String> methodsTable; // return type, method name without parameter
|
private HashMap<String, HashMap<String, String>> typeContext; // (class, (type, identifier))
|
||||||
private Program program;
|
private HashMap<String, HashMap<String, HashMap<String, String>>> methodContext; // (class, (returntype, (identifier, parameter)
|
||||||
|
|
||||||
private boolean hasMain;
|
private boolean hasMain;
|
||||||
|
|
||||||
|
public RefType(List<FieldDecl> fieldDecls,
|
||||||
public RefType(Program program){
|
List<MethodDecl> methodDecls,
|
||||||
this.program = program;
|
HashMap<String, HashMap<String, String>> typeContext,
|
||||||
}
|
HashMap<String, HashMap<String, HashMap<String, String>>> methodContext){
|
||||||
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
|
|
||||||
this.fieldDecls = fieldDecls;
|
this.fieldDecls = fieldDecls;
|
||||||
this.methodDecls = methodDecls;
|
this.methodDecls = methodDecls;
|
||||||
|
this.typeContext = typeContext;
|
||||||
|
this.methodContext = methodContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package abstractSyntaxTree;
|
package abstractSyntaxTree;
|
||||||
|
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
import abstractSyntaxTree.Class.FieldDecl;
|
||||||
import abstractSyntaxTree.Datatype.RefType;
|
import abstractSyntaxTree.Datatype.RefType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -9,10 +10,14 @@ import java.util.List;
|
|||||||
public class Program {
|
public class Program {
|
||||||
public List<RefType> classes;
|
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{
|
public TypeCheckResult typeCheck() throws Exception{
|
||||||
for(RefType oneClass : classes){
|
for(RefType oneClass : classes){
|
||||||
|
HashMap<String, String> classVars = new HashMap<>();
|
||||||
|
for (FieldDecl fielsDecl: oneClass.fieldDecls)
|
||||||
|
classVars.put(fielsDecl.type, fielsDecl.identifier);
|
||||||
oneClass.typeCheck();
|
oneClass.typeCheck();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -2,8 +2,6 @@ package abstractSyntaxTree.Statement;
|
|||||||
|
|
||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
import TypeCheck.AbstractType;
|
import TypeCheck.AbstractType;
|
||||||
import abstractSyntaxTree.Expression.IExpression;
|
|
||||||
import org.objectweb.asm.MethodVisitor;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,6 +12,8 @@ public class BlockStatement extends AbstractType implements IStatement{
|
|||||||
HashMap<String, String > localVars;
|
HashMap<String, String > localVars;
|
||||||
HashMap<String, String > typeIndentifierTable; // from program
|
HashMap<String, String > typeIndentifierTable; // from program
|
||||||
List<IStatement> statements;
|
List<IStatement> statements;
|
||||||
|
// do we need expression, statementexpression
|
||||||
|
|
||||||
public BlockStatement(List<IStatement> statements, HashMap<String, String> localVars, HashMap<String, String> typeIndentifierTable){
|
public BlockStatement(List<IStatement> statements, HashMap<String, String> localVars, HashMap<String, String> typeIndentifierTable){
|
||||||
|
|
||||||
this.statements = statements;
|
this.statements = statements;
|
||||||
|
Loading…
Reference in New Issue
Block a user