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