From 12b09073e316c6dcda8c6045640546fcf7cdb11c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 24 Jun 2019 12:20:48 +0200 Subject: [PATCH] macro processor: allow @#includepath to accept a colon-separated list of paths --- src/macro/Directives.cc | 9 ++++++++- src/macro/Directives.hh | 4 ++-- src/macro/Driver.cc | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/macro/Directives.cc b/src/macro/Directives.cc index daa781e8..fd320e5c 100644 --- a/src/macro/Directives.cc +++ b/src/macro/Directives.cc @@ -68,7 +68,14 @@ IncludePath::interpret(ostream &output, bool no_line_macro) StringPtr msp = dynamic_pointer_cast(expr->eval()); if (!msp) throw StackTrace("File name does not evaluate to a string"); - path = *msp; + size_t last = 0; + size_t next = 0; + while ((next = static_cast(*msp).find(":", last)) != string::npos) + { + path.push_back(static_cast(*msp).substr(last, next-last)); + last = next + 1; + } + path.push_back(static_cast(*msp).substr(last)); } catch (StackTrace &ex) { diff --git a/src/macro/Directives.hh b/src/macro/Directives.hh index 314f3362..38048a7a 100644 --- a/src/macro/Directives.hh +++ b/src/macro/Directives.hh @@ -83,12 +83,12 @@ namespace macro { private: const ExpressionPtr expr; - string path; + vector path; public: IncludePath(const ExpressionPtr expr_arg, Environment &env_arg, const Tokenizer::location location_arg) : Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro) override; - inline string getPath() const { return path; } + inline vector getPath() const { return path; } }; diff --git a/src/macro/Driver.cc b/src/macro/Driver.cc index d24469db..f700b473 100644 --- a/src/macro/Driver.cc +++ b/src/macro/Driver.cc @@ -85,7 +85,10 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi auto ipp = dynamic_pointer_cast(statement); if (ipp) - paths.emplace_back(ipp->getPath()); + { + auto p = ipp->getPath(); + paths.insert(paths.end(), p.begin(), p.end()); + } auto ip = dynamic_pointer_cast(statement); if (ip)