From 58bf658409d0b54c2ccb887652faa1e1098f2d16 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 30 Jan 2017 19:38:11 +0100 Subject: [PATCH] update according to ostd --- include/cubescript/cubescript.hh | 31 +++++++++++++++-------------- src/cs_vm.cc | 22 ++++++++++----------- src/cs_vm.hh | 2 +- src/cubescript.cc | 34 ++++++++++++++++---------------- tools/edit_fallback.hh | 5 +++-- tools/edit_linenoise.hh | 7 ++++--- tools/edit_readline.hh | 5 +++-- tools/repl.cc | 5 +++-- 8 files changed, 58 insertions(+), 53 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 324e71e2..7b97d962 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -4,6 +4,8 @@ #include #include +#include + #include "cubescript_conf.hh" #include @@ -14,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -419,10 +420,10 @@ struct OSTD_EXPORT CsState { return p_inloop; } - ostd::Maybe run_file_str(ostd::ConstCharRange fname); - ostd::Maybe run_file_int(ostd::ConstCharRange fname); - ostd::Maybe run_file_float(ostd::ConstCharRange fname); - ostd::Maybe run_file_bool(ostd::ConstCharRange fname); + std::optional run_file_str(ostd::ConstCharRange fname); + std::optional run_file_int(ostd::ConstCharRange fname); + std::optional run_file_float(ostd::ConstCharRange fname); + std::optional run_file_bool(ostd::ConstCharRange fname); bool run_file(ostd::ConstCharRange fname, CsValue &ret); bool run_file(ostd::ConstCharRange fname); @@ -445,17 +446,17 @@ struct OSTD_EXPORT CsState { void set_var_float_checked(CsFvar *fv, CsFloat v); void set_var_str_checked(CsSvar *fv, ostd::ConstCharRange v); - ostd::Maybe get_var_int(ostd::ConstCharRange name); - ostd::Maybe get_var_float(ostd::ConstCharRange name); - ostd::Maybe get_var_str(ostd::ConstCharRange name); + std::optional get_var_int(ostd::ConstCharRange name); + std::optional get_var_float(ostd::ConstCharRange name); + std::optional get_var_str(ostd::ConstCharRange name); - ostd::Maybe get_var_min_int(ostd::ConstCharRange name); - ostd::Maybe get_var_max_int(ostd::ConstCharRange name); + std::optional get_var_min_int(ostd::ConstCharRange name); + std::optional get_var_max_int(ostd::ConstCharRange name); - ostd::Maybe get_var_min_float(ostd::ConstCharRange name); - ostd::Maybe get_var_max_float(ostd::ConstCharRange name); + std::optional get_var_min_float(ostd::ConstCharRange name); + std::optional get_var_max_float(ostd::ConstCharRange name); - ostd::Maybe get_alias_val(ostd::ConstCharRange name); + std::optional get_alias_val(ostd::ConstCharRange name); virtual void print_var(CsVar *v); @@ -751,12 +752,12 @@ private: }; template - inline ostd::Ptrdiff format_int(R &&writer, CsInt val) { + inline std::ptrdiff_t format_int(R &&writer, CsInt val) { return ostd::format(std::forward(writer), IntFormat, val); } template - inline ostd::Ptrdiff format_float(R &&writer, CsFloat val) { + inline std::ptrdiff_t format_float(R &&writer, CsFloat val) { return ostd::format( std::forward(writer), (val == CsInt(val)) ? RoundFloatFormat : FloatFormat, val diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 6f730709..0067adb9 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -117,7 +117,7 @@ ostd::ConstCharRange CsErrorException::save_msg( if (gs) { /* we can attach line number */ ostd::CharRange r(cs.p_errbuf, sizeof(cs.p_errbuf)); - ostd::Ptrdiff sz = -1; + std::ptrdiff_t sz = -1; if (!gs->src_name.empty()) { sz = ostd::format(r, "%s:%d: %s", gs->src_name, gs->current_line, msg); } else { @@ -144,7 +144,7 @@ static void bcode_ref(uint32_t *code) { bcode_incr(&code[-1]); break; case CsCodeOffset: - code -= ostd::Ptrdiff(code[-1] >> 8); + code -= std::ptrdiff_t(code[-1] >> 8); bcode_incr(code); break; } @@ -163,7 +163,7 @@ static void bcode_unref(uint32_t *code) { bcode_decr(&code[-1]); break; case CsCodeOffset: - code -= ostd::Ptrdiff(code[-1] >> 8); + code -= std::ptrdiff_t(code[-1] >> 8); bcode_decr(code); break; } @@ -1830,34 +1830,34 @@ static bool cs_run_file( return true; } -ostd::Maybe CsState::run_file_str(ostd::ConstCharRange fname) { +std::optional CsState::run_file_str(ostd::ConstCharRange fname) { CsValue ret; if (!cs_run_file(*this, fname, ret)) { - return ostd::nothing; + return std::nullopt; } return ret.get_str(); } -ostd::Maybe CsState::run_file_int(ostd::ConstCharRange fname) { +std::optional CsState::run_file_int(ostd::ConstCharRange fname) { CsValue ret; if (!cs_run_file(*this, fname, ret)) { - return ostd::nothing; + return std::nullopt; } return ret.get_int(); } -ostd::Maybe CsState::run_file_float(ostd::ConstCharRange fname) { +std::optional CsState::run_file_float(ostd::ConstCharRange fname) { CsValue ret; if (!cs_run_file(*this, fname, ret)) { - return ostd::nothing; + return std::nullopt; } return ret.get_float(); } -ostd::Maybe CsState::run_file_bool(ostd::ConstCharRange fname) { +std::optional CsState::run_file_bool(ostd::ConstCharRange fname) { CsValue ret; if (!cs_run_file(*this, fname, ret)) { - return ostd::nothing; + return std::nullopt; } return ret.get_bool(); } diff --git a/src/cs_vm.hh b/src/cs_vm.hh index 854b5a24..d99b33ca 100644 --- a/src/cs_vm.hh +++ b/src/cs_vm.hh @@ -303,7 +303,7 @@ static inline void bcode_incr(uint32_t *bc) { static inline void bcode_decr(uint32_t *bc) { *bc -= 0x100; - if (ostd::Int32(*bc) < 0x100) { + if (std::int32_t(*bc) < 0x100) { delete[] bc; } } diff --git a/src/cubescript.cc b/src/cubescript.cc index 99391d08..e19006c7 100644 --- a/src/cubescript.cc +++ b/src/cubescript.cc @@ -764,70 +764,70 @@ void CsState::set_var_str( } } -ostd::Maybe CsState::get_var_int(ostd::ConstCharRange name) { +std::optional CsState::get_var_int(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_ivar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_value(); } -ostd::Maybe CsState::get_var_float(ostd::ConstCharRange name) { +std::optional CsState::get_var_float(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_fvar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_value(); } -ostd::Maybe CsState::get_var_str(ostd::ConstCharRange name) { +std::optional CsState::get_var_str(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_svar()) { - return ostd::nothing; + return std::nullopt; } return CsString(static_cast(id)->get_value()); } -ostd::Maybe CsState::get_var_min_int(ostd::ConstCharRange name) { +std::optional CsState::get_var_min_int(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_ivar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_val_min(); } -ostd::Maybe CsState::get_var_max_int(ostd::ConstCharRange name) { +std::optional CsState::get_var_max_int(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_ivar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_val_max(); } -ostd::Maybe CsState::get_var_min_float(ostd::ConstCharRange name) { +std::optional CsState::get_var_min_float(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_fvar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_val_min(); } -ostd::Maybe CsState::get_var_max_float(ostd::ConstCharRange name) { +std::optional CsState::get_var_max_float(ostd::ConstCharRange name) { CsIdent *id = get_ident(name); if (!id || id->is_fvar()) { - return ostd::nothing; + return std::nullopt; } return static_cast(id)->get_val_max(); } -ostd::Maybe +std::optional CsState::get_alias_val(ostd::ConstCharRange name) { CsAlias *a = get_alias(name); if (!a) { - return ostd::nothing; + return std::nullopt; } if ((a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)) { - return ostd::nothing; + return std::nullopt; } return a->get_value().get_str(); } diff --git a/tools/edit_fallback.hh b/tools/edit_fallback.hh index da9742fb..7b94e7ad 100644 --- a/tools/edit_fallback.hh +++ b/tools/edit_fallback.hh @@ -1,13 +1,14 @@ #ifndef CS_REPL_HAS_EDIT /* use nothing (no line editing support) */ +#include + #include -#include static void init_lineedit(CsState &, ostd::ConstCharRange) { } -static ostd::Maybe read_line(CsState &, CsSvar *pr) { +static std::optional read_line(CsState &, CsSvar *pr) { ostd::write(pr->get_value()); std::string ret; /* i really need to implement some sort of get_line for ostd streams */ diff --git a/tools/edit_linenoise.hh b/tools/edit_linenoise.hh index b9603b6b..6d2079e4 100644 --- a/tools/edit_linenoise.hh +++ b/tools/edit_linenoise.hh @@ -8,8 +8,9 @@ #include #include +#include + #include -#include #include "linenoise.hh" @@ -59,13 +60,13 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) { linenoiseSetFreeHintsCallback(ln_hint_free); } -static ostd::Maybe read_line(CsState &, CsSvar *pr) { +static std::optional read_line(CsState &, CsSvar *pr) { auto line = linenoise(pr->get_value().data()); if (!line) { /* linenoise traps ctrl-c, detect it and let the user exit */ if (errno == EAGAIN) { raise(SIGINT); - return ostd::nothing; + return std::nullopt; } return std::string{}; } diff --git a/tools/edit_readline.hh b/tools/edit_readline.hh index 4aa81459..b14b4c03 100644 --- a/tools/edit_readline.hh +++ b/tools/edit_readline.hh @@ -5,8 +5,9 @@ #include +#include + #include -#include #include #include @@ -68,7 +69,7 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) { rl_redisplay_function = ln_hint; } -static ostd::Maybe read_line(CsState &, CsSvar *pr) { +static std::optional read_line(CsState &, CsSvar *pr) { auto line = readline(pr->get_value().data()); if (!line) { return std::string(); diff --git a/tools/repl.cc b/tools/repl.cc index ed76f790..63ef0ce3 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -1,9 +1,10 @@ #include +#include + #include #include #include -#include #include @@ -110,7 +111,7 @@ static inline void fill_cmd_args(std::string &writer, ostd::ConstCharRange args) if (args.size() > 1) { writer += '{'; } - for (ostd::Size i = 0; i < args.size(); ++i) { + for (std::size_t i = 0; i < args.size(); ++i) { if (i) { writer += ", "; }