[Kde-bindings] Deparser via XML/XSLT

Ashley Winters jahqueel at yahoo.com
Fri Jun 17 09:19:41 UTC 2005

Here's instructions on running my XML/deparser. I'll put details on the
blog tomorrow, but I wanted to throw out a quick HOWTO.

This is tested on Kubuntu with gcc 3.3.5. It will work with just about
any GCC3 version, but I haven't ever used GCC4.

Have Qt4 rc1 installed.

-- Install the following modules from CPAN:
XML::LibXML    (perl's interface to libxml2)
XML::LibXSLT   (perl's interface to libxslt -- duh)

-- Get the following files:
wget http://perlqt.sf.net/xml/deparse.pl
wget http://perlqt.sf.net/xml/deparse.xsl
wget http://perlqt.sf.net/xml/style.pl

-- At this point, have 100M disk-space free
echo '#include <QtGui/QtGui>' > qtgui.cpp
g++ -E -I/opt/qt4/include qtgui.cpp |
        perl -pe 's,/,!,g if /^# \d+ "/' > qtgui.i
g++ -fdump-translation-unit -c qtgui.i

-- At this point, have 512 megs of ram and some CPU cycles to burn
perl deparse.pl qtgui.i.tu

-- At this point, you'll have a big fat QtGui.xml file. Check it out.
Also, there's a qtgui.i.tu.parsed file which is the frozen AST.
Subsequent runs of deparse.pl will be much faster, since it will thaw()
the data into ram without parsing anything.

Now, here's the cool part. You can take the XML and reconstitute the
original header (to an impressive degree) using XSL. There are two ways
to see the result.

If you have a recent Mozilla/Firefox (or presumably IE6) and some ram
to burn, change line 2 of QtGui.xml to say:

<?xml-stylesheet type="text/xsl" href="deparse.xsl" ?>

And then File->Open QtGui.xml in your browser. It'll transform the XML
file back to a C++ header listing all the Qt classes.

If you don't want to abuse your XML/Web browser, you can use libxslt in
Perl to do the same thing with style.pl:

perl style.pl | less   # edit this script as needed

Ashley Winters

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Kde-bindings mailing list