1 /* Concrete_Expression class implementation: inline functions.
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_inlines_hh
25 #define PPL_Concrete_Expression_inlines_hh 1
26 
27 namespace Parma_Polyhedra_Library {
28 
29 inline
30 Concrete_Expression_Type
Concrete_Expression_Type(Implementation implementation)31 ::Concrete_Expression_Type(Implementation implementation)
32   : impl(implementation) {
33 }
34 
35 inline Concrete_Expression_Type
36 Concrete_Expression_Type
bounded_integer(const Bounded_Integer_Type_Width width,const Bounded_Integer_Type_Representation representation,const Bounded_Integer_Type_Overflow overflow)37 ::bounded_integer(const Bounded_Integer_Type_Width width,
38                   const Bounded_Integer_Type_Representation representation,
39                   const Bounded_Integer_Type_Overflow overflow) {
40   Implementation impl;
41   impl.bounded_integer = true;
42   impl.bounded_integer_type_width = width;
43   impl.bounded_integer_type_representation = representation;
44   impl.bounded_integer_type_overflow = overflow;
45   // Arbitrary choice to ensure determinism.
46   impl.floating_point_format = IEEE754_HALF;
47   return Concrete_Expression_Type(impl);
48 }
49 
50 inline Concrete_Expression_Type
51 Concrete_Expression_Type
floating_point(const Floating_Point_Format format)52 ::floating_point(const Floating_Point_Format format) {
53   Implementation impl;
54   impl.bounded_integer = false;
55   impl.floating_point_format = format;
56   // Arbitrary choices to ensure determinism.
57   impl.bounded_integer_type_width = BITS_128;
58   impl.bounded_integer_type_representation =  SIGNED_2_COMPLEMENT;
59   impl.bounded_integer_type_overflow = OVERFLOW_IMPOSSIBLE;
60   return Concrete_Expression_Type(impl);
61 }
62 
63 inline bool
is_bounded_integer() const64 Concrete_Expression_Type::is_bounded_integer() const {
65   return impl.bounded_integer;
66 }
67 
68 inline bool
is_floating_point() const69 Concrete_Expression_Type::is_floating_point() const {
70   return !impl.bounded_integer;
71 }
72 
73 inline Bounded_Integer_Type_Width
bounded_integer_type_width() const74 Concrete_Expression_Type::bounded_integer_type_width() const {
75   const unsigned int u = impl.bounded_integer_type_width;
76   return static_cast<Bounded_Integer_Type_Width>(u);
77 }
78 
79 inline Bounded_Integer_Type_Representation
bounded_integer_type_representation() const80 Concrete_Expression_Type::bounded_integer_type_representation() const {
81   const unsigned int u = impl.bounded_integer_type_representation;
82   return static_cast<Bounded_Integer_Type_Representation>(u);
83 }
84 
85 inline Bounded_Integer_Type_Overflow
bounded_integer_type_overflow() const86 Concrete_Expression_Type::bounded_integer_type_overflow() const {
87   const unsigned int u = impl.bounded_integer_type_overflow;
88   return static_cast<Bounded_Integer_Type_Overflow>(u);
89 }
90 
91 inline Floating_Point_Format
floating_point_format() const92 Concrete_Expression_Type::floating_point_format() const {
93   const unsigned int u = impl.floating_point_format;
94   return static_cast<Floating_Point_Format>(u);
95 }
96 
97 template <typename Target>
98 template <template <typename T> class Derived>
99 inline bool
is() const100 Concrete_Expression_Common<Target>::is() const {
101   return static_cast<const Concrete_Expression<Target>*>(this)->kind() ==
102          Derived<Target>::KIND;
103 }
104 
105 template <typename Target>
106 template <template <typename T> class Derived>
107 inline Derived<Target>*
as()108 Concrete_Expression_Common<Target>::as() {
109   PPL_ASSERT(is<Derived>());
110   return static_cast<Derived<Target>*>(this);
111 }
112 
113 template <typename Target>
114 template <template <typename T> class Derived>
115 inline const Derived<Target>*
as() const116 Concrete_Expression_Common<Target>::as() const {
117   PPL_ASSERT(is<Derived>());
118   return static_cast<const Derived<Target>*>(this);
119 }
120 
121 } // namespace Parma_Polyhedra_Library
122 
123 #endif // !defined(PPL_Concrete_Expression_inlines_hh)
124