/[eiffelstudio]/branches/eth/eve/Src/Eiffel/API/evaluated_type/natural_a.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/API/evaluated_type/natural_a.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 89347 - (show annotations)
Fri Aug 10 15:09:25 2012 UTC (7 years, 5 months ago) by jasonw
File size: 4295 byte(s)
<<Merged from trunk#89346.>>
1 note
2 description: "Actual type for natural type."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 NATURAL_A
10
11 inherit
12 BASIC_A
13 rename
14 make as cl_make
15 redefine
16 is_natural, base_class,
17 same_as, is_numeric, process,
18 minimum_interval_value,
19 maximum_interval_value,
20 heaviest
21 end
22
23 create
24 make
25
26 feature {NONE} -- Initialization
27
28 make (n: INTEGER)
29 -- Create instance of NATURAL_A represented by `n' bits.
30 require
31 valid_n: n = 8 or n = 16 or n = 32 or n = 64
32 do
33 size := n.to_integer_8
34 cl_make (base_class.class_id)
35 ensure
36 size_set: size = n
37 end
38
39 feature -- Visitor
40
41 process (v: TYPE_A_VISITOR)
42 -- Process current element.
43 do
44 v.process_natural_a (Current)
45 end
46
47 feature -- Property
48
49 is_natural: BOOLEAN = True
50 -- Is the current type an natural type ?
51
52 size: INTEGER_8
53 -- Current is stored on `size' bits.
54
55 feature -- Access
56
57 same_as (other: TYPE_A): BOOLEAN
58 -- Is the current type the same as `other' ?
59 do
60 Result := attached {NATURAL_A} other as n and then size = n.size
61 end
62
63 base_class: CLASS_C
64 -- Class NATURAL
65 do
66 inspect size
67 when 8 then Result := System.natural_8_class.compiled_class
68 when 16 then Result := System.natural_16_class.compiled_class
69 when 32 then Result := System.natural_32_class.compiled_class
70 when 64 then Result := System.natural_64_class.compiled_class
71 end
72 end
73
74 feature -- IL code generation
75
76 minimum_interval_value: INTERVAL_VAL_B
77 -- Minimum value in inspect interval for current type
78 do
79 if size = 64 then
80 create {NAT64_VAL_B} Result.make (0)
81 else
82 check
83 valid_size: size = 8 or size = 16 or size = 32
84 end
85 create {NAT_VAL_B} Result.make (0)
86 end
87 end
88
89 maximum_interval_value: INTERVAL_VAL_B
90 -- Maximum value in inspect interval for current type
91 do
92 inspect size
93 when 8 then
94 create {NAT_VAL_B} Result.make ({NATURAL_8}.max_value)
95 when 16 then
96 create {NAT_VAL_B} Result.make ({NATURAL_16}.max_value)
97 when 32 then
98 create {NAT_VAL_B} Result.make ({NATURAL_32}.max_value)
99 when 64 then
100 create {NAT64_VAL_B} Result.make ({NATURAL_64}.max_value)
101 end
102 end
103
104 heaviest (other: TYPE_A): TYPE_A
105 local
106 l_long: like Current
107 do
108 if other.is_real_64 or other.is_real_32 then
109 Result := other
110 else
111 if other.is_natural then
112 l_long ?= other
113 if size >= l_long.size then
114 Result := Current
115 else
116 Result := other
117 end
118 else
119 Result := Current
120 end
121 end
122 end
123
124 feature {COMPILER_EXPORTER}
125
126 is_numeric: BOOLEAN = True
127 -- Is the current type a numeric type ?
128
129 c_type: NATURAL_I
130 -- C type
131 do
132 inspect size
133 when 8 then Result := uint8_c_type
134 when 16 then Result := uint16_c_type
135 when 32 then Result := uint32_c_type
136 when 64 then Result := uint64_c_type
137 end
138 end
139
140 invariant
141 correct_size: size = 8 or size = 16 or size = 32 or size = 64
142
143 note
144 copyright: "Copyright (c) 1984-2007, Eiffel Software"
145 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
146 licensing_options: "http://www.eiffel.com/licensing"
147 copying: "[
148 This file is part of Eiffel Software's Eiffel Development Environment.
149
150 Eiffel Software's Eiffel Development Environment is free
151 software; you can redistribute it and/or modify it under
152 the terms of the GNU General Public License as published
153 by the Free Software Foundation, version 2 of the License
154 (available at the URL listed under "license" above).
155
156 Eiffel Software's Eiffel Development Environment is
157 distributed in the hope that it will be useful, but
158 WITHOUT ANY WARRANTY; without even the implied warranty
159 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
160 See the GNU General Public License for more details.
161
162 You should have received a copy of the GNU General Public
163 License along with Eiffel Software's Eiffel Development
164 Environment; if not, write to the Free Software Foundation,
165 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
166 ]"
167 source: "[
168 Eiffel Software
169 356 Storke Road, Goleta, CA 93117 USA
170 Telephone 805-685-1006, Fax 805-685-6869
171 Website http://www.eiffel.com
172 Customer support http://support.eiffel.com
173 ]"
174
175 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23