[fpc-pascal] Constants in generics

Ryan Joseph ryan at thealchemistguild.com
Sun Jan 6 18:37:18 CET 2019


Last question I have I think. 

Is this the best way to get "pretty name" string for a set? Having to loop through the entire range of the set is not so great but I don’t see another way. I feel like there should be some utility functions to get names for ord defs also but I just did a crude string conversion for now.

new(ps);
ps^:=tsetconstnode(node).value_set^;
sym:=cconstsym.create_ptr(undefinedname,constset,ps,fromdef);
setdef:=tsetdef(tsetconstnode(node).resultdef);
enumdef:=tenumdef(setdef.elementdef);
prettyname:='[';
for i := setdef.setbase to setdef.setmax do
  if i in tsetconstnode(node).value_set^ then
    begin
      enumsym:=enumdef.int2enumsym(i);
      if assigned(enumsym) then
        enumname:=enumsym.realname
      else if enumdef.typ=orddef then
        begin
          if torddef(enumdef).ordtype=uchar then
            enumname:=chr(i)
          else
            enumname:=tostr(i);
        end
      else
        enumname:=tostr(i);
      if length(prettyname) > 1 then
        prettyname:=prettyname+','+enumname
      else
        prettyname:=prettyname+enumname;
    end;
prettyname:=prettyname+']';


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list