aboutsummaryrefslogtreecommitdiff
path: root/build2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-02 17:28:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:37 +0200
commitda6280024e196efb9e55b753751a772e3a844a82 (patch)
treeb4dc0a1fd32204cd01c29fde2bcfafce000c6c19 /build2
parent7e97d8a41f9d7b0fb82742cdd871a18804267c72 (diff)
Add file path to replay_token
Diffstat (limited to 'build2')
-rw-r--r--build2/parser25
-rw-r--r--build2/token1
2 files changed, 21 insertions, 5 deletions
diff --git a/build2/parser b/build2/parser
index 4b84ae4..aaee359 100644
--- a/build2/parser
+++ b/build2/parser
@@ -347,7 +347,6 @@ namespace build2
// Note also that the peeked token is not part of the replay, until it
// is "got".
//
- //
void
replay_save ()
{
@@ -361,6 +360,9 @@ namespace build2
assert ((replay_ == replay::save && !replay_data_.empty ()) ||
(replay_ == replay::play && replay_i_ == replay_data_.size ()));
+ if (replay_ == replay::save)
+ replay_path_ = path_; // Save old path.
+
replay_i_ = 0;
replay_ = replay::play;
}
@@ -368,6 +370,9 @@ namespace build2
void
replay_stop ()
{
+ if (replay_ == replay::play)
+ path_ = replay_path_; // Restore old path.
+
replay_data_.clear ();
replay_ = replay::stop;
}
@@ -406,9 +411,8 @@ namespace build2
assert (replay_ == replay::save);
replay_tokens r (move (replay_data_));
- replay_ = replay::stop;
replay_data_.clear ();
-
+ replay_ = replay::stop;
return r;
}
@@ -419,6 +423,8 @@ namespace build2
{
assert (replay_ == replay::stop);
+ replay_path_ = path_; // Save old path.
+
replay_data_ = move (d);
replay_i_ = 0;
replay_ = replay::play;
@@ -431,14 +437,22 @@ namespace build2
{
lexer_mode m (lexer_->mode ()); // Get it first since it may expire.
char ps (lexer_->pair_separator ());
- return replay_token {lexer_->next (), m, ps};
+ return replay_token {lexer_->next (), path_, m, ps};
}
const replay_token&
replay_next ()
{
assert (replay_i_ != replay_data_.size ());
- return replay_data_[replay_i_++];
+ const replay_token& rt (replay_data_[replay_i_++]);
+
+ // Update the path. Note that theoretically it is possible that peeking
+ // at the next token will "change" the path of the current token. The
+ // workaround would be to call get_location() before peeking.
+ //
+ path_ = rt.file;
+
+ return rt;
}
// Diagnostics.
@@ -468,6 +482,7 @@ namespace build2
enum class replay {stop, save, play} replay_ = replay::stop;
replay_tokens replay_data_;
size_t replay_i_; // Position of the next token during replay.
+ const path* replay_path_; // Path before replay began (to be restored).
};
}
diff --git a/build2/token b/build2/token
index 19e82dc..7432d52 100644
--- a/build2/token
+++ b/build2/token
@@ -113,6 +113,7 @@ namespace build2
struct replay_token
{
build2::token token;
+ const path* file;
lexer_mode_base mode;
char pair_separator;
};