LCOV - code coverage report
Current view: top level - src/common - stack.cpp (source / functions) Hit Total Coverage
Test: flower-f.info Lines: 57 70 81.4 %
Date: 2022-06-10 00:44:15 Functions: 12 18 66.7 %

          Line data    Source code
       1             : #include <cassert>
       2             : #include <iostream>
       3             : #include "common/stack.hpp"
       4             : #include "common/obstacle.hpp"
       5             : #include "common/exprtype.hpp"
       6             : 
       7        5097 : void Gendarme::push(void * p, type_t type) {
       8        5097 :     assert(pos < MAXSTACK);
       9        5097 :     pointers[pos] = p;
      10        5097 :     types[pos] = type;
      11        5097 :     pos++;
      12        5097 : }
      13             : 
      14        2608 : void Gendarme::burn(void) {
      15        2608 :     pos--;
      16        7705 :     while (pos >= 0) {
      17        5097 :         switch (types[pos]) {
      18         490 :             case _INT_: 
      19         490 :                 delete    static_cast<int *> ( pointers[pos] ); break;
      20         192 :             case _REAL_: 
      21         192 :                 delete    static_cast<float*>( pointers[pos] ); break;
      22          21 :             case _STRING_:
      23          21 :                 delete [] static_cast<char *>( pointers[pos] ); break;
      24         413 :             case _BOOLEAN_:
      25         413 :                 delete    static_cast<bool*> ( pointers[pos] ); break;
      26             :         }
      27        5097 :         pos--;
      28             :     }
      29        2608 :     pos = 0;
      30        2608 : }
      31             : 
      32         828 : Gendarme::~Gendarme(void) {
      33         414 :     burn();
      34         414 : }
      35             : 
      36         362 : Stack::Stack(bool gendarme) {
      37         362 :     pos = 0;
      38      371050 :     for (int i = 0; i < MAXSTACK; i++) {
      39      370688 :         elem[i] = nullptr;
      40      370688 :         defined[i] = false;
      41             :     }
      42         362 : }
      43             : 
      44        5076 : void Stack::push(void * x, type_t type) {
      45             :     #ifdef DEBUG
      46             :     std::cout << "PUSH " << x << '(';
      47             :     switch (type) {
      48             :         case _INT_:
      49             :             std::cout << * static_cast<int *>( x );
      50             :             break;
      51             :         case _REAL_:
      52             :             std::cout << * static_cast<float *>( x );
      53             :             break;
      54             :         case _BOOLEAN_:
      55             :             std::cout << * static_cast<bool *>( x );
      56             :             break;
      57             :         case _STRING_:
      58             :             std::cout << static_cast<char *>( x );
      59             :             break;
      60             :         default:
      61             :             std::cout << "???";
      62             :             break;
      63             :     }
      64             :     std::cout << ')' << std::endl;
      65             :     #endif
      66             : 
      67        5076 :     assert(pos < MAXSTACK);
      68        5076 :     if (isEmpty()) memControl.burn();
      69        5076 :     memControl.push(x, type);
      70        5076 :     elem[pos++] = x;
      71        5076 : }
      72             : 
      73        4985 : void * Stack::pop(void) {
      74        4985 :     assert(pos > 0);
      75        4985 :     return elem[--pos];
      76             : }
      77             : 
      78           3 : void * Stack::top(void) const {
      79           3 :     assert(pos > 0);
      80           3 :     return elem[pos - 1];
      81             : }
      82             : 
      83         467 : void * Stack::get(int x) const {
      84         467 :     assert(pos - x > 0);
      85         467 :     return elem[pos - x - 1];
      86             : }
      87             : 
      88          13 : void Stack::set(int i, void * x) {
      89          13 :     assert(pos - i > 0);
      90          13 :     elem[pos - i - 1] = x;
      91          13 : }
      92             : 
      93           0 : int Stack::size() const {
      94           0 :     return pos;
      95             : }
      96             : 
      97           0 : void * const * Stack::data(void) const {
      98           0 :     return elem;
      99             : }
     100             : 
     101           0 : const type_t * Stack::getTypes(void) const {
     102           0 :     return memControl.getTypes();
     103             : }
     104             : 
     105        5081 : bool Stack::isEmpty(void) const {
     106        5081 :     return pos == 0;
     107             : }
     108             : 
     109           0 : type_t Stack::topType(void) const {
     110           0 :     return memControl.topType();
     111             : }
     112             : 
     113           0 : type_t Gendarme::topType(void) const {
     114           0 :     assert(pos > 0);
     115           0 :     return types[pos - 1];
     116             : }
     117             : 
     118           0 : const type_t * Gendarme::getTypes(void) const {
     119           0 :     return types;
     120             : }
     121             : 
     122          39 : void Stack::updateType(type_t type) {
     123          39 :     memControl.updateType(type);
     124          39 : }
     125             : 
     126          39 : void Gendarme::updateType(type_t type) {
     127          39 :     types[pos] = type;
     128          39 : }

Generated by: LCOV version 1.14