codegen.h
1 #ifndef SYMENGINE_CODEGEN_H
2 #define SYMENGINE_CODEGEN_H
3 
4 #include <symengine/printers.h>
5 #include <symengine/visitor.h>
6 #include <symengine/printers/strprinter.h>
7 #include <symengine/symengine_exception.h>
8 
9 namespace SymEngine
10 {
11 
12 class CodePrinter : public BaseVisitor<CodePrinter, StrPrinter>
13 {
14 public:
15  explicit CodePrinter(CodePrinterPrecision precision
16  = CodePrinterPrecision::Double);
17  using StrPrinter::apply;
18  using StrPrinter::bvisit;
19  using StrPrinter::str_;
20  void bvisit(const Basic &x);
21  void bvisit(const Complex &x);
22  void bvisit(const Dummy &x);
23  void bvisit(const Interval &x);
24  void bvisit(const Contains &x);
25  void bvisit(const Piecewise &x);
26  void bvisit(const BooleanAtom &x);
27  void bvisit(const And &x);
28  void bvisit(const Or &x);
29  void bvisit(const Xor &x);
30  void bvisit(const Not &x);
31  void bvisit(const Integer &x);
32  void bvisit(const Rational &x);
33  void bvisit(const EmptySet &x);
34  void bvisit(const FiniteSet &x);
35  void bvisit(const Reals &x);
36  void bvisit(const Rationals &x);
37  void bvisit(const Integers &x);
38  void bvisit(const UniversalSet &x);
39  void bvisit(const Abs &x);
40  void bvisit(const Ceiling &x);
41  void bvisit(const Truncate &x);
42  void bvisit(const Max &x);
43  void bvisit(const Min &x);
44  void bvisit(const Constant &x);
45  void bvisit(const NaN &x);
46  void bvisit(const Equality &x);
47  void bvisit(const Unequality &x);
48  void bvisit(const LessThan &x);
49  void bvisit(const StrictLessThan &x);
50  void bvisit(const Sign &x);
51  void bvisit(const UnevaluatedExpr &x);
52  void bvisit(const UnivariateSeries &x);
53  void bvisit(const Derivative &x);
54  void bvisit(const Subs &x);
55  void bvisit(const GaloisField &x);
56  void bvisit(const Function &x);
57  void bvisit(const RealDouble &x);
58 #ifdef HAVE_SYMENGINE_MPFR
59  void bvisit(const RealMPFR &x);
60 #endif
61 
62 protected:
63  CodePrinterPrecision precision_;
64  std::string print_scalar_literal(double d) const;
65  std::string print_math_function(const std::string &name) const;
66 };
67 
68 class C89CodePrinter : public BaseVisitor<C89CodePrinter, CodePrinter>
69 {
70 public:
71  explicit C89CodePrinter(CodePrinterPrecision precision
72  = CodePrinterPrecision::Double);
73  using CodePrinter::apply;
74  using CodePrinter::bvisit;
75  using CodePrinter::str_;
76  void bvisit(const Infty &x);
77  void _print_pow(std::ostringstream &o, const RCP<const Basic> &a,
78  const RCP<const Basic> &b) override;
79 };
80 
81 class C99CodePrinter : public BaseVisitor<C99CodePrinter, C89CodePrinter>
82 {
83 public:
84  explicit C99CodePrinter(CodePrinterPrecision precision
85  = CodePrinterPrecision::Double);
86  using C89CodePrinter::apply;
87  using C89CodePrinter::bvisit;
88  using C89CodePrinter::str_;
89  void bvisit(const Infty &x);
90  void _print_pow(std::ostringstream &o, const RCP<const Basic> &a,
91  const RCP<const Basic> &b) override;
92  void bvisit(const Gamma &x);
93  void bvisit(const LogGamma &x);
94 };
95 
96 class CudaCodePrinter : public BaseVisitor<CudaCodePrinter, C99CodePrinter>
97 {
98 public:
99  explicit CudaCodePrinter(CodePrinterPrecision precision
100  = CodePrinterPrecision::Double);
101  using C99CodePrinter::apply;
102  using C99CodePrinter::bvisit;
103  using C99CodePrinter::str_;
104  void bvisit(const Integer &x);
105  void bvisit(const Constant &x);
106  void bvisit(const NaN &x);
107  void bvisit(const Infty &x);
108 };
109 
110 class JSCodePrinter : public BaseVisitor<JSCodePrinter, CodePrinter>
111 {
112 public:
113  using CodePrinter::apply;
114  using CodePrinter::bvisit;
115  using CodePrinter::str_;
116  void bvisit(const Constant &x);
117  void _print_pow(std::ostringstream &o, const RCP<const Basic> &a,
118  const RCP<const Basic> &b) override;
119  void bvisit(const Abs &x);
120  void bvisit(const Sin &x);
121  void bvisit(const Cos &x);
122  void bvisit(const Max &x);
123  void bvisit(const Min &x);
124 };
125 } // namespace SymEngine
126 
127 #endif // SYMENGINE_CODEGEN_H
The lowest unit of symbolic representation.
Definition: basic.h:97
Complex Class.
Definition: complex.h:33
Integer Class.
Definition: integer.h:19
Rational Class.
Definition: rational.h:16
RealDouble Class to hold double values.
Definition: real_double.h:20
UnivariateSeries Class.
Main namespace for SymEngine package.
Definition: add.cpp:19