summaryrefslogtreecommitdiff
path: root/lib/sbin/config_parser.pl
blob: 180a2aebdac7c9b6891c36ea514387a67c14a520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#! /usr/bin/perl

$in = shift(@ARGV);
$tmphome = shift(@ARGV);

if (!$in || !$tmphome) 
{
    printf "Usage: xxx indir tmpdir";
}

# Set up the CCTK home directory
$cachome = $ENV{'CCTK_HOME'} || "$ENV{HOME}/CCTK";
$cachome =~ s:/$::g;

#
#if (!-e "$cachome/lib/perl/thorn_utils.pl" ) {
#    print <<EOE;
#
#ERROR: Cannot find the cactus perl libraries!
#---------------------------------------------
#This error usually means that either CACTUS_HOME is
#set incorrectly, or that your distribution is not
#in ~/cactus. Remeber that CACTUS_HOME has
#to point to the directory above cactus. 
#
#I was looking in
#
#    $cachome/lib/perl
#  
#when I failed.
#
#
#EOE
#    exit;
#}


require "lib/sbin/parameter_parser.pl";
require "lib/sbin/interface_parser.pl";

%thorns = &create_thorn_list;

%interface_database = create_interface_database(%thorns);

%parameter_database = create_parameter_database(%thorns);


@parameter_structure = &create_parameter_structure(%parameter_database);


foreach $line (@parameter_structure)
{
  print "$line\n";
}

@c_parameter_declarations = &create_c_parameter_declarations("test2",%parameter_database);

foreach $line (@c_parameter_declarations)
{
  print "$line\n";
}

#&print_parameter_database(%parameter_database);

#&print_interface_database(%interface_database);

sub create_c_parameter_declarations
{
  local($implementation,%parameter_database) = @_;
  local(@declarations);
  local($line);
  local($type, $type_string, $friend, $block);

  # Deal with variables defined in this thorn. 
  foreach $block ("PUBLIC", "PRIVATE", "PROTECTED")
  {
    $entry = "\U$implementation $block\E variables";
    foreach $parameter (split(/ /, $parameter_database{$entry}))
    {
      $type = @parameter_database{"\U$implementation $parameter\E type"};
      
      $type_string = &get_c_type_string($type);
      
      $line = "  ". $type_string .$parameter . 
	" = _cctk_params." . "\U$implementation\E_\L$parameter\E;";
      
      push(@declarations, $line);
    }
  }

  # Deal with friend variables. 
  foreach $friend (split(/ /,$parameter_database{"\U$implementations\E FRIEND implementations"}))
  {
    $other_implementation = "\U$friend\E";
    $entry = "\U$implementation FRIEND $friend\E variables";
    foreach $parameter (split(/ /, $parameter_database{$entry}))
    {
      $type = @parameter_database{"\U$other_implementation $parameter\E type"};
      
      $type_string = &get_c_type_string($type);
      
      $line = "  ". $type_string .$parameter . 
	" = _cctk_params." . "\U$other_implementation\E_\L$parameter\E;";
      
      push(@declarations, $line);
    }
  }	  
  return @declarations;
}

sub create_parameter_structure
{
  local(%parameter_database) = @_;
  local(@structure);
  local($line, $entry, $thorn, $parameter, $type_string);

  $line = "struct CCTK_PARAMS {";

  push(@structure, $line);

  foreach $entry ( keys %parameter_database )
  {
    if($entry =~ m:([^ ]*) ([^ ]*) type:)
    {
      $thorn = $1;
      $parameter = "\L$2\E";
      $type_string = &get_c_type_string($parameter_database{$entry});

      $line = "  ". $type_string . $thorn . "_". $parameter .";";

      push(@structure, $line);
    }
  }

  $line = "};";
  push(@structure, $line);
  
  return @structure;
}
      
sub create_thorn_list
{
  return ("flesh", "toolkits/test/flesh", 
	   "test1", "toolkits/test/test1", 
	   "test2", "toolkits/test/test2");
}

sub get_c_type_string
{
  local($type) = @_;
  local($type_string);


  if($type eq "KEYWORD" ||
     $type eq "STRING"  ||
     $type eq "SENTENCE")
  {
    $type_string = "char *";
  }
  elsif($type eq "LOGICAL" ||
	$type eq "INTEGER")
  {
    $type_string = "int ";
  }
  elsif($type eq "REAL")
  {
    $type_string = "Double ";
  }
  else
  {
    die("Unknown parameter type '$type'");
  }

  return $type_string;

}