diff --git a/Source/abstractSyntaxTree/Datatype/BoolDatatype.java b/Source/abstractSyntaxTree/Datatype/BoolDatatype.java index 82aa4fa..736606d 100644 --- a/Source/abstractSyntaxTree/Datatype/BoolDatatype.java +++ b/Source/abstractSyntaxTree/Datatype/BoolDatatype.java @@ -4,8 +4,14 @@ import TypeCheck.AbstractType; import TypeCheck.TypeCheckResult; public class BoolDatatype extends AbstractType implements IDatatype{ + boolean value; @Override public TypeCheckResult typeCheck() throws Exception { - return null; + TypeCheckResult result = new TypeCheckResult(); + + result.type = "bool"; + + setTypeCheckResult(result); + return result; } } diff --git a/Source/abstractSyntaxTree/Datatype/CharDatatype.java b/Source/abstractSyntaxTree/Datatype/CharDatatype.java index 5a293ff..ad598fc 100644 --- a/Source/abstractSyntaxTree/Datatype/CharDatatype.java +++ b/Source/abstractSyntaxTree/Datatype/CharDatatype.java @@ -4,8 +4,14 @@ import TypeCheck.AbstractType; import TypeCheck.TypeCheckResult; public class CharDatatype extends AbstractType implements IDatatype{ + char value; @Override public TypeCheckResult typeCheck() throws Exception { - return null; + TypeCheckResult result = new TypeCheckResult(); + + result.type = "char"; + + setTypeCheckResult(result); + return result; } } diff --git a/Source/abstractSyntaxTree/Datatype/IntDatatype.java b/Source/abstractSyntaxTree/Datatype/IntDatatype.java index 216f3c0..9f52ea1 100644 --- a/Source/abstractSyntaxTree/Datatype/IntDatatype.java +++ b/Source/abstractSyntaxTree/Datatype/IntDatatype.java @@ -4,8 +4,14 @@ import TypeCheck.AbstractType; import TypeCheck.TypeCheckResult; public class IntDatatype extends AbstractType implements IDatatype{ + int value; @Override public TypeCheckResult typeCheck() throws Exception { - return null; + TypeCheckResult result = new TypeCheckResult(); + + result.type = "int"; + + setTypeCheckResult(result); + return result; } } diff --git a/Source/abstractSyntaxTree/Datatype/RefType.java b/Source/abstractSyntaxTree/Datatype/RefType.java index 2d9b23a..3077893 100644 --- a/Source/abstractSyntaxTree/Datatype/RefType.java +++ b/Source/abstractSyntaxTree/Datatype/RefType.java @@ -8,14 +8,27 @@ import abstractSyntaxTree.Class.MethodDecl; import java.util.List; public class RefType extends AbstractType implements IDatatype { + public List fieldDecls; + public List methodDecls; public RefType(List fieldDecls, List methodDecls){ this.fieldDecls = fieldDecls; this.methodDecls = methodDecls; } @Override 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 fieldDecls; - List methodDecls; } diff --git a/Source/abstractSyntaxTree/Expression/FieldAccess.java b/Source/abstractSyntaxTree/Expression/FieldAccess.java deleted file mode 100644 index 33373c9..0000000 --- a/Source/abstractSyntaxTree/Expression/FieldAccess.java +++ /dev/null @@ -1,4 +0,0 @@ -package abstractSyntaxTree.Expression; - -public class FieldAccess implements IExpression{ -} diff --git a/Source/abstractSyntaxTree/Expression/InstVarExpression.java b/Source/abstractSyntaxTree/Expression/InstVarExpression.java index aebf162..8eee374 100644 --- a/Source/abstractSyntaxTree/Expression/InstVarExpression.java +++ b/Source/abstractSyntaxTree/Expression/InstVarExpression.java @@ -1,4 +1,10 @@ package abstractSyntaxTree.Expression; +import TypeCheck.TypeCheckResult; + public class InstVarExpression implements IExpression{ + @Override + public TypeCheckResult typeCheck() throws Exception { + return null; + } } diff --git a/Source/abstractSyntaxTree/Expression/VarRefExpression.java b/Source/abstractSyntaxTree/Expression/VarRefExpression.java index 4e5eff4..2361d68 100644 --- a/Source/abstractSyntaxTree/Expression/VarRefExpression.java +++ b/Source/abstractSyntaxTree/Expression/VarRefExpression.java @@ -1,4 +1,10 @@ package abstractSyntaxTree.Expression; +import TypeCheck.TypeCheckResult; + public class VarRefExpression implements IExpression{ + @Override + public TypeCheckResult typeCheck() throws Exception { + return null; + } } diff --git a/Source/abstractSyntaxTree/StatementExpression/AssignExpression.java b/Source/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java similarity index 90% rename from Source/abstractSyntaxTree/StatementExpression/AssignExpression.java rename to Source/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java index 268487a..520370b 100644 --- a/Source/abstractSyntaxTree/StatementExpression/AssignExpression.java +++ b/Source/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java @@ -8,7 +8,7 @@ import abstractSyntaxTree.Statement.IStatement; import java.util.Objects; -public class AssignExpression extends AbstractType implements IExpression, IStatement { +public class AssignStatementExpression extends AbstractType implements IExpression, IStatement { public String operator; public IExpression left; public IExpression right; diff --git a/Source/abstractSyntaxTree/StatementExpression/MethodCall.java b/Source/abstractSyntaxTree/StatementExpression/MethodCall.java deleted file mode 100644 index b019b70..0000000 --- a/Source/abstractSyntaxTree/StatementExpression/MethodCall.java +++ /dev/null @@ -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; - } -} diff --git a/Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java b/Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java new file mode 100644 index 0000000..ee428d6 --- /dev/null +++ b/Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java @@ -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 arguments; + RefType classThatHasTheMethodIfNotThis; + RefType thisClass; + + public MethodCallStatementExpression(String methodName, List 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 methods = searchMethodHere.methodDecls; + + if(!methods.contains(methodName)){ + throw new Exception("method not found"); + } + + return result; + } +}