1 /* Concrete_Expression class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Concrete_Expression_defs_hh
25 #define PPL_Concrete_Expression_defs_hh 1
26 
27 #include "Concrete_Expression_types.hh"
28 #include "globals_defs.hh"
29 #include "Interval_defs.hh"
30 
31 namespace Parma_Polyhedra_Library {
32 
33 //! The type of a concrete expression.
34 class Concrete_Expression_Type {
35 public:
36   /*! \brief
37     Returns the bounded integer type corresponding to \p width,
38     \p representation and \p overflow.
39   */
40   static Concrete_Expression_Type
41   bounded_integer(Bounded_Integer_Type_Width width,
42                   Bounded_Integer_Type_Representation representation,
43                   Bounded_Integer_Type_Overflow overflow);
44 
45   /*! \brief
46     Returns the floating point type corresponding to \p format.
47   */
48   static Concrete_Expression_Type
49   floating_point(Floating_Point_Format format);
50 
51   /*! \brief
52     Returns <CODE>true</CODE> if and only if \p *this is a bounded
53     integer type.
54   */
55   bool is_bounded_integer() const;
56 
57   /*! \brief
58     Returns <CODE>true</CODE> if and only if \p *this is a floating
59     point type.
60   */
61   bool is_floating_point() const;
62 
63   /*! \brief
64     Returns the width in bits of the bounded integer type encoded by
65     \p *this.
66 
67     The behavior is undefined if \p *this does not encode a bounded
68     integer type.
69   */
70   Bounded_Integer_Type_Width bounded_integer_type_width() const;
71 
72   /*! \brief
73     Returns the representation of the bounded integer type encoded by
74     \p *this.
75 
76     The behavior is undefined if \p *this does not encode a bounded
77     integer type.
78   */
79   Bounded_Integer_Type_Representation
80   bounded_integer_type_representation() const;
81 
82   /*! \brief
83     Returns the overflow behavior of the bounded integer type encoded by
84     \p *this.
85 
86     The behavior is undefined if \p *this does not encode a bounded
87     integer type.
88   */
89   Bounded_Integer_Type_Overflow
90   bounded_integer_type_overflow() const;
91 
92   /*! \brief
93     Returns the format of the floating point type encoded by \p *this.
94 
95     The behavior is undefined if \p *this does not encode a floating
96     point type.
97   */
98   Floating_Point_Format floating_point_format() const;
99 
100   //! Checks if all the invariants are satisfied.
101   bool OK() const;
102 
103 private:
104   //! A 32-bit word encoding the type.
105   struct Implementation {
106     bool bounded_integer:1;
107     unsigned int bounded_integer_type_width:23;
108     unsigned int bounded_integer_type_representation:2;
109     unsigned int bounded_integer_type_overflow:2;
110     unsigned int floating_point_format:4;
111   };
112 
113   //! Constructor from \p implementation.
114   Concrete_Expression_Type(Implementation implementation);
115 
116   //! The encoding of \p *this.
117   Implementation impl;
118 };
119 
120 //! Base class for all concrete expressions.
121 template <typename Target>
122 class Concrete_Expression_Common {
123 public:
124   //! Returns the type of \* this.
125   Concrete_Expression_Type type() const;
126 
127   //! Returns the kind of \* this.
128   Concrete_Expression_Kind kind() const;
129 
130   //! Tests if \p *this has the same kind as <CODE>Derived\<Target\></CODE>.
131   template <template <typename T> class Derived>
132   bool is() const;
133 
134   /*! \brief
135     Returns a pointer to \p *this converted to type
136     <CODE>Derived\<Target\>*</CODE>.
137   */
138   template <template <typename T> class Derived>
139   Derived<Target>* as();
140 
141   /*! \brief
142     Returns a pointer to \p *this converted to type
143     <CODE>const Derived\<Target\>*</CODE>.
144   */
145   template <template <typename T> class Derived>
146   const Derived<Target>* as() const;
147 
148 };
149 
150 //! Base class for binary operator applied to two concrete expressions.
151 template <typename Target>
152 class Binary_Operator_Common {
153 public:
154   //! Returns a constant identifying the operator of \p *this.
155   Concrete_Expression_BOP binary_operator() const;
156 
157   //! Returns the left-hand side of \p *this.
158   const Concrete_Expression<Target>* left_hand_side() const;
159 
160   //! Returns the right-hand side of \p *this.
161   const Concrete_Expression<Target>* right_hand_side() const;
162 };
163 
164 //! Base class for unary operator applied to one concrete expression.
165 template <typename Target>
166 class Unary_Operator_Common {
167 public:
168   //! Returns a constant identifying the operator of \p *this.
169   Concrete_Expression_UOP unary_operator() const;
170 
171   //! Returns the argument \p *this.
172   const Concrete_Expression<Target>* argument() const;
173 };
174 
175 //! Base class for cast operator concrete expressions.
176 template <typename Target>
177 class Cast_Operator_Common {
178   //! Returns the casted expression.
179   const Concrete_Expression<Target>* argument() const;
180 };
181 
182 //! Base class for integer constant concrete expressions.
183 template <typename Target>
184 class Integer_Constant_Common {
185 };
186 
187 //! Base class for floating-point constant concrete expression.
188 template <typename Target>
189 class Floating_Point_Constant_Common {
190 };
191 
192 //! Base class for references to some approximable.
193 template <typename Target>
194 class Approximable_Reference_Common {
195 };
196 
197 } // namespace Parma_Polyhedra_Library
198 
199 #include "Concrete_Expression_inlines.hh"
200 
201 #endif // !defined(PPL_Concrete_Expression_defs_hh)
202