1 # Create files containing dummies, wrappers and so on to overcome certain
2 # deficiencies in Cint. In an ideal world it would be unnecessary.
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!)
15 # types which need help to be converted to ex
16 @types=('symbol','function','constant','idx','lorentzidx','coloridx');
17 @moretypes=('numeric','int','double');
20 # C math library functions with one parameter and return type 'function'
21 @cfunc_1p_function=('sin','cos','tan','asin','acos','atan','exp','log',
22 'sinh','cosh','tanh','abs');
24 # C math library functions with one parameter and return type 'ex'
25 @cfunc_1p_ex=('sqrt');
27 # C math library functions with two parameters and return type 'function'
28 @cfunc_2p_function=('atan2');
30 # C math library functions with two parameters and return type 'ex'
33 @binops_ex=('+','-','*','/','%');
34 @binops_relational=('==','!=','<','<=','>','>=');
35 @binops_exconstref=('+=','-=','*=','/=');
39 $opening=<<END_OF_OPENING;
42 * Dummies and wrappers to overcome certain deficiencies of Cint.
43 * This file was generated automatically by dummies.pl.
44 * Please do not modify it directly, edit the perl script instead!
52 my ($rettype,$funcsref)=@_;
53 foreach $f (@$funcsref) {
54 print OUT "// fixes for $rettype $f(x)\n";
56 print OUT "inline $rettype $f($t const & x) { return $f(ex(x)); }\n";
62 inline_cfunc_1p('function',\@cfunc_1p_function);
63 inline_cfunc_1p('ex',\@cfunc_1p_ex);
65 sub inline_single_cfunc_2p {
66 my ($rettype,$types1ref,$types2ref)=@_;
67 foreach $t1 (@$types1ref) {
68 foreach $t2 (@$types2ref) {
69 print OUT "inline $rettype $f($t1 const & x,$t2 const & y) {\n";
70 print OUT " return $f(ex(x),ex(y));\n";
77 my ($rettype,$funcsref)=@_;
78 foreach $f (@$funcsref) {
79 print OUT "// fixes for $rettype $f(x,y)\n";
80 inline_single_cfunc_2p($rettype,\@types,\@types);
81 inline_single_cfunc_2p($rettype,\@types,\@moretypes);
82 inline_single_cfunc_2p($rettype,\@moretypes,\@types);
83 inline_single_cfunc_2p($rettype,\@extype,\@moretypes);
84 inline_single_cfunc_2p($rettype,\@moretypes,\@extype);
89 inline_cfunc_2p('function',\@cfunc_2p_function);
90 inline_cfunc_2p('ex',\@cfunc_2p_ex);
92 sub inline_function_1p {
93 my ($rettype,$func)=@_;
94 print OUT "inline $rettype $func(basic const & x) {\n";
95 print OUT " return $func(ex(x));\n";
99 sub inline_single_function_2p {
100 my ($rettype,$func,$t1,$cast1,$t2,$cast2)=@_;
101 print OUT "inline $rettype $func($t1 x, $t2 y) {\n";
102 print OUT " return $func($cast1(x),$cast2(y));\n";
106 sub inline_single_function_2p_with_defarg {
107 my ($rettype,$func,$t1,$defarg)=@_;
108 print OUT "inline $rettype $func(basic const & x, $t1 y=$defarg) {\n";
109 print OUT " return $func(ex(x),y);\n";
113 sub inline_single_function_3p {
114 my ($rettype,$func,$t1,$cast1,$t2,$cast2,$t3,$cast3)=@_;
115 print OUT "inline $rettype $func($t1 x, $t2 y, $t3 z) {\n";
116 print OUT " return $func($cast1(x),$cast2(y),$cast3(z));\n";
120 sub inline_single_function_3p_with_defarg {
121 my ($rettype,$func,$t1,$cast1,$t2,$cast2,$t3,$defarg)=@_;
122 print OUT "inline $rettype $func($t1 x, $t2 y, $t3 z=$defarg) {\n";
123 print OUT " return $func($cast1(x),$cast2(y),z);\n";
127 sub inline_single_function_4p_with_defarg {
128 my ($rettype,$func,$t1,$cast1,$t2,$cast2,$t3,$cast3,$t4,$defarg)=@_;
129 print OUT "inline $rettype $func($t1 x, $t2 y, $t3 z, $t4 zz=$defarg) {\n";
130 print OUT " return $func($cast1(x),$cast2(y),$cast3(z),zz);\n";
134 sub inline_single_binop {
135 my ($rettype,$op,$t1,$cast1,$t2,$cast2)=@_;
136 inline_single_function_2p($rettype,'operator'.$op,$t1,$cast1,$t2,$cast2);
139 sub inline_single_unaryop {
140 my ($rettype,$op)=@_;
141 print OUT "inline $rettype operator$op(basic const & x) {\n";
142 print OUT " return operator$op(ex(x));\n";
146 sub inline_function_2p {
147 my ($rettype,$func)=@_;
148 print OUT "// fixes for $rettype $func(x,y)\n";
149 inline_single_function_2p($rettype,$func,'ex const &','','basic const &','ex');
150 inline_single_function_2p($rettype,$func,'basic const &','ex','ex const &','');
151 inline_single_function_2p($rettype,$func,'basic const &','ex','basic const &','ex');
156 my ($rettype,$opsref)=@_;
157 foreach $op (@$opsref) {
158 inline_function_2p($rettype,'operator'.$op);
162 inline_binops('ex',\@binops_ex);
163 inline_binops('relational',\@binops_relational);
164 foreach $op (@binops_exconstref) {
165 print OUT "// fixes for ex const & operator$op(x,y)\n";
166 inline_single_binop('ex const &',$op,'ex &','','basic const &','ex');
169 print OUT "// fixes for other operators\n";
170 inline_single_unaryop('ex','+');
171 inline_single_unaryop('ex','-');
172 print OUT "inline ostream & operator<<(ostream & os, basic const & x) {\n";
173 print OUT " return operator<<(os,ex(x));\n";
176 print OUT "// fixes for functions\n";
177 inline_function_2p('bool','are_ex_trivially_equal');
178 inline_function_1p('unsigned','nops');
179 inline_function_1p('ex','expand');
180 inline_function_2p('bool','has');
181 inline_single_function_2p('int','degree','basic const &','ex','symbol const &','');
182 inline_single_function_2p('int','ldegree','basic const &','ex','symbol const &','');
183 inline_single_function_3p_with_defarg('ex','coeff','basic const &','ex','symbol const &','','int','1');
184 inline_function_1p('ex','numer');
185 inline_function_1p('ex','denom');
186 inline_single_function_2p_with_defarg('ex','normal','int','0');
187 inline_single_function_2p('ex','collect','basic const &','ex','symbol const &','');
188 inline_single_function_2p_with_defarg('ex','eval','int','0');
189 inline_single_function_2p_with_defarg('ex','evalf','int','0');
190 inline_single_function_3p_with_defarg('ex','diff','basic const &','ex','symbol const &','','int','1');
191 inline_single_function_3p('ex','series','const basic &','ex','const relational &','ex','int','');
192 inline_single_function_3p('ex','series','const basic &','ex','const symbol &','ex','int','');
193 inline_function_2p('ex','subs');
194 inline_single_function_3p('ex','subs','basic const &','ex','lst const &','','lst const &','');
195 inline_single_function_2p('ex','op','basic const &','ex','int','');
196 inline_function_1p('ex','lhs');
197 inline_function_1p('ex','rhs');
198 inline_function_1p('bool','is_zero');
200 # fixes for simp_lor.h
201 inline_function_2p('simp_lor','lor_g');
202 inline_single_function_2p('simp_lor','lor_vec','const string &','','const basic &','ex');
206 # Create a file containing stubs that may be necessary because Cint always
207 # wants to link against anything that was ever declared:
211 $opening=<<END_OF_OPENING;
214 * Dummies and stubs to overcome certain deficiencies of Cint.
215 * This file was generated automatically by dummies.pl.
216 * Please do not modify it directly, edit the perl script instead!
219 #include <ginac/function.h>
221 #ifndef NO_NAMESPACE_GINAC
222 using namespace GiNaC;
223 #endif // ndef NO_NAMESPACE_GINAC
228 print OUT "void ginsh_get_ginac_functions(void) { }\n";