#include "sieve-common.h"
#include "sieve-commands.h"
#include "sieve-validator.h"
#include "sieve-generator.h"
#include "sieve-binary.h"
#include "sieve-code.h"
#include "sieve-binary.h"
static bool tst_allof_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx,
struct sieve_jumplist *jumps, bool jump_true);
static bool tst_allof_validate_const
(struct sieve_validator *valdtr, struct sieve_command *tst,
int *const_current, int const_new);
const struct sieve_command_def tst_allof = {
"allof",
SCT_TEST,
0, 2, FALSE, FALSE,
NULL, NULL, NULL,
tst_allof_validate_const,
NULL,
tst_allof_generate
};
static bool tst_allof_validate_const
(struct sieve_validator *valdtr ATTR_UNUSED,
struct sieve_command *tst ATTR_UNUSED, int *const_current, int const_next)
{
if ( const_next == 0 ) {
*const_current = 0;
return FALSE;
}
if ( *const_current != -1 )
*const_current = const_next;
return TRUE;
}
static bool tst_allof_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx,
struct sieve_jumplist *jumps, bool jump_true)
{
struct sieve_binary_block *sblock = cgenv->sblock;
struct sieve_ast_node *test;
struct sieve_jumplist false_jumps;
if ( sieve_ast_test_count(ctx->ast_node) > 1 ) {
if ( jump_true ) {
sieve_jumplist_init_temp(&false_jumps, sblock);
}
test = sieve_ast_test_first(ctx->ast_node);
while ( test != NULL ) {
bool result;
if ( jump_true )
result = sieve_generate_test(cgenv, test, &false_jumps, FALSE);
else
result = sieve_generate_test(cgenv, test, jumps, FALSE);
if ( !result ) return FALSE;
test = sieve_ast_test_next(test);
}
if ( jump_true ) {
sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation);
sieve_jumplist_add(jumps, sieve_binary_emit_offset(sblock, 0));
sieve_jumplist_resolve(&false_jumps);
}
} else {
test = sieve_ast_test_first(ctx->ast_node);
sieve_generate_test(cgenv, test, jumps, jump_true);
}
return TRUE;
}