XML Documentation for C++ Code

From RAD Studio
Jump to: navigation, search

Go Up to XML Compiler Output


Previous-generation C++ compilers can generate an XML file with the declarations from a C++ source file and the included headers. The information that is generated is similar to the information being displayed by the C++ Class Explorer, in the sense that both display information from the symbol table of the compiler.

To enable this feature, select Project > Options > C++ Compiler > Advanced and, under Other Options, add one of the command-line options listed below to the "Additional options to pass to the compiler" option.
To enable this feature on the command line, run the command-line compiler with one of the command-line options listed below.

The format (schema) of the XML file is described in Compiler XML Output Global Declarations.

Command-Line Options for XML Output

-Zx - Generate XML Output

The -Zx option prompts the compiler to generate an XML file of the symbols encountered while processing a C++ source file and its headers. For example, given the following source file (test.cpp), the -Zx option makes the compiler produce the XML file test.xml shown below:

test.cpp:

class TBase {
  int id;
};

class TDerived : public TBase {
  char *name;
};

test.xml:

<?xml version="1.0" encoding="utf-8"?>
<file name="test.cpp">
    <class name="TBase" visibility="public">
        <members>
            <field name="id" type="int" visibility="private" />
        </members>
    </class>
    <class name="TDerived" visibility="public">
        <ancestor name="TBase">
            <fieldref name="id" visibility="private" />
        </ancestor>
        <members>
            <field name="name" type="char *" visibility="private" />
        </members>
    </class>
</file>

You can append any combination of the following suboptions to the -Zx option to modify its behavior:

  • f: Skip base type members.
  • m: Emit macros.
  • p: Emit file and line position.

-Zxf - Skip Ancestor Information

When processing a class for XML output by default, the compiler generates information about members of the base types (ancestors) of that class. The f suboption instructs the compiler not to generate any information for base types. The following table illustrates how the suboption f changes the generated .xml for the test.cpp file.

test.xml without the f suboption:

<?xml version="1.0" encoding="utf-8"?>
<file name="test.cpp">
    <class name="TBase" visibility="public">
        <members>
            <field name="id" type="int" visibility="private" />
        </members>
    </class>
    <class name="TDerived" visibility="public">
        <ancestor name="TBase">
            <fieldref name="id" visibility="private" />
        </ancestor>
        <members>
            <field name="name" type="char *" visibility="private" />
        </members>
    </class>
</file>

test.xml with the f suboption:

<?xml version="1.0" encoding="utf-8"?>
<file name="test.cpp">
    <class name="TBase" visibility="public">
        <members>
            <field name="id" type="int" visibility="private" />
        </members>
    </class>
    <class name="TDerived" visibility="public">
        <members>
            <field name="name" type="char *" visibility="private" />
        </members>
    </class>
</file>

-Zxp - Generate Position Information

The p suboption instructs the compiler to include attributes describing the file and line of each declaration. The following table illustrates test.xml with the p suboption enabled.

test.xml with the p suboption:

<?xml version="1.0" encoding="utf-8"?>
<file name="test.cpp">
    <class name="TBase" visibility="public" file="test.cpp" line="1">
        <members>
            <field name="id" type="int" visibility="private" file="test.cpp" line="2" />
        </members>
    </class>
    <class name="TDerived" visibility="public" file="test.cpp" line="5">
        <ancestor name="TBase">
            <fieldref name="id" visibility="private" />
        </ancestor>
        <members>
            <field name="name" type="char *" visibility="private" file="test.cpp" line="6" />
        </members>
    </class>
</file>

See Also