diff --git a/.ci/build-cs b/.ci/build-cs index e3f0136..b598e1a 100755 --- a/.ci/build-cs +++ b/.ci/build-cs @@ -11,6 +11,7 @@ current_triplet=`$CC -dumpmachine` if [ "$CC" = "clang" ]; then export CXX="clang++" + export CXXFLAGS="-stdlib=libc++" else export CXX="g++-10" fi diff --git a/include/cubescript/cubescript/error.hh b/include/cubescript/cubescript/error.hh index a234eb1..6a1f97c 100644 --- a/include/cubescript/cubescript/error.hh +++ b/include/cubescript/cubescript/error.hh @@ -51,7 +51,7 @@ struct LIBCUBESCRIPT_EXPORT error { {} std::string_view what() const { - return std::string_view{p_errbeg, p_errend}; + return std::string_view{p_errbeg, std::size_t(p_errend - p_errbeg)}; } stack_state &get_stack() { diff --git a/include/cubescript/cubescript/util.hh b/include/cubescript/cubescript/util.hh index def0e75..91ae275 100644 --- a/include/cubescript/cubescript/util.hh +++ b/include/cubescript/cubescript/util.hh @@ -43,7 +43,9 @@ struct LIBCUBESCRIPT_EXPORT list_parser { } std::string_view get_input() const { - return std::string_view{p_input_beg, p_input_end}; + return std::string_view{ + p_input_beg, std::size_t(p_input_end - p_input_beg) + }; } bool parse(); @@ -52,10 +54,10 @@ struct LIBCUBESCRIPT_EXPORT list_parser { string_ref get_item() const; std::string_view get_raw_item() const { - return std::string_view{p_ibeg, p_iend}; + return std::string_view{p_ibeg, std::size_t(p_iend - p_ibeg)}; } std::string_view get_quoted_item() const { - return std::string_view{p_qbeg, p_qend}; + return std::string_view{p_qbeg, std::size_t(p_qend - p_qbeg)}; } void skip_until_item(); diff --git a/src/cs_gen.cc b/src/cs_gen.cc index bdeb7f9..3977013 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -242,9 +242,7 @@ void gen_state::gen_val_block(std::string_view v) { break; case '\"': { /* quoted string */ char const *start = str; - str = parse_string( - *ts.pstate, std::string_view{str, send} - ); + str = parse_string(*ts.pstate, make_str_view(str, send)); std::memcpy(&buf[len], start, std::size_t(str - start)); len += (str - start); break; @@ -502,7 +500,7 @@ std::pair gen_state::gen_block( ps.send = v.data() + v.size(); ps.current_line = line; ps.parse_block(VAL_ANY, term); - v = std::string_view{ps.source, ps.send}; + v = make_str_view(ps.source, ps.send); ret_line = ps.current_line; } if (code.size() > (csz + 2)) { diff --git a/src/cs_parser.cc b/src/cs_parser.cc index f278325..9ecf43e 100644 --- a/src/cs_parser.cc +++ b/src/cs_parser.cc @@ -57,8 +57,7 @@ end: nlines = nl; if ((beg == end) || (*beg != '\"')) { throw error{ - cs, "unfinished string '%s'", - std::string_view{orig, std::size_t(beg - orig)} + cs, "unfinished string '%.*s'", int(beg - orig), orig }; } return ++beg; @@ -90,18 +89,14 @@ LIBCUBESCRIPT_EXPORT char const *parse_word( break; case '[': ++it; - it = parse_word(cs, std::string_view{ - it, std::size_t(end - it) - }); + it = parse_word(cs, make_str_view(it, end)); if ((it == end) || (*it != ']')) { throw error{cs, "missing \"]\""}; } break; case '(': ++it; - it = parse_word(cs, std::string_view{ - it, std::size_t(end - it) - }); + it = parse_word(cs, make_str_view(it, end)); if ((it == end) || (*it != ')')) { throw error{cs, "missing \")\""}; } @@ -127,7 +122,7 @@ static inline void p_set_end( if (!end) { return; } - *end = std::string_view{nbeg, nend}; + *end = make_str_view(nbeg, nend); } /* this function assumes the input is definitely a hex digit */ static inline integer_type p_hexd_to_int(char c) { @@ -313,11 +308,9 @@ bool is_valid_name(std::string_view s) { std::string_view parser_state::get_str() { size_t nl; char const *beg = source; - source = parse_string( - *ts.pstate, std::string_view{source, std::size_t(send - source)}, nl - ); + source = parse_string(*ts.pstate, make_str_view(source, send), nl); current_line += nl - 1; - auto ret = std::string_view{beg, std::size_t(source - beg)}; + auto ret = make_str_view(beg, source); return ret.substr(1, ret.size() - 2); } @@ -342,7 +335,7 @@ std::string_view parser_state::read_macro_name() { for (; isalnum(c) || (c == '_'); c = current()) { next_char(); } - return std::string_view{op, std::size_t(source - op)}; + return make_str_view(op, source); } /* advance the parser until we reach any of the given chars, then stop at it */ @@ -406,10 +399,8 @@ void parser_state::skip_comments() { std::string_view parser_state::get_word() { char const *beg = source; - source = parse_word( - *ts.pstate, std::string_view{source, std::size_t(send - source)} - ); - return std::string_view{beg, std::size_t(source - beg)}; + source = parse_word(*ts.pstate, make_str_view(source, send)); + return make_str_view(beg, source); } /* lookups that are invalid but not causing an error */ @@ -718,7 +709,7 @@ void parser_state::parse_blockarg(int ltype) { } /* generate a block string for everything until now */ if (start != end) { - gs.gen_val_block(std::string_view{start, end}); + gs.gen_val_block(make_str_view(start, end)); ++concs; } if (parse_subblock()) { @@ -751,7 +742,7 @@ void parser_state::parse_blockarg(int ltype) { case VAL_COND: { /* compile */ auto ret = gs.gen_block( - std::string_view{start, send}, curline, VAL_NULL, ']' + make_str_view(start, send), curline, VAL_NULL, ']' ); source = ret.second.data(); send = source + ret.second.size(); @@ -759,14 +750,14 @@ void parser_state::parse_blockarg(int ltype) { return; } case VAL_IDENT: - gs.gen_val_ident(std::string_view{start, source - 1}); + gs.gen_val_ident(make_str_view(start, source - 1)); return; default: - gs.gen_val_block(std::string_view{start, source - 1}); + gs.gen_val_block(make_str_view(start, source - 1)); goto done; } } - gs.gen_val_block(std::string_view{start, source - 1}); + gs.gen_val_block(make_str_view(start, source - 1)); /* concat the pieces */ gs.gen_concat(++concs, false, ltype); done: diff --git a/src/cs_state.hh b/src/cs_state.hh index 99457b3..128aadb 100644 --- a/src/cs_state.hh +++ b/src/cs_state.hh @@ -5,6 +5,7 @@ #include #include +#include #include "cs_bcode.hh" #include "cs_ident.hh" diff --git a/src/cs_std.hh b/src/cs_std.hh index 9ed1456..d7e7ae0 100644 --- a/src/cs_std.hh +++ b/src/cs_std.hh @@ -93,6 +93,13 @@ struct charbuf: valbuf { } }; +/* because the dual-iterator constructor is not supported everywhere + * and the pointer + size constructor is ugly as heck + */ +inline std::string_view make_str_view(char const *a, char const *b) { + return std::string_view{a, std::size_t(b - a)}; +} + } /* namespace cubescript */ #endif diff --git a/src/cs_val.cc b/src/cs_val.cc index b8767d7..899590f 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -392,19 +392,19 @@ LIBCUBESCRIPT_EXPORT string_ref concat_values( switch (vals[i].get_type()) { case value_type::INTEGER: case value_type::FLOAT: - case value_type::STRING: - std::ranges::copy( - any_value{vals[i]}.force_string(cs), - std::back_inserter(buf) - ); + case value_type::STRING: { + auto val = any_value{vals[i]}; + auto str = val.force_string(cs); + std::copy(str.begin(), str.end(), std::back_inserter(buf)); break; + } default: break; } if (i == (vals.size() - 1)) { break; } - std::ranges::copy(sep, std::back_inserter(buf)); + std::copy(sep.begin(), sep.end(), std::back_inserter(buf)); } return string_ref{cs, buf.str()}; } diff --git a/src/lib_list.cc b/src/lib_list.cc index 3c3d4d7..e9c1574 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -202,7 +202,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { } auto quote = p.get_quoted_item(); auto *qend = "e[quote.size()]; - res.set_string(std::string_view{list, qend}, cs); + res.set_string(make_str_view(list, qend), cs); }); new_cmd_quiet(gcs, "listfind", "rse", [](auto &cs, auto args, auto &res) { diff --git a/tools/repl.cc b/tools/repl.cc index 2a2daf3..3e017b2 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include