LCOV - code coverage report
Current view: top level - src/detail - ppg_global_detail.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 27 27 100.0 %
Date: 2018-01-08 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
       2             :  *
       3             :  * This program is free software: you can redistribute it and/or modify
       4             :  * it under the terms of the GNU Lesser General Public License as published by
       5             :  * the Free Software Foundation, either version 3 of the License, or
       6             :  * (at your option) any later version.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful,
       9             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :  * GNU Lesser General Public License for more details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : 
      17             : #include "detail/ppg_global_detail.h"
      18             : #include "detail/ppg_context_detail.h"
      19             : #include "detail/ppg_pattern_matching_detail.h"
      20             : #include "ppg_debug.h"
      21             : 
      22             : /* Returns if an action has been triggered.
      23             :  */
      24         138 : bool ppg_recurse_and_process_actions(PPG_Token__ *cur_token)
      25             : {        
      26         138 :    if(!cur_token) { return false; }
      27             :    
      28             : //    PPG_LOG("Triggering action of most recent token\n");
      29             :    
      30         138 :    PPG_Count n_actions = 0;
      31             :    
      32             :    // It may be possible that a token was just started but not
      33             :    // finished. Then we go back to the parent token, that
      34             :    // was the last registered match.
      35             :    //
      36         138 :    if(   (cur_token->misc.state != PPG_Token_Matches)
      37          59 :       && (cur_token->misc.state != PPG_Token_Finalized) 
      38             :    ) {
      39          57 :       cur_token = cur_token->parent;
      40             :    }
      41             :    
      42         281 :    while(cur_token) {
      43             : 
      44         143 :       if(cur_token->action.callback.func) {
      45             :          
      46             :          // Store the tokens that carry actions in reversed order
      47             :          //
      48          85 :          cur_token->misc.action_state = PPG_Action_Enabled;
      49          85 :          ++n_actions;
      50             :          
      51          85 :          if(cur_token->misc.action_flags & PPG_Action_Fallback) {
      52           3 :             cur_token = cur_token->parent;
      53             :          }
      54             :          else {
      55          82 :             break;
      56             :          }
      57             :       }
      58             :       else {
      59          58 :          if(cur_token->misc.action_flags & PPG_Action_Fallback) {
      60           2 :             cur_token = cur_token->parent;
      61             :          }
      62             :          else {
      63          56 :             break;
      64             :          }
      65             :       }
      66             :    }
      67             :    
      68         138 :    return n_actions > 0;
      69             : }
      70             : 
      71         261 : void ppg_delete_stored_events(void)
      72             : {
      73         261 :    ppg_event_buffer_reset(&ppg_context->event_buffer); 
      74         261 : }
      75             : 
      76         158 : void ppg_reset_pattern_matching_engine(void)
      77             : {
      78         158 :    ppg_context->current_token = NULL;
      79             :             
      80         158 :    PPG_FB.cur_furcation = -1;
      81             :    
      82             :    // The token root's state has been reset to PPG_Token_Initialized 
      83             :    // during cleanup.
      84             :    //
      85         158 :    ppg_context->pattern_root->misc.state
      86         158 :          = PPG_Token_Initialized;
      87             :    
      88             :    // Start with the first token in the queue
      89             :    //
      90         158 :    PPG_EB.cur = PPG_EB.start;
      91         158 : }

Generated by: LCOV version 1.10