ColdFrame: Extending

You may find it useful to use your own tagged values to control your own extensions to ColdFrame's code generation. It's only really straightforward to do this for generating additional Ada units; to change the standard generated code requires a deeper fix!

Basic scheme

You need (at least) one new stylesheet for each extension, and one master stylesheet to rule them all (including ColdFrame's standard ones).

The template for your extensions should take the form

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:output method="text"/>

  <!-- The overridable main template. -->
  <xsl:template match="domain">
    <xsl:apply-templates select="." mode="your-extension"/>
  </xsl:template>


  <!-- Your extension. -->
  <xsl:template match="domain" mode="your-extension">

    <!-- ... -->

  </xsl:template>

</xsl-stylesheet>

which allows you to test it on its own by, for example,

$ make -f $TOP/$COLDFRAME/Makefile-os CODEGEN_SCRIPT=your-extension.xsl Domain.ada

In order to combine with ColdFrame's code generation, so that all the generated Ada ends up in the .gen subdirectory, you need a combining script:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:import href="generate-ada.xsl"/>
  <xsl:import href="your-extension.xsl"/>

  <xsl:strip-space elements="*"/>
  <xsl:output method="text"/>

  <xsl:template match="domain">
    <xsl:apply-templates select="." mode="coldframe"/>
    <xsl:apply-templates select="." mode="your-extension"/>
  </xsl:template>

</xsl:stylesheet>

and then you can say

$ make -f $TOP/$COLDFRAME/Makefile-os CODEGEN_SCRIPT=combined-codegen.xsl Domain.gen

It's best to put your extensions after ColdFrame; if you generate a proper body which replaces ColdFrame's default you need it to be later in the output, because gnatchop keeps the last unit it sees.

This should be easily extendable to multiple extensions. Clearly it will be best if they don't interact!

Practicalities

Where are these scripts going to be?

The xsl:import element's href attribute allows you to specify absolute and relative paths, but doesn't (I think) allow you to use environment variables.

Without any path information, as above, the scripts are all expected to be in the same place as combined-codegen.xsl. So one approach would be to copy all of ColdFrame's scripts and all of your extensions to the same place and specify that:

$ make -f $TOP/$COLDFRAME/Makefile-os CODEGEN_SCRIPT=/my/script/dir/combined-codegen.xsl Domain.gen

You can also specify CODEGEN_SCRIPT as an environment variable.

Efficiency

Things will run quicker if your extension can do a simple one-off check to see whether there's anything at all of interest in the domain.


Simon Wright