flibs/tools(n) 1.0 "flibs"

NAME

flibs/tools - Modify program code

TABLE OF CONTENTS

    TABLE OF CONTENTS
    DESCRIPTION
    EXAMPLES
    COPYRIGHT

DESCRIPTION

The editcode program is a specialised preprocessor for Fortran code: its purpose is to transform the code according to certain simple rules:

It reads an input file called "editcode.inp" which should contain keywords and possibly parameters, steering the transformation of the code.

Here is a list of the keywords and their parameters:

Preconditions, postconditions and assertions are implemented as special comments:

 
    ! pre: x > 0.0
    ! post: x > 0.0
    ! assert: x > 0.0

If a condition is longer than one line, simply use & like any ordinary continuation line:

 
    ! assert: x > 0.0 .and. &
    !         y < 0.0

If the condition type is enabled, the condition is transformed into code like this:

 
if ( .not. ( &
    x > 0.0 .and. &
    y > 0.0 &
) then
    write(*,*) 'Assertion failed at line 10 in file myprog.f90:'
    write(*,*) 'x > 0.0 .and. &'
    write(*,*) 'y > 0.0'
endif

The program also handles a simple form of exceptions via try/catch statements:

 
    try
        ... code to handle the ordinary case ...
    catch
        ... code to handle an exception ...
    endtry

(Within a catch section you can use the routines of the exception_handling module)

Note:

To make this preprocessing facility flexible, it consists of a main program and a module that does the actual work:

EXAMPLES

The tests/tools directory contains several examples and a detailed explanation, but here is the input file editcode.inp for these examples:

 
INPUT-DIRECTORY   in
OUTPUT-DIRECTORY  out
ADD-CODE-START    "write(*,*) 'In __ROUTINE__ (__MODULE__)'"
ADD-CODE-END      "write(*,*) 'Leaving __ROUTINE__'"
ADD-CODE-STATEMENT "write(*,*) 'At __LINE__'"
ADD-USE            "use exceptions"
REPLACE-TYPE       "real"  real(dp)
REPLACE-STRING     X Y
ENABLE-IMPLICIT-NONE  yes
!
! Does this cause an error?
ENABLE-PRECONDITIONS

ENABLE-PRECONDITIONS yes

FILE              example.f90

!
! Now the check_init/check_reals example
!
CLEAR-ALL-SETTINGS

INPUT-DIRECTORY   in
OUTPUT-DIRECTORY  out
REPLACE-TYPE real type(checked_real)
ADD-USE "use check_reals"
ADD-CODE-STATEMENT "call check_assignment( __LINE__, '__FILE__' )"
!
! List of files to treat
!
FILE "check_init.f90"

While mainly meant to test the correct working of the program, it does in fact illustrate its capabilities. The README file contains more information.

COPYRIGHT

Copyright © 2008 Arjen Markus <arjenmarkus@sourceforge.net>