[fpc-devel] Macro Processing

Joerg Schuelke joerg.schuelke at gmx.de
Mon May 16 14:13:15 CEST 2011


Am Mon, 16 May 2011 08:37:12 +0200
schrieb Florian Klaempfl <florian at freepascal.org>:

> You still need to keep infoarr and callenum in sync so "simple" macros
> are only half of a solution in this case.

If it should be done, maybe this way:
	But, I have no clue about macro writing

Thats a globally used one, for all lists. Arguments are:
  mac      the macro which is done on every element
  delim    the delimiter of the resulting list
  args     the macro which expands to the arguments (OK first
           attempt ;-)

{$Macro dolist(mac,delim,args):=
  {$Macro __tmp:={$Expand %args%}}   // temp copy of args
  {$Macro _dolist(mac,delim,_arg,_args..):=
    {$Expand %mac%(%_arg%)}          // do it on the first
    {$IFNOT % %_args..%=''}          // are there more
      % %delim%                      // tokenization of delim
      {$Expand _dolist(%mac%,%_args..%)}  // process more
    {$ENDIF}
  }
  {$Expand _dolist(%mac%,%delim%,{$Expand _tmp})} // ?? looks bad
} // the explicit syntax is more annoying then I thought!

It looks bad, I know but I can not think that macro way, There are
other solutions to process a list without recursion, defining macros
with new names like fac_6 fac_5 fac_4 .. and then expanding only once.
There are C programmers who knows how it works.

But if you think you have a need. It is only done once! And then never
touched again. Residing in a general used unit.

// What to do for enum and info
{$Macro en_entry(x):=  proc %% %x%  }
{$Macro info_entry(x):= { id:proc %% %x%;name:'proc' %% % %x%;address:@cb_proc %% %x% }}

// The list I process
{$Macro the_list:=1,2,3,4,5,6}

  callenum=(
    {$Expand dolist(en_entry,',',the_list)}
  );

  infoarr:array[callenum]of inforec={
    {$Expand dolist(info_entry,';',the_list)}
  );

Be generous I really hate that macro stuff and have no clue about it.
                           *****
What I really miss sometimes are simple parameters, doing the half of
the work which I really like to have automated, not that expanding
ones.
And correct expanding compile time informations (without the need of
rtti) too!
                           *****

Regards
	Jörg



More information about the fpc-devel mailing list