aboutsummaryrefslogtreecommitdiff
path: root/build2/cc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-07 11:40:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:42 +0200
commitdb2a696f810e41189bcdf5524696ff3d0cfbe5a9 (patch)
tree754c198967576ce9c9bdb9b07fdb90ad05b0d8d3 /build2/cc
parentbcfcc38538af8bb896551c9e5730767807ad7a67 (diff)
Use target:as<> instead of static_cast for target casting
Diffstat (limited to 'build2/cc')
-rw-r--r--build2/cc/common.cxx4
-rw-r--r--build2/cc/compile.cxx12
-rw-r--r--build2/cc/link.cxx26
-rw-r--r--build2/cc/msvc.cxx6
-rw-r--r--build2/cc/windows-rpath.cxx3
5 files changed, 25 insertions, 26 deletions
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<lib> ())
xt = &link_member (*l, lo); // Pick liba{} or libs{}.
- return static_cast<const file&> (*xt);
+ return xt->as<file> ();
}
// 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<T*> (&p.first);
+ r = &p.first.template as<T> ();
};
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<const file&> (*pt), a,
+ pt->as<file> (), a,
nullptr, nullptr, optf);
}
}
@@ -155,7 +155,7 @@ namespace build2
continue;
process_libraries (bs, lo, sys_lib_dirs,
- static_cast<const file&> (*pt), a,
+ pt->as<file> (), a,
nullptr, nullptr, optf);
}
}
@@ -198,7 +198,7 @@ namespace build2
continue;
process_libraries (bs, lo, sys_lib_dirs,
- static_cast<const file&> (*pt), a,
+ pt->as<file> (), a,
nullptr, nullptr, optf);
}
}
@@ -208,7 +208,7 @@ namespace build2
{
tracer trace (x, "compile::apply");
- file& t (static_cast<file&> (xt));
+ file& t (xt.as<file> ());
const match_data& md (t.data<match_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<const file&> (xt));
+ const file& t (xt.as<file> ());
// 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<const file&> (xt));
+ const file& t (xt.as<file> ());
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<libi&> (*ls.member));
+ libi& li (ls.member->as<libi> ());
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<file&> (xt));
+ file& t (xt.as<file> ());
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<file&> (*t.member));
+ file& r (t.member->as<file> ());
r.recipe (a, group_recipe);
return r;
};
@@ -541,7 +541,7 @@ namespace build2
//
if (group)
{
- obj& o (static_cast<obj&> (ot));
+ obj& o (ot.as<obj> ());
switch (lt)
{
@@ -680,7 +680,7 @@ namespace build2
// (see search_library() for details).
//
if (win && f->member != nullptr && f->is_a<libs> ())
- f = static_cast<const file*> (f->member.get ());
+ f = &f->member->as<file> ();
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<libs> ())
- f = static_cast<const file*> (f->member.get ());
+ f = &f->member->as<file> ();
cs.append (f->path ().string ());
}
@@ -893,11 +893,11 @@ namespace build2
{
tracer trace (x, "link::perform_update");
+ const file& t (xt.as<file> ());
+
auto oop (a.outer_operation ());
bool for_install (oop == install_id || oop == uninstall_id);
- const file& t (static_cast<const file&> (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<const file&> (*t.member));
+ auto& imp (t.member->as<file> ());
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<const file&> (
- lt == otype::e ? *t.member : *t.member->member));
+ (lt == otype::e ? t.member : t.member->member)->as<file> ());
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<const file&> (*t.member));
+ auto& imp (t.member->as<file> ());
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<const file&> (xt));
+ const file& t (xt.as<file> ());
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<const file&> (*t.member).path ().leaf ());
+ path imp (t.member->as<file> ().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<T&> (p.first));
+ T& t (p.first.template as<T> ());
if (t.path ().empty ())
t.path (move (f));
@@ -340,7 +340,7 @@ namespace build2
true, // Implied.
trace));
assert (!exist || !p.second);
- r = static_cast<libs*> (&p.first);
+ r = &p.first.as<libs> ();
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<const file&> (
- *l->member->member).path ().string ()
+ ? &l->member->member->as<file> ().path ().string ()
: nullptr);
r.insert (windows_dll {f, pdb, string ()});