instvar typecheck and getTypeCheckresults
This commit is contained in:
parent
112c5f2c1b
commit
6915a97432
@ -105,6 +105,9 @@ public class Compiler {
|
||||
|
||||
|
||||
//abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.returnType = "char";
|
||||
AssignStatementExpression a = (AssignStatementExpression) abstractSyntaxTree.classes.get(0).methodDecls.get(0).codeBlock.statements.get(2);
|
||||
InstVarExpression b = (InstVarExpression) a.left;
|
||||
b.classRef = abstractSyntaxTree.classes.get(0);
|
||||
abstractSyntaxTree.typeCheck();
|
||||
|
||||
abstractSyntaxTree.codeGen();
|
||||
|
@ -1,29 +1,11 @@
|
||||
class ExampleEmpty {
|
||||
|
||||
}
|
||||
|
||||
class Example {
|
||||
int i;
|
||||
boolean b;
|
||||
char c;
|
||||
|
||||
}
|
||||
class Example2 {
|
||||
boolean instVarBool;
|
||||
int m(int n){
|
||||
int localA;
|
||||
int localB;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
class Example3 {
|
||||
char isNice;
|
||||
char m(int n) {
|
||||
int test = 12;
|
||||
this.m(test);
|
||||
boolean l;
|
||||
l = false;
|
||||
return 't';
|
||||
localA = 5;
|
||||
this.i = 3;
|
||||
return localA;
|
||||
}
|
||||
}
|
@ -37,6 +37,6 @@ public class BoolDatatype extends AbstractType implements IDatatype{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,6 @@ public class CharDatatype extends AbstractType implements IDatatype{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,6 @@ public class IntDatatype extends AbstractType implements IDatatype{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -186,9 +186,8 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
&& Objects.equals(right, binaryExpression.right)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -27,4 +27,8 @@ public class BooleanConstantExpression extends AbstractType implements IExpressi
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||
|
||||
}
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,9 @@ public class CharConstantExpression extends AbstractType implements IExpression{
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
@ -14,7 +15,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstVarExpression implements IExpression{
|
||||
public class InstVarExpression extends AbstractType implements IExpression{
|
||||
|
||||
public RefType classRef;
|
||||
|
||||
@ -85,6 +86,6 @@ public class InstVarExpression implements IExpression{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ public class IntConstantExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws Exception {
|
||||
return null;
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
result.type = "int";
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,6 +41,6 @@ public class IntConstantExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import org.objectweb.asm.*;
|
||||
@ -12,7 +13,7 @@ import org.objectweb.asm.MethodVisitor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LocalVarIdentifier implements IExpression{
|
||||
public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
|
||||
String identifier;
|
||||
public LocalVarIdentifier(String identifier){
|
||||
@ -31,6 +32,7 @@ public class LocalVarIdentifier implements IExpression{
|
||||
} else {
|
||||
throw new Exception("TypeCheck Exception: Local var " + identifier + " does not exist.");
|
||||
}
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -73,6 +75,11 @@ public class LocalVarIdentifier implements IExpression{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -81,9 +88,4 @@ public class LocalVarIdentifier implements IExpression{
|
||||
return (Objects.equals(identifier, localVarIdentifier.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,6 @@ public class UnaryExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
continue;
|
||||
// set return of block if not known yet
|
||||
|
||||
if(this.returnType == null)
|
||||
if(this.returnType == null|| this.returnType == "not")
|
||||
this.returnType = typeOfCurrentStatement.type;
|
||||
|
||||
if (!typeOfCurrentStatement.type.equals(this.returnType))
|
||||
@ -113,6 +113,6 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -31,6 +31,6 @@ public class EmptyStatement extends AbstractType implements IStatement{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,6 @@ public class IfElseStatement extends AbstractType implements IStatement{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class IfStatement extends AbstractType implements IStatement{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package abstractSyntaxTree.Statement;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
@ -8,7 +9,7 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LocalVarDecl implements IStatement{
|
||||
public class LocalVarDecl extends AbstractType implements IStatement{
|
||||
String type;
|
||||
String identifier;
|
||||
public LocalVarDecl(String type, String identifier) {
|
||||
@ -62,6 +63,6 @@ public class LocalVarDecl implements IStatement{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public TypeCheckResult getTypeCheckResult() {
|
||||
// return this.
|
||||
// }
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,6 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -143,4 +143,8 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
&& Objects.equals(right, assignStatementExpression.right)
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -103,4 +103,9 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
&& Objects.equals(arguments, methodCallStatementExpression.arguments)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -84,4 +84,8 @@ public class NewStatementExpression extends AbstractType implements IExpression,
|
||||
descriptor.append(")V"); // Constructors always return void
|
||||
return descriptor.toString();
|
||||
}
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user