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

DepsBuilder Class Reference

#include <cmt_deps_builder.h>

Collaboration diagram for DepsBuilder:

[legend]
List of all members.

Public Methods

void? clear ()
void? add (const cmt_string &path, const cmt_string &substitution)
void? add_includes (const Use &use)
CmtSystem::cmt_string_vector &? run (const cmt_string &file_name)

Private Attributes

CmtSystem::cmt_string_vector? m_include_paths
CmtSystem::cmt_string_vector? m_substitutions
CmtSystem::cmt_string_vector? m_deps
CmtSystem::cmt_string_vector? m_all_deps

Member Function Documentation

void DepsBuilder::add (? const cmt_string &? ? path,
const cmt_string &? ? substitution
)?
?

Definition at line 617 of file cmt_deps_builder.cxx.

References cmt_string::erase(), CmtSystem::file_separator(), m_include_paths, m_substitutions, cmt_vector< cmt_string >::push_back(), and cmt_string::size().

Referenced by add_includes(), and CmtGenerator::prepare_use_context().

00618 {
00619   if (path[path.size () - 1] == CmtSystem::file_separator ())
00620     {
00621       cmt_string p = path;
00622       p.erase (path.size () - 1);
00623       m_include_paths.push_back (p);
00624     }
00625   else
00626     {
00627       m_include_paths.push_back (path);
00628     }
00629 
00630   m_substitutions.push_back (substitution);
00631 }

void DepsBuilder::add_includes (? const Use &? ? use )?
?

Definition at line 634 of file cmt_deps_builder.cxx.

References add(), CmtSystem::file_separator(), Symbol::find(), cmt_string::find(), CmtSystem::getenv(), Use::includes, Include::name, cmt_string::npos, cmt_string::replace_all(), Symbol::resolve_macro_value(), cmt_vector< Include >::size(), and cmt_string::substr().

Referenced by CmtGenerator::prepare_use_context().

00635 {
00636   const Include::IncludeVector& includes = use.includes;
00637   int include_number;
00638 
00639   for (include_number = 0;
00640        include_number < includes.size ();
00641        include_number++)
00642     {
00643       const Include& include = includes[include_number];
00644 
00645       cmt_string temp = include.name;
00646       cmt_string pattern;
00647       cmt_string name;
00648       char end_pattern;
00649 
00650       int start = 0;
00651 
00652       for (;;)
00653         {
00654           int begin;
00655 
00656           begin = temp.find (start, "${");
00657           if (begin != cmt_string::npos)
00658             {
00659               end_pattern = '}';
00660             }
00661           else
00662             {
00663               begin = temp.find (start, "$(");
00664               if (begin != cmt_string::npos)
00665                 {
00666                   end_pattern = ')';
00667                 }
00668               else
00669                 {
00670                   break;
00671                 }
00672             }
00673 
00674           start = begin + 2;
00675 
00676           int end;
00677           end = temp.find (start, end_pattern);
00678           if (end == cmt_string::npos) break;
00679           if (end < begin) break;
00680           start = end + 1;
00681 
00682           temp.substr (begin, end - begin + 1, pattern);
00683           temp.substr (begin + 2, end - begin - 2, name);
00684 
00685           Symbol* macro = Symbol::find (name);
00686           if (macro != 0)
00687             {
00688               cmt_string value = macro->resolve_macro_value ();
00689               value += CmtSystem::file_separator ();
00690               temp.replace_all (pattern, value);
00691             }
00692           else
00693             {
00694               cmt_string value = CmtSystem::getenv (name);
00695               value += CmtSystem::file_separator ();
00696               temp.replace_all (pattern, value);
00697             }
00698         }
00699       add (temp, include.name);
00700     }
00701 }

void DepsBuilder::clear (? ? )?
?

Definition at line 610 of file cmt_deps_builder.cxx.

References cmt_vector< cmt_string >::clear(), m_include_paths, and m_substitutions.

Referenced by CmtGenerator::prepare_use_context().

00611 {
00612   m_include_paths.clear ();
00613   m_substitutions.clear ();
00614 }

CmtSystem::cmt_string_vector & DepsBuilder::run (? const cmt_string &? ? file_name )?
?

Definition at line 704 of file cmt_deps_builder.cxx.

