[fpc-devel] Need advice for refactoring

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Jul 17 02:36:26 CEST 2010


Since some time I'm trying to separate the syntax from the semantics 
processing in the parser. It turned out to be quite complicated, so that 
I want to use some methodology. (Yes, I've been warned ;-)

For profiling and debugging I want to have both the old and new code in 
the same executable file, so that a commandline option or environment 
variable can be used to select which "version" to use. Is this feasable, 
WRT the invocation of fpc with e.g. the test suite? How would you do it?

Furthermore I have no clue how to use new compiler at all. Do I have to 
rebuild fpc, or how else is the fpc executable (or link?) related to 
concrete (machine/target specific) compilers?


The separation shall be done in multiple steps. In the first step I'll 
enclose all semantical code into begin-end, so that it can be easily 
hidden (folded) in the Lazarus IDE. Later these blocks shall be extended 
into

   if cond then
     new_proc
   else
   begin
     [old code, also copied into new_proc()]
   end;

This has the advantage over $IF... that the IDE allows to navigate to 
everything in both if-else branches. It also should allow to apply 
patches (from updated trunk), to some degree, because the code sequence 
is not much modified.

The new_proc procedures will be local subroutines first, which can share 
the local variables of the enclosing parse_... procedure. Later these 
subroutines will be moved into different units, where they finally are 
exchangable by changing the searchpath. Here again it's helpful to view 
both versions in different editor windows, side by side.

For first results see the dodi/parser_rewrite branch.


Perhaps I missed more issues? Any hints are welcome :-)

DoDi




More information about the fpc-devel mailing list