[fpc-pascal] Printing types in generics
Ryan Joseph
ryan at thealchemistguild.com
Thu Oct 19 07:14:02 CEST 2017
How should you print types in generics for debugging? here’s an example of how I’m doing it now but it’s hacky (forced type casting pointers) and tkSString crashes like it is. There should be a better solution I think.
procedure TStaticArray.PrintValue (value: T);
begin
case typeKind of
tkClass:
begin
if not IsDefault(value) then
TObjectPtr(@value)^.Show
else
writeln('nil');
end;
tkPointer:
begin
if not IsDefault(value) then
writeln(HexStr(PPointer(@value)^))
else
writeln('nil');
end;
tkRecord:
writeln('record');
tkSString:
// TODO: crashes.
writeln(PString(@value)^);
otherwise
writeln(PInteger(@value)^); // this is just a hack to print compiler types
end;
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list