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

http://github.com/tybor/Liberty · Specman e · 177 lines · 112 code · 18 blank · 47 comment · 5 complexity · 58b32f93112aa588cdf98b8fdf80c1bd MD5 · raw file

  1. class C_FIELD
  2. inherit
  3. IDENTIFIED_NODE
  4. CONTEXTED_NODE
  5. FILED_NODE
  6. TYPED_NODE
  7. STORABLE_NODE
  8. WRAPPER_FEATURE
  9. create {GCCXML_TREE}
  10. make
  11. feature {ANY}
  12. store
  13. local
  14. container_type: COMPOSED_NODE
  15. do
  16. container_type := composed_types.reference_at(context)
  17. if container_type /= Void then
  18. -- Add Current to its container
  19. container_type.fields.add_last(Current)
  20. else
  21. -- Fields may be part of a composed type that will be not be wrapped, for example PThread structures when wrapping GObject introspection facilities. Therefore its container will not be present in the composed types!
  22. log("Ignoring field #(1) of #(2) in %"#(3)%"%N" # c_string_name # context.to_utf8)
  23. end
  24. end
  25. is_fundamental: BOOLEAN
  26. do
  27. Result := types.at(dequalify(type)).is_fundamental
  28. end
  29. is_void: BOOLEAN False
  30. has_wrapper: BOOLEAN
  31. local field_type: C_TYPE
  32. do
  33. -- You may want to write "Result := types.at(dequalify(type)).has_wrapper" but that's simplicistic
  34. field_type := types.reference_at(dequalify(type))
  35. if field_type/=Void then
  36. Result:=field_type.has_wrapper
  37. end
  38. rescue
  39. log("C_FIELD.has_wrapper failed%N")
  40. print_run_time_stack
  41. die_with_code (exit_failure_code)
  42. -- if type/=Void then
  43. -- field_type := types.at(dequalify(type))
  44. -- if field_type /= Void then
  45. -- Result := field_type.has_wrapper
  46. -- else
  47. -- log(once "Warning: C field #(1) in line #(2) is of an unknown type!%N"
  48. -- # c_string_name # &line )
  49. -- Result := False
  50. -- end
  51. -- else
  52. -- log(once "Warning: C field #(1) in line #(2) is typeless!%N"
  53. -- # c_string_name # &line )
  54. -- Result := False
  55. -- end
  56. end
  57. wrapper_type: STRING
  58. do
  59. Result := types.at(dequalify(type)).wrapper_type
  60. end
  61. container: COMPOSED_NODE
  62. -- The node representing the C entity that contains Current field
  63. do
  64. if stored_parent = Void then
  65. stored_parent := composed_types.at(context)
  66. end
  67. Result := stored_parent
  68. ensure
  69. Result /= Void
  70. end
  71. is_to_be_emitted: BOOLEAN True
  72. -- all fields of a composed node will be emitted (if possible)
  73. wrap_on (a_stream: OUTPUT_STREAM)
  74. do
  75. not_yet_implemented
  76. end
  77. append_getter_and_setter (a_structure_name: STRING)
  78. require
  79. a_structure_name /= Void
  80. local
  81. setter, getter, getter_description, setter_description: STRING; eiffel_field: ABSTRACT_STRING
  82. do
  83. if is_anonymous then
  84. log(once "Anonymous field in #(1) at line #(2): not wrappable." # a_structure_name # &line_row)
  85. queries.append(once "%T-- Anonymous field at line #(1).%N" # &line_row)
  86. elseif not is_public then
  87. log(once "Private field #(1) in #(2) not wrapped." # c_string_name # a_structure_name)
  88. queries.append(once "%T-- Unwrapped private field #(1).%N" # c_string_name)
  89. elseif not has_wrapper then
  90. log(once "Field #(1) in #(2) doesn't have a wrapper.%N" # c_string_name # a_structure_name)
  91. queries.append(once "%T-- Unwrappable field #(1).%N"#c_string_name)
  92. -- doesn't have a valid wrapper
  93. else -- we can actually wrap it
  94. eiffel_field := adapt(c_string_name, once "_field")
  95. setter := a_structure_name + once "_set_" + eiffel_field
  96. getter := a_structure_name + once "_get_" + eiffel_field
  97. setter.to_lower
  98. getter.to_lower
  99. -- TODO: descriptions := feature_descriptions.reference_at(a_structure_name)
  100. getter_description := "-- TODO: getter description%N"
  101. setter_description := "-- TODO: setter description%N"
  102. -- if descriptions /= Void then
  103. -- setter_description:=formatted_description(descriptions.reference_at(eiffel_field))
  104. -- getter_description:=formatted_description(descriptions.reference_at(eiffel_field))
  105. -- else setter_description:=once ""; getter_description:=once ""
  106. -- end
  107. -- log(once "Field #(1).#(2) (%"#(3)%", %"#(4)%" " #
  108. -- a_structure_name # c_field # setter_description # getter_description)
  109. queries.append(once " #(1) (a_structure: POINTER): #(2) %N%
  110. % -- Query for #(3) field of #(4) structure.%N%
  111. % #(5)%N%
  112. % external %"plug_in%"%N%
  113. % alias %"{%N%
  114. % location: %".%"%N%
  115. % module_name: %"plugin%"%N%
  116. % feature_name: %"#(1)%"%N%
  117. % }%"%N%
  118. % end%N%N" # getter # wrapper_type # c_string_name # a_structure_name
  119. # getter_description)
  120. setters.append(once " #(1) (a_structure: POINTER; a_value: #(2)) %N%
  121. % -- Setter for #(3) field of #(4) structure.%N%
  122. % #(5)%N%
  123. % external %"plug_in%"%N%
  124. % alias %"{%N%
  125. % location: %".%"%N%
  126. % module_name: %"plugin%"%N%
  127. % feature_name: %"#(1)%"%N%
  128. % }%"%N%
  129. % end%N%N" # setter # wrapper_type # c_string_name # a_structure_name # setter_description)
  130. -- log(once "command, ")
  131. -- -- Note: Type safety is assured by Eiffel and GCC-XML so we can
  132. -- -- be less type-strict-paranoid here and use some type-casts.
  133. -- TODO: the next print_on commands cause compiler crash if
  134. -- they operate on a ROPE, made using the "|" operator instead
  135. -- of +.
  136. ("#define #(1)(a_structure) (((#(2) #(3)*) (a_structure))->#(4))%N%N"
  137. # getter # container.c_type # container.c_string_name
  138. # c_string_name).print_on(include)
  139. -- the above line previously was written, rather unreadably like this ("#define " + getter + "(a_structure) (((" + container.c_type + " " + container.c_string_name + "*) (a_structure))->" + c_string_name + ")%N%N").print_on(include)
  140. ("#define #(1)(a_structure,a_value) do {(((#(2) #(3)*)(a_structure)))->#(4) = (a_value);}while(0)%N%N"
  141. # setter # container.c_type # container.c_string_name
  142. # c_string_name).print_on(include)
  143. -- the above line previously was written, rather unreadably like this ("#define " + setter + "(a_structure,a_value) do {(((" + container.c_type + " " + container.c_string_name + "*)(a_structure)))->" + c_string_name + " = (a_value);}while(0)%N%N").print_on(include)
  144. end
  145. end
  146. feature {} -- Implementation
  147. stored_parent: COMPOSED_NODE
  148. end -- class C_FIELD
  149. -- Copyright (C) 2008-2017: Paolo Redaelli
  150. -- wrappers-generator is free software: you can redistribute it and/or modify it
  151. -- under the terms of the GNU General Public License as publhed by the Free
  152. -- Software Foundation, either version 2 of the License, or (at your option)
  153. -- any later version.
  154. -- wrappers-generator is distributed in the hope that it will be useful, but
  155. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  156. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  157. -- more details.
  158. -- You should have received a copy of the GNU General Public License along with
  159. -- th program. If not, see <http://www.gnu.org/licenses/>.