PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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