/src/tools/semantics/code/feature_local_context/liberty_inline_agent_context.e

http://github.com/tybor/Liberty · Specman e · 192 lines · 152 code · 26 blank · 14 comment · 8 complexity · e6bc53be76c1af02e27fef85f5ab258b 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_INLINE_AGENT_CONTEXT
  16. inherit
  17. LIBERTY_FEATURE_LOCAL_CONTEXT
  18. insert
  19. LIBERTY_AST_HANDLER
  20. create {LIBERTY_BUILDER_TOOLS}
  21. make
  22. feature {ANY}
  23. current_type: LIBERTY_ACTUAL_TYPE is
  24. do
  25. Result := current_entity.result_type
  26. end
  27. result_type: LIBERTY_TYPE is
  28. do
  29. if result_entity /= Void then
  30. Result := result_entity.result_type
  31. end
  32. end
  33. parameters: TRAVERSABLE[LIBERTY_PARAMETER] is
  34. do
  35. Result := parameters_list
  36. ensure then
  37. definition: Result = parameters_list
  38. end
  39. locals: TRAVERSABLE[LIBERTY_LOCAL] is
  40. do
  41. Result := locals_list
  42. ensure then
  43. definition: Result = locals_list
  44. end
  45. is_parameter (name: ABSTRACT_STRING): BOOLEAN is
  46. do
  47. Result := parameters_map.has(name.intern)
  48. end
  49. parameter (name: ABSTRACT_STRING): LIBERTY_PARAMETER is
  50. do
  51. Result := parameters_map.reference_at(name.intern)
  52. end
  53. is_local (name: ABSTRACT_STRING): BOOLEAN is
  54. do
  55. Result := locals_map.has(name.intern)
  56. end
  57. local_var (name: ABSTRACT_STRING): LIBERTY_LOCAL is
  58. do
  59. Result := locals_map.reference_at(name.intern)
  60. end
  61. current_entity: LIBERTY_CURRENT
  62. result_entity: LIBERTY_RESULT
  63. can_retry: BOOLEAN is False
  64. retry_instruction (a_position: LIBERTY_POSITION): LIBERTY_RETRY is
  65. do
  66. check False end
  67. end
  68. feature {LIBERTY_BUILDER_TOOLS, LIBERTY_FEATURE_LOCAL_CONTEXT}
  69. add_parameter (a_parameter: LIBERTY_PARAMETER) is
  70. do
  71. parameters_list.add_last(a_parameter)
  72. parameters_map.add(a_parameter, a_parameter.name)
  73. end
  74. add_local (a_local: LIBERTY_LOCAL) is
  75. do
  76. locals_list.add_last(a_local)
  77. locals_map.add(a_local, a_local.name)
  78. end
  79. reconcile_retry_instructions (a_feature: LIBERTY_FEATURE) is
  80. do
  81. check False end
  82. end
  83. set_result_type (a_result_type: like result_type) is
  84. do
  85. result_entity := a_result_type.result_entity
  86. end
  87. feature {LIBERTY_INLINE_AGENT, LIBERTY_SEMANTICS_BUILDER}
  88. specialized_in (a_type: like current_type): like Current is
  89. do
  90. Result := twin
  91. Result.set_specialized_in(a_type)
  92. end
  93. feature {LIBERTY_INLINE_AGENT_CONTEXT}
  94. set_specialized_in (a_type: like current_type) is
  95. local
  96. i: INTEGER; p: LIBERTY_PARAMETER; l: LIBERTY_LOCAL
  97. pl: like parameters_list; pm: like parameters_map
  98. ll: like locals_list; lm: like locals_map
  99. do
  100. current_entity := a_type.current_entity
  101. if result_entity /= Void then
  102. set_result_type(result_type.specialized_in(a_type))
  103. end
  104. from
  105. pl := parameters_list
  106. pm := parameters_map
  107. i := pl.lower
  108. until
  109. i > pl.upper
  110. loop
  111. p := pl.item(i).specialized_in(a_type)
  112. if p /= pl.item(i) then
  113. if pl = parameters_list then
  114. pl := pl.twin
  115. pm := pm.twin
  116. end
  117. pl.put(p, i)
  118. pm.put(p, p.name)
  119. end
  120. i := i + 1
  121. end
  122. if pl /= parameters_list then
  123. parameters_list := pl
  124. parameters_map := pm
  125. end
  126. from
  127. ll := locals_list
  128. lm := locals_map
  129. i := ll.lower
  130. until
  131. i > ll.upper
  132. loop
  133. l := ll.item(i).specialized_in(a_type)
  134. if l /= ll.item(i) then
  135. if ll = locals_list then
  136. ll := ll.twin
  137. lm := lm.twin
  138. end
  139. ll.put(l, i)
  140. lm.put(l, l.name)
  141. end
  142. i := i + 1
  143. end
  144. if ll /= locals_list then
  145. locals_list := ll
  146. locals_map := lm
  147. end
  148. end
  149. feature {}
  150. parameters_map: DICTIONARY[LIBERTY_PARAMETER, FIXED_STRING]
  151. parameters_list: COLLECTION[LIBERTY_PARAMETER]
  152. locals_map: DICTIONARY[LIBERTY_LOCAL, FIXED_STRING]
  153. locals_list: COLLECTION[LIBERTY_LOCAL]
  154. make (a_parent_context: LIBERTY_FEATURE_LOCAL_CONTEXT) is
  155. require
  156. a_parent_context /= Void
  157. do
  158. current_entity := a_parent_context.current_type.current_entity
  159. create {FAST_ARRAY[LIBERTY_PARAMETER]} parameters_list.make(0)
  160. create {HASHED_DICTIONARY[LIBERTY_PARAMETER, FIXED_STRING]} parameters_map.with_capacity(a_parent_context.parameters.count + 3)
  161. create {FAST_ARRAY[LIBERTY_LOCAL]} locals_list.make(0)
  162. create {HASHED_DICTIONARY[LIBERTY_LOCAL, FIXED_STRING]} locals_map.with_capacity(a_parent_context.locals.count + 3)
  163. a_parent_context.parameters.do_all(agent add_parameter)
  164. a_parent_context.locals.do_all(agent add_local)
  165. end
  166. end