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

http://github.com/tybor/Liberty · Specman e · 145 lines · 97 code · 17 blank · 31 comment · 4 complexity · b5a983787f5f91c9f1812b21a5243e86 MD5 · raw file

  1. class C_FILE
  2. -- An header file that will be wrapped as a wrapper class containing all the functions and variables defined in that file.
  3. inherit
  4. IDENTIFIED_NODE
  5. STORABLE_NODE
  6. WRAPPER_CLASS
  7. redefine compute_eiffel_name
  8. end
  9. insert
  10. NAME_CONVERTER
  11. FILE_TOOLS
  12. COLLECTION_SORTER[WRAPPER_FEATURE]
  13. create {GCCXML_TREE}
  14. make
  15. feature {ANY}
  16. store
  17. do
  18. files.put(Current, id)
  19. check
  20. is_named
  21. end
  22. symbols.put(Current, c_string_name)
  23. files_by_name.put(Current, c_string_name)
  24. create features
  25. end
  26. is_to_be_emitted: BOOLEAN
  27. do
  28. Result := file_exists(c_string_name) and (global or else headers.has(c_string_name))
  29. end
  30. emit_wrapper
  31. -- Emits into a deferred class named like the file itself the wrappers
  32. -- for all the function and the variable contained into Current file.
  33. local
  34. path: POSIX_PATH_NAME
  35. do
  36. if is_to_be_emitted then
  37. create path.make_from_string(directory)
  38. path.add_last(eiffel_name.as_lower + once ".e")
  39. -- if path.is_file then
  40. -- log(once "Copying existing file #(1) onto #(1).orig.%N" # path.to_string)
  41. -- copy_to(path.to_string, path.to_string+once ".orig")
  42. -- end
  43. log(once "Outputting wrapper for functions found in file #(1) on #(2).%N" # c_name.as_utf8 # path.to_string)
  44. create {TEXT_FILE_WRITE} output.connect_to(path.to_string)
  45. -- end
  46. emit_header_on(output)
  47. log(once "Sorting file features%N")
  48. if features.count > 1 then
  49. sort(features)
  50. end
  51. features.for_each(agent {WRAPPER_FEATURE}.wrap_on(output))
  52. emit_footer_on(output)
  53. output.disconnect
  54. else
  55. log(once "Skipping file '#(1)'.%N"#c_string_name)
  56. end
  57. emitted := True
  58. end
  59. emit_header_on (a_stream: OUTPUT_STREAM)
  60. -- Put on `output' the header on an "external" class named 'eiffel_name'
  61. -- from the beginning until the "feature {} -- External calls" label
  62. -- included
  63. require
  64. a_stream /= Void
  65. do
  66. a_stream.put_string(automatically_generated_header)
  67. a_stream.put_string(deferred_class)
  68. a_stream.put_line(eiffel_name)
  69. -- emit_description_on(class_descriptions.reference_at(eiffel_name),a_stream)
  70. a_stream.put_string(inherits_string)
  71. a_stream.put_line("%T%T" | settings.standard_typedefs_class)
  72. a_stream.put_string(externals_header) --line
  73. end
  74. emit_footer_on (a_stream: OUTPUT_STREAM)
  75. require
  76. a_stream /= Void
  77. do
  78. a_stream.put_string(once "%Nend -- class ")
  79. a_stream.put_line(eiffel_name)
  80. end
  81. suffix: STRING "_EXTERNALS"
  82. compute_eiffel_name
  83. local
  84. path: POSIX_PATH_NAME
  85. do
  86. -- The Eiffel class name for `c_name'; extension is removed,
  87. -- CamelCase is converted into CAMEL_CASE, dashes are converted to
  88. -- underscores, `suffix' is added at the endi, eventual; i.e.:
  89. -- class_name_from_header("/usr/include/foo/bar/maman.h").is_equal("MAMAN_EXTERNALS")
  90. create path.make_from_string(c_string_name.string)
  91. -- TODO: change PATH_NAME.make_from_string to accept ABSTRACT_STRING instead of plain STRINGs
  92. create cached_eiffel_name.copy(path.last)
  93. cached_eiffel_name.remove_tail(path.extension.count)
  94. -- camelcase_translator.substitute_all_in(cached_eiffel_name) -- insert_underscores(cached_eiffel_name)
  95. -- Remove trailing underscores
  96. from
  97. until
  98. cached_eiffel_name.first /= '_'
  99. loop
  100. cached_eiffel_name.remove_first
  101. end
  102. -- Remove spurious underscores at the end
  103. from
  104. until
  105. cached_eiffel_name.last /= '_'
  106. loop
  107. cached_eiffel_name.remove_last
  108. end
  109. cached_eiffel_name.replace_all('-', '_')
  110. cached_eiffel_name.to_upper
  111. cached_eiffel_name.append(suffix)
  112. ensure then
  113. cached_eiffel_name.occurrences('.') = 0
  114. end
  115. feature {ANY} -- Content
  116. features: FAST_ARRAY[WRAPPER_FEATURE]
  117. end -- class C_FILE
  118. -- Copyright (C) 2008-2017: ,2009,2010 Paolo Redaelli
  119. -- wrappers-generator is free software: you can redistribute it and/or modify it
  120. -- under the terms of the GNU General Public License as publhed by the Free
  121. -- Software Foundation, either version 2 of the License, or (at your option)
  122. -- any later version.
  123. -- wrappers-generator is distributed in the hope that it will be useful, but
  124. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  125. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  126. -- more details.
  127. -- You should have received a copy of the GNU General Public License along with
  128. -- th program. If not, see <http://www.gnu.org/licenses/>.