Changeset 563 for CMT/HEAD/source
- Timestamp:
- Mar 16, 2011, 3:32:16 PM (14 years ago)
- Location:
- CMT/HEAD/source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
CMT/HEAD/source/cmt_parser.cxx
r562 r563 6729 6729 } 6730 6730 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 6731 6752 if (Me.m_debug) cout << "parser3> current_tag=" << Me.m_current_tag << endl; 6732 6753 … … 8935 8956 */ 8936 8957 cmt_vector<bool> auto_imports_states (base_auto_imports_states); 8937 8958 Use::UsePtrVector uses; 8959 8938 8960 for (i = 0; i < constituent.imports.size (); i++) 8939 8961 { … … 8955 8977 if (Cmt::get_debug ()) 8956 8978 { 8957 cout << constituent.name << " needs imports " << import << " "8958 << use_index << ""8959 << u->get_package()->get_name() << " "8960 << " u->auto_imports=" << u->auto_imports8961 << " Off=" << Off8962 << " 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 << ")" 8963 8985 << endl; 8964 8986 } … … 8967 8989 if (p->is_cmt ()) continue; 8968 8990 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); 8972 8995 } 8973 8996 else … … 8978 9001 " cannot be imported (requested for " + 8979 9002 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 } 8980 9010 } 8981 9011 } 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); 8982 9017 8983 9018 if (Cmt::get_debug ()) … … 8994 9029 { 8995 9030 // 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; 8997 9033 /** 8998 9034 * 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) 9000 9036 * 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) 9002 9038 */ 9003 9039 Use* u = Uses[i]; -
CMT/HEAD/source/cmt_project.cxx
r552 r563 645 645 project_use->selected = true; 646 646 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); 648 650 project_use->initial_scope = ScopePublic; 649 651 project->set_use(project_use); -
CMT/HEAD/source/cmt_use.cxx
r550 r563 72 72 UseContext () 73 73 { 74 m_auto_imports = On; 74 m_auto_imports = Unspecified; 75 //m_auto_imports = On; 75 76 } 76 77 … … 99 100 100 101 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 } 101 121 } 102 122 … … 882 902 // Here the version may contain wild cards 883 903 884 UseContext save = UseContext::current ();904 //UseContext save = UseContext::current (); 885 905 886 906 /** … … 888 908 * currently being parsed. 889 909 */ 910 //UseContext::set_current (UseContext::mask_auto_imports (UseContext::get_current_auto_imports (), auto_imports)); 911 /* 890 912 switch (auto_imports) 891 913 { … … 894 916 // unspecified => we forward the state saved in the current use context 895 917 896 UseContext::set_current (UseContext::get_current_auto_imports ());918 //UseContext::set_current (UseContext::get_current_auto_imports ()); 897 919 break; 898 920 case Off: … … 913 935 break; 914 936 } 915 937 */ 916 938 if (Cmt::get_debug ()) 917 939 { … … 934 956 show_packages (); 935 957 } 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 /* 937 973 switch (new_use->auto_imports) 938 974 { … … 947 983 break; 948 984 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) 950 987 { 988 */ 951 989 /** 952 990 * Warning : this Use had been previously specified as -no_auto_imports … … 960 998 * 961 999 */ 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); 963 1003 } 964 1004 break; 965 1005 } 966 1006 */ 967 1007 968 1008 if (Cmt::get_debug ()) … … 973 1013 } 974 1014 975 UseContext& c = UseContext::current ();976 c = save;1015 //UseContext& c = UseContext::current (); 1016 //c = save; 977 1017 978 1018 Use::reorder (new_use, parent); … … 1180 1220 } 1181 1221 1222 void 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 1182 1293 /** 1183 1294 * 1) Given a Use object identified by its index in the ordered_uses() array, … … 1188 1299 * 1189 1300 */ 1301 /* 1190 1302 void Use::set_auto_imports_state (int use_index, 1191 1303 cmt_vector<bool>& auto_imports_states) … … 1217 1329 // check if this is already done (recursivity ending) 1218 1330 if (auto_imports_states[use_index]) return; 1331 auto_imports_states[use_index] = true; 1219 1332 1220 1333 Use* use = uses[use_index]; … … 1222 1335 // We only have to deal with Use objects that were 1223 1336 // actually turned Off 1224 if (use->auto_imports != Off) return;1225 1337 // if (use->auto_imports != Off) return; 1338 */ 1226 1339 /** 1227 1340 * Here, use points to a Use object which had been declared as … … 1234 1347 */ 1235 1348 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 (); 1241 1363 for (int i = 0; i < size; i++) 1242 1364 { … … 1244 1366 1245 1367 // first find the index of this use. 1246 1368 1247 1369 int j = u->m_index; 1248 1370 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 1249 1383 if (j >= 0) 1250 1384 { 1385 if (use->sub_use_auto_imports[i] != Off) 1386 { 1387 set_auto_imports_state (j, auto_imports_states); 1388 } 1389 */ 1390 /* 1251 1391 if (u->sub_use_auto_imports[i] == Off) 1252 1392 { … … 1257 1397 auto_imports_states[j] = true; 1258 1398 } 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 */ 1263 1418 //---------------------------------------------------------- 1264 1419 // … … 2553 2708 const cmt_string& native_version, 2554 2709 Use* context_use, 2555 State specified_auto_imports)2710 const State specified_auto_imports) 2556 2711 { 2557 2712 bool do_need_new = false; … … 2699 2854 2700 2855 //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; 2703 2858 } 2704 2859 … … 2735 2890 */ 2736 2891 2737 if (use != 0) use->discard (); 2892 //if (use != 0) use->discard (); 2893 use->discard (); 2738 2894 use = old_use; 2895 if (context_use != 0) 2896 { 2897 context_use->sub_uses[context_use->sub_uses.size () - 1] = use; 2898 } 2739 2899 found = use->move_to (native_version); 2740 2900 } … … 2763 2923 { 2764 2924 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 } 2765 2929 } 2766 2930 … … 3637 3801 // it with the new one. 3638 3802 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 3639 3810 selected_use->m_index = m_index; 3640 3811 selected_use->auto_imports = auto_imports; … … 3652 3823 } 3653 3824 3825 void 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 /* 3654 3925 void Use::set_auto_imports (State new_state) 3655 3926 { … … 3692 3963 s += u->get_package_name (); 3693 3964 s += "("; 3694 s += state_text[state ];3965 s += state_text[state + 1]; 3695 3966 s += ")"; 3696 3967 } … … 3708 3979 } 3709 3980 } 3710 3981 */ 3711 3982 void Use::set_native_version (bool state) 3712 3983 { -
CMT/HEAD/source/cmt_use.h
r550 r563 32 32 const cmt_string& version, 33 33 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); 36 39 static Use* add (const cmt_string& path, 37 40 const cmt_string& package, … … 41 44 const cmt_string& native_version, 42 45 Use* context_use, 43 State specified_auto_imports = Unspecified);46 const State specified_auto_imports = Unspecified); 44 47 static void move (Use* use1); 45 48 static void reorder (Use* use1, Use* use2); … … 120 123 121 124 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); 123 130 void set_native_version (bool state); 124 131 bool has_native_version () const;
Note: See TracChangeset
for help on using the changeset viewer.