]> www.ginac.de Git - ginac.git/blob - cint/dummies.pl
86f797a6ad89a5d84005d3266657809a9dc7ebb4
[ginac.git] / cint / dummies.pl
1 # Create files containing dummies, wrappers and so on to overcome certain
2 # deficiencies in Cint.  In an ideal world it would be unnecessary.
3
4 $header='dummies.h';
5 $source='dummies.cpp';
6
7 # Generate a header file which is additionally included in cint
8 # to work around the broken overloading resolution of cint for
9 # C library functions and other problems.
10 # E.g: if a function declared as ex sin(ex const & x) and called
11 # with sin(y) where y is a symbol, cint favours a conversion from
12 # symbol to void * to double over symbol to ex and thus calls the
13 # C math library function double sin(double x) (sigh!)
14
15 # types which need help to be converted to ex
16 @types=('symbol','function','constant','idx','lorentzidx','coloridx');
17 @moretypes=('numeric','int','double');
18 @extype=('ex');
19
20 # functions with one parameter
21 @functions1p=('sin','cos','tan','asin','acos','atan','exp','log','sqrt',
22               'sinh','cosh','tanh','abs');
23
24 # functions with two parameters
25 @functions2p=('pow','atan2');
26
27 open OUT,">$header";
28
29 $opening=<<END_OF_OPENING;
30 /*  dummies.h
31  *
32  *  Dummies and wrappers to overcome certain deficiencies of Cint.
33  *  This file was generated automatically by dummies.pl.
34  *  Please do not modify it directly, edit the perl script instead!
35  */
36
37 END_OF_OPENING
38
39 print OUT $opening;
40
41 foreach $f (@functions1p) {
42     print OUT "// fixes for $f(x)\n";
43     foreach $t (@types) {
44         print OUT "inline ex $f($t const & x) { return $f(ex(x)); }\n";
45     }
46     print OUT "\n";
47 }  
48
49 sub inlines2 {
50     my ($types1ref,$types2ref)=@_;
51     foreach $t1 (@$types1ref) {
52         foreach $t2 (@$types2ref) {
53             print OUT "inline ex $f($t1 const & x,$t2 const & y) {\n";
54             print OUT "    return $f(ex(x),ex(y));\n";
55             print OUT "}\n";
56         }
57     }
58 }
59
60 foreach $f (@functions2p) {
61     print OUT "// fixes for $f(x,y)\n";
62     inlines2(\@types,\@types);
63     inlines2(\@types,\@moretypes);
64     inlines2(\@moretypes,\@types);
65     inlines2(\@extype,\@moretypes);
66     inlines2(\@moretypes,\@extype);
67     print OUT "\n";
68 }  
69
70 close OUT;
71
72 # Create a file containing stubs that may be necessary because Cint always
73 # wants to link against anything that was ever declared:
74
75 open OUT,">$source";
76
77 $opening=<<END_OF_OPENING;
78 /*  dummies.cpp
79  *
80  *  Dummies and stubs to overcome certain deficiencies of Cint.
81  *  This file was generated automatically by dummies.pl.
82  *  Please do not modify it directly, edit the perl script instead!
83  */
84
85 #include <ginac/function.h>
86
87 #ifndef NO_NAMESPACE_GINAC
88 using namespace GiNaC;
89 #endif // ndef NO_NAMESPACE_GINAC
90
91 END_OF_OPENING
92
93 print OUT $opening;
94 print OUT "void ginsh_get_ginac_functions(void) { }\n";
95
96 close OUT;
97
98 # Create dummies