From 7b9eb752cad04aaadc4552d0f26d307b04af1869 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Feb 2017 08:09:53 +0200 Subject: Pass const target& to recipes --- build2/cc/compile.cxx | 67 +++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'build2/cc/compile.cxx') diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index 66ea9bd..98d1218 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -78,10 +78,11 @@ namespace build2 void compile:: append_lib_options (const scope& bs, cstrings& args, - target& t, + const target& t, lorder lo) const { - auto opt = [&args, this] (file& l, const string& t, bool com, bool exp) + auto opt = [&args, this] ( + const file& l, const string& t, bool com, bool exp) { // Note that in our model *.export.poptions are always "interface", // even if set on liba{}/libs{}, unlike loptions. @@ -98,31 +99,35 @@ namespace build2 // In case we don't have the "small function object" optimization. // - const function optf (opt); + const function optf (opt); // Note that here we don't need to see group members (see apply()). // - for (prerequisite& p: group_prerequisites (t)) + for (const prerequisite& p: const_group_prerequisites (t)) { - target* pt (p.target); // Already searched and matched. + const target* pt (p.target); // Already searched and matched. bool a; - if (lib* l = pt->is_a ()) + if (const lib* l = pt->is_a ()) a = (pt = &link_member (*l, lo))->is_a (); else if (!(a = pt->is_a ()) && !pt->is_a ()) continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + static_cast (*pt), a, nullptr, nullptr, optf); } } void compile:: - hash_lib_options (const scope& bs, sha256& cs, target& t, lorder lo) const + hash_lib_options (const scope& bs, + sha256& cs, + const target& t, + lorder lo) const { - auto opt = [&cs, this] (file& l, const string& t, bool com, bool exp) + auto opt = [&cs, this] ( + const file& l, const string& t, bool com, bool exp) { assert (exp); @@ -136,21 +141,21 @@ namespace build2 // In case we don't have the "small function object" optimization. // - const function optf (opt); + const function optf (opt); - for (prerequisite& p: group_prerequisites (t)) + for (const prerequisite& p: const_group_prerequisites (t)) { - target* pt (p.target); // Already searched and matched. + const target* pt (p.target); // Already searched and matched. bool a; - if (lib* l = pt->is_a ()) + if (const lib* l = pt->is_a ()) a = (pt = &link_member (*l, lo))->is_a (); else if (!(a = pt->is_a ()) && !pt->is_a ()) continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + static_cast (*pt), a, nullptr, nullptr, optf); } } @@ -164,7 +169,8 @@ namespace build2 target& t, lorder lo) const { - auto opt = [&m, this] (file& l, const string& t, bool com, bool exp) + auto opt = [&m, this] ( + const file& l, const string& t, bool com, bool exp) { assert (exp); @@ -178,7 +184,7 @@ namespace build2 // In case we don't have the "small function object" optimization. // - const function optf (opt); + const function optf (opt); for (prerequisite& p: group_prerequisites (t)) { @@ -192,7 +198,7 @@ namespace build2 continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + static_cast (*pt), a, nullptr, nullptr, optf); } } @@ -399,12 +405,15 @@ namespace build2 switch (a) { - case perform_update_id: - return [this] (action a, target& t) {return perform_update (a, t);}; - case perform_clean_id: - return [this] (action a, target& t) {return perform_clean (a, t);}; - default: - return noop_recipe; // Configure update. + case perform_update_id: return [this] (action a, const target& t) + { + return perform_update (a, t); + }; + case perform_clean_id: return [this] (action a, const target& t) + { + return perform_clean (a, t); + }; + default: return noop_recipe; // Configure update. } } @@ -440,7 +449,7 @@ namespace build2 } void compile:: - append_prefixes (prefix_map& m, target& t, const variable& var) const + append_prefixes (prefix_map& m, const target& t, const variable& var) const { tracer trace (x, "append_prefixes"); @@ -1394,15 +1403,15 @@ namespace build2 msvc_filter_cl (ifdstream&, const path& src); target_state compile:: - perform_update (action a, target& xt) const + perform_update (action a, const target& xt) const { - file& t (static_cast (xt)); + const file& t (static_cast (xt)); // Update prerequisites and determine if any relevant ones render us // out-of-date. Note that currently we treat all the prerequisites // as potentially affecting the result (for simplicity/performance). // - file* s; + const file* s; { auto p (execute_prerequisites (x_src, a, t, t.mtime ())); @@ -1621,9 +1630,9 @@ namespace build2 } target_state compile:: - perform_clean (action a, target& xt) const + perform_clean (action a, const target& xt) const { - file& t (static_cast (xt)); + const file& t (static_cast (xt)); if (cid == "msvc") return clean_extra (a, t, {".d", ".idb", ".pdb"}); -- cgit v1.1