From d4a6fb02ab5741aa41251653f0be3feb4594e553 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 2 Mar 2015 15:17:28 +0200 Subject: Cleanup to support clang compilation --- build/algorithm.cxx | 2 +- build/path-map | 4 +-- build/prefix-map | 59 +++++++++++++++++---------------------- build/target.cxx | 8 ++++-- tests/build/prefix-map/driver.cxx | 11 ++++---- 5 files changed, 39 insertions(+), 45 deletions(-) diff --git a/build/algorithm.cxx b/build/algorithm.cxx index 4c3ae08..5be5cad 100644 --- a/build/algorithm.cxx +++ b/build/algorithm.cxx @@ -54,7 +54,7 @@ namespace build const string& n (i->first); const rule& ru (i->second); - void* m; + void* m (nullptr); { auto g ( make_exception_guard ( diff --git a/build/path-map b/build/path-map index c422dde..ee2dd79 100644 --- a/build/path-map +++ b/build/path-map @@ -29,12 +29,12 @@ namespace build { typedef basic_path K; - typedef C char_type; + typedef C delimiter_type; typedef std::basic_string string_type; typedef compare_prefix> base; explicit - compare_prefix (C d): base (d) {} + compare_prefix (delimiter_type d): base (d) {} bool operator() (const K& x, const K& y) const diff --git a/build/prefix-map b/build/prefix-map index d98c842..5214fae 100644 --- a/build/prefix-map +++ b/build/prefix-map @@ -12,6 +12,19 @@ namespace build { + // A map of hierarchical "paths", e.g., 'foo.bar' or 'foo/bar' with + // the ability to retrieve a range of entries that have a specific + // prefix. The '.' and '/' above are the delimiter characters. + // + // Note that as a special rule, the default implementation of + // compare_prefix treats empty key as everyone's prefix even if + // the paths don't start with the delimiter (useful to represent + // a "root path"). + // + // Implementation-wise, the idea is to pretend that each key ends + // with the delimiter. This way we automatically avoid matching + // 'foobar' as having a prefix 'foo'. + // template struct compare_prefix; @@ -20,12 +33,12 @@ namespace build { typedef std::basic_string K; - typedef C char_type; + typedef C delimiter_type; typedef typename K::size_type size_type; typedef typename K::traits_type traits_type; explicit - compare_prefix (C d): d_ (d) {} + compare_prefix (delimiter_type d): d_ (d) {} bool operator() (const K& x, const K& y) const @@ -71,22 +84,9 @@ namespace build } private: - C d_; + delimiter_type d_; }; - // A map of hierarchical "paths", e.g., 'foo.bar' or 'foo/bar' with - // the ability to retrieve a range of entries that have a specific - // prefix. The '.' and '/' above are the delimiter characters. - // - // Note that as a special rule, the default implementation of - // compare_prefix treats empty key as everyone's prefix even if - // the paths don't start with the delimiter (useful to represent - // a "root path"). - // - // Implementation-wise, the idea is to pretend that each key ends - // with the delimiter. This way we automatically avoid matching - // 'foobar' as having a prefix 'foo'. - // template struct prefix_map_common: M { @@ -94,18 +94,17 @@ namespace build typedef typename map_type::key_type key_type; typedef typename map_type::value_type value_type; typedef typename map_type::key_compare compare_type; - typedef typename compare_type::char_type char_type; + typedef typename compare_type::delimiter_type delimiter_type; typedef typename map_type::iterator iterator; typedef typename map_type::const_iterator const_iterator; explicit - prefix_map_common (char_type delimiter) - : map_type (compare_type (delimiter)) {} + prefix_map_common (delimiter_type d) + : map_type (compare_type (d)) {} - prefix_map_common (std::initializer_list init, - char_type delimiter) - : map_type (std::move (init), compare_type (delimiter)) {} + prefix_map_common (std::initializer_list i, delimiter_type d) + : map_type (std::move (i), compare_type (d)) {} std::pair find_prefix (const key_type&); @@ -114,30 +113,24 @@ namespace build find_prefix (const key_type&) const; }; - template ::char_type D = 0> + template ::delimiter_type D> struct prefix_map_impl: prefix_map_common { typedef typename prefix_map_common::value_type value_type; prefix_map_impl (): prefix_map_common (D) {} - prefix_map_impl (std::initializer_list init) - : prefix_map_common (std::move (init), D) {} - }; - - template - struct prefix_map_impl: prefix_map_common - { - using prefix_map_common::prefix_map_common; + prefix_map_impl (std::initializer_list i) + : prefix_map_common (std::move (i), D) {} }; template ::char_type D = 0> + typename compare_prefix::delimiter_type D> using prefix_map = prefix_map_impl>, D>; template ::char_type D = 0> + typename compare_prefix::delimiter_type D> using prefix_multimap = prefix_map_impl>, D>; } diff --git a/build/target.cxx b/build/target.cxx index b4c4481..4168991 100644 --- a/build/target.cxx +++ b/build/target.cxx @@ -159,10 +159,12 @@ namespace build // since it will do nothing and it most likely not what the author // intended. // - if (target* t = search_existing_target (p)) - return t; + target* t (search_existing_target (p)); + + if (t == nullptr) + fail << "no explicit target for prerequisite " << p; - fail << "no explicit target for prerequisite " << p; + return t; } // type info diff --git a/tests/build/prefix-map/driver.cxx b/tests/build/prefix-map/driver.cxx index d365df2..2110d31 100644 --- a/tests/build/prefix-map/driver.cxx +++ b/tests/build/prefix-map/driver.cxx @@ -14,10 +14,10 @@ using namespace build; int main () { - typedef prefix_map pm; + typedef prefix_map pm; { - const pm m ('.'); + const pm m; { auto r (m.find_prefix ("")); @@ -31,7 +31,7 @@ main () } { - pm m {{{"foo", 1}}, '.'}; + pm m {{{"foo", 1}}}; { auto r (m.find_prefix ("")); @@ -67,7 +67,7 @@ main () } { - pm m {{{"foo", 1}, {"bar", 2}}, '.'}; + pm m {{{"foo", 1}, {"bar", 2}}}; { auto r (m.find_prefix ("")); @@ -113,8 +113,7 @@ main () pm m ( {{"boo", 1}, {"foo", 2}, {"fooa", 3}, {"foo.bar", 4}, {"foo.fox", 5}, - {"xoo", 5}}, - '.'); + {"xoo", 5}}); { auto r (m.find_prefix ("fo")); -- cgit v1.1