aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/scope.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-08-26 07:34:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-08-26 07:34:15 +0200
commit8e0e8edb727a5367d991880b033eb13060f4c8eb (patch)
tree75916dbef9b7a0dc6ef0fa939b9f748fc353d5cc /libbuild2/scope.cxx
parent113c43a42d20073428d46c04a1aa1cb305ea12d7 (diff)
Make target types project-wide
Diffstat (limited to 'libbuild2/scope.cxx')
-rw-r--r--libbuild2/scope.cxx39
1 files changed, 13 insertions, 26 deletions
diff --git a/libbuild2/scope.cxx b/libbuild2/scope.cxx
index 6e00511..8d5e37a 100644
--- a/libbuild2/scope.cxx
+++ b/libbuild2/scope.cxx
@@ -589,48 +589,33 @@ namespace build2
}
const target_type* scope::
- find_target_type (const string& tt, const scope** rs) const
+ find_target_type (const string& tt) const
{
- // Search scopes outwards, stopping at the project root.
+ // Search the project's root scope then the global scope.
//
- for (const scope* s (this);
- s != nullptr;
- s = s->root () ? &s->global_scope () : s->parent_scope ())
+ if (const scope* rs = root_scope ())
{
- if (s->target_types.empty ())
- continue;
-
- if (const target_type* r = s->target_types.find (tt))
- {
- if (rs != nullptr)
- *rs = s;
-
+ if (const target_type* r = rs->root_extra->target_types.find (tt))
return r;
- }
}
- return nullptr;
+ return ctx.global_target_types.find (tt);
}
// Find target type from file name.
//
static const target_type*
- find_file_target_type (const scope* s, const string& n)
+ find_target_type_file (const scope& s, const string& n)
{
// Pretty much the same logic as in find_target_type() above.
//
- for (;
- s != nullptr;
- s = s->root () ? &s->global_scope () : s->parent_scope ())
+ if (const scope* rs = s.root_scope ())
{
- if (s->target_types.empty ())
- continue;
-
- if (const target_type* r = s->target_types.find_file (n))
+ if (const target_type* r = rs->root_extra->target_types.find_file (n))
return r;
}
- return nullptr;
+ return s.ctx.global_target_types.find_file (n);
}
pair<const target_type*, optional<string>> scope::
@@ -720,7 +705,7 @@ namespace build2
// We only consider files without extension for file name mapping.
//
if (!ext)
- tt = find_file_target_type (this, v);
+ tt = find_target_type_file (*this, v);
//@@ TODO: derive type from extension.
@@ -767,6 +752,8 @@ namespace build2
pair<reference_wrapper<const target_type>, bool> scope::
derive_target_type (const string& name, const target_type& base)
{
+ assert (root_scope () == this);
+
// Base target type uses extensions.
//
bool ext (base.fixed_extension != nullptr ||
@@ -818,7 +805,7 @@ namespace build2
? &target_print_0_ext_verb // Fixed extension, no use printing.
: nullptr; // Normal.
- return target_types.insert (name, move (dt));
+ return root_extra->target_types.insert (name, move (dt));
}
// scope_map