File: c_mode.e

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (376 lines) | stat: -rw-r--r-- 13,465 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries
--
-- SmartEiffel is  free software;  you can redistribute it and/or  modify it
-- under  the terms of the  GNU General Public License, as published by  the
-- Free Software Foundation; either version 2, or (at your option) any later
-- version.
-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT 
-- ANY WARRANTY;  without  even the implied warranty  of MERCHANTABILITY  or
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-- more details.  You should have received a copy of  the GNU General Public
-- License along with SmartEiffel;  see the file COPYING.  If not,  write to
-- the Free Software Foundation,  Inc., 59 Temple Place - Suite 330,  Boston, 
-- MA 02111-1307, USA.
--
-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.
--			   - University of Nancy 1 - FRANCE
-- Copyright(C) 2003:      INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne
--			   - University of Nancy 2 - FRANCE
--
--		 Dominique COLNET, Suzanne COLLIN, Olivier ZENDRA,
--			   Philippe RIBET, Cyril ADRIAN
--
-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
--
class C_MODE
      --
      -- Used by the new-generation installer.
      --
inherit
   INSTALL_GLOBALS
   VISITABLE

creation
   {INSTALL} make

feature {C_MODE_VISITOR}

   accept(visitor: C_MODE_VISITOR) is
      do
         visitor.visit_c_mode(Current)
      end

