aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-07-23 10:49:37 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-07-23 10:49:37 +0200
commit7292c24ba3e4c0016e40466239437fe5819c47de (patch)
treefa066913ee9d5a8aea7d26bfd02ffa691dd4e1a4 /libbuild2/parser.cxx
parent4c628d939413bb722a6819d8e3798d79051619ce (diff)
Reserve variable names/components that start with underscore to build2 core
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r--libbuild2/parser.cxx30
1 files changed, 28 insertions, 2 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index d0661a9..a6f6ae6 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -4216,8 +4216,34 @@ namespace build2
// Note that the overridability can still be restricted (e.g., by a module
// that enters this variable or by a pattern).
//
- return scope_->var_pool ().insert (
- move (ns[0].value), true /* overridable */);
+ bool ovr (true);
+ auto r (scope_->var_pool ().insert (
+ move (ns[0].value), nullptr, nullptr, &ovr));
+
+ if (!r.second)
+ return r.first;
+
+ // If it's newly entered, verify it's not reserved for the build2 core.
+ // We reserve:
+ //
+ // - Variable components that start with underscore (_x, x._y).
+ //
+ // - Variables in the `build`, `import`, and `export` namespaces.
+ //
+ const string& n (r.first.name);
+
+ const char* w (
+ n[0] == '_' ? "name starts with underscore" :
+ n.find ("._") != string::npos ? "component starts with underscore" :
+ n.compare (0, 6, "build.") == 0 ? "is in 'build' namespace" :
+ n.compare (0, 7, "import.") == 0 ? "is in 'import' namespace" :
+ n.compare (0, 7, "export.") == 0 ? "is in 'export' namespace" : nullptr);
+
+ if (w != nullptr)
+ fail (l) << "variable name '" << n << "' is reserved" <<
+ info << "variable " << w;
+
+ return r.first;
}
void parser::