mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-20 20:31:56 +00:00
Changed all type comparisons to use SymbolType.XXX.equals()
This commit is contained in:
parent
aaf556abe1
commit
9636e26191
@ -29,7 +29,7 @@ public class OperatorDivide extends OperatorBinary {
|
||||
@Override
|
||||
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
|
||||
if(left instanceof SymbolTypePointer) {
|
||||
if(right.equals(SymbolType.BYTE) || right.equals(SymbolType.WORD)|| right.equals(SymbolType.NUMBER)) {
|
||||
if(SymbolType.BYTE.equals(right) || SymbolType.WORD.equals(right) || SymbolType.NUMBER.equals(right)) {
|
||||
return left;
|
||||
} else {
|
||||
throw new NoMatchingType("Cannot divide pointer by "+right.toString());
|
||||
|
@ -23,7 +23,7 @@ public class OperatorMultiply extends OperatorBinary {
|
||||
@Override
|
||||
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
|
||||
if(left instanceof SymbolTypePointer) {
|
||||
if(right.equals(SymbolType.BYTE) || right.equals(SymbolType.WORD)|| right.equals(SymbolType.NUMBER)) {
|
||||
if(SymbolType.BYTE.equals(right) || SymbolType.WORD.equals(right) || SymbolType.NUMBER.equals(right)) {
|
||||
return left;
|
||||
} else {
|
||||
throw new NoMatchingType("Cannot multiply pointer by "+right.toString());
|
||||
|
@ -155,17 +155,17 @@ public class SymbolTypeConversion {
|
||||
public static boolean assignmentTypeMatch(SymbolType lValueType, SymbolType rValueType) {
|
||||
if(lValueType.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.WORD) && rValueType.equals(SymbolType.BYTE))
|
||||
if(SymbolType.WORD.equals(lValueType) && SymbolType.BYTE.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.DWORD) && rValueType.equals(SymbolType.BYTE))
|
||||
if(SymbolType.DWORD.equals(lValueType) && SymbolType.BYTE.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.DWORD) && rValueType.equals(SymbolType.WORD))
|
||||
if(SymbolType.DWORD.equals(lValueType) && SymbolType.WORD.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.SWORD) && rValueType.equals(SymbolType.SBYTE))
|
||||
if(SymbolType.SWORD.equals(lValueType) && SymbolType.SBYTE.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.SDWORD) && rValueType.equals(SymbolType.SBYTE))
|
||||
if(SymbolType.SDWORD.equals(lValueType) && SymbolType.SBYTE.equals(rValueType))
|
||||
return true;
|
||||
if(lValueType.equals(SymbolType.SDWORD) && rValueType.equals(SymbolType.SWORD))
|
||||
if(SymbolType.SDWORD.equals(lValueType) && SymbolType.SWORD.equals(rValueType))
|
||||
return true;
|
||||
if(SymbolType.NUMBER.equals(rValueType) && SymbolType.isInteger(lValueType)) {
|
||||
// R-value is still a number - constants are probably not done being identified & typed
|
||||
@ -175,7 +175,7 @@ public class SymbolTypeConversion {
|
||||
// R-value is still a number - constants are probably not done being identified & typed
|
||||
return true;
|
||||
}
|
||||
if(SymbolType.STRING.equals(rValueType) && lValueType instanceof SymbolTypePointer && ((SymbolTypePointer) lValueType).getElementType().equals(SymbolType.BYTE)) {
|
||||
if(SymbolType.STRING.equals(rValueType) && lValueType instanceof SymbolTypePointer && SymbolType.BYTE.equals(((SymbolTypePointer) lValueType).getElementType())) {
|
||||
// String value can be assigned into a pointer
|
||||
return true;
|
||||
}
|
||||
@ -198,7 +198,7 @@ public class SymbolTypeConversion {
|
||||
return false;
|
||||
else if(lValueType instanceof SymbolTypePointer && rValueType instanceof SymbolTypePointer && ((SymbolTypePointer) lValueType).getElementType().equals(((SymbolTypePointer) rValueType).getElementType()))
|
||||
return false;
|
||||
else if(lValueType instanceof SymbolTypePointer && SymbolType.STRING.equals(rValueType) && ((SymbolTypePointer) lValueType).getElementType().equals(SymbolType.BYTE))
|
||||
else if(lValueType instanceof SymbolTypePointer && SymbolType.STRING.equals(rValueType) && SymbolType.BYTE.equals(((SymbolTypePointer) lValueType).getElementType()))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
@ -73,7 +73,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
|
||||
SymbolType valueType = SymbolTypeInference.inferType(getScope(), constVal);
|
||||
SymbolType variableType = variable.getType();
|
||||
|
||||
if(!variableType.equals(SymbolType.NUMBER) && valueType.equals(SymbolType.NUMBER)) {
|
||||
if(!SymbolType.NUMBER.equals(variableType) && SymbolType.NUMBER.equals(valueType)) {
|
||||
// Value is number - wait til it is cast to a proper type
|
||||
constants.remove(constRef);
|
||||
continue;
|
||||
|
@ -37,7 +37,7 @@ public class PassNAddNumberTypeConversions extends Pass2SsaOptimization {
|
||||
modified.set(true);
|
||||
}
|
||||
SymbolType rightType = SymbolTypeInference.inferType(getProgram().getScope(), right);
|
||||
if(rightType.equals(SymbolType.NUMBER)) {
|
||||
if(SymbolType.NUMBER.equals(rightType)) {
|
||||
getLog().append("Adding number conversion cast (" + castType + ") " + binary.getRight().toString() + " in " + ((currentStmt==null)?"":currentStmt.toString(getProgram(), false)));
|
||||
binary.addRightCast(castType, stmtIt, currentBlock==null?null:currentBlock.getScope(), getScope());
|
||||
modified.set(true);
|
||||
|
@ -40,7 +40,7 @@ public class PassNAddTypeConversionAssignment extends Pass2SsaOptimization {
|
||||
}
|
||||
|
||||
// Detect word literal constructor
|
||||
if(leftType.equals(SymbolType.WORD) && isLiteralWordCandidate(rightType)) {
|
||||
if(SymbolType.WORD.equals(leftType) && isLiteralWordCandidate(rightType)) {
|
||||
SymbolType conversionType = SymbolType.WORD;
|
||||
getLog().append("Identified literal word (" + conversionType + ") " + binary.getRight().toString() + " in " + (currentStmt == null ? "" : currentStmt.toString(getProgram(), false)));
|
||||
binary.addRightCast(conversionType, stmtIt, currentBlock == null ? null : currentBlock.getScope(), getScope());
|
||||
@ -55,7 +55,7 @@ public class PassNAddTypeConversionAssignment extends Pass2SsaOptimization {
|
||||
}
|
||||
|
||||
// Detect dword literal constructor
|
||||
if(leftType.equals(SymbolType.DWORD) && isLiteralWordCandidate(rightType)) {
|
||||
if(SymbolType.DWORD.equals(leftType) && isLiteralWordCandidate(rightType)) {
|
||||
SymbolType conversionType = SymbolType.DWORD;
|
||||
getLog().append("Identified literal word (" + conversionType + ") " + binary.getRight().toString() + " in " + (currentStmt == null ? "" : currentStmt.toString(getProgram(), false)));
|
||||
binary.addRightCast(conversionType, stmtIt, currentBlock == null ? null : currentBlock.getScope(), getScope());
|
||||
|
@ -68,7 +68,7 @@ public class PassNDowngradeConstantTypeConversions extends Pass2SsaOptimization
|
||||
*/
|
||||
public boolean isWordLike(RValue rValue) {
|
||||
SymbolType symbolType = SymbolTypeInference.inferType(getProgram().getScope(), rValue);
|
||||
return symbolType.equals(SymbolType.WORD) || symbolType instanceof SymbolTypePointer;
|
||||
return SymbolType.WORD.equals(symbolType) || symbolType instanceof SymbolTypePointer;
|
||||
}
|
||||
|
||||
|
||||
@ -79,10 +79,10 @@ public class PassNDowngradeConstantTypeConversions extends Pass2SsaOptimization
|
||||
* @return true if the value is a constant cast to word
|
||||
*/
|
||||
public boolean isConstantWord(RValue rValue) {
|
||||
if(rValue instanceof ConstantInteger && ((ConstantInteger) rValue).getType().equals(SymbolType.WORD)) {
|
||||
if(rValue instanceof ConstantInteger && SymbolType.WORD.equals(((ConstantInteger) rValue).getType())) {
|
||||
return true;
|
||||
}
|
||||
if((rValue instanceof ConstantCastValue) && ((ConstantCastValue) rValue).getToType().equals(SymbolType.WORD))
|
||||
if((rValue instanceof ConstantCastValue) && SymbolType.WORD.equals(((ConstantCastValue) rValue).getToType()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class PassNTypeIdSimplification extends Pass2SsaOptimization {
|
||||
if(Operators.TYPEID.equals(unary.getOperator())) {
|
||||
RValue rValue = unary.getOperand();
|
||||
SymbolType symbolType = SymbolTypeInference.inferType(getScope(), rValue);
|
||||
if(symbolType.equals(SymbolType.VAR) || symbolType.equals(SymbolType.NUMBER)) {
|
||||
if(SymbolType.VAR.equals(symbolType) || SymbolType.NUMBER.equals(symbolType)) {
|
||||
|
||||
} else {
|
||||
getLog().append("Resolving typeid() " + currentStmt.toString(getProgram(), false));
|
||||
|
Loading…
x
Reference in New Issue
Block a user