Compare commits

..

No commits in common. "3d246af3873a094be109cc9035055c9d99abb2e2" and "c185b56065ce3c9415f32837a1803011721cd358" have entirely different histories.

7 changed files with 5 additions and 66 deletions

View File

@ -1,6 +1,5 @@
package TypeCheck;
import java.util.List;
import java.util.Objects;
public class TypeCheckHelper {
@ -21,12 +20,4 @@ public class TypeCheckHelper {
}
return result;
}
public static boolean typeExists(String type, List<String> typeslist) {
if(type.equals("int") || type.equals("bool") || type.equals("char")){
return true;
}
return typeslist.contains(type);
}
}

View File

@ -1,20 +1,14 @@
package abstractSyntaxTree.Class;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Program;
import java.util.ArrayList;
import java.util.List;
public class FieldDecl extends AbstractType implements IClass{
private Program program;
public class FieldDecl implements IClass {
private String type;
private String identifier;
public FieldDecl(Program program){
this.program = program;
}
public TypeCheckResult typeCheck(List<FieldDecl> classFieldsIdentifier) throws Exception {
TypeCheckResult result = new TypeCheckResult();
if (classFieldsIdentifier.contains(this.identifier)){
@ -22,11 +16,8 @@ public class FieldDecl extends AbstractType implements IClass{
} else {
classFieldsIdentifier.add(this);
}
//TypeCheckHelper.typeExists(type, ) // need all types of classes
setTypeCheckResult(result);
result.type = this.type;
return result;
//write field table
}
}

View File

@ -1,24 +1,12 @@
package abstractSyntaxTree.Class;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Program;
import java.util.HashMap;
import java.util.List;
public class MethodDecl implements IClass {
private Program program;
private HashMap<String, String> localVars;
public MethodDecl(Program program){
this.program = program;
}
public TypeCheckResult typeCheck(List<MethodDecl> fieldsOrMethods) throws Exception {
return null;
// write localvars
// write method table
}
}

View File

@ -4,28 +4,14 @@ import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Program;
import jdk.jshell.spi.ExecutionControl;
import org.objectweb.asm.MethodVisitor;
import java.util.HashMap;
import java.util.List;
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 boolean hasMain;
public RefType(Program program){
this.program = program;
}
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
this.fieldDecls = fieldDecls;
this.methodDecls = methodDecls;

View File

@ -3,24 +3,13 @@ package abstractSyntaxTree;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Datatype.RefType;
import java.util.HashMap;
import java.util.List;
public class Program {
public List<RefType> classes;
public HashMap<String, HashMap<String, String>> classTypeIndentifierTable; // (class, (type, identifier))
public TypeCheckResult typeCheck() throws Exception{
for(RefType oneClass : classes){
oneClass.typeCheck();
}
return null;
}
public void codeGen() throws Exception{
for(RefType oneClass : classes){
oneClass.codeGen();
}
}
}

View File

@ -5,17 +5,13 @@ import TypeCheck.AbstractType;
import abstractSyntaxTree.Expression.IExpression;
import org.objectweb.asm.MethodVisitor;
import java.util.HashMap;
import java.util.List;
public class BlockStatement extends AbstractType implements IStatement{
//We will need a parameter which holds the symbol table
HashMap<String, String > localVars;
HashMap<String, String > typeIndentifierTable; // from program
List<IStatement> statements;
public BlockStatement(List<IStatement> statements, HashMap<String, String> localVars, HashMap<String, String> typeIndentifierTable){
public BlockStatement(List<IStatement> statements){
this.statements = statements;
}
@Override

View File

@ -5,8 +5,6 @@ import org.objectweb.asm.MethodVisitor;
public interface IStatement {
TypeCheckResult typeCheck() throws Exception;
void CodeGen(MethodVisitor mv) throws Exception;