fix build with libc++, and try using it in CI with clang

master
Daniel Kolesa 2021-04-12 19:53:24 +02:00
parent 5e9aefb52a
commit a5003678da
10 changed files with 39 additions and 38 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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();

View File

@ -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<std::size_t, std::string_view> 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)) {

View File

@ -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:

View File

@ -5,6 +5,7 @@
#include <unordered_map>
#include <string>
#include <vector>
#include "cs_bcode.hh"
#include "cs_ident.hh"

View File

@ -93,6 +93,13 @@ struct charbuf: valbuf<char> {
}
};
/* 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

View File

@ -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()};
}

View File

@ -202,7 +202,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
}
auto quote = p.get_quoted_item();
auto *qend = &quote[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) {

View File

@ -16,6 +16,7 @@
#include <optional>
#include <memory>
#include <iterator>
#include <string>
#include <cubescript/cubescript.hh>