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

http://github.com/tybor/Liberty · Specman e · 110 lines · 66 code · 14 blank · 30 comment · 3 complexity · d6fc85d42f6f76f11fe9c2893a486802 MD5 · raw file

  1. deferred class NAMED_NODE
  2. -- A GCC_XML node that MAY have a "name" attribute.
  3. -- Comparable using the `eiffel_name' feature for comparison to get a more stable output.
  4. -- Nameless nodes are considered non-public
  5. inherit
  6. GCCXML_NODE
  7. COMPARABLE
  8. undefine is_equal
  9. end
  10. insert
  11. NAME_CONVERTER
  12. feature {ANY} -- Comparability
  13. infix "<" (other: NAMED_NODE): BOOLEAN
  14. -- Comparon made on the name used in the wrappers
  15. do
  16. Result := Current.eiffel_name < other.eiffel_name
  17. end
  18. feature {ANY}
  19. is_anonymous: BOOLEAN
  20. -- Is Current node anonynmous?
  21. do
  22. Result := not is_named
  23. end
  24. is_named: BOOLEAN
  25. -- Does Current actually have a name?
  26. do
  27. Result := attributes.has(once U"name") and then not c_name.is_empty
  28. end
  29. c_name: UNICODE_STRING
  30. do
  31. Result := attribute_at(once U"name")
  32. ensure
  33. is_named implies Result /= Void
  34. end
  35. c_string_name: STRING
  36. local a_name: UNICODE_STRING
  37. do
  38. a_name := c_name
  39. if a_name/=Void then
  40. Result:= c_name.to_utf8
  41. end
  42. end
  43. eiffel_name: STRING
  44. -- the name of Current when wrapped in Liberty Eiffel.
  45. do
  46. if cached_eiffel_name = Void then
  47. compute_eiffel_name
  48. end
  49. Result := cached_eiffel_name
  50. end
  51. is_public: BOOLEAN
  52. -- Does Current node have a name and does it start with an alphabetical character? Names
  53. -- starting with underscores or other strange characters are
  54. -- usually considered private in C/C++ languages.
  55. do
  56. Result := is_named and then c_name.first.to_character.is_letter
  57. end
  58. feature {} -- Implementation
  59. cached_eiffel_name: STRING
  60. compute_eiffel_name
  61. do
  62. if is_named then
  63. cached_eiffel_name := eiffel_feature(c_string_name)
  64. check
  65. is_public: cached_eiffel_name.first /= '_'
  66. not cached_eiffel_name.has_substring("__")
  67. end
  68. elseif has_assigned_name then
  69. cached_eiffel_name := eiffel_feature(assigned_name)
  70. else
  71. -- Actually trying to wrap a nameless element that is not
  72. -- identified by its position in a file is quite hopeless. We
  73. -- neverethells may assign a unique name, using the line of the
  74. -- gccxml file as unique id. Quite a shameless trick, but I guess
  75. -- that such elements are quite esoteric and unreachable and
  76. -- unusable also on C level.
  77. create cached_eiffel_name.make_from_string(once "anonymous_gccxml_element_at_line_#(1)_r#(2)" # &line # &column)
  78. -- TODO once we have convert this create will be mimicked by a simple assignment.
  79. -- It could also be written like this:
  80. -- cached_eiffel_name := (once "anonymous_gccxml_element_at_l#(1)_r#(2)" # &line # &column).string
  81. end
  82. ensure
  83. cached_eiffel_name /= Void
  84. end
  85. end -- class NAMED_NODE
  86. -- Copyright (C) 2008-2017: Paolo Redaelli
  87. -- wrappers-generator is free software: you can redistribute it and/or modify it
  88. -- under the terms of the GNU General Public License as publhed by the Free
  89. -- Software Foundation, either version 2 of the License, or (at your option)
  90. -- any later version.
  91. -- wrappers-generator is distributed in the hope that it will be useful, but
  92. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  93. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  94. -- more details.
  95. -- You should have received a copy of the GNU General Public License along with
  96. -- th program. If not, see <http://www.gnu.org/licenses/>.