Coverage Report

Created: 2026-07-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/tst-truefalse.c
Line
Count
Source
1
/* Copyright (c) Pigeonhole authors, see top-level COPYING file */
2
3
#include "sieve-ast.h"
4
#include "sieve-validator.h"
5
#include "sieve-generator.h"
6
#include "sieve-binary.h"
7
8
#include "sieve-commands.h"
9
#include "sieve-code.h"
10
#include "sieve-interpreter.h"
11
12
/*
13
 * True/False test command
14
 */
15
16
static bool
17
tst_false_validate_const(struct sieve_validator *valdtr,
18
       struct sieve_command *tst, int *const_current,
19
       int const_next);
20
static bool
21
tst_false_generate(const struct sieve_codegen_env *cgenv,
22
       struct sieve_command *cmd, struct sieve_jumplist *jumps,
23
       bool jump_true);
24
25
const struct sieve_command_def tst_false = {
26
  .identifier = "false",
27
  .type = SCT_TEST,
28
  .positional_args = 0,
29
  .subtests = 0,
30
  .block_allowed = FALSE,
31
  .block_required = FALSE,
32
  .validate_const = tst_false_validate_const,
33
  .control_generate = tst_false_generate
34
};
35
36
static bool
37
tst_true_validate_const(struct sieve_validator *valdtr,
38
      struct sieve_command *tst, int *const_current,
39
      int const_next);
40
static bool
41
tst_true_generate(const struct sieve_codegen_env *cgenv,
42
      struct sieve_command *cmd, struct sieve_jumplist *jumps,
43
      bool jump_true);
44
45
const struct sieve_command_def tst_true = {
46
  .identifier = "true",
47
  .type = SCT_TEST,
48
  .positional_args = 0,
49
  .subtests = 0,
50
  .block_allowed = FALSE,
51
  .block_required = FALSE,
52
  .validate_const = tst_true_validate_const,
53
  .control_generate = tst_true_generate
54
};
55
56
/*
57
 * Code validation
58
 */
59
60
static bool
61
tst_false_validate_const(struct sieve_validator *valdtr ATTR_UNUSED,
62
       struct sieve_command *tst ATTR_UNUSED,
63
       int *const_current, int const_next ATTR_UNUSED)
64
0
{
65
0
  *const_current = 0;
66
0
  return TRUE;
67
0
}
68
69
static bool
70
tst_true_validate_const(struct sieve_validator *valdtr ATTR_UNUSED,
71
      struct sieve_command *tst ATTR_UNUSED,
72
      int *const_current, int const_next ATTR_UNUSED)
73
0
{
74
0
  *const_current = 1;
75
0
  return TRUE;
76
0
}
77
78
/*
79
 * Code generation
80
 */
81
82
static bool
83
tst_false_generate(const struct sieve_codegen_env *cgenv,
84
       struct sieve_command *cmd ATTR_UNUSED,
85
       struct sieve_jumplist *jumps, bool jump_true)
86
0
{
87
0
  if (!jump_true) {
88
0
    sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation);
89
0
    sieve_jumplist_add(
90
0
      jumps, sieve_binary_emit_offset(cgenv->sblock, 0));
91
0
  }
92
0
  return TRUE;
93
0
}
94
95
static bool
96
tst_true_generate(const struct sieve_codegen_env *cgenv,
97
      struct sieve_command *cmd ATTR_UNUSED,
98
      struct sieve_jumplist *jumps, bool jump_true)
99
0
{
100
0
  if (jump_true) {
101
0
    sieve_operation_emit(cgenv->sblock, NULL, &sieve_jmp_operation);
102
0
    sieve_jumplist_add(
103
0
      jumps, sieve_binary_emit_offset(cgenv->sblock, 0));
104
0
  }
105
0
  return TRUE;
106
0
}