From e3e597180487328a54721e2afb95e33ed853d586 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 1 Feb 2017 16:36:24 +0200 Subject: Pass const scope& where modification should not happen --- build2/cc/common | 8 ++++---- build2/cc/common.cxx | 10 +++++----- build2/cc/compile | 10 +++++----- build2/cc/compile.cxx | 36 ++++++++++++++++++++++-------------- build2/cc/link | 12 ++++++------ build2/cc/link.cxx | 20 +++++++++++++------- build2/cc/pkgconfig.cxx | 2 +- build2/cc/utility | 2 +- build2/cc/utility.cxx | 2 +- build2/cc/windows-manifest.cxx | 2 +- build2/cc/windows-rpath.cxx | 10 ++++++---- 11 files changed, 65 insertions(+), 49 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common b/build2/cc/common index c11e733..06df4c3 100644 --- a/build2/cc/common +++ b/build2/cc/common @@ -184,7 +184,7 @@ namespace build2 // public: void - process_libraries (scope&, + process_libraries (const scope&, lorder, const dir_paths&, file&, @@ -210,7 +210,7 @@ namespace build2 private: file& - resolve_library (scope&, + resolve_library (const scope&, name, lorder, const dir_paths&, @@ -222,10 +222,10 @@ namespace build2 const prerequisite_key&) const; dir_paths - extract_library_dirs (scope&) const; + extract_library_dirs (const scope&) const; bool - pkgconfig_extract (scope&, + pkgconfig_extract (const scope&, bin::lib&, bin::liba*, bin::libs*, diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index aa0a45b..e7b26a1 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -46,7 +46,7 @@ namespace build2 // void common:: process_libraries ( - scope& top_bs, + const scope& top_bs, lorder top_lo, const dir_paths& top_sysd, file& l, @@ -183,7 +183,7 @@ namespace build2 proc_lib (&l, p, s); } - scope& bs (t == nullptr || cc ? top_bs : l.base_scope ()); + const scope& bs (t == nullptr || cc ? top_bs : l.base_scope ()); optional lo; // Calculate lazily. const dir_paths* sysd (nullptr); // Resolve lazily. @@ -386,7 +386,7 @@ namespace build2 // that's the only way to guarantee it will be up-to-date. // file& common:: - resolve_library (scope& s, + resolve_library (const scope& s, name n, lorder lo, const dir_paths& sysd, @@ -657,7 +657,7 @@ namespace build2 // if (cid == "msvc") { - scope& rs (*p.scope->root_scope ()); + const scope& rs (*p.scope->root_scope ()); const process_path& ld (cast (rs["bin.ld.path"])); if (s == nullptr && !sn.empty ()) @@ -821,7 +821,7 @@ namespace build2 } dir_paths common:: - extract_library_dirs (scope& bs) const + extract_library_dirs (const scope& bs) const { dir_paths r; diff --git a/build2/cc/compile b/build2/cc/compile index 11b3919..b6fc7d6 100644 --- a/build2/cc/compile +++ b/build2/cc/compile @@ -40,10 +40,10 @@ namespace build2 private: void - append_lib_options (scope&, cstrings&, target&, lorder) const; + append_lib_options (const scope&, cstrings&, target&, lorder) const; void - hash_lib_options (scope&, sha256&, target&, lorder) const; + hash_lib_options (const scope&, sha256&, target&, lorder) const; // Mapping of include prefixes (e.g., foo in ) for auto- // generated headers to directories where they will be generated. @@ -61,15 +61,15 @@ namespace build2 append_prefixes (prefix_map&, target&, const variable&) const; void - append_lib_prefixes (scope&, prefix_map&, target&, lorder) const; + append_lib_prefixes (const scope&, prefix_map&, target&, lorder) const; prefix_map - build_prefix_map (scope&, target&, lorder) const; + build_prefix_map (const scope&, target&, lorder) const; // Reverse-lookup target type from extension. // const target_type* - map_extension (scope&, const string&, const string&) const; + map_extension (const scope&, const string&, const string&) const; // Header dependency injection. // diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index bc35272..2176b82 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -76,7 +76,10 @@ namespace build2 // (first one is cc.export.*) recursively, prerequisite libraries first. // void compile:: - append_lib_options (scope& bs, cstrings& args, target& t, lorder lo) const + append_lib_options (const scope& bs, + cstrings& args, + target& t, + lorder lo) const { auto opt = [&args, this] (file& l, const string& t, bool com, bool exp) { @@ -117,7 +120,7 @@ namespace build2 } void compile:: - hash_lib_options (scope& bs, sha256& cs, target& t, lorder lo) const + hash_lib_options (const scope& bs, sha256& cs, target& t, lorder lo) const { auto opt = [&cs, this] (file& l, const string& t, bool com, bool exp) { @@ -156,7 +159,10 @@ namespace build2 // recursively, prerequisite libraries first. // void compile:: - append_lib_prefixes (scope& bs, prefix_map& m, target& t, lorder lo) const + append_lib_prefixes (const scope& bs, + prefix_map& m, + target& t, + lorder lo) const { auto opt = [&m, this] (file& l, const string& t, bool com, bool exp) { @@ -199,8 +205,8 @@ namespace build2 file& t (static_cast (xt)); const match_data& md (t.data ()); - scope& bs (t.base_scope ()); - scope& rs (*bs.root_scope ()); + const scope& bs (t.base_scope ()); + const scope& rs (*bs.root_scope ()); otype ct (compile_type (t)); // Derive file name from target name. @@ -405,7 +411,7 @@ namespace build2 // Reverse-lookup target type from extension. // const target_type* compile:: - map_extension (scope& s, const string& n, const string& e) const + map_extension (const scope& s, const string& n, const string& e) const { // We will just have to try all of the possible ones, in the "most // likely to match" order. @@ -442,7 +448,7 @@ namespace build2 // "imported as installed" library), then it can't possibly // generate any headers for us. // - scope* rs (t.base_scope ().root_scope ()); + const scope* rs (t.base_scope ().root_scope ()); if (rs == nullptr) return; @@ -526,7 +532,9 @@ namespace build2 } auto compile:: - build_prefix_map (scope& bs, target& t, lorder lo) const -> prefix_map + build_prefix_map (const scope& bs, + target& t, + lorder lo) const -> prefix_map { prefix_map m; @@ -737,8 +745,8 @@ namespace build2 info << "while extracting header dependencies from " << src; })); - scope& bs (t.base_scope ()); - scope& rs (*bs.root_scope ()); + const scope& bs (t.base_scope ()); + const scope& rs (*bs.root_scope ()); // Initialize lazily, only if required. // @@ -937,8 +945,8 @@ namespace build2 // dir_path out; - scope& bs (scopes.find (d)); - if (scope* rs = bs.root_scope ()) + const scope& bs (scopes.find (d)); + if (const scope* rs = bs.root_scope ()) { tt = map_extension (bs, n, e); @@ -1403,8 +1411,8 @@ namespace build2 return p.second; } - scope& bs (t.base_scope ()); - scope& rs (*bs.root_scope ()); + const scope& bs (t.base_scope ()); + const scope& rs (*bs.root_scope ()); otype ct (compile_type (t)); lorder lo (link_order (bs, ct)); diff --git a/build2/cc/link b/build2/cc/link index 5f28204..d1b0e7a 100644 --- a/build2/cc/link +++ b/build2/cc/link @@ -71,13 +71,13 @@ namespace build2 // Library handling. // void - append_libraries (strings&, file&, bool, scope&, lorder) const; + append_libraries (strings&, file&, bool, const scope&, lorder) const; void - hash_libraries (sha256&, file&, bool, scope&, lorder) const; + hash_libraries (sha256&, file&, bool, const scope&, lorder) const; void - rpath_libraries (strings&, target&, scope&, lorder, bool) const; + rpath_libraries (strings&, target&, const scope&, lorder, bool) const; // Windows rpath emulation (windows-rpath.cxx). // @@ -93,13 +93,13 @@ namespace build2 using windows_dlls = std::set; timestamp - windows_rpath_timestamp (file&, scope&, lorder) const; + windows_rpath_timestamp (file&, const scope&, lorder) const; windows_dlls - windows_rpath_dlls (file&, scope&, lorder) const; + windows_rpath_dlls (file&, const scope&, lorder) const; void - windows_rpath_assembly (file&, scope&, lorder, + windows_rpath_assembly (file&, const scope&, lorder, const string&, timestamp, bool) const; diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx index 6de294a..d85faed 100644 --- a/build2/cc/link.cxx +++ b/build2/cc/link.cxx @@ -322,8 +322,8 @@ namespace build2 file& t (static_cast (xt)); - scope& bs (t.base_scope ()); - scope& rs (*bs.root_scope ()); + const scope& bs (t.base_scope ()); + const scope& rs (*bs.root_scope ()); otype lt (link_type (t)); lorder lo (link_order (bs, lt)); @@ -657,7 +657,7 @@ namespace build2 void link:: append_libraries (strings& args, file& l, bool la, - scope& bs, lorder lo) const + const scope& bs, lorder lo) const { // Note: lack of the "small function object" optimization will really // kill us here since we are called in a loop. @@ -704,7 +704,11 @@ namespace build2 } void link:: - hash_libraries (sha256& cs, file& l, bool la, scope& bs, lorder lo) const + hash_libraries (sha256& cs, + file& l, + bool la, + const scope& bs, + lorder lo) const { bool win (tclass == "windows"); @@ -747,7 +751,9 @@ namespace build2 void link:: rpath_libraries (strings& args, - target& t, scope& bs, lorder lo, + target& t, + const scope& bs, + lorder lo, bool for_install) const { // Use -rpath-link on targets that support it (Linux, *BSD). Note @@ -887,8 +893,8 @@ namespace build2 file& t (static_cast (xt)); - scope& bs (t.base_scope ()); - scope& rs (*bs.root_scope ()); + const scope& bs (t.base_scope ()); + const scope& rs (*bs.root_scope ()); otype lt (link_type (t)); lorder lo (link_order (bs, lt)); diff --git a/build2/cc/pkgconfig.cxx b/build2/cc/pkgconfig.cxx index 6c8159f..d32cd61 100644 --- a/build2/cc/pkgconfig.cxx +++ b/build2/cc/pkgconfig.cxx @@ -37,7 +37,7 @@ namespace build2 // search_library() POV. // bool common:: - pkgconfig_extract (scope& s, + pkgconfig_extract (const scope& s, lib& lt, liba* at, libs* st, diff --git a/build2/cc/utility b/build2/cc/utility index b481202..050b645 100644 --- a/build2/cc/utility +++ b/build2/cc/utility @@ -37,7 +37,7 @@ namespace build2 // same directory have to have the same link order. // lorder - link_order (scope& base, otype); + link_order (const scope& base, otype); // Given the link order return the library member (liba or libs) to link. // diff --git a/build2/cc/utility.cxx b/build2/cc/utility.cxx index f8a0afc..5c5d1fe 100644 --- a/build2/cc/utility.cxx +++ b/build2/cc/utility.cxx @@ -18,7 +18,7 @@ namespace build2 using namespace bin; lorder - link_order (scope& bs, otype ot) + link_order (const scope& bs, otype ot) { // Initialize to suppress 'may be used uninitialized' warning produced // by MinGW GCC 5.4.0. diff --git a/build2/cc/windows-manifest.cxx b/build2/cc/windows-manifest.cxx index 44d8f7b..b0b0feb 100644 --- a/build2/cc/windows-manifest.cxx +++ b/build2/cc/windows-manifest.cxx @@ -43,7 +43,7 @@ namespace build2 { tracer trace (x, "windows_manifest"); - scope& rs (t.root_scope ()); + const scope& rs (t.root_scope ()); const char* pa (windows_manifest_arch (cast (rs[x_target_cpu]))); diff --git a/build2/cc/windows-rpath.cxx b/build2/cc/windows-rpath.cxx index 35d83cc..00911d4 100644 --- a/build2/cc/windows-rpath.cxx +++ b/build2/cc/windows-rpath.cxx @@ -46,7 +46,7 @@ namespace build2 // adding to the assembly or timestamp_nonexistent if there aren't any. // timestamp link:: - windows_rpath_timestamp (file& t, scope& bs, lorder lo) const + windows_rpath_timestamp (file& t, const scope& bs, lorder lo) const { timestamp r (timestamp_nonexistent); @@ -116,7 +116,9 @@ namespace build2 // duplicates). // auto link:: - windows_rpath_dlls (file& t, scope& bs, lorder lo) const -> windows_dlls + windows_rpath_dlls (file& t, + const scope& bs, + lorder lo) const -> windows_dlls { windows_dlls r; @@ -204,7 +206,7 @@ namespace build2 // void link:: windows_rpath_assembly (file& t, - scope& bs, + const scope& bs, lorder lo, const string& tcpu, timestamp ts, @@ -276,7 +278,7 @@ namespace build2 << " processorArchitecture='" << pa << "'\n" << " version='0.0.0.0'/>\n"; - scope& as (*t.root_scope ().weak_scope ()); // Amalgamation scope. + const scope& as (*t.root_scope ().weak_scope ()); // Amalgamation. auto link = [&as, &ad] (const path& f, const path& l) { -- cgit v1.1