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 | |
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
-rw-r--r-- | lib/sbin/CST | 68 | ||||
-rw-r--r-- | lib/sbin/CSTUtils.pl | 8 | ||||
-rw-r--r-- | lib/sbin/CreateFunctionBindings.pl | 1261 | ||||
-rw-r--r-- | lib/sbin/CreateImplementationBindings.pl | 145 | ||||
-rw-r--r-- | lib/sbin/CreateParameterBindings.pl | 518 | ||||
-rw-r--r-- | lib/sbin/GridFuncStuff.pl | 24 | ||||
-rw-r--r-- | lib/sbin/c_file_processor.pl | 104 | ||||
-rw-r--r-- | lib/sbin/create_c_stuff.pl | 293 | ||||
-rw-r--r-- | lib/sbin/create_fortran_stuff.pl | 108 | ||||
-rw-r--r-- | lib/sbin/output_config.pl | 27 |
10 files changed, 988 insertions, 1568 deletions
diff --git a/lib/sbin/CST b/lib/sbin/CST index 42781521..c02737b8 100644 --- a/lib/sbin/CST +++ b/lib/sbin/CST @@ -6,7 +6,7 @@ # @desc # Parses the the configuration files for thorns. # @enddesc -# @version $Header: /mnt/data2/cvs2svn/cvs-repositories/Cactus/lib/sbin/CST,v 1.47 2001-09-16 15:35:22 allen Exp $ +# @version $Header: /mnt/data2/cvs2svn/cvs-repositories/Cactus/lib/sbin/CST,v 1.48 2002-03-27 15:34:17 tradke Exp $ #@@*/ # Global parameter to track the number of errors from the CST @@ -74,7 +74,6 @@ require "$sbin_dir/ProcessConfiguration.pl"; require "$sbin_dir/create_c_stuff.pl"; require "$sbin_dir/create_fortran_stuff.pl"; require "$sbin_dir/GridFuncStuff.pl"; -require "$sbin_dir/output_config.pl"; require "$sbin_dir/ImpParamConsistency.pl"; require "$sbin_dir/CSTUtils.pl"; require "$sbin_dir/MakeUtils.pl"; @@ -99,10 +98,7 @@ print "Parsing configuration files...\n"; $configuration_database = &CreateConfigurationDatabase(%thorns); #$debug_configuration = 1; -if($debug_configuration) -{ - &PrintConfigurationDatabase($configuration_database); -} +&PrintConfigurationDatabase($configuration_database) if($debug_configuration); # Restrict the rest of this to thorns with source @@ -113,10 +109,7 @@ print "Parsing interface files...\n"; %interface_database = &create_interface_database(scalar(keys %system_database), %system_database, %source_thorns); #$debug_interface = 1; -if($debug_interface) -{ - &print_interface_database(%interface_database); -} +&print_interface_database(%interface_database) if($debug_interface); # Parse the parameter.ccl files print "Parsing parameter files...\n"; @@ -129,44 +122,35 @@ print "Parsing schedule files...\n"; print "Checking consistency...\n"; %parameter_database = &CheckImpParamConsistency(scalar(keys %interface_database), %interface_database, %parameter_database); -if($debug_parameters) -{ - &print_parameter_database(%parameter_database); -} +&print_parameter_database(%parameter_database) if($debug_parameters); #$debug_interface = 1; -if($debug_interface) -{ - &print_interface_database(%interface_database); -} +&print_interface_database(%interface_database) if($debug_interface); #$debug_schedule = 1; -if($debug_schedule) -{ - &print_schedule_database(%schedule_database); -} +&print_schedule_database(%schedule_database) if($debug_schedule); # Create all the bindings print "Creating Thorn-Flesh bindings...\n"; &CreateBindings($bindings_dir, \%parameter_database, \%interface_database, \%schedule_database); # Create header file of active thorns for the code -@activethornsheader = &CreateActiveThornsHeader(%source_thorns); -&OutputFile("$bindings_dir/include/", "thornlist.h", @activethornsheader); +$activethornsheader = &CreateActiveThornsHeader(%source_thorns); +&WriteFile("$bindings_dir/include/thornlist.h", \$activethornsheader); # Create define file of active thorns -@definethornsheader = &CreateDefineThornsHeader(%source_thorns); -&OutputFile("$bindings_dir/include/", "cctk_DefineThorn.h", @definethornsheader); +$definethornsheader = &CreateDefineThornsHeader(%source_thorns); +&WriteFile("$bindings_dir/include/cctk_DefineThorn.h", \$definethornsheader); # Create define file for this thorn -@definethisthornheader = &CreateDefineThisThornHeader(%source_thorns); -&OutputFile("$bindings_dir/include/", "definethisthorn.h", @definethisthornheader); +$definethisthornheader = &CreateDefineThisThornHeader(%source_thorns); +&WriteFile("$bindings_dir/include/definethisthorn.h", \$definethisthornheader); # Create the header files used by the thorns &BuildHeaders($cctk_home,$bindings_dir,%interface_database); # Finally (must be last), create the make.thornlist file. -@make_thornlist = &CreateMakeThornlist(\%thorns, \%interface_database); +$make_thornlist = &CreateMakeThornlist(\%thorns, \%interface_database); # Stop the make process if there were any errors if ($CST_errors) @@ -189,7 +173,7 @@ if ($CST_errors) exit(1); } -&OutputFile($config_dir, "make.thornlist", @make_thornlist); +&WriteFile("$config_dir/make.thornlist", \$make_thornlist); print "CST finished.\n"; exit; @@ -389,7 +373,7 @@ sub CreateMakeThornlist $thorn_linklist .= ' ' . &CreateThornLinkList($thorns, $interface_database); - return ("$thornlist", "", "$thorn_linklist", "", "$config_thornlist", ""); + return ($thornlist . "\n" . $thorn_linklist . "\n" . $config_thornlist); } @@ -511,7 +495,7 @@ sub CreateActiveThornsHeader $header .= "\"\"};\n\n"; $header .= "static int nthorns = $nthorns;\n\n"; - return ("$header", ""); + return ($header); } @@ -552,7 +536,7 @@ sub CreateDefineThornsHeader $header .= "#define \U$2"."_"."\U$3\E\n"; } - return ("$header", ""); + return ($header); } @@ -596,7 +580,7 @@ sub CreateDefineThisThornHeader $header .= "#endif\n\n"; } - return ("$header", ""); + return ($header); } @@ -618,7 +602,6 @@ sub CreateDefineThisThornHeader sub CreateBindings { my($bindings_dir, $rhparameter_db, $rhinterface_db, $rhschedule_db) = @_; - my($start_dir); # Create the bindings directory if it doesn't exist. if(! -d $bindings_dir) @@ -626,9 +609,6 @@ sub CreateBindings mkdir("$bindings_dir", 0755) || die "Unable to create $bindings_dir"; } - # Remember where we started. - $start_dir = `pwd`; - # Create the bindings for the subsystems. print " Creating implementation bindings...\n"; &CreateImplementationBindings($bindings_dir, $rhparameter_db, $rhinterface_db); @@ -642,14 +622,6 @@ sub CreateBindings &CreateFunctionBindings($bindings_dir, $rhinterface_db); # Place an appropriate make.code.defn in the bindings directory. - chdir $bindings_dir; - - $dataout = "SRCS = \n"; - $dataout .= "SUBDIRS = Functions Implementations Parameters Variables Schedule\n"; - &WriteFile("make.code.defn",\$dataout); - - # Go back to where we started. - chdir $start_dir; - + $dataout = "SUBDIRS = Functions Implementations Parameters Variables Schedule"; + &WriteFile("$bindings_dir/make.code.defn",\$dataout); } - diff --git a/lib/sbin/CSTUtils.pl b/lib/sbin/CSTUtils.pl index 4a1dc2be..bb0d22d4 100644 --- a/lib/sbin/CSTUtils.pl +++ b/lib/sbin/CSTUtils.pl @@ -184,11 +184,9 @@ sub WriteFile $data_in = ""; if (-e $filename) { - open(IN, "<$filename"); - while (<IN>) - { - $data_in .= $_; - } + open(IN, "< $filename"); + $data_in = join ('', <IN>); + close IN; } if ($$rdata ne $data_in) diff --git a/lib/sbin/CreateFunctionBindings.pl b/lib/sbin/CreateFunctionBindings.pl index 24f3b825..53923c43 100644 --- a/lib/sbin/CreateFunctionBindings.pl +++ b/lib/sbin/CreateFunctionBindings.pl @@ -3,10 +3,10 @@ # @file CreateFunctionBindings.pl # @date Sat Feb 10 2001 # @author Gabrielle Allen -# @desc -# +# @desc +# # @enddesc -# @version $Id$ +# @version $Id$ #@@*/ @@ -14,15 +14,9 @@ # @routine CreateFunctionBindings # @date Sat Feb 10 2001 # @author Gabrielle Allen -# @desc +# @desc # Creates bindings for thorn provided functions -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub CreateFunctionBindings @@ -30,11 +24,14 @@ sub CreateFunctionBindings my($bindings_dir, $rhinterface_db) = @_; my($dataout); my($function_db); + my($registerfiles); -# Create Function Database + $registerfiles = 'IsOverloaded.c OverloadThorns.c FortranThornFunctions.c DummyThornFunctions.c RegisterThornFunctions.c'; + + # Create Function Database $function_db = &FunctionDatabase($rhinterface_db); -# Create directories + # Create directories if(! -d $bindings_dir) { mkdir("$bindings_dir", 0755) || die "Unable to create $bindings_dir"; @@ -43,86 +40,65 @@ sub CreateFunctionBindings chdir $bindings_dir; - if(! -d "Functions") + if(! -d 'Functions') { - mkdir("Functions", 0755) || die "Unable to create Functions directory"; + mkdir('Functions', 0755) || die 'Unable to create Functions directory'; } - if(! -d "include") + if(! -d 'include') { - mkdir("include", 0755) || die "Unable to create include directory"; + mkdir('include', 0755) || die 'Unable to create include directory'; } -# Create ThornOverloadables.h - chdir "include"; + # Create ThornOverloadables.h $dataout = &ThornOverloadables($function_db); - &WriteFile("ThornOverloadables.h",\$dataout); - chdir $bindings_dir; + &WriteFile('include/ThornOverloadables.h',\$dataout); -# Create DummyThornFunctions.c - chdir "Functions"; + # Create DummyThornFunctions.c $dataout = &DummyThornFunctions($function_db); - &WriteFile("DummyThornFunctions.c",\$dataout); - chdir $bindings_dir; + &WriteFile('Functions/DummyThornFunctions.c',\$dataout); -# Create OverloadThorns.c - chdir "Functions"; + # Create OverloadThorns.c $dataout = &OverloadThorns(); - &WriteFile("OverloadThorns.c",\$dataout); - chdir $bindings_dir; + &WriteFile('Functions/OverloadThorns.c',\$dataout); -# Create FortranThornFunctions.c - chdir "Functions"; + # Create FortranThornFunctions.c $dataout = &FortranThornFunctions($function_db); - &WriteFile("FortranThornFunctions.c",\$dataout); - chdir $bindings_dir; + &WriteFile('Functions/FortranThornFunctions.c',\$dataout); -# Create Thorn Include Prototypes - chdir "include"; - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + # Create Thorn Include Prototypes + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $filename = $thorn."_Prototypes.h"; $dataout = &ThornIncludes($thorn,$function_db,$rhinterface_db); - &WriteFile($filename,\$dataout); + &WriteFile("include/${thorn}_Prototypes.h",\$dataout); } - chdir $bindings_dir; -# Create Master Include Prototypes - chdir "include"; - $filename = "cctk_FunctionAliases.h"; + # Create Master Include Prototypes $dataout = &ThornMasterIncludes($rhinterface_db); - &WriteFile($filename,\$dataout); - chdir $bindings_dir; + &WriteFile('include/cctk_FunctionAliases.h',\$dataout); -# Create THORN_Register.c - chdir "Functions"; - $registerfiles = ""; - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + # Create THORN_Register.c + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $filename = $thorn."_Register.c"; + $filename = "${thorn}_Register.c"; $dataout = &RegisterThornFunctions($thorn,$function_db,$rhinterface_db); - &WriteFile($filename,\$dataout); + &WriteFile("Functions/$filename",\$dataout); $registerfiles .= " $filename"; } - chdir $bindings_dir; -# Create Master registration file RegisterThornFunctions.c - chdir "Functions"; + # Create Master registration file RegisterThornFunctions.c $dataout = &RegisterAllFunctions($rhinterface_db); - &WriteFile("RegisterThornFunctions.c",\$dataout); - chdir $bindings_dir; + &WriteFile('Functions/RegisterThornFunctions.c',\$dataout); -# Create IsOverloaded functions - chdir "Functions"; + # Create IsOverloaded functions $dataout = &IsOverloadedBindings($function_db); - &WriteFile("IsOverloaded.c",\$dataout); - chdir $bindings_dir; + &WriteFile('Functions/IsOverloaded.c',\$dataout); + + # Create make.code.defn + $dataout = "SRCS = $registerfiles"; + &WriteFile("Functions/make.code.defn",\$dataout); -# Create make.code.defn - chdir "Functions"; - $dataout = "\nSRCS = IsOverloaded.c OverloadThorns.c FortranThornFunctions.c DummyThornFunctions.c RegisterThornFunctions.c $registerfiles\n\n"; - &WriteFile("make.code.defn",\$dataout); chdir $start_dir; return; @@ -133,116 +109,78 @@ sub CreateFunctionBindings # @routine IsOverloadedBindings # @date Tue Feb 20 2001 # @author Gabrielle Allen -# @desc +# @desc # Code for returning number of times a function has been overloaded. -# This should be done in a better way, and include flesh overloaded +# This should be done in a better way, and include flesh overloaded # functions -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub IsOverloadedBindings { my($function_db) = @_; - my($dataout,$line,@data); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header IsOverloaded.c\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Query how many times a function is overloaded\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - - $line = "\#include <stdlib.h>\n\n"; - push(@data, $line); - $line = "\#include \"cctk_Flesh.h\"\n\n"; - push(@data, $line); - $line = "\#include \"cctk_FortranString.h\"\n\n"; - push(@data, $line); - - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + push(@data, '/*@@'); + push(@data, ' @file IsOverloaded.c'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Query how many times a function is overloaded'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include <stdlib.h>'); + push(@data, ''); + push(@data, '#include "cctk_Flesh.h"'); + push(@data, '#include "cctk_FortranString.h"'); + push(@data, ''); + + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) { - $line = "int CCTKBindings_Overload$function(void *);\n"; - push(@data, $line); + push(@data, "int CCTKBindings_Overload$function(void *);"); } } - $line = "int CCTK_IsOverloaded(const char *function);\n"; - push(@data, $line); - - $line = "int CCTK_IsOverloaded(const char *function)\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - $line = " int retval=0;\n\n"; - push(@data, $line); - $line = " const char *cctk_dummy_string; /* avoid warnings */\n\n"; - push(@data, $line); - $line = " cctk_dummy_string=function; /* avoid warnings */\n\n"; - push(@data, $line); - - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + push(@data, 'int CCTK_IsOverloaded(const char *function);'); + push(@data, 'int CCTK_IsOverloaded(const char *function)'); + push(@data, '{'); + push(@data, ' int retval = 0;'); + push(@data, ''); + push(@data, ' (void) (function + 0); /* avoid warnings */'); + push(@data, ''); + + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) { - $line = " if (strcmp(function,\"$function\")==0)\n"; - push(@data, $line); - $line = " {\n"; - push(@data, $line); - $line = " retval = CCTKBindings_Overload$function(NULL);\n"; - push(@data, $line); - $line = " }\n\n"; - push(@data, $line); + push(@data, " if (strcmp(function, \"$function\") == 0)"); + push(@data, ' {'); + push(@data, " retval = CCTKBindings_Overload$function(NULL);"); + push(@data, ' }'); + push(@data, ''); } } - $line = " return retval;\n"; - push(@data, $line); - $line = "}\n\n\n"; - push(@data, $line); + push(@data, ' return retval;'); + push(@data, '}'); + push(@data, ''); # Put fortran binding here for the moment - $line = "void CCTK_FCALL CCTK_FNAME(CCTK_IsOverloaded)\n"; - push(@data, $line); - $line = " (int *ret, ONE_FORTSTRING_ARG);\n"; - push(@data, $line); - $line = "void CCTK_FCALL CCTK_FNAME(CCTK_IsOverloaded)\n"; - push(@data, $line); - $line = " (int *ret, ONE_FORTSTRING_ARG)\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - $line = " ONE_FORTSTRING_CREATE(name);\n"; - push(@data, $line); - $line = " *ret = CCTK_IsOverloaded(name);\n"; - push(@data, $line); - $line = " free(name);\n"; - push(@data, $line); - $line = "}\n"; - push(@data, $line); - - - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - - return $dataout; + push(@data, 'void CCTK_FCALL CCTK_FNAME(CCTK_IsOverloaded) (int *ret, ONE_FORTSTRING_ARG);'); + push(@data, 'void CCTK_FCALL CCTK_FNAME(CCTK_IsOverloaded) (int *ret, ONE_FORTSTRING_ARG)'); + push(@data, '{'); + push(@data, ' ONE_FORTSTRING_CREATE(name);'); + push(@data, ' *ret = CCTK_IsOverloaded(name);'); + push(@data, ' free(name);'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + + return join ("\n", @data); } @@ -250,366 +188,252 @@ sub IsOverloadedBindings # @routine ThornOverloadables # @date Sat Feb 10 # @author Gabrielle Allen -# @desc +# @desc # Create include file for thorn function overloads -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub ThornOverloadables { my($function_db) = @_; - my($dataout,$line,@data); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header ThornOverloadables.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " The overloadable functions from thorns\n"; - push(@data, $line); - $line = " See OverloadMacros.h to see how to use these.\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#ifdef OVERLOADABLE_CALL\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_CALL\n"; - push(@data, $line); - $line = "\#endif\n\n"; - push(@data, $line); - $line = "\#ifdef OVERLOABLE_PREFIX\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_PREFIX\n"; - push(@data, $line); - $line = "\#endif\n\n"; - push(@data, $line); - $line = "\#ifdef OVERLOABLE_DUMMY_PREFIX\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_DUMMY_PREFIX\n"; - push(@data, $line); - $line = "\#endif\n\n"; - push(@data, $line); - $line = "\#define OVERLOADABLE_CALL CCTKBindings_\n"; - push(@data, $line); - $line = "\#define OVERLOADABLE_PREFIX\n"; - push(@data, $line); - $line = "\#define OVERLOADABLE_DUMMY_PREFIX CCTKBindings_Dummy\n\n"; - push(@data, $line); - $line = "#ifdef ARGUMENTS\n"; - push(@data, $line); - $line = "#undef ARGUMENTS\n"; - push(@data, $line); - $line = "#endif\n\n"; - push(@data, $line); - $line = "#ifdef RETURN_TYPE\n"; - push(@data, $line); - $line = "#undef RETURN_TYPE\n"; - push(@data, $line); - $line = "#endif\n\n"; - push(@data, $line); - - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + push(@data, '/*@@'); + push(@data, ' @header ThornOverloadables.h'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' The overloadable functions from thorns'); + push(@data, ' See OverloadMacros.h to see how to use these.'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#ifdef OVERLOADABLE_CALL'); + push(@data, '#undef OVERLOADABLE_CALL'); + push(@data, '#endif'); + push(@data, ''); + push(@data, '#ifdef OVERLOABLE_PREFIX'); + push(@data, '#undef OVERLOADABLE_PREFIX'); + push(@data, '#endif'); + push(@data, ''); + push(@data, '#ifdef OVERLOABLE_DUMMY_PREFIX'); + push(@data, '#undef OVERLOADABLE_DUMMY_PREFIX'); + push(@data, '#endif'); + push(@data, ''); + push(@data, '#define OVERLOADABLE_CALL CCTKBindings_'); + push(@data, '#define OVERLOADABLE_PREFIX'); + push(@data, '#define OVERLOADABLE_DUMMY_PREFIX CCTKBindings_Dummy'); + push(@data, ''); + push(@data, '#ifdef ARGUMENTS'); + push(@data, '#undef ARGUMENTS'); + push(@data, '#endif'); + push(@data, ''); + push(@data, '#ifdef RETURN_TYPE'); + push(@data, '#undef RETURN_TYPE'); + push(@data, '#endif'); + push(@data, ''); + + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) { - $line = "\#define ARGUMENTS $function_db->{\"$function CARGS\"}\n"; - push(@data, $line); - $line = "\#define RETURN_TYPE $function_db->{\"$function RET\"}\n\n"; - push(@data,$line); - $line = "OVERLOADABLE($function)\n\n"; - push(@data,$line); - $line = "\#undef ARGUMENTS\n"; - push(@data,$line); - $line = "\#undef RETURN_TYPE\n\n"; - push(@data,$line); + push(@data, "#define ARGUMENTS $function_db->{\"$function CARGS\"}"); + push(@data, "#define RETURN_TYPE $function_db->{\"$function RET\"}"); + push(@data, ''); + push(@data, "OVERLOADABLE($function)"); + push(@data, ''); + push(@data, '#undef ARGUMENTS'); + push(@data, '#undef RETURN_TYPE'); + push(@data, ''); } } - - $line = "#ifdef ARGUMENTS\n"; - push(@data, $line); - $line = "#undef ARGUMENTS\n"; - push(@data, $line); - $line = "#endif\n\n"; - push(@data, $line); - $line = "#ifdef RETURN_TYPE\n"; - push(@data, $line); - $line = "#undef RETURN_TYPE\n"; - push(@data, $line); - $line = "#endif\n\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_CALL\n"; - push(@data,$line); - $line = "\#undef OVERLOADABLE_PREFIX\n"; - push(@data,$line); - $line = "\#undef OVERLOADABLE_DUMMY_PREFIX\n"; - push(@data,$line); - - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - return $dataout; -} + push(@data, '#undef OVERLOADABLE_CALL'); + push(@data, '#undef OVERLOADABLE_PREFIX'); + push(@data, '#undef OVERLOADABLE_DUMMY_PREFIX'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + return join ("\n", @data); +} #/*@@ # @routine ThornMasterIncludes # @date Thu Feb 15 2001 # @author Gabrielle Allen -# @desc +# @desc # Master file of function prototypes for each thorn -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub ThornMasterIncludes { my($rhinterface_db) = @_; - my($line,@data,$dataout,$thorn); + my(@data); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header cctk_FunctionAliases.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Prototypes for overloaded functions used by all thorn\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#ifndef _CCTK_FUNCTIONALIASES_H_\n"; - push(@data, $line); - $line = "\#define _CCTK_FUNCTIONALIASES_H_\n\n"; - push(@data, $line); - - $line = "\#ifdef CCODE\n"; - push(@data, $line); - $line = "int CCTK_IsOverloaded(const char *function);\n\n"; - push(@data, $line); - $line = "\#endif\n\n"; - push(@data, $line); - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + push(@data, '/*@@'); + push(@data, ' @header cctk_FunctionAliases.h'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Prototypes for overloaded functions used by all thorns'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#ifndef _CCTK_FUNCTIONALIASES_H_'); + push(@data, '#define _CCTK_FUNCTIONALIASES_H_ 1'); + push(@data, ''); + + push(@data, '#ifdef CCODE'); + push(@data, 'int CCTK_IsOverloaded(const char *function);'); + push(@data, ''); + push(@data, '#endif'); + push(@data, ''); + + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $line = "\#ifdef THORN_IS_$thorn\n"; - push(@data, $line); - $line = "\#include \"$thorn"."_Prototypes.h\"\n"; - push(@data, $line); - $line = "\#endif\n\n"; - push(@data, $line); + push(@data, "#ifdef THORN_IS_$thorn"); + push(@data, "#include \"${thorn}_Prototypes.h\""); + push(@data, '#endif'); + push(@data, ''); } - $line = "\#endif\n\n"; - push(@data, $line); + push(@data, '#endif /* _CCTK_FUNCTIONALIASES_H_ */'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - - return $dataout; + return join ("\n", @data); } - #/*@@ # @routine OverloadThorns # @date Tue Feb 20 2001 # @author Gabrielle Allen -# @desc +# @desc # Main file for overloading thorns. Note that the text doesn't change # but the contents does depending on the thorn set used. For this reason # it is in the bindings and not in the Flesh. -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub OverloadThorns { - my($line,@data,$dataout); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = "\@file OverloadThornFunctions.c\n"; - push(@data, $line); - $line = "\@desc \n"; - push(@data, $line); - $line = "Contains routines to overload thorn functions\n"; - push(@data, $line); - $line = "Uses the overload macros to make sure of consistency and\n"; - push(@data, $line); - $line = "to save typing !\n"; - push(@data, $line); - $line = "\@enddesc\n"; - push(@data, $line); - $line = "\@\@*/\n\n"; - push(@data, $line); - - $line = "\#include <stdio.h>\n"; - push(@data, $line); - $line = "\#include <stdlib.h>\n"; - push(@data, $line); - $line = "\#include <string.h>\n\n"; - push(@data, $line); - - $line = "\#include \"cctk_Flesh.h\"\n"; - push(@data, $line); - $line = "\#include \"cctk_WarnLevel.h\"\n"; - push(@data, $line); - $line = "\#include \"OverloadMacros.h\"\n\n"; - push(@data, $line); - - $line = "/* Define the prototypes for the dummy functions. */\n"; - push(@data, $line); - $line = "\#define OVERLOADABLE(name) OVERLOADABLE_DUMMYPROTOTYPE(name)\n\n"; - push(@data, $line); - - $line = "\#include \"ThornOverloadables.h\"\n\n"; - push(@data, $line); - - $line = "\#undef OVERLOADABLE\n\n"; - push(@data, $line); - - $line = "\#define OVERLOADABLE(name) OVERLOADABLE_FUNCTION(name)\n\n"; - push(@data, $line); - - $line = "\#include \"ThornOverloadables.h\"\n\n"; - push(@data, $line); - - $line = "\#undef OVERLOADABLE\n\n"; - push(@data, $line); - - $line = "\#undef OVERLOADABLE_CALL\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_PREFIX\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE_DUMMY_PREFIX\n\n"; - push(@data, $line); - - $line = "/* Initialising Stuff */\n\n"; - push(@data, $line); - - $line = "void CCTKBindings_SetupThornFunctions(void);\n"; - push(@data, $line); - $line = "void CCTKBindings_SetupThornFunctions(void)\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - $line = "\#undef OVERLOADABLE\n"; - push(@data, $line); - $line = "\#define OVERLOADABLE(name) OVERLOADABLE_INITIALISE(name)\n"; - push(@data, $line); - $line = "\#include \"ThornOverloadables.h\"\n"; - push(@data, $line); - $line = "#undef OVERLOADABLE\n"; - push(@data, $line); - $line = "}\n\n"; - push(@data, $line); - - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - - return $dataout; + push(@data, '/*@@'); + push(@data, ' @file OverloadThornFunctions.c'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Contains routines to overload thorn functions'); + push(@data, ' Uses the overload macros to make sure of consistency '); + push(@data, ' and to save typing !'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include <stdio.h>'); + push(@data, '#include <stdlib.h>'); + push(@data, '#include <string.h>'); + push(@data, ''); + + push(@data, '#include "cctk_Flesh.h"'); + push(@data, '#include "cctk_WarnLevel.h"'); + push(@data, '#include "OverloadMacros.h"'); + push(@data, ''); + + push(@data, '/* Define the prototypes for the dummy functions. */'); + push(@data, '#define OVERLOADABLE(name) OVERLOADABLE_DUMMYPROTOTYPE(name)'); + push(@data, ''); + + push(@data, '#include "ThornOverloadables.h"'); + push(@data, ''); + + push(@data, '#undef OVERLOADABLE'); + push(@data, ''); + + push(@data, '#define OVERLOADABLE(name) OVERLOADABLE_FUNCTION(name)'); + push(@data, ''); + + push(@data, '#include "ThornOverloadables.h"'); + push(@data, ''); + + push(@data, '#undef OVERLOADABLE'); + push(@data, ''); + + push(@data, '#undef OVERLOADABLE_CALL'); + push(@data, '#undef OVERLOADABLE_PREFIX'); + push(@data, '#undef OVERLOADABLE_DUMMY_PREFIX'); + push(@data, ''); + + push(@data, '/* Initialising Stuff */'); + push(@data, ''); + + push(@data, 'void CCTKBindings_SetupThornFunctions(void);'); + push(@data, 'void CCTKBindings_SetupThornFunctions(void)'); + push(@data, '{'); + push(@data, '#undef OVERLOADABLE'); + push(@data, '#define OVERLOADABLE(name) OVERLOADABLE_INITIALISE(name)'); + push(@data, '#include "ThornOverloadables.h"'); + push(@data, '#undef OVERLOADABLE'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + + return join ("\n", @data); } - #/*@@ # @routine ThornIncludes.h # @date Thu Feb 15 2001 # @author Gabrielle Allen -# @desc +# @desc # Create function prototypes for each thorn -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub ThornIncludes { - my($thorn,$function_db,$rhinterface_db) = @_; - my($line,@data,$dataout,$function); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header $thorn"."_Prototypes.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Prototypes for overloaded functions used by this thorn\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#ifndef _\U$thorn\E_PROTOTYPES_H_\n"; - push(@data, $line); - $line = "\#define _\U$thorn\E_PROTOTYPES_H_\n\n"; - push(@data, $line); - - - $line = "\#ifdef CCODE\n"; - push(@data, $line); - - foreach $function (split(" ",($rhinterface_db->{"\U$thorn USES FUNCTION\E"}))) + push(@data, '/*@@'); + push(@data, " \@header ${thorn}_Prototypes.h"); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Prototypes for overloaded functions used by this thorn'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, "#ifndef _\U$thorn\E_PROTOTYPES_H_"); + push(@data, "#define _\U$thorn\E_PROTOTYPES_H_ 1"); + push(@data, ''); + + push(@data, '#ifdef CCODE'); + + foreach $function (split(' ',($rhinterface_db->{"\U$thorn USES FUNCTION\E"}))) { if ($function !~ m:^\s*$:) { - $line = "extern $function_db->{\"$function RET\"} (*$function)($function_db->{\"$function CARGS\"});\n"; - push(@data, $line); + push(@data, "extern $function_db->{\"$function RET\"} (*$function)($function_db->{\"$function CARGS\"});"); } } - $line = "\#endif /*CCODE*/\n\n"; - push(@data, $line); + push(@data, '#endif /* CCODE */'); + push(@data, ''); - $line = "\#endif\n\n"; - push(@data, $line); + push(@data, '#endif'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - - return $dataout; + return join ("\n", @data); } @@ -617,180 +441,119 @@ sub ThornIncludes # @routine RegisterAllFunctions # @date Sun Feb 11 2001 # @author Gabrielle Allen -# @desc +# @desc # Create file to call all thorn function registration -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub RegisterAllFunctions { my($rhinterface_db) = @_; - my($dataout,$line,@data); - - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header RegisterAllFunctions.c\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Register aliased functions from active thorns\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@returntype int\n"; - push(@data, $line); - $line = " \@returndesc \n"; - push(@data, $line); - $line = " Minus number of failed overloads\n"; - push(@data, $line); - $line = " \@endreturndesc\n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#include \"cctk_Flesh.h\"\n"; - push(@data, $line); - $line = "\#include \"cctk_ActiveThorns.h\"\n\n"; - push(@data, $line); - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) - { - $line = "int CCTKBindings_".$thorn."Aliases(void);\n"; - push(@data, $line); - } - $line = "int CCTKBindings_RegisterThornFunctions(void);\n\n"; - push(@data, $line); - $line = "int CCTKBindings_RegisterThornFunctions(void)\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - $line = " int retval = 0;\n"; - push(@data, $line); - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + my(@data) = (); + + push(@data, '/*@@'); + push(@data, ' @file RegisterAllFunctions.c'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Register aliased functions from active thorns'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include "cctk_Flesh.h"'); + push(@data, '#include "cctk_ActiveThorns.h"'); + push(@data, ''); + + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $line = " if (CCTK_IsThornActive(\"$thorn\"))\n"; - push(@data, $line); - $line = " {\n"; - push(@data, $line); - $line = " retval =+ CCTKBindings_".$thorn."Aliases();\n"; - push(@data, $line); - $line = " }\n"; - push(@data, $line); + push(@data, "int CCTKBindings_${thorn}Aliases(void);"); } - $line = " return retval;\n"; - push(@data, $line); - $line = "}\n"; - push(@data, $line); - $dataout = ""; - foreach $line (@data) + push(@data, 'int CCTKBindings_RegisterThornFunctions(void);'); + push(@data, 'int CCTKBindings_RegisterThornFunctions(void)'); + push(@data, '{'); + push(@data, ' int retval = 0;'); + + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $dataout .= $line; + push(@data, " if (CCTK_IsThornActive(\"$thorn\"))"); + push(@data, ' {'); + push(@data, " retval += CCTKBindings_${thorn}Aliases();"); + push(@data, ' }'); } + push(@data, ' return retval;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - return $dataout; - + return join ("\n", @data); } + #/*@@ # @routine DummyThornFunctions # @date Sat Feb 10 # @author Gabrielle Allen -# @desc +# @desc # Check contents for ThornOverloadables_h -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub DummyThornFunctions { my($function_db) = @_; - my($dataout,$line,@data); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header DummyThornFunctions.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Dummy functions for overloaded thorn functions\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#include <stdlib.h>\n\n"; - push(@data, $line); - $line = "\#include \"cctk_Flesh.h\"\n"; - push(@data, $line); - $line = "\#include \"cctk_WarnLevel.h\"\n\n"; - push(@data, $line); - - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + push(@data, '/*@@'); + push(@data, ' @header DummyThornFunctions.h'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Dummy functions for overloaded thorn functions'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include <stdlib.h>'); + push(@data, ''); + push(@data, '#include "cctk_Flesh.h"'); + push(@data, '#include "cctk_WarnLevel.h"'); + push(@data, ''); + + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) - { - $ret = $function_db->{"$function RET"}; - - $line = "$ret CCTKBindings_Dummy$function($function_db->{\"$function CARGS\"});\n"; - push(@data, $line); - $line = "$ret CCTKBindings_Dummy$function($function_db->{\"$function CARGS\"})\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - - # Make sure we use all arguments to avoid warnings - $line = " const void *cctk_dummy_pointer;\n"; - push(@data, $line); - $line = " cctk_dummy_pointer = cctk_dummy_pointer;\n"; - push(@data, $line); - foreach $arg (split(",",$function_db->{"$function CARGS"})) - { - $arg =~ m:(.*\s+\**)([^\s*\*]+)\s*:; -# $type=$1; - $name=$2; - $line = " cctk_dummy_pointer = \&$name;\n"; - push(@data, $line); - } - $line = " CCTK_Warn(1,__LINE__,__FILE__,\"Bindings\",\n"; - push(@data, $line); - $line = " \"CCTKBindings_Dummy$function: Calling thorn function $function which has not been overloaded\");\n"; - push(@data, $line); - if ($ret =~ m:INT:i) - { - $line = "return -1;"; - push(@data, $line); - } - elsif ($ret =~ m:REAL:i) - { - $line = "return 0;"; - push(@data, $line); - } - $line = "}\n\n"; - push(@data, $line); - } - } + { + $ret = $function_db->{"$function RET"}; - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; + push(@data, "$ret CCTKBindings_Dummy$function($function_db->{\"$function CARGS\"});"); + push(@data, "$ret CCTKBindings_Dummy$function($function_db->{\"$function CARGS\"})"); + push(@data, '{'); + + # Make sure we use all arguments to avoid warnings + foreach $arg (split(',',$function_db->{"$function CARGS"})) + { + $arg =~ m:.*\s+\**([^\s*\*]+)\s*:; + push(@data, " (void) ($1 + 0)"); + } + push(@data, ' CCTK_Warn(1, __LINE__, __FILE__, "Bindings",'); + push(@data, " \"CCTKBindings_Dummy$function: Calling thorn function $function which has not been overloaded\");"); + if ($ret =~ m:INT:i) + { + push(@data, ' return -1;'); + } + elsif ($ret =~ m:REAL:i) + { + push(@data, ' return 0;'); + } + push(@data, '}'); + push(@data, ''); + } } + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - return $dataout; - + return join ("\n", @data); } @@ -798,39 +561,31 @@ sub DummyThornFunctions # @routine RegisterThornFunctions # @date Sun Feb 11 2001 # @author Gabrielle Allen -# @desc +# @desc # Create contents for files to register aliased functions -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub RegisterThornFunctions { my($thorn,$function_db,$rhinterface_db) = @_; - my($dataout,$line,@data,$function); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header $thorn"."_Register.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Register aliased functions for $thorn\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#include \"cctk_Flesh.h\"\n"; - push(@data, $line); - - foreach $function (split(" ",$rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"})) + push(@data, '/*@@'); + push(@data, " \@header ${thorn}_Register.h"); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, " Register aliased functions for $thorn"); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include "cctk_Flesh.h"'); + push(@data, ''); + + foreach $function (split(' ',$rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"})) { if ($function !~ m:^\s*$:) { @@ -838,53 +593,34 @@ sub RegisterThornFunctions $ret = $function_db->{"$function RET"}; $args = $function_db->{"$function CARGS"}; - $line = "$ret $provided_with($args);\n"; - push(@data, $line); - $line = "int CCTKBindings_Overload$function($ret (* $function)($args));\n"; - push(@data, $line); + push(@data, "$ret $provided_with($args);"); + push(@data, "int CCTKBindings_Overload$function($ret (* $function)($args));"); } } - $line = "\n"; - push(@data, $line); - $line = "int CCTKBindings_".$thorn."Aliases(void);\n"; - push(@data, $line); - $line = "\n"; - push(@data, $line); - $line = "int CCTKBindings_".$thorn."Aliases(void)\n"; - push(@data, $line); - $line = "{\n"; - push(@data, $line); - $line = " int retval=0; /* returns minus number of failed overloads */\n"; - push(@data, $line); - $line = " int ierr=0;\n\n"; - push(@data, $line); - $line = " retval = ierr; /* use ierr to prevent warnings */\n\n"; - push(@data, $line); - - - foreach $function (split(" ",$rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"})) + push(@data, ''); + push(@data, "int CCTKBindings_${thorn}Aliases(void);"); + push(@data, "int CCTKBindings_${thorn}Aliases(void)"); + push(@data, '{'); + push(@data, ' int retval = 0; /* returns minus number of failed overloads */'); + push(@data, ' int ierr = 0;'); + push(@data, ''); + push(@data, ' retval = ierr; /* use ierr to prevent warnings */'); + push(@data, ''); + + foreach $function (split(' ',$rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"})) { if ($function !~ m:^\s*$:) { - $line = " ierr = CCTKBindings_Overload$function($rhinterface_db->{\"\U$thorn PROVIDES FUNCTION\E $function WITH\"});\n"; - push(@data, $line); - $line = " retval = (ierr == 0) ? retval-- : retval;\n"; - push(@data, $line); + push(@data, " ierr = CCTKBindings_Overload$function($rhinterface_db->{\"\U$thorn PROVIDES FUNCTION\E $function WITH\"});"); + push(@data, ' retval = (ierr == 0) ? retval-- : retval;'); } } - - $line = " return retval;\n"; - push(@data, $line); - $line = "}\n"; - push(@data, $line); - - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - return ($dataout); + push(@data, ' return retval;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + + return join ("\n", @data); } @@ -892,184 +628,148 @@ sub RegisterThornFunctions # @routine FortranThornFunctions # @date Sat Feb 10 2001 # @author Gabrielle Allen -# @desc +# @desc # Create fortran wrappers for thorn functions -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub FortranThornFunctions { my($function_db) = @_; - my($dataout,$line,@data,$function); + my(@data) = (); # Header Data - $line = "/*\@\@\n"; - push(@data, $line); - $line = " \@header FortranThornFunctions.h\n"; - push(@data, $line); - $line = " \@desc\n"; - push(@data, $line); - $line = " Fortran wrappers for overloaded thorn functions\n"; - push(@data, $line); - $line = " \@enddesc \n"; - push(@data, $line); - $line = " \@\@*/\n\n"; - push(@data, $line); - $line = "\#include <stdlib.h>\n\n"; - push(@data, $line); - $line = "\#include \"cctk_Flesh.h\"\n"; - push(@data, $line); - $line = "\#include \"cctk_WarnLevel.h\"\n\n"; - push(@data, $line); - $line = "\#include \"cctk_FortranString.h\"\n\n"; - push(@data, $line); + push(@data, '/*@@'); + push(@data, ' @header FortranThornFunctions.h'); + push(@data, ' @author Automatically generated by CreateFunctionBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Fortran wrappers for overloaded thorn functions'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include <stdlib.h>'); + push(@data, ''); + push(@data, '#include "cctk_Flesh.h"'); + push(@data, '#include "cctk_WarnLevel.h"'); + push(@data, '#include "cctk_FortranString.h"'); + push(@data, ''); # Do aliased function prototypes - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) { - $line = "extern $function_db->{\"$function RET\"} (*$function)($function_db->{\"$function CARGS\"});\n"; - push(@data, $line); + push(@data, "extern $function_db->{\"$function RET\"} (*$function)($function_db->{\"$function CARGS\"});"); } } - $line = "\n\n"; - push(@data, $line); + push(@data, ''); + push(@data, ''); - - foreach $function (split(" ",$function_db->{"FUNCTIONS"})) + foreach $function (split(' ',$function_db->{'FUNCTIONS'})) { if ($function !~ m:^\s*$:) { - $line = "$function_db->{\"$function RET\"} CCTK_FCALL CCTK_FNAME($function)\n"; - $line .= "($function_db->{\"$function WARGS\"}"; + push(@data, "$function_db->{\"$function RET\"} CCTK_FCALL CCTK_FNAME($function)"); + $line = "($function_db->{\"$function WARGS\"}"; if ($function_db->{"$function STRINGS"} == 1) { - $line .= ", ONE_FORTSTRING_ARG"; + $line .= ', ONE_FORTSTRING_ARG'; } elsif ($function_db->{"$function STRINGS"} == 2) { - $line .= ", TWO_FORTSTRINGS_ARGS"; + $line .= ', TWO_FORTSTRINGS_ARGS'; } elsif ($function_db->{"$function STRINGS"} == 3) { - $line .= ", THREE_FORTSTRINGS_ARGS"; + $line .= ', THREE_FORTSTRINGS_ARGS'; } - - $line .= ")"; + $line .= ')'; # prototype - push(@data, "$line;\n"); + push(@data, "$line;"); # call - push(@data, "$line\n"); - $line = "{\n"; push(@data, $line); + push(@data, '{'); - if ($function_db->{"$function TYPE"} =~ "FUNC") + if ($function_db->{"$function TYPE"} =~ 'FUNC') { - $line = " $function_db->{\"$function RET\"} cctki_retval;\n"; - push(@data, $line); + push(@data, " $function_db->{\"$function RET\"} cctki_retval;"); } if ($function_db->{"$function STRINGS"} == 1) { - $line = "ONE_FORTSTRING_CREATE(cctki_string1)\n"; - push(@data, $line); + push(@data, 'ONE_FORTSTRING_CREATE(cctki_string1)'); } elsif ($function_db->{"$function STRINGS"} == 2) { - $line = "TWO_FORTSTRINGS_CREATE(cctki_string1,cctki_string2)\n"; - push(@data, $line); + push(@data, 'TWO_FORTSTRINGS_CREATE(cctki_string1, cctki_string2)'); } elsif ($function_db->{"$function STRINGS"} == 3) { - $line = "THREE_FORTSTRINGS_CREATE(cctki_string1,cctki_string2,cctki_string3)\n"; - push(@data, $line); + push(@data, 'THREE_FORTSTRINGS_CREATE(cctki_string1, cctki_string2, cctki_string3)'); } - if ($function_db->{"$function TYPE"} =~ "FUNC") + if ($function_db->{"$function TYPE"} =~ 'FUNC') { - $line = " cctki_retval = \n"; - push(@data, $line); + push(@data, ' cctki_retval = '); } - $line = " $function($function_db->{\"$function WCALL\"}"; - push(@data, $line); + push(@data, " $function($function_db->{\"$function WCALL\"}"); if ($function_db->{"$function STRINGS"} == 1) { - $line = ", cctki_string1"; - push(@data, $line); + push(@data, ', cctki_string1'); } elsif ($function_db->{"$function STRINGS"} == 2) { - $line = ", cctki_string1, cctki_string2"; - push(@data, $line); + push(@data, ', cctki_string1, cctki_string2'); } elsif ($function_db->{"$function STRINGS"} == 3) { - $line = ", cctki_string1, cctki_string2, cctki_string3"; - push(@data, $line); + push(@data, ', cctki_string1, cctki_string2, cctki_string3'); } - $line = ");\n"; - push(@data, $line); + push(@data, ');'); if ($function_db->{"$function STRINGS"} == 1) { - $line = " free(cctki_string1);\n"; - push(@data, $line); + push(@data, ' free(cctki_string1);'); } elsif ($function_db->{"$function STRINGS"} == 2) { - $line = " free(cctki_string1);\n free(cctki_string2);\n"; - push(@data, $line); + push(@data, ' free(cctki_string1);'); + push(@data, ' free(cctki_string2);'); } elsif ($function_db->{"$function STRINGS"} == 3) { - $line = " free(cctki_string1);\n free(cctki_string2);\n free(cctki_string3);\n"; - push(@data, $line); + push(@data, ' free(cctki_string1);'); + push(@data, ' free(cctki_string2);'); + push(@data, ' free(cctki_string3);'); } - if ($function_db->{"$function TYPE"} =~ "FUNC") + if ($function_db->{"$function TYPE"} =~ 'FUNC') { - $line = " return cctki_retval; \n"; - push(@data, $line); + push(@data, ' return cctki_retval;'); } - $line = "}\n"; - push(@data, $line); + push(@data, '}'); } } + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - $dataout = ""; - foreach $line (@data) - { - $dataout .= $line; - } - - return $dataout; + return join ("\n", @data); } + #/*@@ # @routine FunctionDatabase # @date Wed Dec 06 11.37 # @author Gabrielle Allen -# @desc +# @desc # Check consistency for Thorn Functions and create database -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub FunctionDatabase @@ -1077,73 +777,73 @@ sub FunctionDatabase my($rhinterface_db) = @_; my($thorn,$inret,$inargs,$message,$function); - $function_db->{"FUNCTIONS"}= " "; - $function_db->{"PROVIDED FUNCTIONS"}= " "; + $function_db->{'FUNCTIONS'}= ' '; + $function_db->{'PROVIDED FUNCTIONS'}= ' '; # Add used functions to database - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - foreach $function (split(" ",($rhinterface_db->{"\U$thorn USES FUNCTION\E"}))) + foreach $function (split(' ',($rhinterface_db->{"\U$thorn USES FUNCTION\E"}))) { $inargs = $rhinterface_db->{"\U$thorn FUNCTION\E $function ARGS"}; $inret = $rhinterface_db->{"\U$thorn FUNCTION\E $function RET"}; ($nstrings,$types,$c,$fortran,$wrappercall,$wrapperargs,$cargs) = &ParseArguments($inret,$inargs); - if ($function_db->{"FUNCTIONS"} =~ / $function / && $function !~ /^\s*$/) + if ($function_db->{'FUNCTIONS'} =~ / $function / && $function !~ /^\s*$/) { if ($types ne $function_db->{"$function TYPES"}) { $message = "Argument types for aliased $function do not match"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } if ($inret ne $function_db->{"$function RET"}) { $message = "Return types for aliased $function do not match"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } } else { if ($inret =~ m:^\s*void\s*$:) { - $function_db->{"$function CARGS"} = "SUB"; + $function_db->{"$function CARGS"} = 'SUB'; } else { - $function_db->{"$function CARGS"} = "FUNC"; + $function_db->{"$function CARGS"} = 'FUNC'; } if ($c) { if ($fortran) { - $function_db->{"$function LANG"} = "FC"; + $function_db->{"$function LANG"} = 'FC'; } else { - $function_db->{"$function LANG"} = "C"; + $function_db->{"$function LANG"} = 'C'; $message = "Fortran wrapper not created for alias $function"; - &CST_error(1,$message,"",__LINE__,__FILE__); + &CST_error(1,$message,'',__LINE__,__FILE__); } } else { - $function_db->{"$function LANG"} = ""; + $function_db->{"$function LANG"} = ''; $message = "Can't create alias for $function"; - &CST_error(0,$message,"",__LINE__,__FILE__); - } + &CST_error(0,$message,'',__LINE__,__FILE__); + } - if ($rhinterface_db->{"\U$thorn FUNCTION\E $function RET"} eq "void") + if ($rhinterface_db->{"\U$thorn FUNCTION\E $function RET"} eq 'void') { - $function_db->{"$function TYPE"} = "SUB"; + $function_db->{"$function TYPE"} = 'SUB'; } else { - $function_db->{"$function TYPE"} = "FUNC"; + $function_db->{"$function TYPE"} = 'FUNC'; } - $function_db->{"FUNCTIONS"} .= "$function "; + $function_db->{'FUNCTIONS'} .= "$function "; $function_db->{"$function STRINGS"} = $nstrings; $function_db->{"$function CARGS"} = $cargs; $function_db->{"$function TYPES"} = $types; @@ -1155,58 +855,53 @@ sub FunctionDatabase } # Check consistency of providing functions - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - foreach $function (split(" ",($rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"}))) + foreach $function (split(' ',($rhinterface_db->{"\U$thorn PROVIDES FUNCTION\E"}))) { $inargs = $rhinterface_db->{"\U$thorn FUNCTION\E $function ARGS"}; $inret = $rhinterface_db->{"\U$thorn FUNCTION\E $function RET"}; ($nstrings,$types,$c,$fortran,$wrappercall,$wrapperargs,$cargs) = &ParseArguments($inret,$inargs); - if ($function_db->{"FUNCTIONS"} =~ / $function / && $function !~ /^\s*$/) + if ($function_db->{'FUNCTIONS'} =~ / $function / && $function !~ /^\s*$/) { if ($types ne $function_db->{"$function TYPES"}) { $message = "Argument types for aliased $function do not match"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } if ($inret ne $function_db->{"$function RET"}) { $message = "Return types for aliased $function do not match"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } } - $function_db->{"PROVIDED FUNCTIONS"} .= "$function "; + $function_db->{'PROVIDED FUNCTIONS'} .= "$function "; } } # Check to see if any functions are potentially used and not provided - foreach $function (split(" ",($function_db->{"FUNCTIONS"}))) + foreach $function (split(' ',($function_db->{'FUNCTIONS'}))) { - if ($function_db->{"PROVIDED FUNCTIONS"} !~ / $function /) + if ($function_db->{'PROVIDED FUNCTIONS'} !~ / $function /) { $message = "Aliased function $function is not provided by any thorn"; - &CST_error(1,$message,"",__LINE__,__FILE__); + &CST_error(1,$message,'',__LINE__,__FILE__); } } return $function_db; } + #/*@@ # @routine ParseArguments # @date Sun Feb 11 2001 # @author Gabrielle Allen -# @desc +# @desc # Parse the argument list and create versions for C and Fortran -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub ParseArguments @@ -1218,11 +913,11 @@ sub ParseArguments # print "=================\n"; # print "All args: $args\n"; - $fwrapperargs = ""; - $fwrappercallargs = ""; - $ccallargs = ""; - $types = ""; - $number_args = split(",",$args); + $fwrapperargs = ''; + $fwrappercallargs = ''; + $ccallargs = ''; + $types = ''; + $number_args = split(',',$args); # Need to count strings for fortran wrappers $number_strings = 0; @@ -1232,7 +927,7 @@ sub ParseArguments # Will be set to zero if can't add the aliased C function $c = 1; - foreach $arg (split(",",$args)) + foreach $arg (split(',',$args)) { # print " Arg is $arg\n"; @@ -1252,7 +947,7 @@ sub ParseArguments # print " Type is $type\n"; # treat string differently - + if ($type =~ m/CCTK_STRING/) { $number_strings++; @@ -1283,7 +978,7 @@ sub ParseArguments $fortran = 0; $c = 0; $message = "Error parsing aliased function argument $arg"; - &CST_error(1,$message,"",__LINE__,__FILE__); + &CST_error(1,$message,'',__LINE__,__FILE__); } } diff --git a/lib/sbin/CreateImplementationBindings.pl b/lib/sbin/CreateImplementationBindings.pl index 75e2b0f2..254bffc9 100644 --- a/lib/sbin/CreateImplementationBindings.pl +++ b/lib/sbin/CreateImplementationBindings.pl @@ -27,42 +27,38 @@ sub CreateImplementationBindings chdir $bindings_dir; - if(! -d "Implementations") + if(! -d 'Implementations') { - mkdir("Implementations", 0755) || die "Unable to create Implementations directory"; + mkdir('Implementations', 0755) || die 'Unable to create Implementations directory'; } - if(! -d "include") + if(! -d 'include') { - mkdir("include", 0755) || die "Unable to create include directory"; + mkdir('include', 0755) || die 'Unable to create include directory'; } - chdir "Implementations"; - @data = (); - - foreach $thorn (sort split(" ", $rhinterface_db->{"THORNS"})) + foreach $thorn (sort split(' ', $rhinterface_db->{'THORNS'})) { - push(@data, "int CCTKi_BindingsThorn_$thorn(void);\n") + push(@data, "int CCTKi_BindingsThorn_$thorn(void);") } - push(@data, "int CCTKi_BindingsImplementationsInitialise(void)\n{\n"); - - foreach $thorn (sort split(" ", $rhinterface_db->{"THORNS"})) + push(@data, 'int CCTKi_BindingsImplementationsInitialise(void);'); + push(@data, 'int CCTKi_BindingsImplementationsInitialise(void)'); + push(@data, '{'); + foreach $thorn (sort split(' ', $rhinterface_db->{'THORNS'})) { - push(@data, " CCTKi_BindingsThorn_$thorn();\n") + push(@data, " CCTKi_BindingsThorn_$thorn();") } + push(@data, ' return 0;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - push(@data, "\n return 0;\n}\n"); + $dataout = join ("\n", @data); + &WriteFile('Implementations/ImplementationBindings.c',\$dataout); - &OutputFile(".", "ImplementationBindings.c", @data); - - - $dataout = ""; - $dataout .= "\n"; - $dataout .= "SRCS = ImplementationBindings.c\n\n"; - - &WriteFile("make.code.defn",\$dataout); + $dataout = 'SRCS = ImplementationBindings.c'; + &WriteFile('Implementations/make.code.defn',\$dataout); if(! -d "$build_dir") { @@ -71,81 +67,78 @@ sub CreateImplementationBindings chdir "$build_dir"; - foreach $thorn (sort split(" ", $rhinterface_db->{"THORNS"})) + foreach $thorn (sort split(' ', $rhinterface_db->{'THORNS'})) { - if(! -d "$thorn") { mkdir("$thorn", 0755) || die "Unable to create $build_dir/$thorn"; } - chdir "$thorn"; - $myimp = $rhinterface_db->{"\U$thorn\E IMPLEMENTS"}; @data = (); - - push(@data, "#include <stdio.h>\n"); - push(@data, "#include \"cctki_ActiveThorns.h\"\n\n"); - - push(@data, "int CCTKi_BindingsThorn_${thorn}(void);\n"); - push(@data, "int CCTKi_BindingsThorn_${thorn}(void)\n{\n"); - - push(@data, " int retval;\n"); - - push(@data, " const char *name[] = {\"$thorn\",0};"); - push(@data, " const char *implementation[]={\"$myimp\",0};"); - - push(@data, " const char *ancestors[]=\n {"); + push(@data, '#include <stdio.h>'); + push(@data, ''); + push(@data, '#include "cctki_ActiveThorns.h"'); + push(@data, ''); + + push(@data, "int CCTKi_BindingsThorn_${thorn}(void);"); + push(@data, "int CCTKi_BindingsThorn_${thorn}(void)"); + push(@data, '{'); + push(@data, ' int retval;'); + push(@data, " const char *name[] = {\"$thorn\", 0};"); + push(@data, " const char *implementation[] = {\"$myimp\", 0};"); + push(@data, ' const char *ancestors[] ='); + push(@data, ' {'); foreach $ancestor (split(" ",$rhinterface_db->{"IMPLEMENTATION \U$myimp\E ANCESTORS"})) { push(@data, " \"$ancestor\","); } - push(@data, " 0,"); - push(@data, " };\n"); + push(@data, ' 0,'); + push(@data, ' };'); + push(@data, ''); # Just pass the ones this thorn has declared itself to be friends with. - push(@data, " const char *friends[]=\n {"); + push(@data, ' const char *friends[] ='); + push(@data, ' {'); foreach $friend (split(" ",$rhinterface_db->{"\U$thorn\E FRIEND"})) { push(@data, " \"$friend\","); } - push(@data, " 0,"); - push(@data, " };\n"); - - push(@data, " /* Should be able to do below with a constant initialiser but sr8000 compiler complains"); - push(@data, " * So have to laboriously assign values to each member of array."); - push(@data, " */"); - push(@data, " struct iAttributeList attributes[5];"); - push(@data, ""); - push(@data, " attributes[0].attribute = \"name\";"); - push(@data, " attributes[0].AttributeData.StringList = name;"); - push(@data, " attributes[1].attribute = \"implementation\";"); - push(@data, " attributes[1].AttributeData.StringList = implementation;"); - push(@data, " attributes[2].attribute = \"ancestors\";"); - push(@data, " attributes[2].AttributeData.StringList = ancestors;"); - push(@data, " attributes[3].attribute = \"friends\";"); - push(@data, " attributes[3].AttributeData.StringList = friends;"); - push(@data, " attributes[4].attribute = 0;"); - push(@data, " attributes[4].AttributeData.StringList = 0;"); - push(@data, "\n"); - - push(@data, " retval = CCTKi_RegisterThorn(attributes);"); - - push(@data, "\n return retval;\n}\n"); - - &OutputFile(".", "cctk_ThornBindings.c", @data); - - - $dataout = ""; - $dataout .= "\n"; - $dataout .= "SRCS = cctk_ThornBindings.c\n\n"; - - &WriteFile("make.code.defn",\$dataout); - - chdir ".."; + push(@data, ' 0,'); + push(@data, ' };'); + push(@data, ''); + + push(@data, ' /* Should be able to do below with a constant initialiser but sr8000 compiler complains'); + push(@data, ' * So have to laboriously assign values to each member of array.'); + push(@data, ' */'); + push(@data, ' struct iAttributeList attributes[5];'); + push(@data, ''); + push(@data, ' attributes[0].attribute = "name";'); + push(@data, ' attributes[0].AttributeData.StringList = name;'); + push(@data, ' attributes[1].attribute = "implementation";'); + push(@data, ' attributes[1].AttributeData.StringList = implementation;'); + push(@data, ' attributes[2].attribute = "ancestors";'); + push(@data, ' attributes[2].AttributeData.StringList = ancestors;'); + push(@data, ' attributes[3].attribute = "friends";'); + push(@data, ' attributes[3].AttributeData.StringList = friends;'); + push(@data, ' attributes[4].attribute = 0;'); + push(@data, ' attributes[4].AttributeData.StringList = 0;'); + push(@data, ''); + push(@data, ' retval = CCTKi_RegisterThorn(attributes);'); + push(@data, ''); + push(@data, ' return retval;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + + $dataout = join ("\n", @data); + &WriteFile("$thorn/cctk_ThornBindings.c",\$dataout); + + $dataout = 'SRCS = cctk_ThornBindings.c'; + &WriteFile("$thorn/make.code.defn",\$dataout); } + chdir($start_dir); } 1; diff --git a/lib/sbin/CreateParameterBindings.pl b/lib/sbin/CreateParameterBindings.pl index f0405528..e2f7819b 100644 --- a/lib/sbin/CreateParameterBindings.pl +++ b/lib/sbin/CreateParameterBindings.pl @@ -3,9 +3,9 @@ # @date Sun Jul 25 00:52:36 1999 # @author Tom Goodale # @desc -# Parameter binding stuff +# Parameter binding stuff # @enddesc -# @version $Header$ +# @version $Header$ #@@*/ #/*@@ @@ -15,12 +15,6 @@ # @desc # Create the bindings used for the parameters. # @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# #@@*/ sub CreateParameterBindings @@ -44,377 +38,275 @@ sub CreateParameterBindings chdir $bindings_dir; - if(! -d "Parameters") + if(! -d 'Parameters') { - mkdir("Parameters", 0755) || die "Unable to create Parameters directory"; + mkdir('Parameters', 0755) || die 'Unable to create Parameters directory'; } - if(! -d "include") + if(! -d 'include') { - mkdir("include", 0755) || die "Unable to create include directory"; + mkdir('include', 0755) || die 'Unable to create include directory'; } - chdir "Parameters"; - - # Generate all global parameters %these_parameters = &get_global_parameters($rhparameter_db); - @data = &CreateParameterBindingFile("CCTK_BindingsParametersGlobal", "GLOBAL_PARAMETER_STRUCT", \%these_parameters, $rhparameter_db); + $dataout = &CreateParameterBindingFile('CCTK_BindingsParametersGlobal', 'GLOBAL_PARAMETER_STRUCT', \%these_parameters, $rhparameter_db); - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - &WriteFile("Global.c",\$dataout); + &WriteFile('Parameters/Global.c',\$dataout); - $files = "Global.c"; - $structures{"GLOBAL_PARAMETER_STRUCT"} = "cctk_params_global"; + $files = 'Global.c'; + $structures{'GLOBAL_PARAMETER_STRUCT'} = 'cctk_params_global'; # Generate the global data header file - chdir ".."; - chdir "include"; + $dataout = &CreateCStructureParameterHeader('CCTK_BindingsParametersGlobal', 'GLOBAL_PARAMETER_STRUCT', \%these_parameters, $rhparameter_db); - @data = &CreateCStructureParameterHeader("CCTK_BindingsParametersGlobal", "GLOBAL_PARAMETER_STRUCT", \%these_parameters, $rhparameter_db); - - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - $dataout .= "\n\n"; + &WriteFile('include/ParameterCGlobal.h',\$dataout); - &WriteFile("ParameterCGlobal.h",\$dataout); - - $header_files{"GLOBAL"} = "ParameterCGlobal.h"; - - chdir ".."; - chdir "Parameters"; + $header_files{'GLOBAL'} = 'ParameterCGlobal.h'; # Generate all restricted parameters - foreach $implementation (split(" ",$rhinterface_db->{"IMPLEMENTATIONS"})) + foreach $implementation (split(' ',$rhinterface_db->{'IMPLEMENTATIONS'})) { $rhinterface_db->{"IMPLEMENTATION \U$implementation\E THORNS"} =~ m:([^ ]+):; $thorn = $1; - %these_parameters = &GetThornParameterList($thorn, "RESTRICTED", $rhparameter_db); + %these_parameters = &GetThornParameterList($thorn, 'RESTRICTED', $rhparameter_db); if((keys %these_parameters > 0)) { - @data = &CreateParameterBindingFile("CCTK_BindingsParameters$implementation"."_restricted", "RESTRICTED_\U$implementation\E_STRUCT", \%these_parameters, $rhparameter_db); + $dataout = &CreateParameterBindingFile("CCTK_BindingsParameters${implementation}_restricted", "RESTRICTED_\U$implementation\E_STRUCT", \%these_parameters, $rhparameter_db); - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - &WriteFile("\U$implementation\E". "_restricted.c",\$dataout); + &WriteFile("Parameters/\U$implementation\E_restricted.c",\$dataout); - $files .= " \U$implementation\E". "_restricted.c"; - $routines{"CCTK_BindingsParameters$implementation"."_restricted"} = "$implementation"; - $structures{"RESTRICTED_\U$implementation\E_STRUCT"} = "$implementation"."rest"; + $files .= " \U$implementation\E_restricted.c"; + $routines{"CCTK_BindingsParameters${implementation}_restricted"} = "$implementation"; + $structures{"RESTRICTED_\U$implementation\E_STRUCT"} = "${implementation}rest"; # Generate the data header file - chdir ".."; - chdir "include"; - - @data = &CreateCStructureParameterHeader("CCTK_BindingsParameters$implementation"."_restricted", "RESTRICTED_\U$implementation\E_STRUCT", \%these_parameters, $rhparameter_db); - + $dataout = &CreateCStructureParameterHeader("CCTK_BindingsParameters${implementation}_restricted", "RESTRICTED_\U$implementation\E_STRUCT", \%these_parameters, $rhparameter_db); - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - $dataout .= "\n\n"; - &WriteFile("ParameterCRestricted\U$implementation\E".".h",\$dataout); - - $header_files{"\U$implementation\E RESTRICTED"} = "ParameterCRestricted\U$implementation\E".".h"; - - chdir ".."; - chdir "Parameters"; + &WriteFile("include/ParameterCRestricted\U$implementation\E.h",\$dataout); + $header_files{"\U$implementation\E RESTRICTED"} = "ParameterCRestricted\U$implementation\E.h"; } } # Generate all private parameters - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - %these_parameters = &GetThornParameterList($thorn, "PRIVATE", $rhparameter_db); + %these_parameters = &GetThornParameterList($thorn, 'PRIVATE', $rhparameter_db); if((keys %these_parameters > 0)) { - @data = &CreateParameterBindingFile("CCTK_BindingsParameters$thorn"."_private", "PRIVATE_\U$thorn\E_STRUCT", \%these_parameters, $rhparameter_db); + $dataout = &CreateParameterBindingFile("CCTK_BindingsParameters${thorn}_private", "PRIVATE_\U$thorn\E_STRUCT", \%these_parameters, $rhparameter_db); + &WriteFile("Parameters/\U$thorn\E_private.c",\$dataout); - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - $dataout .= "\n\n"; - &WriteFile("\U$thorn\E"."_private.c",\$dataout); - - - $files .= " \U$thorn\E". "_private.c"; - $routines{"CCTK_BindingsParameters$thorn"."_private"} = "$thorn"; + $files .= " \U$thorn\E_private.c"; + $routines{"CCTK_BindingsParameters${thorn}_private"} = "$thorn"; # Generate the data header file - chdir ".."; - chdir "include"; - - @data = &CreateCStructureParameterHeader("CCTK_BindingsParameters$thorn"."_private", "PRIVATE_\U$thorn\E_STRUCT", \%these_parameters, $rhparameter_db); - - $structures{"PRIVATE_\U$thorn\E_STRUCT"} = "$thorn"."priv"; + $dataout = &CreateCStructureParameterHeader("CCTK_BindingsParameters${thorn}_private", "PRIVATE_\U$thorn\E_STRUCT", \%these_parameters, $rhparameter_db); + $structures{"PRIVATE_\U$thorn\E_STRUCT"} = "${thorn}priv"; - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - $dataout .= "\n\n"; - &WriteFile("ParameterCPrivate\U$thorn\E".".h",\$dataout); - - - $header_files{"\U$thorn\E PRIVATE"} = "ParameterCPrivate\U$thorn\E".".h"; - - chdir ".."; - chdir "Parameters"; + &WriteFile("include/ParameterCPrivate\U$thorn\E.h",\$dataout); + $header_files{"\U$thorn\E PRIVATE"} = "ParameterCPrivate\U$thorn\E.h"; } } - $dataout = ""; - $dataout .= "\#include <stdio.h>\n"; - $dataout .= "\#include <stdlib.h>\n"; - $dataout .= "\#include <string.h>\n"; - $dataout .= "\#include \"cctk_Config.h\"\n"; - $dataout .= "\#include \"cctk_Misc.h\"\n"; - $dataout .= "\#include \"cctk_WarnLevel.h\"\n"; + @thorns = split(' ',$rhinterface_db->{'THORNS'}); + @data = (); + push(@data, map ('extern int CCTKi_BindingsCreate' . $_ . 'Parameters(void);', @thorns)); + push(@data, ''); + push(@data, map ('extern int CCTKi_Bindings' . $_ . 'ParameterExtensions(void);', @thorns)); + push(@data, ''); + push(@data, ''); - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) - { - $dataout .= "extern int CCTKi_BindingsCreate$thorn"."Parameters(void);\n\n"; - } - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) - { - $dataout .= "extern int CCTKi_Bindings$thorn"."ParameterExtensions(void);\n\n"; - } + push(@data, 'int CCTKi_BindingsParametersInitialise(void);'); + push(@data, 'int CCTKi_BindingsParametersInitialise(void)'); + push(@data, '{'); - $dataout .= "int CCTKi_BindingsParametersInitialise(void);\n\n"; - $dataout .= "int CCTKi_BindingsParametersInitialise(void)\n"; - $dataout .= "\{\n\n"; - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) - { - $dataout .= " CCTKi_BindingsCreate$thorn"."Parameters();\n\n"; - } - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) - { - $dataout .= " CCTKi_Bindings$thorn"."ParameterExtensions();\n\n"; - } + push(@data, map (' CCTKi_BindingsCreate' . $_ . 'Parameters();', @thorns)); + push(@data, ''); + push(@data, map (' CCTKi_Bindings' . $_ . 'ParameterExtensions();', @thorns)); + push(@data, ''); - $dataout .= "return 0;\n"; - $dataout .= "}\n\n"; + push(@data, ' return 0;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - &WriteFile("BindingsParameters.c",\$dataout); + $dataout = join ("\n", @data); + &WriteFile('Parameters/BindingsParameters.c',\$dataout); $newfilelist = NewParamStuff($rhparameter_db, $rhinterface_db); - $dataout = ""; - $dataout .= "SRCS = BindingsParameters.c $files $newfilelist\n"; - &WriteFile("make.code.defn",\$dataout); + $dataout = "SRCS = BindingsParameters.c $files $newfilelist"; + &WriteFile('Parameters/make.code.defn',\$dataout); # Create the appropriate thorn parameter headers - chdir ".."; - chdir "include"; - - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { + $dataout = &CreateFortranThornParameterBindings($thorn, $rhparameter_db, $rhinterface_db); + &WriteFile("include/\U$thorn\E_FParameters.h",\$dataout); - @data = &CreateFortranThornParameterBindings($thorn, $rhparameter_db, $rhinterface_db); - - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - &WriteFile("\U$thorn\E"."_FParameters.h",\$dataout); - - $dataout = ""; $implementation = $rhinterface_db->{"\U$thorn\E IMPLEMENTS"}; - $dataout .= "\#ifndef _\U$thorn\E_PARAMETERS_H_\n\n"; - $dataout .= "\#define _\U$thorn\E_PARAMETERS_H_\n\n"; - - if($header_files{"GLOBAL"}) - { - $dataout .= "#include \"". $header_files{"GLOBAL"} ."\"\n"; - } - - if($header_files{"\U$implementation\E RESTRICTED"}) - { - $dataout .= "#include \"". $header_files{"\U$implementation\E RESTRICTED"}."\"\n"; - } - - if($header_files{"\U$thorn\E PRIVATE"}) - { - $dataout .= "#include \"".$header_files{"\U$thorn\E PRIVATE"}."\"\n"; - } - - $dataout .= "\n"; @data = (); - foreach $friend (split(" ",$rhparameter_db->{"\U$thorn\E SHARES implementations"})) + push(@data, '/*@@'); + push(@data, " \@header \U$thorn\E_CParameters.h"); + push(@data, ' @author Automatically generated by CreateParameterBindings.pl'); + push(@data, ' @desc'); + push(@data, " Declares parameters of thorn $thorn"); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, "#ifndef _\U$thorn\E_PARAMETERS_H_"); + push(@data, "#define _\U$thorn\E_PARAMETERS_H_ 1"); + push(@data, ''); + + if($header_files{'GLOBAL'}) { - $dataout .= "#include \"ParameterCRestricted\U$friend\E.h\"\n"; - - $rhinterface_db->{"IMPLEMENTATION \U$friend\E THORNS"} =~ m:([^ ]*):; - - $friend_thorn = $1; - - foreach $parameter (split(" ",$rhparameter_db->{"\U$thorn SHARES $friend\E variables"})) - { - $type = $rhparameter_db->{"\U$friend_thorn $parameter\E type"}; - - $type_string = &get_c_type_string($type); - - $line = "const $type_string $parameter = RESTRICTED_\U$friend\E_STRUCT.$parameter;"; - - push(@data, $line); - - } - } - - $dataout .= "\n"; - - $dataout .= "#define DECLARE_CCTK_PARAMETERS \\\n"; - - if($header_files{"GLOBAL"}) - { - $dataout .= " DECLARE_GLOBAL_PARAMETER_STRUCT_PARAMS \\\n"; + push(@data, "#include \"$header_files{'GLOBAL'}\""); } if($header_files{"\U$implementation\E RESTRICTED"}) { - $dataout .= " DECLARE_RESTRICTED_\U$implementation\E_STRUCT_PARAMS \\\n"; + push(@data, "#include \"" . $header_files{"\U$implementation\E RESTRICTED"} . "\""); } if($header_files{"\U$thorn\E PRIVATE"}) { - $dataout .= " DECLARE_PRIVATE_\U$thorn\E_STRUCT_PARAMS \\\n"; + push(@data, "#include \"" . $header_files{"\U$thorn\E PRIVATE"} . "\""); } - foreach $line (@data) + foreach $friend (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"})) { - $dataout .= " $line \\\n"; + push(@data, "#include \"ParameterCRestricted\U$friend\E.h\""); } + push(@data, ''); - $dataout .= " const void *cctk_pdummy_pointer;\n\n"; - - $dataout .= "#define USE_CCTK_PARAMETERS \\\n"; - - if($header_files{"GLOBAL"}) + @use = (); + push(@data, '#define DECLARE_CCTK_PARAMETERS \\'); + push(@use, '#define USE_CCTK_PARAMETERS \\'); + if($header_files{'GLOBAL'}) { - $dataout .= " USE_GLOBAL_PARAMETER_STRUCT_PARAMS \\\n"; + push(@data, ' DECLARE_GLOBAL_PARAMETER_STRUCT_PARAMS \\'); + push(@use, ' USE_GLOBAL_PARAMETER_STRUCT_PARAMS \\'); } if($header_files{"\U$implementation\E RESTRICTED"}) { - $dataout .= " USE_RESTRICTED_\U$implementation\E_STRUCT_PARAMS \\\n"; + push(@data, " DECLARE_RESTRICTED_\U$implementation\E_STRUCT_PARAMS \\"); + push(@use, " USE_RESTRICTED_\U$implementation\E_STRUCT_PARAMS \\"); } if($header_files{"\U$thorn\E PRIVATE"}) { - $dataout .= " USE_PRIVATE_\U$thorn\E_STRUCT_PARAMS \\\n"; + push(@data, " DECLARE_PRIVATE_\U$thorn\E_STRUCT_PARAMS \\"); + push(@use, " USE_PRIVATE_\U$thorn\E_STRUCT_PARAMS \\"); } - foreach $friend (split(" ",$rhparameter_db->{"\U$thorn\E SHARES implementations"})) + foreach $friend (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"})) { $rhinterface_db->{"IMPLEMENTATION \U$friend\E THORNS"} =~ m:([^ ]*):; - foreach $parameter (split(" ",$rhparameter_db->{"\U$thorn SHARES $friend\E variables"})) + $friend_thorn = $1; + + foreach $parameter (split(' ',$rhparameter_db->{"\U$thorn SHARES $friend\E variables"})) { - $dataout .= " cctk_pdummy_pointer = \&$parameter; \\\n"; + $type = $rhparameter_db->{"\U$friend_thorn $parameter\E type"}; + $type_string = &get_c_type_string($type); + + push(@data, " const $type_string$parameter = RESTRICTED_\U$friend\E_STRUCT.$parameter; \\"); + push(@use, " (void) ($parameter + 0); \\"); } } - $dataout .= " cctk_pdummy_pointer = cctk_pdummy_pointer;\n\n"; - - $dataout .= "#endif\n"; - &WriteFile("\U$thorn\E"."_CParameters.h",\$dataout); + push(@data, ' USE_CCTK_PARAMETERS'); + push(@data, ''); + push(@data, @use); + push(@data, ''); + push(@data, "#endif /* _\U$thorn\E_PARAMETERS_H_ */"); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + $dataout = join ("\n", @data); + &WriteFile("include/\U$thorn\E_CParameters.h",\$dataout); } # Write this one to a temporary file and read it back in # Can probably do this better - open(OUT, "| perl $cctk_home/lib/sbin/c_file_processor.pl $top/config-data > CParameterStructNames_temp.h") || die "Cannot create CParameterStructNames.h by running c_file_processor.pl"; + open(OUT, "| perl $cctk_home/lib/sbin/c_file_processor.pl $top/config-data > include/CParameterStructNames_temp.h") || die 'Cannot create CParameterStructNames.h by running c_file_processor.pl'; foreach $structure (keys %structures) { print OUT "#define $structure CCTK_FORTRAN_COMMON_NAME($structures{$structure})\n"; } - print OUT "\n"; close OUT; - open(IN,"<CParameterStructNames_temp.h"); - $dataout = ""; - while (<IN>) - { - $dataout .= $_; - } + open(IN,'< include/CParameterStructNames_temp.h'); + $dataout = join ('', <IN>); close IN; - &WriteFile("CParameterStructNames.h",\$dataout); + &WriteFile('include/CParameterStructNames.h',\$dataout); - $dataout = ""; - $dataout .= "#include \"CParameterStructNames.h\"\n\n"; - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + @data = (); + push(@data, '#include "CParameterStructNames.h"'); + push(@data, ''); + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $dataout .= "\#ifdef THORN\_IS\_$thorn\n"; - $dataout .= "\#include \"\U$thorn\E"."\_CParameters.h\"\n"; - $dataout .= "\#endif\n\n"; + push(@data, "#ifdef THORN\_IS\_$thorn"); + push(@data, "#include \"\U$thorn\E_CParameters.h\""); + push(@data, '#endif'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline } - &WriteFile("CParameters.h",\$dataout); + $dataout = join ("\n", @data); + &WriteFile('include/CParameters.h',\$dataout); - $dataout = ""; - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + @data = (); + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { - $dataout .= "\#ifdef THORN_IS\_$thorn\n"; - $dataout .= "\#include \"\U$thorn\E"."\_FParameters.h\"\n"; - $dataout .= "\#endif\n\n"; + push(@data, "#ifdef THORN\_IS\_$thorn"); + push(@data, "#include \"\U$thorn\E_FParameters.h\""); + push(@data, '#endif'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline } - &WriteFile("FParameters.h",\$dataout); - - $dataout = "/* get the CCTK datatype definitions */\n"; - $dataout .= "#include \"cctk_Types.h\"\n\n"; - $dataout .= "#ifdef CCODE\n"; - $dataout .= "#include \"CParameters.h\"\n"; - $dataout .= "#endif\n\n"; - $dataout .= "#ifdef FCODE\n"; - $dataout .= "#include \"FParameters.h\"\n"; - $dataout .= "#endif\n\n"; - &WriteFile("cctk_Parameters.h",\$dataout); + $dataout = join ("\n", @data); + &WriteFile('include/FParameters.h',\$dataout); + @data = (); + push(@data, '/* get the CCTK datatype definitions */'); + push(@data, '#include "cctk_Types.h"'); + push(@data, ''); + push(@data, '#ifdef CCODE'); + push(@data, '#include "CParameters.h"'); + push(@data, '#elif FCODE'); + push(@data, '#include "FParameters.h"'); + push(@data, '#endif'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - chdir $start_dir; + $dataout = join ("\n", @data); + &WriteFile('include/cctk_Parameters.h',\$dataout); + chdir $start_dir; } + sub NewParamStuff { my($rhparameter_db, $rhinterface_db) = @_; @@ -431,39 +323,48 @@ sub NewParamStuff my(@extensiondata); my(@data); - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) { $imp = $rhinterface_db->{"\U$thorn\E IMPLEMENTS"}; - push(@data, "#include <stdarg.h>"); - push(@data, ""); - push(@data, "#include \"cctk_Config.h\""); - push(@data, "#include \"cctk_Constants.h\""); - push(@data, "#include \"ParameterBindings.h\""); - - push(@data, "#include \"CParameterStructNames.h\""); - - foreach $block ("GLOBAL", "RESTRICTED", "PRIVATE") + push(@data, '/*@@'); + push(@data, " \@file Create${thorn}Parameters.c"); + push(@data, ' @author Automatically generated by CreateParameterBindings.pl'); + push(@data, ' @desc'); + push(@data, ' Creates/extends parameters for this thorn'); + push(@data, ' @enddesc'); + push(@data, ' @@*/'); + push(@data, ''); + push(@data, ''); + + push(@data, '#include <stdarg.h>'); + push(@data, ''); + push(@data, '#include "cctk_Config.h"'); + push(@data, '#include "cctk_Constants.h"'); + push(@data, '#include "ParameterBindings.h"'); + push(@data, '#include "CParameterStructNames.h"'); + + foreach $block ('GLOBAL', 'RESTRICTED', 'PRIVATE') { %these_parameters = &GetThornParameterList($thorn, $block, $rhparameter_db); if((keys %these_parameters > 0)) { - if($block eq "GLOBAL") + if($block eq 'GLOBAL') { - push(@data, "#include \"ParameterCGlobal.h\""); + push(@data, '#include "ParameterCGlobal.h"'); } - elsif($block eq "RESTRICTED") + elsif($block eq 'RESTRICTED') { push(@data, "#include \"ParameterCRestricted\U$imp\E.h\""); } - elsif($block eq "PRIVATE") + elsif($block eq 'PRIVATE') { push(@data, "#include \"ParameterCPrivate\U$thorn\E.h\""); } else { - die "Internal error"; + die 'Internal error'; } # print "Generating $block parameters for $thorn, providing $imp\n"; @@ -475,7 +376,7 @@ sub NewParamStuff # Now the parameter extensions # print $rhparameter_db->{"\U$thorn\E SHARES implementations"} . "\n"; - foreach $block (split(" ",$rhparameter_db->{"\U$thorn\E SHARES implementations"})) + foreach $block (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"})) { push(@data, "#include \"ParameterCRestricted\U$block\E.h\""); @@ -485,43 +386,41 @@ sub NewParamStuff } - push(@data, ""); - push(@data, "int CCTKi_BindingsCreate$thorn"."Parameters(void);\n"); - push(@data, "int CCTKi_BindingsCreate$thorn"."Parameters(void)"); - push(@data, "{"); + push(@data, ''); + push(@data, "int CCTKi_BindingsCreate${thorn}Parameters(void);"); + push(@data, "int CCTKi_BindingsCreate${thorn}Parameters(void)"); + push(@data, '{'); push(@data, @creationdata); - push(@data, " return 0;"); - push(@data, "}"); + push(@data, ' return 0;'); + push(@data, '}'); - push(@data, ""); - push(@data, "int CCTKi_Bindings$thorn"."ParameterExtensions(void);\n"); - push(@data, "int CCTKi_Bindings$thorn"."ParameterExtensions(void)"); - push(@data, "{"); + push(@data, ''); + push(@data, "int CCTKi_Bindings${thorn}ParameterExtensions(void);"); + push(@data, "int CCTKi_Bindings${thorn}ParameterExtensions(void)"); + push(@data, '{'); push(@data, @extensiondata); - push(@data, " return 0;"); - push(@data, "}"); + push(@data, ' return 0;'); + push(@data, '}'); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - $dataout = ""; - foreach $line (@data) - { - $dataout .= "$line\n"; - } - &WriteFile("Create$thorn"."Parameters.c",\$dataout); + $dataout = join ("\n", @data); + &WriteFile("Parameters/Create${thorn}Parameters.c",\$dataout); @data=(); @creationdata=(); @extensiondata=(); - $filelist .= " Create$thorn"."Parameters.c"; + $filelist .= " Create${thorn}Parameters.c"; } return $filelist; } + sub CreateParameterRegistrationStuff { my($block, $thorn, $imp, $rhparameter_db, %these_parameters) = @_; @@ -529,21 +428,21 @@ sub CreateParameterRegistrationStuff my($line); my($structure, $type, $n_ranges); - if($block eq "GLOBAL") + if($block eq 'GLOBAL') { - $structure="GLOBAL_PARAMETER_STRUCT"; + $structure='GLOBAL_PARAMETER_STRUCT'; } - elsif($block eq "RESTRICTED") + elsif($block eq 'RESTRICTED') { $structure="RESTRICTED_\U$imp\E_STRUCT"; } - elsif($block eq "PRIVATE") + elsif($block eq 'PRIVATE') { $structure = "PRIVATE_\U$thorn\E_STRUCT"; } else { - die "Internal error"; + die 'Internal error'; } # print "Thorn is $thorn\n"; @@ -570,31 +469,31 @@ sub CreateParameterRegistrationStuff $steerable = $rhparameter_db->{"\U$thorn $parameter\E steerable"}; if ($steerable =~ /never/i || $steerable =~/^$/) { - $steerable_type = "CCTK_STEERABLE_NEVER"; + $steerable_type = 'CCTK_STEERABLE_NEVER'; } elsif ($steerable =~ /always/i) { - $steerable_type = "CCTK_STEERABLE_ALWAYS"; + $steerable_type = 'CCTK_STEERABLE_ALWAYS'; } elsif ($steerable =~ /recover/i) { - $steerable_type = "CCTK_STEERABLE_RECOVER"; + $steerable_type = 'CCTK_STEERABLE_RECOVER'; } else { $message = "Illegal steerable type ($steerable) for parameter $parameter in $thorn"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } - $line=" CCTKi_ParameterCreate(\"$parameter\", /* The parameter name */\n". - " \"$thorn\", /* The thorn */\n". - " \"$type\", /* The parameter type*/\n". - " \"$block\", /* The scoping block */\n". - " $steerable_type, /* Is it steerable ? */\n". - " " . $rhparameter_db->{"\U$thorn $parameter\E description"} . ", /* The description */\n" . - " \"" . $quoted_default . "\", /* The default value */\n" . - " &($structure.$parameter), /* The actual data pointer */\n". - " $n_ranges /* How many allowed ranges it has */"; + $line=" CCTKi_ParameterCreate(\"$parameter\",\n" . + " \"$thorn\",\n" . + " \"$type\",\n" . + " \"$block\",\n" . + " $steerable_type,\n" . + " " . $rhparameter_db->{"\U$thorn $parameter\E description"} . ",\n" . + " \"" . $quoted_default . "\",\n" . + " &($structure.$parameter),\n" . + " $n_ranges"; for($range=1; $range <= $n_ranges; $range++) { @@ -617,19 +516,18 @@ sub CreateParameterRegistrationStuff # as the beginning of an escape sequence in C strings $quoted_range =~ s:\\:\\\\:g; - $line .= ",\n \"".$quoted_range."\", $range_description"; - + $line .= ",\n \"".$quoted_range."\",$range_description"; } - $line .=");\n"; + $line .= ");\n"; push(@data, $line); } - return @data; } + sub CreateParameterExtensionStuff { my($block, $thorn, $rhparameter_db) = @_; @@ -639,7 +537,7 @@ sub CreateParameterExtensionStuff # print "Extending $block from $thorn\n"; - foreach $parameter (split(" ",$rhparameter_db->{"\U$thorn\E SHARES \U$block\E variables"})) + foreach $parameter (split(' ',$rhparameter_db->{"\U$thorn\E SHARES \U$block\E variables"})) { $n_ranges = $rhparameter_db->{"\U$thorn $parameter\E ranges"}; @@ -662,15 +560,11 @@ sub CreateParameterExtensionStuff push(@data, " \"$parameter\","); push(@data, " \"$thorn\","); push(@data, " \"$quoted_range\","); - push(@data, " $range_description);"); + push(@data, " $range_description);"); push(@data, ""); - # print "Adding \"$quoted_range\" to $parameter\n"; - - } - } return @data; diff --git a/lib/sbin/GridFuncStuff.pl b/lib/sbin/GridFuncStuff.pl index 4a4c400f..c9d9c7b4 100644 --- a/lib/sbin/GridFuncStuff.pl +++ b/lib/sbin/GridFuncStuff.pl @@ -43,8 +43,6 @@ sub CreateVariableBindings { mkdir("include", 0755) || die "Unable to create include directory"; } - chdir "include"; - foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) { @@ -58,7 +56,7 @@ sub CreateVariableBindings $dataout .= "$line\n"; } - &WriteFile("$thorn\_arguments.h",\$dataout); + &WriteFile("include/$thorn\_arguments.h",\$dataout); } $dataout = "/* get the CCTK datatype definitions */\n"; @@ -66,7 +64,8 @@ sub CreateVariableBindings $dataout .= "#ifdef CCODE\n"; $dataout .= "#define CCTK_ARGUMENTS CCTK_CARGUMENTS\n"; $dataout .= "#define _CCTK_ARGUMENTS _CCTK_CARGUMENTS\n"; - $dataout .= "#define DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_CARGUMENTS\n"; + $dataout .= "#define DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_CARGUMENTS \\\n"; + $dataout .= " USE_CCTK_CARGUMENTS\n"; $dataout .= "#endif\n\n"; $dataout .= "#ifdef FCODE\n"; $dataout .= "#define CCTK_ARGUMENTS CCTK_FARGUMENTS\n"; @@ -86,15 +85,12 @@ sub CreateVariableBindings $dataout .= "#endif\n\n"; } - &WriteFile("cctk_Arguments.h",\$dataout); - - chdir ".."; + &WriteFile("include/cctk_Arguments.h",\$dataout); if(! -d "Variables") { mkdir("Variables", 0755) || die "Unable to create Variables directory"; } - chdir "Variables"; $filelist = "BindingsVariables.c"; @@ -122,7 +118,7 @@ sub CreateVariableBindings $dataout .= " return 0;\n}\n\n"; - &WriteFile("BindingsVariables.c",\$dataout); + &WriteFile("Variables/BindingsVariables.c",\$dataout); foreach $thorn (split(" ",$rhinterface_db->{"THORNS"})) { @@ -149,7 +145,7 @@ sub CreateVariableBindings $dataout .= " return 0;\n}\n"; - &WriteFile("$thorn.c",\$dataout); + &WriteFile("Variables/$thorn.c",\$dataout); $filelist .= " $thorn.c"; } @@ -165,12 +161,12 @@ sub CreateVariableBindings $dataout .= "$line\n"; } - &WriteFile("$thorn\_FortranWrapper.c",\$dataout); + &WriteFile("Variables/$thorn\_FortranWrapper.c",\$dataout); $filelist .= " $thorn\_FortranWrapper.c"; } $dataout = "SRCS = $filelist\n"; - &WriteFile("make.code.defn",\$dataout); + &WriteFile("Variables/make.code.defn",\$dataout); chdir $start_dir; } @@ -538,18 +534,16 @@ sub CreateCArgumentUses $suffix .= "_p"; } - push(@declarations, "cctk_dummy_pointer = \&$argument$suffix;"); + push(@declarations, "(void) ($argument$suffix + 0);"); } } } return @declarations; - } - #/*@@ # @routine CreateFortranArgumentList # @date Thu Jan 28 14:33:50 1999 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 diff --git a/lib/sbin/create_c_stuff.pl b/lib/sbin/create_c_stuff.pl index 0b0370c1..9618fcae 100644 --- a/lib/sbin/create_c_stuff.pl +++ b/lib/sbin/create_c_stuff.pl @@ -3,10 +3,10 @@ # @file create_c_stuff.pl # @date Mon Jan 11 10:53:22 1999 # @author Tom Goodale -# @desc -# +# @desc +# # @enddesc -# @version $Id$ +# @version $Id$ #@@*/ @@ -14,15 +14,9 @@ # @routine CreateParameterBindingFile # @date Wed Jan 20 15:20:23 1999 # @author Tom Goodale -# @desc +# @desc # Creates the bindings used to link the thorn parameters with the flesh. -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -# +# @enddesc #@@*/ sub CreateParameterBindingFile @@ -33,50 +27,32 @@ sub CreateParameterBindingFile my($type, $type_string); # Header Data - $line = "\#include <stdio.h>"; - push(@data, $line); - $line = "\#include <stdlib.h>"; - push(@data, $line); - $line = "\#include <string.h>"; - push(@data, $line); - $line = "\#include <stdarg.h>"; - push(@data, $line); - $line = "\#include \"cctk_Config.h\""; - push(@data, $line); - $line = "\#include \"CParameterStructNames.h\""; - push(@data, $line); - $line = "\#include \"cctk_Misc.h\""; - push(@data, $line); - $line = "\#include \"ParameterBindings.h\""; - push(@data, $line); - push(@data, ""); + push(@data, '#include "cctk_Config.h"'); + push(@data, '#include "CParameterStructNames.h"'); + push(@data, ''); # Create the structure - - push(@data,( "struct ", "{")); + push(@data, 'struct'); + push(@data, '{'); foreach $parameter (&order_params($rhparameters,$rhparameter_db)) { $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"}; - $type_string = &get_c_type_string($type); - $line = " " . $type_string ." " .$parameter . ";"; - - push(@data, $line); + push(@data, " $type_string$parameter;"); } # Some compilers don't like an empty structure. if((keys %$rhparameters) == 0) { - push(@data, " int dummy_parameter;"); + push(@data, ' int dummy_parameter;'); } push(@data, "} $structure;"); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - push(@data, ""); - - return @data; + return join ("\n", @data); } @@ -84,14 +60,9 @@ sub CreateParameterBindingFile # @routine get_c_type_string # @date Mon Jan 11 15:33:50 1999 # @author Tom Goodale -# @desc +# @desc # Returns the correct type string for a parameter -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory +# @enddesc #@@*/ sub get_c_type_string @@ -100,71 +71,65 @@ sub get_c_type_string my($type_string); - if($type eq "KEYWORD" || - $type eq "STRING" || - $type eq "SENTENCE") + if($type eq 'KEYWORD' || + $type eq 'STRING' || + $type eq 'SENTENCE') { - $type_string = "char *"; + $type_string = 'char *'; } - elsif($type eq "BOOLEAN") + elsif($type eq 'BOOLEAN') { - $type_string = "CCTK_INT "; - } - elsif($type eq "INT") + $type_string = 'CCTK_INT '; + } + elsif($type eq 'INT') { - $type_string = "CCTK_INT "; + $type_string = 'CCTK_INT '; } - elsif($type eq "INT2") + elsif($type eq 'INT2') { - $type_string = "CCTK_INT2 "; + $type_string = 'CCTK_INT2 '; } - elsif($type eq "INT4") + elsif($type eq 'INT4') { - $type_string = "CCTK_INT4 "; + $type_string = 'CCTK_INT4 '; } - elsif($type eq "INT8") + elsif($type eq 'INT8') { - $type_string = "CCTK_INT8 "; + $type_string = 'CCTK_INT8 '; } - elsif($type eq "REAL") + elsif($type eq 'REAL') { - $type_string = "CCTK_REAL "; + $type_string = 'CCTK_REAL '; } - elsif($type eq "REAL4") + elsif($type eq 'REAL4') { - $type_string = "CCTK_REAL4 "; + $type_string = 'CCTK_REAL4 '; } - elsif($type eq "REAL8") + elsif($type eq 'REAL8') { - $type_string = "CCTK_REAL8 "; + $type_string = 'CCTK_REAL8 '; } - elsif($type eq "REAL16") + elsif($type eq 'REAL16') { - $type_string = "CCTK_REAL16 "; + $type_string = 'CCTK_REAL16 '; } else { - $message = "Unknown parameter type '$type'"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,"Unknown parameter type '$type'",'',__LINE__,__FILE__); } return $type_string; - } + #/*@@ # @routine GetThornParameterList # @date Wed Jan 20 15:29:40 1999 # @author Tom Goodale -# @desc +# @desc # Gets a list of all parameters in a particular block in a thorn. # Returns a hash table. -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory +# @enddesc #@@*/ sub GetThornParameterList @@ -174,7 +139,7 @@ sub GetThornParameterList $params = $rhparameter_db->{"\U$thorn $block\E variables"}; - foreach $parameter (split(" ", $params)) + foreach $parameter (split(' ', $params)) { if($parameter =~ m:[^ ]:) { @@ -185,6 +150,7 @@ sub GetThornParameterList return %parameter_list; } + sub CreateCStructureParameterHeader { my($prefix, $structure, $rhparameters, $rhparameter_db) = @_; @@ -195,46 +161,49 @@ sub CreateCStructureParameterHeader my(@use); # Create the structure - - push(@data,("#ifdef __cplusplus", "extern \"C\"", "{", "#endif", "")); - push(@data,( "extern struct ", "{")); + push(@data, '#ifdef __cplusplus'); + push(@data, 'extern "C"'); + push(@data, '{'); + push(@data, '#endif'); + push(@data, ''); + push(@data, 'extern struct'); + push(@data, '{'); foreach $parameter (&order_params($rhparameters, $rhparameter_db)) { $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"}; - $type_string = &get_c_type_string($type); - $line = " ".$type_string ." " .$parameter . ";"; - - push(@data, $line); - - $line = " const $type_string $parameter = $structure.$parameter; \\"; - - push(@definition, $line); - - $line = " cctk_pdummy_pointer = \&$parameter; \\"; - - push(@use, $line); + push(@data, " $type_string $parameter;"); + push(@definition, " const $type_string $parameter = $structure.$parameter; \\"); + push(@use, " (void) ($parameter + 0); \\"); } # Some compilers don't like an empty structure. if((keys %$rhparameters) == 0) { - push(@data, " int dummy_parameter;"); + push(@data, ' int dummy_parameter;'); } - push(@data, "} $structure;", ""); + push(@data, "} $structure;"); + push(@data, ''); - push(@data,("#ifdef __cplusplus", "}", "#endif", "")); + push(@data, '#ifdef __cplusplus'); + push(@data, '}'); + push(@data, '#endif'); + push(@data, ''); - push(@data, "#define DECLARE_$structure"."_PARAMS \\", @definition); - push(@data, ""); - push(@data, "#define USE_$structure"."_PARAMS \\", @use); + push(@data, "#define DECLARE_${structure}_PARAMS \\"); + push(@data, @definition); + push(@data, ''); + push(@data, "#define USE_${structure}_PARAMS \\"); + push(@data, @use); + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline - return @data; + return join ("\n", @data); } + sub order_params { my($rhparameters, $rhparameter_db) = @_; @@ -246,87 +215,79 @@ sub order_params { $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"}; - if($type eq "KEYWORD" || - $type eq "STRING" || - $type eq "SENTENCE") + if($type eq 'KEYWORD' || + $type eq 'STRING' || + $type eq 'SENTENCE') { push(@string_params, $parameter); } - elsif($type eq "BOOLEAN" || - $type eq "INT") + elsif($type eq 'BOOLEAN' || + $type eq 'INT') { push(@int_params, $parameter); } - elsif($type eq "REAL") + elsif($type eq 'REAL') { push(@float_params, $parameter); } else { - $message = "Unknown parameter type '$type'"; - &CST_error(0,$message,__LINE__,__FILE__); + $message = "Unknown parameter type '$type'"; + &CST_error(0,$message,__LINE__,__FILE__); } - } - + return (@float_params, @string_params, @int_params); } -sub create_parameter_code -{ - my($structure, $implementation,$parameter, $rhparameter_db) = @_; - my($type, $type_string); - my($line, @lines); - my($default); - my($temp_default); - - $default = $rhparameter_db->{"\U$implementation $parameter\E default"}; - $type = $rhparameter_db->{"\U$implementation $parameter\E type"}; - - $type_string = &get_c_type_string($type); - - if($type_string eq "char *") - { - $line = " $structure" .".$parameter = malloc(" - . (length($default)-1). "\*sizeof(char));"; - push(@lines, $line); - - $line = " if($structure.$parameter)"; - push(@lines, $line); - - $line = " strcpy($structure.$parameter, $default);"; - push(@lines, $line); - } - elsif($type eq "BOOLEAN") - { - # Logicals need to be done specially. - - # Strip out any quote marks, and spaces at start and end. - $temp_default = $default; - $temp_default =~ s:\"::g; - $temp_default =~ s:\s*$:: ; - $temp_default =~ s:^\s*:: ; - - $line = " CCTK_SetLogical(\&($structure.$parameter),\"$temp_default\");"; - push(@lines, $line); - } - else - { - $line = " $structure.$parameter = $default;"; - push(@lines, $line); - } - - $line = "CCTKi_ParameterCreate($parameter, $implementation, - \"foobar\",\"" . $rhparameter_db->{"\U$implementation $parameter\E type"}."\" - const char *scope, - int steerable, - const char *description, - const char *defval, - void *data)"; +#sub create_parameter_code +#{ +# my($structure, $implementation,$parameter, $rhparameter_db) = @_; +# my($type, $type_string); +# my($line, @lines); +# my($default); +# my($temp_default); +# +# $default = $rhparameter_db->{"\U$implementation $parameter\E default"}; +# $type = $rhparameter_db->{"\U$implementation $parameter\E type"}; +# +# $type_string = &get_c_type_string($type); +# +# if($type_string eq 'char *') +# { +# $line = " $structure.$parameter = malloc(" . (length($default)-1) . '*sizeof(char));'; +# push(@lines, $line); +# +# push(@lines, " if ($structure.$parameter)"); +# push(@lines, " strcpy($structure.$parameter, $default);"); +# } +# elsif($type eq "BOOLEAN") +# { +# # Logicals need to be done specially. +# +# # Strip out any quote marks, and spaces at start and end. +# $temp_default = $default; +# $temp_default =~ s:\"::g; +# $temp_default =~ s:\s*$:: ; +# $temp_default =~ s:^\s*:: ; +# +# push(@lines, " CCTK_SetLogical(\&($structure.$parameter),\"$temp_default\");"); +# } +# else +# { +# push(@lines, " $structure.$parameter = $default;"); +# } +# +# $line = "CCTKi_ParameterCreate($parameter, $implementation, +# \"foobar\",\"" . $rhparameter_db->{"\U$implementation $parameter\E type"}."\" +# const char *scope, +# int steerable, +# const char *description, +# const char *defval, +# void *data)"; +# +# return @lines; +#} - return @lines; -} - 1; - diff --git a/lib/sbin/create_fortran_stuff.pl b/lib/sbin/create_fortran_stuff.pl index 502fee90..2e3c881c 100644 --- a/lib/sbin/create_fortran_stuff.pl +++ b/lib/sbin/create_fortran_stuff.pl @@ -3,9 +3,9 @@ # @file create_fortran_stuff.pl # @date Tue Jan 12 09:52:35 1999 # @author Tom Goodale -# @desc -# -# @enddesc +# @desc +# +# @enddesc #@@*/ sub CreateFortranThornParameterBindings @@ -19,66 +19,66 @@ sub CreateFortranThornParameterBindings my(%alias_names); my(%num_aliases); - push(@file, "#define DECLARE_CCTK_PARAMETERS \\"); + push(@file, '#define DECLARE_CCTK_PARAMETERS \\'); # Generate all global parameters %these_parameters = &get_global_parameters($rhparameter_db); if((keys %these_parameters) > 0) { - @data = &CreateFortranCommonDeclaration("cctk_params_global", \%these_parameters, $rhparameter_db); + @data = &CreateFortranCommonDeclaration('cctk_params_global', \%these_parameters, $rhparameter_db); - foreach $line (@data) + if (@data) { - push(@file, "$line&&\\"); + push(@file, join ("&&\\\n", @data) . "&&\\"); } } # Generate all restricted parameters of this thorn - %these_parameters = &GetThornParameterList($thorn, "RESTRICTED", $rhparameter_db); + %these_parameters = &GetThornParameterList($thorn, 'RESTRICTED', $rhparameter_db); if((keys %these_parameters > 0)) { $implementation = $rhinterface_db->{"\U$thorn\E IMPLEMENTS"}; - - @data = &CreateFortranCommonDeclaration("$implementation"."rest", \%these_parameters, $rhparameter_db); - foreach $line (@data) + @data = &CreateFortranCommonDeclaration("${implementation}rest", \%these_parameters, $rhparameter_db); + + if (@data) { - push(@file, "$line&&\\"); + push(@file, join ("&&\\\n", @data) . "&&\\"); } } # Generate all private parameters of this thorn - %these_parameters = &GetThornParameterList($thorn, "PRIVATE", $rhparameter_db); + %these_parameters = &GetThornParameterList($thorn, 'PRIVATE', $rhparameter_db); if((keys %these_parameters > 0)) { - @data = &CreateFortranCommonDeclaration("$thorn"."priv", \%these_parameters, $rhparameter_db); + @data = &CreateFortranCommonDeclaration("${thorn}priv", \%these_parameters, $rhparameter_db); - foreach $line (@data) + if (@data) { - push(@file, "$line&&\\"); + push(@file, join ("&&\\\n", @data) . "&&\\"); } } # Parameters from friends - # This number can be local to each thorn - it doesn't matter if + # This number can be local to each thorn - it doesn't matter if # members of a common block get different names in different # thorns, especially if the variable isn't being used ! $num_aliases = 0; - foreach $friend (split(" ",$rhparameter_db->{"\U$thorn\E SHARES implementations"})) + foreach $friend (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"})) { # Determine which thorn provides this friend implementation $rhinterface_db->{"IMPLEMENTATION \U$friend\E THORNS"} =~ m:([^ ]*):; - + $friend_thorn = $1; - - %these_parameters = &GetThornParameterList($friend_thorn, "RESTRICTED", $rhparameter_db); - + + %these_parameters = &GetThornParameterList($friend_thorn, 'RESTRICTED', $rhparameter_db); + %alias_names = (); foreach $parameter (sort(keys %these_parameters)) @@ -86,30 +86,30 @@ sub CreateFortranThornParameterBindings # Alias the parameter unless it is one we want. if(($rhparameter_db->{"\U$thorn SHARES $friend\E variables"} =~ m:( )*$parameter( )*:) && (length($1) > 0)||length($2)>0||$1 eq $rhparameter_db->{"\U$thorn SHARES $friend\E variables"}) { - $alias_names{$parameter} = "$parameter"; + $alias_names{$parameter} = $parameter; } else { - $alias_names{$parameter} = "CCTKH".$num_aliases; + $alias_names{$parameter} = "CCTKH$num_aliases"; $num_aliases++; } } - @data = &CreateFortranCommonDeclaration("$friend"."rest", \%these_parameters, $rhparameter_db, \%alias_names); - - foreach $line (@data) + @data = &CreateFortranCommonDeclaration("${friend}rest", \%these_parameters, $rhparameter_db, \%alias_names); + + if (@data) { - push(@file, "$line&&\\"); + push(@file, join ("&&\\\n", @data) . "&&\\"); } - - } - push(@file, ("","")); - - return (@file); + push(@file, ''); + push(@file, ''); + + return join ("\n", @file); } + sub CreateFortranCommonDeclaration { my($common_block, $rhparameters, $rhparameter_db, $rhaliases) = @_; @@ -132,43 +132,35 @@ sub CreateFortranCommonDeclaration $definition = "COMMON /$common_block/"; - $sepchar = ""; + $sepchar = ''; foreach $parameter (&order_params($rhparameters,$rhparameter_db)) { $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"}; - + $type_string = &get_fortran_type_string($type); if($aliases == 0) { $line = "$type_string $parameter"; - } - else - { - $line = "$type_string $rhaliases->{$parameter}"; - } - - push(@data, $line); - - if($aliases == 0) - { $definition .= "$sepchar$parameter"; } else { + $line = "$type_string $rhaliases->{$parameter}"; $definition .= "$sepchar$rhaliases->{$parameter}"; } + push(@data, $line); - $sepchar = ","; + $sepchar = ','; } push(@data, $definition); return @data; } - + sub get_fortran_type_string { @@ -176,25 +168,25 @@ sub get_fortran_type_string my($type_string); - if($type eq "KEYWORD" || - $type eq "STRING" || - $type eq "SENTENCE") + if($type eq 'KEYWORD' || + $type eq 'STRING' || + $type eq 'SENTENCE') { - $type_string = "CCTK_STRING "; - } - elsif($type eq "BOOLEAN" || - $type eq "INT") + $type_string = 'CCTK_STRING '; + } + elsif($type eq 'BOOLEAN' || + $type eq 'INT') { - $type_string = "CCTK_INT"; + $type_string = 'CCTK_INT'; } - elsif($type eq "REAL") + elsif($type eq 'REAL') { - $type_string = "CCTK_REAL "; + $type_string = 'CCTK_REAL '; } else { $message = "Unknown parameter type '$type'"; - &CST_error(0,$message,"",__LINE__,__FILE__); + &CST_error(0,$message,'',__LINE__,__FILE__); } return $type_string; diff --git a/lib/sbin/output_config.pl b/lib/sbin/output_config.pl deleted file mode 100644 index 6d632bd9..00000000 --- a/lib/sbin/output_config.pl +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/perl -s -#/*@@ -# @file output_config.pl -# @date Tue Jan 19 18:59:59 1999 -# @author Tom Goodale -# @desc -# Outputs all configuration data -# @enddesc -#@@*/ - -sub OutputFile -{ - my($directory, $file, @data) = @_; - - $dataout = ""; - - foreach $line (@data) - { - $dataout .= "$line\n"; - } - - &WriteFile("$directory/$file",\$dataout); - -} - -1; - |