aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-12-03 19:15:58 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-12-03 19:15:58 +0200
commit41d3540e97b87fabc58af6226e6b7784767bc047 (patch)
tree9352aa6c90d37b4eb286d16287f934c4fecf0e27
parent0dfd165b5381286dc76f96637b9eb24b26a0b4b9 (diff)
Fix reverse lookup of extension to target type in C++ dep extraction
-rw-r--r--build/cxx/compile.cxx59
-rw-r--r--build/cxx/module.cxx7
-rw-r--r--build/scope14
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<const string*, const target_type*>;
-
- 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<string> (*l))] = &h::static_type;
-
- if (auto l = r["c.ext"])
- m[&extension_pool.find (as<string> (*l))] = &c::static_type;
-
- if (auto l = r["hxx.ext"])
- m[&extension_pool.find (as<string> (*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<string> (*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<string> (*l) == e)
+ return &tt;
- if (auto l = r["txx.ext"])
- m[&extension_pool.find (as<string> (*l))] = &txx::static_type;
+ return nullptr;
+ };
- if (auto l = r["cxx.ext"])
- m[&extension_pool.find (as<string> (*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 <foo/bar>) 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<const value>
+ lookup (const target_type& tt,
+ const string& name,
+ const variable& var) const
+ {
+ return lookup (&tt, &name, var);
+ }
+
+ build::lookup<const value>
+ lookup (const target_type& tt, const string& name, const string& var) const
+ {
+ return lookup (tt, name, var_pool.find (var));
+ }
+
+ build::lookup<const value>
lookup (const target_type*, const string* name, const variable&) const;
// Return a value suitable for assignment (or append if you only