mirror of
https://github.com/irmen/prog8.git
synced 2025-11-01 22:16:16 +00:00
start making '&' (address-of) return a typed pointer, fixes some errors
This commit is contained in:
@@ -635,14 +635,14 @@ private fun ExpressionContext.toAst(insideParentheses: Boolean=false) : Expressi
|
||||
|
||||
if(addressof()!=null) {
|
||||
val addressOf = addressof()
|
||||
val identifier = addressOf.scoped_identifier()
|
||||
val identifier = addressOf.scoped_identifier().toAst()
|
||||
val msb = addressOf.ADDRESS_OF_MSB()!=null
|
||||
// note: &< (ADDRESS_OF_LSB) is equivalent to a regular &.
|
||||
return if (identifier != null)
|
||||
AddressOf(addressof().scoped_identifier().toAst(),null, null, msb, toPosition())
|
||||
else {
|
||||
val array = addressOf.arrayindexed()
|
||||
AddressOf(array.scoped_identifier().toAst(), array.arrayindex().toAst(), null, msb, toPosition())
|
||||
val index = addressOf.arrayindex()?.toAst()
|
||||
return if(index!=null) {
|
||||
AddressOf(identifier, index, null, msb, toPosition())
|
||||
} else {
|
||||
AddressOf(identifier,null, null, msb, toPosition())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -553,7 +553,17 @@ data class AddressOf(var identifier: IdentifierReference?, var arrayIndex: Array
|
||||
return null
|
||||
}
|
||||
override fun referencesIdentifier(nameInSource: List<String>) = identifier?.nameInSource==nameInSource || arrayIndex?.referencesIdentifier(nameInSource)==true || dereference?.referencesIdentifier(nameInSource)==true
|
||||
override fun inferType(program: Program) = InferredTypes.knownFor(BaseDataType.UWORD)
|
||||
override fun inferType(program: Program): InferredTypes.InferredType {
|
||||
if(identifier!=null) {
|
||||
val type = identifier!!.inferType(program).getOrUndef()
|
||||
val addrofDt = type.typeForAddressOf(msb)
|
||||
if(addrofDt.isUndefined) return InferredTypes.unknown()
|
||||
else return InferredTypes.knownFor(addrofDt)
|
||||
} else if(dereference!=null) {
|
||||
TODO("address-of struct ptr deref field -> ptr type itself?")
|
||||
} else
|
||||
throw FatalAstException("invalid addressof")
|
||||
}
|
||||
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
|
||||
override fun accept(visitor: AstWalker, parent: Node)= visitor.visit(this, parent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user