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

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

http://github.com/tybor/Liberty
Specman e | 160 lines | 94 code | 20 blank | 46 comment | 5 complexity | 81de86f7932c8e13fbb9a2f7ae8230e5 MD5 | raw file
  1class C_ENUM_VALUE
  2
  3inherit
  4   GCCXML_NODE
  5   NAMED_NODE
  6      redefine eiffel_name
  7      end
  8
  9insert
 10   SHARED_COLLECTIONS
 11   NAME_CONVERTER
 12
 13create {GCCXML_TREE}
 14   make
 15
 16feature {ANY}
 17   value: STRING
 18         -- The numeric value of Current
 19      do
 20         Result := attribute_at(once U"init").to_utf8
 21      end
 22
 23   eiffel_name: STRING
 24         -- The eiffel name of the value. Clash with reserved words and with feature name of class ANY are avoided adding the suffix "_value" when Result will be used to form getter feature names (i.e. "_....")
 25      local
 26         enum: C_ENUM; get: STRING
 27      do
 28         if stored_eiffel_name = Void then
 29            --print("Enum value: ")
 30            stored_eiffel_name := c_name.to_utf8
 31            -- print(stored_eiffel_name)
 32
 33            enum ?= parent
 34            if enum /= Void then
 35               if enum.longest_prefix > 0 then
 36                  -- this further test may be buggy and enum.prefix_length < c_string_name.count then
 37                  stored_eiffel_name.remove_head(enum.longest_prefix)
 38               else
 39                   log("#(1) enumeration values: value '#(2)' (at line #(3)) is the longest prefix: keeping name to avoid problems%N"
 40	                  # enum.values.count.to_string # c_string_name # line.out)
 41               end
 42            else log("The parent of C_ENUM_VALUE at line #(1) not a C_ENUM!%N" # line.out)
 43            end
 44
 45            stored_eiffel_name := eiffel_feature(stored_eiffel_name)
 46
 47            get := once "_" + stored_eiffel_name
 48            if any_features.has(get) then
 49               -- The getter formed with Current will clash with a feature of class ANY; let's escape it
 50               stored_eiffel_name := stored_eiffel_name + once "_value"
 51            end
 52         end
 53         Result := stored_eiffel_name
 54      end
 55
 56feature {ANY} -- Plain enumeration
 57   append_to_buffers
 58         -- Append in `setters' the text of a command to set the enumeration
 59         -- currently being emitted to the value of Current C_ENUM_VALUE for an
 60         -- enumeration value with `a_name' with a low level value `a_value'.
 61         -- Append in `queries' the text of a query for an enumeration value
 62         -- with `a_name' with a low level value `a_value'.
 63      do
 64         log(once "enum item #(1) wrapped as #(2)%N" # c_string_name # eiffel_name)
 65         -- Append to `validity_query' the part of the comparon dealing with
 66         -- Current value, i.e. "(a_value = FooBarOne)"....
 67
 68         validity_query.append (once "(a_value = #(1)_low_level) " # eiffel_name)
 69         -- append_enum setter
 70         setters.append(once "%Tset_#(1)%N%
 71                %               do%N%
 72                %                       value := #(1)_low_level%N%
 73                %               end%N%N" # eiffel_name)
 74         -- TODO: formatted_description(feature_description(class_name,setter_name))
 75         -- Append enum query
 76
 77         queries.append(once "       is_#(1): BOOLEAN%N%
 78                %               do%N%
 79                %                       Result := (value=#(1)_low_level)%N%
 80                %               end%N%N" # eiffel_name)
 81         -- TODO: add formatted_description(feature_description(class_name,getter_name)),
 82         -- Append in `low_level_values' a declaration labelled
 83         -- `an_eiffel_value' to access `a_low_level_value' found in
 84         -- `a_file_name'
 85
 86         low_level_values.append(once "     #(1)_low_level: INTEGER%N%
 87                %               external %"plug_in%"%N%
 88                %               alias %"{%N%
 89                %                       location: %".%"%N%
 90                %                       module_name: %"plugin%"%N%
 91                %                       feature_name: %"#(2)%"%N%
 92                %                       }%"%N%
 93                %               end%N%N" # eiffel_name # c_string_name)
 94      end
 95
 96feature {ANY} -- "Flag" enumeration
 97   append_as_flag_to_buffers
 98         -- Append in `setters' the text of setter and unsetter commands for the Current value of the enumeration currently being emitted.
 99         -- Append in `queries' the text of a query to see if Current value is set
100         --and a low level value
101         -- `a_value'.
102      do
103         log(once "flag item #(1) wrapped as #(2)%N" # 
104		 	c_string_name # eiffel_name)
105         -- Append to `validity_query' the part of the comparon dealing with
106         -- Current value, i.e. "(a_value = FooBarOne)"....
107
108         validity_query.append(once "#(1)_low_level" # eiffel_name)
109         -- append_enum setter
110         setters.append(once "%Tset_#(1)%N%
111                %               do%N%
112                %                       value := value.bit_or(#(1)_low_level)%N%
113                %               end%N%
114                %%N%
115                %%Tunset_#(1)%N%
116                %               do%N%
117                %                       value := value.bit_xor(#(1)_low_level)%N%
118                %               end%N%
119                %%N" # eiffel_name)
120         -- formatted_description(feature_description(class_name,setter_name))
121         -- TODO: put descriptions into setter and unsetter
122         -- Append enum query
123
124         queries.append(once "       is_#(1): BOOLEAN%N%
125                %               do%N%
126                %                       Result := (value.bit_and(#(1)_low_level).to_boolean)%N%
127                %               end%N%N" # eiffel_name)
128         -- TODO: add formatted_description(feature_description(class_name,getter_name)),
129         -- Append in `low_level_values' a declaration labelled
130         -- `an_eiffel_value' to access `a_low_level_value' found in
131         -- `a_file_name'
132
133         low_level_values.append(once "     #(1)_low_level: INTEGER%N%
134                %               external %"plug_in%"%N%
135                %               alias %"{%N%
136                %                       location: %".%"%N%
137                %                       module_name: %"plugin%"%N%
138                %                       feature_name: %"#(2)%"%N%
139                %                       }%"%N%
140                %               end%N%N" # eiffel_name # c_string_name)
141         -- TODO: add description
142      end
143
144feature {} -- Implementation
145   stored_eiffel_name: STRING
146
147end -- class C_ENUM_VALUE
148
149-- Copyright (C) 2008-2017: Paolo Redaelli
150
151-- wrappers-generator  is free software: you can redistribute it and/or modify it
152-- under the terms of the GNU General Public License as publhed by the Free
153-- Software Foundation, either version 2 of the License, or (at your option)
154-- any later version.
155-- wrappers-generator is distributed in the hope that it will be useful, but
156-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
157-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
158-- more details.
159-- You should have received a copy of the GNU General Public License along with
160-- th program.  If not, see <http://www.gnu.org/licenses/>.