References CmtSystem::basename(), build_deps(), cmt_vector< cmt_string >::clear(), CmtSystem::dirname(), CmtSystem::execute(), Symbol::find(), m_all_deps, m_deps, m_include_paths, m_substitutions, cmt_vector< cmt_string >::push_back(), cmt_string::replace_all(), Symbol::resolve_macro_value(), cmt_vector< cmt_string >::size(), and CmtSystem::split().

Referenced by DependencyGenerator::build().

00705 {
00706   m_deps.clear ();
00707   m_all_deps.clear ();
00708 
00709   cmt_string preprocessor;
00710   Symbol* macro = Symbol::find ("preprocessor_command");
00711   if (macro != 0)
00712     {
00713       preprocessor = macro->resolve_macro_value ();
00714     }
00715 
00716   if (preprocessor == "")
00717     {
00718         //
00719         //   Since no preprocessor command is defined,
00720         // we use the internal mechanism provided here.
00721         //
00722       cmt_string new_dir;
00723 
00724       CmtSystem::dirname (file_name, new_dir);
00725 
00726       build_deps (file_name,
00727                   new_dir,
00728                   0,
00729                   m_include_paths,
00730                   m_substitutions,
00731                   m_all_deps,
00732                   m_deps);
00733     }
00734   else
00735     {
00736         //
00737         //  An external preprocessor command is defined. We expect it
00738         // to follow a "standard" syntax for its output, ie:
00739         //   o It starts with:
00740         //       .o: ...
00741         //   o There may be many lines with trailing back-slashes
00742         //   o All entries are space-separated
00743         //   o One of the entries is the source file name itself
00744         //
00745         //  The preprocessor command expects the list of -I options
00746         // (resolved from the "includes" macro) and the list of 
00747         // -D/-U options (resolved from the "*_pp_*flags" macros)
00748         //
00749 
00750         //
00751         // Building the complete command (still the pp_*flags are
00752         // missing)
00753         //
00754       preprocessor += " ";
00755       macro = Symbol::find ("includes");
00756       preprocessor += macro->resolve_macro_value ();
00757       preprocessor += " ";
00758       preprocessor += file_name;
00759       
00760       cmt_string output;
00761       
00762       CmtSystem::execute (preprocessor, output);
00763 
00764         //
00765         // Make the output as one single big line.
00766         //
00767 
00768       output.replace_all ("\n", " ");
00769       output.replace_all ("\\ ", " ");
00770       
00771       CmtSystem::cmt_string_vector files;
00772       
00773       CmtSystem::split (output, " \t", files);
00774 
00775         //
00776         // Analyze each entry
00777         //
00778       
00779       for (int i = 1; i < files.size (); i++)
00780         {
00781           const cmt_string& file = files[i];
00782           if (file == file_name) continue;
00783           
00784           cmt_string dir;
00785           cmt_string name;
00786           cmt_string full_name;
00787           
00788           CmtSystem::dirname (file, dir);
00789 
00790             //
00791             // Only declared include_paths will be taken into account
00792             // Others are considered as system include paths.
00793             //
00794           
00795           for (int j = 0; j < m_include_paths.size (); j++)
00796             {
00797               const cmt_string& p = m_include_paths[j];
00798               if (dir == p)
00799                 {
00800                   CmtSystem::basename (file, name);
00801                   full_name = m_substitutions[j];
00802                   full_name += name;
00803 
00804                     //
00805                     // We add in the "m_deps" list the symbolic form
00806                     // of the path rather that the expanded one.
00807                     //
00808                   
00809                   m_deps.push_back (full_name);
00810                   
00811                   break;
00812                 }
00813             }
00814         }
00815     }
00816 
00817   return (m_deps);
00818 }

Member Data Documentation

CmtSystem::cmt_string_vector DepsBuilder::m_all_deps [private]
?

Definition at line 28 of file cmt_deps_builder.h.

Referenced by run().

CmtSystem::cmt_string_vector DepsBuilder::m_deps [private]
?

Definition at line 27 of file cmt_deps_builder.h.

Referenced by run().

CmtSystem::cmt_string_vector DepsBuilder::m_include_paths [private]
?

Definition at line 24 of file cmt_deps_builder.h.

Referenced by add(), clear(), and run().

CmtSystem::cmt_string_vector DepsBuilder::m_substitutions [private]
?

Definition at line 25 of file cmt_deps_builder.h.

Referenced by add(), clear(), and run().


The documentation for this class was generated from the following files:
Generated on Wed Sep 1 11:00:18 2004 for CMT by 1.2.18