Loading parser.cpp +23 −1 Changes for parser.cpp: 23 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -173,7 +173,29 @@ bool Parser::parse_string(const std::string& content, Makefile& mf) { return true; } bool Parser::handle_conditional(const std::string& line, Makefile& mf) { bool Parser::handle_conditional(const std::string& line_in, Makefile& mf) { // Strip a trailing inline comment (respecting $()/${} nesting). Conditional // directives in real makefiles frequently carry comments, e.g. // "endif # sub_make_done" or "else # need-sub-make"; without stripping, // exact matches like (line == "endif") would fail and corrupt the // conditional stack for the remainder of the file. std::string line = line_in; { int depth = 0; for (size_t i = 0; i < line.size(); i++) { if (line[i] == '$' && i + 1 < line.size() && (line[i+1] == '(' || line[i+1] == '{')) { depth++; i++; } else if ((line[i] == ')' || line[i] == '}') && depth > 0) { depth--; } else if (line[i] == '#' && depth == 0 && (i == 0 || line[i-1] != '\\')) { line = trim(line.substr(0, i)); break; } } } if (line.substr(0, 5) == "ifeq " || line.substr(0, 5) == "ifeq\t" || line == "ifeq") { if (!cond_stack_.empty() && !cond_stack_.back().active) { Loading Loading
parser.cpp +23 −1 Changes for parser.cpp: 23 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -173,7 +173,29 @@ bool Parser::parse_string(const std::string& content, Makefile& mf) { return true; } bool Parser::handle_conditional(const std::string& line, Makefile& mf) { bool Parser::handle_conditional(const std::string& line_in, Makefile& mf) { // Strip a trailing inline comment (respecting $()/${} nesting). Conditional // directives in real makefiles frequently carry comments, e.g. // "endif # sub_make_done" or "else # need-sub-make"; without stripping, // exact matches like (line == "endif") would fail and corrupt the // conditional stack for the remainder of the file. std::string line = line_in; { int depth = 0; for (size_t i = 0; i < line.size(); i++) { if (line[i] == '$' && i + 1 < line.size() && (line[i+1] == '(' || line[i+1] == '{')) { depth++; i++; } else if ((line[i] == ')' || line[i] == '}') && depth > 0) { depth--; } else if (line[i] == '#' && depth == 0 && (i == 0 || line[i-1] != '\\')) { line = trim(line.substr(0, i)); break; } } } if (line.substr(0, 5) == "ifeq " || line.substr(0, 5) == "ifeq\t" || line == "ifeq") { if (!cond_stack_.empty() && !cond_stack_.back().active) { Loading