feature {INSTALL}

   c_file:               INI_PARSER
   cpp_file:             INI_PARSER
   name:                 STRING
   c_compiler_type:      STRING
   c_compiler_path:      STRING
   c_compiler_options:   STRING
   c_linker_path:        STRING
   c_linker_options:     STRING
   cpp_compiler_type:    STRING
   cpp_compiler_path:    STRING
   cpp_compiler_options: STRING
   cpp_linker_path:      STRING
   cpp_linker_options:   STRING
   smarteiffel_options:  STRING

   could_read_template:  BOOLEAN
         -- True if a template was used by the last `set_c_compiler_type'
         -- call.

   reset(a_name: like name;
         a_c_file: like ini_parser; a_c_compiler_type: like c_compiler_type
         a_cpp_file: like ini_parser; a_cpp_compiler_type: like cpp_compiler_type) is
      require
         name_not_void:      a_name /= Void

         compiler_exists:    a_c_compiler_type /= Void

         good_c_file:        a_c_file /= Void
                             implies a_c_compiler_type.is_equal(a_c_file.item(fz_conf_compiler_type))

         good_cpp_file:      a_cpp_file /= Void
                             implies (a_cpp_compiler_type /= Void
                                      and then a_cpp_compiler_type.is_equal(a_cpp_file.item(fz_conf_cpp_compiler_type)))

         known_c_compiler:   a_c_compiler_type /= fz_conf_undefined
                             implies system_tools.compiler_list.has(a_c_compiler_type)

         known_cpp_compiler: a_cpp_compiler_type /= fz_conf_undefined
                             implies system_tools.c_plus_plus_compiler_list.has(a_cpp_compiler_type)
      do
         name.copy(a_name)
         c_file := a_c_file
         if a_c_compiler_type /= fz_conf_undefined then
            c_compiler_type := system_tools.compiler_list.item(system_tools.compiler_list.index_of(a_c_compiler_type))
         end
         cpp_file := a_cpp_file
         if a_cpp_compiler_type /= fz_conf_undefined then
            cpp_compiler_type := system_tools.c_plus_plus_compiler_list.item(system_tools.c_plus_plus_compiler_list.index_of(a_cpp_compiler_type))
         end
         read_template
      end

   set_c_compiler_path(ccp: STRING) is
      do
         if ccp = Void then
            c_compiler_path := Void
         else
            buf_c_compiler_path.copy(ccp)
            c_compiler_path := buf_c_compiler_path
         end
      ensure
         ccp = Void implies c_compiler_path = Void
         ccp /= Void implies c_compiler_path.is_equal(ccp)
      end

   set_c_compiler_options(cco: STRING) is
      do
         if cco = Void then
            c_compiler_options := Void
         else
            buf_c_compiler_options.copy(cco)
            c_compiler_options := buf_c_compiler_options
         end
         if c_same then
            if cco = Void then
               c_linker_options := Void
            else
               buf_c_linker_options.copy(cco)
               c_linker_options := buf_c_linker_options
            end
         end
      ensure
         cco = Void implies c_compiler_options = Void
         cco /= Void implies c_compiler_options.is_equal(cco)
      end

   set_c_linker_path(clp: STRING) is
      do
         if clp = Void then
            c_linker_path := Void
         else
            buf_c_linker_path.copy(clp)
            c_linker_path := buf_c_linker_path
         end
      ensure
         clp = Void implies c_linker_path = Void
         clp /= Void implies c_linker_path.is_equal(clp)
      end

   set_c_linker_options(clo: STRING) is
      do
         if clo = Void then
            c_linker_options := Void
         else
            buf_c_linker_options.copy(clo)
            c_linker_options := buf_c_linker_options
         end
         c_same := False
      ensure
         clo = Void implies c_linker_options = Void
         clo /= Void implies c_linker_options.is_equal(clo)
      end

   set_cpp_compiler_path(ccp: STRING) is
      do
         if ccp = Void then
            cpp_compiler_path := Void
         else
            buf_cpp_compiler_path.copy(ccp)
            cpp_compiler_path := buf_cpp_compiler_path
         end
      ensure
         ccp = Void implies cpp_compiler_path = Void
         ccp /= Void implies cpp_compiler_path.is_equal(ccp)
      end

   set_cpp_compiler_options(cco: STRING) is
      do
         if cco = Void then
            cpp_compiler_options := Void
         else
            buf_cpp_compiler_options.copy(cco)
            cpp_compiler_options := buf_cpp_compiler_options
         end
         if cpp_same then
            if cco = Void then
               cpp_linker_options := Void
            else
               buf_cpp_linker_options.copy(cco)
               cpp_linker_options := buf_cpp_linker_options
            end
         end
      ensure
         cco = Void implies cpp_compiler_options = Void
         cco /= Void implies cpp_compiler_options.is_equal(cco)
      end

   set_cpp_linker_path(clp: STRING) is
      do
         if clp = Void then
            cpp_linker_path := Void
         else
            buf_cpp_linker_path.copy(clp)
            cpp_linker_path := buf_cpp_linker_path
         end
      ensure
         clp = Void implies cpp_linker_path = Void
         clp /= Void implies cpp_linker_path.is_equal(clp)
      end

   set_cpp_linker_options(clo: STRING) is
      do
         if clo = Void then
            cpp_linker_options := Void
         else
            buf_cpp_linker_options.copy(clo)
            cpp_linker_options := buf_cpp_linker_options
         end
         cpp_same := False
      ensure
         clo = Void implies cpp_linker_options = Void
         clo /= Void implies cpp_linker_options.is_equal(clo)
      end

   set_smarteiffel_options(so: STRING) is
      do
         if so = Void then
            smarteiffel_options := Void
         else
            buf_smarteiffel_options.copy(so)
            smarteiffel_options := buf_smarteiffel_options
         end
      ensure
         so = Void implies smarteiffel_options = Void
         so /= Void implies smarteiffel_options.is_equal(so)
      end

feature {NONE}

   make(a_name: like name;
        a_c_file: like c_file; a_c_compiler_type: like c_compiler_type
        a_cpp_file: like cpp_file; a_cpp_compiler_type: like cpp_compiler_type) is
      require
         name_not_void:      a_name /= Void

         compiler_exists:    a_c_compiler_type /= Void

         good_c_file:        a_c_file /= Void
                             implies a_c_compiler_type.is_equal(a_c_file.item(fz_conf_compiler_type))

         good_cpp_file:      a_cpp_file /= Void
                             implies (a_cpp_compiler_type /= Void
                                      and then a_cpp_compiler_type.is_equal(a_cpp_file.item(fz_conf_cpp_compiler_type)))

         known_c_compiler:   a_c_compiler_type /= fz_conf_undefined
                             implies system_tools.compiler_list.has(a_c_compiler_type)

         known_cpp_compiler: a_cpp_compiler_type /= fz_conf_undefined
                             implies system_tools.c_plus_plus_compiler_list.has(a_cpp_compiler_type)
      do
         -- Create buffers:
         create name.make(8)
         create buf_c_compiler_path.make(16)
         create buf_c_compiler_options.make(16)
         create buf_c_linker_path.make(16)
         create buf_c_linker_options.make(16)
         create buf_cpp_compiler_path.make(16)
         create buf_cpp_compiler_options.make(16)
         create buf_cpp_linker_path.make(16)
         create buf_cpp_linker_options.make(16)
         create buf_smarteiffel_options.make(16)

         reset(a_name, a_c_file, a_c_compiler_type, a_cpp_file, a_cpp_compiler_type)
      end

   read_template is
         -- Reads the template into the keys of this C mode.
      local
         tmp: STRING
         rc: INI_PARSER
      do
         set_c_compiler_path(Void)
         set_c_compiler_options(Void)
         set_c_linker_path(Void)
         set_c_linker_options(Void)
         set_cpp_compiler_path(Void)
         set_cpp_compiler_options(Void)
         set_cpp_linker_path(Void)
         set_cpp_linker_options(Void)
         set_smarteiffel_options(Void)
         c_same := False
         cpp_same := False

         could_read_template := False
         rc := c_file
         if rc /= Void then
            could_read_template := rc.has(fz_conf_compiler_type)
               and then rc.item(fz_conf_compiler_type).is_equal(c_compiler_type)
            if could_read_template then

               if rc.section_has(name, fz_conf_compiler_path) then
                  tmp := rc.section_item(name, fz_conf_compiler_path)
                  set_c_compiler_path(tmp)
               end
               if rc.section_has(name, fz_conf_compiler_options) then
                  tmp := rc.section_item(name, fz_conf_compiler_options)
                  set_c_compiler_options(tmp)
               end
               if rc.section_has(name, fz_conf_linker_path) then
                  tmp := rc.section_item(name, fz_conf_linker_path)
                  set_c_linker_path(tmp)
               end
               if rc.section_has(name, fz_conf_linker_options) then
                  tmp := rc.section_item(name, fz_conf_linker_options)
                  set_c_linker_options(tmp)
               end
               if rc.section_has(name, fz_conf_smarteiffel_options) then
                  tmp := rc.section_item(name, fz_conf_smarteiffel_options)
                  set_smarteiffel_options(tmp)
               end

               c_same := c_compiler_options = c_linker_options
               if not c_same and then c_compiler_options /= Void and then c_linker_options /= Void then
                  c_same := c_compiler_options.is_equal(c_linker_options)
               end
            end
         end

         rc := cpp_file
         if rc /= Void then
            could_read_template := could_read_template
               and then rc.has(fz_conf_cpp_compiler_type)
               and then (rc.item(fz_conf_cpp_compiler_type).is_equal(cpp_compiler_type)
                         or else rc.item(fz_conf_compiler_type).is_equal(cpp_compiler_type))
            if could_read_template then
               cpp_compiler_type := system_tools.c_plus_plus_compiler_list.item(system_tools.c_plus_plus_compiler_list.index_of(rc.item(fz_conf_cpp_compiler_type)));

               if rc.section_has(name, fz_conf_cpp_compiler_path) then
                  tmp := rc.section_item(name, fz_conf_cpp_compiler_path)
                  set_cpp_compiler_path(tmp)
               end
               if rc.section_has(name, fz_conf_cpp_compiler_options) then
                  tmp := rc.section_item(name, fz_conf_cpp_compiler_options)
                  set_cpp_compiler_options(tmp)
               end
               if rc.section_has(name, fz_conf_cpp_linker_path) then
                  tmp := rc.section_item(name, fz_conf_cpp_linker_path)
                  set_cpp_linker_path(tmp)
               end
               if rc.section_has(name, fz_conf_cpp_linker_options) then
                  tmp := rc.section_item(name, fz_conf_cpp_linker_options)
                  set_cpp_linker_options(tmp)
               end

               cpp_same := cpp_compiler_options = cpp_linker_options
               if not cpp_same and then cpp_compiler_options /= Void and then cpp_linker_options /= Void then
                  cpp_same := cpp_compiler_options.is_equal(cpp_linker_options)
               end
            end
         end
      end

   buf_c_compiler_path: STRING
   buf_c_compiler_options: STRING
   buf_c_linker_path: STRING
   buf_c_linker_options: STRING
   buf_cpp_compiler_path: STRING
   buf_cpp_compiler_options: STRING
   buf_cpp_linker_path: STRING
   buf_cpp_linker_options: STRING
   buf_smarteiffel_options: STRING

   c_same: BOOLEAN
   cpp_same: BOOLEAN

invariant

   name /= Void
   c_compiler_type /= Void
   cpp_file /= Void implies cpp_compiler_type /= Void

end