Avatox (Ada, Via Asis, To Xml) is an application that traverses one or more Ada compilation units and outputs the ASIS representation of the unit(s) as an XML document. The resulting XML document(s) can then have an XSL stylesheet applied in turn.

Avatox is invoked with the name of the unit along with "-I" directives to specify the directories on which it depends, with the output optionally being directed to a file (via "-o" option).

Here's a brief excerpt, as generated by:

avatox avatox.adb -Imckae -I$GNAT/include/asis

<A_DECLARATION pedigree="asis" startLine="47" endLine="299" startCol="1" endCol="11">
 <A_PROCEDURE_BODY_DECLARATION pedigree="asis" startLine="47" endLine="299" startCol="1" endCol="11">
 </A_PROCEDURE_BODY_DECLARATION>
 <A_DEFINING_NAME pedigree="asis" startLine="47" endLine="47" startCol="11" endCol="16">
  <A_DEFINING_IDENTIFIER pedigree="asis" name="Avatox" startLine="47" endLine="47" startCol="11" endCol="16"/>
 </A_DEFINING_NAME>

To use the canonical XML style for ASIS element naming, adding the "-x" switch adjusts capitalization and removes underscores, altering the previous excerpt to look like this:

<aDeclaration pedigree="asis" startLine="47" endLine="299" startCol="1" endCol="11">
 <aProcedureBodyDeclaration pedigree="asis" startLine="47" endLine="299" startCol="1" endCol="11">
 </aProcedureBodyDeclaration>
 <aDefiningName pedigree="asis" startLine="47" endLine="47" startCol="11" endCol="16">
  <aDefiningIdentifier pedigree="asis" name="Avatox" startLine="47" endLine="47" startCol="11" endCol="16"/>
 </aDefiningName>

     

The structure of the output XML is documented in the Avatox XML Format summary.

There are a number of other Avatox options for collecting and processing units on which dependencies exist, for indicating where to write the generated XML files, and to configure XSL transformations. See the Avatox User Guide for complete information.

What is Avatox good for?

By obtaining an XML representation of the source code syntax, one can apply XML-based querying and analysis tools to it. (The XPath In Ada distribution contains a test program one can use to query XML documents.)

  • Find all string literals that appear in a variable declaration:

    //A_DECLARATION[A_VARIABLE_DECLARATION]/descendant::A_STRING_LITERAL/@literal

  • Find every assignment statement:

    //AN_ASSIGNMENT_STATEMENT

Given that the Avatox XML representation of the source code comprehensively represents the content and layout of the source code, there's nothing stopping one from developing a utility to reconstitute the Ada source from the XML.

Given that, XSLT transformations become available to modify the Avatox XML to produce a modified version of the original program. And the capability to apply XSL transformations to the Avatox XML files is now embedded within Avatox itself.

An Avatox XML compiler could be developed (although it might use an Ada source representation as an intermediate language :-).

If a converter for a Language Other Than Ada (LOTA) or a subset of it could be developed that generated Avatox conformant XML, applications written in a LOTA could be converted into Ada.

Source Code Generation: axf2ada

Included in the avatox/transforms subdirectory is an in-development version of axf2ada.xsl, an XSL stylesheet that generates Ada source code from AXF (Avatox Xml Format) documents.

This version of axf2ada is "pre-alpha", i.e., it is incomplete and not yet ready for production use. It can demonstrate, though, the regeneration of the Avatox source code from Avatox' AXF representation. Avatox' AXF representation was created by invoking Avatox as follows:

avatox -a -I mckae -I strings_edit_subset -I /opt/gnat-gpl-2006/include/asis -o avatox_code.axf *.ad[bs]

The code was then regenerated with the aid of the xalan stylesheet processor:

xalan -in avatox_code.axf -xsl transforms/axf2ada.xsl -out avatox_regen.ada

The resulting Ada code was then gnatchopped into separate files and verified against the original code that it was an exact functional match. (The verification of Avatox source code regeneration was done by stripping out all comments, pretty printing the original and regenerated code with gnatpp, and then comparing the resulting files for functional equivalence.)

Here is a zipped in-work version of just axf2ada. (It is zipped so that your browser won't try to execute it.) This link will be periodically updated as new templates and fixes are added.

Known axf2ada Issues
  • Comments are not handled well. Some are omitted, others show up near their original location, but not in the same exact position.
  • When an AXF structural or semantic element is encountered for which no XSL template has been defined, the string "NYH:" and the name of the element is output. This assists in flagging those elements for which templates still need to be created.
  • Not an axf2ada problem per se, but some XSL transformation engines that are not fully conformant to the XSL standard are unable to process axf2ada.xsl. Among those that do correctly process axf2ada are Xalan and the OrangeVolt EclipseXSLT plug-in for Eclipse. It is known that libxslt 1.1.15 fails to conform and so cannot perform an axf2ada transformation (which is ironic since that is what is built into Avatox).
Current Status of Avatox - Version 1.8

Changes since 1.7:

  • Fixed a problem with private parts of various kinds of units not being recognized as private.

  • Fixed a letter casing problem with rep specs.

  • Numerous upgrades to the AXF2Ada stylesheet.

Reports of errors or suggested enhancements are appreciated.

 

 
 
 

©2007 McKae Technologies