From 49fd34cb82d8edae683526a5d9fdd3c86136e646 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 30 May 2017 10:23:27 +0200 Subject: Rework C/C++ standard translation in preparation for experimental/modules Also fix bug in clang-apple versioning. --- build2/cc/common.hxx | 20 ++------------------ build2/cc/compile.cxx | 11 ++++------- build2/cc/gcc.cxx | 2 +- build2/cc/guess.cxx | 45 +++++++++++++++++++++++++-------------------- build2/cc/link.cxx | 2 +- build2/cc/module.cxx | 11 ++++++----- build2/cc/module.hxx | 11 ++++++----- 7 files changed, 45 insertions(+), 57 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common.hxx b/build2/cc/common.hxx index 55e6675..fa6ec5a 100644 --- a/build2/cc/common.hxx +++ b/build2/cc/common.hxx @@ -112,7 +112,7 @@ namespace build2 const string& tsys; // x.target.system const string& tclass; // x.target.class - const string& tstd; // Translated x_std value (can be empty). + const strings& tstd; // Translated x_std value (options). const process_path* pkgconfig; // pkgconfig.path (can be NULL). const dir_paths& sys_lib_dirs; // x.sys_lib_dirs @@ -153,7 +153,7 @@ namespace build2 uint64_t mj, uint64_t mi, const process_path& path, const target_triplet& tg, - const string& std, + const strings& std, const process_path* pkgc, const dir_paths& sld, const dir_paths& sid, @@ -177,22 +177,6 @@ namespace build2 public: common (data&& d): data (move (d)) {} - // Language standard (x.std) mapping. - // - void - append_std (cstrings& args) const - { - if (!tstd.empty ()) - args.push_back (tstd.c_str ()); - } - - void - hash_std (sha256& cs) const - { - if (!tstd.empty ()) - cs.append (tstd); - } - // Library handling. // public: diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index 5a95169..ce96e00 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -531,7 +531,7 @@ namespace build2 hash_options (cs, t, c_coptions); hash_options (cs, t, x_coptions); - hash_std (cs); + hash_options (cs, tstd); if (ct == otype::s) { @@ -1183,8 +1183,7 @@ namespace build2 // append_options (args, t, c_coptions); append_options (args, t, x_coptions); - - append_std (args); + append_options (args, tstd); if (cid == compiler_id::msvc) { @@ -2057,8 +2056,7 @@ namespace build2 // append_options (args, t, c_coptions); append_options (args, t, x_coptions); - - append_std (args); + append_options (args, tstd); if (cid == compiler_id::msvc) { @@ -2272,11 +2270,10 @@ namespace build2 append_options (args, t, c_coptions); append_options (args, t, x_coptions); + append_options (args, tstd); string out, out1; // Storage. - append_std (args); - if (cid == compiler_id::msvc) { // The /F*: option variants with separate names only became available diff --git a/build2/cc/gcc.cxx b/build2/cc/gcc.cxx index b5dd236..7f52a91 100644 --- a/build2/cc/gcc.cxx +++ b/build2/cc/gcc.cxx @@ -38,7 +38,7 @@ namespace build2 args.push_back (xc.recall_string ()); append_options (args, rs, c_coptions); append_options (args, rs, x_coptions); - if (!tstd.empty ()) args.push_back (tstd.c_str ()); + append_options (args, tstd); append_options (args, rs, c_loptions); append_options (args, rs, x_loptions); args.push_back ("-print-search-dirs"); diff --git a/build2/cc/guess.cxx b/build2/cc/guess.cxx index 9f14661..7dde013 100644 --- a/build2/cc/guess.cxx +++ b/build2/cc/guess.cxx @@ -1096,28 +1096,33 @@ namespace build2 compiler_info r; const compiler_id& id (gr.id); - if (id.type == "gcc") + switch (id.value ()) { - assert (id.variant.empty ()); - r = guess_gcc (xl, xc, c_coptions, x_coptions, move (gr)); - } - else if (id.type == "clang") - { - assert (id.variant.empty () || id.variant == "apple"); - r = guess_clang (xl, xc, c_coptions, x_coptions, move (gr)); - } - else if (id.type == "icc") - { - assert (id.variant.empty ()); - r = guess_icc (xl, xc, c_coptions, x_coptions, move (gr)); - } - else if (id.type == "msvc") - { - assert (id.variant.empty ()); - r = guess_msvc (xl, xc, c_coptions, x_coptions, move (gr)); + case compiler_id::gcc: + { + assert (id.variant.empty ()); + r = guess_gcc (xl, xc, c_coptions, x_coptions, move (gr)); + break; + } + case compiler_id::clang: + { + assert (id.variant.empty () || id.variant == "apple"); + r = guess_clang (xl, xc, c_coptions, x_coptions, move (gr)); + break; + } + case compiler_id::msvc: + { + assert (id.variant.empty ()); + r = guess_msvc (xl, xc, c_coptions, x_coptions, move (gr)); + break; + } + case compiler_id::icc: + { + assert (id.variant.empty ()); + r = guess_icc (xl, xc, c_coptions, x_coptions, move (gr)); + break; + } } - else - assert (false); // Derive binutils pattern unless this has already been done by the // compiler-specific code. diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx index 91c2739..5c75d34 100644 --- a/build2/cc/link.cxx +++ b/build2/cc/link.cxx @@ -1192,7 +1192,7 @@ namespace build2 { append_options (args, t, c_coptions); append_options (args, t, x_coptions); - append_std (args); + append_options (args, tstd); } append_options (args, t, c_loptions); diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx index 885d6c7..cdc45e5 100644 --- a/build2/cc/module.cxx +++ b/build2/cc/module.cxx @@ -118,10 +118,9 @@ namespace build2 } } - // Translate x_std value (if any) to the compiler option (if any). + // Translate x_std value (if any) to the compiler option(s) (if any). // - if (auto l = rs[x_std]) - tstd = translate_std (ci, rs, cast (*l)); + tstd = translate_std (ci, rs, cast_null (rs[x_std])); // Extract system library search paths from the compiler and determine // additional system include search paths. @@ -129,7 +128,7 @@ namespace build2 dir_paths lib_dirs; dir_paths inc_dirs; - if (ci.id.type == "msvc") + if (ci.id.value () == compiler_id::msvc) lib_dirs = msvc_library_search_paths (ci.path, rs); else { @@ -188,7 +187,9 @@ namespace build2 if (!tstd.empty ()) { - dr << " std " << tstd << '\n'; + dr << " std "; // One less space. + for (const string& o: tstd) dr << ' ' << o; + dr << '\n'; } if (!ci.cc_pattern.empty ()) // bin_pattern printed by bin diff --git a/build2/cc/module.hxx b/build2/cc/module.hxx index eaa82eb..db17998 100644 --- a/build2/cc/module.hxx +++ b/build2/cc/module.hxx @@ -32,13 +32,14 @@ namespace build2 void init (scope&, const location&, const variable_map&); - // Translate the x.std value to the standard-selecting option if there - // is any. + // Translate the x.std value (if any) to the standard-selecting + // option(s) (if any). May also check/set x.features.* variables on the + // root scope. // - virtual string - translate_std (const compiler_info&, scope&, const string&) const = 0; + virtual strings + translate_std (const compiler_info&, scope&, const string*) const = 0; - string tstd; + strings tstd; compiler_id::value_type cid; -- cgit v1.1