Changeset 563 for CMT/HEAD


Ignore:
Timestamp:
Mar 16, 2011, 3:32:16 PM (13 years ago)
Author:
rybkin
Message:

See C.L. 446

Location:
CMT/HEAD
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r562 r563  
     12011-03-16    <rybkin@lal.in2p3.fr> 446
     2
     3        * source/cmt_use.h: In class Use, change signature of functions
     4        set_auto_imports_state, set_auto_imports
     5        * source/cmt_use.cxx: In helper class UseContext, introduce and implement
     6        function mask_auto_imports, in class use_action_iterator, in function
     7        get_use, do not deal with auto_imports state of added Use object. In class
     8        Use, function add, ensure that finally chosen Use object gets appended to
     9        sub_uses of context_use, it is used when setting auto_imports states.
     10        Implement functions set_auto_imports_state, set_auto_imports with modified
     11        signatures making sure all sub uses are operated upon recursively, order
     12        from last to first, depth first, and first encountered taking precedence
     13        * source/cmt_parser.cxx: In class Cmt, in function parser, configure
     14        auto_imports state of all uses after all requirements have been read. In
     15        class StandardMacroBuilder, in function fill_for_all_constituents, ensure
     16        that all sub uses of imported packages are also imported if not imported
     17        yet and not specified with -no_auto_imports option
     18        * source/cmt_project.cxx: In class ProjectFactory function create_project,
     19        use set_auto_imports with modified signature
     20       
    1212011-03-08    <rybkin@lal.in2p3.fr> 445
    222
  • CMT/HEAD/source/cmt_parser.cxx

    r562 r563  
    67296729    }
    67306730
     6731  //
     6732  // Set auto_imports
     6733  //
     6734
     6735  Use::UsePtrVector uses;
     6736  Use* use (0);
     6737  use = Use::find (CmtSystem::get_home_package ());
     6738  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
     6739    uses.push_back (use);
     6740  uses.push_back (&(Use::current()));
     6741  use = Use::find (CmtSystem::get_user_context_package ());
     6742  if (use != 0 && !use->discarded && !use->m_hidden && use->located ())
     6743    uses.push_back (use);
     6744
     6745  cmt_map <Use*, bool> visited;
     6746  for (int i = uses.size () - 1; i >= 0; i--)
     6747    {
     6748      Use* use = uses[i];
     6749      use->set_auto_imports (use->auto_imports, use->auto_imports, visited);
     6750    }
     6751
    67316752  if (Me.m_debug) cout << "parser3> current_tag=" << Me.m_current_tag << endl;
    67326753
     
    89358956         */
    89368957        cmt_vector<bool> auto_imports_states (base_auto_imports_states);
    8937        
     8958        Use::UsePtrVector uses;
     8959
    89388960        for (i = 0; i < constituent.imports.size (); i++)
    89398961          {
     
    89558977                if (Cmt::get_debug ())
    89568978                  {
    8957                     cout << constituent.name  << " needs imports " << import << " "
    8958                          << use_index << " "
    8959                          << u->get_package()->get_name() << " "
    8960                          << " u->auto_imports=" << u->auto_imports
    8961                          << " Off=" << Off
    8962                          << " On=" << On
     8979                    cout << constituent.name  << " needs imports " << import
     8980                         << " i=" << use_index << " package="
     8981                         << u->get_package()->get_name()
     8982                         << " auto_imports=" << u->auto_imports
     8983                         << " (Off=" << Off
     8984                         << " On=" << On << ")"
    89638985                         << endl;
    89648986                  }
     
    89678989                if (p->is_cmt ()) continue;
    89688990               
    8969                 if (u->auto_imports != Off) continue;
    8970                
    8971                 Use::set_auto_imports_state (use_index, auto_imports_states);
     8991                uses.push_back (u);
     8992                //u->set_auto_imports_state (auto_imports_states, visited);
     8993                //if (u->auto_imports != Off) continue;
     8994                //Use::set_auto_imports_state (use_index, auto_imports_states);
    89728995              }
    89738996            else
     
    89789001                                       " cannot be imported (requested for " +
    89799002                                       constituent.name +")");
     9003                if (Cmt::get_debug ())
     9004                  {
     9005                    cout << "import [" << i << "] "
     9006                         << ("package " + import +
     9007                             " cannot be imported (requested for " +
     9008                             constituent.name +")")  << endl;
     9009                  }
    89809010              }
    89819011          }
     9012
     9013        cmt_map <Use*, bool> visited;
     9014        static bool yes (true);
     9015        visited.add (&(Use::current()), yes);
     9016        Use::set_auto_imports_state (uses, auto_imports_states, visited);
    89829017       
    89839018        if (Cmt::get_debug ())
     
    89949029          {
    89959030            //      if (base_auto_imports_states[i]== On && auto_imports_states[i] == Off) continue;
    8996             if (base_auto_imports_states[i] == On || auto_imports_states[i] == Off) continue;
     9031            if (base_auto_imports_states[i] || !auto_imports_states[i]) continue;
     9032            //if (base_auto_imports_states[i] == On || auto_imports_states[i] == Off) continue;
    89979033            /**
    89989034             *  Consider the package (i) for import only if it is:
    8999              *   o not imported yet (i.e., base_auto_imports_states[i] != On)
     9035             *   o not imported yet (i.e., base_auto_imports_states[i] != true)
    90009036             *   o requested for import according to -import=xxx modifiers for
    9001              *     the current constituent (i.e., auto_imports_states[i] != Off)
     9037             *     the current constituent (i.e., auto_imports_states[i] != false)
    90029038             */
    90039039            Use* u = Uses[i];
  • CMT/HEAD/source/cmt_project.cxx

    r552 r563  
    645645      project_use->selected  = true;
    646646      project_use->m_located = true;
    647       project_use->set_auto_imports(Off);
     647      cmt_map <Use*, bool> visited;
     648      project_use->set_auto_imports(Unspecified, Off, visited);
     649      //project_use->set_auto_imports(Off);
    648650      project_use->initial_scope = ScopePublic;     
    649651      project->set_use(project_use);
  • CMT/HEAD/source/cmt_use.cxx

    r550 r563  
    7272  UseContext ()
    7373  {
    74     m_auto_imports = On;
     74    m_auto_imports = Unspecified;
     75    //m_auto_imports = On;
    7576  }
    7677
     
    99100
    100101    return (c.m_auto_imports);
     102  }
     103
     104  static State mask_auto_imports (State context_state, State auto_imports)
     105  {
     106    switch (auto_imports)
     107      {
     108      case Unspecified:
     109        return context_state;
     110        break;
     111      case Off:
     112        return Off;
     113        break;
     114      case On:
     115        if (context_state != Off)
     116          return On;
     117        else
     118          return context_state;
     119        break;
     120      }
    101121  }
    102122
     
    882902    // Here the version may contain wild cards
    883903
    884     UseContext save = UseContext::current ();
     904    //UseContext save = UseContext::current ();
    885905
    886906    /**
     
    888908     *  currently being parsed.
    889909     */
     910    //UseContext::set_current (UseContext::mask_auto_imports (UseContext::get_current_auto_imports (), auto_imports));
     911    /*
    890912    switch (auto_imports)
    891913      {
     
    894916        // unspecified => we forward the state saved in the current use context
    895917
    896         UseContext::set_current (UseContext::get_current_auto_imports ());
     918        //UseContext::set_current (UseContext::get_current_auto_imports ());
    897919        break;
    898920      case Off:
     
    913935        break;
    914936      }
    915 
     937*/
    916938    if (Cmt::get_debug ())
    917939      {
     
    934956                show_packages ();
    935957              }
    936 
     958            /*
     959            if (&(Use::current()) == parent)
     960              {
     961                cmt_map <Use*, bool> visited;
     962                static bool yes (true);
     963                visited.add (&(Use::current()), yes);
     964                new_use->set_auto_imports
     965                  (UseContext::mask_auto_imports (Use::current().auto_imports,
     966                                                  auto_imports),
     967                   auto_imports, visited);
     968              }
     969            */
     970            //new_use->set_auto_imports (UseContext::get_current_auto_imports (),
     971            //                 auto_imports);
     972            /*
    937973            switch (new_use->auto_imports)
    938974              {
     
    947983                break;
    948984              case Off:
    949                 if (UseContext::get_current_auto_imports () == On)
     985                if (UseContext::get_current_auto_imports () != Off)
     986                  //if (UseContext::get_current_auto_imports () == On)
    950987                  {
     988            */
    951989                    /**
    952990                     *  Warning : this Use had been previously specified as -no_auto_imports
     
    960998                     *
    961999                     */
    962                     new_use->set_auto_imports (On);
     1000            /*
     1001                    new_use->set_auto_imports (UseContext::get_current_auto_imports ());
     1002                    //new_use->set_auto_imports (On);
    9631003                  }
    9641004                break;
    9651005              }
    966 
     1006            */
    9671007
    9681008            if (Cmt::get_debug ())
     
    9731013              }
    9741014
    975             UseContext& c = UseContext::current ();
    976             c = save;
     1015            //UseContext& c = UseContext::current ();
     1016            //c = save;
    9771017
    9781018            Use::reorder (new_use, parent);
     
    11801220}
    11811221
     1222void Use::set_auto_imports_state (const Use::UsePtrVector& uses,
     1223                                  cmt_vector<bool>& auto_imports_states,
     1224                                  cmt_map <Use*, bool>& visited)
     1225{
     1226  if (0 == uses.size ()) return;
     1227  static bool yes (true);
     1228
     1229  static int level (-1);
     1230  if (Cmt::get_debug ())
     1231    {
     1232      level++;
     1233      cout << "Use::set_auto_imports_state>|";
     1234      for (int i = level; i > 0; i--) cout << "-";
     1235      for (int i = uses.size () - 1; i >= 0; i--)
     1236        {
     1237          cout << " " << uses[i]->get_package_name ()
     1238               << "(" << uses[i]->auto_imports << ")";
     1239        }
     1240      cout << ">" << endl;
     1241    }
     1242
     1243  for (int i = uses.size () - 1; i >= 0; i--)
     1244    {
     1245      Use* use = uses[i];
     1246      if (visited.has (use)) continue;
     1247      visited.add (use, yes);
     1248      if (!auto_imports_states[use->m_index])
     1249        auto_imports_states[use->m_index] = true;
     1250
     1251      Use::UsePtrVector subuses;
     1252      for (int i = 0; i < use->sub_uses.size (); i++)
     1253        {
     1254          if (use->sub_uses[i]->m_index >= 0)
     1255            {
     1256              if (use->sub_use_auto_imports[i] != Off)
     1257                {
     1258                  subuses.push_back (use->sub_uses[i]);
     1259                }
     1260              else
     1261                {
     1262                  visited.add (use->sub_uses[i], yes);
     1263                }
     1264            }
     1265          else
     1266            {
     1267              visited.add (use->sub_uses[i], yes);
     1268              if (Cmt::get_debug ())
     1269                {
     1270                  cout << "Use::set_auto_imports_state> " << use->get_package_name ()
     1271                       << ": sub_use " << use->sub_uses[i]->get_package_name () << "["
     1272                       << use->sub_uses[i] << "] invalid" << endl;
     1273                }
     1274            }
     1275        }
     1276      Use::set_auto_imports_state (subuses, auto_imports_states, visited);
     1277    }
     1278
     1279  if (Cmt::get_debug ())
     1280    {
     1281      cout << "Use::set_auto_imports_state><";
     1282      for (int i = level; i > 0; i--) cout << "-";
     1283      for (int i = uses.size () - 1; i >= 0; i--)
     1284        {
     1285          cout << " " << uses[i]->get_package_name ()
     1286               << "(" << (auto_imports_states[uses[i]->m_index] ? "+" : "-") << ")";
     1287        }
     1288      cout << "|" << endl;
     1289      level--;
     1290    }
     1291}
     1292
    11821293/**
    11831294 *   1) Given a Use object identified by its index in the ordered_uses() array,
     
    11881299 *
    11891300 */
     1301 /*
    11901302void Use::set_auto_imports_state (int use_index,
    11911303                                  cmt_vector<bool>& auto_imports_states)
     
    12171329  // check if this is already done (recursivity ending)
    12181330  if (auto_imports_states[use_index]) return;
     1331  auto_imports_states[use_index] = true;
    12191332
    12201333  Use* use = uses[use_index];
     
    12221335  // We only have to deal with Use objects that were
    12231336  // actually turned Off
    1224   if (use->auto_imports != Off) return;
    1225 
     1337  //  if (use->auto_imports != Off) return;
     1338  */
    12261339  /**
    12271340   *  Here, use points to a Use object which had been declared as
     
    12341347   */
    12351348 
    1236   auto_imports_states[use_index] = true;
    1237 
    1238   int size = 0;
    1239 
    1240   size = use->sub_uses.size ();
     1349  //  auto_imports_states[use_index] = true;
     1350  /*
     1351  cmt_string s;
     1352  static const cmt_string state_text[] = {"Unspecified", "Off", "On"};
     1353 
     1354  if (Cmt::get_debug ())
     1355    {
     1356      s = "Use::set_auto_imports_state>(";
     1357      s += use->get_package_name ();
     1358      s += ")";
     1359      //cout << s << endl;
     1360    }
     1361
     1362  int size = use->sub_uses.size ();
    12411363  for (int i = 0; i < size; i++)
    12421364    {
     
    12441366
    12451367      // first find the index of this use.
    1246 
     1368     
    12471369      int j = u->m_index;
    12481370
     1371      if (Cmt::get_debug ())
     1372        {
     1373          char num[32]; sprintf (num, "%#x", u);
     1374          s += " ";
     1375          s += use->sub_uses[i]->get_package_name ();
     1376          s += "(";
     1377          s += state_text[use->sub_use_auto_imports[i] + 1];
     1378          s += ")[p=";
     1379          s += num;
     1380          s += "]";
     1381        }
     1382     
    12491383      if (j >= 0)
    12501384        {
     1385          if (use->sub_use_auto_imports[i] != Off)
     1386            {
     1387              set_auto_imports_state (j, auto_imports_states);
     1388            }
     1389  */
     1390          /*
    12511391          if (u->sub_use_auto_imports[i] == Off)
    12521392            {
     
    12571397              auto_imports_states[j] = true;
    12581398            }
    1259         }
    1260     }
    1261 }
    1262 
     1399            */
     1400  /*
     1401        }
     1402      else
     1403        {
     1404          if (Cmt::get_debug ())
     1405            {
     1406              cout << "Use::set_auto_imports_state> " << use->get_package_name ()
     1407                   << ": sub_use " << u->get_package_name () << "[" << u
     1408                   << "] invalid" << endl;
     1409            }
     1410        }
     1411    }
     1412  if (Cmt::get_debug ())
     1413    {
     1414      cout << s << endl;
     1415    }
     1416}
     1417  */
    12631418//----------------------------------------------------------
    12641419//
     
    25532708               const cmt_string& native_version,
    25542709               Use* context_use,
    2555                State specified_auto_imports)
     2710               const State specified_auto_imports)
    25562711{
    25572712  bool do_need_new = false;
     
    26992854
    27002855      //CmtError::set (CmtError::package_not_found, use->get_package_name ());
    2701       //use->m_located = false;
    2702       use = 0;
     2856      use->m_located = false;
     2857      //use = 0;
    27032858    }
    27042859
     
    27352890           */
    27362891
    2737           if (use != 0) use->discard ();
     2892          //if (use != 0) use->discard ();
     2893          use->discard ();
    27382894          use = old_use;
     2895          if (context_use != 0)
     2896            {
     2897              context_use->sub_uses[context_use->sub_uses.size () - 1] = use;
     2898            }
    27392899          found = use->move_to (native_version);
    27402900        }
     
    27632923            {
    27642924              use = use->set_selected_version (selected_use);
     2925              if (context_use != 0)
     2926                {
     2927                  context_use->sub_uses[context_use->sub_uses.size () - 1] = use;
     2928                }
    27652929            }
    27662930         
     
    36373801      // it with the new one.
    36383802
     3803      if (Cmt::get_debug ())
     3804        {
     3805          cout << "set_selected_version> Replace "
     3806               << get_package_name () << "(" << m_index << ")[" << this << "] with "
     3807               << selected_use->get_package_name () << "(" << selected_use->m_index << ")[" << selected_use << "]" << endl;
     3808        }
     3809
    36393810      selected_use->m_index = m_index;
    36403811      selected_use->auto_imports = auto_imports;
     
    36523823}
    36533824
     3825void Use::set_auto_imports (State context_state, State specified_state,
     3826                            cmt_map <Use*, bool>& visited)
     3827{
     3828  if (visited.has (this)) return;
     3829
     3830  static int level (-1);
     3831  if (Cmt::get_debug ())
     3832    {
     3833      level++;
     3834      cout << "Use::set_auto_imports>|";
     3835      for (int i = level; i > 0; i--) cout << "-";
     3836      cout << get_package_name () << "> "
     3837           << auto_imports << " -> "
     3838           << "(" << context_state << ")" << specified_state << endl;
     3839    }
     3840
     3841  static bool yes (true);
     3842  visited.add (this, yes);
     3843  //  if (auto_imports == context_state) return;
     3844 
     3845  //State old_state = auto_imports;
     3846 
     3847  //auto_imports = context_state;
     3848
     3849  switch (context_state)
     3850    {
     3851    case Unspecified:
     3852    case On:
     3853      //if (auto_imports == specified_state) return;
     3854      auto_imports = specified_state;
     3855      /*
     3856      switch (auto_imports)
     3857        {
     3858        case Unspecified:
     3859          break;
     3860        case Off:
     3861          context_state = Off;
     3862          break;
     3863        case On:
     3864          context_state = On;
     3865          break;
     3866        }
     3867      */
     3868      context_state = UseContext::mask_auto_imports (context_state, auto_imports);
     3869      break;
     3870    case Off:
     3871      //if (auto_imports == context_state) return;
     3872      auto_imports = context_state;
     3873      break;
     3874    }
     3875  cmt_string s;
     3876  static const cmt_string state_text[] = {"Unspecified", "Off", "On"};
     3877 
     3878  if (Cmt::get_debug ())
     3879    {
     3880      s = "Use::set_auto_imports><";
     3881      for (int i = level; i > 0; i--) s += "-";
     3882      s += get_package_name ();
     3883      s += "|";
     3884      //cout << s << endl;
     3885    }
     3886 
     3887  for (int i = sub_uses.size () - 1; i >= 0; i--)
     3888    //for (int i = 0; i < sub_uses.size (); i++)
     3889    {
     3890      State state = sub_use_auto_imports[i];
     3891      if (Cmt::get_debug ())
     3892        {
     3893          s += " ";
     3894          s += sub_uses[i]->get_package_name ();
     3895          s += "(";
     3896          s += state_text[state + 1];
     3897          s += ")";
     3898        }
     3899      if (sub_uses[i]->m_index >= 0 && !sub_uses[i]->discarded)
     3900        {
     3901          sub_uses[i]->set_auto_imports (context_state, state, visited);
     3902        }
     3903      else
     3904        {
     3905          visited.add (sub_uses[i], yes);
     3906          if (Cmt::get_debug ())
     3907            {
     3908              char num[32]; sprintf (num, "%#x", sub_uses[i]);
     3909              s += "[";
     3910              s += num;
     3911              s += ", discarded=";
     3912              s += (sub_uses[i]->discarded ? "1" : "0");
     3913              s += "] invalid";
     3914            }
     3915        }
     3916    }
     3917
     3918  if (Cmt::get_debug ())
     3919    {
     3920      cout << s << endl;
     3921      level--;
     3922    }
     3923}
     3924/*
    36543925void Use::set_auto_imports (State new_state)
    36553926{
     
    36923963              s += u->get_package_name ();
    36933964              s += "(";
    3694               s += state_text[state];
     3965              s += state_text[state + 1];
    36953966              s += ")";
    36963967            }
     
    37083979    }
    37093980}
    3710 
     3981*/
    37113982void Use::set_native_version (bool state)
    37123983{
  • CMT/HEAD/source/cmt_use.h

    r550 r563  
    3232                         const cmt_string& version,
    3333                         const cmt_string& path);
    34   static void set_auto_imports_state (int use_index,
    35                                       cmt_vector<bool>& auto_imports_states);
     34  //static void set_auto_imports_state (int use_index,
     35  //cmt_vector<bool>& auto_imports_states);
     36  static void set_auto_imports_state (const Use::UsePtrVector& uses,
     37                                      cmt_vector<bool>& auto_imports_states,
     38                                      cmt_map <Use*, bool>& visited);
    3639  static Use* add (const cmt_string& path,
    3740                   const cmt_string& package,
     
    4144                   const cmt_string& native_version,
    4245                   Use* context_use,
    43                    State specified_auto_imports = Unspecified);
     46                   const State specified_auto_imports = Unspecified);
    4447  static void move (Use* use1);
    4548  static void reorder (Use* use1, Use* use2);
     
    120123
    121124  void change_path (const cmt_string& path);
    122   void set_auto_imports (State new_state);
     125  void set_auto_imports (State context_state, State specified_state,
     126                         cmt_map <Use*, bool>& visited);
     127  //  void set_auto_imports (State new_state);
     128  //void set_auto_imports_state (cmt_vector<bool>& auto_imports_states,
     129  //cmt_map <Use*, bool>& visited);
    123130  void set_native_version (bool state);
    124131  bool has_native_version () const;
Note: See TracChangeset for help on using the changeset viewer.