From: Alan T. DeKok Date: Mon, 26 Jun 2017 20:59:17 +0000 (-0400) Subject: remove "if_taken" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e586cc136b4dde4dc3faa6d9898160dac40ceab;p=thirdparty%2Ffreeradius-server.git remove "if_taken" which removes unlang_else and unlang_elsif(), and lets them re-use unlang_group and unlang_if instead. --- diff --git a/src/include/interpreter.h b/src/include/interpreter.h index fcd545d0dbc..c5437e4f070 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -262,7 +262,6 @@ typedef struct { unlang_type_t unwind; //!< Unwind to this one if it exists. ///< This is used for break and return. - bool if_taken : 1; //!< we took the previous "if", so skip the next "else" bool resume : 1; //!< resume the current section after calling a sub-section bool top_frame : 1; //!< are we the top frame of the stack? diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index cf3968dda62..2ce4b41aa16 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -136,7 +136,6 @@ static inline void unlang_push(unlang_stack_t *stack, unlang_t *program, rlm_rco frame->result = result; frame->priority = -1; frame->unwind = UNLANG_TYPE_NULL; - frame->if_taken = false; frame->resume = false; frame->state = NULL; } @@ -1022,7 +1021,6 @@ static unlang_action_t unlang_if(REQUEST *request, unlang_stack_t *stack, */ if (!condition) { RDEBUG2(" ..."); - frame->if_taken = false; if (*presult != RLM_MODULE_UNKNOWN) *priority = instruction->actions[*presult]; @@ -1030,59 +1028,22 @@ static unlang_action_t unlang_if(REQUEST *request, unlang_stack_t *stack, } /* - * We took the "if". Go recurse into its' children. - */ - frame->if_taken = true; - - return unlang_group(request, stack, presult, priority); -} - -static unlang_action_t unlang_elsif(REQUEST *request, unlang_stack_t *stack, - rlm_rcode_t *presult, int *priority) -{ - unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - unlang_t *instruction = frame->instruction; - - /* - * Like UNLANG_TYPE_ELSE, but allow for a later "else" - */ - if (frame->if_taken) { - RDEBUG2("... skipping %s for request %" PRIu64 ": Preceding \"if\" was taken", - unlang_ops[instruction->type].name, request->number); - frame->if_taken = true; - return UNLANG_ACTION_CONTINUE; - } - - /* - * Check the "if" condition. + * Tell the main interpreter to skip over the else / + * elsif blocks, as this "if" condition was taken. */ - return unlang_if(request, stack, presult, priority); -} - -static unlang_action_t unlang_else(REQUEST *request, unlang_stack_t *stack, - rlm_rcode_t *presult, int *priority) -{ - unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - unlang_t *instruction = frame->instruction; - - if (frame->if_taken) { - RDEBUG2("... skipping %s for request %" PRIu64 ": Preceding \"if\" was taken", - unlang_ops[instruction->type].name, request->number); - frame->if_taken = false; - - *presult = RLM_MODULE_NOOP; - *priority = instruction->actions[RLM_MODULE_NOOP]; - return UNLANG_ACTION_CONTINUE; + while (frame->next && + ((frame->next->type == UNLANG_TYPE_ELSE) || + (frame->next->type == UNLANG_TYPE_ELSIF))) { + frame->next = frame->next->next; } /* - * We need to process it. Go do that. + * We took the "if". Go recurse into its' children. */ - frame->if_taken = false; - return unlang_group(request, stack, presult, priority); } + static unlang_action_t unlang_module_resumption(REQUEST *request, unlang_stack_t *stack, rlm_rcode_t *presult, int *priority) { @@ -1181,12 +1142,12 @@ unlang_op_t unlang_ops[] = { }, [UNLANG_TYPE_ELSE] = { .name = "else", - .func = unlang_else, + .func = unlang_group, .debug_braces = true }, [UNLANG_TYPE_ELSIF] = { .name = "elsif", - .func = unlang_elsif, + .func = unlang_if, .debug_braces = true }, [UNLANG_TYPE_UPDATE] = { @@ -1294,6 +1255,7 @@ start_subsection: */ while (frame->instruction != NULL) { resume_subsection: + frame->next = frame->instruction->next; instruction = frame->instruction; DUMP_STACK; @@ -1463,7 +1425,6 @@ resume_subsection: } /* switch over return code from the interpreter function */ frame->instruction = frame->next; - if (frame->instruction) frame->next = frame->instruction->next; } RDEBUG4("** [%i] %s - done current subsection with (%s %d)",