LCOV - code coverage report
Current view: top level - src/pattern - segment.c (source / functions) Hit Total Coverage
Test: passgen-test.info Lines: 36 36 100.0 %
Date: 2024-11-29 06:05:05 Functions: 8 8 100.0 %

          Line data    Source code
       1             : #include "passgen/pattern/segment.h"
       2             : #include "passgen/config.h"
       3             : #include "passgen/container/stack.h"
       4             : #include "passgen/pattern/group.h"
       5             : #include "passgen/pattern/literal.h"
       6             : #include "passgen/pattern/repeat.h"
       7             : #include "passgen/pattern/segment_item.h"
       8             : #include "passgen/pattern/set.h"
       9             : 
      10       36647 : void passgen_pattern_segment_init(passgen_pattern_segment *segment) {
      11       36647 :     segment->multiplier = 1;
      12       36647 :     passgen_stack_init(&segment->items, sizeof(passgen_pattern_item));
      13       36647 : }
      14             : 
      15       36647 : void passgen_pattern_segment_free(passgen_pattern_segment *segment) {
      16      108760 :     for(size_t i = 0; i < segment->items.len; i++) {
      17       72113 :         passgen_pattern_item *item = passgen_stack_get(&segment->items, i);
      18             : 
      19       72113 :         passgen_pattern_item_free(item);
      20             :     }
      21             : 
      22       36647 :     passgen_stack_free(&segment->items);
      23             : 
      24       36647 :     PASSGEN_CLEAR(segment);
      25       36647 : }
      26             : 
      27             : passgen_pattern_item *
      28       72266 : passgen_pattern_segment_new_item(passgen_pattern_segment *segment) {
      29       72266 :     passgen_pattern_item *item = passgen_stack_push(&segment->items, NULL);
      30       72266 :     passgen_pattern_item_init(item);
      31             : 
      32       72266 :     return item;
      33             : }
      34             : 
      35             : passgen_pattern_literal *
      36       62447 : passgen_pattern_segment_new_char(passgen_pattern_segment *segment) {
      37       62447 :     passgen_pattern_item *item = passgen_pattern_segment_new_item(segment);
      38       62447 :     item->kind = PASSGEN_PATTERN_LITERAL;
      39       62447 :     passgen_pattern_literal_init(&item->data.literal);
      40             : 
      41       62447 :     return &item->data.literal;
      42             : }
      43             : 
      44             : passgen_pattern_set *
      45        3119 : passgen_pattern_segment_new_set(passgen_pattern_segment *segment) {
      46        3119 :     passgen_pattern_item *item = passgen_pattern_segment_new_item(segment);
      47        3119 :     item->kind = PASSGEN_PATTERN_SET;
      48        3119 :     passgen_pattern_set_init(&item->data.set);
      49             : 
      50        3119 :     return &item->data.set;
      51             : }
      52             : 
      53             : passgen_pattern_group *
      54        3274 : passgen_pattern_segment_new_group(passgen_pattern_segment *segment) {
      55        3274 :     passgen_pattern_item *item = passgen_pattern_segment_new_item(segment);
      56        3274 :     item->kind = PASSGEN_PATTERN_GROUP;
      57        3274 :     passgen_pattern_group_init(&item->data.group);
      58             : 
      59        3274 :     return &item->data.group;
      60             : }
      61             : 
      62             : passgen_pattern_special *
      63         137 : passgen_pattern_segment_new_special(passgen_pattern_segment *segment) {
      64         137 :     passgen_pattern_item *item = passgen_pattern_segment_new_item(segment);
      65         137 :     item->kind = PASSGEN_PATTERN_SPECIAL;
      66             : 
      67         137 :     return &item->data.special;
      68             : }
      69             : 
      70             : passgen_pattern_item *
      71          35 : passgen_pattern_segment_get_item(passgen_pattern_segment *segment, size_t n) {
      72          35 :     return passgen_stack_get(&segment->items, n);
      73             : }

Generated by: LCOV version 1.14