mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-07 06:37:31 +00:00
Moving array properties from type to variable. Fixed the last few tests.
This commit is contained in:
parent
8656cc4785
commit
4ab7fe0596
@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.CompileError;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -23,50 +22,45 @@ public class Pass3AssertArrayLengths extends Pass2SsaAssertion {
|
||||
Collection<Variable> allConstants = getScope().getAllConstants(true);
|
||||
for(Variable constantVar : allConstants) {
|
||||
SymbolType constantType = constantVar.getType();
|
||||
if(constantType instanceof SymbolTypeArray) {
|
||||
RValue declaredSize = ((SymbolTypeArray) constantType).getSize();
|
||||
if(declaredSize != null) {
|
||||
if(!(declaredSize instanceof ConstantValue)) {
|
||||
throw new CompileError("Error! Array declared size is not constant " + constantType.toString());
|
||||
}
|
||||
ConstantLiteral declaredSizeVal = ((ConstantValue) declaredSize).calculateLiteral(getScope());
|
||||
if(!(declaredSizeVal instanceof ConstantInteger)) {
|
||||
if(constantVar.isArray() && constantVar.getArraySize() != null) {
|
||||
ConstantValue declaredSize = constantVar.getArraySize();
|
||||
ConstantLiteral declaredSizeVal = declaredSize.calculateLiteral(getScope());
|
||||
if(!(declaredSizeVal instanceof ConstantInteger)) {
|
||||
throw new CompileError("Error! Array declared size is not integer " + constantType.toString());
|
||||
}
|
||||
Integer declaredSizeInt = ((ConstantInteger) declaredSizeVal).getInteger().intValue();
|
||||
// A constant size was found - Check that a value with the same size is present
|
||||
ConstantValue constantValue = constantVar.getConstantValue();
|
||||
if(constantValue == null) {
|
||||
throw new CompileError("Error! Array with a size not initialized " + constantVar.toString(getProgram()));
|
||||
} else if(constantValue instanceof ConstantArrayFilled) {
|
||||
ConstantValue assignedSize = ((ConstantArrayFilled) constantValue).getSize();
|
||||
ConstantLiteral assignedSizeVal = assignedSize.calculateLiteral(getScope());
|
||||
if(!(assignedSizeVal instanceof ConstantInteger)) {
|
||||
throw new CompileError("Error! Array declared size is not integer " + constantType.toString());
|
||||
}
|
||||
Integer declaredSizeInt = ((ConstantInteger) declaredSizeVal).getInteger().intValue();
|
||||
// A constant size was found - Check that a value with the same size is present
|
||||
ConstantValue constantValue = constantVar.getConstantValue();
|
||||
if(constantValue == null) {
|
||||
throw new CompileError("Error! Array with a size not initialized " + constantVar.toString(getProgram()));
|
||||
} else if(constantValue instanceof ConstantArrayFilled) {
|
||||
ConstantValue assignedSize = ((ConstantArrayFilled) constantValue).getSize();
|
||||
ConstantLiteral assignedSizeVal = assignedSize.calculateLiteral(getScope());
|
||||
if(!(assignedSizeVal instanceof ConstantInteger)) {
|
||||
throw new CompileError("Error! Array declared size is not integer " + constantType.toString());
|
||||
}
|
||||
Integer assignedSizeInt = ((ConstantInteger) declaredSizeVal).getInteger().intValue();
|
||||
if(!assignedSizeInt.equals(declaredSizeInt)) {
|
||||
throw new CompileError("Error! Array length mismatch " + constantVar.toString(getProgram()));
|
||||
}
|
||||
} else if(constantValue instanceof ConstantArrayList) {
|
||||
Integer assignedSizeVal = ((ConstantArrayList) constantValue).getElements().size();
|
||||
Integer assignedSizeInt = ((ConstantInteger) declaredSizeVal).getInteger().intValue();
|
||||
if(!assignedSizeInt.equals(declaredSizeInt)) {
|
||||
throw new CompileError("Error! Array length mismatch " + constantVar.toString(getProgram()));
|
||||
}
|
||||
} else if(constantValue instanceof ConstantArrayList) {
|
||||
Integer assignedSizeVal = ((ConstantArrayList) constantValue).getElements().size();
|
||||
if(assignedSizeVal > declaredSizeInt) {
|
||||
throw new CompileError("Error! Array length mismatch " + constantVar.toString(getProgram()));
|
||||
}
|
||||
} else if(constantValue instanceof ConstantArrayKickAsm) {
|
||||
// KickAsm array initializer is assumed good!
|
||||
} else {
|
||||
ConstantLiteral constantLiteral = constantValue.calculateLiteral(getScope());
|
||||
if(constantLiteral instanceof ConstantString) {
|
||||
Integer assignedSizeVal = ((ConstantString) constantLiteral).getStringLength();
|
||||
if(assignedSizeVal > declaredSizeInt) {
|
||||
throw new CompileError("Error! Array length mismatch " + constantVar.toString(getProgram()));
|
||||
}
|
||||
} else if(constantValue instanceof ConstantArrayKickAsm) {
|
||||
// KickAsm array initializer is assumed good!
|
||||
} else if(constantLiteral instanceof ConstantPointer) {
|
||||
// Constant Pointers are OK for sized arrays
|
||||
} else {
|
||||
ConstantLiteral constantLiteral = constantValue.calculateLiteral(getScope());
|
||||
if(constantLiteral instanceof ConstantString) {
|
||||
Integer assignedSizeVal = ((ConstantString) constantLiteral).getStringLength();
|
||||
if(assignedSizeVal > declaredSizeInt) {
|
||||
throw new CompileError("Error! Array length mismatch " + constantVar.toString(getProgram()));
|
||||
}
|
||||
} else if(constantLiteral instanceof ConstantPointer) {
|
||||
// Constant Pointers are OK for sized arrays
|
||||
} else {
|
||||
throw new AssertionFailed("Error! Array with a size unknown initialization value " + constantVar.toString(getProgram()));
|
||||
}
|
||||
throw new AssertionFailed("Error! Array with a size unknown initialization value " + constantVar.toString(getProgram()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
Fixing struct type size struct Person to 5
|
||||
Fixing struct type size struct Person to 5
|
||||
Fixing struct type size struct Person to 5
|
||||
Fixing pointer increment (struct Person*) main::person ← ++ (struct Person*) main::person
|
||||
Rewriting struct pointer member access *((struct Person*) print_person::person).id
|
||||
Rewriting struct pointer member access *((struct Person*) print_person::person).initials
|
||||
|
@ -1,4 +1,5 @@
|
||||
Fixing struct type size struct Person to 16
|
||||
Fixing struct type size struct Person to 16
|
||||
Fixing pointer increment (struct Person*) main::person ← ++ (struct Person*) main::person
|
||||
Rewriting struct pointer member access *((struct Person*) main::person).name
|
||||
Rewriting struct pointer member access *((struct Person*) main::person).name
|
||||
|
Loading…
x
Reference in New Issue
Block a user