1 /************************************************************************
2 ************************************************************************
3 FAUST compiler
4 Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
21
22 #ifndef __ATERM__
23 #define __ATERM__
24
25 #include <stdio.h>
26 #include <list>
27 #include <map>
28
29 #include "exception.hh"
30 #include "garbageable.hh"
31 #include "mterm.hh"
32 #include "normalize.hh"
33 #include "signals.hh"
34 #include "sigorderrules.hh"
35 #include "sigprint.hh"
36 #include "simplify.hh"
37 #include "tlib.hh"
38
39 using namespace std;
40
41 /**
42 * Implements a additive term, a set of mterms added together
43 * m1 + m2 + m3 + ...
44 */
45
46 class aterm : public virtual Garbageable {
47 map<Tree, mterm> fSig2MTerms; ///< mapping between signatures and corresponding mterms
48
49 public:
50 aterm(); ///< create an empty aterm (equivalent to 0)
51 aterm(Tree t); ///< create a aterm from an additive exp
52 // aterm (const aterm& a); ///< create a copy of an aterm
53
54 const aterm& operator+=(Tree t); ///< add in place an additive expression tree
55 const aterm& operator-=(Tree t); ///< add in place an additive expression tree
56
57 const aterm& operator+=(const mterm& m); ///< add in place an mterm
58 const aterm& operator-=(const mterm& m); ///< add in place an mterm
59 Tree normalizedTree() const; ///< return the corresponding normalized expression tree
60
61 ostream& print(ostream& dst) const; ///< print a aterm m1 + m2 + m3 +...
62 mterm greatestDivisor() const; ///< return the greatest divisor of any two mterms
63 aterm factorize(const mterm& d); ///< reorganize the aterm by factorizing d
64 };
65
operator <<(ostream & s,const aterm & a)66 inline ostream& operator<<(ostream& s, const aterm& a)
67 {
68 return a.print(s);
69 }
70
71 #endif
72