aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-11-15 09:23:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-11-15 09:23:39 +0200
commit96c59ff30a2dbe2cc441024c81caaf79823441ac (patch)
tree3e6108d8bb34627ff1947e6455bded3ca4af2335
parent11f990b55294a9eb8d5d4f29fa9a277702ca72b9 (diff)
Fix bug in cc::parser location storage
-rw-r--r--libbuild2/cc/parser.cxx2
-rw-r--r--libbuild2/cc/parser.hxx2
-rw-r--r--libbuild2/diagnostics.hxx6
-rw-r--r--libbuild2/types.hxx27
4 files changed, 32 insertions, 5 deletions
diff --git a/libbuild2/cc/parser.cxx b/libbuild2/cc/parser.cxx
index abfe5bd..690f41c 100644
--- a/libbuild2/cc/parser.cxx
+++ b/libbuild2/cc/parser.cxx
@@ -187,7 +187,7 @@ namespace build2
//
if (!ex && t.type == type::semi)
{
- module_marker_ = move (l);
+ module_marker_ = location_value (move (l));
return;
}
diff --git a/libbuild2/cc/parser.hxx b/libbuild2/cc/parser.hxx
index cc2eaa3..f1188ff 100644
--- a/libbuild2/cc/parser.hxx
+++ b/libbuild2/cc/parser.hxx
@@ -47,7 +47,7 @@ namespace build2
lexer* l_;
unit* u_;
- optional<location> module_marker_;
+ optional<location_value> module_marker_;
};
}
}
diff --git a/libbuild2/diagnostics.hxx b/libbuild2/diagnostics.hxx
index 9008fc3..4b3af4e 100644
--- a/libbuild2/diagnostics.hxx
+++ b/libbuild2/diagnostics.hxx
@@ -356,6 +356,12 @@ namespace build2
}
location_prologue
+ operator() (const location_value& l) const
+ {
+ return location_prologue (epilogue_, type_, mod_, name_, l, sverb_ ());
+ }
+
+ location_prologue
operator() (const path_name& f) const
{
return location_prologue (epilogue_, type_, mod_, name_, f, sverb_ ());
diff --git a/libbuild2/types.hxx b/libbuild2/types.hxx
index bedcf1a..8566c50 100644
--- a/libbuild2/types.hxx
+++ b/libbuild2/types.hxx
@@ -311,12 +311,12 @@ namespace build2
// Diagnostics location.
//
+ // Note that location maintains a shallow reference to path. Zero lines or
+ // columns are not printed.
+ //
class location
{
public:
- // Note that location maintains a shallow reference to path. Zero lines
- // or columns are not printed.
- //
explicit
location (const path* f = nullptr, uint64_t l = 0, uint64_t c = 0)
: file (f), line (l), column (c) {}
@@ -333,6 +333,27 @@ namespace build2
uint64_t column;
};
+ // Similar (and implicit-convertible) to the above but stores a copy of the
+ // path.
+ //
+ class location_value: public location
+ {
+ public:
+ location_value () = default;
+
+ 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 ()) {}
+
+ 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 ()) {}
+
+ path file_value;
+ };
+
// See context.
//
enum class run_phase {load, match, execute};