PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/tybor/Liberty
Specman e | 145 lines | 97 code | 17 blank | 31 comment | 4 complexity | b5a983787f5f91c9f1812b21a5243e86 MD5 | raw file
  1class C_FILE
  2   -- An header file that will be wrapped as a wrapper class containing all the functions and variables defined in that file.
  3
  4inherit
  5   IDENTIFIED_NODE
  6   STORABLE_NODE
  7   WRAPPER_CLASS
  8      redefine compute_eiffel_name
  9      end
 10
 11insert
 12   NAME_CONVERTER
 13   FILE_TOOLS
 14   COLLECTION_SORTER[WRAPPER_FEATURE]
 15
 16create {GCCXML_TREE}
 17   make
 18
 19feature {ANY}
 20   store
 21      do
 22         files.put(Current, id)
 23         check
 24            is_named
 25         end
 26         symbols.put(Current, c_string_name)
 27         files_by_name.put(Current, c_string_name)
 28         create features
 29      end
 30
 31   is_to_be_emitted: BOOLEAN
 32      do
 33         Result := file_exists(c_string_name) and (global or else headers.has(c_string_name))
 34      end
 35
 36   emit_wrapper
 37         -- Emits into a deferred class named like the file itself the wrappers
 38         -- for all the function and the variable contained into Current file.
 39      local
 40         path: POSIX_PATH_NAME
 41      do
 42         if is_to_be_emitted then
 43            create path.make_from_string(directory)
 44            path.add_last(eiffel_name.as_lower + once ".e")
 45            -- if path.is_file then
 46            --      log(once "Copying existing file #(1) onto #(1).orig.%N" # path.to_string)
 47            --      copy_to(path.to_string, path.to_string+once ".orig")
 48            -- end
 49
 50            log(once "Outputting wrapper for functions found in file #(1) on #(2).%N" # c_name.as_utf8 # path.to_string)
 51
 52            create {TEXT_FILE_WRITE} output.connect_to(path.to_string)
 53            -- end
 54            emit_header_on(output)
 55            log(once "Sorting file features%N")
 56            if features.count > 1 then
 57               sort(features)
 58            end
 59
 60            features.for_each(agent {WRAPPER_FEATURE}.wrap_on(output))
 61            emit_footer_on(output)
 62            output.disconnect
 63         else
 64            log(once "Skipping file '#(1)'.%N"#c_string_name)
 65         end
 66         emitted := True
 67      end
 68
 69   emit_header_on (a_stream: OUTPUT_STREAM)
 70         -- Put on `output' the header on an "external" class named 'eiffel_name'
 71         -- from the beginning until the "feature {} -- External calls" label
 72         -- included
 73      require
 74         a_stream /= Void
 75      do
 76         a_stream.put_string(automatically_generated_header)
 77         a_stream.put_string(deferred_class)
 78         a_stream.put_line(eiffel_name)
 79         -- emit_description_on(class_descriptions.reference_at(eiffel_name),a_stream)
 80         a_stream.put_string(inherits_string)
 81         a_stream.put_line("%T%T" | settings.standard_typedefs_class)
 82         a_stream.put_string(externals_header) --line
 83      end
 84
 85   emit_footer_on (a_stream: OUTPUT_STREAM)
 86      require
 87         a_stream /= Void
 88      do
 89         a_stream.put_string(once "%Nend -- class ")
 90         a_stream.put_line(eiffel_name)
 91      end
 92
 93   suffix: STRING "_EXTERNALS"
 94
 95   compute_eiffel_name
 96      local
 97         path: POSIX_PATH_NAME
 98      do
 99         -- The Eiffel class name for `c_name'; extension is removed,
100         -- CamelCase is converted into CAMEL_CASE, dashes are converted to
101         -- underscores, `suffix' is added at the endi, eventual; i.e.:
102         -- class_name_from_header("/usr/include/foo/bar/maman.h").is_equal("MAMAN_EXTERNALS")
103         create path.make_from_string(c_string_name.string)
104         -- TODO: change PATH_NAME.make_from_string to accept ABSTRACT_STRING instead of plain STRINGs
105         create cached_eiffel_name.copy(path.last)
106         cached_eiffel_name.remove_tail(path.extension.count)
107         -- camelcase_translator.substitute_all_in(cached_eiffel_name) -- insert_underscores(cached_eiffel_name)
108         -- Remove trailing underscores
109
110         from
111         until
112            cached_eiffel_name.first /= '_'
113         loop
114            cached_eiffel_name.remove_first
115         end
116         -- Remove spurious underscores at the end
117         from
118         until
119            cached_eiffel_name.last /= '_'
120         loop
121            cached_eiffel_name.remove_last
122         end
123
124         cached_eiffel_name.replace_all('-', '_')
125         cached_eiffel_name.to_upper
126         cached_eiffel_name.append(suffix)
127      ensure then
128         cached_eiffel_name.occurrences('.') = 0
129      end
130
131feature {ANY} -- Content
132   features: FAST_ARRAY[WRAPPER_FEATURE]
133
134end -- class C_FILE
135-- Copyright (C) 2008-2017: ,2009,2010 Paolo Redaelli
136-- wrappers-generator  is free software: you can redistribute it and/or modify it
137-- under the terms of the GNU General Public License as publhed by the Free
138-- Software Foundation, either version 2 of the License, or (at your option)
139-- any later version.
140-- wrappers-generator is distributed in the hope that it will be useful, but
141-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
142-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
143-- more details.
144-- You should have received a copy of the GNU General Public License along with
145-- th program.  If not, see <http://www.gnu.org/licenses/>.