/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. --
  15. class LIBERTY_CAST_EXPRESSION
  16. --
  17. -- Used internally to force the expression type, either via conformance or conversion.
  18. --
  19. inherit
  20. LIBERTY_EXPRESSION
  21. create {LIBERTY_CALL_PROMOTION, LIBERTY_CAST_EXPRESSION}
  22. make
  23. feature {ANY}
  24. expression: LIBERTY_EXPRESSION
  25. result_type: LIBERTY_TYPE
  26. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  27. local
  28. e: LIBERTY_EXPRESSION
  29. do
  30. check result_type.specialized_in(a_type) = result_type end
  31. e := expression.specialized_in(a_type)
  32. if e = expression then
  33. Result := Current
  34. else
  35. create Result.make(e, result_type)
  36. end
  37. end
  38. is_valid_type (a_expression: like expression; a_result_type: like result_type): BOOLEAN is
  39. require
  40. a_expression /= Void
  41. a_result_type /= Void
  42. {LIBERTY_ACTUAL_TYPE} ?:= a_result_type.known_type
  43. local
  44. actual_type: LIBERTY_ACTUAL_TYPE
  45. do
  46. actual_type ::= a_result_type.known_type
  47. Result := a_expression.result_type.known_type.is_conform_to(actual_type)
  48. or else a_expression.result_type.known_type.converts_to(actual_type)
  49. end
  50. accept (v: VISITOR) is
  51. local
  52. v0: LIBERTY_CAST_EXPRESSION_VISITOR
  53. do
  54. v0 ::= v
  55. v0.visit_liberty_cast_expression(Current)
  56. end
  57. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  58. mark_reachable_code (mark: INTEGER) is
  59. do
  60. expression.mark_reachable_code(mark)
  61. end
  62. feature {}
  63. make (a_expression: like expression; a_result_type: like result_type) is
  64. require
  65. a_expression /= Void
  66. a_result_type /= Void
  67. is_valid_type(a_expression, a_result_type)
  68. do
  69. expression := a_expression
  70. result_type := a_result_type
  71. position := a_expression.position
  72. ensure
  73. expression = a_expression
  74. result_type = a_result_type
  75. position = a_expression.position
  76. end
  77. invariant
  78. is_valid_type(expression, result_type)
  79. end