Main Page | Class Hierarchy | Class List | File List | Class 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 Member Functions

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

Protected Member Functions

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 387 of file cmt_triggers.cxx.

References CmtSystem::execute(), include_dirs, package_upper, cmt_string::replace_all(), cmt_string::size(), and CmtSystem::split().

00388                                                                       :
00389         package (package_name),
00390         constituent (constituent_ref)
00391 {
00392   cmt_string dirs;
00393 
00394   int pos;
00395   char c;
00396 
00397   package_upper = package;
00398 
00399   for (pos = 0; pos < package_upper.size (); pos++)
00400     {
00401       c = package_upper[pos];
00402       package_upper[pos] = toupper (c);
00403     }
00404 
00405   CmtSystem::execute ("cmt show include_dirs", dirs);
00406   dirs.replace_all ("\n", "");
00407   CmtSystem::split (dirs, " ", include_dirs);
00408 }


Member Function Documentation

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

Definition at line 545 of file cmt_triggers.cxx.

References cmt_vector< T >::add(), cmt_vector< T >::size(), and triggers.

Referenced by filter().

00546 {
00547   for (int i = 0; i < triggers.size (); i++)
00548     {
00549       const cmt_string& trigger = triggers[i];
00550 
00551       if (trigger == name) return;
00552     }
00553 
00554   cmt_string& new_trigger = triggers.add ();
00555 
00556   new_trigger = name;
00557 }

void DependencyAnalyzer::add_use Libmap libmap  )  [protected]
 

Definition at line 559 of file cmt_triggers.cxx.

References cmt_vector< Libmap * >::push_back(), cmt_vector< Libmap * >::size(), and uses.

Referenced by filter().

00560 {
00561   for (int i = 0; i < uses.size (); i++)
00562     {
00563       const Libmap& ref = *(uses[i]);
00564 
00565       if (ref == libmap) return;
00566     }
00567 
00568   uses.push_back (&libmap);
00569 }

void DependencyAnalyzer::begin  )  [virtual]
 

Reimplemented from Awk.

Definition at line 410 of file cmt_triggers.cxx.

00411 {
00412 }

void DependencyAnalyzer::end  )  [virtual]
 

Reimplemented from Awk.

Reimplemented in LibraryAnalyzer, and ApplicationAnalyzer.

Definition at line 541 of file cmt_triggers.cxx.

00542 {
00543 }

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

Reimplemented from Awk.

Definition at line 414 of file cmt_triggers.cxx.

References add_trigger(), add_use(), CmtSystem::cmt_string_vector, CmtSystem::file_separator(), cmt_string::find(), cmt_string::find_last_of(), Libmap::find_with_trigger(), Cmt::get_quiet(), include_dirs, Libmap::null(), package_upper, cmt_string::replace(), cmt_string::replace_all(), cmt_vector< T >::size(), CmtSystem::split(), cmt_string::substr(), and cmt_string::trim().

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


Member Data Documentation

Constituent& DependencyAnalyzer::constituent [protected]
 

Definition at line 364 of file cmt_triggers.cxx.

CmtSystem::cmt_string_vector DependencyAnalyzer::include_dirs [protected]
 

Definition at line 361 of file cmt_triggers.cxx.

Referenced by DependencyAnalyzer(), and filter().

cmt_string DependencyAnalyzer::package [protected]
 

Definition at line 365 of file cmt_triggers.cxx.

cmt_string DependencyAnalyzer::package_upper [protected]
 

Definition at line 366 of file cmt_triggers.cxx.

Referenced by DependencyAnalyzer(), and filter().

CmtSystem::cmt_string_vector DependencyAnalyzer::triggers [protected]
 

Definition at line 363 of file cmt_triggers.cxx.

Referenced by add_trigger().

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

Definition at line 362 of file cmt_triggers.cxx.

Referenced by add_use().


The documentation for this class was generated from the following file:
Generated on Mon May 2 10:25:36 2005 for CMT by doxygen 1.3.5