LCOV - code coverage report
Current view: top level - sql/common - sql_stack.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 30 60.0 %
Date: 2021-10-13 02:24:04 Functions: 5 7 71.4 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : #include "sql_stack.h"
      11             : 
      12             : sql_stack *
      13      540385 : sql_stack_new(sql_allocator *sa, int size)
      14             : {
      15      540385 :         assert(sa);
      16      540385 :         sql_stack *s = SA_NEW(sa, sql_stack);
      17      540385 :         if (s == NULL)
      18             :                 return NULL;
      19             : 
      20      540385 :         *s = (sql_stack) {
      21             :                 .sa = sa,
      22             :                 .size = size,
      23      540385 :                 .values = SA_NEW_ARRAY(sa, void*, size),
      24             :         };
      25      540385 :         if (s->values == NULL) {
      26             :                 //_DELETE(s);
      27           0 :                 return NULL;
      28             :         }
      29             :         return s;
      30             : }
      31             : 
      32             : void
      33       31284 : sql_stack_push(sql_stack *s, void *v)
      34             : {
      35       31284 :         if (s->top >= s->size) {
      36             :                 void **nvalues;
      37             :                 int osz = s->size;
      38             : 
      39           0 :                 s->size *= 2;
      40           0 :                 nvalues = SA_RENEW_ARRAY(s->sa, void*, s->values, s->size, osz);
      41           0 :                 if (nvalues == NULL) {
      42           0 :                         s->size = osz;
      43           0 :                         return;
      44             :                 }
      45           0 :                 s->values = nvalues;
      46             :         }
      47       31284 :         s->values[s->top++] = v;
      48             : }
      49             : 
      50             : void *
      51       31284 : sql_stack_pop(sql_stack *s)
      52             : {
      53       31284 :         if (s->top == 0)
      54             :                 return NULL;
      55       31284 :         return s->values[--s->top];
      56             : }
      57             : 
      58             : void *
      59           0 : sql_stack_peek(sql_stack *s, int p)
      60             : {
      61           0 :         if (p>=s->top)
      62             :                 return NULL;
      63           0 :         return s->values[(s->top-1)-p];
      64             : }
      65             : 
      66             : void *
      67       35139 : sql_stack_fetch(sql_stack *s, int p)
      68             : {
      69       35139 :         if (p>=s->top)
      70             :                 return NULL;
      71       35123 :         return s->values[p];
      72             : }
      73             : 
      74             : int
      75      223380 : sql_stack_top(sql_stack *s)
      76             : {
      77      223380 :         return s->top;
      78             : }
      79             : 
      80             : int
      81           0 : sql_stack_empty(sql_stack *s)
      82             : {
      83           0 :         return (s->top == 0);
      84             : }

Generated by: LCOV version 1.14