From 864b993f143845ef3538dc883322e6588f9339e8 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 22 May 2019 23:50:50 +0200 Subject: [PATCH] Eliminated SymbolTypeSimple. Eliminated SymbolTypeInference.infer(type, ...). Eliminiated most of SymbolTypeNumberInference. --- .../model/operators/OperatorAddressOf.java | 3 +- .../model/operators/OperatorAssignment.java | 4 +- .../kickc/model/operators/OperatorBinary.java | 3 +- .../model/operators/OperatorBitwiseAnd.java | 2 +- .../model/operators/OperatorBitwiseNot.java | 3 +- .../model/operators/OperatorBitwiseOr.java | 2 +- .../model/operators/OperatorBitwiseXor.java | 2 +- .../model/operators/OperatorCastBool.java | 3 +- .../model/operators/OperatorCastByte.java | 3 +- .../model/operators/OperatorCastDWord.java | 3 +- .../model/operators/OperatorCastPtr.java | 3 +- .../model/operators/OperatorCastSByte.java | 3 +- .../model/operators/OperatorCastSDWord.java | 3 +- .../model/operators/OperatorCastSWord.java | 3 +- .../model/operators/OperatorCastWord.java | 3 +- .../kickc/model/operators/OperatorDWord.java | 3 +- .../model/operators/OperatorDecrement.java | 3 +- .../kickc/model/operators/OperatorDeref.java | 3 +- .../model/operators/OperatorDerefIdx.java | 3 +- .../kickc/model/operators/OperatorDivide.java | 2 +- .../kickc/model/operators/OperatorEqual.java | 3 +- .../model/operators/OperatorGetHigh.java | 3 +- .../kickc/model/operators/OperatorGetLow.java | 3 +- .../model/operators/OperatorGreaterThan.java | 3 +- .../operators/OperatorGreaterThanEqual.java | 3 +- .../model/operators/OperatorIncrement.java | 3 +- .../model/operators/OperatorLessThan.java | 3 +- .../operators/OperatorLessThanEqual.java | 3 +- .../model/operators/OperatorLogicAnd.java | 3 +- .../model/operators/OperatorLogicNot.java | 3 +- .../model/operators/OperatorLogicOr.java | 3 +- .../kickc/model/operators/OperatorMinus.java | 2 +- .../kickc/model/operators/OperatorModulo.java | 2 +- .../model/operators/OperatorMultiply.java | 2 +- .../kickc/model/operators/OperatorNeg.java | 3 +- .../model/operators/OperatorNotEqual.java | 3 +- .../kickc/model/operators/OperatorPlus.java | 4 +- .../kickc/model/operators/OperatorPos.java | 3 +- .../model/operators/OperatorSetHigh.java | 3 +- .../kickc/model/operators/OperatorSetLow.java | 3 +- .../model/operators/OperatorShiftLeft.java | 6 +- .../model/operators/OperatorShiftRight.java | 5 +- .../kickc/model/operators/OperatorSizeOf.java | 3 +- .../kickc/model/operators/OperatorTypeId.java | 2 +- .../kickc/model/operators/OperatorUnary.java | 3 +- .../kickc/model/operators/OperatorWord.java | 3 +- .../model/types/SymbolTypeBlockScope.java | 2 +- .../model/types/SymbolTypeInference.java | 29 +----- .../kickc/model/types/SymbolTypeInteger.java | 2 +- .../kickc/model/types/SymbolTypeNamed.java | 2 +- .../types/SymbolTypeNumberInference.java | 94 ------------------- .../kickc/model/types/SymbolTypePointer.java | 2 +- .../model/types/SymbolTypeProcedure.java | 2 +- .../kickc/model/types/SymbolTypeProgram.java | 2 +- .../kickc/model/types/SymbolTypeSimple.java | 5 - 55 files changed, 55 insertions(+), 222 deletions(-) delete mode 100644 src/main/java/dk/camelot64/kickc/model/types/SymbolTypeSimple.java diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorAddressOf.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorAddressOf.java index 5b3c998dd..f0da75fec 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorAddressOf.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorAddressOf.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.ConstantNotLiteral; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Unary Address-of Operator (&p) */ @@ -20,7 +19,7 @@ public class OperatorAddressOf extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return new SymbolTypePointer(operandType); } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorAssignment.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorAssignment.java index b42c177eb..9e84e1b3d 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorAssignment.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorAssignment.java @@ -2,8 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; -import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Binary assignment operator ( x = y ) */ @@ -19,7 +17,7 @@ public class OperatorAssignment extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return left; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBinary.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBinary.java index 0ae783a25..9a6a79d30 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBinary.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBinary.java @@ -1,7 +1,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** A binary expression operator */ @@ -25,6 +24,6 @@ public abstract class OperatorBinary extends Operator { * @param right The type of the right operand * @return The type resulting from applying the operator to the operands */ - public abstract SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right); + public abstract SymbolType inferType(SymbolType left, SymbolType right); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseAnd.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseAnd.java index 931576215..84af74049 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseAnd.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseAnd.java @@ -21,7 +21,7 @@ public class OperatorBitwiseAnd extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple type1, SymbolTypeSimple type2) { + public SymbolType inferType(SymbolType type1, SymbolType type2) { // Handle pointers as words if(type1 instanceof SymbolTypePointer) { type1 = SymbolType.WORD; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseNot.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseNot.java index 3ef8aac69..690067238 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseNot.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseNot.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorBitwiseNot extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseOr.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseOr.java index 3e6a46208..9a0309952 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseOr.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseOr.java @@ -21,7 +21,7 @@ public class OperatorBitwiseOr extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple type1, SymbolTypeSimple type2) { + public SymbolType inferType(SymbolType type1, SymbolType type2) { // Handle pointers as words if(type1 instanceof SymbolTypePointer) { type1 = SymbolType.WORD; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseXor.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseXor.java index 2d614f2ab..8c4d71d4a 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseXor.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorBitwiseXor.java @@ -21,7 +21,7 @@ public class OperatorBitwiseXor extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple type1, SymbolTypeSimple type2) { + public SymbolType inferType(SymbolType type1, SymbolType type2) { // Handle pointers as words if(type1 instanceof SymbolTypePointer) { type1 = SymbolType.WORD; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastBool.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastBool.java index 24b02a921..f0b17f0f6 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastBool.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastBool.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -26,7 +25,7 @@ public class OperatorCastBool extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.BOOLEAN; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastByte.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastByte.java index b00ba311a..7b843b4c0 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastByte.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastByte.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -26,7 +25,7 @@ public class OperatorCastByte extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.BYTE; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastDWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastDWord.java index 111b94b7a..54cb2efc7 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastDWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastDWord.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -28,7 +27,7 @@ public class OperatorCastDWord extends OperatorCast { @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.DWORD; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastPtr.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastPtr.java index 142ecc533..041089cd9 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastPtr.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastPtr.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -33,7 +32,7 @@ public class OperatorCastPtr extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return new SymbolTypePointer(elementType); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSByte.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSByte.java index 9487eae97..7d020c032 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSByte.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSByte.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorCastSByte extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.SBYTE; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSDWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSDWord.java index 6ec765ca7..bea05b604 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSDWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSDWord.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorCastSDWord extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.SDWORD; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSWord.java index b8a618979..7954d4243 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastSWord.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorCastSWord extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.SWORD; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastWord.java index 0b1097086..aa0b6c1b6 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorCastWord.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -27,7 +26,7 @@ public class OperatorCastWord extends OperatorCast { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.WORD; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDWord.java index b0e06378c..9ef7fc18d 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDWord.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.NoMatchingType; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -24,7 +23,7 @@ public class OperatorDWord extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { // Handle pointers as words if(left instanceof SymbolTypePointer) { left = SymbolType.WORD; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDecrement.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDecrement.java index 76dbf6087..5dfd1a7a4 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDecrement.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDecrement.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorDecrement extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDeref.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDeref.java index c8a524b31..f14f87a66 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDeref.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDeref.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Unary Pointer Dereference Operator (*p) */ @@ -20,7 +19,7 @@ public class OperatorDeref extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { if(operandType instanceof SymbolTypePointer) { return ((SymbolTypePointer) operandType).getElementType(); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDerefIdx.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDerefIdx.java index c4cf2b56f..834e5c66b 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDerefIdx.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDerefIdx.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Binary Pointer Dereference with an index Operator ( p[i] / *(p+i) ) */ @@ -19,7 +18,7 @@ public class OperatorDerefIdx extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(left instanceof SymbolTypePointer) { return ((SymbolTypePointer) left).getElementType(); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDivide.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDivide.java index e145eb480..eb3be39a8 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorDivide.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorDivide.java @@ -27,7 +27,7 @@ public class OperatorDivide extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(left instanceof SymbolTypePointer) { if(SymbolType.BYTE.equals(right) || SymbolType.WORD.equals(right) || SymbolType.NUMBER.equals(right)) { return left; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorEqual.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorEqual.java index 08777da59..cc990790f 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorEqual.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorEqual.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -25,7 +24,7 @@ public class OperatorEqual extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java index 79902c0c2..e7ad53157 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetHigh.java @@ -5,7 +5,6 @@ import dk.camelot64.kickc.model.ConstantNotLiteral; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -40,7 +39,7 @@ public class OperatorGetHigh extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { if(operandType instanceof SymbolTypePointer || SymbolType.WORD.equals(operandType) || SymbolType.SWORD.equals(operandType)) { return SymbolType.BYTE; } else if(SymbolType.DWORD.equals(operandType) || SymbolType.SDWORD.equals(operandType)) { diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java index 7542903f6..6d8e03c03 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGetLow.java @@ -5,7 +5,6 @@ import dk.camelot64.kickc.model.ConstantNotLiteral; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -40,7 +39,7 @@ public class OperatorGetLow extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { if(operandType instanceof SymbolTypePointer || SymbolType.WORD.equals(operandType) || SymbolType.SWORD.equals(operandType)) { return SymbolType.BYTE; } else if(SymbolType.DWORD.equals(operandType) || SymbolType.SDWORD.equals(operandType)) { diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThan.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThan.java index fcf503c84..f1614c0be 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThan.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThan.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorGreaterThan extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThanEqual.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThanEqual.java index b195f1e40..2ce48f329 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThanEqual.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorGreaterThanEqual.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorGreaterThanEqual extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorIncrement.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorIncrement.java index 70671914f..a7532ff7a 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorIncrement.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorIncrement.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantPointer; @@ -26,7 +25,7 @@ public class OperatorIncrement extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThan.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThan.java index a3d0c379f..ad61da0e8 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThan.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThan.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorLessThan extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThanEqual.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThanEqual.java index af07b0378..cbf042583 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThanEqual.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLessThanEqual.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorLessThanEqual extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicAnd.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicAnd.java index d755616a3..0088ec944 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicAnd.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicAnd.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -22,7 +21,7 @@ public class OperatorLogicAnd extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicNot.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicNot.java index 740f1ce01..990cab0f1 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicNot.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicNot.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorLogicNot extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicOr.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicOr.java index 5c838560a..5d5b92e68 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicOr.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorLogicOr.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -22,7 +21,7 @@ public class OperatorLogicOr extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorMinus.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorMinus.java index ce472ffd7..50c1fb6f7 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorMinus.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorMinus.java @@ -29,7 +29,7 @@ public class OperatorMinus extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple type1, SymbolTypeSimple type2) { + public SymbolType inferType(SymbolType type1, SymbolType type2) { // Handle pointer types if(type1 instanceof SymbolTypePointer && SymbolType.isInteger(type2)) { return new SymbolTypePointer(((SymbolTypePointer) type1).getElementType()); diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorModulo.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorModulo.java index 4fc0a3388..7235c3fdc 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorModulo.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorModulo.java @@ -24,7 +24,7 @@ public class OperatorModulo extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { // Handle numeric types through proper promotion if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) { return SymbolTypeConversion.convertedMathType((SymbolTypeInteger) left, (SymbolTypeInteger) right); diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorMultiply.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorMultiply.java index 48b4cf2d4..a32595647 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorMultiply.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorMultiply.java @@ -21,7 +21,7 @@ public class OperatorMultiply extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(left instanceof SymbolTypePointer) { if(SymbolType.BYTE.equals(right) || SymbolType.WORD.equals(right) || SymbolType.NUMBER.equals(right)) { return left; diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorNeg.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorNeg.java index ce736a9d1..2e777f4f1 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorNeg.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorNeg.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorNeg extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorNotEqual.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorNotEqual.java index 8b995c59e..7aba1389b 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorNotEqual.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorNotEqual.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -29,7 +28,7 @@ public class OperatorNotEqual extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return SymbolType.BOOLEAN; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorPlus.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorPlus.java index 0cb8ec7b8..7df7c77bd 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorPlus.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorPlus.java @@ -37,7 +37,7 @@ public class OperatorPlus extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple type1, SymbolTypeSimple type2) { + public SymbolType inferType(SymbolType type1, SymbolType type2) { // Handle all non-numeric types if(SymbolType.isInteger(type1) && type2 instanceof SymbolTypePointer) { return new SymbolTypePointer(((SymbolTypePointer) type2).getElementType()); @@ -59,7 +59,7 @@ public class OperatorPlus extends OperatorBinary { * @param type The type to check * @return true if the type is string like */ - private boolean isStringLike(SymbolTypeSimple type) { + private boolean isStringLike(SymbolType type) { if(SymbolType.STRING.equals(type)) { return true; } else if(SymbolType.BYTE.equals(type)) { diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorPos.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorPos.java index 03acd3465..507bba6fc 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorPos.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorPos.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorPos extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return operandType; } } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetHigh.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetHigh.java index 19662e139..041322a18 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetHigh.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetHigh.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Binary SetHighByte Operator ( w hi= b ) */ @@ -19,7 +18,7 @@ public class OperatorSetHigh extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(left instanceof SymbolTypePointer) { return left; } else if(SymbolType.BYTE.equals(left)) { diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetLow.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetLow.java index bd4cd763a..180b4b5bd 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetLow.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSetLow.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** Binary SetLowByte Operator ( w lo= b ) */ @@ -19,7 +18,7 @@ public class OperatorSetLow extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(left instanceof SymbolTypePointer) { return left; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftLeft.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftLeft.java index 3350f82f7..5d84970ef 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftLeft.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftLeft.java @@ -2,10 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeConversion; -import dk.camelot64.kickc.model.types.SymbolTypeInteger; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; -import dk.camelot64.kickc.model.values.ConstantBool; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -25,7 +21,7 @@ public class OperatorShiftLeft extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return left; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftRight.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftRight.java index 2f8a9dca0..352dae6d5 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftRight.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorShiftRight.java @@ -2,9 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeConversion; -import dk.camelot64.kickc.model.types.SymbolTypeInteger; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -24,7 +21,7 @@ public class OperatorShiftRight extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { return left; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSizeOf.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSizeOf.java index 11fa1b0a1..422f6a4c2 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorSizeOf.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorSizeOf.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.symbols.ConstantVar; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; import dk.camelot64.kickc.model.values.ConstantRef; @@ -23,7 +22,7 @@ public class OperatorSizeOf extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.BYTE; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorTypeId.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorTypeId.java index c5dca47db..0d09c75e9 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorTypeId.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorTypeId.java @@ -24,7 +24,7 @@ public class OperatorTypeId extends OperatorUnary { } @Override - public SymbolType inferType(SymbolTypeSimple operandType) { + public SymbolType inferType(SymbolType operandType) { return SymbolType.BYTE; } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorUnary.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorUnary.java index d9efd026f..2c1775de7 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorUnary.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorUnary.java @@ -2,7 +2,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.symbols.ProgramScope; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantLiteral; /** A unary expression operator */ @@ -25,6 +24,6 @@ public abstract class OperatorUnary extends Operator { * @param operandType The type of the operand * @return The type resulting from applying the operator to the operand */ - public abstract SymbolType inferType(SymbolTypeSimple operandType); + public abstract SymbolType inferType(SymbolType operandType); } diff --git a/src/main/java/dk/camelot64/kickc/model/operators/OperatorWord.java b/src/main/java/dk/camelot64/kickc/model/operators/OperatorWord.java index c84710823..01f96476c 100644 --- a/src/main/java/dk/camelot64/kickc/model/operators/OperatorWord.java +++ b/src/main/java/dk/camelot64/kickc/model/operators/OperatorWord.java @@ -3,7 +3,6 @@ package dk.camelot64.kickc.model.operators; import dk.camelot64.kickc.model.CompileError; import dk.camelot64.kickc.model.types.NoMatchingType; import dk.camelot64.kickc.model.types.SymbolType; -import dk.camelot64.kickc.model.types.SymbolTypeSimple; import dk.camelot64.kickc.model.values.ConstantInteger; import dk.camelot64.kickc.model.values.ConstantLiteral; @@ -23,7 +22,7 @@ public class OperatorWord extends OperatorBinary { } @Override - public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { + public SymbolType inferType(SymbolType left, SymbolType right) { if(SymbolType.BYTE.equals(left) && SymbolType.BYTE.equals(right)) { return SymbolType.WORD; } diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeBlockScope.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeBlockScope.java index 8d5b113f4..4fc97f3cb 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeBlockScope.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeBlockScope.java @@ -1,7 +1,7 @@ package dk.camelot64.kickc.model.types; /** A block scope */ -public class SymbolTypeBlockScope implements SymbolTypeSimple { +public class SymbolTypeBlockScope implements SymbolType { public SymbolTypeBlockScope() { diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java index 6c308eec4..f2af3c947 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java @@ -1,8 +1,6 @@ package dk.camelot64.kickc.model.types; import dk.camelot64.kickc.model.CompileError; -import dk.camelot64.kickc.model.Program; -import dk.camelot64.kickc.model.operators.Operator; import dk.camelot64.kickc.model.operators.OperatorBinary; import dk.camelot64.kickc.model.operators.OperatorUnary; import dk.camelot64.kickc.model.statements.*; @@ -24,22 +22,7 @@ public class SymbolTypeInference { */ public static SymbolType inferType(ProgramScope programScope, OperatorUnary operator, RValue rValue) { SymbolType valueType = inferType(programScope, rValue); - return inferType(operator, valueType); - } - - /** - * Infer the type of a unary operator on an operand type - * - * @param operator The unary operator - * @param operandType The operand type - * @return The type of the result from applying the operator on the operand - */ - public static SymbolType inferType(OperatorUnary operator, SymbolType operandType) { - if(operandType instanceof SymbolTypeSimple) { - return operator.inferType((SymbolTypeSimple) operandType); - } else { - throw new RuntimeException("Not implemented!"); - } + return operator.inferType(valueType); } /** @@ -54,15 +37,7 @@ public class SymbolTypeInference { public static SymbolType inferType(ProgramScope programScope, RValue left, OperatorBinary operator, RValue right) { SymbolType leftType = inferType(programScope, left); SymbolType rightType = inferType(programScope, right); - return inferType(leftType, operator, rightType); - } - - public static SymbolType inferType(SymbolType left, OperatorBinary operator, SymbolType right) { - if(left instanceof SymbolTypeSimple && right instanceof SymbolTypeSimple) { - return operator.inferType((SymbolTypeSimple) left, (SymbolTypeSimple) right); - } else { - throw new RuntimeException("Not implemented!"); - } + return operator.inferType(leftType, rightType); } public static SymbolType inferType(ProgramScope symbols, RValue rValue) { diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInteger.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInteger.java index 2a4cdfa7f..9a64e214d 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInteger.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInteger.java @@ -1,6 +1,6 @@ package dk.camelot64.kickc.model.types; /** Integer type marker interface. */ -public interface SymbolTypeInteger extends SymbolTypeSimple { +public interface SymbolTypeInteger extends SymbolType { } diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNamed.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNamed.java index fce17747e..5578a24bf 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNamed.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNamed.java @@ -1,7 +1,7 @@ package dk.camelot64.kickc.model.types; /** Basic named (string, char, ...) Symbol Types */ -public class SymbolTypeNamed implements SymbolTypeSimple { +public class SymbolTypeNamed implements SymbolType { private String typeName; diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java index 983e6a21f..9a1519369 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java @@ -1,15 +1,5 @@ package dk.camelot64.kickc.model.types; -import dk.camelot64.kickc.model.InternalError; -import dk.camelot64.kickc.model.operators.OperatorBinary; -import dk.camelot64.kickc.model.operators.OperatorUnary; -import dk.camelot64.kickc.model.statements.StatementAssignment; -import dk.camelot64.kickc.model.symbols.ProgramScope; -import dk.camelot64.kickc.model.values.ConstantInteger; -import dk.camelot64.kickc.model.values.ConstantLiteral; -import dk.camelot64.kickc.model.values.ConstantValue; -import dk.camelot64.kickc.model.values.RValue; - import java.util.ArrayList; import java.util.List; @@ -19,90 +9,6 @@ import java.util.List; */ public class SymbolTypeNumberInference { - /** - * Infer the potential types for an RValue with {@link SymbolType#NUMBER} type - * - * @return The potential types - */ - public static List inferTypesRValue(ProgramScope symbols, StatementAssignment assignment) { - RValue rValue1 = assignment.getrValue1(); - RValue rValue2 = assignment.getrValue2(); - if(assignment.getrValue1() == null && assignment.getOperator() == null && assignment.getrValue2() instanceof ConstantValue) { - return inferTypes(symbols, (ConstantValue) rValue2); - } else if(assignment.getrValue1() == null && assignment.getOperator() instanceof OperatorUnary && assignment.getrValue2() instanceof ConstantValue) { - return inferTypes(symbols, (OperatorUnary) assignment.getOperator(), (ConstantValue) rValue2); - } else if(assignment.getOperator() instanceof OperatorBinary && assignment.getrValue1() instanceof ConstantValue && assignment.getrValue2() instanceof ConstantValue) { - return inferTypes(symbols, (ConstantValue) rValue1, (OperatorBinary) assignment.getOperator(), (ConstantValue) rValue2); - } else { - return new ArrayList<>(); - } - } - - /** - * Infer the potential types for a binary operator with {@link SymbolType#NUMBER} type - * - * @return The potential types - */ - public static List inferTypes(ProgramScope programScope, ConstantValue leftValue, OperatorBinary operator, ConstantValue rightValue) { - if(SymbolType.NUMBER.equals(leftValue.getType(programScope)) && SymbolType.NUMBER.equals(rightValue.getType(programScope))) { - // Calculate resulting constant literal - ConstantLiteral leftLiteral = leftValue.calculateLiteral(programScope); - ConstantLiteral rightLiteral = rightValue.calculateLiteral(programScope); - ConstantLiteral literal = operator.calculateLiteral(leftLiteral, rightLiteral); - if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(programScope))) { - SymbolType literalType = SymbolTypeInference.inferType(programScope, leftValue, operator, rightValue); - ((ConstantInteger) literal).setType(literalType); - throw new InternalError("Unexpected advanced literal type calculation!"); - } - return inferTypes(programScope, literal); - } else { - throw new InternalError("Both operands must be number type."); - } - } - - /** - * Infer the potential types for a unary operator with {@link SymbolType#NUMBER} type - * - * @return The potential types - */ - public static List inferTypes(ProgramScope programScope, OperatorUnary operator, ConstantValue constantValue) { - if(SymbolType.NUMBER.equals(constantValue.getType(programScope))) { - // Calculate resulting constant literal - ConstantLiteral operandLiteral = constantValue.calculateLiteral(programScope); - ConstantLiteral literal = operator.calculateLiteral(operandLiteral, programScope); - if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(programScope))) { - SymbolType literalType = SymbolTypeInference.inferType(programScope, operator, constantValue); - ((ConstantInteger) literal).setType(literalType); - throw new InternalError("Unexpected advanced literal type calculation!"); - } - return inferTypes(programScope, literal); - } else { - throw new InternalError("Operand must be number type."); - } - } - - /** - * Infer the potential types for a constant value with {@link SymbolType#NUMBER} type - * - * @return The potential types - */ - public static List inferTypes(ProgramScope programScope, ConstantValue constantValue) { - // Calculate resulting constant literal - ConstantLiteral constantLiteral = constantValue.calculateLiteral(programScope); - return inferTypes(programScope, constantLiteral); - } - - /** - * Infer the potential types for a constant literal with {@link SymbolType#NUMBER} type - */ - public static List inferTypes(ProgramScope programScope, ConstantLiteral literal) { - if(literal instanceof ConstantInteger && SymbolType.NUMBER.equals(literal.getType(programScope))) { - return inferTypes(((ConstantInteger) literal).getValue()); - } else { - throw new InternalError("Literal must number type."); - } - } - /** * Find any fixed integer types that can contain the passed integer value * @param value the value to examine diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypePointer.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypePointer.java index 8be80416d..451b04e87 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypePointer.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypePointer.java @@ -1,7 +1,7 @@ package dk.camelot64.kickc.model.types; /** A pointer */ -public class SymbolTypePointer implements SymbolTypeSimple { +public class SymbolTypePointer implements SymbolType { /** The number of bytes needed to represent a pointer in memory. */ public static final int SIZE_BYTES = 2; diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProcedure.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProcedure.java index e97924672..30f9e25bd 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProcedure.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProcedure.java @@ -3,7 +3,7 @@ package dk.camelot64.kickc.model.types; import java.util.Objects; /** A function returning another type */ -public class SymbolTypeProcedure implements SymbolTypeSimple { +public class SymbolTypeProcedure implements SymbolType { private SymbolType returnType; diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProgram.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProgram.java index 489f81cc8..186ba98b5 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProgram.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeProgram.java @@ -1,7 +1,7 @@ package dk.camelot64.kickc.model.types; /** A program */ -public class SymbolTypeProgram implements SymbolTypeSimple { +public class SymbolTypeProgram implements SymbolType { public SymbolTypeProgram() { diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeSimple.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeSimple.java deleted file mode 100644 index ea306056a..000000000 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeSimple.java +++ /dev/null @@ -1,5 +0,0 @@ -package dk.camelot64.kickc.model.types; - -/** Marker interface for simple symbol types - ie. not a multi-type */ -public interface SymbolTypeSimple extends SymbolType { -}