PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/code/expressions/liberty_cast_expression.e

http://github.com/tybor/Liberty
Specman e | 89 lines | 62 code | 10 blank | 17 comment | 2 complexity | 0db5a8066cde094f86027bdaaaac792b MD5 | raw file
 1-- This file is part of Liberty Eiffel.
 2--
 3-- Liberty Eiffel is free software: you can redistribute it and/or modify
 4-- it under the terms of the GNU General Public License as published by
 5-- the Free Software Foundation, version 3 of the License.
 6--
 7-- Liberty Eiffel is distributed in the hope that it will be useful,
 8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
 9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10-- GNU General Public License for more details.
11--
12-- You should have received a copy of the GNU General Public License
13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
14--
15class LIBERTY_CAST_EXPRESSION
16   --
17   -- Used internally to force the expression type, either via conformance or conversion.
18   --
19
20inherit
21   LIBERTY_EXPRESSION
22
23create {LIBERTY_CALL_PROMOTION, LIBERTY_CAST_EXPRESSION}
24   make
25
26feature {ANY}
27   expression: LIBERTY_EXPRESSION
28   result_type: LIBERTY_TYPE
29
30   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
31      local
32         e: LIBERTY_EXPRESSION
33      do
34         check result_type.specialized_in(a_type) = result_type end
35         e := expression.specialized_in(a_type)
36         if e = expression then
37            Result := Current
38         else
39            create Result.make(e, result_type)
40         end
41      end
42
43   is_valid_type (a_expression: like expression; a_result_type: like result_type): BOOLEAN is
44      require
45         a_expression /= Void
46         a_result_type /= Void
47         {LIBERTY_ACTUAL_TYPE} ?:= a_result_type.known_type
48      local
49         actual_type: LIBERTY_ACTUAL_TYPE
50      do
51         actual_type ::= a_result_type.known_type
52         Result := a_expression.result_type.known_type.is_conform_to(actual_type)
53            or else a_expression.result_type.known_type.converts_to(actual_type)
54      end
55
56   accept (v: VISITOR) is
57      local
58         v0: LIBERTY_CAST_EXPRESSION_VISITOR
59      do
60         v0 ::= v
61         v0.visit_liberty_cast_expression(Current)
62      end
63
64feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
65   mark_reachable_code (mark: INTEGER) is
66      do
67         expression.mark_reachable_code(mark)
68      end
69
70feature {}
71   make (a_expression: like expression; a_result_type: like result_type) is
72      require
73         a_expression /= Void
74         a_result_type /= Void
75         is_valid_type(a_expression, a_result_type)
76      do
77         expression := a_expression
78         result_type := a_result_type
79         position := a_expression.position
80      ensure
81         expression = a_expression
82         result_type = a_result_type
83         position = a_expression.position
84      end
85
86invariant
87   is_valid_type(expression, result_type)
88
89end