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 ++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) (limited to 'build/cxx/compile.cxx') 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. -- cgit v1.1