diff options
author | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2002-03-27 15:34:19 +0000 |
---|---|---|
committer | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2002-03-27 15:34:19 +0000 |
commit | 489ed36e225fbadf3618d9e338d158750347fa9f (patch) | |
tree | 606b59cd9a8da7b83da483f23d54a9fb8a21e53e /lib/sbin/c_file_processor.pl | |
parent | 358c188550d74a47d1fb817de7d9add766720f04 (diff) |
Reworked treatment of CCTK_DECLARE macros. Now the C file preprocessor
will put everything up to the closing bracket for a routine into a new block.
Also, the USE_CCTK macro is now appended directly to the CCTK_DECLARE macro.
There is no need anymore to use CCTK_NO_AUTOUSE_MACRO.
Also changed the way how parameters and arguments are used within the USE_CCTK
macros: now it's done by "(void) (parameter = 0);" which is better than
assigning the address of it to some dummy pointer.
This fixes problems where one had to parse for a possible return statement
at the end of the routine.
This fix closes PR Cactus/949.
Also did some perl code optimization and added grdoc headers for files
generated by the CST.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@2676 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/c_file_processor.pl')
-rw-r--r-- | lib/sbin/c_file_processor.pl | 104 |
1 files changed, 26 insertions, 78 deletions
diff --git a/lib/sbin/c_file_processor.pl b/lib/sbin/c_file_processor.pl index 303c80b0..b948a7f1 100644 --- a/lib/sbin/c_file_processor.pl +++ b/lib/sbin/c_file_processor.pl @@ -2,19 +2,14 @@ #/*@@ # @file c_file_processor.pl # @date Fri Jan 22 18:09:47 1999 -# @author Tom Goodale / Gerd Lanfermann +# @author Tom Goodale / Gerd Lanfermann / Thomas Radke # @desc -# Processes a c file replacing certain strings which can't be dealt -# with by the normal c preprocessor. +# Processes certain things within a C source file +# which can't be dealt with by the normal C preprocessor. # -# It also parses the C source and adds the USE macros, which perform -# a dummy assign. This avoid ugly warnings on some compilers. -# This auto adding was tested on all C-thorns and it worked. Since this -# does not match the full C syntax, there can pathological cases, where -# this script will not be able to put the USE stuff in the right place. -# There is a switch to turn this auto-adding off: place the string -# "CCTK_NO_AUTOUSE_MACRO" somewhere at the top (within a comment). -# Everything after will not be matched. +# This script puts everything after a DECLARE_CCTK macro +# until the end of the routine into a new block. +# It also fixes the function names for fortran wrappers. # @enddesc # @version $Header$ #@@*/ @@ -35,92 +30,46 @@ require "$fortran_name_file"; # print "# 1 $source_file_name\n"; #} -$checkfor1 = "DECLARE_CCTK_PARAMETERS"; -$addmacro1 = "USE_CCTK_PARAMETERS"; -$domacro1 = 0; -$done1 = 0; - -$checkfor2 = "DECLARE_CCTK_ARGUMENTS"; -$addmacro2 = "USE_CCTK_CARGUMENTS"; -$domacro2 = 0; -$done2 = 0; - +$closing_brackets = ''; +$routine = ''; $n_arg_braces = -3; -$skip = 0; -$skipstring = "CCTK_NO_AUTOUSE_MACRO"; - +# parse the file up to a ";\n" $/ = ";\n"; $* = 1; -$routine = ''; - -# parse the file up to a ";\n" while (<>) { # split in lines... and collect in routine; foreach $mline (split ("\n")) { - $routine .= $mline . "\n"; - - $skip = 1 if ($mline =~ /$skipstring/); - # skip one-line comments - # (note that this is still incomplete for C comments - + # (note that this is still incomplete for multi-line C comments - # it is not checked if some code follows after the closing '*/') - next if ($mline =~ m/^\s*\/\//); - next if ($mline =~ m/^\s*\/\*.*\*\//); - - # check if the DECLARE macros are found on a line - if ($mline =~ m/$checkfor2/) + if ($mline !~ m/^\s*\/\// && $mline !~ m/^\s*\/\*.*\*\/\s*$/) { - # remove the trailing semicolon (is already expanded by the macro) - if ($mline =~ m/$checkfor2(\s*;)/) + # check if the DECLARE macros are found on a line + if ($mline =~ s/(DECLARE_CCTK_(PARAMETERS|ARGUMENTS))(\s*;)?/$1 {/g) { - $routine =~ s/$checkfor2$1/$checkfor2/g; + $closing_brackets = "} /* closing bracket for $1 block */ " . $closing_brackets; + $n_arg_braces = -1; } - $domacro2 = 1; - $n_arg_braces = 0; - $trigger = 1; - } - if ($mline =~ m/$checkfor1/) - { - # remove the trailing semicolon (is already expanded by the macro) - if ($mline =~ m/$checkfor1(\s*;)/) + + # start counting braces if there has been a DECLARE macro + if ($closing_brackets) { - $routine =~ s/$checkfor1$1/$checkfor1/g; + $n_arg_braces-- while ($mline =~ m/(})/g); + $n_arg_braces++ while ($mline =~ m/({)/g); } - $domacro1 = 1; - $n_arg_braces = 0; - $trigger = 1; - } - # start counting braces if there has been a DECLARE_ - if ($trigger) - { - $n_arg_braces-- while ($mline =~ m/(})/g); - $n_arg_braces++ while ($mline =~ m/({)/g); + + $mline = "$closing_brackets$mline" if ($n_arg_braces == -1); } - if ($n_arg_braces == -1 && ! $skip) + $routine .= $mline . "\n"; + + if ($n_arg_braces == -1) { - # Start adding first macro, deal with "return }"first, "}" after - if ($domacro1) - { - if (! ($routine =~ s/([ \t\f]*)(return\s*\S*\s*}\s*)$/$1$addmacro1; $1$2/s)) - { - $routine =~ s/(}\s*$)/ $addmacro1; $1/s; - } - $domacro1 = 0; - } - # Start adding second macro - if ($domacro2) - { - if (! ($routine =~ s/([ \t\f]*)(return\s*\S*\s*}\s*)$/$1$addmacro2 $1$2/s)) - { - $routine =~ s/(}\s*$)/ $addmacro2 $1/s; - } - $domacro2 = 0; - } + $closing_brackets = ''; $n_arg_braces = -2; # call the fortran namefix routine/reset routine @@ -131,7 +80,6 @@ while (<>) } fixfnames ($routine); -$routine = ''; sub fixfnames |