1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-08-11 02:25:17 +00:00

Changed all type comparisons to use SymbolType.XXX.equals()

This commit is contained in:
Jesper Gravgaard
2019-05-22 15:53:48 +02:00
parent aaf556abe1
commit 9636e26191
8 changed files with 18 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ public class OperatorDivide extends OperatorBinary {
@Override @Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
if(left instanceof SymbolTypePointer) { 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; return left;
} else { } else {
throw new NoMatchingType("Cannot divide pointer by "+right.toString()); throw new NoMatchingType("Cannot divide pointer by "+right.toString());

View File

@@ -23,7 +23,7 @@ public class OperatorMultiply extends OperatorBinary {
@Override @Override
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) { public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
if(left instanceof SymbolTypePointer) { 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; return left;
} else { } else {
throw new NoMatchingType("Cannot multiply pointer by "+right.toString()); throw new NoMatchingType("Cannot multiply pointer by "+right.toString());

View File

@@ -155,17 +155,17 @@ public class SymbolTypeConversion {
public static boolean assignmentTypeMatch(SymbolType lValueType, SymbolType rValueType) { public static boolean assignmentTypeMatch(SymbolType lValueType, SymbolType rValueType) {
if(lValueType.equals(rValueType)) if(lValueType.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.WORD) && rValueType.equals(SymbolType.BYTE)) if(SymbolType.WORD.equals(lValueType) && SymbolType.BYTE.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.DWORD) && rValueType.equals(SymbolType.BYTE)) if(SymbolType.DWORD.equals(lValueType) && SymbolType.BYTE.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.DWORD) && rValueType.equals(SymbolType.WORD)) if(SymbolType.DWORD.equals(lValueType) && SymbolType.WORD.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.SWORD) && rValueType.equals(SymbolType.SBYTE)) if(SymbolType.SWORD.equals(lValueType) && SymbolType.SBYTE.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.SDWORD) && rValueType.equals(SymbolType.SBYTE)) if(SymbolType.SDWORD.equals(lValueType) && SymbolType.SBYTE.equals(rValueType))
return true; return true;
if(lValueType.equals(SymbolType.SDWORD) && rValueType.equals(SymbolType.SWORD)) if(SymbolType.SDWORD.equals(lValueType) && SymbolType.SWORD.equals(rValueType))
return true; return true;
if(SymbolType.NUMBER.equals(rValueType) && SymbolType.isInteger(lValueType)) { if(SymbolType.NUMBER.equals(rValueType) && SymbolType.isInteger(lValueType)) {
// R-value is still a number - constants are probably not done being identified & typed // 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 // R-value is still a number - constants are probably not done being identified & typed
return true; 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 // String value can be assigned into a pointer
return true; return true;
} }
@@ -198,7 +198,7 @@ public class SymbolTypeConversion {
return false; return false;
else if(lValueType instanceof SymbolTypePointer && rValueType instanceof SymbolTypePointer && ((SymbolTypePointer) lValueType).getElementType().equals(((SymbolTypePointer) rValueType).getElementType())) else if(lValueType instanceof SymbolTypePointer && rValueType instanceof SymbolTypePointer && ((SymbolTypePointer) lValueType).getElementType().equals(((SymbolTypePointer) rValueType).getElementType()))
return false; 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; return false;
else else
return true; return true;

View File

@@ -73,7 +73,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
SymbolType valueType = SymbolTypeInference.inferType(getScope(), constVal); SymbolType valueType = SymbolTypeInference.inferType(getScope(), constVal);
SymbolType variableType = variable.getType(); 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 // Value is number - wait til it is cast to a proper type
constants.remove(constRef); constants.remove(constRef);
continue; continue;

View File

@@ -37,7 +37,7 @@ public class PassNAddNumberTypeConversions extends Pass2SsaOptimization {
modified.set(true); modified.set(true);
} }
SymbolType rightType = SymbolTypeInference.inferType(getProgram().getScope(), right); 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))); 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()); binary.addRightCast(castType, stmtIt, currentBlock==null?null:currentBlock.getScope(), getScope());
modified.set(true); modified.set(true);

View File

@@ -40,7 +40,7 @@ public class PassNAddTypeConversionAssignment extends Pass2SsaOptimization {
} }
// Detect word literal constructor // Detect word literal constructor
if(leftType.equals(SymbolType.WORD) && isLiteralWordCandidate(rightType)) { if(SymbolType.WORD.equals(leftType) && isLiteralWordCandidate(rightType)) {
SymbolType conversionType = SymbolType.WORD; SymbolType conversionType = SymbolType.WORD;
getLog().append("Identified literal word (" + conversionType + ") " + binary.getRight().toString() + " in " + (currentStmt == null ? "" : currentStmt.toString(getProgram(), false))); 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()); binary.addRightCast(conversionType, stmtIt, currentBlock == null ? null : currentBlock.getScope(), getScope());
@@ -55,7 +55,7 @@ public class PassNAddTypeConversionAssignment extends Pass2SsaOptimization {
} }
// Detect dword literal constructor // Detect dword literal constructor
if(leftType.equals(SymbolType.DWORD) && isLiteralWordCandidate(rightType)) { if(SymbolType.DWORD.equals(leftType) && isLiteralWordCandidate(rightType)) {
SymbolType conversionType = SymbolType.DWORD; SymbolType conversionType = SymbolType.DWORD;
getLog().append("Identified literal word (" + conversionType + ") " + binary.getRight().toString() + " in " + (currentStmt == null ? "" : currentStmt.toString(getProgram(), false))); 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()); binary.addRightCast(conversionType, stmtIt, currentBlock == null ? null : currentBlock.getScope(), getScope());

View File

@@ -68,7 +68,7 @@ public class PassNDowngradeConstantTypeConversions extends Pass2SsaOptimization
*/ */
public boolean isWordLike(RValue rValue) { public boolean isWordLike(RValue rValue) {
SymbolType symbolType = SymbolTypeInference.inferType(getProgram().getScope(), 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 * @return true if the value is a constant cast to word
*/ */
public boolean isConstantWord(RValue rValue) { 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; 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 true;
return false; return false;
} }

View File

@@ -30,7 +30,7 @@ public class PassNTypeIdSimplification extends Pass2SsaOptimization {
if(Operators.TYPEID.equals(unary.getOperator())) { if(Operators.TYPEID.equals(unary.getOperator())) {
RValue rValue = unary.getOperand(); RValue rValue = unary.getOperand();
SymbolType symbolType = SymbolTypeInference.inferType(getScope(), rValue); 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 { } else {
getLog().append("Resolving typeid() " + currentStmt.toString(getProgram(), false)); getLog().append("Resolving typeid() " + currentStmt.toString(getProgram(), false));