/src/tools/semantics/code/liberty_feature_name.e

http://github.com/tybor/Liberty · Specman e · 222 lines · 178 code · 30 blank · 14 comment · 3 complexity · 58263e66705ab869d805585b6e048696 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_FEATURE_NAME
  16. inherit
  17. LIBERTY_POSITIONABLE
  18. redefine is_equal, out_in_tagged_out_memory
  19. end
  20. insert
  21. HASHABLE
  22. redefine out_in_tagged_out_memory
  23. end
  24. COMPARABLE
  25. redefine is_equal, out_in_tagged_out_memory
  26. end
  27. LIBERTY_AST_HANDLER
  28. redefine is_equal, out_in_tagged_out_memory
  29. end
  30. create {ANY}
  31. make, prefixed, infixed
  32. create {LIBERTY_BUILDER_TOOLS, LIBERTY_FEATURE_LOCAL_CONTEXT}
  33. make_from_ast
  34. create {LIBERTY_TYPE_RESOLVER_IN_TYPE}
  35. make_from_ast_entity_name
  36. create {LIBERTY_BUILDER_TOOLS}
  37. make_regular
  38. create {LIBERTY_BUILDER_TOOLS, LIBERTY_PREFIX_CALL}
  39. make_prefix
  40. create {LIBERTY_BUILDER_TOOLS, LIBERTY_INFIX_CALL}
  41. make_infix
  42. feature {ANY}
  43. name: FIXED_STRING
  44. full_name: FIXED_STRING
  45. out_in_tagged_out_memory is
  46. do
  47. if is_prefix then
  48. tagged_out_memory.append(once "prefix ")
  49. elseif is_infix then
  50. tagged_out_memory.append(once "infix ")
  51. end
  52. name.out_in_tagged_out_memory
  53. end
  54. is_equal (other: like Current): BOOLEAN is
  55. do
  56. Result := type = other.type and then name = other.name
  57. check
  58. Result = (full_name = other.full_name)
  59. end
  60. end
  61. is_regular: BOOLEAN is
  62. do
  63. Result := type = type_regular
  64. end
  65. is_prefix: BOOLEAN is
  66. do
  67. Result := type = type_prefix
  68. end
  69. is_infix: BOOLEAN is
  70. do
  71. Result := type = type_infix
  72. end
  73. hash_code: INTEGER is
  74. do
  75. Result := full_name.hash_code
  76. end
  77. infix "<" (other: like Current): BOOLEAN is
  78. do
  79. Result := full_name < other.full_name
  80. end
  81. feature {LIBERTY_FEATURE_NAME}
  82. type: INTEGER_8
  83. feature {}
  84. make_from_ast_entity_name (ast: LIBERTY_AST_ENTITY_NAME; class_ast: LIBERTY_AST_ONE_CLASS; file: FIXED_STRING) is
  85. require
  86. ast /= Void
  87. class_ast /= Void
  88. do
  89. make_regular(ast.image.image.intern, errors.semantics_position(ast.image.index, class_ast, file))
  90. position := errors.semantics_position(ast.image.index, class_ast, file)
  91. end
  92. make_from_ast (ast: LIBERTY_AST_FEATURE_NAME_OR_ALIAS; class_ast: LIBERTY_AST_ONE_CLASS; file: FIXED_STRING) is
  93. require
  94. ast /= Void
  95. class_ast /= Void
  96. do
  97. if ast.is_regular then
  98. make_from_ast_entity_name(ast.entity_name, class_ast, file)
  99. elseif ast.is_prefix then
  100. make_prefix(ast.free_operator_name.image.image.intern, errors.semantics_position(ast.free_operator_name.image.index, class_ast, file))
  101. position := errors.semantics_position(ast.free_operator_name.image.index, class_ast, file)
  102. else
  103. check ast.is_infix end
  104. make_infix(ast.free_operator_name.image.image.intern, errors.semantics_position(ast.free_operator_name.image.index, class_ast, file))
  105. position := errors.semantics_position(ast.free_operator_name.image.index, class_ast, file)
  106. end
  107. end
  108. make_regular (a_name: like name; a_position: like position) is
  109. require
  110. a_name = a_name.intern
  111. do
  112. name := a_name
  113. full_name := a_name
  114. type := type_regular
  115. position := a_position
  116. ensure
  117. name = a_name
  118. type = type_regular
  119. position = a_position
  120. end
  121. make_prefix (a_name: like name; a_position: like position) is
  122. require
  123. a_name = a_name.intern
  124. do
  125. name := sane_name(a_name)
  126. full_name := (once "prefix " + name).intern
  127. type := type_prefix
  128. position := a_position
  129. ensure
  130. name = sane_name(a_name)
  131. type = type_prefix
  132. position = a_position
  133. end
  134. make_infix (a_name: like name; a_position: like position) is
  135. require
  136. a_name = a_name.intern
  137. do
  138. name := sane_name(a_name)
  139. full_name := (once "infix " + name).intern
  140. type := type_infix
  141. position := a_position
  142. ensure
  143. name = sane_name(a_name)
  144. type = type_infix
  145. position = a_position
  146. end
  147. make (a_name: like name) is
  148. require
  149. a_name = a_name.intern
  150. do
  151. make_regular(a_name, errors.unknown_position)
  152. ensure
  153. name = a_name
  154. end
  155. infixed (a_name: like name) is
  156. require
  157. a_name = a_name.intern
  158. do
  159. make_infix(a_name, errors.unknown_position)
  160. ensure
  161. name = a_name
  162. end
  163. prefixed (a_name: like name) is
  164. require
  165. a_name = a_name.intern
  166. do
  167. make_prefix(a_name, errors.unknown_position)
  168. ensure
  169. name = a_name
  170. end
  171. sane_name (a_name: FIXED_STRING): FIXED_STRING is
  172. do
  173. if a_name.first = '"' then
  174. check a_name.last = '"' end
  175. Result := (a_name.substring(2, a_name.upper - 1)).intern
  176. else
  177. check a_name.last /= '"' end
  178. Result := a_name
  179. end
  180. ensure
  181. a_name.first = '"' implies a_name = ("%"" + Result + "%"").intern
  182. a_name.first /= '"' implies Result = a_name
  183. end
  184. type_regular: INTEGER_8 is 1
  185. type_prefix: INTEGER_8 is 2
  186. type_infix: INTEGER_8 is 3
  187. errors: LIBERTY_ERRORS
  188. invariant
  189. name /= Void
  190. full_name /= Void
  191. type /= 0
  192. end