mirror of
https://github.com/irmen/prog8.git
synced 2025-11-02 13:16:07 +00:00
simplify
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user