The machinery drift uses to intercept calls to Grid_releaseBlkPtr is lacking in
sophistication, and as such can put some unwanted constraints on the code base.
The technique used is to declare a preprocessor #define in Flash.h
to expand occurrences of Grid_releaseBlkPtr to something larger that includes
__FILE__ and __LINE__. This is how drift is able to
correlate calls to Grid_releaseBlkPtr with the originating line of
source code. Unfortunately this technique places a very specific restriction on the
code once drift is enabled. The trouble comes from the types of source lines that
may refer to a subroutine without calling it. The primary offender being use
statements with only clauses listing the module members to import into scope.
Because macro expansion is dumb with respect to context, it will expand occurrences
of Grid_releaseBlkPtr in these use statements, turning them into
syntactic rubbish. The remedy for this issue is to make sure the line
#include "Flash.h" comes after all statements involving
Grid_releaseBlkPtr but not calling it, and before all statements that
are calls to Grid_releaseBlkPtr. In practice this is quite easy. With
only one subroutine per file, there will only be one line like:
use Grid_interface, only: ..., Grid_releaseBlkPtr, ...
and it will come before all calls to Grid_releaseBlkPtr, so just move
the #include "Flash.h" after the use statements. The following is an example:
Incorrect |
Correct |
#include "Flash.h"
subroutine Flash_subroutine()
use Grid_interface, only: Grid_releaseBlkPtr
implicit none
[...]
call Grid_releaseBlkPtr(...)
[...]
end subroutine Flash_subroutine
|
subroutine Flash_subroutine()
use Grid_interface, only: Grid_releaseBlkPtr
implicit none
#include "Flash.h"
[...]
call Grid_releaseBlkPtr(...)
[...]
end subroutine Flash_subroutine
|
If such a solution is not possible because no separation between all use
and call statements exists, then there are two remaining courses of action
to get the source file to compile. One, hide these calls to Grid_releaseBlkPtr
from drift by forceably disabling the macro expansion. To do so, just add the
line #undef Grid_releaseBlkPtr after #include "Flash.h". The
second option is to carry out the macro expansion by hand. This also requires
disabling the macro with the undef just mentioned, but then also rewriting each
call to Grid_releaseBlkPtr just as the preprocessor would. Please consult
Flash.h to see the text that gets substituted in for Grid_releaseBlkPtr.