fb-doc: auto-generate documentation from FB source

User projects written in or related to FreeBASIC.
Post Reply
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

fb-doc: auto-generate documentation from FB source

Post by TJF »

In common programming languages and integrated development environments it's state-of-the-art to write the documentation in the source code files. The documentation context is placed in dedicatet comment blocks and some tools are used to extract it from the source code and auto-generate the documentation in different output formats, like ie pdf or html. The keywords of the documentation are auto linked. The format, a glossary and other standard elements are auto-generated.

Unfortunately there's no similar tool for FB source code yet. That's why the fb-doc project gets started. It supports the auto-generation of documentation from FB source using well developed, existing standard tool chains like GTK-Doc or Doxygen.

How it works:

fb-doc is the source code of a command line tool and has to be compiled first. The executable is usually started in the source code folder of a FB project. There it creates two new folders ../doc and ../doc/c_src (if not present) and it scans the FB files (*.bas and *.bi). In the c_src folder a set of pseudo C code files is created similar to the FB source files (.bas gets .c, .bi gets .h). This pseudo C code contains all the documentation relevant stuctures. These are snippets like empty UNIONs, TYPEs and SUBs/FUNCTIONs. Also all FB comments are exported to the pseudo code, unless the comments are marked as private with a '~' character (like '~ or /'~ ... '/). Then the pseudo C code can be used to auto-generate the documentation using standard tools.

Of course, this implements that the documentation is in C syntax. Ie
  • DECLARE FUNCTION abc (BYVAL xyz AS INTEGER) AS SHORT
gets
  • short abc (int xyz);
This may be a downside for clean FB projects. (I guess there is a way to work around with Doxygen, but I didn't check it.) On the other hand it's an welcome side effect if the documetation is for a library that should be combined with other C libraries (ie like GooData).

Example

This documentation for GooData (developer snapshot) is generated with fb-doc and GTK-Doc. Ie the subsection GooAxis is generated by the following FB code

Code: Select all

'/**
 '* goo_axis_new:
 '* @Parent: the parent item, or %NULL. If a parent is specified, it will assume
 '*  ownership of the item, and the item will automatically be freed when it is
 '*  removed from the parent. Otherwise call g_object_unref() to free it.
 '*   @Back: the background box to connect the axis to (a #GooCanvasRect, #GooCanvasImage,
 '*          #GooCanvasGroup, ...). Note: to set the axis position and size, the properties
 '*          #GooCanvasItemSimple:x, #GooCanvasItemSimple:y, #GooCanvasItemSimple:width and
 '*          #GooCanvasItemSimple:height will be red (and therefore must be set in the
 '*          background box item).
 '*   @Text: the label text for the axis
 '*  @Modus: the position and type (like %GOO_AXIS_SOUTH or %GOO_GRIDAXIS_SOUTH, ...)
 '*    @...: optional pairs of property names and values, and a terminating %NULL.
 '*
 '* Creates a new axis item.
 '*
 '* Returns: (transfer full): a new axis item.
 '**/
FUNCTION goo_axis_new CDECL( _
  BYVAL Parent AS GooCanvasItem PTR, _
  BYVAL Back AS GooCanvasItem PTR, _
  BYVAL Text AS gchar PTR, _
  BYVAL Modus AS GooAxisType, _
  ...) AS GooAxis PTR

' ...
The source contains the documentation context in C syntax, as needed for the doc-tools. Each line is separated by an ' so that it doesn't bother fbc compiling. Alternatively a /' ... '/ comment block can be used.

The project is in an early stage. There're no comments in the code yet, and the FB keywords have to be in upper-case letters (can be auto-transformed by FBeauty). But hopefully it's good enough for first user tests.

Find the latest version on this download page
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

fb-doc version 0.2 out now

Post by TJF »

Check the new self-hosted documentation online. It contains a tutorial and detailed information about the source code, including caller / callee graphs (autogenerated by the tool-chain fb-doc / Doxygen / GraphViz).

Graph examples:

An include graph
Image

A caller graph for function parseListNam
Image

New features:
  • completely renewed code base
  • help and version information
  • complete translation of all blocks (TYPE / UNION)
  • support for non-case-sensitive FB keywords
  • operating on files or pipes (input and output)
  • walking through FB source trees
  • variable target path
  • recursiv scanning of subfolders
  • fully Doxygen support
  • Geany mode for generating customized templates
  • four inbuild emitters (C source, Templates for gtk-doc or Doxygen, Function names)
  • interface for external emitter plugins
  • self-hosted documentation and tutorial (including caller / callee graphs)
Download Have fun!
Post Reply