]> www.ginac.de Git - ginac.git/blob - cint/genheader.pl
genheader.pl: create a header file 'cint_workaround.h' to fix the broken
[ginac.git] / cint / genheader.pl
1 #!/usr/bin/perl -w
2
3 # Generate a header file which is additionally included in cint
4 # to work around the broken overloading resolution of cint for
5 # C library functions
6 # e.g. if a function declared as ex sin(ex const & x) and called
7 # with sin(y) where y is a symbol, cint favours a conversion from
8 # symbol to void * to double over symbol to ex and thus calls the
9 # C math library function double sin(double x) (sigh!)
10
11 $header='cint_workaround.h';
12
13 # types which need help to be converted to ex
14 @types=('symbol','function','constant','idx','lorentzidx','coloridx');
15 @moretypes=('numeric','int','double');
16 @extype=('ex');
17
18 # functions with one parameter
19 @functions1p=('sin','cos','tan','asin','acos','atan','exp','log','sqrt',
20               'sinh','cosh','tanh','abs');
21
22 # functions with two parameters
23 @functions2p=('pow','atan2');
24
25 open OUT,">$header";
26
27 foreach $f (@functions1p) {
28     print OUT "// fixes for $f(x)\n";
29     foreach $t (@types) {
30         print OUT "inline ex $f($t const & x) { return $f(ex(x)); }\n";
31     }
32     print OUT "\n";
33 }  
34
35 sub inlines2 {
36     my ($types1ref,$types2ref)=@_;
37     foreach $t1 (@$types1ref) {
38         foreach $t2 (@$types2ref) {
39             print OUT "inline ex $f($t1 const & x,$t2 const & y) {\n";
40             print OUT "    return $f(ex(x),ex(y));\n";
41             print OUT "}\n";
42         }
43     }
44 }
45
46 foreach $f (@functions2p) {
47     print OUT "// fixes for $f(x,y)\n";
48     inlines2(\@types,\@types);
49     inlines2(\@types,\@moretypes);
50     inlines2(\@moretypes,\@types);
51     inlines2(\@extype,\@moretypes);
52     inlines2(\@moretypes,\@extype);
53     print OUT "\n";
54 }  
55
56 close OUT;
57
58