mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:18:03 +00:00
Refactored typedClasses
This commit is contained in:
parent
ec5cb4b490
commit
24c01a3f34
@ -8,44 +8,28 @@ public class TypedExpressionHelp {
|
||||
|
||||
public static TypedExpression convertExpression( TypedProgram typedProgram, Expression expression) {
|
||||
if (expression instanceof BoolLiteral boolLiteral) {
|
||||
TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral( typedProgram, boolLiteral);
|
||||
typedBoolLiteral.typeCheck( typedProgram);
|
||||
return typedBoolLiteral;
|
||||
return new TypedBoolLiteral(boolLiteral);
|
||||
}
|
||||
else if (expression instanceof CharLiteral charLiteral) {
|
||||
TypedCharLiteral typedCharLiteral = new TypedCharLiteral( typedProgram, charLiteral);
|
||||
typedCharLiteral.typeCheck( typedProgram);
|
||||
return typedCharLiteral;
|
||||
return new TypedCharLiteral(charLiteral);
|
||||
}
|
||||
else if (expression instanceof IntLiteral intLiteral) {
|
||||
TypedIntLiteral typedIntLiteral = new TypedIntLiteral( typedProgram, intLiteral);
|
||||
typedIntLiteral.typeCheck( typedProgram);
|
||||
return typedIntLiteral;
|
||||
return new TypedIntLiteral(intLiteral);
|
||||
}
|
||||
else if (expression instanceof Binary binary) {
|
||||
TypedBinary typedBinary = new TypedBinary( typedProgram, binary);
|
||||
typedBinary.typeCheck( typedProgram);
|
||||
return typedBinary;
|
||||
return new TypedBinary(typedProgram, binary);
|
||||
}
|
||||
else if (expression instanceof FieldVarAccess fieldVarAccess) {
|
||||
TypedFieldVarAccess typedFieldVarAccess = new TypedFieldVarAccess( typedProgram, fieldVarAccess);
|
||||
typedFieldVarAccess.typeCheck( typedProgram);
|
||||
return typedFieldVarAccess;
|
||||
return new TypedFieldVarAccess(typedProgram, fieldVarAccess);
|
||||
}
|
||||
else if (expression instanceof MethodCall methodCall) {
|
||||
TypedMethodCall typedMethodCall = new TypedMethodCall( typedProgram, methodCall);
|
||||
typedMethodCall.typeCheck(typedProgram);
|
||||
return typedMethodCall;
|
||||
return new TypedMethodCall(typedProgram, methodCall);
|
||||
}
|
||||
else if (expression instanceof New newStmt) {
|
||||
TypedNew typedNew = new TypedNew( typedProgram, newStmt);
|
||||
typedNew.typeCheck( typedProgram);
|
||||
return typedNew;
|
||||
return new TypedNew(typedProgram, newStmt);
|
||||
}
|
||||
else if (expression instanceof Unary unary) {
|
||||
TypedUnary typedUnary = new TypedUnary( typedProgram, unary);
|
||||
typedUnary.typeCheck( typedProgram);
|
||||
return typedUnary;
|
||||
return new TypedUnary(typedProgram, unary);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -20,12 +20,13 @@ public class TypedAssignment implements TypedStatement {
|
||||
|
||||
public TypedAssignment(TypedProgram typedProgram, Assignment untyped) {
|
||||
convertToTypedAssignment(typedProgram, untyped);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedAssignment(TypedProgram typedProgram, Assignment untyped) {
|
||||
value = convertExpression(typedProgram, untyped.value());
|
||||
location = new TypedFieldVarAccess(typedProgram, untyped.location());
|
||||
location.typeCheck(typedProgram);
|
||||
//location.typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ public class TypedBinary implements TypedExpression {
|
||||
|
||||
public TypedBinary(TypedProgram typedProgram, Binary unTypedBinary) {
|
||||
convertToTypedBinary(typedProgram, unTypedBinary);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedBinary(TypedProgram typedProgram, Binary unTypedBinary) {
|
||||
|
@ -41,45 +41,31 @@ public class TypedBlock implements TypedNode {
|
||||
vars.add(new TypedLocalVariable(typedProgram, declaration));
|
||||
}
|
||||
if (stmt instanceof Assignment assignment) {
|
||||
TypedAssignment typedAssignment = new TypedAssignment(typedProgram, assignment);
|
||||
typedAssignment.typeCheck(typedProgram);
|
||||
stmts.add(typedAssignment);
|
||||
stmts.add(new TypedAssignment(typedProgram, assignment));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof For forStmt) {
|
||||
TypedFor typedFor = new TypedFor(typedProgram, forStmt);
|
||||
typedFor.typeCheck(typedProgram);
|
||||
stmts.add(typedFor);
|
||||
stmts.add(new TypedFor(typedProgram, forStmt));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof IfElse ifElse) {
|
||||
TypedIfElse typedIfElse = new TypedIfElse(typedProgram, ifElse);
|
||||
typedIfElse.typeCheck(typedProgram);
|
||||
stmts.add(typedIfElse);
|
||||
stmts.add(new TypedIfElse(typedProgram, ifElse));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof While whileStmt) {
|
||||
TypedWhile typedWhile = new TypedWhile(typedProgram, whileStmt);
|
||||
typedWhile.typeCheck(typedProgram);
|
||||
stmts.add(typedWhile);
|
||||
stmts.add(new TypedWhile(typedProgram, whileStmt));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof DoWhile doWhile) {
|
||||
TypedDoWhile typedDoWhile = new TypedDoWhile(typedProgram, doWhile);
|
||||
typedDoWhile.typeCheck(typedProgram);
|
||||
stmts.add(typedDoWhile);
|
||||
stmts.add(new TypedDoWhile(typedProgram, doWhile));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof Return returnStmt) {
|
||||
TypedReturn typedReturn = new TypedReturn(typedProgram, returnStmt);
|
||||
typedReturn.typeCheck(typedProgram);
|
||||
stmts.add(typedReturn);
|
||||
stmts.add(new TypedReturn(typedProgram, returnStmt));
|
||||
continue;
|
||||
}
|
||||
if (stmt instanceof New newStmt) {
|
||||
TypedNew typedNew = new TypedNew(typedProgram, newStmt);
|
||||
typedNew.typeCheck(typedProgram);
|
||||
stmts.add(typedNew);
|
||||
stmts.add(new TypedNew(typedProgram, newStmt));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -94,9 +80,7 @@ public class TypedBlock implements TypedNode {
|
||||
}
|
||||
|
||||
if (stmt instanceof MethodCall methodCall) {
|
||||
TypedMethodCall typedMethodCall = new TypedMethodCall(typedProgram, methodCall);
|
||||
typedMethodCall.typeCheck(typedProgram);
|
||||
stmts.add(typedMethodCall);
|
||||
stmts.add(new TypedMethodCall(typedProgram, methodCall));
|
||||
}
|
||||
|
||||
if (stmt instanceof Print printStmt) {
|
||||
|
@ -18,11 +18,11 @@ public class TypedBoolLiteral implements TypedExpression {
|
||||
private Type type;
|
||||
|
||||
|
||||
public TypedBoolLiteral(TypedProgram typedProgram, BoolLiteral unTypedBoolLiteral) {
|
||||
convertToTypedBoolLiteral(typedProgram, unTypedBoolLiteral);
|
||||
public TypedBoolLiteral(BoolLiteral unTypedBoolLiteral) {
|
||||
convertToTypedBoolLiteral(unTypedBoolLiteral);
|
||||
}
|
||||
|
||||
public void convertToTypedBoolLiteral(TypedProgram typedProgram, BoolLiteral unTypedBoolLiteral) {
|
||||
public void convertToTypedBoolLiteral(BoolLiteral unTypedBoolLiteral) {
|
||||
value = unTypedBoolLiteral.value();
|
||||
type = Type.BOOL;
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ public class TypedCharLiteral implements TypedExpression {
|
||||
private char value;
|
||||
private Type type;
|
||||
|
||||
public TypedCharLiteral(TypedProgram typedProgram, CharLiteral unTypedCharLiteral) {
|
||||
convertToCharLiteral(typedProgram, unTypedCharLiteral);
|
||||
public TypedCharLiteral( CharLiteral unTypedCharLiteral) {
|
||||
convertToCharLiteral(unTypedCharLiteral);
|
||||
}
|
||||
|
||||
public void convertToCharLiteral(TypedProgram typedProgram, CharLiteral unTypedCharLiteral) {
|
||||
public void convertToCharLiteral(CharLiteral unTypedCharLiteral) {
|
||||
value = unTypedCharLiteral.value();
|
||||
type = Type.CHAR;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class TypedDoWhile implements TypedStatement {
|
||||
|
||||
public TypedDoWhile(TypedProgram typedProgram, DoWhile unTypedDoWhile) {
|
||||
convertToTypedDoWhile(typedProgram, unTypedDoWhile);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedDoWhile(TypedProgram typedProgram, DoWhile unTypedDoWhile) {
|
||||
|
@ -25,6 +25,7 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
|
||||
public TypedFieldVarAccess(TypedProgram typedProgram, FieldVarAccess unTypedFieldVarAccess) {
|
||||
convertToTypedFieldVarAccess(typedProgram, unTypedFieldVarAccess);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedFieldVarAccess(TypedProgram typedProgram, FieldVarAccess unTypedFieldVarAccess) {
|
||||
|
@ -22,6 +22,7 @@ public class TypedFor implements TypedStatement {
|
||||
|
||||
public TypedFor(TypedProgram typedProgram, For unTypedFor) {
|
||||
convertToTypedFor(typedProgram, unTypedFor);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedFor(TypedProgram typedProgram, For unTypedFor) {
|
||||
|
@ -21,6 +21,7 @@ public class TypedIfElse implements TypedStatement {
|
||||
|
||||
public TypedIfElse(TypedProgram typedProgram, IfElse unTypedIfElse) {
|
||||
convertToTypedIfElse(typedProgram, unTypedIfElse);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedIfElse(TypedProgram typedProgram, IfElse unTypedIfElse) {
|
||||
|
@ -20,11 +20,11 @@ public class TypedIntLiteral implements TypedExpression {
|
||||
private Type type;
|
||||
|
||||
|
||||
public TypedIntLiteral(TypedProgram typedProgram, IntLiteral unTypedIntLiteral) {
|
||||
convertToTypedIntLiteral(typedProgram, unTypedIntLiteral);
|
||||
public TypedIntLiteral(IntLiteral unTypedIntLiteral) {
|
||||
convertToTypedIntLiteral(unTypedIntLiteral);
|
||||
}
|
||||
|
||||
public void convertToTypedIntLiteral(TypedProgram typedProgram, IntLiteral unTypedIntLiteral) {
|
||||
public void convertToTypedIntLiteral(IntLiteral unTypedIntLiteral) {
|
||||
value = unTypedIntLiteral.value();
|
||||
type = Type.INT;
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
|
||||
|
||||
public TypedMethodCall(TypedProgram typedProgram, MethodCall unTypedMethodCall) {
|
||||
convertToTypedMethodCall(typedProgram, unTypedMethodCall);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedMethodCall(TypedProgram typedProgram, MethodCall unTypedMethodCall) {
|
||||
recipient = new TypedFieldVarAccess(typedProgram, unTypedMethodCall.recipient());
|
||||
recipient.typeCheck(typedProgram);
|
||||
//recipient.typeCheck(typedProgram);
|
||||
for (Expression arg : unTypedMethodCall.args()) {
|
||||
args.add(convertExpression(typedProgram, arg));
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public class TypedNew implements TypedExpression, TypedStatement {
|
||||
|
||||
public TypedNew(TypedProgram typedProgram, New unTypedNew) {
|
||||
convertToTypedNew(typedProgram, unTypedNew);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedNew(TypedProgram typedProgram, New unTypedNew) {
|
||||
|
@ -19,6 +19,7 @@ public class TypedReturn implements TypedStatement {
|
||||
|
||||
public TypedReturn(TypedProgram typedProgram, Return unTypedReturn) {
|
||||
convertToTypedReturn(typedProgram, unTypedReturn);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedReturn(TypedProgram typedProgram, Return unTypedReturn) {
|
||||
|
@ -18,6 +18,7 @@ public class TypedUnary implements TypedExpression {
|
||||
|
||||
public TypedUnary(TypedProgram typedProgram, Unary unTypedUnary) {
|
||||
convertToTypedUnary(typedProgram, unTypedUnary);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedUnary(TypedProgram typedProgram, Unary unTypedUnary) {
|
||||
|
@ -17,6 +17,7 @@ public class TypedWhile implements TypedStatement {
|
||||
|
||||
public TypedWhile(TypedProgram typedProgram, While unTypedWhile) {
|
||||
convertToTypedWhile(typedProgram, unTypedWhile);
|
||||
typeCheck(typedProgram);
|
||||
}
|
||||
|
||||
public void convertToTypedWhile(TypedProgram typedProgram, While unTypedWhile) {
|
||||
|
Loading…
Reference in New Issue
Block a user