aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/b.cxx2
-rw-r--r--libbuild2/cc/parser.cxx4
-rw-r--r--libbuild2/config/init.cxx2
-rw-r--r--libbuild2/diagnostics.hxx16
-rw-r--r--libbuild2/dist/operation.cxx3
-rw-r--r--libbuild2/in/rule.cxx4
-rw-r--r--libbuild2/types.hxx50
-rw-r--r--libbuild2/types.ixx65
-rw-r--r--libbuild2/utility.cxx6
-rw-r--r--libbuild2/version/init.cxx6
-rw-r--r--libbuild2/version/utility.cxx4
11 files changed, 126 insertions, 36 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index 486b44c..b7e534e 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -741,7 +741,7 @@ main (int argc, char* argv[])
}
const path p ("<buildspec>");
- const location l (&p, 0, 0); //@@ TODO
+ const location l (p, 0, 0); //@@ TODO
meta_operation_id mid (0); // Not yet translated.
const meta_operation_info* mif (nullptr);
diff --git a/libbuild2/cc/parser.cxx b/libbuild2/cc/parser.cxx
index 706dc48..45120e2 100644
--- a/libbuild2/cc/parser.cxx
+++ b/libbuild2/cc/parser.cxx
@@ -197,7 +197,7 @@ namespace build2
// enter: module keyword
// leave: semi
- location l (get_location (t));
+ location_value l (get_location (t));
l_->next (t);
@@ -208,7 +208,7 @@ namespace build2
//
if (!ex && t.type == type::semi)
{
- module_marker_ = location_value (move (l));
+ module_marker_ = move (l);
return;
}
diff --git a/libbuild2/config/init.cxx b/libbuild2/config/init.cxx
index c9c6130..d48e0a8 100644
--- a/libbuild2/config/init.cxx
+++ b/libbuild2/config/init.cxx
@@ -242,7 +242,7 @@ namespace build2
{
for (const path& f: cast<paths> (l))
{
- location l (&f);
+ location l (f);
const string& s (f.string ());
diff --git a/libbuild2/diagnostics.hxx b/libbuild2/diagnostics.hxx
index 4b3af4e..6a37561 100644
--- a/libbuild2/diagnostics.hxx
+++ b/libbuild2/diagnostics.hxx
@@ -300,7 +300,7 @@ namespace build2
location_prologue_base (const char* type,
const char* mod,
const char* name,
- const path_name& f,
+ const path_name_view& f,
stream_verbosity sverb)
: type_ (type), mod_ (mod), name_ (name),
loc_ (f),
@@ -312,7 +312,7 @@ namespace build2
path&& f,
stream_verbosity sverb)
: type_ (type), mod_ (mod), name_ (name),
- file_ (move (f)), loc_ (&file_),
+ file_ (move (f)), loc_ (file_),
sverb_ (sverb) {}
void
@@ -367,6 +367,18 @@ namespace build2
return location_prologue (epilogue_, type_, mod_, name_, f, sverb_ ());
}
+ location_prologue
+ operator() (const path_name_view& f) const
+ {
+ return location_prologue (epilogue_, type_, mod_, name_, f, sverb_ ());
+ }
+
+ location_prologue
+ operator() (const path_name_value& f) const
+ {
+ return location_prologue (epilogue_, type_, mod_, name_, f, sverb_ ());
+ }
+
// fail (relative (src)) << ...
//
location_prologue
diff --git a/libbuild2/dist/operation.cxx b/libbuild2/dist/operation.cxx
index eb7cce1..12ae464 100644
--- a/libbuild2/dist/operation.cxx
+++ b/libbuild2/dist/operation.cxx
@@ -144,7 +144,8 @@ namespace build2
// since the meta operation is dist and we know what we are doing.
//
values params;
- const location loc (path_name ("<dist>")); // Dummy location.
+ path_name pn ("<dist>");
+ const location loc (pn); // Dummy location.
const operations& ops (rs->root_extra->operations);
diff --git a/libbuild2/in/rule.cxx b/libbuild2/in/rule.cxx
index de7ad88..593fb6d 100644
--- a/libbuild2/in/rule.cxx
+++ b/libbuild2/in/rule.cxx
@@ -221,7 +221,7 @@ namespace build2
// can be overriden with custom substitution semantics.
//
optional<string> v (
- substitute (location (&ip, ln), a, t, n, strict));
+ substitute (location (ip, ln), a, t, n, strict));
assert (v); // Rule semantics change without version increment?
@@ -302,7 +302,7 @@ namespace build2
// Not tracking column for now (see also depdb above).
//
- const location l (&ip, ln);
+ const location l (ip, ln);
// Scan the line looking for substiutions in the $<name>$ form. In
// the strict mode treat $$ as an escape sequence.
diff --git a/libbuild2/types.hxx b/libbuild2/types.hxx
index 8566c50..b76bbb4 100644
--- a/libbuild2/types.hxx
+++ b/libbuild2/types.hxx
@@ -228,6 +228,7 @@ namespace build2
//
using butl::path;
using butl::path_name;
+ using butl::path_name_view;
using butl::path_name_value;
using butl::dir_path;
using butl::path_cast;
@@ -311,26 +312,37 @@ namespace build2
// Diagnostics location.
//
- // Note that location maintains a shallow reference to path. Zero lines or
- // columns are not printed.
+ // Note that location maintains a shallow reference to path/path_name. Zero
+ // lines or columns are not printed.
//
class location
{
public:
+ path_name_view file;
+ uint64_t line;
+ uint64_t column;
+
+ location (): line (0), column (0) {}
+
+ explicit
+ location (const path& f, uint64_t l = 0, uint64_t c = 0)
+ : file (&f, nullptr /* name */), line (l), column (c) {}
+
explicit
- location (const path* f = nullptr, uint64_t l = 0, uint64_t c = 0)
+ location (path&&, uint64_t = 0, uint64_t = 0) = delete;
+
+ explicit
+ location (const path_name_view& f, uint64_t l = 0, uint64_t c = 0)
: file (f), line (l), column (c) {}
explicit
- location (path_name f, uint64_t l = 0, uint64_t c = 0)
- : file (std::move (f)), line (l), column (c) {}
+ location (path_name_view&&, uint64_t = 0, uint64_t = 0) = delete;
bool
- empty () const {return file.empty ();}
+ empty () const {return file.null () || file.empty ();}
- path_name file;
- uint64_t line;
- uint64_t column;
+ protected:
+ location (uint64_t l, uint64_t c): line (l), column (c) {}
};
// Similar (and implicit-convertible) to the above but stores a copy of the
@@ -339,19 +351,17 @@ namespace build2
class location_value: public location
{
public:
- location_value () = default;
+ path_name_value file;
- explicit
- location_value (const location& l)
- : location (path_name (file_value, l.file.name), l.line, l.column),
- file_value (l.file.path != nullptr ? *l.file.path : path ()) {}
+ location_value ();
explicit
- location_value (location&& l)
- : location (path_name (file_value, move (l.file.name)), l.line, l.column),
- file_value (l.file.path != nullptr ? *l.file.path : path ()) {}
+ location_value (const location&);
- path file_value;
+ location_value (location_value&&);
+ location_value (const location_value&);
+ location_value& operator= (location_value&&);
+ location_value& operator= (const location_value&);
};
// See context.
@@ -375,7 +385,7 @@ namespace std
operator<< (ostream&, const ::butl::path&);
LIBBUILD2_SYMEXPORT ostream&
- operator<< (ostream&, const ::butl::path_name&);
+ operator<< (ostream&, const ::butl::path_name_view&);
// Print as recall[@effect].
//
@@ -387,4 +397,6 @@ namespace std
//
#include <libbuild2/name.hxx>
+#include <libbuild2/types.ixx>
+
#endif // LIBBUILD2_TYPES_HXX
diff --git a/libbuild2/types.ixx b/libbuild2/types.ixx
new file mode 100644
index 0000000..5b30cd4
--- /dev/null
+++ b/libbuild2/types.ixx
@@ -0,0 +1,65 @@
+// file : libbuild2/types.ixx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+namespace build2
+{
+ // Note that in the constructors we cannot pass the file data member to the
+ // base class constructor as it is not initialized yet (and so its base
+ // path/name pointers are not initialized). Thus, we initialize the path
+ // name view in the constructor body.
+ //
+ inline location_value::
+ location_value ()
+ {
+ location::file = file;
+ }
+
+ inline location_value::
+ location_value (const location& l)
+ : location (l.line, l.column), file (l.file)
+ {
+ location::file = file;
+ }
+
+ inline location_value::
+ location_value (location_value&& l)
+ : location (l.line, l.column),
+ file (std::move (l.file))
+ {
+ location::file = file;
+ }
+
+ inline location_value::
+ location_value (const location_value& l)
+ : location (l.line, l.column), file (l.file)
+ {
+ location::file = file;
+ }
+
+ inline location_value& location_value::
+ operator= (location_value&& l)
+ {
+ if (this != &l)
+ {
+ file = std::move (l.file);
+ line = l.line;
+ column = l.column;
+ }
+
+ return *this;
+ }
+
+ inline location_value& location_value::
+ operator= (const location_value& l)
+ {
+ if (this != &l)
+ {
+ file = l.file;
+ line = l.line;
+ column = l.column;
+ }
+
+ return *this;
+ }
+}
diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx
index 8e38213..20f0c22 100644
--- a/libbuild2/utility.cxx
+++ b/libbuild2/utility.cxx
@@ -46,11 +46,11 @@ namespace std
}
ostream&
- operator<< (ostream& os, const ::butl::path_name& pn)
+ operator<< (ostream& os, const ::butl::path_name_view& v)
{
- assert (!pn.empty ());
+ assert (!v.empty ());
- return pn.name ? (os << *pn.name) : (os << *pn.path);
+ return v.name != nullptr && *v.name ? (os << **v.name) : (os << *v.path);
}
ostream&
diff --git a/libbuild2/version/init.cxx b/libbuild2/version/init.cxx
index c9d5021..9a56756 100644
--- a/libbuild2/version/init.cxx
+++ b/libbuild2/version/init.cxx
@@ -74,8 +74,8 @@ namespace build2
if (nv.value != pn.string ())
{
path bf (rs.src_path () / rs.root_extra->bootstrap_file);
- location ml (&f, nv.value_line, nv.value_column);
- location bl (&bf);
+ location ml (f, nv.value_line, nv.value_column);
+ location bl (bf);
fail (ml) << "package name " << nv.value << " does not match "
<< "build system project name " << pn <<
@@ -164,7 +164,7 @@ namespace build2
}
catch (const manifest_parsing& e)
{
- location l (&f, e.line, e.column);
+ location l (f, e.line, e.column);
fail (l) << e.description;
}
catch (const io_error& e)
diff --git a/libbuild2/version/utility.cxx b/libbuild2/version/utility.cxx
index 0669da7..867aaa8 100644
--- a/libbuild2/version/utility.cxx
+++ b/libbuild2/version/utility.cxx
@@ -63,12 +63,12 @@ namespace build2
}
catch (const manifest_parsing& e)
{
- location l (&in, e.line, e.column);
+ location l (in, e.line, e.column);
fail (l) << e.description;
}
catch (const manifest_serialization& e)
{
- location l (&r.path);
+ location l (r.path);
fail (l) << e.description;
}
catch (const io_error& e)