00001
00002
00003
00004
00005
00006
00007 #include
00008 #include
00009 #include
00010 #include
00011
00012 #include "cmt_constituent.h"
00013 #include "cmt_generator.h"
00014 #include "cmt_system.h"
00015 #include "cmt_database.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024 void Constituent::show (const cmt_string& name)
00025 {
00026 Constituent* cptr = find (name);
00027 if (cptr == 0) return;
00028
00029 const Constituent& constituent = *cptr;
00030
00031 constituent.show ();
00032 }
00033
00034
00035 void Constituent::parse_all ()
00036 {
00037 static ConstituentVector& Constituents = constituents ();
00038
00039 int number;
00040
00041 for (number = 0; number < Symbol::symbol_number (); number++)
00042 {
00043 Symbol& symbol = Symbol::symbol (number);
00044
00045 if (symbol.type != Symbol::SymbolAction) continue;
00046
00047 if (symbol.value_lists.size () < 1) continue;
00048
00049 cmt_string value = symbol.build_macro_value ();
00050
00051 if (value != "")
00052 {
00053 add_for_action (symbol.name);
00054 }
00055 }
00056
00057 for (number = 0; number < Constituents.size (); number++)
00058 {
00059 Constituent& constituent = Constituents[number];
00060
00061 constituent.parse ();
00062 }
00063 }
00064
00065
00066 void Constituent::show_all ()
00067 {
00068 static ConstituentVector& Constituents = constituents ();
00069
00070 int number;
00071
00072 for (number = 0; number < Constituents.size (); number++)
00073 {
00074 const Constituent& constituent = Constituents[number];
00075
00076 constituent.show ();
00077 }
00078 }
00079
00080
00081 void Constituent::show_names ()
00082 {
00083 static ConstituentVector& Constituents = constituents ();
00084
00085 int number;
00086
00087 for (number = 0; number < Constituents.size (); number++)
00088 {
00089 Constituent& constituent = Constituents[number];
00090 cout << constituent.name << endl;
00091 }
00092 }
00093
00094
00095 Constituent* Constituent::find (const cmt_string& name)
00096 {
00097 static ConstituentVector& Constituents = constituents ();
00098
00099 int constituent_index;
00100
00101 if (Constituents.size () == 0) return (0);
00102
00103 for (constituent_index = 0;
00104 constituent_index < Constituents.size ();
00105 constituent_index++)
00106 {
00107 Constituent& constituent = Constituents[constituent_index];
00108
00109 if (constituent.name == name)
00110 {
00111 return (&constituent);
00112 }
00113 }
00114
00115 return (0);
00116 }
00117
00118 class constituents_action_iterator
00119 {
00120 public:
00121 typedef enum
00122 {
00123 ready,
00124 need_include
00125 } states;
00126
00127 constituents_action_iterator (Constituent& c) : m_constituent (c)
00128 {
00129 m_state = ready;
00130 }
00131
00132 void set (const cmt_string& w)
00133 {
00134 int equal;
00135
00136 if (w == "") return;
00137
00138 if (m_state == need_include)
00139 {
00140 m_state = ready;
00141
00142 cmt_string& include = m_constituent.includes.add ();
00143 include = w;
00144 }
00145
00146 if (w == "-OS9")
00147 {
00148 m_constituent.need_OS9 = true;
00149 }
00150 else if ((w == "-Windows") ||
00151 (w == "-windows"))
00152 {
00153 m_constituent.windows = true;
00154 }
00155 else if (w == "-no_share")
00156 {
00157 m_constituent.no_share = true;
00158 }
00159 else if (w == "-no_static")
00160 {
00161 m_constituent.no_static = true;
00162 }
00163 else if (w == "-prototypes")
00164 {
00165 m_constituent.need_prototypes = true;
00166 }
00167 else if (w == "-no_prototypes")
00168 {
00169 m_constituent.need_prototypes = false;
00170 }
00171 else if (w == "-check")
00172 {
00173 m_constituent.need_check = true;
00174 }
00175 else if (w == "-triggers")
00176 {
00177 if (m_constituent.type == Library)
00178 {
00179
00180 }
00181 }
00182 else if (w == "-no_triggers")
00183 {
00184 if (m_constituent.type == Library)
00185 {
00186 m_constituent.build_triggers = false;
00187 }
00188 }
00189 else if (w == "-I")
00190 {
00191 m_state = need_include;
00192 }
00193 else if (w.substr (0, 3) == "-s=")
00194 {
00195 w.substr (3, m_subdir);
00196 }
00197 else if (w.substr (0, 3) == "-x=")
00198 {
00199 cmt_string& exclude = m_constituent.excludes.add ();
00200 w.substr (3, exclude);
00201 cmt_regexp& exp = m_constituent.exclude_exprs.add ();
00202 exp.set (exclude);
00203 }
00204 else if (w.substr (0, 3) == "-k=")
00205 {
00206 cmt_string& select = m_constituent.selects.add ();
00207 w.substr (3, select);
00208 cmt_regexp& exp = m_constituent.select_exprs.add ();
00209 exp.set (select);
00210 }
00211 else if (w.substr (0, 8) == "-import=")
00212 {
00213 cmt_string& import = m_constituent.imports.add ();
00214 w.substr (8, import);
00215 }
00216 else if (w.substr (0, 7) == "-group=")
00217 {
00218 cmt_string group_name = "";
00219
00220 w.substr (7, group_name);
00221
00222 if (group_name != "")
00223 {
00224 m_constituent.group = Group::add (group_name);
00225 }
00226 }
00227 else if (w.substr (0, 8) == "-suffix=")
00228 {
00229 w.substr (8, m_constituent.suffix);
00230 }
00231 else if (w == "-target_tag")
00232 {
00233 m_constituent.has_target_tag = true;
00234 }
00235 else if (w.substr (0, 1) == "-")
00236 {
00237 if (!Cmt::get_quiet ())
00238 {
00239 cerr << "#CMT> Warning: bad option "
00240 << w << " in constituent " << m_constituent.name << endl;
00241
00242 }
00243 }
00244 else if ((equal = w.find ("=")) != cmt_string::npos)
00245 {
00246 cmt_string variable_name;
00247 cmt_string variable_value;
00248
00249 w.substr (0, equal, variable_name);
00250 w.substr (equal + 1, variable_value);
00251
00252 Variable* v = Variable::find (m_constituent.variables, variable_name);
00253 if (v == 0)
00254 {
00255 v = &(m_constituent.variables.add ());
00256 v->set (variable_name);
00257 }
00258
00259 (*v) = variable_value;
00260 }
00261 else
00262 {
00263
00264
00265 cmt_string& module = m_constituent.modules.add ();
00266
00267 module.erase (0);
00268
00269
00270
00271
00272
00273
00274 if (CmtSystem::absolute_path (w))
00275 {
00276 module += w;
00277 }
00278 else
00279 {
00280 cmt_string prefix;
00281 cmt_string name = w;
00282
00283 CmtSystem::dirname (name, prefix);
00284 if (prefix == "../src") CmtSystem::basename (name, name);
00285
00286 module += m_subdir;
00287
00288 if (module != "")
00289 {
00290 module += CmtSystem::file_separator ();
00291 }
00292
00293 module += name;
00294 }
00295 }
00296 }
00297
00298 Constituent& m_constituent;
00299 cmt_string m_subdir;
00300 states m_state;
00301 };
00302
00303
00304 void Constituent::action (ConstituentType type,
00305 const CmtSystem::cmt_string_vector& words)
00306 {
00307 cmt_string generator;
00308 cmt_string name;
00309 Constituent* constituent;
00310
00311 int i = 1;
00312
00313 if (type == Document)
00314 {
00315 generator = words[i];
00316 if (generator == "") return;
00317 i++;
00318 }
00319
00320 name = words[i];
00321 if (name == "") return;
00322 i++;
00323
00324 constituent = add (type, name, generator);
00325
00326 for (;i < words.size (); i++)
00327 {
00328 const cmt_string& w = words[i];
00329 cmt_string& parameter = constituent->parameters.add ();
00330 parameter = w;
00331 }
00332 }
00333
00334
00335 void Constituent::parse ()
00336 {
00337 if (parameters.size () == 0) return;
00338
00339 Constituent& me = *this;
00340
00341 modules.clear ();
00342
00343 constituents_action_iterator it (me);
00344
00345 for (int i = 0; i < parameters.size (); i++)
00346 {
00347 const cmt_string& w = parameters[i];
00348 cmt_string ew = w;
00349
00350 Symbol::expand (ew);
00351
00352 CmtSystem::cmt_string_vector ws;
00353
00354
00355
00356 if (ew.substr (0, 13) == "action_value=")
00357 {
00358 it.set (ew);
00359 }
00360 else
00361 {
00362 CmtSystem::split (ew, " \t", ws);
00363
00364 for (int j = 0; j < ws.size (); ++j)
00365 {
00366 const cmt_string& w = ws[j];
00367
00368
00369 it.set (w);
00370 }
00371 }
00372 }
00373
00374 parameters.clear ();
00375 }
00376
00377
00378 Constituent* Constituent::add (ConstituentType type,
00379 const cmt_string& name,
00380 const cmt_string& generator)
00381 {
00382 static ConstituentVector& Constituents = constituents ();
00383
00384 {
00385 Constituent* constituent;
00386
00387 if (name == "") return (0);
00388
00389 constituent = find (name);
00390 if (constituent != 0) return (constituent);
00391 }
00392
00393 Constituent& constituent = Constituents.add ();
00394 constituent.clear ();
00395
00396 constituent.name = name;
00397 constituent.generator = generator;
00398 constituent.type = type;
00399 constituent.need_prototypes = Cmt::need_prototypes ();
00400
00401 return (&constituent);
00402 }
00403
00404
00405 Constituent* Constituent::add_for_action (const cmt_string& name)
00406 {
00407 Constituent* constituent;
00408
00409 constituent = add (Document, name, "cmt_action_runner");
00410
00411 constituent->group = Group::add ("cmt_actions");
00412 constituent->has_target_tag = true;
00413
00414 cmt_string& p1 = constituent->parameters.add ();
00415 p1 = "action_value=";
00416 p1 += "$(";
00417 p1 += name;
00418 p1 += ")";
00419
00420 return (constituent);
00421 }
00422
00423
00424 void Constituent::clear_all ()
00425 {
00426 static ConstituentVector& Constituents = constituents ();
00427
00428 for (int i = 0; i < Constituents.size (); i++)
00429 {
00430 Constituent& c = Constituents[i];
00431 c.clear ();
00432 }
00433 Constituents.clear ();
00434 }
00435
00436
00437 Constituent::ConstituentVector& Constituent::constituents ()
00438 {
00439 static Database& db = Database::instance ();
00440 static ConstituentVector& Constituents = db.constituents ();
00441
00442 return (Constituents);
00443 }
00444
00445
00446 Constituent::Constituent ()
00447 {
00448 clear ();
00449 }
00450
00451
00452 Constituent::~Constituent ()
00453 {
00454 }
00455
00456
00457 void Constituent::clear ()
00458 {
00459 name = "";
00460 generator = "";
00461 type = Document;
00462 group = 0;
00463 modules.clear ();
00464 parameters.clear ();
00465 need_OS9 = false;
00466 windows = false;
00467 no_static = false;
00468 no_share = false;
00469 need_prototypes = false;
00470 need_check = false;
00471 build_triggers = false;
00472 has_target_tag = false;
00473 excludes.clear ();
00474 exclude_exprs.clear ();
00475 selects.clear ();
00476 select_exprs.clear ();
00477 includes.clear ();
00478 imports.clear ();
00479 variables.clear ();
00480 }
00481
00482
00483 void Constituent::build_all_makefiles (bool simulation)
00484 {
00485 static ConstituentVector& Constituents = constituents ();
00486
00487 int i;
00488
00489 for (i = 0; i < Constituents.size (); i++)
00490 {
00491 Constituent& constituent = Constituents[i];
00492
00493 constituent.build_makefile (simulation);
00494 }
00495 }
00496
00497
00498 void Constituent::build_all_msdev_files (bool simulation)
00499 {
00500 static ConstituentVector& Constituents = constituents ();
00501
00502 int i;
00503
00504 Generator::build_msdev_workspace (Constituents);
00505
00506 for (i = 0; i < Constituents.size (); i++)
00507 {
00508 Constituent& constituent = Constituents[i];
00509
00510 constituent.build_msdev_file (simulation);
00511 }
00512 }
00513
00514
00515
00516 void Constituent::build_all_vsnet_files (bool simulation)
00517 {
00518 static ConstituentVector& Constituents = constituents ();
00519
00520 int i;
00521
00522 Generator::build_vsnet_workspace (Constituents);
00523
00524 for (i = 0; i < Constituents.size (); i++)
00525 {
00526 Constituent& constituent = Constituents[i];
00527
00528 constituent.build_vsnet_file (simulation);
00529 }
00530 }
00531
00532
00533 void Constituent::build_makefile (bool simulation) const
00534 {
00535 if (!simulation)
00536 {
00537 Generator::build_constituent_makefile (*this);
00538 }
00539 }
00540
00541
00542 void Constituent::build_msdev_file (bool simulation) const
00543 {
00544 if (!simulation)
00545 {
00546 Generator::build_msdev (*this);
00547 }
00548 }
00549
00550
00551
00552 void Constituent::build_vsnet_file (bool simulation) const
00553 {
00554 if (!simulation)
00555 {
00556 Generator::build_vsnet (*this);
00557 }
00558 }
00559
00560
00561 void Constituent::show () const
00562 {
00563 int i;
00564
00565 switch (type)
00566 {
00567 case Library:
00568 cout << "library";
00569 break;
00570 case Application:
00571 cout << "application";
00572 break;
00573 case Document:
00574 cout << "document " << generator;
00575 break;
00576 }
00577
00578 cout << " " << name;
00579
00580 if (group != 0)
00581 {
00582 cout << " -group=" << group->name ();
00583 }
00584
00585 if (suffix != 0)
00586 {
00587 cout << " -suffix=" << suffix;
00588 }
00589
00590 if ((type == Application) && need_check)
00591 {
00592 cout << " -check";
00593 }
00594
00595 if ((type == Library) && no_share)
00596 {
00597 cout << " -no_share";
00598 }
00599
00600 if ((type == Library) && no_static)
00601 {
00602 cout << " -no_static";
00603 }
00604
00605 if ((type == Library) && build_triggers)
00606 {
00607 cout << " -triggers";
00608 }
00609
00610 if (has_target_tag)
00611 {
00612 cout << " -target_tag";
00613 }
00614
00615 for (i = 0; i < (imports.size ()); i++)
00616 {
00617 const cmt_string& import_name = imports[i];
00618
00619 cout << " -import=" << import_name;
00620 }
00621
00622 for (i = 0; i < (excludes.size ()); i++)
00623 {
00624 const cmt_string& exclude = excludes[i];
00625
00626 cout << " -x=" << exclude;
00627 }
00628
00629 for (i = 0; i < (selects.size ()); i++)
00630 {
00631 const cmt_string& select = selects[i];
00632
00633 cout << " -k=" << select;
00634 }
00635
00636 for (i = 0; i < (modules.size ()); i++)
00637 {
00638 const cmt_string& module_name = modules[i];
00639
00640 cout << " " << module_name;
00641 }
00642
00643 for (i = 0; i < (variables.size ()); i++)
00644 {
00645 const Variable& v = variables[i];
00646
00647 cout << " " << v.name << "=" << v.value;
00648 }
00649
00650 cout << endl;
00651 }