From db2a696f810e41189bcdf5524696ff3d0cfbe5a9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Feb 2017 11:40:07 +0200 Subject: Use target:as<> instead of static_cast for target casting --- build2/cc/common.cxx | 4 ++-- build2/cc/compile.cxx | 12 ++++++------ build2/cc/link.cxx | 26 +++++++++++++------------- build2/cc/msvc.cxx | 6 +++--- build2/cc/windows-rpath.cxx | 3 +-- 5 files changed, 25 insertions(+), 26 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index 654ff53..7b8499c 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -439,7 +439,7 @@ namespace build2 if (const lib* l = xt->is_a ()) xt = &link_member (*l, lo); // Pick liba{} or libs{}. - return static_cast (*xt); + return xt->as (); } // Note that pk's scope should not be NULL (even if dir is absolute). If @@ -563,7 +563,7 @@ namespace build2 trace)); assert (!exist || !p.second); - r = static_cast (&p.first); + r = &p.first.template as (); }; auto search =[&a, &s, diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index 98d1218..5090f11 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -115,7 +115,7 @@ namespace build2 continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + pt->as (), a, nullptr, nullptr, optf); } } @@ -155,7 +155,7 @@ namespace build2 continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + pt->as (), a, nullptr, nullptr, optf); } } @@ -198,7 +198,7 @@ namespace build2 continue; process_libraries (bs, lo, sys_lib_dirs, - static_cast (*pt), a, + pt->as (), a, nullptr, nullptr, optf); } } @@ -208,7 +208,7 @@ namespace build2 { tracer trace (x, "compile::apply"); - file& t (static_cast (xt)); + file& t (xt.as ()); const match_data& md (t.data ()); const scope& bs (t.base_scope ()); @@ -1405,7 +1405,7 @@ namespace build2 target_state compile:: perform_update (action a, const target& xt) const { - const file& t (static_cast (xt)); + const file& t (xt.as ()); // Update prerequisites and determine if any relevant ones render us // out-of-date. Note that currently we treat all the prerequisites @@ -1632,7 +1632,7 @@ namespace build2 target_state compile:: perform_clean (action a, const target& xt) const { - const file& t (static_cast (xt)); + const file& t (xt.as ()); if (cid == "msvc") return clean_extra (a, t, {".d", ".idb", ".pdb"}); diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx index 6c17037..2bdf8c1 100644 --- a/build2/cc/link.cxx +++ b/build2/cc/link.cxx @@ -297,7 +297,7 @@ namespace build2 lk = b; append_ext (lk); - libi& li (static_cast (*ls.member)); + libi& li (ls.member->as ()); lk = li.derive_path (move (lk), tsys == "mingw32" ? "a" : "lib"); } else if (!v.empty ()) @@ -322,7 +322,7 @@ namespace build2 tracer trace (x, "link::apply"); - file& t (static_cast (xt)); + file& t (xt.as ()); const scope& bs (t.base_scope ()); const scope& rs (*bs.root_scope ()); @@ -341,7 +341,7 @@ namespace build2 else t.member = &search (tt, t.dir, t.out, t.name, nullptr, nullptr); - file& r (static_cast (*t.member)); + file& r (t.member->as ()); r.recipe (a, group_recipe); return r; }; @@ -541,7 +541,7 @@ namespace build2 // if (group) { - obj& o (static_cast (ot)); + obj& o (ot.as ()); switch (lt) { @@ -680,7 +680,7 @@ namespace build2 // (see search_library() for details). // if (win && f->member != nullptr && f->is_a ()) - f = static_cast (f->member.get ()); + f = &f->member->as (); args.push_back (relative (f->path ()).string ()); } @@ -727,7 +727,7 @@ namespace build2 // (see search_library() for details). // if (win && f->member != nullptr && f->is_a ()) - f = static_cast (f->member.get ()); + f = &f->member->as (); cs.append (f->path ().string ()); } @@ -893,11 +893,11 @@ namespace build2 { tracer trace (x, "link::perform_update"); + const file& t (xt.as ()); + auto oop (a.outer_operation ()); bool for_install (oop == install_id || oop == uninstall_id); - const file& t (static_cast (xt)); - const scope& bs (t.base_scope ()); const scope& rs (*bs.root_scope ()); @@ -1369,7 +1369,7 @@ namespace build2 // derived from the import library by changing the extension. // Lucky for us -- there is no option to name it. // - auto& imp (static_cast (*t.member)); + auto& imp (t.member->as ()); out2 = "/IMPLIB:" + relative (imp.path ()).string (); args.push_back (out2.c_str ()); } @@ -1379,9 +1379,9 @@ namespace build2 // if (find_option ("/DEBUG", args, true)) { + auto& pdb ( - static_cast ( - lt == otype::e ? *t.member : *t.member->member)); + (lt == otype::e ? t.member : t.member->member)->as ()); out1 = "/PDB:" + relative (pdb.path ()).string (); args.push_back (out1.c_str ()); } @@ -1415,7 +1415,7 @@ namespace build2 // On Windows libs{} is the DLL and its first ad hoc group // member is the import library. // - auto& imp (static_cast (*t.member)); + auto& imp (t.member->as ()); out = "-Wl,--out-implib=" + relative (imp.path ()).string (); args.push_back (out.c_str ()); } @@ -1629,7 +1629,7 @@ namespace build2 target_state link:: perform_clean (action a, const target& xt) const { - const file& t (static_cast (xt)); + const file& t (xt.as ()); switch (link_type (t)) { diff --git a/build2/cc/msvc.cxx b/build2/cc/msvc.cxx index 86a7d38..94064ca 100644 --- a/build2/cc/msvc.cxx +++ b/build2/cc/msvc.cxx @@ -69,7 +69,7 @@ namespace build2 // if (lt == otype::s && l.compare (0, 3, " ") == 0) { - path imp (static_cast (*t.member).path ().leaf ()); + path imp (t.member->as ().path ().leaf ()); if (l.find (imp.string ()) != string::npos && l.find (imp.base ().string () + ".exp") != string::npos) @@ -276,7 +276,7 @@ namespace build2 true, // Implied. trace)); assert (!exist || !p.second); - T& t (static_cast (p.first)); + T& t (p.first.template as ()); if (t.path ().empty ()) t.path (move (f)); @@ -340,7 +340,7 @@ namespace build2 true, // Implied. trace)); assert (!exist || !p.second); - r = static_cast (&p.first); + r = &p.first.as (); if (r->member == nullptr) { diff --git a/build2/cc/windows-rpath.cxx b/build2/cc/windows-rpath.cxx index 94b1145..46a3d3a 100644 --- a/build2/cc/windows-rpath.cxx +++ b/build2/cc/windows-rpath.cxx @@ -137,8 +137,7 @@ namespace build2 // const string* pdb ( l->member != nullptr && l->member->member != nullptr - ? &static_cast ( - *l->member->member).path ().string () + ? &l->member->member->as ().path ().string () : nullptr); r.insert (windows_dll {f, pdb, string ()}); -- cgit v1.1