Boost logo

Boost :

From: Hartmut Kaiser (hartmutkaiser_at_[hidden])
Date: 2003-01-15 11:03:44


Vincent Finn wrote:

> >>I was talking to you on the boost newsgroup about spirit
> being slow to
> >>compile Here is a standalone section of code, it'll compile but you
> >>can't do anything with it The compile takes about 15 mins on my
> >>machine (We are using spirit for a second file but that is
> smaller and
> >>only takes a minute or two)
[snip]

> I'll give it a go :-)

There is something you can do additionally, I think.

The large compile times result from the tight coupling of all your
Spirit grammars, so that these couldn't be compiled separately (as far
as I understood it). To overcome this problem you have to decouple the
use of a grammar from it's instantiation. I've solved this through a
small helper generator template function like the following:

    // parse the grammar and return the resulting parse tree
    template <typename IteratorT>
    boost::spirit::parse_info<IteratorT>
    parse_grammar (IteratorT const &first, IteratorT const &last);

This declaration you should make visible to the code, which _uses_ the
grammar. There you have to replace your call to

    boost::spirit::parse(first, last) --> parse_grammar(first, last);

The definition of the function parse_grammar has to look like the
following

    template <typename IteratorT>
    boost::spirit::parse_info<IteratorT>
    parse_grammar (IteratorT const &first, IteratorT const &last)
    {
        return boost::spirit::parse(first, last);
    }

and this definition you can put into a separate compilation unit. The
only problem left is, that you have to instantiate the correct
parse_grammar function explicitely with the iterator type, you've used,
maybe like the following:

    template boost::spirit::parse_info<char const *>
    parse_grammar (char const * const &first, char const * const &last);

Certainly this explicit instantiation should go into the second
compilation unit.
Hope this helps.

Regards Hartmut

BTW this method works well for me already in the ongoing Spirit based C
preprocessor sample.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk