/src/tools/wrappers-generator/descriptions.e

http://github.com/tybor/Liberty · Specman e · 205 lines · 147 code · 12 blank · 46 comment · 12 complexity · c99b7ef1c577301c7bf40afd06bfedf0 MD5 · raw file

  1. deferred class DESCRIPTIONS
  2. -- Access to descriptions of classes and features.
  3. insert
  4. FILE_TOOLS
  5. SHARED_SETTINGS
  6. NAME_CONVERTER
  7. feature {ANY} -- Descriptions reading
  8. read_descriptions_from (a_file_name: STRING)
  9. -- Read description comment for classes and features from the file
  10. -- named `a_file_name',
  11. -- filling `class_descriptions' and `feature_descriptions'. Leading and
  12. -- trailing spaces are removed. Lines starting with "--" are ignored
  13. -- as comments. Class descriptions are in the form "CLASS_NAME
  14. -- Description text", feature descriptions are "CLASS_NAME.feature
  15. -- Description text".
  16. require
  17. a_file_name /= Void
  18. file_exists(a_file_name)
  19. is_file(a_file_name)
  20. local
  21. line, described: STRING; words: LINKED_LIST[STRING]; descriptions: TEXT_FILE_READ
  22. do
  23. create descriptions.connect_to(a_file_name)
  24. if descriptions.is_connected then
  25. from
  26. descriptions.read_line
  27. until
  28. descriptions.end_of_input
  29. loop
  30. line := descriptions.last_string
  31. line.left_adjust
  32. line.right_adjust
  33. if line.has_prefix(once "--") then
  34. debug
  35. log(once ".")
  36. end
  37. else
  38. create words.make
  39. line.split_in(words)
  40. if not words.is_empty then
  41. described := words.first
  42. words.remove_first
  43. read_description(described, words)
  44. debug
  45. log(once ".")
  46. end
  47. end
  48. end
  49. descriptions.read_line
  50. end
  51. check
  52. descriptions.end_of_input
  53. end
  54. descriptions.disconnect
  55. else
  56. debug
  57. log(once "Couldn't connect to `#(1)' to read descriptions.%N" # a_file_name)
  58. end
  59. end
  60. end
  61. read_description (a_described: STRING; a_description: COLLECTION[STRING])
  62. -- When `a_described' is a valid class name (i.e. "CLASS_NAME_01") `a_description' is added into `class_descriptions'; when `a_described' is a valid class name with a feature name with a dot in the middle (like "ANOTHER_CLASS.my_feature_12_foo"); adds
  63. -- `a_description' is added into `feature_descriptions' in the latter.
  64. -- Leading and trailing spaces are removed from `a_described'; comments -
  65. -- starting with "--" are skipped; See `read_comments' for further
  66. -- informations.
  67. local
  68. described_class, described_feature: STRING; dot: INTEGER
  69. subdictionary: HASHED_DICTIONARY[COLLECTION[STRING], STRING]
  70. do
  71. -- Remove leading and trailing spaces
  72. a_described.left_adjust
  73. a_described.right_adjust
  74. if not a_described.has_prefix(once "--") then
  75. -- Look for class name and feature name
  76. inspect
  77. a_described.occurrences('.')
  78. when 0 then
  79. -- could be a class
  80. if is_valid_class_name(a_described) then
  81. debug
  82. log(once "Description for class #(1): %"#(2)%".%N" # a_described # & a_description)
  83. -- a_description.for_each(agent log) log(once "%".%N")
  84. end
  85. class_descriptions.put(a_description, a_described)
  86. else
  87. log(once "Comment file: invalid class name `#(1)'.%N" # a_described)
  88. end
  89. when 1 then
  90. -- could be a feature (i.e. CLASS.feature)
  91. -- Look for the dot and see if has a meaningful position
  92. dot := a_described.first_index_of('.')
  93. if dot > a_described.lower and dot < a_described.count then
  94. described_class := a_described.substring(1, dot - 1)
  95. described_feature := a_described.substring(dot + 1, a_described.count)
  96. debug
  97. log(once "Description for feature #(1) of #(2) #(3)%".%N" #
  98. described_feature # described_class # &a_description )
  99. -- a_description.for_each(agent log) log(once "%".%N")
  100. end
  101. subdictionary := feature_descriptions.reference_at(described_class)
  102. if subdictionary = Void then
  103. create subdictionary.make
  104. feature_descriptions.put(subdictionary, described_class)
  105. end
  106. subdictionary.put(a_description, described_feature)
  107. else
  108. log(once "Comment file: empty class or feature name %"" | a_described | once "%".%N")
  109. end
  110. else
  111. log(once "Comment file: feature name %"" | a_described | once "%" has too many dots.%N")
  112. end
  113. -- inspect
  114. end
  115. -- if has "--" prefix
  116. end
  117. feature {ANY} -- Outputting description
  118. emit_description_on (a_description: COLLECTION[STRING]; a_formatter: FORMATTER)
  119. -- Put 'a_description' on 'a_formatter' formatting it as an Eiffel
  120. -- comment with lines shorter that 'description_lenght' characters.
  121. -- Nothing is done when `a_description' is Void.
  122. require
  123. a_formatter /= Void
  124. local
  125. word: STRING; iter: ITERATOR[STRING]; length, new_length: INTEGER
  126. do
  127. if a_description /= Void then
  128. from
  129. iter := a_description.new_iterator
  130. iter.start
  131. a_formatter.append(comment)
  132. length := 0
  133. until
  134. iter.is_off
  135. loop
  136. word := iter.item
  137. new_length := length + word.count
  138. if new_length > description_lenght then
  139. a_formatter.append(comment)
  140. length := 0
  141. else
  142. a_formatter.put(' ')
  143. length := new_length + 1
  144. end
  145. a_formatter.append(word)
  146. iter.next
  147. end
  148. end
  149. end
  150. feature {ANY} -- Queries
  151. feature_description (a_class_name, a_feature_name: STRING): COLLECTION[STRING]
  152. -- The description of `a_feature_name' in `a_class_name'. Void when
  153. -- there is no description.
  154. require
  155. a_class_name /= Void
  156. local
  157. dictionary: HASHED_DICTIONARY[COLLECTION[STRING], STRING]
  158. do
  159. dictionary := feature_descriptions.reference_at(a_class_name)
  160. if dictionary /= Void then
  161. Result := dictionary.reference_at(a_feature_name)
  162. -- debug
  163. -- log(once "feature_description(%"#(1)%",%"#(2)%")=%"#(3)%"%N"#a_class_name#a_feature_name#formatted_description(Result))
  164. -- end
  165. end
  166. end
  167. feature {} -- Descriptions
  168. description_lenght: INTEGER 70
  169. class_descriptions: HASHED_DICTIONARY[COLLECTION[STRING], STRING]
  170. -- Class description comments. Key is classname.
  171. once
  172. create Result.make
  173. end
  174. feature_descriptions: HASHED_DICTIONARY[HASHED_DICTIONARY[COLLECTION[STRING], STRING], STRING]
  175. -- Feature descriptions dictionary. The outer dictionary is indexed by
  176. -- classname, the inner one by feature name. So to get the description of
  177. -- feature foo in class BAR you shall invoke
  178. -- feature_descriptions.at("BAR").at("foo")
  179. once
  180. create Result.make
  181. end
  182. end -- class DESCRIPTIONS
  183. -- Copyright (C) 2008-2017: Paolo Redaelli
  184. -- wrappers-generator is free software: you can redistribute it and/or modify it
  185. -- under the terms of the GNU General Public License as publhed by the Free
  186. -- Software Foundation, either version 2 of the License, or (at your option)
  187. -- any later version.
  188. -- wrappers-generator is distributed in the hope that it will be useful, but
  189. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  190. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  191. -- more details.
  192. -- You should have received a copy of the GNU General Public License along with
  193. -- th program. If not, see <http://www.gnu.org/licenses/>.