diff options
Diffstat (limited to 'libbuild2/cc/parser.cxx')
-rw-r--r-- | libbuild2/cc/parser.cxx | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/libbuild2/cc/parser.cxx b/libbuild2/cc/parser.cxx index 61d62b7..f62847e 100644 --- a/libbuild2/cc/parser.cxx +++ b/libbuild2/cc/parser.cxx @@ -15,9 +15,11 @@ namespace build2 using type = token_type; void parser:: - parse (ifdstream& is, const path_name& in, unit& u) + parse (ifdstream& is, const path_name& in, unit& u, const compiler_id& cid) { - lexer l (is, in); + cid_ = &cid; + + lexer l (is, in, true /* preprocessed */); l_ = &l; u_ = &u; @@ -82,6 +84,12 @@ namespace build2 // to call it __import) or it can have a special attribute (GCC // currently marks it with [[__translated]]). // + // Similarly, MSVC drops the `module;` marker and replaces all + // other `module` keywords with `__preprocessed_module`. + // + // Clang doesn't appear to rewrite anything, at least as of + // version 18. + // if (bb == 0 && t.first) { const string& id (t.value); // Note: tracks t. @@ -102,7 +110,9 @@ namespace build2 // Fall through. } - if (id == "module") + if (id == "module" || + (cid_->type == compiler_type::msvc && + id == "__preprocessed_module")) { location_value l (get_location (t)); l_->next (t); @@ -113,7 +123,9 @@ namespace build2 else n = false; } - else if (id == "import" /*|| id == "__import"*/) + else if (id == "import" /* || + (cid_->type == compiler_type::gcc && + id == "__import")*/) { l_->next (t); @@ -181,7 +193,7 @@ namespace build2 // pair<string, bool> np (parse_module_name (t, true /* partition */)); - // Should be {}-balanced. + // Skip attributes (should be {}-balanced). // for (; t.type != type::eos && t.type != type::semi && !t.first; @@ -195,7 +207,7 @@ namespace build2 if (!u_->module_info.name.empty ()) fail (l) << "multiple module declarations"; - u_->type =np.second + u_->type = np.second ? (ex ? unit_type::module_intf_part : unit_type::module_impl_part) : (ex ? unit_type::module_intf : unit_type::module_impl); u_->module_info.name = move (np.first); @@ -226,22 +238,28 @@ namespace build2 } case type::colon: { + // Add the module name to the partition so that code that doesn't + // need to distinguish between different kinds of imports doesn't + // have to. + // + // Note that if this itself is a partition, then we need to strip + // the partition part from the module name. + // switch (u_->type) { case unit_type::module_intf: case unit_type::module_impl: + un = u_->module_info.name; + break; case unit_type::module_intf_part: case unit_type::module_impl_part: + un.assign (u_->module_info.name, 0, u_->module_info.name.find (':')); break; default: fail (t) << "partition importation out of module purview"; } - // Add the module name to the partition so that code that doesn't - // need to distinguish beetween different kinds of imports doesn't - // have to. - // - un = u_->module_info.name + parse_module_part (t); + parse_module_part (t, un); ut = import_type::module_part; break; } @@ -256,7 +274,7 @@ namespace build2 return; } - // Should be {}-balanced. + // Skip attributes (should be {}-balanced). // for (; t.type != type::eos && t.type != type::semi && !t.first; |