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

http://github.com/tybor/Liberty · Specman e · 143 lines · 109 code · 14 blank · 20 comment · 13 complexity · aa79cf031ec37350931265cf2e796ef5 MD5 · raw file

  1. class C_TYPEDEF
  2. inherit
  3. C_TYPE
  4. IDENTIFIED_NODE
  5. MOVABLE_NODE
  6. -- Hence a NAMED_NODE and FILED_NODE
  7. -- using the definition made in WRAPPER_CLASS
  8. undefine compute_eiffel_name
  9. end
  10. TYPED_NODE
  11. CONTEXTED_NODE
  12. STORABLE_NODE
  13. WRAPPER_CLASS
  14. create {GCCXML_TREE}
  15. make
  16. feature {ANY}
  17. store
  18. do
  19. -- if not standard_typedefs.has(c_string_name) then
  20. -- Current typedef is not a standard one and requires a query for anchored declarations.
  21. typedefs.add_first(Current)
  22. -- end
  23. types.fast_put(Current, id)
  24. check
  25. is_named
  26. end
  27. symbols.put(Current, c_string_name)
  28. end
  29. standard_typedefs: SET[STRING]
  30. -- The standard typedefs defined by the C language.
  31. once
  32. Result := {HASHED_SET[STRING] << "long int", "int8_t", "uint8_t", "int16_t", "uint16_t", "int32_t", "uint32_t", "int64_t", "uint64_t", "intptr_t", "uintptr_t", "int_least8_t", "uint_least8_t", "int_least16_t", "uint_least16_t", "int_least32_t", "uint_least32_t", "int_least64_t", "uint_least64_t", "int_fast8_t", "uint_fast8_t", "int_fast16_t", "uint_fast16_t", "int_fast32_t", "uint_fast32_t", "int_fast64_t", "uint_fast64_t", "intmax_t", "uintmax_t", "size_t", "ssize_t", "ptrdiff_t" >> }
  33. end
  34. wrapper_type: STRING
  35. do
  36. if not settings.are_standard_typedefs_emitted and then standard_typedefs.has(c_string_name) then
  37. Result := once "like " + c_string_name
  38. else
  39. if referree.has_wrapper then
  40. Result := referree.wrapper_type
  41. else
  42. log("C typedef #(1) at line #(2) is not wrappable" # c_string_name # &line)
  43. end
  44. end
  45. end
  46. is_fundamental: BOOLEAN
  47. local
  48. a_type: C_TYPE
  49. do
  50. a_type := types.at(type)
  51. if a_type /= Void then
  52. Result := a_type.is_fundamental
  53. else
  54. raise("unknown type")
  55. end
  56. end
  57. is_void: BOOLEAN False
  58. has_wrapper: BOOLEAN
  59. do
  60. Result := types.at(type).has_wrapper
  61. end
  62. is_to_be_emitted: BOOLEAN
  63. do
  64. Result := is_public and then (global or else headers.has(c_file.c_string_name))
  65. end
  66. wrap_on (a_stream: OUTPUT_STREAM)
  67. -- If Current ultimately refers to a fundamental type then put an empty query on `a_stream', otherwise nothing is done.
  68. local
  69. query_name: STRING
  70. do
  71. if is_to_be_emitted then
  72. if is_fundamental then
  73. if has_wrapper then
  74. query_name := eiffel_feature(c_string_name)
  75. log(once "Anchored query #(2) for typedef #(1)%N" # c_string_name # query_name)
  76. buffer.append(once " #(1): #(2)%N%
  77. % -- typedef #(3) from #(4)%N%
  78. % -- Empty by design, used for anchored declarations.%N%
  79. % do%N%
  80. % ensure Result.is_default%N%
  81. % end%N%
  82. %%N" # query_name # wrapper_type # c_string_name
  83. # c_file.c_string_name )
  84. else
  85. buffer.append(once "%T-- #(1) unwrappable: no wrapper type.%N" # c_string_name)
  86. -- TODO: add the case of typedef to void
  87. end
  88. buffer.print_on(a_stream)
  89. else
  90. -- It refers to something else; let's assign it a name
  91. referree.set_name(eiffel_feature(c_string_name))
  92. end
  93. end
  94. end -- invariant name.is_equal(once U"Typedef")
  95. feature {ANY}
  96. emit_wrapper
  97. local a_composed_type: COMPOSED_NODE
  98. do
  99. if a_composed_type ?:= referree then
  100. log("Emitting wrapper for typedef #(1)%N" # c_string_name)
  101. a_composed_type ::= referree
  102. if a_composed_type /=Void then
  103. if not a_composed_type.is_named then
  104. log("Referred #(1) is anonymous, forcingly setting its name to #(2)%N" #
  105. a_composed_type.c_type # c_string_name)
  106. a_composed_type.set_name(c_string_name)
  107. end
  108. a_composed_type.emit_wrapper
  109. else
  110. log(" typedef #(1) has no referree node%N" # c_string_name)
  111. end
  112. else
  113. log("No wrapper for typedef #(1)%N" # c_string_name)
  114. end
  115. emitted := True
  116. end
  117. suffix: STRING ""
  118. end -- class C_TYPEDEF
  119. -- Copyright (C) 2008-2017: Paolo Redaelli
  120. -- wrappers-generator is free software: you can redistribute it and/or modify it
  121. -- under the terms of the GNU General Public License as publhed by the Free
  122. -- Software Foundation, either version 2 of the License, or (at your option)
  123. -- any later version.
  124. -- wrappers-generator is distributed in the hope that it will be useful, but
  125. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  126. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  127. -- more details.
  128. -- You should have received a copy of the GNU General Public License along with
  129. -- th program. If not, see <http://www.gnu.org/licenses/>.