This commit is contained in:
Irmen de Jong
2025-05-18 17:50:49 +02:00
parent 6d4ccc5feb
commit adf5600a9b
10 changed files with 65 additions and 71 deletions

View File

@@ -1093,7 +1093,10 @@ class ArrayLiteral(val type: InferredTypes.InferredType, // inferred because
val unique = dts.toSet()
if(unique.size==1) {
val dt = unique.single()
return InferredTypes.knownFor(DataType.arrayOfPointersTo(dt.sub, dt.subType))
return if(dt.subType!=null)
InferredTypes.knownFor(DataType.arrayOfPointersTo(dt.subType!!))
else
InferredTypes.knownFor(DataType.arrayOfPointersTo(dt.sub!!))
}
}
return when {
@@ -1474,7 +1477,7 @@ class FunctionCallExpression(override var target: IdentifierReference,
}
is StructDecl -> {
// calling a struct is syntax for allocating a static instance, and returns a pointer to that (not the instance itself)
return InferredTypes.knownFor(DataType.pointerToType(stmt))
return InferredTypes.knownFor(DataType.pointer(stmt))
}
else -> return InferredTypes.unknown()
}
@@ -1691,7 +1694,7 @@ class PtrDereference(val identifier: IdentifierReference, val chain: List<String
struct = fieldDt.subType as StructDecl
}
if(field==null) {
return InferredTypes.knownFor(DataType.pointerToType(struct))
return InferredTypes.knownFor(DataType.pointer(struct))
}
val fieldDt = struct.getFieldType(field)
return if(fieldDt==null)

View File

@@ -93,27 +93,10 @@ object InferredTypes {
else -> throw IllegalArgumentException("invalid sub type")
}
}
type.isPointerArray -> {
InferredType.known(DataType.arrayOfPointersTo(type.sub, type.subType))
}
type.isArray -> {
InferredType.known(DataType.arrayFor(type.sub!!, false))
}
type.isPointer -> {
if(type.subType!=null)
InferredType.known(DataType.pointerToType(type.subType!!))
else if(type.sub!=null)
InferredType.known(DataType.pointer(type.sub!!))
else
InferredType.known(DataType.pointerFromAntlr(type.subTypeFromAntlr!!))
}
type.isPointerArray -> InferredType.known(DataType.arrayOfPointersTo(type.sub, type.subType))
type.isStructInstance -> {
if(type.subType!=null)
InferredType.known(DataType.structInstance(type.subType!!))
else
InferredType.known(DataType.structInstanceFromAntlr(type.subTypeFromAntlr!!))
}
type.isPointerArray -> InferredType.known(type)
type.isArray -> InferredType.known(type)
type.isPointer -> InferredType.known(type)
type.isStructInstance -> InferredType.known(type)
else -> throw IllegalArgumentException("invalid type $type")
}
}