On Dec 18, 2006, at 11:08 PM, David Balmain wrote:

I need to think a little more about this but a code generator seems
like the best way to go so +1.

While you were away I wrote one in Perl called "boilerplater.pl" and integrated it into KinoSearch. The implementation turned out to be somewhat more elaborate than I'd originally planned, because it parses all header files and builds a model of the entire object hierarchy before generating any code. However, once it was mostly finished, all of a sudden everything else got a lot easier. :)

Note that because this is a code generator which produces deterministic output directly from C source code, Perl is only required on the developer's system (and there are no dependencies other than Perl 5.6). I thought about using Ruby or Java, because I didn't want to appear partisan, but oh well. :) It could be re- implemented if need be, though there's a lot of the kind of text wrangling which is Perl's strong suit.

Here's some generated code, for the TopDocCollector class:

http://www.rectangular.com/svn/kinosearch/trunk/c_src/KinoSearch/ Search/TopDocCollector.r

The TopDocCollector.h header file which fed boilerplater.pl:

http://www.rectangular.com/svn/kinosearch/trunk/c_src/KinoSearch/ Search/TopDocCollector.h

The TopDocCollector C file, which makes use of a couple HitQueue methods:

http://www.rectangular.com/svn/kinosearch/trunk/c_src/KinoSearch/ Search/TopDocCollector.c

boilerplater.pl itself (POD documentation at the end)...

  http://www.rectangular.com/svn/kinosearch/trunk/devel/boilerplater.pl

If you change out every kino_, Kino_, KINO_ and KinoSearch for lucy_, Lucy, LUCY, and Lucy, that TopDocCollector code is basically what I'd like to see in our source repository.

Thoughts?

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/


Reply via email to