From 41d3540e97b87fabc58af6226e6b7784767bc047 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Dec 2015 19:15:58 +0200 Subject: Fix reverse lookup of extension to target type in C++ dep extraction --- build/cxx/compile.cxx | 59 ++++++++++++++++++++++----------------------------- build/cxx/module.cxx | 7 ------ build/scope | 14 ++++++++++++ 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/build/cxx/compile.cxx b/build/cxx/compile.cxx index d986cac..72f8562 100644 --- a/build/cxx/compile.cxx +++ b/build/cxx/compile.cxx @@ -156,35 +156,34 @@ namespace build } } - // The strings used as the map key should be from the extension_pool. - // This way we can just compare pointers. + // Reverse-lookup target type from extension. // - using ext_map = map; - - static ext_map - build_ext_map (scope& r) + static const target_type* + map_extension (scope& s, const string& n, const string& e) { - ext_map m; - - if (auto l = r["h.ext"]) - m[&extension_pool.find (as (*l))] = &h::static_type; - - if (auto l = r["c.ext"]) - m[&extension_pool.find (as (*l))] = &c::static_type; - - if (auto l = r["hxx.ext"]) - m[&extension_pool.find (as (*l))] = &hxx::static_type; + // We will just have to try all of the possible ones, in the + // "most likely to match" order. + // + const variable& var (var_pool.find ("extension")); - if (auto l = r["ixx.ext"]) - m[&extension_pool.find (as (*l))] = &ixx::static_type; + auto test = [&s, &n, &e, &var] (const target_type& tt) + -> const target_type* + { + if (auto l = s.lookup (tt, n, var)) + if (as (*l) == e) + return &tt; - if (auto l = r["txx.ext"]) - m[&extension_pool.find (as (*l))] = &txx::static_type; + return nullptr; + }; - if (auto l = r["cxx.ext"]) - m[&extension_pool.find (as (*l))] = &cxx::static_type; + if (auto r = test (hxx::static_type)) return r; + if (auto r = test (h::static_type)) return r; + if (auto r = test (ixx::static_type)) return r; + if (auto r = test (txx::static_type)) return r; + if (auto r = test (cxx::static_type)) return r; + if (auto r = test (c::static_type)) return r; - return m; + return nullptr; } // Mapping of include prefixes (e.g., foo in ) for auto- @@ -611,17 +610,9 @@ namespace build // accurately determine target types for headers that // could be auto-generated. // - if (scope* r = scopes.find (d).root_scope ()) - { - // Get cached (or build) a map of the extensions for the - // C/C++ files this project is using. - // - const ext_map& m (build_ext_map (*r)); - - auto i (m.find (e)); - if (i != m.end ()) - tt = i->second; - } + scope& b (scopes.find (d)); + if (b.root_scope () != nullptr) + tt = map_extension (b, n, *e); // If it is outside any project, or the project doesn't have // such an extension, assume it is a plain old C header. diff --git a/build/cxx/module.cxx b/build/cxx/module.cxx index c704ab0..c979328 100644 --- a/build/cxx/module.cxx +++ b/build/cxx/module.cxx @@ -78,13 +78,6 @@ namespace build v.find ("cxx.export.libs", strings_type); v.find ("cxx.std", string_type); - - v.find ("h.ext", string_type); - v.find ("c.ext", string_type); - v.find ("hxx.ext", string_type); - v.find ("ixx.ext", string_type); - v.find ("txx.ext", string_type); - v.find ("cxx.ext", string_type); } // Register target types. diff --git a/build/scope b/build/scope index e52f615..551ce9d 100644 --- a/build/scope +++ b/build/scope @@ -102,6 +102,20 @@ namespace build } build::lookup + lookup (const target_type& tt, + const string& name, + const variable& var) const + { + return lookup (&tt, &name, var); + } + + build::lookup + lookup (const target_type& tt, const string& name, const string& var) const + { + return lookup (tt, name, var_pool.find (var)); + } + + build::lookup lookup (const target_type*, const string* name, const variable&) const; // Return a value suitable for assignment (or append if you only -- cgit v1.1