GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 87.8% 968 / 0 / 1103
Functions: 100.0% 15 / 0 / 15
Branches: 69.9% 575 / 0 / 823

shumate/vector/shumate-vector-expression-filter.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2021 James Westman <james@jwestman.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
16 */
17
18
19 #include "shumate-vector-renderer.h"
20 #include "shumate-vector-expression-filter-private.h"
21 #include "shumate-vector-expression-interpolate-private.h"
22 #include "shumate-vector-expression-type-private.h"
23 #include "../shumate-vector-reader-iter.h"
24
25 typedef enum {
26 GEOM_POINT = 1 << 0,
27 GEOM_LINESTRING = 1 << 1,
28 GEOM_POLYGON = 1 << 2,
29 } GeometryTypeFlags;
30
31 struct _ShumateVectorExpressionFilter
32 {
33 ShumateVectorExpression parent_instance;
34
35 ExpressionType type;
36
37 GPtrArray *expressions;
38
39 union {
40 ShumateVectorValue value;
41 GPtrArray *format_parts;
42 char *fast_get_key;
43 GHashTable *match_expressions;
44 struct {
45 char *key;
46 GHashTable *haystack;
47 } fast_in;
48 struct {
49 ShumateVectorValue value;
50 char *key;
51 } fast_eq;
52 GeometryTypeFlags fast_geometry_type;
53 };
54 };
55
56 typedef struct {
57 ShumateVectorExpression *string;
58 ShumateVectorExpression *font_scale;
59 ShumateVectorExpression *text_color;
60 } FormatExpressionPart;
61
62
4/6
shumate_vector_expression_filter_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 8 times.
shumate_vector_expression_filter_get_type:
✓ Branch 2 → 3 taken 8 times.
✓ Branch 2 → 7 taken 2460 times.
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 7 not taken.
2484 G_DEFINE_TYPE (ShumateVectorExpressionFilter, shumate_vector_expression_filter, SHUMATE_TYPE_VECTOR_EXPRESSION)
63
64
65 static void
66 10 format_expression_part_free (FormatExpressionPart *part)
67 {
68
1/2
✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 4 not taken.
10 g_clear_object (&part->string);
69
2/2
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 6 times.
10 g_clear_object (&part->font_scale);
70
2/2
✓ Branch 6 → 7 taken 4 times.
✓ Branch 6 → 8 taken 6 times.
10 g_clear_object (&part->text_color);
71
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 10 times.
10 g_free (part);
72 10 }
73 G_DEFINE_AUTOPTR_CLEANUP_FUNC (FormatExpressionPart, format_expression_part_free);
74
75
76 const ExprInfo *shumate_vector_expression_type_lookup (register const char *str, register size_t len);
77
78
79 static ShumateVectorExpression *optimize (ShumateVectorExpressionFilter *self);
80
81
82 ShumateVectorExpression *
83 1180 shumate_vector_expression_filter_from_literal (ShumateVectorValue *value)
84 {
85 2360 g_autoptr(ShumateVectorExpressionFilter) self = NULL;
86
87 1180 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
88 1180 self->type = EXPR_LITERAL;
89 1180 shumate_vector_value_copy (value, &self->value);
90
91 1180 return (ShumateVectorExpression *)g_steal_pointer (&self);
92 }
93
94
95 ShumateVectorExpression *
96 1272 shumate_vector_expression_filter_from_array_or_literal (JsonNode *node,
97 ShumateVectorExpressionContext *ctx,
98 GError **error)
99 {
100
4/4
✓ Branch 2 → 3 taken 1260 times.
✓ Branch 2 → 5 taken 12 times.
✓ Branch 4 → 5 taken 26 times.
✓ Branch 4 → 7 taken 1234 times.
1272 if (node == NULL || JSON_NODE_HOLDS_NULL (node))
101 38 return shumate_vector_expression_filter_from_literal (&SHUMATE_VECTOR_VALUE_INIT);
102
2/2
✓ Branch 8 → 9 taken 806 times.
✓ Branch 8 → 14 taken 428 times.
1234 else if (JSON_NODE_HOLDS_VALUE (node))
103 {
104 806 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
105
1/2
✓ Branch 10 → 11 taken 806 times.
✗ Branch 10 → 12 not taken.
806 if (!shumate_vector_value_set_from_json_literal (&value, node, error))
106 return NULL;
107 806 return shumate_vector_expression_filter_from_literal (&value);
108 }
109
1/2
✓ Branch 15 → 16 taken 428 times.
✗ Branch 15 → 18 not taken.
428 else if (JSON_NODE_HOLDS_ARRAY (node))
110 428 return shumate_vector_expression_filter_from_json_array (json_node_get_array (node), ctx, error);
111 else
112 {
113 ✗ g_set_error (error,
114 SHUMATE_STYLE_ERROR,
115 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
116 "Expected a literal or array");
117 ✗ return NULL;
118 }
119 }
120
121 ShumateVectorExpression *
122 838 shumate_vector_expression_filter_from_json_array (JsonArray *array,
123 ShumateVectorExpressionContext *ctx,
124 GError **error)
125 {
126 1676 g_autoptr(ShumateVectorExpressionFilter) self = NULL;
127 838 JsonNode *op_node;
128 838 const char *op;
129 838 const ExprInfo *info;
130
131
2/2
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 6 taken 836 times.
838 if (json_array_get_length (array) == 0)
132 {
133 2 g_set_error (error,
134 SHUMATE_STYLE_ERROR,
135 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
136 "Expected first element of filter array to be a string");
137 2 return NULL;
138 }
139
140 836 op_node = json_array_get_element (array, 0);
141
4/4
✓ Branch 8 → 9 taken 834 times.
✓ Branch 8 → 11 taken 2 times.
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 13 taken 832 times.
836 if (!JSON_NODE_HOLDS_VALUE (op_node) || json_node_get_value_type (op_node) != G_TYPE_STRING)
142 {
143 4 g_set_error (error,
144 SHUMATE_STYLE_ERROR,
145 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
146 "Expected first element of filter array to be a string");
147 4 return NULL;
148 }
149
150 832 op = json_node_get_string (op_node);
151 832 info = shumate_vector_expression_type_lookup (op, strlen (op));
152
153
2/2
✓ Branch 15 → 16 taken 2 times.
✓ Branch 15 → 18 taken 830 times.
832 if (info == NULL)
154 {
155 2 g_set_error (error,
156 SHUMATE_STYLE_ERROR,
157 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
158 "Unrecognized operator %s", op);
159 2 return FALSE;
160 }
161
162 /* Expressions that don't use the child expressions array */
163
12/12
✓ Branch 18 → 19 taken 12 times.
✓ Branch 18 → 37 taken 2 times.
✓ Branch 18 → 60 taken 92 times.
✓ Branch 18 → 72 taken 4 times.
✓ Branch 18 → 73 taken 8 times.
✓ Branch 18 → 74 taken 6 times.
✓ Branch 18 → 127 taken 6 times.
✓ Branch 18 → 157 taken 6 times.
✓ Branch 18 → 178 taken 6 times.
✓ Branch 18 → 182 taken 4 times.
✓ Branch 18 → 186 taken 6 times.
✓ Branch 18 → 190 taken 678 times.
830 switch (info->type)
164 {
165 12 case EXPR_COLLATOR:
166 {
167 12 JsonNode *node;
168 12 JsonObject *object;
169 12 ShumateVectorExpression *child = NULL;
170
171
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 24 taken 12 times.
12 if (json_array_get_length (array) != 2)
172 {
173 ✗ g_set_error (error,
174 SHUMATE_STYLE_ERROR,
175 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
176 "Operator `collator` expected exactly 1 argument, got %d",
177 ✗ json_array_get_length (array) - 1);
178 ✗ return NULL;
179 }
180
181 12 node = json_array_get_element (array, 1);
182
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 29 taken 12 times.
12 if (!JSON_NODE_HOLDS_OBJECT (node))
183 {
184 ✗ g_set_error (error,
185 SHUMATE_STYLE_ERROR,
186 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
187 "Operator `collator` expected an object");
188 ✗ return NULL;
189 }
190
191 12 object = json_node_get_object (node);
192
193 12 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
194 12 self->type = EXPR_COLLATOR;
195 12 self->expressions = g_ptr_array_new_with_free_func (g_object_unref);
196
197
1/2
✓ Branch 35 → 36 taken 12 times.
✗ Branch 35 → 257 not taken.
12 if (!(child = shumate_vector_expression_filter_from_array_or_literal (json_object_get_member (object, "case-sensitive"), ctx, error)))
198 return NULL;
199 12 g_ptr_array_add (self->expressions, child);
200
201 12 return (ShumateVectorExpression *)g_steal_pointer (&self);
202 }
203
204 2 case EXPR_FORMAT:
205 {
206 2 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
207 2 self->type = EXPR_FORMAT;
208 2 self->format_parts = g_ptr_array_new_with_free_func ((GDestroyNotify)format_expression_part_free);
209
210
1/2
✓ Branch 59 → 42 taken 10 times.
✗ Branch 59 → 256 not taken.
12 for (int i = 1, n = json_array_get_length (array); i < n;)
211 {
212 10 JsonNode *arg_node = json_array_get_element (array, i);
213 10 JsonNode *format_node = NULL;
214 10 FormatExpressionPart *part = g_new0 (FormatExpressionPart, 1);
215
216 10 g_ptr_array_add (self->format_parts, part);
217
218 10 part->string = shumate_vector_expression_filter_from_array_or_literal (arg_node, ctx, error);
219
1/2
✓ Branch 46 → 47 taken 10 times.
✗ Branch 46 → 256 not taken.
10 if (part->string == NULL)
220 return NULL;
221
222 10 i ++;
223
2/2
✓ Branch 47 → 48 taken 8 times.
✓ Branch 47 → 256 taken 2 times.
10 if (i >= n)
224 break;
225
226 8 format_node = json_array_get_element (array, i);
227
2/2
✓ Branch 50 → 51 taken 4 times.
✓ Branch 50 → 59 taken 4 times.
8 if (JSON_NODE_HOLDS_OBJECT (format_node))
228 {
229 4 JsonObject *format_object = json_node_get_object (format_node);
230
231 4 i ++;
232
233
1/2
✓ Branch 54 → 55 taken 4 times.
✗ Branch 54 → 256 not taken.
4 if (!(part->text_color = shumate_vector_expression_filter_from_array_or_literal (json_object_get_member (format_object, "text-color"), ctx, error)))
234 return NULL;
235
236
1/2
✓ Branch 57 → 58 taken 4 times.
✗ Branch 57 → 256 not taken.
4 if (!(part->font_scale = shumate_vector_expression_filter_from_array_or_literal (json_object_get_member (format_object, "font-scale"), ctx, error)))
237 return NULL;
238 }
239 }
240
241 return (ShumateVectorExpression *)g_steal_pointer (&self);
242 }
243
244 92 case EXPR_TYPE_LITERAL:
245 {
246 92 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
247 92 JsonNode *arg;
248
249
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 66 taken 92 times.
92 if (json_array_get_length (array) != 2)
250 {
251 ✗ g_set_error (error,
252 SHUMATE_STYLE_ERROR,
253 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
254 "Operator `literal` expected exactly 1 argument, got %d",
255 ✗ json_array_get_length (array) - 1);
256 ✗ return NULL;
257 }
258
259 92 arg = json_array_get_element (array, 1);
260
261
1/2
✓ Branch 68 → 69 taken 92 times.
✗ Branch 68 → 70 not taken.
92 if (!shumate_vector_value_set_from_json_literal (&value, arg, error))
262 return NULL;
263
264 92 return shumate_vector_expression_filter_from_literal (&value);
265 }
266
267 4 case EXPR_INTERPOLATE:
268 4 return shumate_vector_expression_interpolate_from_json_array (array, ctx, error);
269
270 8 case EXPR_STEP:
271 8 return shumate_vector_expression_step_from_json_array (array, ctx, error);
272
273 6 case EXPR_MATCH:
274 {
275 6 ShumateVectorExpression *input_expr;
276
277 6 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
278 6 self->type = EXPR_MATCH;
279 6 self->expressions = g_ptr_array_new_with_free_func (g_object_unref);
280 6 self->match_expressions = g_hash_table_new_full (
281 (GHashFunc)shumate_vector_value_hash,
282 (GEqualFunc)shumate_vector_value_equal,
283 (GDestroyNotify)shumate_vector_value_free,
284 g_object_unref
285 );
286
287
1/2
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 83 taken 6 times.
6 if (json_array_get_length (array) < 3)
288 {
289 ✗ g_set_error (error,
290 SHUMATE_STYLE_ERROR,
291 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
292 "Operator `match` expected at least 2 arguments, got %d",
293 ✗ json_array_get_length (array) - 1);
294 ✗ return NULL;
295 }
296
297 6 input_expr = shumate_vector_expression_filter_from_array_or_literal (json_array_get_element (array, 1), ctx, error);
298
1/2
✓ Branch 85 → 86 taken 6 times.
✗ Branch 85 → 256 not taken.
6 if (input_expr == NULL)
299 return NULL;
300 6 g_ptr_array_add (self->expressions, input_expr);
301
302
2/2
✓ Branch 119 → 89 taken 10 times.
✓ Branch 119 → 120 taken 6 times.
16 for (int i = 2, n = json_array_get_length (array); i + 1 < n; i += 2)
303 {
304 10 JsonNode *label_node = json_array_get_element (array, i);
305 10 JsonNode *output_node = json_array_get_element (array, i + 1);
306
2/2
✓ Branch 256 → 257 taken 16 times.
✓ Branch 256 → 258 taken 2 times.
848 g_autoptr(ShumateVectorExpression) output_expr =
307 10 shumate_vector_expression_filter_from_array_or_literal (output_node, ctx, error);
308
309
1/2
✓ Branch 92 → 93 taken 10 times.
✗ Branch 92 → 117 not taken.
10 if (output_expr == NULL)
310 return NULL;
311
312
2/2
✓ Branch 94 → 95 taken 4 times.
✓ Branch 94 → 108 taken 6 times.
10 if (JSON_NODE_HOLDS_ARRAY (label_node))
313 {
314 4 JsonArray *labels = json_node_get_array (label_node);
315
2/2
✓ Branch 107 → 98 taken 10 times.
✓ Branch 107 → 115 taken 4 times.
14 for (int j = 0, m = json_array_get_length (labels); j < m; j ++)
316 {
317 10 JsonNode *label = json_array_get_element (labels, j);
318 20 g_autoptr(ShumateVectorValue) label_value = g_new0 (ShumateVectorValue, 1);
319
320
1/2
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 104 taken 10 times.
10 if (!shumate_vector_value_set_from_json_literal (label_value, label, error))
321 ✗ return NULL;
322
323 10 g_hash_table_insert (self->match_expressions, g_steal_pointer (&label_value), g_object_ref (output_expr));
324 }
325 }
326 else
327 {
328
0/2
✗ Branch 117 → 118 not taken.
✗ Branch 117 → 256 not taken.
12 g_autoptr(ShumateVectorValue) label_value = g_new0 (ShumateVectorValue, 1);
329
330
1/2
✗ Branch 110 → 111 not taken.
✓ Branch 110 → 113 taken 6 times.
6 if (!shumate_vector_value_set_from_json_literal (label_value, label_node, error))
331 ✗ return NULL;
332
333 6 g_hash_table_insert (self->match_expressions, g_steal_pointer (&label_value), g_object_ref (output_expr));
334 }
335 }
336
337
1/2
✓ Branch 121 → 122 taken 6 times.
✗ Branch 121 → 258 not taken.
6 if (json_array_get_length (array) % 2 == 1)
338 {
339 6 JsonNode *default_node = json_array_get_element (array, json_array_get_length (array) - 1);
340 12 ShumateVectorExpression *default_expr =
341 6 shumate_vector_expression_filter_from_array_or_literal (default_node, ctx, error);
342
343
1/2
✓ Branch 125 → 126 taken 6 times.
✗ Branch 125 → 256 not taken.
6 if (default_expr == NULL)
344
2/2
✓ Branch 256 → 257 taken 16 times.
✓ Branch 256 → 258 taken 2 times.
18 return NULL;
345
346 6 g_ptr_array_add (self->expressions, g_steal_pointer (&default_expr));
347 }
348
349 return (ShumateVectorExpression *)g_steal_pointer (&self);
350 }
351
352 6 case EXPR_LET:
353 {
354 6 g_auto(ShumateVectorExpressionContext) child_ctx = {0};
355 6 ShumateVectorExpression *child_expr = NULL;
356
357
1/2
✗ Branch 128 → 129 not taken.
✓ Branch 128 → 133 taken 6 times.
6 if (json_array_get_length (array) % 2 != 0)
358 {
359 ✗ g_set_error (error,
360 SHUMATE_STYLE_ERROR,
361 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
362 "Operator `let` expected an odd number of arguments, got %d",
363 ✗ json_array_get_length (array) - 1);
364 ✗ return NULL;
365 }
366
367 6 child_ctx.parent = ctx;
368 6 child_ctx.variables = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
369
370
2/2
✓ Branch 150 → 136 taken 8 times.
✓ Branch 150 → 151 taken 6 times.
14 for (int i = 1, n = json_array_get_length (array); i < n - 1; i += 2)
371 {
372 8 JsonNode *name_node;
373 8 ShumateVectorExpression *expr = NULL;
374
375 8 name_node = json_array_get_element (array, i);
376
2/4
✓ Branch 138 → 139 taken 8 times.
✗ Branch 138 → 141 not taken.
✗ Branch 140 → 141 not taken.
✓ Branch 140 → 144 taken 8 times.
8 if (!JSON_NODE_HOLDS_VALUE (name_node) || json_node_get_value_type (name_node) != G_TYPE_STRING)
377 {
378 ✗ g_set_error (error,
379 SHUMATE_STYLE_ERROR,
380 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
381 "Expected variable name to be a string (at index %d)",
382 i);
383 ✗ return NULL;
384 }
385
386 8 expr = shumate_vector_expression_filter_from_array_or_literal (
387 8 json_array_get_element (array, i + 1),
388 &child_ctx,
389 error
390 );
391
1/2
✓ Branch 146 → 147 taken 8 times.
✗ Branch 146 → 155 not taken.
8 if (expr == NULL)
392 return NULL;
393
394 8 g_hash_table_insert (child_ctx.variables,
395 8 (char *)json_node_get_string (name_node),
396 expr);
397 }
398
399 6 child_expr = shumate_vector_expression_filter_from_array_or_literal (
400 6 json_array_get_element (array, json_array_get_length (array) - 1),
401 &child_ctx,
402 error
403 );
404 6 return child_expr;
405 }
406
407 6 case EXPR_VAR:
408 {
409 6 JsonNode *arg_node;
410 6 const char *variable = NULL;
411
412
1/2
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 162 taken 6 times.
6 if (json_array_get_length (array) != 2)
413 {
414 ✗ g_set_error (error,
415 SHUMATE_STYLE_ERROR,
416 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
417 "Operator `var` expected exactly one argument, got %d",
418 ✗ json_array_get_length (array) - 1);
419 ✗ return NULL;
420 }
421
422 6 arg_node = json_array_get_element (array, 1);
423
2/4
✓ Branch 164 → 165 taken 6 times.
✗ Branch 164 → 167 not taken.
✗ Branch 166 → 167 not taken.
✓ Branch 166 → 169 taken 6 times.
6 if (!JSON_NODE_HOLDS_VALUE (arg_node) || json_node_get_value_type (arg_node) != G_TYPE_STRING)
424 {
425 ✗ g_set_error (error,
426 SHUMATE_STYLE_ERROR,
427 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
428 "Operator `var` expected a string literal");
429 ✗ return NULL;
430 }
431
432 6 variable = json_node_get_string (arg_node);
433
434
1/2
✓ Branch 175 → 171 taken 6 times.
✗ Branch 175 → 176 not taken.
12 for (ShumateVectorExpressionContext *c = ctx; c != NULL; c = c->parent)
435 {
436 6 ShumateVectorExpression *expr = g_hash_table_lookup (c->variables, variable);
437
1/2
✓ Branch 172 → 173 taken 6 times.
✗ Branch 172 → 174 not taken.
6 if (expr != NULL)
438 6 return g_object_ref (expr);
439 }
440
441 ✗ g_set_error (error,
442 SHUMATE_STYLE_ERROR,
443 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
444 "Variable `%s` not found",
445 variable);
446 ✗ return NULL;
447 }
448
449 6 case EXPR_E:
450 {
451 6 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
452 6 shumate_vector_value_set_number (&value, G_E);
453 6 return shumate_vector_expression_filter_from_literal (&value);
454 }
455
456 4 case EXPR_LN2:
457 {
458 4 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
459 4 shumate_vector_value_set_number (&value, G_LN2);
460 4 return shumate_vector_expression_filter_from_literal (&value);
461 }
462
463 6 case EXPR_PI:
464 {
465 6 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
466 6 shumate_vector_value_set_number (&value, G_PI);
467 6 return shumate_vector_expression_filter_from_literal (&value);
468 }
469
470 default:
471 678 break;
472 }
473
474 678 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
475 678 self->type = info->type;
476
477
4/4
✓ Branch 192 → 193 taken 178 times.
✓ Branch 192 → 199 taken 500 times.
✓ Branch 194 → 195 taken 6 times.
✓ Branch 194 → 199 taken 172 times.
678 if (info->expect_exprs_set && json_array_get_length (array) - 1 != info->expect_exprs)
478 {
479 18 g_set_error (error,
480 SHUMATE_STYLE_ERROR,
481 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
482 "Operator `%s` expected exactly %d arguments, got %d",
483 6 op, info->expect_exprs, json_array_get_length (array) - 1);
484 6 return FALSE;
485 }
486
487
4/4
✓ Branch 199 → 200 taken 434 times.
✓ Branch 199 → 206 taken 238 times.
✓ Branch 201 → 202 taken 4 times.
✓ Branch 201 → 206 taken 430 times.
672 if (info->expect_ge_exprs_set && json_array_get_length (array) - 1 < info->expect_ge_exprs)
488 {
489 12 g_set_error (error,
490 SHUMATE_STYLE_ERROR,
491 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
492 "Operator `%s` expected at least %d arguments, got %d",
493 4 op, info->expect_ge_exprs, json_array_get_length (array) - 1);
494 4 return FALSE;
495 }
496
497
4/4
✓ Branch 206 → 207 taken 374 times.
✓ Branch 206 → 213 taken 294 times.
✓ Branch 208 → 209 taken 4 times.
✓ Branch 208 → 213 taken 370 times.
668 if (info->expect_le_exprs_set && json_array_get_length (array) - 1 > info->expect_le_exprs)
498 {
499 12 g_set_error (error,
500 SHUMATE_STYLE_ERROR,
501 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
502 "Operator `%s` expected at most %d arguments, got %d",
503 4 op, info->expect_le_exprs, json_array_get_length (array) - 1);
504 4 return FALSE;
505 }
506
507
2/2
✓ Branch 253 → 214 taken 1174 times.
✓ Branch 253 → 254 taken 662 times.
1836 for (int i = 1; i < json_array_get_length (array); i ++)
508 {
509 1174 JsonNode *arg = json_array_get_element (array, i);
510 1172 g_autoptr(ShumateVectorExpression) expr = NULL;
511
512
2/2
✓ Branch 215 → 216 taken 644 times.
✓ Branch 215 → 245 taken 530 times.
1174 if (i == 1
513
2/2
✓ Branch 216 → 217 taken 332 times.
✓ Branch 216 → 245 taken 312 times.
644 && info->lookup_first_arg
514
2/2
✓ Branch 218 → 219 taken 108 times.
✓ Branch 218 → 245 taken 224 times.
332 && JSON_NODE_HOLDS_VALUE (arg)
515
2/2
✓ Branch 220 → 221 taken 16 times.
✓ Branch 220 → 245 taken 92 times.
108 && json_node_get_value_type (arg) == G_TYPE_STRING)
516 16 {
517 /* If the first argument of a function is a string,
518 * convert it to a GET expression so we can do things like
519 * ["==", "admin_level", 2] */
520 16 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
521 16 const char *string = json_node_get_string (arg);
522
523
2/2
✓ Branch 223 → 224 taken 2 times.
✓ Branch 223 → 227 taken 14 times.
16 if (g_strcmp0 ("zoom", string) == 0)
524 {
525 2 expr = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
526 2 ((ShumateVectorExpressionFilter *)expr)->type = EXPR_ZOOM;
527 }
528
2/2
✓ Branch 228 → 229 taken 6 times.
✓ Branch 228 → 232 taken 8 times.
14 else if (g_strcmp0 ("$type", string) == 0)
529 {
530 6 expr = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
531 6 ((ShumateVectorExpressionFilter *)expr)->type = EXPR_GEOMETRY_TYPE;
532 }
533 else
534 {
535 8 expr = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
536 8 ((ShumateVectorExpressionFilter *)expr)->type = EXPR_FAST_GET;
537
1/2
✗ Branch 234 → 235 not taken.
✓ Branch 234 → 236 taken 8 times.
16 ((ShumateVectorExpressionFilter *)expr)->fast_get_key = g_strdup (string);
538 }
539 }
540
2/2
✓ Branch 246 → 247 taken 1156 times.
✓ Branch 246 → 256 taken 2 times.
1158 else if (!(expr = shumate_vector_expression_filter_from_array_or_literal (arg, ctx, error)))
541 return NULL;
542
543
2/2
✓ Branch 247 → 248 taken 644 times.
✓ Branch 247 → 250 taken 528 times.
1172 if (self->expressions == NULL)
544 644 self->expressions = g_ptr_array_new_with_free_func (g_object_unref);
545 1172 g_ptr_array_add (self->expressions, g_steal_pointer (&expr));
546 }
547
548 662 return optimize (g_steal_pointer (&self));
549 }
550
551
552 ShumateVectorExpression *
553 20 shumate_vector_expression_filter_from_format (const char *format, GError **error)
554 {
555 40 g_autoptr(ShumateVectorExpressionFilter) self = NULL;
556
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 20 times.
20 g_auto(GStrv) parts = NULL;
557 20 int balance = 0;
558
559
3/4
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 18 times.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 8 taken 2 times.
20 if (strchr (format, '{') == NULL || strchr (format, '}') == NULL)
560 {
561 18 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
562 18 shumate_vector_value_set_string (&value, format);
563 18 return shumate_vector_expression_filter_from_literal (&value);
564 }
565
566 2 self = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
567 2 self->type = EXPR_CONCAT;
568 2 self->expressions = g_ptr_array_new_with_free_func (g_object_unref);
569
570 /* Ensure the braces in the format string are balanced and not nested */
571
2/2
✓ Branch 20 → 12 taken 36 times.
✓ Branch 20 → 21 taken 2 times.
38 for (int i = 0, n = strlen (format); i < n; i ++)
572 {
573
2/2
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 14 taken 34 times.
36 if (format[i] == '{')
574 2 balance ++;
575
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 16 taken 32 times.
34 else if (format[i] == '}')
576 2 balance --;
577
578
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 36 times.
36 if (balance != 0 && balance != 1)
579 {
580 ✗ g_set_error (error,
581 SHUMATE_STYLE_ERROR,
582 SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
583 "Format string `%s` is nested or unbalanced",
584 format);
585 ✗ return NULL;
586 }
587 }
588
589 2 parts = g_strsplit_set (format, "{}", 0);
590
591 2 for (int i = 0; TRUE;)
592 2 {
593 2 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
594 4 g_autoptr(ShumateVectorExpressionFilter) get_expr = NULL;
595
596
1/2
✓ Branch 22 → 23 taken 4 times.
✗ Branch 22 → 41 not taken.
4 if (parts[i] == NULL)
597 break;
598
599
1/2
✓ Branch 23 → 24 taken 4 times.
✗ Branch 23 → 27 not taken.
4 if (strlen (parts[i]) > 0)
600 {
601 4 shumate_vector_value_set_string (&value, parts[i]);
602 4 g_ptr_array_add (self->expressions, shumate_vector_expression_filter_from_literal (&value));
603 }
604 4 i ++;
605
606
2/2
✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 41 taken 2 times.
4 if (parts[i] == NULL)
607 break;
608
609 2 get_expr = g_object_new (SHUMATE_TYPE_VECTOR_EXPRESSION_FILTER, NULL);
610 2 get_expr->type = EXPR_FAST_GET;
611
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 2 times.
2 get_expr->fast_get_key = g_strdup (parts[i]);
612 2 g_ptr_array_add (self->expressions, g_steal_pointer (&get_expr));
613 2 i ++;
614 }
615
616
1/2
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 44 not taken.
2 return (ShumateVectorExpression *)g_steal_pointer (&self);
617 }
618
619 static GeometryTypeFlags
620 12 parse_geometry_type_flag (const char *flag)
621 {
622
2/2
✓ Branch 3 → 4 taken 10 times.
✓ Branch 3 → 9 taken 2 times.
12 if (g_strcmp0 (flag, "Point") == 0)
623 return GEOM_POINT;
624
2/2
✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 9 taken 4 times.
10 else if (g_strcmp0 (flag, "LineString") == 0)
625 return GEOM_LINESTRING;
626
2/2
✓ Branch 7 → 8 taken 4 times.
✓ Branch 7 → 9 taken 2 times.
6 else if (g_strcmp0 (flag, "Polygon") == 0)
627 return GEOM_POLYGON;
628 else
629 4 return 0;
630 }
631
632 static ShumateVectorExpression *
633 662 optimize (ShumateVectorExpressionFilter *self)
634 {
635
5/5
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 9 taken 266 times.
✓ Branch 2 → 37 taken 28 times.
✓ Branch 2 → 57 taken 14 times.
✓ Branch 2 → 116 taken 338 times.
662 switch (self->type)
636 {
637 16 case EXPR_ANY:
638 case EXPR_ALL:
639
3/4
✓ Branch 3 → 4 taken 12 times.
✓ Branch 3 → 5 taken 4 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 116 taken 12 times.
16 if (self->expressions == NULL || self->expressions->len == 0)
640 {
641
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 4 times.
4 g_clear_pointer (&self->expressions, g_ptr_array_unref);
642 4 shumate_vector_value_set_boolean (&self->value, self->type == EXPR_ALL);
643 4 self->type = EXPR_LITERAL;
644 }
645 break;
646
647 266 case EXPR_EQ:
648 case EXPR_NE:
649 {
650 266 ShumateVectorExpressionFilter *key_expr, *value_expr;
651
652
2/2
✓ Branch 9 → 10 taken 262 times.
✓ Branch 9 → 116 taken 4 times.
266 if (self->expressions->len != 2)
653 break;
654
655 262 key_expr = self->expressions->pdata[0];
656 262 value_expr = self->expressions->pdata[1];
657
658
3/4
✓ Branch 11 → 12 taken 254 times.
✓ Branch 11 → 116 taken 8 times.
✓ Branch 13 → 14 taken 254 times.
✗ Branch 13 → 116 not taken.
262 if (!SHUMATE_IS_VECTOR_EXPRESSION_FILTER (key_expr) || !SHUMATE_IS_VECTOR_EXPRESSION_FILTER (value_expr))
659 break;
660
2/2
✓ Branch 14 → 15 taken 206 times.
✓ Branch 14 → 116 taken 48 times.
254 if (value_expr->type != EXPR_LITERAL)
661 break;
662
663
3/3
✓ Branch 15 → 16 taken 8 times.
✓ Branch 15 → 29 taken 8 times.
✓ Branch 15 → 116 taken 190 times.
206 switch (key_expr->type)
664 {
665 8 case EXPR_FAST_GET:
666
2/2
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 6 times.
8 self->type = self->type == EXPR_EQ ? EXPR_FAST_EQ : EXPR_FAST_NE;
667
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 8 times.
8 self->fast_eq.key = g_strdup (key_expr->fast_get_key);
668 8 shumate_vector_value_copy (&value_expr->value, &self->fast_eq.value);
669
1/2
✓ Branch 27 → 28 taken 8 times.
✗ Branch 27 → 116 not taken.
8 g_clear_pointer (&self->expressions, g_ptr_array_unref);
670 break;
671 8 case EXPR_GEOMETRY_TYPE:
672 {
673 8 const char *geometry_type;
674
675
1/2
✓ Branch 30 → 31 taken 8 times.
✗ Branch 30 → 36 not taken.
8 if (!shumate_vector_value_get_string (&value_expr->value, &geometry_type))
676 break;
677
678
2/2
✓ Branch 31 → 32 taken 4 times.
✓ Branch 31 → 33 taken 4 times.
8 self->type = self->type == EXPR_EQ ? EXPR_FAST_GEOMETRY_TYPE : EXPR_FAST_NOT_GEOMETRY_TYPE;
679 8 self->fast_geometry_type = parse_geometry_type_flag (geometry_type);
680
1/2
✓ Branch 34 → 35 taken 8 times.
✗ Branch 34 → 36 not taken.
8 g_clear_pointer (&self->expressions, g_ptr_array_unref);
681 break;
682 }
683 default:
684 break;
685 }
686
687 break;
688 }
689
690 28 case EXPR_GET:
691 case EXPR_HAS:
692 case EXPR_NOT_HAS:
693 {
694 28 ShumateVectorExpressionFilter *key_expr = self->expressions->pdata[0];
695 28 const char *key;
696
697
1/2
✓ Branch 37 → 38 taken 28 times.
✗ Branch 37 → 56 not taken.
28 if (self->expressions->len != 1)
698 break;
699
700
1/2
✓ Branch 39 → 40 taken 28 times.
✗ Branch 39 → 56 not taken.
28 if (!SHUMATE_IS_VECTOR_EXPRESSION_FILTER (key_expr))
701 break;
702
2/2
✓ Branch 40 → 41 taken 18 times.
✓ Branch 40 → 56 taken 10 times.
28 if (key_expr->type != EXPR_LITERAL)
703 break;
704
705
1/2
✓ Branch 42 → 43 taken 18 times.
✗ Branch 42 → 56 not taken.
18 if (shumate_vector_value_get_string (&key_expr->value, &key))
706 {
707
4/4
✓ Branch 43 → 44 taken 10 times.
✓ Branch 43 → 46 taken 8 times.
✓ Branch 44 → 45 taken 4 times.
✓ Branch 44 → 46 taken 6 times.
18 self->type = (self->type == EXPR_GET) ? EXPR_FAST_GET : (self->type == EXPR_HAS) ? EXPR_FAST_HAS : EXPR_FAST_NOT_HAS;
708
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 18 times.
18 self->fast_get_key = g_strdup (key);
709
1/2
✓ Branch 54 → 55 taken 18 times.
✗ Branch 54 → 56 not taken.
18 g_clear_pointer (&self->expressions, g_ptr_array_unref);
710 }
711 break;
712 }
713
714 14 case EXPR_IN:
715 case EXPR_NOT_IN:
716 {
717 14 ShumateVectorExpressionFilter *key_expr = self->expressions->pdata[0];
718
719
1/2
✓ Branch 58 → 59 taken 14 times.
✗ Branch 58 → 116 not taken.
14 if (!SHUMATE_IS_VECTOR_EXPRESSION_FILTER (key_expr))
720 break;
721
722
3/3
✓ Branch 59 → 60 taken 2 times.
✓ Branch 59 → 85 taken 6 times.
✓ Branch 59 → 116 taken 6 times.
14 switch (key_expr->type)
723 {
724 2 case EXPR_GEOMETRY_TYPE:
725
2/2
✓ Branch 65 → 61 taken 2 times.
✓ Branch 65 → 66 taken 2 times.
4 for (int i = 1, n = self->expressions->len; i < n; i ++)
726 {
727 2 ShumateVectorExpressionFilter *expr = self->expressions->pdata[i];
728
2/4
✓ Branch 62 → 63 taken 2 times.
✗ Branch 62 → 66 not taken.
✓ Branch 63 → 64 taken 2 times.
✗ Branch 63 → 66 not taken.
2 if (!SHUMATE_IS_VECTOR_EXPRESSION_FILTER (expr) || expr->type != EXPR_LITERAL)
729 break;
730 }
731
732
1/2
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 2 times.
2 self->type = self->type == EXPR_IN ? EXPR_FAST_GEOMETRY_TYPE : EXPR_FAST_NOT_GEOMETRY_TYPE;
733 2 self->fast_geometry_type = 0;
734
735
2/2
✓ Branch 83 → 69 taken 2 times.
✓ Branch 83 → 84 taken 2 times.
4 for (int i = 1; i < self->expressions->len; i ++)
736 {
737 2 ShumateVectorExpressionFilter *value_expr = self->expressions->pdata[i];
738
739
1/2
✓ Branch 69 → 70 taken 2 times.
✗ Branch 69 → 77 not taken.
2 if (value_expr->value.type == SHUMATE_VECTOR_VALUE_TYPE_ARRAY)
740 {
741
2/2
✓ Branch 76 → 71 taken 4 times.
✓ Branch 76 → 82 taken 2 times.
6 for (int j = 0, n = value_expr->value.array->len; j < n; j ++)
742 {
743 4 const char *geometry_type;
744
1/2
✓ Branch 72 → 73 taken 4 times.
✗ Branch 72 → 75 not taken.
4 if (shumate_vector_value_get_string (g_ptr_array_index (value_expr->value.array, j), &geometry_type))
745 4 self->fast_geometry_type |= parse_geometry_type_flag (geometry_type);
746 }
747 }
748 else
749 {
750 ✗ const char *geometry_type;
751 ✗ if (shumate_vector_value_get_string (&value_expr->value, &geometry_type))
752 ✗ self->fast_geometry_type |= parse_geometry_type_flag (geometry_type);
753 }
754 }
755
756 2 g_clear_pointer (&self->expressions, g_ptr_array_unref);
757 break;
758
759 6 case EXPR_FAST_GET:
760
2/2
✓ Branch 90 → 86 taken 6 times.
✓ Branch 90 → 91 taken 6 times.
12 for (int i = 1, n = self->expressions->len; i < n; i ++)
761 {
762 6 ShumateVectorExpressionFilter *expr = self->expressions->pdata[i];
763
2/4
✓ Branch 87 → 88 taken 6 times.
✗ Branch 87 → 91 not taken.
✓ Branch 88 → 89 taken 6 times.
✗ Branch 88 → 91 not taken.
6 if (!SHUMATE_IS_VECTOR_EXPRESSION_FILTER (expr) || expr->type != EXPR_LITERAL)
764 break;
765 }
766
767
2/2
✓ Branch 91 → 92 taken 2 times.
✓ Branch 91 → 93 taken 4 times.
6 self->type = self->type == EXPR_IN ? EXPR_FAST_IN : EXPR_FAST_NOT_IN;
768
1/2
✗ Branch 93 → 94 not taken.
✓ Branch 93 → 95 taken 6 times.
6 self->fast_in.key = g_strdup (key_expr->fast_get_key);
769
770 6 self->fast_in.haystack = g_hash_table_new_full (
771 (GHashFunc)shumate_vector_value_hash, (GEqualFunc)shumate_vector_value_equal, (GDestroyNotify)shumate_vector_value_free, NULL
772 );
773
2/2
✓ Branch 114 → 103 taken 6 times.
✓ Branch 114 → 115 taken 6 times.
12 for (int i = 1; i < self->expressions->len; i ++)
774 {
775 6 ShumateVectorExpressionFilter *value_expr = self->expressions->pdata[i];
776
777
1/2
✓ Branch 103 → 104 taken 6 times.
✗ Branch 103 → 110 not taken.
6 if (value_expr->value.type == SHUMATE_VECTOR_VALUE_TYPE_ARRAY)
778 {
779
2/2
✓ Branch 109 → 105 taken 16 times.
✓ Branch 109 → 113 taken 6 times.
22 for (int j = 0, n = value_expr->value.array->len; j < n; j ++)
780 {
781 16 ShumateVectorValue *value = g_new0 (ShumateVectorValue, 1);
782 16 shumate_vector_value_copy (g_ptr_array_index (value_expr->value.array, j), value);
783 16 g_hash_table_add (self->fast_in.haystack, value);
784 }
785 }
786 else
787 {
788 ✗ ShumateVectorValue *value = g_new0 (ShumateVectorValue, 1);
789 ✗ shumate_vector_value_copy (&value_expr->value, value);
790 ✗ g_hash_table_add (self->fast_in.haystack, value);
791 }
792 }
793
794 6 g_clear_pointer (&self->expressions, g_ptr_array_unref);
795 break;
796
797 default:
798 break;
799 }
800
801 break;
802 }
803
804 default:
805 break;
806 }
807
808 662 return (ShumateVectorExpression *)self;
809 }
810
811
812 static void
813 1898 shumate_vector_expression_filter_finalize (GObject *object)
814 {
815 1898 ShumateVectorExpressionFilter *self = (ShumateVectorExpressionFilter *)object;
816
817
2/2
✓ Branch 2 → 3 taken 622 times.
✓ Branch 2 → 4 taken 1276 times.
1898 g_clear_pointer (&self->expressions, g_ptr_array_unref);
818
819
7/7
✓ Branch 4 → 5 taken 1184 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 4 → 9 taken 6 times.
✓ Branch 4 → 11 taken 28 times.
✓ Branch 4 → 13 taken 6 times.
✓ Branch 4 → 17 taken 8 times.
✓ Branch 4 → 21 taken 664 times.
1898 switch (self->type)
820 {
821 1184 case EXPR_LITERAL:
822 1184 shumate_vector_value_unset (&self->value);
823 1184 break;
824 2 case EXPR_FORMAT:
825
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 21 not taken.
2 g_clear_pointer (&self->format_parts, g_ptr_array_unref);
826 break;
827 6 case EXPR_MATCH:
828
1/2
✓ Branch 9 → 10 taken 6 times.
✗ Branch 9 → 21 not taken.
6 g_clear_pointer (&self->match_expressions, g_hash_table_unref);
829 break;
830 28 case EXPR_FAST_GET:
831 case EXPR_FAST_HAS:
832 case EXPR_FAST_NOT_HAS:
833
1/2
✓ Branch 11 → 12 taken 28 times.
✗ Branch 11 → 21 not taken.
28 g_clear_pointer (&self->fast_get_key, g_free);
834 break;
835 6 case EXPR_FAST_IN:
836 case EXPR_FAST_NOT_IN:
837
1/2
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 15 not taken.
6 g_clear_pointer (&self->fast_in.key, g_free);
838
1/2
✓ Branch 15 → 16 taken 6 times.
✗ Branch 15 → 21 not taken.
6 g_clear_pointer (&self->fast_in.haystack, g_hash_table_unref);
839 break;
840 8 case EXPR_FAST_EQ:
841 case EXPR_FAST_NE:
842
1/2
✓ Branch 17 → 18 taken 8 times.
✗ Branch 17 → 19 not taken.
8 g_clear_pointer (&self->fast_eq.key, g_free);
843 8 shumate_vector_value_unset (&self->fast_eq.value);
844 8 break;
845 default:
846 break;
847 }
848
849 1898 G_OBJECT_CLASS (shumate_vector_expression_filter_parent_class)->finalize (object);
850 1898 }
851
852
853 static gboolean
854 1890 shumate_vector_expression_filter_eval (ShumateVectorExpression *expr,
855 ShumateVectorRenderScope *scope,
856 ShumateVectorValue *out)
857 {
858 1890 ShumateVectorExpressionFilter *self = (ShumateVectorExpressionFilter *)expr;
859 3780 g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
860 1890 g_auto(ShumateVectorValue) value2 = SHUMATE_VECTOR_VALUE_INIT;
861 1890 g_auto(ShumateVectorValue) value3 = SHUMATE_VECTOR_VALUE_INIT;
862 1890 gboolean inverted = FALSE;
863 1890 gboolean boolean;
864 1890 double number, number2;
865 1890 g_autofree char *string = NULL;
866 1890 ShumateVectorExpression **expressions = NULL;
867 1890 ShumateVectorCollator collator;
868 1890 guint n_expressions = 0;
869
870
2/2
✓ Branch 2 → 3 taken 614 times.
✓ Branch 2 → 4 taken 1276 times.
1890 if (self->expressions)
871 {
872 614 expressions = (ShumateVectorExpression **)self->expressions->pdata;
873 614 n_expressions = self->expressions->len;
874 }
875
876
47/50
✓ Branch 4 → 5 taken 1208 times.
✓ Branch 4 → 6 taken 18 times.
✓ Branch 4 → 36 taken 12 times.
✓ Branch 4 → 57 taken 14 times.
✓ Branch 4 → 58 taken 28 times.
✗ Branch 4 → 67 not taken.
✓ Branch 4 → 88 taken 4 times.
✓ Branch 4 → 96 taken 6 times.
✓ Branch 4 → 97 taken 4 times.
✓ Branch 4 → 117 taken 4 times.
✓ Branch 4 → 120 taken 4 times.
✓ Branch 4 → 121 taken 4 times.
✓ Branch 4 → 128 taken 2 times.
✓ Branch 4 → 133 taken 2 times.
✓ Branch 4 → 134 taken 4 times.
✓ Branch 4 → 155 taken 16 times.
✓ Branch 4 → 156 taken 234 times.
✓ Branch 4 → 183 taken 52 times.
✓ Branch 4 → 239 taken 6 times.
✓ Branch 4 → 247 taken 8 times.
✓ Branch 4 → 250 taken 6 times.
✓ Branch 4 → 259 taken 24 times.
✓ Branch 4 → 284 taken 2 times.
✓ Branch 4 → 295 taken 2 times.
✓ Branch 4 → 317 taken 2 times.
✓ Branch 4 → 328 taken 14 times.
✓ Branch 4 → 348 taken 6 times.
✓ Branch 4 → 363 taken 24 times.
✓ Branch 4 → 387 taken 32 times.
✓ Branch 4 → 412 taken 4 times.
✓ Branch 4 → 425 taken 12 times.
✓ Branch 4 → 430 taken 2 times.
✓ Branch 4 → 476 taken 4 times.
✗ Branch 4 → 490 not taken.
✓ Branch 4 → 495 taken 6 times.
✓ Branch 4 → 508 taken 28 times.
✓ Branch 4 → 510 taken 6 times.
✓ Branch 4 → 525 taken 12 times.
✓ Branch 4 → 557 taken 6 times.
✓ Branch 4 → 568 taken 36 times.
✓ Branch 4 → 613 taken 4 times.
✓ Branch 4 → 614 taken 4 times.
✓ Branch 4 → 618 taken 6 times.
✓ Branch 4 → 620 taken 2 times.
✓ Branch 4 → 621 taken 2 times.
✓ Branch 4 → 625 taken 2 times.
✓ Branch 4 → 626 taken 6 times.
✓ Branch 4 → 630 taken 4 times.
✓ Branch 4 → 631 taken 2 times.
✗ Branch 4 → 641 not taken.
1890 switch (self->type)
877 {
878 1208 case EXPR_LITERAL:
879 1208 shumate_vector_value_copy (&self->value, out);
880 1208 return TRUE;
881
882 18 case EXPR_TO_BOOLEAN:
883 {
884
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 18 times.
18 g_assert (n_expressions == 1);
885
886
1/2
✓ Branch 9 → 10 taken 18 times.
✗ Branch 9 → 643 not taken.
18 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
887 return FALSE;
888
889
4/5
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 13 not taken.
✓ Branch 10 → 15 taken 10 times.
✓ Branch 10 → 20 taken 4 times.
✓ Branch 10 → 25 taken 2 times.
18 switch (value.type)
890 {
891 2 case SHUMATE_VECTOR_VALUE_TYPE_NULL:
892 2 shumate_vector_value_set_boolean (out, FALSE);
893 2 return TRUE;
894 ✗ case SHUMATE_VECTOR_VALUE_TYPE_BOOLEAN:
895 ✗ shumate_vector_value_copy (&value, out);
896 ✗ return TRUE;
897 10 case SHUMATE_VECTOR_VALUE_TYPE_NUMBER:
898
4/4
✓ Branch 15 → 16 taken 8 times.
✓ Branch 15 → 17 taken 2 times.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 6 times.
10 shumate_vector_value_set_boolean (out, value.number != 0 && !isnan (value.number));
899 10 return TRUE;
900 4 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
901
3/4
✓ Branch 20 → 21 taken 4 times.
✗ Branch 20 → 22 not taken.
✓ Branch 21 → 22 taken 2 times.
✓ Branch 21 → 23 taken 2 times.
4 shumate_vector_value_set_boolean (out, value.string != NULL && value.string[0] != '\0');
902 4 return TRUE;
903 2 default:
904 2 shumate_vector_value_set_boolean (out, TRUE);
905 2 return TRUE;
906 }
907 }
908
909 case EXPR_TO_COLOR:
910
1/2
✓ Branch 36 → 27 taken 14 times.
✗ Branch 36 → 643 not taken.
14 for (int i = 0; i < n_expressions; i ++)
911 {
912 14 GdkRGBA rgba;
913
914
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 14 times.
14 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
915 ✗ continue;
916
917
2/2
✓ Branch 31 → 32 taken 12 times.
✓ Branch 31 → 34 taken 2 times.
14 if (shumate_vector_value_get_color (&value, &rgba))
918 {
919 12 shumate_vector_value_set_color (out, &rgba);
920 12 return TRUE;
921 }
922 }
923
924 return FALSE;
925
926 case EXPR_TO_NUMBER:
927
1/2
✓ Branch 57 → 37 taken 16 times.
✗ Branch 57 → 643 not taken.
16 for (int i = 0; i < n_expressions; i ++)
928 {
929
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 16 times.
16 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
930 ✗ continue;
931
932
4/5
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 43 taken 4 times.
✓ Branch 40 → 47 taken 2 times.
✓ Branch 40 → 49 taken 8 times.
✗ Branch 40 → 56 not taken.
16 switch (value.type)
933 {
934 2 case SHUMATE_VECTOR_VALUE_TYPE_NULL:
935 2 shumate_vector_value_set_number (out, 0);
936 2 return TRUE;
937 4 case SHUMATE_VECTOR_VALUE_TYPE_BOOLEAN:
938
2/2
✓ Branch 43 → 44 taken 2 times.
✓ Branch 43 → 45 taken 2 times.
4 shumate_vector_value_set_number (out, value.boolean ? 1 : 0);
939 4 return TRUE;
940 2 case SHUMATE_VECTOR_VALUE_TYPE_NUMBER:
941 2 shumate_vector_value_copy (&value, out);
942 2 return TRUE;
943 8 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
944 {
945 8 char *endptr = NULL;
946 8 number = g_ascii_strtod (value.string, &endptr);
947
4/6
✓ Branch 50 → 51 taken 8 times.
✗ Branch 50 → 55 not taken.
✓ Branch 51 → 52 taken 8 times.
✗ Branch 51 → 55 not taken.
✓ Branch 52 → 53 taken 6 times.
✓ Branch 52 → 55 taken 2 times.
8 if (errno == 0 && endptr != NULL && *endptr == '\0')
948 {
949 6 shumate_vector_value_set_number (out, number);
950 6 return TRUE;
951 }
952 }
953 2 break;
954 default:
955 break;
956 }
957 }
958
959 return FALSE;
960
961 28 case EXPR_TO_STRING:
962 {
963 28 g_autofree char *string = NULL;
964
965
1/2
✓ Branch 58 → 59 taken 28 times.
✗ Branch 58 → 61 not taken.
28 g_assert (n_expressions == 1);
966
967
1/2
✓ Branch 60 → 62 taken 28 times.
✗ Branch 60 → 65 not taken.
28 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
968 return FALSE;
969 28 string = shumate_vector_value_as_string (&value);
970 28 shumate_vector_value_set_string (out, string);
971 28 return TRUE;
972 }
973
974 ✗ case EXPR_TYPEOF:
975 {
976 ✗ g_assert (n_expressions == 1);
977
978 ✗ if (!shumate_vector_expression_eval (expressions[0], scope, &value))
979 return FALSE;
980
981 ✗ switch (value.type)
982 {
983 ✗ case SHUMATE_VECTOR_VALUE_TYPE_NULL:
984 ✗ shumate_vector_value_set_string (out, "null");
985 ✗ return TRUE;
986 ✗ case SHUMATE_VECTOR_VALUE_TYPE_BOOLEAN:
987 ✗ shumate_vector_value_set_string (out, "boolean");
988 ✗ return TRUE;
989 ✗ case SHUMATE_VECTOR_VALUE_TYPE_NUMBER:
990 ✗ shumate_vector_value_set_string (out, "number");
991 ✗ return TRUE;
992 ✗ case SHUMATE_VECTOR_VALUE_TYPE_STRING:
993 ✗ shumate_vector_value_set_string (out, "string");
994 ✗ return TRUE;
995 ✗ case SHUMATE_VECTOR_VALUE_TYPE_ARRAY:
996 ✗ shumate_vector_value_set_string (out, "array");
997 ✗ return TRUE;
998 ✗ case SHUMATE_VECTOR_VALUE_TYPE_COLOR:
999 ✗ shumate_vector_value_set_string (out, "color");
1000 ✗ return TRUE;
1001 ✗ case SHUMATE_VECTOR_VALUE_TYPE_RESOLVED_IMAGE:
1002 ✗ shumate_vector_value_set_string (out, "resolvedImage");
1003 ✗ return TRUE;
1004 ✗ default:
1005 ✗ shumate_vector_value_set_string (out, "value");
1006 ✗ return TRUE;
1007 }
1008 }
1009
1010 4 case EXPR_NOT:
1011
1/2
✓ Branch 88 → 89 taken 4 times.
✗ Branch 88 → 91 not taken.
4 g_assert (n_expressions == 1);
1012
1013
1/2
✓ Branch 90 → 92 taken 4 times.
✗ Branch 90 → 643 not taken.
4 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1014 return FALSE;
1015
1/2
✓ Branch 93 → 94 taken 4 times.
✗ Branch 93 → 643 not taken.
4 if (!shumate_vector_value_get_boolean (&value, &boolean))
1016 return FALSE;
1017
1018 4 shumate_vector_value_set_boolean (out, !boolean);
1019 4 return TRUE;
1020
1021 6 case EXPR_NONE:
1022 6 inverted = TRUE;
1023 10 G_GNUC_FALLTHROUGH;
1024 10 case EXPR_ANY:
1025
2/2
✓ Branch 106 → 98 taken 14 times.
✓ Branch 106 → 107 taken 6 times.
20 for (int i = 0; i < n_expressions; i ++)
1026 {
1027
1/2
✓ Branch 99 → 100 taken 14 times.
✗ Branch 99 → 643 not taken.
14 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
1028 return FALSE;
1029
1/2
✓ Branch 101 → 102 taken 14 times.
✗ Branch 101 → 643 not taken.
14 if (!shumate_vector_value_get_boolean (&value, &boolean))
1030 return FALSE;
1031
1032
2/2
✓ Branch 102 → 103 taken 4 times.
✓ Branch 102 → 105 taken 10 times.
14 if (boolean)
1033 {
1034 4 shumate_vector_value_set_boolean (out, TRUE ^ inverted);
1035 4 return TRUE;
1036 }
1037 }
1038
1039 6 shumate_vector_value_set_boolean (out, FALSE ^ inverted);
1040 6 return TRUE;
1041
1042 case EXPR_ALL:
1043
2/2
✓ Branch 117 → 109 taken 6 times.
✓ Branch 117 → 118 taken 2 times.
8 for (int i = 0; i < n_expressions; i ++)
1044 {
1045
1/2
✓ Branch 110 → 111 taken 6 times.
✗ Branch 110 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
1046 return FALSE;
1047
1/2
✓ Branch 112 → 113 taken 6 times.
✗ Branch 112 → 643 not taken.
6 if (!shumate_vector_value_get_boolean (&value, &boolean))
1048 return FALSE;
1049
1050
2/2
✓ Branch 113 → 114 taken 2 times.
✓ Branch 113 → 116 taken 4 times.
6 if (!boolean)
1051 {
1052 2 shumate_vector_value_set_boolean (out, FALSE);
1053 2 return TRUE;
1054 }
1055 }
1056
1057 2 shumate_vector_value_set_boolean (out, TRUE);
1058 2 return TRUE;
1059
1060 4 case EXPR_NOT_HAS:
1061 4 inverted = TRUE;
1062 8 G_GNUC_FALLTHROUGH;
1063 8 case EXPR_HAS:
1064
1/2
✓ Branch 121 → 122 taken 8 times.
✗ Branch 121 → 127 not taken.
8 g_assert (n_expressions == 1);
1065
1066 8 string = shumate_vector_expression_eval_string (expressions[0], scope, NULL);
1067 8 shumate_vector_render_scope_get_variable (scope, string, &value);
1068 8 shumate_vector_value_set_boolean (out, !shumate_vector_value_is_null (&value) ^ inverted);
1069 8 return TRUE;
1070
1071 2 case EXPR_GET:
1072
1/2
✓ Branch 128 → 129 taken 2 times.
✗ Branch 128 → 132 not taken.
2 g_assert (n_expressions == 1);
1073
1074 2 string = shumate_vector_expression_eval_string (expressions[0], scope, NULL);
1075 2 shumate_vector_render_scope_get_variable (scope, string, out);
1076 2 return TRUE;
1077
1078 2 case EXPR_NOT_IN:
1079 2 inverted = TRUE;
1080 6 G_GNUC_FALLTHROUGH;
1081 6 case EXPR_IN:
1082
1/2
✓ Branch 134 → 135 taken 6 times.
✗ Branch 134 → 137 not taken.
6 g_assert (n_expressions >= 1);
1083
1084 6 shumate_vector_expression_eval (expressions[0], scope, &value);
1085
1086
2/2
✓ Branch 152 → 138 taken 12 times.
✓ Branch 152 → 153 taken 2 times.
20 for (int i = 1; i < n_expressions; i ++)
1087 {
1088 12 shumate_vector_expression_eval (expressions[i], scope, &value2);
1089
1090
2/2
✓ Branch 140 → 141 taken 2 times.
✓ Branch 140 → 143 taken 10 times.
12 if (shumate_vector_value_equal (&value, &value2))
1091 {
1092 2 shumate_vector_value_set_boolean (out, TRUE ^ inverted);
1093 2 return TRUE;
1094 }
1095
2/2
✓ Branch 143 → 144 taken 2 times.
✓ Branch 143 → 151 taken 8 times.
10 else if (value2.type == SHUMATE_VECTOR_VALUE_TYPE_ARRAY)
1096 {
1097
1/2
✓ Branch 150 → 145 taken 8 times.
✗ Branch 150 → 151 not taken.
8 for (int i = 0, n = value2.array->len; i < n; i ++)
1098
2/2
✓ Branch 146 → 147 taken 2 times.
✓ Branch 146 → 149 taken 6 times.
8 if (shumate_vector_value_equal (&value, g_ptr_array_index (value2.array, i)))
1099 {
1100 2 shumate_vector_value_set_boolean (out, TRUE ^ inverted);
1101 2 return TRUE;
1102 }
1103 }
1104 }
1105
1106 2 shumate_vector_value_set_boolean (out, FALSE ^ inverted);
1107 2 return TRUE;
1108
1109 16 case EXPR_NE:
1110 16 inverted = TRUE;
1111 250 G_GNUC_FALLTHROUGH;
1112 250 case EXPR_EQ:
1113
1/2
✓ Branch 156 → 157 taken 250 times.
✗ Branch 156 → 159 not taken.
250 g_assert (n_expressions == 2 || n_expressions == 3);
1114
1115
2/2
✓ Branch 158 → 160 taken 248 times.
✓ Branch 158 → 643 taken 2 times.
250 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1116 return FALSE;
1117
1/2
✓ Branch 161 → 162 taken 248 times.
✗ Branch 161 → 643 not taken.
248 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1118 return FALSE;
1119
1120
2/2
✓ Branch 162 → 163 taken 4 times.
✓ Branch 162 → 180 taken 244 times.
248 if (n_expressions == 3)
1121 {
1122 4 const char *str1, *str2;
1123 4 g_autofree char *str1_auto = NULL;
1124 4 g_autofree char *str2_auto = NULL;
1125
1126
1/2
✓ Branch 164 → 165 taken 4 times.
✗ Branch 164 → 177 not taken.
4 if (!shumate_vector_value_get_string (&value, &str1))
1127 return FALSE;
1128
1/2
✓ Branch 166 → 167 taken 4 times.
✗ Branch 166 → 177 not taken.
4 if (!shumate_vector_value_get_string (&value2, &str2))
1129 return FALSE;
1130
1131
1/2
✓ Branch 168 → 169 taken 4 times.
✗ Branch 168 → 177 not taken.
4 if (!shumate_vector_expression_eval (expressions[2], scope, &value3))
1132 return FALSE;
1133
1/2
✓ Branch 170 → 171 taken 4 times.
✗ Branch 170 → 177 not taken.
4 if (!shumate_vector_value_get_collator (&value3, &collator))
1134 return FALSE;
1135
1136
2/2
✓ Branch 171 → 172 taken 2 times.
✓ Branch 171 → 175 taken 2 times.
4 if (!collator.case_sensitive)
1137 {
1138 2 str1 = str1_auto = g_utf8_casefold (str1, -1);
1139 2 str2 = str2_auto = g_utf8_casefold (str2, -1);
1140 }
1141
1142 4 shumate_vector_value_set_boolean (out, (g_utf8_collate (str1, str2) == 0) ^ inverted);
1143 4 return TRUE;
1144 }
1145 else
1146 {
1147 244 shumate_vector_value_set_boolean (out, shumate_vector_value_equal (&value, &value2) ^ inverted);
1148 244 return TRUE;
1149 }
1150
1151 52 case EXPR_LT:
1152 case EXPR_GT:
1153 case EXPR_LE:
1154 case EXPR_GE:
1155 {
1156 52 int cmp;
1157 52 const char *str, *str2;
1158 52 g_autofree char *str_auto = NULL;
1159 52 g_autofree char *str2_auto = NULL;
1160
1/2
✓ Branch 183 → 184 taken 52 times.
✗ Branch 183 → 186 not taken.
52 g_assert (n_expressions == 2 || n_expressions == 3);
1161
1162
1/2
✓ Branch 185 → 187 taken 52 times.
✗ Branch 185 → 225 not taken.
52 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1163 return FALSE;
1164
1/2
✓ Branch 188 → 189 taken 52 times.
✗ Branch 188 → 225 not taken.
52 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1165 return FALSE;
1166
1167
2/2
✓ Branch 189 → 190 taken 4 times.
✓ Branch 189 → 203 taken 48 times.
52 if (n_expressions == 3)
1168 {
1169
1/2
✓ Branch 191 → 192 taken 4 times.
✗ Branch 191 → 225 not taken.
4 if (!shumate_vector_expression_eval (expressions[2], scope, &value3))
1170 return FALSE;
1171
1/2
✓ Branch 193 → 194 taken 4 times.
✗ Branch 193 → 225 not taken.
4 if (!shumate_vector_value_get_collator (&value3, &collator))
1172 return FALSE;
1173
1174
1/2
✓ Branch 195 → 196 taken 4 times.
✗ Branch 195 → 225 not taken.
4 if (!shumate_vector_value_get_string (&value, &str))
1175 return FALSE;
1176
1/2
✓ Branch 197 → 198 taken 4 times.
✗ Branch 197 → 225 not taken.
4 if (!shumate_vector_value_get_string (&value2, &str2))
1177 return FALSE;
1178
1179
1/2
✓ Branch 198 → 199 taken 4 times.
✗ Branch 198 → 202 not taken.
4 if (!collator.case_sensitive)
1180 {
1181 4 str = str_auto = g_utf8_casefold (str, -1);
1182 4 str2 = str2_auto = g_utf8_casefold (str2, -1);
1183 }
1184
1185 4 cmp = g_utf8_collate (str, str2);
1186 }
1187
2/2
✓ Branch 204 → 205 taken 34 times.
✓ Branch 204 → 210 taken 14 times.
48 else if (shumate_vector_value_get_number (&value, &number))
1188 {
1189
1/2
✓ Branch 206 → 207 taken 34 times.
✗ Branch 206 → 225 not taken.
34 if (!shumate_vector_value_get_number (&value2, &number2))
1190 return FALSE;
1191
1192
4/4
✓ Branch 207 → 208 taken 18 times.
✓ Branch 207 → 215 taken 16 times.
✓ Branch 208 → 209 taken 8 times.
✓ Branch 208 → 215 taken 10 times.
34 cmp = number > number2 ? 1 : number < number2 ? -1 : 0;
1193 }
1194
2/2
✓ Branch 211 → 212 taken 12 times.
✓ Branch 211 → 225 taken 2 times.
14 else if (shumate_vector_value_get_string (&value, &str))
1195 {
1196
1/2
✓ Branch 213 → 214 taken 12 times.
✗ Branch 213 → 225 not taken.
12 if (!shumate_vector_value_get_string (&value2, &str2))
1197 return FALSE;
1198
1199 12 cmp = g_utf8_collate (str, str2);
1200 }
1201 else
1202 return FALSE;
1203
1204
4/5
✓ Branch 215 → 216 taken 10 times.
✓ Branch 215 → 217 taken 10 times.
✓ Branch 215 → 219 taken 12 times.
✓ Branch 215 → 221 taken 18 times.
✗ Branch 215 → 223 not taken.
50 switch (self->type)
1205 {
1206 10 case EXPR_LT:
1207 10 shumate_vector_value_set_boolean (out, (cmp < 0) ^ inverted);
1208 10 break;
1209 10 case EXPR_GT:
1210 10 shumate_vector_value_set_boolean (out, (cmp > 0) ^ inverted);
1211 10 break;
1212 12 case EXPR_LE:
1213 12 shumate_vector_value_set_boolean (out, (cmp <= 0) ^ inverted);
1214 12 break;
1215 18 case EXPR_GE:
1216 18 shumate_vector_value_set_boolean (out, (cmp >= 0) ^ inverted);
1217 18 break;
1218 ✗ default:
1219 ✗ g_assert_not_reached ();
1220 }
1221
1222 return TRUE;
1223 }
1224
1225 case EXPR_CASE:
1226
1/2
✓ Branch 239 → 228 taken 10 times.
✗ Branch 239 → 643 not taken.
10 for (int i = 0; i < n_expressions; i += 2)
1227 {
1228
1/2
✓ Branch 229 → 230 taken 10 times.
✗ Branch 229 → 643 not taken.
10 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
1229 return FALSE;
1230
1231
2/2
✓ Branch 230 → 231 taken 2 times.
✓ Branch 230 → 233 taken 8 times.
10 if (i + 1 == n_expressions)
1232 {
1233 /* fallback value */
1234 2 shumate_vector_value_steal (&value, out);
1235 2 return TRUE;
1236 }
1237 else
1238 {
1239 8 gboolean bool_result;
1240
1/2
✓ Branch 234 → 235 taken 8 times.
✗ Branch 234 → 238 not taken.
8 if (!shumate_vector_value_get_boolean (&value, &bool_result))
1241 4 return FALSE;
1242
1243
2/2
✓ Branch 235 → 236 taken 4 times.
✓ Branch 235 → 237 taken 4 times.
8 if (bool_result)
1244 4 return shumate_vector_expression_eval (expressions[i + 1], scope, out);
1245 }
1246 }
1247
1248 /* no case matched and there was no fallback */
1249 return FALSE;
1250
1251 case EXPR_COALESCE:
1252
2/2
✓ Branch 247 → 240 taken 14 times.
✓ Branch 247 → 248 taken 2 times.
16 for (int i = 0; i < n_expressions; i ++)
1253 {
1254
2/2
✓ Branch 241 → 242 taken 4 times.
✓ Branch 241 → 243 taken 10 times.
14 if (!shumate_vector_expression_eval (expressions[i], scope, out))
1255 4 continue;
1256
1257
2/2
✓ Branch 244 → 245 taken 4 times.
✓ Branch 244 → 643 taken 6 times.
10 if (shumate_vector_value_is_null (out))
1258 4 continue;
1259
1260 return TRUE;
1261 }
1262
1263 /* no expression succeeded, return null */
1264 2 shumate_vector_value_unset (out);
1265 2 return TRUE;
1266
1267 6 case EXPR_MATCH:
1268 {
1269 6 ShumateVectorExpression *output_expr;
1270
1271
1/2
✓ Branch 250 → 251 taken 6 times.
✗ Branch 250 → 253 not taken.
6 g_assert (n_expressions == 1 || n_expressions == 2);
1272
1273
1/2
✓ Branch 252 → 254 taken 6 times.
✗ Branch 252 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1274 return FALSE;
1275
1276 6 output_expr = g_hash_table_lookup (self->match_expressions, &value);
1277
1278
2/2
✓ Branch 255 → 256 taken 4 times.
✓ Branch 255 → 257 taken 2 times.
6 if (output_expr != NULL)
1279 4 return shumate_vector_expression_eval (output_expr, scope, out);
1280
1/2
✓ Branch 257 → 258 taken 2 times.
✗ Branch 257 → 643 not taken.
2 else if (n_expressions == 2)
1281 2 return shumate_vector_expression_eval (expressions[1], scope, out);
1282 else
1283 return FALSE;
1284 }
1285
1286 /* no case matched and there was no fallback */
1287 return FALSE;
1288
1289 24 case EXPR_CONCAT:
1290 {
1291 48 g_autoptr(GString) string_builder = g_string_new ("");
1292
1293
2/2
✓ Branch 279 → 261 taken 36 times.
✓ Branch 279 → 280 taken 24 times.
60 for (int i = 0; i < n_expressions; i ++)
1294 {
1295
1/2
✓ Branch 262 → 263 taken 36 times.
✗ Branch 262 → 282 not taken.
36 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
1296 return FALSE;
1297
1298
1/2
✗ Branch 263 → 264 not taken.
✓ Branch 263 → 265 taken 36 times.
36 g_free (string);
1299 36 string = shumate_vector_value_as_string (&value);
1300
1301
1/2
✓ Branch 267 → 268 taken 36 times.
✗ Branch 267 → 269 not taken.
72 g_string_append (string_builder, string);
1302 }
1303
1304 24 shumate_vector_value_set_string (out, string_builder->str);
1305 24 return TRUE;
1306 }
1307
1308 2 case EXPR_DOWNCASE:
1309 {
1310 2 const char *str;
1311 2 g_autofree char *string_down = NULL;
1312
1/2
✓ Branch 284 → 285 taken 2 times.
✗ Branch 284 → 287 not taken.
2 g_assert (n_expressions == 1);
1313
1314
1/2
✓ Branch 286 → 288 taken 2 times.
✗ Branch 286 → 293 not taken.
2 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1315 return FALSE;
1316
1/2
✓ Branch 289 → 290 taken 2 times.
✗ Branch 289 → 293 not taken.
2 if (!shumate_vector_value_get_string (&value, &str))
1317 return FALSE;
1318
1319 2 string_down = g_utf8_strdown (str, -1);
1320
1321 2 shumate_vector_value_set_string (out, string_down);
1322 2 return TRUE;
1323 }
1324
1325 2 case EXPR_RESOLVED_LOCALE:
1326 {
1327 2 g_autofree char *locale = NULL;
1328
1329
1/2
✓ Branch 295 → 296 taken 2 times.
✗ Branch 295 → 298 not taken.
2 g_assert (n_expressions == 1);
1330
1331
1/2
✓ Branch 297 → 299 taken 2 times.
✗ Branch 297 → 315 not taken.
2 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1332 return FALSE;
1333
1/2
✓ Branch 300 → 301 taken 2 times.
✗ Branch 300 → 315 not taken.
2 if (!shumate_vector_value_get_collator (&value, &collator))
1334 return FALSE;
1335
1336
1/2
✗ Branch 302 → 303 not taken.
✓ Branch 302 → 304 taken 2 times.
2 locale = g_strdup (g_get_language_names ()[0]);
1337
1338 /* if there is an encoding at the end, remove it */
1339
1/2
✗ Branch 310 → 311 not taken.
✓ Branch 310 → 312 taken 2 times.
2 if (strchr (locale, '.'))
1340 ✗ *strchr (locale, '.') = '\0';
1341
1342 /* replace _ with - */
1343 2 g_strdelimit (locale, "_", '-');
1344
1345 2 shumate_vector_value_set_string (out, locale);
1346 2 return TRUE;
1347 }
1348
1349 2 case EXPR_UPCASE:
1350 {
1351 2 const char *str;
1352 2 g_autofree char *string_up = NULL;
1353
1/2
✓ Branch 317 → 318 taken 2 times.
✗ Branch 317 → 320 not taken.
2 g_assert (n_expressions == 1);
1354
1355
1/2
✓ Branch 319 → 321 taken 2 times.
✗ Branch 319 → 326 not taken.
2 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1356 return FALSE;
1357
1/2
✓ Branch 322 → 323 taken 2 times.
✗ Branch 322 → 326 not taken.
2 if (!shumate_vector_value_get_string (&value, &str))
1358 return FALSE;
1359
1360 2 string_up = g_utf8_strup (str, -1);
1361
1362 2 shumate_vector_value_set_string (out, string_up);
1363 2 return TRUE;
1364 }
1365
1366 14 case EXPR_ADD:
1367 case EXPR_MUL:
1368 case EXPR_MIN:
1369 case EXPR_MAX:
1370
1/2
✓ Branch 328 → 329 taken 14 times.
✗ Branch 328 → 331 not taken.
14 g_assert (n_expressions >= 1);
1371
1372
1/2
✓ Branch 330 → 332 taken 14 times.
✗ Branch 330 → 643 not taken.
14 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1373 return FALSE;
1374
1/2
✓ Branch 333 → 345 taken 14 times.
✗ Branch 333 → 643 not taken.
14 if (!shumate_vector_value_get_number (&value, &number))
1375 return FALSE;
1376
1377
2/2
✓ Branch 345 → 334 taken 26 times.
✓ Branch 345 → 346 taken 10 times.
36 for (int i = 1; i < n_expressions; i ++)
1378 {
1379
1/2
✓ Branch 335 → 336 taken 26 times.
✗ Branch 335 → 643 not taken.
26 if (!shumate_vector_expression_eval (expressions[i], scope, &value))
1380 return FALSE;
1381
2/2
✓ Branch 337 → 338 taken 22 times.
✓ Branch 337 → 643 taken 4 times.
26 if (!shumate_vector_value_get_number (&value, &number2))
1382 return FALSE;
1383
1384
4/5
✓ Branch 338 → 339 taken 6 times.
✓ Branch 338 → 340 taken 4 times.
✓ Branch 338 → 341 taken 6 times.
✓ Branch 338 → 342 taken 6 times.
✗ Branch 338 → 343 not taken.
22 switch (self->type)
1385 {
1386 6 case EXPR_ADD:
1387 6 number += number2;
1388 6 break;
1389 4 case EXPR_MUL:
1390 4 number *= number2;
1391 4 break;
1392 6 case EXPR_MIN:
1393 6 number = MIN (number, number2);
1394 6 break;
1395 6 case EXPR_MAX:
1396 6 number = MAX (number, number2);
1397 6 break;
1398 ✗ default:
1399 22 g_assert_not_reached ();
1400 }
1401 }
1402
1403 10 shumate_vector_value_set_number (out, number);
1404 10 return TRUE;
1405
1406 6 case EXPR_SUB:
1407
1/2
✓ Branch 348 → 349 taken 6 times.
✗ Branch 348 → 350 not taken.
6 g_assert (n_expressions >= 1);
1408
1/2
✓ Branch 349 → 351 taken 6 times.
✗ Branch 349 → 353 not taken.
6 g_assert (n_expressions <= 2);
1409
1410
1/2
✓ Branch 352 → 354 taken 6 times.
✗ Branch 352 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1411 return FALSE;
1412
1/2
✓ Branch 355 → 356 taken 6 times.
✗ Branch 355 → 643 not taken.
6 if (!shumate_vector_value_get_number (&value, &number))
1413 return FALSE;
1414
1415
2/2
✓ Branch 356 → 357 taken 2 times.
✓ Branch 356 → 358 taken 4 times.
6 if (n_expressions == 1)
1416 2 shumate_vector_value_set_number (out, 0 - number);
1417 else
1418 {
1419
1/2
✓ Branch 359 → 360 taken 4 times.
✗ Branch 359 → 643 not taken.
4 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1420 return FALSE;
1421
1/2
✓ Branch 361 → 362 taken 4 times.
✗ Branch 361 → 643 not taken.
4 if (!shumate_vector_value_get_number (&value2, &number2))
1422 return FALSE;
1423
1424 4 shumate_vector_value_set_number (out, number - number2);
1425 }
1426 return TRUE;
1427
1428 24 case EXPR_DIV:
1429 case EXPR_REM:
1430 case EXPR_POW:
1431
1/2
✓ Branch 363 → 364 taken 24 times.
✗ Branch 363 → 366 not taken.
24 g_assert (n_expressions == 2);
1432
1433
1/2
✓ Branch 365 → 367 taken 24 times.
✗ Branch 365 → 643 not taken.
24 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1434 return FALSE;
1435
1/2
✓ Branch 368 → 369 taken 24 times.
✗ Branch 368 → 643 not taken.
24 if (!shumate_vector_value_get_number (&value, &number))
1436 return FALSE;
1437
1438
1/2
✓ Branch 370 → 371 taken 24 times.
✗ Branch 370 → 643 not taken.
24 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1439 return FALSE;
1440
1/2
✓ Branch 372 → 373 taken 24 times.
✗ Branch 372 → 643 not taken.
24 if (!shumate_vector_value_get_number (&value2, &number2))
1441 return FALSE;
1442
1443
3/4
✓ Branch 373 → 374 taken 12 times.
✓ Branch 373 → 380 taken 8 times.
✓ Branch 373 → 383 taken 4 times.
✗ Branch 373 → 386 not taken.
24 switch (self->type)
1444 {
1445 12 case EXPR_DIV:
1446
2/2
✓ Branch 374 → 375 taken 10 times.
✓ Branch 374 → 379 taken 2 times.
12 if (number2 == 0)
1447
4/4
✓ Branch 375 → 376 taken 6 times.
✓ Branch 375 → 378 taken 4 times.
✓ Branch 376 → 377 taken 2 times.
✓ Branch 376 → 378 taken 4 times.
12 shumate_vector_value_set_number (out, number == 0 ? NAN : number > 0 ? INFINITY : -INFINITY);
1448 else
1449 2 shumate_vector_value_set_number (out, number / number2);
1450 return TRUE;
1451
1452 8 case EXPR_REM:
1453
2/2
✓ Branch 380 → 381 taken 6 times.
✓ Branch 380 → 382 taken 2 times.
8 if (number2 == 0)
1454 6 shumate_vector_value_set_number (out, NAN);
1455 else
1456 2 shumate_vector_value_set_number (out, fmod (number, number2));
1457 return TRUE;
1458
1459 4 case EXPR_POW:
1460 4 number = pow (number, number2);
1461
1/2
✓ Branch 383 → 384 taken 4 times.
✗ Branch 383 → 643 not taken.
4 if (isnan (number))
1462 return FALSE;
1463
1464 4 shumate_vector_value_set_number (out, number);
1465 4 return TRUE;
1466
1467 ✗ default:
1468 ✗ g_assert_not_reached ();
1469 }
1470
1471 return TRUE;
1472
1473 32 case EXPR_ABS:
1474 case EXPR_ACOS:
1475 case EXPR_ASIN:
1476 case EXPR_ATAN:
1477 case EXPR_CEIL:
1478 case EXPR_COS:
1479 case EXPR_FLOOR:
1480 case EXPR_LN:
1481 case EXPR_LOG10:
1482 case EXPR_LOG2:
1483 case EXPR_ROUND:
1484 case EXPR_SIN:
1485 case EXPR_SQRT:
1486 case EXPR_TAN:
1487
1/2
✓ Branch 387 → 388 taken 32 times.
✗ Branch 387 → 390 not taken.
32 g_assert (n_expressions == 1);
1488
1489
1/2
✓ Branch 389 → 391 taken 32 times.
✗ Branch 389 → 643 not taken.
32 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1490 return FALSE;
1491
1/2
✓ Branch 392 → 393 taken 32 times.
✗ Branch 392 → 643 not taken.
32 if (!shumate_vector_value_get_number (&value, &number))
1492 return FALSE;
1493
1494
14/15
✓ Branch 393 → 394 taken 4 times.
✓ Branch 393 → 395 taken 2 times.
✓ Branch 393 → 396 taken 2 times.
✓ Branch 393 → 397 taken 2 times.
✓ Branch 393 → 398 taken 2 times.
✓ Branch 393 → 399 taken 2 times.
✓ Branch 393 → 400 taken 2 times.
✓ Branch 393 → 401 taken 2 times.
✓ Branch 393 → 402 taken 2 times.
✓ Branch 393 → 403 taken 2 times.
✓ Branch 393 → 404 taken 4 times.
✓ Branch 393 → 405 taken 2 times.
✓ Branch 393 → 406 taken 2 times.
✓ Branch 393 → 407 taken 2 times.
✗ Branch 393 → 408 not taken.
32 switch (self->type)
1495 {
1496 4 case EXPR_ABS:
1497 4 number = fabs (number);
1498 4 break;
1499 2 case EXPR_ACOS:
1500 2 number = acos (number);
1501 2 break;
1502 2 case EXPR_ASIN:
1503 2 number = asin (number);
1504 2 break;
1505 2 case EXPR_ATAN:
1506 2 number = atan (number);
1507 2 break;
1508 2 case EXPR_CEIL:
1509 2 number = ceil (number);
1510 2 break;
1511 2 case EXPR_COS:
1512 2 number = cos (number);
1513 2 break;
1514 2 case EXPR_FLOOR:
1515 2 number = floor (number);
1516 2 break;
1517 2 case EXPR_LN:
1518 2 number = log (number);
1519 2 break;
1520 2 case EXPR_LOG10:
1521 2 number = log10 (number);
1522 2 break;
1523 2 case EXPR_LOG2:
1524 2 number = log2 (number);
1525 2 break;
1526 4 case EXPR_ROUND:
1527 4 number = round (number);
1528 4 break;
1529 2 case EXPR_SIN:
1530 2 number = sin (number);
1531 2 break;
1532 2 case EXPR_SQRT:
1533 2 number = sqrt (number);
1534 2 break;
1535 2 case EXPR_TAN:
1536 2 number = tan (number);
1537 2 break;
1538 ✗ default:
1539 ✗ g_assert_not_reached ();
1540 }
1541
1542
1/2
✓ Branch 409 → 410 taken 32 times.
✗ Branch 409 → 643 not taken.
32 if (isnan (number))
1543 return FALSE;
1544
1545 32 shumate_vector_value_set_number (out, number);
1546 32 return TRUE;
1547
1548 4 case EXPR_IMAGE:
1549 {
1550 1894 g_autoptr(ShumateVectorSprite) sprite = NULL;
1551
1/2
✓ Branch 412 → 413 taken 4 times.
✗ Branch 412 → 415 not taken.
4 g_assert (n_expressions == 1);
1552
1553 4 string = shumate_vector_expression_eval_string (expressions[0], scope, NULL);
1554
1/2
✗ Branch 414 → 416 not taken.
✓ Branch 414 → 417 taken 4 times.
4 if (string == NULL)
1555 {
1556 ✗ shumate_vector_value_unset (out);
1557 ✗ return TRUE;
1558 }
1559
1560 4 sprite = shumate_vector_sprite_sheet_get_sprite (scope->sprites, string, scope->scale_factor);
1561
2/2
✓ Branch 418 → 419 taken 2 times.
✓ Branch 418 → 421 taken 2 times.
4 if (sprite == NULL)
1562 {
1563 2 shumate_vector_value_unset (out);
1564 2 return TRUE;
1565 }
1566
1567 2 shumate_vector_value_set_image (out, sprite, string);
1568 2 return TRUE;
1569 }
1570
1571 12 case EXPR_COLLATOR:
1572
1/2
✓ Branch 425 → 426 taken 12 times.
✗ Branch 425 → 429 not taken.
12 g_assert (n_expressions == 1);
1573
1574 12 collator.case_sensitive = shumate_vector_expression_eval_boolean (expressions[0], scope, FALSE);
1575 12 shumate_vector_value_set_collator (out, &collator);
1576 12 return TRUE;
1577
1578 2 case EXPR_FORMAT:
1579 {
1580 2 FormatExpressionPart **format_expressions = (FormatExpressionPart **)self->format_parts->pdata;
1581 2 n_expressions = self->format_parts->len;
1582 1890 g_autoptr(GPtrArray) format_parts = g_ptr_array_new_full (n_expressions, (GDestroyNotify)shumate_vector_format_part_free);
1583
1584
2/2
✓ Branch 471 → 432 taken 10 times.
✓ Branch 471 → 472 taken 2 times.
14 for (int i = 0; i < n_expressions; i++)
1585 {
1586
1/2
✓ Branch 474 → 475 taken 2 times.
✗ Branch 474 → 643 not taken.
22 g_autoptr(ShumateVectorFormatPart) part = g_new0 (ShumateVectorFormatPart, 1);
1587
1588
1/2
✓ Branch 434 → 435 taken 10 times.
✗ Branch 434 → 466 not taken.
10 if (!shumate_vector_expression_eval (format_expressions[i]->string, scope, &value))
1589 return FALSE;
1590
1591
2/4
✓ Branch 435 → 436 taken 8 times.
✗ Branch 435 → 444 not taken.
✓ Branch 435 → 447 taken 2 times.
✗ Branch 435 → 466 not taken.
10 switch (value.type)
1592 {
1593 8 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
1594 {
1595 8 const char *string;
1596 8 shumate_vector_value_get_string (&value, &string);
1597
1598
1/2
✗ Branch 437 → 438 not taken.
✓ Branch 437 → 439 taken 8 times.
8 if (strlen (string) == 0)
1599 ✗ continue;
1600
1601
1/2
✗ Branch 439 → 440 not taken.
✓ Branch 439 → 442 taken 8 times.
8 part->string = g_strdup (string);
1602 8 break;
1603 }
1604
1605 ✗ case SHUMATE_VECTOR_VALUE_TYPE_RESOLVED_IMAGE:
1606 {
1607 ✗ part->string = shumate_vector_value_as_string (&value);
1608 ✗ shumate_vector_value_get_image (&value, &part->sprite);
1609 ✗ g_object_ref (part->sprite);
1610 ✗ break;
1611 }
1612
1613 2 case SHUMATE_VECTOR_VALUE_TYPE_NULL:
1614 2 continue;
1615
1616 default:
1617 return FALSE;
1618 }
1619
1620
2/2
✓ Branch 449 → 450 taken 4 times.
✓ Branch 449 → 457 taken 4 times.
8 if (format_expressions[i]->text_color != NULL)
1621 {
1622
1/2
✓ Branch 451 → 452 taken 4 times.
✗ Branch 451 → 466 not taken.
4 if (!shumate_vector_expression_eval (format_expressions[i]->text_color, scope, &value))
1623 return FALSE;
1624
1625
2/2
✓ Branch 453 → 454 taken 2 times.
✓ Branch 453 → 457 taken 2 times.
4 if (!shumate_vector_value_is_null (&value))
1626 {
1627
1/2
✓ Branch 455 → 456 taken 2 times.
✗ Branch 455 → 466 not taken.
2 if (!shumate_vector_value_get_color (&value, &part->text_color))
1628 return FALSE;
1629 2 part->has_text_color = TRUE;
1630 }
1631 }
1632
1633
2/2
✓ Branch 457 → 458 taken 4 times.
✓ Branch 457 → 465 taken 4 times.
8 if (format_expressions[i]->font_scale != NULL)
1634 {
1635
1/2
✓ Branch 459 → 460 taken 4 times.
✗ Branch 459 → 466 not taken.
4 if (!shumate_vector_expression_eval (format_expressions[i]->font_scale, scope, &value))
1636 return FALSE;
1637
1638
2/2
✓ Branch 461 → 462 taken 2 times.
✓ Branch 461 → 465 taken 2 times.
4 if (!shumate_vector_value_is_null (&value))
1639 {
1640
1/2
✓ Branch 463 → 464 taken 2 times.
✗ Branch 463 → 466 not taken.
2 if (!shumate_vector_value_get_number (&value, &part->font_scale))
1641 return FALSE;
1642 2 part->has_font_scale = TRUE;
1643 }
1644 }
1645
1646 8 g_ptr_array_add (format_parts, g_steal_pointer (&part));
1647 }
1648
1649 2 shumate_vector_value_set_formatted (out, format_parts);
1650 2 return TRUE;
1651 }
1652
1653 4 case EXPR_GEOMETRY_TYPE:
1654 {
1655 4 VectorTile__Tile__Feature *feature = shumate_vector_reader_iter_get_feature_struct (scope->reader);
1656 4 ShumateGeometryType geometry_type;
1657
1658
1/2
✗ Branch 477 → 478 not taken.
✓ Branch 477 → 480 taken 4 times.
4 if (feature == NULL)
1659 {
1660 ✗ shumate_vector_value_unset (out);
1661 ✗ return TRUE;
1662 }
1663
1664 4 geometry_type = shumate_vector_reader_iter_get_feature_geometry_type (scope->reader);
1665
1666
1/4
✓ Branch 481 → 482 taken 4 times.
✗ Branch 481 → 484 not taken.
✗ Branch 481 → 486 not taken.
✗ Branch 481 → 488 not taken.
4 switch (geometry_type)
1667 {
1668 4 case SHUMATE_GEOMETRY_TYPE_POINT:
1669 case SHUMATE_GEOMETRY_TYPE_MULTIPOINT:
1670 4 shumate_vector_value_set_string (out, "Point");
1671 4 return TRUE;
1672 ✗ case SHUMATE_GEOMETRY_TYPE_LINESTRING:
1673 case SHUMATE_GEOMETRY_TYPE_MULTILINESTRING:
1674 ✗ shumate_vector_value_set_string (out, "LineString");
1675 ✗ return TRUE;
1676 ✗ case SHUMATE_GEOMETRY_TYPE_POLYGON:
1677 case SHUMATE_GEOMETRY_TYPE_MULTIPOLYGON:
1678 ✗ shumate_vector_value_set_string (out, "Polygon");
1679 ✗ return TRUE;
1680 ✗ default:
1681 ✗ shumate_vector_value_unset (out);
1682 ✗ return TRUE;
1683 }
1684 }
1685
1686 ✗ case EXPR_ID:
1687 {
1688 ✗ VectorTile__Tile__Feature *feature = shumate_vector_reader_iter_get_feature_struct (scope->reader);
1689
1690 ✗ if (!feature || !feature->has_id)
1691 ✗ shumate_vector_value_unset (out);
1692 else
1693 ✗ shumate_vector_value_set_number (out, feature->id);
1694 return TRUE;
1695 }
1696
1697 6 case EXPR_GLOBAL_STATE:
1698 {
1699 6 ShumateVectorValue *global_val;
1700
1701
1/2
✓ Branch 495 → 496 taken 6 times.
✗ Branch 495 → 497 not taken.
6 g_assert (n_expressions == 1);
1702
1703
1/2
✗ Branch 496 → 498 not taken.
✓ Branch 496 → 500 taken 6 times.
6 if (scope->global_state == NULL)
1704 {
1705 ✗ shumate_vector_value_unset (out);
1706 ✗ return TRUE;
1707 }
1708
1709 6 string = shumate_vector_expression_eval_string (expressions[0], scope, NULL);
1710
1711
2/2
✓ Branch 501 → 502 taken 2 times.
✓ Branch 501 → 504 taken 4 times.
6 if (string == NULL)
1712 {
1713 2 shumate_vector_value_unset (out);
1714 2 return TRUE;
1715 }
1716
1717 4 global_val = g_hash_table_lookup (scope->global_state, string);
1718
1719
1/2
✓ Branch 505 → 506 taken 4 times.
✗ Branch 505 → 507 not taken.
4 if (global_val != NULL)
1720 4 shumate_vector_value_copy (global_val, out);
1721 else
1722 ✗ shumate_vector_value_unset (out);
1723 return TRUE;
1724 }
1725
1726 28 case EXPR_ZOOM:
1727 28 shumate_vector_value_set_number (out, scope->zoom_level);
1728 28 return TRUE;
1729
1730 6 case EXPR_AT:
1731 {
1732 6 GPtrArray *array;
1733
1/2
✓ Branch 510 → 511 taken 6 times.
✗ Branch 510 → 513 not taken.
6 g_assert (n_expressions == 2);
1734
1735
1/2
✓ Branch 512 → 514 taken 6 times.
✗ Branch 512 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1736 return FALSE;
1737
1/2
✓ Branch 515 → 516 taken 6 times.
✗ Branch 515 → 643 not taken.
6 if (!shumate_vector_value_get_number (&value, &number))
1738 return FALSE;
1739
1740
1/2
✓ Branch 517 → 518 taken 6 times.
✗ Branch 517 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1741 return FALSE;
1742
1/2
✓ Branch 519 → 520 taken 6 times.
✗ Branch 519 → 643 not taken.
6 if (!(array = shumate_vector_value_get_array (&value2)))
1743 return FALSE;
1744
1745
4/6
✓ Branch 520 → 521 taken 6 times.
✗ Branch 520 → 643 not taken.
✓ Branch 521 → 522 taken 4 times.
✓ Branch 521 → 643 taken 2 times.
✓ Branch 522 → 523 taken 4 times.
✗ Branch 522 → 643 not taken.
6 if (number < 0 || number >= array->len || number != (int)number)
1746 return FALSE;
1747
1748 4 shumate_vector_value_copy (g_ptr_array_index (array, (int)number), out);
1749 4 return TRUE;
1750 }
1751
1752 12 case EXPR_INDEX_OF:
1753
1/2
✓ Branch 525 → 526 taken 12 times.
✗ Branch 525 → 528 not taken.
12 g_assert (n_expressions == 2 || n_expressions == 3);
1754
1755
1/2
✓ Branch 527 → 529 taken 12 times.
✗ Branch 527 → 643 not taken.
12 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1756 return FALSE;
1757
1758
2/2
✓ Branch 529 → 530 taken 2 times.
✓ Branch 529 → 536 taken 10 times.
12 if (n_expressions == 3)
1759 {
1760
1/2
✓ Branch 531 → 532 taken 2 times.
✗ Branch 531 → 643 not taken.
2 if (!shumate_vector_expression_eval (expressions[2], scope, &value2))
1761 return FALSE;
1762
1/2
✓ Branch 533 → 534 taken 2 times.
✗ Branch 533 → 643 not taken.
2 if (!shumate_vector_value_get_number (&value2, &number))
1763 return FALSE;
1764
2/4
✓ Branch 534 → 535 taken 2 times.
✗ Branch 534 → 643 not taken.
✓ Branch 535 → 537 taken 2 times.
✗ Branch 535 → 643 not taken.
2 if (number != (int)number || number < 0)
1765 return FALSE;
1766 }
1767 else
1768 10 number = 0;
1769
1770
1/2
✓ Branch 538 → 539 taken 12 times.
✗ Branch 538 → 643 not taken.
12 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1771 return FALSE;
1772
1773
2/3
✓ Branch 539 → 540 taken 8 times.
✓ Branch 539 → 547 taken 4 times.
✗ Branch 539 → 643 not taken.
12 switch (value2.type)
1774 {
1775 8 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
1776 {
1777 8 const char *string;
1778 8 const char *substring;
1779 8 const char *found;
1780
1781 8 shumate_vector_value_get_string (&value2, &string);
1782
1/2
✓ Branch 542 → 543 taken 8 times.
✗ Branch 542 → 546 not taken.
8 if (!shumate_vector_value_get_string (&value, &substring))
1783 return FALSE;
1784
1785 8 number = MIN (number, g_utf8_strlen (string, -1));
1786 8 found = strstr (g_utf8_offset_to_pointer (string, (int)number), substring);
1787
1788
2/2
✓ Branch 543 → 544 taken 4 times.
✓ Branch 543 → 545 taken 4 times.
8 if (found == NULL)
1789 4 shumate_vector_value_set_number (out, -1);
1790 else
1791 4 shumate_vector_value_set_number (out, g_utf8_pointer_to_offset (string, found));
1792
1793 return TRUE;
1794 }
1795
1796 4 case SHUMATE_VECTOR_VALUE_TYPE_ARRAY:
1797 {
1798 4 GPtrArray *array = shumate_vector_value_get_array (&value2);
1799
1800
2/2
✓ Branch 554 → 549 taken 10 times.
✓ Branch 554 → 555 taken 2 times.
16 for (; number < array->len; number ++)
1801 {
1802
2/2
✓ Branch 550 → 551 taken 2 times.
✓ Branch 550 → 553 taken 8 times.
10 if (shumate_vector_value_equal (g_ptr_array_index (array, (int)number), &value))
1803 {
1804 2 shumate_vector_value_set_number (out, number);
1805 2 return TRUE;
1806 }
1807 }
1808
1809 2 shumate_vector_value_set_number (out, -1);
1810 2 return TRUE;
1811 }
1812
1813 default:
1814 return FALSE;
1815 }
1816
1817 6 case EXPR_LENGTH:
1818
1/2
✓ Branch 557 → 558 taken 6 times.
✗ Branch 557 → 560 not taken.
6 g_assert (n_expressions == 1);
1819
1820
1/2
✓ Branch 559 → 561 taken 6 times.
✗ Branch 559 → 643 not taken.
6 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1821 return FALSE;
1822
1823
2/3
✓ Branch 561 → 562 taken 2 times.
✓ Branch 561 → 565 taken 4 times.
✗ Branch 561 → 643 not taken.
6 switch (value.type)
1824 {
1825 2 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
1826 {
1827 2 const char *string;
1828 2 shumate_vector_value_get_string (&value, &string);
1829 2 shumate_vector_value_set_number (out, g_utf8_strlen (string, -1));
1830 2 return TRUE;
1831 }
1832
1833 4 case SHUMATE_VECTOR_VALUE_TYPE_ARRAY:
1834 {
1835 4 GPtrArray *array = shumate_vector_value_get_array (&value);
1836 4 shumate_vector_value_set_number (out, array->len);
1837 4 return TRUE;
1838 }
1839
1840 default:
1841 return FALSE;
1842 }
1843
1844 36 case EXPR_SLICE:
1845 {
1846 36 double start, end;
1847
1848
1/2
✓ Branch 568 → 569 taken 36 times.
✗ Branch 568 → 571 not taken.
36 g_assert (n_expressions == 2 || n_expressions == 3);
1849
1850
1/2
✓ Branch 570 → 572 taken 36 times.
✗ Branch 570 → 612 not taken.
36 if (!shumate_vector_expression_eval (expressions[0], scope, &value))
1851 return FALSE;
1852
1853
1/2
✓ Branch 573 → 574 taken 36 times.
✗ Branch 573 → 612 not taken.
36 if (!shumate_vector_expression_eval (expressions[1], scope, &value2))
1854 return FALSE;
1855
1/2
✓ Branch 575 → 576 taken 36 times.
✗ Branch 575 → 612 not taken.
36 if (!shumate_vector_value_get_number (&value2, &start))
1856 return FALSE;
1857
1/2
✓ Branch 576 → 577 taken 36 times.
✗ Branch 576 → 612 not taken.
36 if (start != (int)start)
1858 return FALSE;
1859
1860
2/2
✓ Branch 577 → 578 taken 22 times.
✓ Branch 577 → 583 taken 14 times.
36 if (n_expressions == 3)
1861 {
1862
1/2
✓ Branch 579 → 580 taken 22 times.
✗ Branch 579 → 612 not taken.
22 if (!shumate_vector_expression_eval (expressions[2], scope, &value2))
1863 return FALSE;
1864
1/2
✓ Branch 581 → 582 taken 22 times.
✗ Branch 581 → 612 not taken.
22 if (!shumate_vector_value_get_number (&value2, &end))
1865 return FALSE;
1866
1/2
✓ Branch 582 → 584 taken 22 times.
✗ Branch 582 → 612 not taken.
22 if (end != (int)end)
1867 return FALSE;
1868 }
1869 else
1870 14 end = G_MAXDOUBLE;
1871
1872
2/3
✓ Branch 584 → 585 taken 18 times.
✓ Branch 584 → 599 taken 18 times.
✗ Branch 584 → 612 not taken.
36 switch (value.type)
1873 {
1874 18 case SHUMATE_VECTOR_VALUE_TYPE_STRING:
1875 {
1876 18 const char *input;
1877 18 const char *start_ptr, *end_ptr;
1878 18 long len;
1879
1880 18 shumate_vector_value_get_string (&value, &input);
1881 18 len = g_utf8_strlen (input, -1);
1882
1883
2/2
✓ Branch 586 → 587 taken 6 times.
✓ Branch 586 → 588 taken 12 times.
18 if (start < 0)
1884 6 start = MAX (len + start, 0);
1885 else
1886 12 start = MIN (start, len);
1887
1888
2/2
✓ Branch 589 → 590 taken 6 times.
✓ Branch 589 → 591 taken 12 times.
18 if (end < 0)
1889 6 end = MAX (len + end, 0);
1890 else
1891 12 end = MIN (end, len);
1892
1893
2/2
✓ Branch 592 → 593 taken 6 times.
✓ Branch 592 → 595 taken 12 times.
18 if (start >= end)
1894 {
1895 6 shumate_vector_value_set_string (out, "");
1896 6 return TRUE;
1897 }
1898
1899 12 start_ptr = g_utf8_offset_to_pointer (input, (int)start);
1900 12 end_ptr = g_utf8_offset_to_pointer (input, (int)end);
1901
1902 12 string = g_strndup (start_ptr, end_ptr - start_ptr);
1903 12 shumate_vector_value_set_string (out, string);
1904 12 return TRUE;
1905 }
1906
1907 18 case SHUMATE_VECTOR_VALUE_TYPE_ARRAY:
1908 {
1909 18 GPtrArray *array = shumate_vector_value_get_array (&value);
1910 18 long len = array->len;
1911
1912
2/2
✓ Branch 600 → 601 taken 6 times.
✓ Branch 600 → 602 taken 12 times.
18 if (start < 0)
1913 6 start = MAX (len + start, 0);
1914 else
1915 12 start = MIN (start, len);
1916
1917
2/2
✓ Branch 603 → 604 taken 6 times.
✓ Branch 603 → 605 taken 12 times.
18 if (end < 0)
1918 6 end = MAX (len + end, 0);
1919 else
1920 12 end = MIN (end, len);
1921
1922 18 shumate_vector_value_start_array (out);
1923
2/2
✓ Branch 611 → 608 taken 26 times.
✓ Branch 611 → 612 taken 18 times.
44 for (int i = start; i < end; i ++)
1924 {
1925 26 shumate_vector_value_copy (
1926 26 g_ptr_array_index (array, (int)i),
1927 &value2
1928 );
1929 26 shumate_vector_value_array_append (out, &value2);
1930 }
1931 return TRUE;
1932 }
1933
1934 default:
1935 return FALSE;
1936 }
1937 }
1938
1939 4 case EXPR_FAST_NOT_HAS:
1940 4 inverted = TRUE;
1941 8 G_GNUC_FALLTHROUGH;
1942 8 case EXPR_FAST_HAS:
1943 8 shumate_vector_render_scope_get_variable (scope, self->fast_get_key, &value);
1944 8 shumate_vector_value_set_boolean (out, !shumate_vector_value_is_null (&value) ^ inverted);
1945 8 return TRUE;
1946
1947 6 case EXPR_FAST_GET:
1948 6 shumate_vector_render_scope_get_variable (scope, self->fast_get_key, out);
1949 6 return TRUE;
1950
1951 2 case EXPR_FAST_NOT_IN:
1952 2 inverted = TRUE;
1953 4 G_GNUC_FALLTHROUGH;
1954 4 case EXPR_FAST_IN:
1955 4 shumate_vector_render_scope_get_variable (scope, self->fast_in.key, &value);
1956 4 shumate_vector_value_set_boolean (out, g_hash_table_contains (self->fast_in.haystack, &value) ^ inverted);
1957 4 return TRUE;
1958
1959 2 case EXPR_FAST_NE:
1960 2 inverted = TRUE;
1961 8 G_GNUC_FALLTHROUGH;
1962 8 case EXPR_FAST_EQ:
1963 8 shumate_vector_render_scope_get_variable (scope, self->fast_eq.key, &value);
1964 8 shumate_vector_value_set_boolean (out, shumate_vector_value_equal (&value, &self->fast_eq.value) ^ inverted);
1965 8 return TRUE;
1966
1967 4 case EXPR_FAST_NOT_GEOMETRY_TYPE:
1968 4 inverted = TRUE;
1969 6 G_GNUC_FALLTHROUGH;
1970 6 case EXPR_FAST_GEOMETRY_TYPE:
1971 {
1972 6 VectorTile__Tile__Feature *feature = shumate_vector_reader_iter_get_feature_struct (scope->reader);
1973 6 gboolean result = FALSE;
1974
1975
1/2
✗ Branch 632 → 633 not taken.
✓ Branch 632 → 635 taken 6 times.
6 if (feature == NULL)
1976 {
1977 ✗ shumate_vector_value_unset (out);
1978 ✗ return TRUE;
1979 }
1980
1981
1/4
✓ Branch 635 → 636 taken 6 times.
✗ Branch 635 → 637 not taken.
✗ Branch 635 → 638 not taken.
✗ Branch 635 → 639 not taken.
6 switch (feature->type)
1982 {
1983 6 case VECTOR_TILE__TILE__GEOM_TYPE__POINT:
1984 6 result = self->fast_geometry_type & GEOM_POINT;
1985 6 break;
1986 ✗ case VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING:
1987 ✗ result = self->fast_geometry_type & GEOM_LINESTRING;
1988 ✗ break;
1989 ✗ case VECTOR_TILE__TILE__GEOM_TYPE__POLYGON:
1990 ✗ result = self->fast_geometry_type & GEOM_POINT;
1991 ✗ break;
1992 default:
1993 result = FALSE;
1994 break;
1995 }
1996
1997 6 shumate_vector_value_set_boolean (out, result ^ inverted);
1998 6 return TRUE;
1999 }
2000
2001 ✗ default:
2002 1890 g_assert_not_reached ();
2003 }
2004 }
2005
2006 static ShumateVectorIndexBitset *
2007 22 shumate_vector_expression_filter_eval_bitset (ShumateVectorExpression *expr,
2008 ShumateVectorRenderScope *scope,
2009 ShumateVectorIndexBitset *mask)
2010 {
2011 22 ShumateVectorExpressionFilter *self = (ShumateVectorExpressionFilter *)expr;
2012 22 VectorTile__Tile__Layer *layer = shumate_vector_reader_iter_get_layer_struct (scope->reader);
2013 22 ShumateVectorIndexBitset *bitset = NULL;
2014
2015
7/9
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 9 not taken.
✓ Branch 3 → 15 taken 2 times.
✓ Branch 3 → 27 taken 2 times.
✓ Branch 3 → 33 taken 4 times.
✗ Branch 3 → 43 not taken.
✓ Branch 3 → 52 taken 2 times.
✓ Branch 3 → 59 taken 2 times.
✓ Branch 3 → 62 taken 2 times.
22 switch (self->type)
2016 {
2017 8 case EXPR_LITERAL:
2018 {
2019 8 gboolean result = FALSE;
2020 8 bitset = shumate_vector_index_bitset_new (layer->n_features);
2021 8 shumate_vector_value_get_boolean (&self->value, &result);
2022
2/2
✓ Branch 6 → 7 taken 4 times.
✓ Branch 6 → 8 taken 4 times.
8 if (result)
2023 4 shumate_vector_index_bitset_not (bitset);
2024 8 return bitset;
2025 }
2026
2027 ✗ case EXPR_FAST_EQ:
2028 case EXPR_FAST_NE:
2029 ✗ bitset = shumate_vector_index_get_bitset (scope->index, scope->source_layer_idx, self->fast_eq.key, &self->fast_eq.value);
2030 ✗ if (bitset == NULL)
2031 ✗ bitset = shumate_vector_index_bitset_new (layer->n_features);
2032 else
2033 ✗ bitset = shumate_vector_index_bitset_copy (bitset);
2034 ✗ if (self->type == EXPR_FAST_NE)
2035 ✗ shumate_vector_index_bitset_not (bitset);
2036 return bitset;
2037
2038 2 case EXPR_FAST_NOT_IN:
2039 case EXPR_FAST_IN:
2040 {
2041 2 GHashTableIter iter;
2042 2 ShumateVectorValue *value;
2043 2 bitset = shumate_vector_index_bitset_new (layer->n_features);
2044 2 g_hash_table_iter_init (&iter, self->fast_in.haystack);
2045
2/2
✓ Branch 23 → 18 taken 4 times.
✓ Branch 23 → 24 taken 2 times.
8 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&value))
2046 {
2047 4 ShumateVectorIndexBitset *current_bitset = shumate_vector_index_get_bitset (scope->index, scope->source_layer_idx, self->fast_in.key, value);
2048
2/2
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 22 taken 2 times.
4 if (current_bitset != NULL)
2049 2 shumate_vector_index_bitset_or (bitset, current_bitset);
2050 }
2051
2052
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 2 times.
2 if (self->type == EXPR_FAST_NOT_IN)
2053 ✗ shumate_vector_index_bitset_not (bitset);
2054
2055 2 return bitset;
2056 }
2057
2058 2 case EXPR_FAST_HAS:
2059 case EXPR_FAST_NOT_HAS:
2060 2 bitset = shumate_vector_index_get_bitset_has (scope->index, scope->source_layer_idx, self->fast_get_key);
2061
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 2 times.
2 if (bitset == NULL)
2062 ✗ bitset = shumate_vector_index_bitset_new (layer->n_features);
2063 else
2064 2 bitset = shumate_vector_index_bitset_copy (bitset);
2065
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 63 taken 2 times.
2 if (self->type == EXPR_FAST_NOT_HAS)
2066 ✗ shumate_vector_index_bitset_not (bitset);
2067 return bitset;
2068
2069 4 case EXPR_FAST_GEOMETRY_TYPE:
2070 case EXPR_FAST_NOT_GEOMETRY_TYPE:
2071 {
2072 4 ShumateVectorIndexBitset *current_bitset;
2073 4 bitset = shumate_vector_index_bitset_new (layer->n_features);
2074
2075
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 37 taken 4 times.
4 if (self->fast_geometry_type & GEOM_POINT)
2076 {
2077 ✗ current_bitset = shumate_vector_index_get_bitset_broad_geometry_type (scope->index, scope->source_layer_idx, SHUMATE_GEOMETRY_TYPE_POINT);
2078 ✗ shumate_vector_index_bitset_or (bitset, current_bitset);
2079 }
2080
2081
1/2
✓ Branch 37 → 38 taken 4 times.
✗ Branch 37 → 40 not taken.
4 if (self->fast_geometry_type & GEOM_LINESTRING)
2082 {
2083 4 current_bitset = shumate_vector_index_get_bitset_broad_geometry_type (scope->index, scope->source_layer_idx, SHUMATE_GEOMETRY_TYPE_LINESTRING);
2084 4 shumate_vector_index_bitset_or (bitset, current_bitset);
2085 }
2086
2087
1/2
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 63 taken 4 times.
4 if (self->fast_geometry_type & GEOM_POLYGON)
2088 {
2089 ✗ current_bitset = shumate_vector_index_get_bitset_broad_geometry_type (scope->index, scope->source_layer_idx, SHUMATE_GEOMETRY_TYPE_POLYGON);
2090 ✗ shumate_vector_index_bitset_or (bitset, current_bitset);
2091 }
2092
2093 return bitset;
2094 }
2095
2096 ✗ case EXPR_NOT:
2097 ✗ bitset = shumate_vector_expression_filter_eval_bitset (g_ptr_array_index (self->expressions, 0), scope, mask);
2098 ✗ shumate_vector_index_bitset_not (bitset);
2099 ✗ return bitset;
2100
2101 case EXPR_ALL:
2102
2/2
✓ Branch 52 → 46 taken 4 times.
✓ Branch 52 → 63 taken 2 times.
6 for (int i = 0; i < self->expressions->len; i ++)
2103 {
2104 4 ShumateVectorIndexBitset *current_bitset = shumate_vector_expression_filter_eval_bitset (g_ptr_array_index (self->expressions, i), scope, bitset);
2105
2/2
✓ Branch 47 → 48 taken 2 times.
✓ Branch 47 → 50 taken 2 times.
4 if (i == 0)
2106 bitset = current_bitset;
2107 else
2108 {
2109 2 shumate_vector_index_bitset_and (bitset, current_bitset);
2110 2 shumate_vector_index_bitset_free (current_bitset);
2111 }
2112
2113
1/2
✓ Branch 50 → 51 taken 4 times.
✗ Branch 50 → 63 not taken.
4 if (bitset == NULL)
2114 return NULL;
2115 }
2116 return bitset;
2117
2118 case EXPR_ANY:
2119 case EXPR_NONE:
2120
2/2
✓ Branch 59 → 53 taken 4 times.
✓ Branch 59 → 60 taken 2 times.
6 for (int i = 0; i < self->expressions->len; i ++)
2121 {
2122 4 ShumateVectorIndexBitset *current_bitset;
2123 4 current_bitset = shumate_vector_expression_filter_eval_bitset (g_ptr_array_index (self->expressions, i), scope, bitset);
2124 /* Invert the result bitset so we can pass it to the mask parameter of eval_bitset(), saving some work
2125 if there are any non-bitset-optimized expressions */
2126 4 shumate_vector_index_bitset_not (current_bitset);
2127
2/2
✓ Branch 55 → 56 taken 2 times.
✓ Branch 55 → 58 taken 2 times.
4 if (i == 0)
2128 bitset = current_bitset;
2129 else
2130 {
2131 2 shumate_vector_index_bitset_and (bitset, current_bitset);
2132 2 shumate_vector_index_bitset_free (current_bitset);
2133 }
2134 }
2135
2136
1/2
✓ Branch 60 → 61 taken 2 times.
✗ Branch 60 → 63 not taken.
2 if (self->type == EXPR_ANY)
2137 2 shumate_vector_index_bitset_not (bitset);
2138
2139 return bitset;
2140
2141 2 default:
2142 2 return SHUMATE_VECTOR_EXPRESSION_CLASS (shumate_vector_expression_filter_parent_class)->eval_bitset (expr, scope, mask);
2143 }
2144 }
2145
2146 static void
2147 22 shumate_vector_expression_filter_collect_indexes (ShumateVectorExpression *expr,
2148 const char *layer_name,
2149 ShumateVectorIndexDescription *index_description)
2150 {
2151 22 ShumateVectorExpressionFilter *self = (ShumateVectorExpressionFilter *)expr;
2152
2153
5/6
✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 4 not taken.
✓ Branch 2 → 6 taken 2 times.
✓ Branch 2 → 12 taken 2 times.
✓ Branch 2 → 14 taken 4 times.
✓ Branch 2 → 23 taken 10 times.
22 switch (self->type)
2154 {
2155 ✗ case EXPR_FAST_EQ:
2156 case EXPR_FAST_NE:
2157 ✗ shumate_vector_index_description_add (index_description, layer_name, self->fast_eq.key, &self->fast_eq.value);
2158 ✗ break;
2159
2160 2 case EXPR_FAST_IN:
2161 case EXPR_FAST_NOT_IN:
2162 {
2163 2 GHashTableIter iter;
2164 2 ShumateVectorValue *value;
2165 2 g_hash_table_iter_init (&iter, self->fast_in.haystack);
2166
2/2
✓ Branch 10 → 8 taken 4 times.
✓ Branch 10 → 11 taken 2 times.
6 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&value))
2167 4 shumate_vector_index_description_add (index_description, layer_name, self->fast_in.key, value);
2168 2 break;
2169 }
2170
2171 2 case EXPR_FAST_HAS:
2172 case EXPR_FAST_NOT_HAS:
2173 2 shumate_vector_index_description_add_has_index (index_description, layer_name, self->fast_get_key);
2174 2 break;
2175
2176 4 case EXPR_FAST_GEOMETRY_TYPE:
2177 case EXPR_FAST_NOT_GEOMETRY_TYPE:
2178
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 4 times.
4 if (self->fast_geometry_type & GEOM_POINT)
2179 ✗ shumate_vector_index_description_add_broad_geometry_type (index_description, layer_name);
2180
2181
1/2
✓ Branch 16 → 17 taken 4 times.
✗ Branch 16 → 18 not taken.
4 if (self->fast_geometry_type & GEOM_LINESTRING)
2182 4 shumate_vector_index_description_add_broad_geometry_type (index_description, layer_name);
2183
2184
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 23 taken 4 times.
4 if (self->fast_geometry_type & GEOM_POLYGON)
2185 ✗ shumate_vector_index_description_add_broad_geometry_type (index_description, layer_name);
2186
2187 break;
2188
2189 case EXPR_ANY:
2190 case EXPR_ALL:
2191 case EXPR_NONE:
2192 case EXPR_NOT:
2193
2/2
✓ Branch 22 → 20 taken 8 times.
✓ Branch 22 → 23 taken 4 times.
12 for (int i = 0; i < self->expressions->len; i ++)
2194 8 shumate_vector_expression_collect_indexes (g_ptr_array_index (self->expressions, i), layer_name, index_description);
2195 break;
2196
2197 default:
2198 break;
2199 }
2200 22 }
2201
2202 static void
2203 8 shumate_vector_expression_filter_class_init (ShumateVectorExpressionFilterClass *klass)
2204 {
2205 8 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2206 8 ShumateVectorExpressionClass *expr_class = SHUMATE_VECTOR_EXPRESSION_CLASS (klass);
2207
2208 8 object_class->finalize = shumate_vector_expression_filter_finalize;
2209 8 expr_class->eval = shumate_vector_expression_filter_eval;
2210 8 expr_class->eval_bitset = shumate_vector_expression_filter_eval_bitset;
2211 8 expr_class->collect_indexes = shumate_vector_expression_filter_collect_indexes;
2212 }
2213
2214
2215 static void
2216 1898 shumate_vector_expression_filter_init (ShumateVectorExpressionFilter *self)
2217 {
2218 1898 }
2219