Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DependencyAnalyzer Class Reference

Inheritance diagram for DependencyAnalyzer

Inheritance graph
[legend]
Collaboration diagram for DependencyAnalyzer:

Collaboration graph
[legend]
List of all members.

Public Methods

 DependencyAnalyzer (const cmt_string& package_name, Constituent& constituent_ref)
void begin ()
void filter (const cmt_string& line)
virtual void end ()

Protected Methods

void add_trigger (const cmt_string& name)
void add_use (Libmap& libmap)

Protected Attributes

CmtSystem::cmt_string_vector include_dirs
cmt_vector<Libmap*> uses
CmtSystem::cmt_string_vector triggers
Constituentconstituent
cmt_string package
cmt_string package_upper

Constructor & Destructor Documentation

DependencyAnalyzer::DependencyAnalyzer ( const cmt_string & package_name,
Constituent & constituent_ref )
 

Definition at line 380 of file cmt_triggers.cxx.

00381                                                                       :
00382         package (package_name),
00383         constituent (constituent_ref)
00384 {
00385   cmt_string dirs;
00386 
00387   int pos;
00388   char c;
00389 
00390   package_upper = package;
00391 
00392   for (pos = 0; pos < package_upper.size (); pos++)
00393     {
00394       c = package_upper[pos];
00395       package_upper[pos] = toupper (c);
00396     }
00397 
00398   CmtSystem::execute ("cmt show include_dirs", dirs);
00399   dirs.replace_all ("\n", "");
00400   CmtSystem::split (dirs, " ", include_dirs);
00401 }


Member Function Documentation

void DependencyAnalyzer::add_trigger ( const cmt_string & name ) [protected]
 

Definition at line 538 of file cmt_triggers.cxx.

Referenced by filter().

00539 {
00540   for (int i = 0; i < triggers.size (); i++)
00541     {
00542       const cmt_string& trigger = triggers[i];
00543 
00544       if (trigger == name) return;
00545     }
00546 
00547   cmt_string& new_trigger = triggers.add ();
00548 
00549   new_trigger = name;
00550 }

void DependencyAnalyzer::add_use ( Libmap & libmap ) [protected]
 

Definition at line 552 of file cmt_triggers.cxx.

Referenced by filter().

00553 {
00554   for (int i = 0; i < uses.size (); i++)
00555     {
00556       const Libmap& ref = *(uses[i]);
00557 
00558       if (ref == libmap) return;
00559     }
00560 
00561   uses.push_back (&libmap);
00562 }

void DependencyAnalyzer::begin ( ) [virtual]
 

Reimplemented from Awk.

Definition at line 403 of file cmt_triggers.cxx.

00404 {
00405 }

void DependencyAnalyzer::end ( ) [virtual]
 

Reimplemented from Awk.

Reimplemented in LibraryAnalyzer, and ApplicationAnalyzer.

Definition at line 534 of file cmt_triggers.cxx.

00535 {
00536 }

void DependencyAnalyzer::filter ( const cmt_string & line ) [virtual]
 

Reimplemented from Awk.

Definition at line 407 of file cmt_triggers.cxx.

00408 {
00409     /* Clip target out of dependency file... */
00410   int pos = line.find ("=");
00411   if ((pos == 0) || (pos == cmt_string::npos))
00412     {
00413       if (!Cmt::get_quiet ())
00414         {
00415           cerr << "  ERROR: Syntax in dependency file: " << line << endl;
00416           cerr << "  Missing = or target name." << endl;
00417         }
00418       exit (1);
00419     }
00420 
00421   cmt_string module;
00422 
00423   line.substr (0, pos, module);
00424   module.trim ();
00425   module.replace ("_dependencies", "");
00426 
00427   if (module == "cmt_path_make") return;
00428 
00429   int underscore = module.find_last_of ("_");
00430 
00431   if (underscore != cmt_string::npos)
00432     {
00433       module[underscore] = '.';
00434     }
00435 
00436   static cmt_string dependencies;
00437 
00438   line.substr (pos + 1, dependencies);
00439 
00440   if (dependencies == "") 
00441     {
00442       cerr << "  WARNING: It seems there is nothing after \'=\' "
00443           "in dependency file " << m_file_name << endl;
00444       return;
00445     }
00446 
00447   CmtSystem::cmt_string_vector deps;
00448 
00449   CmtSystem::split (dependencies, " ", deps);
00450 
00451   for (int i = 0; i < deps.size (); i++)
00452     {
00453       const cmt_string& dep = deps[i];
00454 
00455         //
00456         // dep may either be:
00457         //  o the module itself
00458         //  o a file in one of include_dirs
00459         //  o something else
00460         //
00461 
00462       if (dep.find (module) != cmt_string::npos)
00463         {
00464           // This is the module itself.
00465         }
00466       else
00467         {
00468           bool found = false;
00469 
00470           for (int j = 0; j < include_dirs.size (); j++)
00471             {
00472               const cmt_string& dir = include_dirs[j];
00473 
00474               if (dep.find (dir) == 0)
00475                 {
00476                   // This is a local dependency.
00477 
00478                   cmt_string name = dep;
00479 
00480                   if (dir == "$(src)")
00481                     {
00482                       cmt_string new_dir;
00483 
00484                       new_dir = "$(";
00485                       new_dir += package_upper;
00486                       new_dir += "ROOT)/src/";
00487 
00488                       name.replace (dir, new_dir);
00489                     }
00490 
00491                   if (CmtSystem::file_separator () == '\\')
00492                     {
00493                       name.replace_all (CmtSystem::file_separator (), "/");
00494                     }
00495 
00496                   Libmap& libmap = Libmap::find_with_trigger (name);
00497 
00498                   if (libmap != Libmap::null ())
00499                     {
00500                       add_use (libmap);
00501                     }
00502                   else
00503                     {
00504                       add_trigger (name);
00505                     }
00506 
00507                   found = true;
00508                   break;
00509                 }
00510             }
00511 
00512           if (!found)
00513             {
00514               cmt_string name = dep;
00515 
00516               if (CmtSystem::file_separator () == '\\')
00517                 {
00518                   name.replace_all (CmtSystem::file_separator (), "/");
00519                 }
00520 
00521               // This is an external dependency.
00522 
00523               Libmap& libmap = Libmap::find_with_trigger (name);
00524 
00525               if (libmap != Libmap::null ())
00526                 {
00527                   add_use (libmap);
00528                 }
00529             }
00530         }
00531     }
00532 }


Member Data Documentation

Constituent & DependencyAnalyzer::constituent [protected]
 

Definition at line 357 of file cmt_triggers.cxx.

CmtSystem::cmt_string_vector DependencyAnalyzer::include_dirs [protected]
 

Definition at line 354 of file cmt_triggers.cxx.

cmt_string DependencyAnalyzer::package [protected]
 

Definition at line 358 of file cmt_triggers.cxx.

cmt_string DependencyAnalyzer::package_upper [protected]
 

Definition at line 359 of file cmt_triggers.cxx.

CmtSystem::cmt_string_vector DependencyAnalyzer::triggers [protected]
 

Definition at line 356 of file cmt_triggers.cxx.

cmt_vector< Libmap *> DependencyAnalyzer::uses [protected]
 

Definition at line 355 of file cmt_triggers.cxx.


The documentation for this class was generated from the following file:
Generated at Thu May 16 16:27:47 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000