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