summaryrefslogtreecommitdiff
path: root/lib/sbin/create_c_stuff.pl
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2003-01-07 10:52:04 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2003-01-07 10:52:04 +0000
commitaa43e2844030b15e54af1f427334894148290473 (patch)
tree2940ae75e3bf9182eda5f42efc025f206051f481 /lib/sbin/create_c_stuff.pl
parentcb5a1fdb849b82aba9f9aa727790d656349396a0 (diff)
Get rid of superfluous typecasts in DECLARE_CCTK_PARAMETERS.
Declare (C pointers to) string parameters as 'const char *const' pointers. This closes Cactus-1350. git-svn-id: http://svn.cactuscode.org/flesh/trunk@3074 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/create_c_stuff.pl')
-rw-r--r--lib/sbin/create_c_stuff.pl47
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/sbin/create_c_stuff.pl b/lib/sbin/create_c_stuff.pl
index cf635e5a..34aba7de 100644
--- a/lib/sbin/create_c_stuff.pl
+++ b/lib/sbin/create_c_stuff.pl
@@ -24,7 +24,7 @@ sub CreateParameterBindingFile
my($prefix, $structure, $rhparameters, $rhparameter_db) = @_;
my($line,@data);
my(%parameters);
- my($type, $type_string);
+ my($type);
# Header Data
push(@data, '#include "cctk_Config.h"');
@@ -38,7 +38,7 @@ sub CreateParameterBindingFile
foreach $parameter (&order_params($rhparameters,$rhparameter_db))
{
my $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"};
- my $type_string = &get_c_type_string($type);
+ my ($type_string) = &get_c_type_string($type);
my $realname = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E realname"};
@@ -51,7 +51,7 @@ sub CreateParameterBindingFile
$suffix = "[$array_size]";
}
- push(@data, " $type_string$realname$suffix;");
+ push(@data, " $type_string $realname$suffix;");
}
# Some compilers don't like an empty structure.
@@ -72,64 +72,73 @@ sub CreateParameterBindingFile
# @date Mon Jan 11 15:33:50 1999
# @author Tom Goodale
# @desc
-# Returns the correct type string for a parameter
+# Returns the correct type string for a parameter, both for declaring it
+# as modifiable member of a structure as well as a assign-once local variable
# @enddesc
#@@*/
sub get_c_type_string
{
my($type) = @_;
- my($type_string);
+ my($type_string, $decl_type_string);
+ $decl_type_string = '';
if($type eq 'KEYWORD' ||
$type eq 'STRING' ||
$type eq 'SENTENCE')
{
$type_string = 'char *';
+ $decl_type_string = 'char *const';
}
elsif($type eq 'BOOLEAN')
{
- $type_string = 'CCTK_INT ';
+ $type_string = 'CCTK_INT';
}
elsif($type eq 'INT')
{
- $type_string = 'CCTK_INT ';
+ $type_string = 'CCTK_INT';
}
elsif($type eq 'INT2')
{
- $type_string = 'CCTK_INT2 ';
+ $type_string = 'CCTK_INT2';
}
elsif($type eq 'INT4')
{
- $type_string = 'CCTK_INT4 ';
+ $type_string = 'CCTK_INT4';
}
elsif($type eq 'INT8')
{
- $type_string = 'CCTK_INT8 ';
+ $type_string = 'CCTK_INT8';
}
elsif($type eq 'REAL')
{
- $type_string = 'CCTK_REAL ';
+ $type_string = 'CCTK_REAL';
}
elsif($type eq 'REAL4')
{
- $type_string = 'CCTK_REAL4 ';
+ $type_string = 'CCTK_REAL4';
}
elsif($type eq 'REAL8')
{
- $type_string = 'CCTK_REAL8 ';
+ $type_string = 'CCTK_REAL8';
}
elsif($type eq 'REAL16')
{
- $type_string = 'CCTK_REAL16 ';
+ $type_string = 'CCTK_REAL16';
}
else
{
&CST_error(0,"Unknown parameter type '$type'",'',__LINE__,__FILE__);
}
+ if (! $decl_type_string)
+ {
+ $decl_type_string = $type_string;
+ }
+ # add the const qualifier for assign-once local variables
+ $decl_type_string = "const $decl_type_string";
- return $type_string;
+ return ($type_string, $decl_type_string);
}
@@ -183,7 +192,7 @@ sub CreateCStructureParameterHeader
foreach $parameter (&order_params($rhparameters, $rhparameter_db))
{
my $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"};
- my $type_string = &get_c_type_string($type);
+ my ($type_string, $decl_type_string) = &get_c_type_string($type);
my $array_size = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E array_size"};
@@ -192,14 +201,14 @@ sub CreateCStructureParameterHeader
if($array_size)
{
- $varprefix = '*';
+ $varprefix = '*const ';
$suffix = "[$array_size]";
}
my $realname = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E realname"};
push(@data, " $type_string $realname$suffix;");
- push(@definition, " const $type_string $varprefix$parameter = (const $type_string $varprefix)$structure.$realname; \\");
+ push(@definition, " $decl_type_string $varprefix$parameter = $structure.$realname; \\");
push(@use, " (void) ($parameter + 0); \\");
}
@@ -260,7 +269,7 @@ sub order_params
&CST_error(0,$message,__LINE__,__FILE__);
}
}
-
+
return (@float_params, @string_params, @int_params);
}