From 5164c843513212ab1ac1f721c4de04b6a865eb0c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 19 Jan 2017 16:50:40 +0200 Subject: Get rid of extension_pool --- build2/cc/common.cxx | 26 ++++++++++---------------- build2/cc/compile.cxx | 9 ++++----- build2/cc/link.cxx | 4 ++-- build2/cc/msvc.cxx | 13 ++++++------- build2/cc/pkgconfig.cxx | 5 +++-- 5 files changed, 25 insertions(+), 32 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index 86d998e..6429a38 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -408,7 +408,7 @@ namespace build2 { // This is import. // - const string* ext; + optional ext; const target_type* tt (s.find_target_type (n, ext)); // Changes name. if (tt == nullptr) @@ -455,7 +455,7 @@ namespace build2 // Windows. // bool l (p.is_a ()); - const string* ext (l ? nullptr : p.tk.ext); // Only for liba/libs. + const optional& ext (l ? nullopt : p.tk.ext); // Only liba/libs. // Then figure out what we need to search for. // @@ -464,7 +464,7 @@ namespace build2 // liba // path an; - const string* ae (nullptr); + optional ae; if (l || p.is_a ()) { @@ -494,10 +494,7 @@ namespace build2 e = "a"; } - ae = ext == nullptr - ? &extension_pool.find (e) - : ext; - + ae = ext ? ext : string (e); if (!ae->empty ()) { an += '.'; @@ -508,7 +505,7 @@ namespace build2 // libs // path sn; - const string* se (nullptr); + optional se; if (l || p.is_a ()) { @@ -528,10 +525,7 @@ namespace build2 else e = "so"; } - se = ext == nullptr - ? &extension_pool.find (e) - : ext; - + se = ext ? ext : string (e); if (!se->empty ()) { sn += '.'; @@ -574,7 +568,7 @@ namespace build2 // if (tclass == "windows") { - s = &targets.insert (d, dir_path (), name, nullptr, trace); + s = &targets.insert (d, dir_path (), name, nullopt, trace); if (s->member == nullptr) { @@ -606,7 +600,7 @@ namespace build2 s->mtime (mt); } } - else if (ext == nullptr && tsys == "mingw32") + else if (!ext && tsys == "mingw32") { // Above we searched for the import library (.dll.a) but if it's // not found, then we also search for the .dll (unless the @@ -614,7 +608,7 @@ namespace build2 // directly. Note also that the resulting libs{} would end up // being the .dll. // - se = &extension_pool.find ("dll"); + se = string ("dll"); f = f.base (); // Remove .a from .dll.a. mt = file_mtime (f); @@ -762,7 +756,7 @@ namespace build2 // lib& lt ( targets.insert ( - *pd, dir_path (), name, l ? p.tk.ext : nullptr, trace)); + *pd, dir_path (), name, l ? p.tk.ext : nullopt, trace)); // It should automatically link-up to the members we have found. // diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index 23499ad..f837765 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -415,12 +415,11 @@ namespace build2 // only use the target type and name from the target key so we can // pass bogus values for the rest. // - const string* dummy (nullptr); - target_key tk {&tt, nullptr, nullptr, &n, dummy}; + target_key tk {&tt, nullptr, nullptr, &n, target_key::nullext}; // This is like prerequisite search. // - if (const string* de = tt.extension (tk, s, true)) + if (optional de = tt.extension (tk, s, true)) if (*de == e) return true; @@ -913,7 +912,7 @@ namespace build2 // dir_path d (f.directory ()); string n (f.leaf ().base ().string ()); - const string* e (&extension_pool.find (f.extension ())); + string e (f.extension ()); // Determine the target type. // @@ -935,7 +934,7 @@ namespace build2 scope& bs (scopes.find (d)); if (scope* rs = bs.root_scope ()) { - tt = map_extension (bs, n, *e); + tt = map_extension (bs, n, e); if (bs.out_path () != bs.src_path () && d.sub (bs.src_path ())) out = out_src (d, *rs); diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx index 8010598..e1dac16 100644 --- a/build2/cc/link.cxx +++ b/build2/cc/link.cxx @@ -337,7 +337,7 @@ namespace build2 if (t.member != nullptr) // Might already be there. assert (t.member->type () == tt); else - t.member = &search (tt, t.dir, t.out, t.name, nullptr, nullptr); + t.member = &search (tt, t.dir, t.out, t.name, nullopt, nullptr); file& r (static_cast (*t.member)); r.recipe (a, group_recipe); @@ -519,7 +519,7 @@ namespace build2 // obj*{} is always in the out tree. // target& ot ( - search (tt, d, dir_path (), *cp.tk.name, nullptr, cp.scope)); + search (tt, d, dir_path (), *cp.tk.name, nullopt, cp.scope)); // If we are cleaning, check that this target is in the same or // a subdirectory of our project root. diff --git a/build2/cc/msvc.cxx b/build2/cc/msvc.cxx index 5ce2f2a..4ac82a0 100644 --- a/build2/cc/msvc.cxx +++ b/build2/cc/msvc.cxx @@ -231,7 +231,7 @@ namespace build2 // tracer trace (mod, "msvc_search_library"); - const string* ext (p.tk.ext); + const optional& ext (p.tk.ext); const string& name (*p.tk.name); // Assemble the file path. @@ -249,10 +249,9 @@ namespace build2 if (*sfx != '\0') f += sfx; - const string& e ( - ext == nullptr || p.is_a () // Only for liba/libs. - ? extension_pool.find ("lib") - : *ext); + const string& e (!ext || p.is_a () // Only for liba/libs. + ? string ("lib") + : *ext); if (!e.empty ()) { @@ -268,7 +267,7 @@ namespace build2 { // Enter the target. // - T& t (targets.insert (d, dir_path (), name, &e, trace)); + T& t (targets.insert (d, dir_path (), name, e, trace)); if (t.path ().empty ()) t.path (move (f)); @@ -323,7 +322,7 @@ namespace build2 msvc_search_library (x, ld, d, p, otype::s, pf, sf)) { r = &targets.insert ( - d, dir_path (), *p.tk.name, nullptr, trace); + d, dir_path (), *p.tk.name, nullopt, trace); if (r->member == nullptr) { diff --git a/build2/cc/pkgconfig.cxx b/build2/cc/pkgconfig.cxx index f8d35af..6c8159f 100644 --- a/build2/cc/pkgconfig.cxx +++ b/build2/cc/pkgconfig.cxx @@ -417,10 +417,11 @@ namespace build2 // dir_path out; string name (l, 2); // Sans -l. - const string* ext (nullptr); prerequisite_key pk { - nullopt, {&lib::static_type, &out, &out, &name, ext}, &s}; + nullopt, + {&lib::static_type, &out, &out, &name, target_key::nullext}, + &s}; if (lib* lt = static_cast (search_library (sysd, usrd, pk))) { -- cgit v1.1