renamed files, some more attributes and some type check
This commit is contained in:
parent
c712be94a4
commit
610c13d8a2
@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
|
|||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
|
||||||
public class BoolDatatype extends AbstractType implements IDatatype{
|
public class BoolDatatype extends AbstractType implements IDatatype{
|
||||||
|
boolean value;
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
return null;
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
|
||||||
|
result.type = "bool";
|
||||||
|
|
||||||
|
setTypeCheckResult(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
|
|||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
|
||||||
public class CharDatatype extends AbstractType implements IDatatype{
|
public class CharDatatype extends AbstractType implements IDatatype{
|
||||||
|
char value;
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
return null;
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
|
||||||
|
result.type = "char";
|
||||||
|
|
||||||
|
setTypeCheckResult(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,14 @@ import TypeCheck.AbstractType;
|
|||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
|
|
||||||
public class IntDatatype extends AbstractType implements IDatatype{
|
public class IntDatatype extends AbstractType implements IDatatype{
|
||||||
|
int value;
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
return null;
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
|
||||||
|
result.type = "int";
|
||||||
|
|
||||||
|
setTypeCheckResult(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,27 @@ import abstractSyntaxTree.Class.MethodDecl;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RefType extends AbstractType implements IDatatype {
|
public class RefType extends AbstractType implements IDatatype {
|
||||||
|
public List<FieldDecl> fieldDecls;
|
||||||
|
public List<MethodDecl> methodDecls;
|
||||||
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
|
public RefType(List<FieldDecl> fieldDecls, List<MethodDecl> methodDecls){
|
||||||
this.fieldDecls = fieldDecls;
|
this.fieldDecls = fieldDecls;
|
||||||
this.methodDecls = methodDecls;
|
this.methodDecls = methodDecls;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
return null;
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
|
||||||
|
// for (FieldDecl fieldDecl : fieldDecls) {
|
||||||
|
// fieldDecl.typeCheck();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (MethodDecl methodDecl : methodDecls) {
|
||||||
|
// methodDecl.typeCheck();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
result.type = "class";
|
||||||
|
setTypeCheckResult(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
List<FieldDecl> fieldDecls;
|
|
||||||
List<MethodDecl> methodDecls;
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
package abstractSyntaxTree.Expression;
|
|
||||||
|
|
||||||
public class FieldAccess implements IExpression{
|
|
||||||
}
|
|
@ -1,4 +1,10 @@
|
|||||||
package abstractSyntaxTree.Expression;
|
package abstractSyntaxTree.Expression;
|
||||||
|
|
||||||
|
import TypeCheck.TypeCheckResult;
|
||||||
|
|
||||||
public class InstVarExpression implements IExpression{
|
public class InstVarExpression implements IExpression{
|
||||||
|
@Override
|
||||||
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
package abstractSyntaxTree.Expression;
|
package abstractSyntaxTree.Expression;
|
||||||
|
|
||||||
|
import TypeCheck.TypeCheckResult;
|
||||||
|
|
||||||
public class VarRefExpression implements IExpression{
|
public class VarRefExpression implements IExpression{
|
||||||
|
@Override
|
||||||
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import abstractSyntaxTree.Statement.IStatement;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AssignExpression extends AbstractType implements IExpression, IStatement {
|
public class AssignStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||||
public String operator;
|
public String operator;
|
||||||
public IExpression left;
|
public IExpression left;
|
||||||
public IExpression right;
|
public IExpression right;
|
@ -1,13 +0,0 @@
|
|||||||
package abstractSyntaxTree.StatementExpression;
|
|
||||||
|
|
||||||
import TypeCheck.AbstractType;
|
|
||||||
import TypeCheck.TypeCheckResult;
|
|
||||||
import abstractSyntaxTree.Expression.IExpression;
|
|
||||||
import abstractSyntaxTree.Statement.IStatement;
|
|
||||||
|
|
||||||
public class MethodCall extends AbstractType implements IExpression, IStatement {
|
|
||||||
@Override
|
|
||||||
public TypeCheckResult typeCheck() throws Exception {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
package abstractSyntaxTree.StatementExpression;
|
||||||
|
|
||||||
|
import TypeCheck.AbstractType;
|
||||||
|
import TypeCheck.TypeCheckResult;
|
||||||
|
import abstractSyntaxTree.Class.MethodDecl;
|
||||||
|
import abstractSyntaxTree.Datatype.RefType;
|
||||||
|
import abstractSyntaxTree.Expression.IExpression;
|
||||||
|
import abstractSyntaxTree.Statement.IStatement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||||
|
String methodName;
|
||||||
|
List<IExpression> arguments;
|
||||||
|
RefType classThatHasTheMethodIfNotThis;
|
||||||
|
RefType thisClass;
|
||||||
|
|
||||||
|
public MethodCallStatementExpression(String methodName, List<IExpression> arguments) {
|
||||||
|
this.methodName = methodName;
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeCheckResult typeCheck() throws Exception {
|
||||||
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
|
|
||||||
|
RefType searchMethodHere;
|
||||||
|
if(classThatHasTheMethodIfNotThis == null){
|
||||||
|
searchMethodHere = thisClass;
|
||||||
|
} else {
|
||||||
|
searchMethodHere = classThatHasTheMethodIfNotThis;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MethodDecl> methods = searchMethodHere.methodDecls;
|
||||||
|
|
||||||
|
if(!methods.contains(methodName)){
|
||||||
|
throw new Exception("method not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user