R++ based XML Generator.

Steven T. Hatton hattons at globalsymmetry.com
Sat Sep 3 08:18:03 UTC 2005

On Friday 02 September 2005 19:35, Steven T. Hatton wrote:
> I created an XML generator derived from the r++ DefalutVisitor.  Someone
> may find it modestly useful.  If nothing else, it might be useful as a
> cut-n-paste template for something that is actually useful.
> There are a few things commented out, and a few more that probably should
> be commented out.  If an attribute is commented out, or if the value
> parameter to sth::XmlTree::_setAttribute(name, value) is quoted, that means
> something wasn't working either in my code, or in r++.

I now have a function that creates a diagnostic element in the XML holding 
arbitrary text. I am pushing a description of any token that seems to be 
producing wrong results to a diagnostic element under the element 
representing the AST node where it appears.

What seems to be happening is that in AST nodes which have a member variable 
intended to hold a token stream index, but for which no corresponding token 
exists the variable holds garbage.

The ones I've identified so far are:


Something I did with some code I wrote to parse an ELF file was this:
//In a header file I did:
#ifndef ELF32_EHDR_H
#define ELF32_EHDR_H
#include "Types.h"

namespace sth {
  namespace elf32 {

    struct Elf32_Ehdr_base {
      unsigned char e_ident[EI_NIDENT];
      Elf32_Half    e_type;
      Elf32_Half    e_machine;
      Elf32_Word    e_version;
      Elf32_Addr    e_entry;
      Elf32_Off     e_phoff;
      Elf32_Off     e_shoff;
      Elf32_Word    e_flags;
      Elf32_Half    e_ehsize;
      Elf32_Half    e_phentsize;
      Elf32_Half    e_phnum;
      Elf32_Half    e_shentsize;
      Elf32_Half    e_shnum;
      Elf32_Half    e_shstrndx;
      static const Elf32_Ehdr_base Z;
    struct Elf32_Ehdr: Elf32_Ehdr_base { Elf32_Ehdr(); };

//Then in a source file I did:
#include "Elf32_Ehdr.h"

namespace sth {
  namespace elf32{

    const Elf32_Ehdr_base Elf32_Ehdr_base::Z = {};



I believe that is the code that actually worked.  If not, it's very close.  
Unfortunately, I yanked it because at the time, I reasoned that "I know what 
I'm doing, so I won't need this".  I'm not sure that was a good idea.

I'm not sure if there's anything wrong with the current r++ AST, or if I just 
don't understand it.  The approach shown above might be useful to someone if 
they do think the AST nodes should be zero-initialized.  A factory approach 
might also work.  Of course, they could always be initialized per instance 
when created.

> My code is here:
> http://baldur.globalsymmetry.com/open-source/org/kde/kdevelop/rxx/sth/

> All that the code currently does is create a QDomDocument and streams it to
> a std::ostream passed as a parameter to the constructor. This is an example
> of the XML generated:

> I find the default xml rendering provided by Mozilla to be a useful means
> of viewing the file.  KXMLEditor also works well.
> If I've accomplished nothing else, I've demonstrated that r++'s AST makes a
> very pretty dot graph:
> http://baldur.globalsymmetry.com/open-source/org/kde/kdevelop/rxx/doc/html/
> To get the really cool frames for the Doxygen output go here:
> http://baldur.globalsymmetry.com/open-source/org/kde/kdevelop/rxx/doc/html/


More information about the KDevelop-devel mailing list