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

http://github.com/tybor/Liberty · Specman e · 134 lines · 93 code · 13 blank · 28 comment · 2 complexity · e2df5fc793ca352df7ffe0f5b5b5969b MD5 · raw file

  1. class C_VARIABLE
  2. inherit
  3. CONTEXTED_NODE
  4. IDENTIFIED_NODE
  5. MOVABLE_NODE
  6. -- hence a NAMED_NODE and a FILED_NODE
  7. TYPED_NODE
  8. STORABLE_NODE
  9. WRAPPER_FEATURE
  10. create {GCCXML_TREE}
  11. make
  12. feature {ANY}
  13. store
  14. do
  15. symbols.put(Current, c_string_name)
  16. variables.add_first(Current)
  17. end
  18. is_to_be_emitted: BOOLEAN
  19. do
  20. Result := (is_public or has_assigned_name) and then (global or else headers.has(c_file.c_string_name))
  21. end
  22. wrap_on (a_stream: OUTPUT_STREAM)
  23. do
  24. if not has_wrapper then
  25. log("Variable `#(1)' does not have a wrapper type (address of query emitted anyway)%N" # c_string_name)
  26. buffer.reset
  27. buffer.append(once " -- Variable #(1) in file %"#(2)%" does not have a wrapper type%N" #
  28. c_string_name # c_file.c_string_name )
  29. -- TODO: provide the reason; using developer_exception_name
  30. -- triggers some recursion bug AFAIK. Paolo 2009-10-02
  31. buffer.append(once " address_of_#(1): POINTER%N%
  32. % -- Address of #(1)%N%
  33. % external %"plug_in%"%N%
  34. % alias %"{%N%
  35. % location: %".%"%N%
  36. % module_name: %"plugin%"%N%
  37. % feature_name: %"&#(2)%"%N%
  38. % }%"%N%
  39. % end%N%N" #
  40. eiffel_feature(c_string_name) # c_string_name)
  41. -- For debugging purpose the line where the node occurred were once
  42. -- printed in the comment, like this:
  43. -- buffer.append(once
  44. -- " address_of_#(1): POINTER%N%
  45. -- % -- Address of #(1) (node at line #(2))%N%
  46. -- % external %"plug_in%"%N%
  47. -- % alias %"{%N%
  48. -- % location: %".%"%N%
  49. -- % module_name: %"plugin%"%N%
  50. -- % feature_name: %"&#(3)%"%N%
  51. -- % }%"%N%
  52. -- % end%N%N" # eiffel_feature(c_string_name) # line_row.to_utf8 # c_string_name)
  53. -- this information is not printed anymore to make the generated
  54. -- classes a little more stable, avoiding unnecessary changes.
  55. elseif not is_public then
  56. log(once "Skipping 'hidden' variable `#(1)'%N" # c_string_name)
  57. buffer.append(once "%T-- `hidden' variable #(1) skipped.%N" # c_string_name)
  58. elseif not namespace.is_main then
  59. log(once "Skipping variable `#(1)' belonging to namespace #(2)%N" # c_string_name # namespace.c_string_name)
  60. buffer.append(once "%T-- variable #(1) in namespace #(2) skipped.%N" # c_string_name # namespace.c_string_name)
  61. else
  62. log(once "Variable #(1)%N" # c_string_name)
  63. buffer.append(once "%T#(1): #(2)%N%
  64. % -- #(1)%N%
  65. % external %"plug_in%"%N%
  66. % alias %"{%N%
  67. % location: %".%"%N%
  68. % module_name: %"plugin%"%N%
  69. % feature_name: %"#(3)%"%N%
  70. % }%"%N%
  71. % end%N%
  72. %%N%
  73. % address_of_#(1): POINTER%N%
  74. % -- Address of #(1)%N%
  75. % external %"plug_in%"%N%
  76. % alias %"{%N%
  77. % location: %".%"%N%
  78. % module_name: %"plugin%"%N%
  79. % feature_name: %"&#(3)%"%N%
  80. % }%"%N%
  81. % end%N%
  82. %%N%
  83. % set_#(1) (a_value: #(2))%N%
  84. % -- Set variable #(1) value%N%
  85. % external %"plug_in%"%N%
  86. % alias %"{%N%
  87. % location: %".%"%N%
  88. % module_name: %"plugin%"%N%
  89. % feature_name: %"set_#(3)%"%N%
  90. % }%"%N%
  91. % end%N%N" #
  92. eiffel_feature(c_string_name) # wrapper_type # c_string_name)
  93. ("#define set_#(1)(a_value) #(1) = (a_value);%N" # c_string_name).print_on(include)
  94. end
  95. buffer.print_on(a_stream)
  96. end
  97. is_void: BOOLEAN False
  98. wrapper_type: STRING
  99. do
  100. Result := types.at(dequalify(type)).wrapper_type
  101. end
  102. has_wrapper: BOOLEAN
  103. do
  104. Result := types.at(dequalify(type)).has_wrapper
  105. end
  106. is_fundamental: BOOLEAN
  107. do
  108. Result := types.at(dequalify(type)).is_fundamental
  109. end
  110. end -- class C_VARIABLE
  111. -- Copyright (C) 2008-2017: Paolo Redaelli
  112. -- wrappers-generator is free software: you can redistribute it and/or modify it
  113. -- under the terms of the GNU General Public License as publhed by the Free
  114. -- Software Foundation, either version 2 of the License, or (at your option)
  115. -- any later version.
  116. -- wrappers-generator is distributed in the hope that it will be useful, but
  117. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  118. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  119. -- more details.
  120. -- You should have received a copy of the GNU General Public License along with
  121. -- th program. If not, see <http://www.gnu.org/licenses/>.