From bbb9aaaa515be96748756a4bfae0e6c237e86429 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 15 Jan 2023 12:49:28 +0200 Subject: [PATCH] Typing - Added `getReferType()` to `Pointer` type to refer the `Type` instance of the data being pointed to DGen - Fixed bug whereby pointer types were not being transformed correctly in typeTransform()` --- source/tlang/compiler/codegen/emit/dgen.d | 14 ++++++++++++-- source/tlang/compiler/symbols/typing/core.d | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/codegen/emit/dgen.d b/source/tlang/compiler/codegen/emit/dgen.d index 4d835253..7c219d27 100644 --- a/source/tlang/compiler/codegen/emit/dgen.d +++ b/source/tlang/compiler/codegen/emit/dgen.d @@ -17,7 +17,7 @@ import compiler.codegen.mapper : SymbolMapper; import compiler.symbols.data : SymbolType, Variable, Function, VariableParameter; import compiler.symbols.check : getCharacter; import misc.utils : Stack; -import compiler.symbols.typing.core : Type, Primitive, Integer, Void; +import compiler.symbols.typing.core : Type, Primitive, Integer, Void, Pointer; public final class DCodeEmitter : CodeEmitter { @@ -58,8 +58,18 @@ public final class DCodeEmitter : CodeEmitter // TODO: Some types will ident transform + /* Pointer types */ + if(cast(Pointer)typeIn) + { + /* Extract type being pointed to */ + Pointer pointerType = cast(Pointer)typeIn; + Type referType = pointerType.getReferType(); + + /* The type is then `transform()*` */ + return typeTransform(referType)~"*"; + } /* Integral types transformation */ - if(cast(Integer)typeIn) + else if(cast(Integer)typeIn) { Integer integralType = cast(Integer)typeIn; diff --git a/source/tlang/compiler/symbols/typing/core.d b/source/tlang/compiler/symbols/typing/core.d index b46303c5..ada3f9cb 100644 --- a/source/tlang/compiler/symbols/typing/core.d +++ b/source/tlang/compiler/symbols/typing/core.d @@ -105,6 +105,11 @@ public class Pointer : Integer super(name, 8); this.dataType = dataType; } + + public Type getReferType() + { + return dataType; + } } /**