1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-11 16:30:56 +00:00

Fixed toUpperCase() to use a specific locale. Closes #262

This commit is contained in:
jespergravgaard 2019-08-16 21:00:29 +02:00
parent 09d68e6931
commit eaabba4ea2
5 changed files with 14 additions and 7 deletions

View File

@ -3,6 +3,8 @@ package dk.camelot64.kickc.model;
import dk.camelot64.kickc.model.values.ConstantValue;
import dk.camelot64.kickc.model.values.Value;
import java.util.Locale;
/** The different registers available for a program */
public class Registers {
@ -24,7 +26,7 @@ public class Registers {
}
public static Register getRegister(String name) {
switch(name.toUpperCase()) {
switch(name.toUpperCase(Locale.ENGLISH)) {
case "A":
return getRegisterA();
case "X":

View File

@ -9,6 +9,8 @@ import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantRef;
import java.util.Locale;
/** SizeOf operator sizeof(expr). Will be resolved into a constant as soon as the expression has been resolved enough. */
public class OperatorSizeOf extends OperatorUnary {
@ -56,7 +58,7 @@ public class OperatorSizeOf extends OperatorUnary {
if(type instanceof SymbolTypePointer) {
return "SIZEOF_POINTER";
} else {
return "SIZEOF_" + type.getTypeName().toUpperCase().replace(" ", "_");
return "SIZEOF_" + type.getTypeName().toUpperCase(Locale.ENGLISH).replace(" ", "_");
}
}

View File

@ -8,6 +8,8 @@ import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantRef;
import java.util.Locale;
/**
* TypeId operator typeid(expr) returns byte value representing the type of the expression.
* Will be resolved into a constant as soon as the expression has been resolved enough.
@ -60,7 +62,7 @@ public class OperatorTypeId extends OperatorUnary {
} else if(type instanceof SymbolTypePointer) {
return "POINTER_" + getTypeIdConstantName(((SymbolTypePointer) type).getElementType());
} else {
return type.getTypeName().toUpperCase().replace(" ", "_");
return type.getTypeName().toUpperCase(Locale.ENGLISH).replace(" ", "_");
}
}

View File

@ -135,7 +135,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public Object visitGlobalDirectiveEncoding(KickCParser.GlobalDirectiveEncodingContext ctx) {
try {
this.currentEncoding = ConstantString.Encoding.valueOf(ctx.NAME().getText().toUpperCase());
this.currentEncoding = ConstantString.Encoding.valueOf(ctx.NAME().getText().toUpperCase(Locale.ENGLISH));
} catch(IllegalArgumentException e) {
throw new CompileError("Unknown string encoding " + ctx.NAME().getText(), new StatementSource(ctx));
}
@ -474,7 +474,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public AsmDirectiveClobber visitAsmDirectiveClobber(KickCParser.AsmDirectiveClobberContext ctx) {
String clobberString = ctx.STRING().getText().toUpperCase();
String clobberString = ctx.STRING().getText().toUpperCase(Locale.ENGLISH);
clobberString = clobberString.substring(1, clobberString.length() - 1);
if(!clobberString.matches("[AXY]*")) {
throw new CompileError("Error! Illegal clobber value " + clobberString, new StatementSource(ctx));
@ -761,7 +761,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
public Object visitDirectiveInterrupt(KickCParser.DirectiveInterruptContext ctx) {
String interruptType;
if(ctx.getChildCount() > 1) {
interruptType = ctx.getChild(2).getText().toUpperCase();
interruptType = ctx.getChild(2).getText().toUpperCase(Locale.ENGLISH);
} else {
// The default interrupt type
interruptType = Procedure.InterruptType.DEFAULT.name();

View File

@ -12,6 +12,7 @@ import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
import dk.camelot64.kickc.model.values.*;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@ -113,7 +114,7 @@ public class PassNStructPointerRewriting extends Pass2SsaOptimization {
* @return The name of the constant
*/
private static String getMemberOffsetConstantName(StructDefinition structDefinition, String memberName) {
return "OFFSET_" + structDefinition.getType().getTypeName().toUpperCase().replace(" ", "_") + "_" + memberName.toUpperCase();
return "OFFSET_" + structDefinition.getType().getTypeName().toUpperCase(Locale.ENGLISH).replace(" ", "_") + "_" + memberName.toUpperCase();
}