remove useless parse catch

This commit is contained in:
zawz 2021-05-21 16:49:01 +02:00
parent 15ac04f505
commit 09186df7b1
3 changed files with 733 additions and 948 deletions

View file

@ -17,7 +17,7 @@ CC=g++
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++20
ifeq ($(DEBUG),true)
# debugging flags
CXXFLAGS += -g -D NO_PARSE_CATCH
CXXFLAGS += -g
else
# release flags
CXXFLAGS += -Ofast

View file

@ -223,7 +223,6 @@ int main(int argc, char* argv[])
}
}
}
#ifndef NO_PARSE_CATCH
catch(format_error& e)
{
if(tsh != nullptr)
@ -232,7 +231,6 @@ int main(int argc, char* argv[])
printFormatError(e);
return ERR_PARSE;
}
#endif
catch(ztd::option_error& e)
{
std::cerr << e.what() << std::endl;

View file

@ -254,11 +254,6 @@ std::pair<arithmetic*, parse_context> parse_arithmetic(parse_context ctx)
{
arithmetic* ret = nullptr;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
ctx.i = skip_chars(ctx, SEPARATORS);
if(ctx.i>ctx.size || ctx[ctx.i] == ')')
{
@ -353,14 +348,6 @@ std::pair<arithmetic*, parse_context> parse_arithmetic(parse_context ctx)
return std::make_pair(ret, ctx);
}
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -529,11 +516,6 @@ std::pair<arg*, parse_context> parse_arg(parse_context ctx, const char* end, con
// j : start of subarg , q = start of quote
uint32_t j=ctx.i,q=ctx.i;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
if(unexpected != NULL && is_in(ctx[ctx.i], unexpected))
{
parse_error( unexpected_token(ctx[ctx.i]) , ctx);
@ -604,15 +586,6 @@ std::pair<arg*, parse_context> parse_arg(parse_context ctx, const char* end, con
if(val != "")
ret->add(val);
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -733,11 +706,7 @@ std::pair<redirect*, parse_context> parse_redirect(parse_context ctx)
if(is_redirect)
{
redirect* ret=nullptr;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
ret = new redirect;
ret->op = std::string(ctx.data+start, ctx.i-start);
if(needs_arg)
@ -779,15 +748,6 @@ std::pair<redirect*, parse_context> parse_redirect(parse_context ctx)
ctx=pa.second;
}
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
if(ret!=nullptr)
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
else
@ -805,11 +765,6 @@ std::pair<arglist*, parse_context> parse_arglist(parse_context ctx, bool hard_er
{
arglist* ret = nullptr;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
if(word_eq("[[", ctx, ARG_END) ) // [[ bash specific parsing
{
if(!ctx.bash)
@ -907,16 +862,6 @@ std::pair<arglist*, parse_context> parse_arglist(parse_context ctx, bool hard_er
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
if(ret != nullptr)
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -928,11 +873,6 @@ std::pair<pipeline*, parse_context> parse_pipeline(parse_context ctx)
{
pipeline* ret = new pipeline;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
if(ctx[ctx.i] == '!' && ctx.i+1<ctx.size && is_in(ctx[ctx.i+1], SPACES))
{
ret->negated = true;
@ -954,14 +894,6 @@ std::pair<pipeline*, parse_context> parse_pipeline(parse_context ctx)
}
ctx.i++;
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -974,11 +906,6 @@ std::pair<condlist*, parse_context> parse_condlist(parse_context ctx)
condlist* ret = new condlist;
ctx.i = skip_unread(ctx);
#ifndef NO_PARSE_CATCH
try
{
#endif
;
bool optype=AND_OP;
while(ctx.i<ctx.size)
{
@ -1017,14 +944,6 @@ std::pair<condlist*, parse_context> parse_condlist(parse_context ctx)
return std::make_pair(ret, ctx);
}
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1034,12 +953,6 @@ std::tuple<list*, parse_context, std::string> parse_list_until(parse_context ctx
ctx.i=skip_unread(ctx);
std::string found_end_word;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
char& end_c = opts.end_char;
std::vector<std::string>& end_words = opts.end_words;
@ -1150,14 +1063,6 @@ std::tuple<list*, parse_context, std::string> parse_list_until(parse_context ctx
}
}
ctx.expecting=old_expect;
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_tuple(ret, ctx, found_end_word);
}
@ -1170,11 +1075,6 @@ std::pair<subshell*, parse_context> parse_subshell(parse_context ctx)
uint32_t start=ctx.i;
ctx.i = skip_unread(ctx);
#ifndef NO_PARSE_CATCH
try
{
#endif
;
auto pp=parse_list_until(ctx, {.end_char=')', .expecting=")"} );
ret->lst=std::get<0>(pp);
ctx=std::get<1>(pp);
@ -1183,14 +1083,7 @@ std::pair<subshell*, parse_context> parse_subshell(parse_context ctx)
parse_error("Subshell is empty", ctx, start-1);
}
ctx.i++;
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret,ctx);
}
@ -1204,11 +1097,6 @@ std::pair<brace*, parse_context> parse_brace(parse_context ctx)
uint32_t start=ctx.i;
ctx.i = skip_unread(ctx);
#ifndef NO_PARSE_CATCH
try
{
#endif
;
auto pp=parse_list_until(ctx, {.end_char='}', .expecting="}"});
ret->lst=std::get<0>(pp);
ctx=std::get<1>(pp);
@ -1218,14 +1106,6 @@ std::pair<brace*, parse_context> parse_brace(parse_context ctx)
return std::make_pair(ret, ctx+1);
}
ctx.i++;
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret,ctx);
}
@ -1237,11 +1117,6 @@ std::pair<function*, parse_context> parse_function(parse_context ctx, const char
{
function* ret = new function;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
ctx.i=skip_unread(ctx);
if(ctx[ctx.i] != '{')
{
@ -1261,14 +1136,6 @@ std::pair<function*, parse_context> parse_function(parse_context ctx, const char
ctx=std::get<1>(pp);
ctx.i++;
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1383,11 +1250,6 @@ std::pair<cmd*, parse_context> parse_cmd(parse_context ctx)
cmd* ret = new cmd;
uint32_t start=ctx.i;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
ctx = parse_cmd_varassigns(ret, ctx);
auto wp=get_word(ctx, ARG_END);
@ -1423,15 +1285,6 @@ std::pair<cmd*, parse_context> parse_cmd(parse_context ctx)
ctx.i++;
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1443,11 +1296,6 @@ std::pair<case_block*, parse_context> parse_case(parse_context ctx)
case_block* ret = new case_block;
ctx.i=skip_chars(ctx, SPACES);
#ifndef NO_PARSE_CATCH
try
{
#endif
;
// get the treated argument
auto pa = parse_arg(ctx);
ret->carg = pa.first;
@ -1527,14 +1375,6 @@ std::pair<case_block*, parse_context> parse_case(parse_context ctx)
return std::make_pair(ret, ctx);
}
ctx.i+=4;
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
if(ret != nullptr) delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1543,11 +1383,6 @@ std::pair<if_block*, parse_context> parse_if(parse_context ctx)
{
if_block* ret = new if_block;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
while(true)
{
std::string word;
@ -1596,15 +1431,6 @@ std::pair<if_block*, parse_context> parse_if(parse_context ctx)
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1613,11 +1439,6 @@ std::pair<for_block*, parse_context> parse_for(parse_context ctx)
for_block* ret = new for_block;
ctx.i = skip_chars(ctx, SPACES);
#ifndef NO_PARSE_CATCH
try
{
#endif
;
auto wp = get_word(ctx, ARG_END);
if(!valid_name(wp.first))
@ -1672,14 +1493,6 @@ std::pair<for_block*, parse_context> parse_for(parse_context ctx)
auto lp = parse_list_until(ctx, {.word_mode=true, .end_words={"done"}} );
ret->ops=std::get<0>(lp);
ctx=std::get<1>(lp);
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1688,11 +1501,6 @@ std::pair<while_block*, parse_context> parse_while(parse_context ctx)
{
while_block* ret = new while_block;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
// cond
parse_context oldctx = ctx;
auto pp=parse_list_until(ctx, {.word_mode=true, .end_words={"do"}});
@ -1716,14 +1524,6 @@ std::pair<while_block*, parse_context> parse_while(parse_context ctx)
parse_error("while is empty", oldctx);
ctx.has_errored=true;
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
delete ret;
throw e;
}
#endif
return std::make_pair(ret, ctx);
}
@ -1734,11 +1534,6 @@ std::pair<block*, parse_context> parse_block(parse_context ctx)
ctx.i = skip_chars(ctx, SEPARATORS);
block* ret = nullptr;
#ifndef NO_PARSE_CATCH
try
{
#endif
;
if(ctx.i>=ctx.size)
{
parse_error("Unexpected end of file", ctx);
@ -1865,14 +1660,6 @@ std::pair<block*, parse_context> parse_block(parse_context ctx)
}
ctx=pp.second;
}
#ifndef NO_PARSE_CATCH
}
catch(format_error& e)
{
if(ret != nullptr) delete ret;
throw e;
}
#endif
return std::make_pair(ret,ctx);
}