mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-23 08:32:39 +00:00
Eliminated SymbolTypeSimple. Eliminated SymbolTypeInference.infer(type, ...). Eliminiated most of SymbolTypeNumberInference.
This commit is contained in:
parent
2fb9a5baf3
commit
864b993f14
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class OperatorTypeId extends OperatorUnary {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SymbolType inferType(SymbolTypeSimple operandType) {
|
||||
public SymbolType inferType(SymbolType operandType) {
|
||||
return SymbolType.BYTE;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** Integer type marker interface. */
|
||||
public interface SymbolTypeInteger extends SymbolTypeSimple {
|
||||
public interface SymbolTypeInteger extends SymbolType {
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<SymbolTypeIntegerFixed> 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<SymbolTypeIntegerFixed> 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<SymbolTypeIntegerFixed> 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<SymbolTypeIntegerFixed> 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<SymbolTypeIntegerFixed> 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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** A program */
|
||||
public class SymbolTypeProgram implements SymbolTypeSimple {
|
||||
public class SymbolTypeProgram implements SymbolType {
|
||||
|
||||
public SymbolTypeProgram() {
|
||||
|
||||
|
@ -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 {
|
||||
}
|
Loading…
Reference in New Issue
Block a user