From 94f4153da9dd2ad0c166568f273e9ba2f4928554 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 8 Oct 2018 09:01:59 -0400 Subject: Re-arrange depfile parser token processing logic Re-arrange the existing logic to support later addition of post-token code even for empty tokens. --- src/depfile_parser.cc | 21 ++++++++++----------- src/depfile_parser.in.cc | 21 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc index 24e374f..2ad2a00 100644 --- a/src/depfile_parser.cc +++ b/src/depfile_parser.cc @@ -175,22 +175,21 @@ yy15: } int len = (int)(out - filename); - const bool is_target = parsing_targets; + const bool is_dependency = !parsing_targets; if (len > 0 && filename[len - 1] == ':') { len--; // Strip off trailing colon, if any. parsing_targets = false; } - if (len == 0) - continue; - - if (!is_target) { - ins_.push_back(StringPiece(filename, len)); - } else if (!out_.str_) { - out_ = StringPiece(filename, len); - } else if (out_ != StringPiece(filename, len)) { - *err = "depfile has multiple output paths"; - return false; + if (len > 0) { + if (is_dependency) { + ins_.push_back(StringPiece(filename, len)); + } else if (!out_.str_) { + out_ = StringPiece(filename, len); + } else if (out_ != StringPiece(filename, len)) { + *err = "depfile has multiple output paths"; + return false; + } } } if (parsing_targets) { diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc index 464efda..4df8ce2 100644 --- a/src/depfile_parser.in.cc +++ b/src/depfile_parser.in.cc @@ -94,22 +94,21 @@ bool DepfileParser::Parse(string* content, string* err) { } int len = (int)(out - filename); - const bool is_target = parsing_targets; + const bool is_dependency = !parsing_targets; if (len > 0 && filename[len - 1] == ':') { len--; // Strip off trailing colon, if any. parsing_targets = false; } - if (len == 0) - continue; - - if (!is_target) { - ins_.push_back(StringPiece(filename, len)); - } else if (!out_.str_) { - out_ = StringPiece(filename, len); - } else if (out_ != StringPiece(filename, len)) { - *err = "depfile has multiple output paths"; - return false; + if (len > 0) { + if (is_dependency) { + ins_.push_back(StringPiece(filename, len)); + } else if (!out_.str_) { + out_ = StringPiece(filename, len); + } else if (out_ != StringPiece(filename, len)) { + *err = "depfile has multiple output paths"; + return false; + } } } if (parsing_targets) { -- cgit v0.12