source: CMT/v1r14p20031120/src/cmt_constituent.cxx @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 14.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5
6#include "cmt_constituent.h"
7#include "cmt_generator.h"
8#include "cmt_system.h"
9#include "cmt_database.h"
10
11/*----------------------------------------------------------*/
12/*                                                          */
13/*  Operations on Constituent                               */
14/*                                                          */
15/*----------------------------------------------------------*/
16
17//----------------------------------------------------------
18void Constituent::show (const cmt_string& name)
19{
20  Constituent* cptr = find (name);
21  if (cptr == 0) return;
22
23  const Constituent& constituent = *cptr;
24
25  constituent.show ();
26}
27
28//----------------------------------------------------------
29void Constituent::parse_all ()
30{
31  static ConstituentVector& Constituents = constituents ();
32
33  int number;
34
35  for (number = 0; number < Constituents.size (); number++)
36    {
37      Constituent& constituent = Constituents[number];
38
39      constituent.parse ();
40    }
41}
42
43//----------------------------------------------------------
44void Constituent::show_all ()
45{
46  static ConstituentVector& Constituents = constituents ();
47
48  int number;
49
50  for (number = 0; number < Constituents.size (); number++)
51    {
52      const Constituent& constituent = Constituents[number];
53
54      constituent.show ();
55    }
56}
57
58//----------------------------------------------------------
59void Constituent::show_names ()
60{
61  static ConstituentVector& Constituents = constituents ();
62
63  int number;
64
65  for (number = 0; number < Constituents.size (); number++)
66    {
67      Constituent& constituent = Constituents[number];
68      cout << constituent.name << endl;
69    }
70}
71
72//----------------------------------------------------------
73Constituent* Constituent::find (const cmt_string& name)
74{
75  static ConstituentVector& Constituents = constituents ();
76
77  int constituent_index;
78
79  if (Constituents.size () == 0) return (0);
80
81  for (constituent_index = 0;
82       constituent_index < Constituents.size ();
83       constituent_index++)
84    {
85      Constituent& constituent = Constituents[constituent_index];
86
87      if (constituent.name == name)
88        {
89          return (&constituent);
90        }
91    }
92
93  return (0);
94}
95
96class constituents_action_iterator
97{
98public:
99  typedef enum
100  {
101    ready,
102    need_include
103  } states;
104
105  constituents_action_iterator (Constituent& c) : m_constituent (c)
106  {
107    m_state = ready;
108  }
109
110  void set (const cmt_string& w)
111  {
112    int equal;
113
114    if (w == "") return;
115
116    if (m_state == need_include)
117      {
118        m_state = ready;
119
120        cmt_string& include = m_constituent.includes.add ();
121        include = w;
122      }
123
124    if (w == "-OS9")
125      {
126        m_constituent.need_OS9 = true;
127      }
128    else if ((w == "-Windows") ||
129             (w == "-windows"))
130      {
131        m_constituent.windows = true;
132      }
133    else if (w == "-no_share")
134      {
135        m_constituent.no_share = true;
136      }
137    else if (w == "-no_static")
138      {
139        m_constituent.no_static = true;
140      }
141    else if (w == "-prototypes")
142      {
143        m_constituent.need_prototypes = true;
144      }
145    else if (w == "-no_prototypes")
146      {
147        m_constituent.need_prototypes = false;
148      }
149    else if (w == "-check")
150      {
151        m_constituent.need_check = true;
152      }
153    else if (w == "-triggers")
154      {
155        if (m_constituent.type == Library)
156          {
157              //m_constituent.build_triggers = true;
158          }
159      }
160    else if (w == "-no_triggers")
161      {
162        if (m_constituent.type == Library)
163          {
164            m_constituent.build_triggers = false;
165          }
166      }
167    else if (w == "-I")
168      {
169        m_state = need_include;
170      }
171    else if (w.substr (0, 3) == "-s=")
172      {
173        w.substr (3, m_subdir);
174      }
175    else if (w.substr (0, 3) == "-x=")
176      {
177        cmt_string& exclude = m_constituent.excludes.add ();
178        w.substr (3, exclude);
179        cmt_regexp& exp = m_constituent.exclude_exprs.add ();
180        exp.set (exclude);
181      }
182    else if (w.substr (0, 3) == "-k=")
183      {
184        cmt_string& select = m_constituent.selects.add ();
185        w.substr (3, select);
186        cmt_regexp& exp = m_constituent.select_exprs.add ();
187        exp.set (select);
188      }
189    else if (w.substr (0, 8) == "-import=")
190      {
191        cmt_string& import = m_constituent.imports.add ();
192        w.substr (8, import);
193      }
194    else if (w.substr (0, 7) == "-group=")
195      {
196        cmt_string group_name = "";
197
198        w.substr (7, group_name);
199       
200        if (group_name != "")
201          {
202            m_constituent.group = Group::add (group_name);
203          }
204      }
205    else if (w.substr (0, 8) == "-suffix=")
206      {
207        w.substr (8, m_constituent.suffix);
208      }
209    else if ((equal = w.find ("=")) != cmt_string::npos)
210      {
211        cmt_string variable_name;
212        cmt_string variable_value;
213       
214        w.substr (0, equal, variable_name);
215        w.substr (equal + 1, variable_value);
216       
217        Variable* v = Variable::find (m_constituent.variables, variable_name);
218        if (v == 0)
219          {
220            v = &(m_constituent.variables.add ());
221            v->set (variable_name);
222          }
223
224        (*v) = variable_value;
225      }
226    else
227      {
228        // We have a normal source module
229 
230        cmt_string& module = m_constituent.modules.add ();
231       
232        module.erase (0);
233         
234        //
235        // The prefix explicitly provided in (w) has priority
236        // over the currently specified (m_subdir) when it is an
237        // absolute path
238        //
239        if (CmtSystem::absolute_path (w))
240          {
241            module += w;
242          }
243        else
244          {
245            cmt_string prefix;
246            cmt_string name = w;
247
248            CmtSystem::dirname (name, prefix);
249            if (prefix == "../src") CmtSystem::basename (name, name);
250
251            module += m_subdir;
252
253            if (module != "")
254              {
255                module += CmtSystem::file_separator ();
256              }
257
258            module += name;
259          }
260      }
261  }
262
263  Constituent& m_constituent;
264  cmt_string m_subdir;
265  states m_state;
266};
267
268//----------------------------------------------------------
269void Constituent::action (ConstituentType type,
270                          const CmtSystem::cmt_string_vector& words)
271{
272  cmt_string generator;
273  cmt_string name;
274  Constituent* constituent;
275
276  int i = 1;
277
278  if (type == Document)
279    {
280      generator = words[i];
281      if (generator == "") return;
282      i++;
283    }
284
285  name = words[i];
286  if (name == "") return;
287  i++;
288
289  constituent = add (type, name, generator);
290
291  for (;i < words.size (); i++)
292    {
293      const cmt_string& w = words[i];
294      cmt_string& parameter = constituent->parameters.add ();
295      parameter = w;
296    }
297}
298
299//----------------------------------------------------------
300void Constituent::parse ()
301{
302  if (parameters.size () == 0) return;
303
304  Constituent& me = *this;
305
306  modules.clear ();
307
308  constituents_action_iterator it (me);
309
310  for (int i = 0; i < parameters.size (); i++)
311    {
312      const cmt_string& w = parameters[i];
313      cmt_string ew = w;
314
315      Symbol::expand (ew);
316
317      CmtSystem::cmt_string_vector ws;
318
319      CmtSystem::split (ew, " \t", ws);
320
321      for (int j = 0; j < ws.size (); ++j)
322        {
323          const cmt_string& w = ws[j];
324         
325            //cerr << "Constituent " << name << " Setting module " << w << endl;
326          it.set (w);
327        }
328    }
329
330  parameters.clear ();
331}
332
333//----------------------------------------------------------
334Constituent* Constituent::add (ConstituentType type,
335                               const cmt_string& name,
336                               const cmt_string& generator)
337{
338  static ConstituentVector& Constituents = constituents ();
339
340  {
341    Constituent* constituent;
342
343    if (name == "") return (0);
344
345    constituent = find (name);
346    if (constituent != 0) return (constituent);
347  }
348
349  Constituent& constituent = Constituents.add ();
350  constituent.clear ();
351
352  constituent.name      = name;
353  constituent.generator = generator;
354  constituent.type      = type;
355  constituent.need_prototypes = Cmt::need_prototypes ();
356
357  return (&constituent);
358}
359
360
361//----------------------------------------------------------
362void Constituent::clear_all ()
363{
364  static ConstituentVector& Constituents = constituents ();
365
366  for (int i = 0; i < Constituents.size (); i++)
367    {
368      Constituent& c = Constituents[i];
369      c.clear ();
370    }
371  Constituents.clear ();
372}
373
374//----------------------------------------------------------
375Constituent::ConstituentVector& Constituent::constituents ()
376{
377  static Database& db = Database::instance ();
378  static ConstituentVector& Constituents = db.constituents ();
379
380  return (Constituents);
381}
382
383//----------------------------------------------------------
384Constituent::Constituent ()
385{
386  clear ();
387}
388
389//----------------------------------------------------------
390Constituent::~Constituent ()
391{
392}
393
394//----------------------------------------------------------
395void Constituent::clear ()
396{
397  name      = "";
398  generator = "";
399  type = Document;
400  group     = 0;
401  modules.clear ();
402  parameters.clear ();
403  need_OS9        = false;
404  windows         = false;
405  no_static       = false;
406  no_share        = false;
407  need_prototypes = false;
408  need_check      = false;
409  build_triggers  = false;
410  excludes.clear ();
411  exclude_exprs.clear ();
412  selects.clear ();
413  select_exprs.clear ();
414  includes.clear ();
415  imports.clear ();
416  variables.clear ();
417}
418
419//----------------------------------------------------------
420void Constituent::build_all_makefiles (bool simulation)
421{
422  static ConstituentVector& Constituents = constituents ();
423
424  int i;
425
426  for (i = 0; i < Constituents.size (); i++)
427    {
428      Constituent& constituent = Constituents[i];
429
430      constituent.build_makefile (simulation);
431    }
432}
433
434//----------------------------------------------------------
435void Constituent::build_all_msdev_files (bool simulation)
436{
437  static ConstituentVector& Constituents = constituents ();
438
439  int i;
440
441  Generator::build_msdev_workspace (Constituents);
442
443  for (i = 0; i < Constituents.size (); i++)
444    {
445      Constituent& constituent = Constituents[i];
446
447      constituent.build_msdev_file (simulation);
448    }
449}
450
451// Visual Studio.Net Support                                     
452//----------------------------------------------------------     
453void Constituent::build_all_vsnet_files (bool simulation)       
454{                                                               
455  static ConstituentVector& Constituents = constituents ();     
456                                                                 
457  int i;                                                         
458                                                                 
459  Generator::build_vsnet_workspace (Constituents);               
460                                                                 
461  for (i = 0; i < Constituents.size (); i++)                     
462    {                                                           
463      Constituent& constituent = Constituents[i];               
464                                                                 
465      constituent.build_vsnet_file (simulation);                 
466    }                                                           
467}                                                               
468                                                                 
469//----------------------------------------------------------
470void Constituent::build_makefile (bool simulation) const
471{
472  if (!simulation)
473    {
474      Generator::build_constituent_makefile (*this);
475    }
476    //else cout << command << endl;
477}
478
479//----------------------------------------------------------
480void Constituent::build_msdev_file (bool simulation) const
481{
482  if (!simulation)
483    {
484      Generator::build_msdev (*this);
485    }
486    //else cout << command << endl;
487}
488
489// Visual Studio.net Support                                 
490//---------------------------------------------------------- 
491void Constituent::build_vsnet_file (bool simulation) const   
492{                                                             
493  if (!simulation)                                           
494    {                                                         
495      Generator::build_vsnet (*this);                         
496    }
497    //else cout << command << endl;
498}
499
500//----------------------------------------------------------
501void Constituent::show () const
502{
503  int i;
504
505  switch (type)
506    {
507      case Library:
508        cout << "library";
509        break;
510      case Application:
511        cout << "application";
512        break;
513      case Document:
514        cout << "document " << generator;
515        break;
516    }
517 
518  cout << " " << name;
519 
520  if (group != 0)
521    {
522      cout << " -group=" << group->name ();
523    }
524 
525  if (suffix != 0)
526    {
527      cout << " -suffix=" << suffix;
528    }
529 
530  if ((type == Application) && need_check)
531    {
532      cout << " -check";
533    }
534 
535  if ((type == Library) && no_share)
536    {
537      cout << " -no_share";
538    }
539 
540  if ((type == Library) && no_static)
541    {
542      cout << " -no_static";
543    }
544 
545  if ((type == Library) && build_triggers)
546    {
547      cout << " -triggers";
548    }
549 
550  for (i = 0; i < (imports.size ()); i++)
551    {
552      const cmt_string& import_name = imports[i];
553     
554      cout << " -import=" << import_name;
555    }
556 
557  for (i = 0; i < (excludes.size ()); i++)
558    {
559      const cmt_string& exclude = excludes[i];
560     
561      cout << " -x=" << exclude;
562    }
563 
564  for (i = 0; i < (selects.size ()); i++)
565    {
566      const cmt_string& select = selects[i];
567     
568      cout << " -k=" << select;
569    }
570 
571  for (i = 0; i < (modules.size ()); i++)
572    {
573      const cmt_string& module_name = modules[i];
574     
575      cout << " " << module_name;
576    }
577 
578  for (i = 0; i < (variables.size ()); i++)
579    {
580      const Variable& v = variables[i];
581     
582      cout << " " << v.name << "=" << v.value;
583    }
584 
585  cout << endl;
586}
Note: See TracBrowser for help on using the repository browser.