1 /*
   2  * Copyright (C) 2009 Dan Carpenter.
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public License
   6  * as published by the Free Software Foundation; either version 2
   7  * of the License, or (at your option) any later version.
   8  *
   9  * This program 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
  12  * GNU General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public License
  15  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16  */
  17 
  18 #include "smatch.h"
  19 #include "smatch_slist.h"
  20 
  21 STATE(ignore);
  22 static struct stree *ignored;
  23 
  24 void add_ignore(int owner, const char *name, struct symbol *sym)
  25 {
  26         set_state_stree(&ignored, owner, name, sym, &ignore);
  27 }
  28 
  29 int is_ignored(int owner, const char *name, struct symbol *sym)
  30 {
  31         return !!get_state_stree(ignored, owner, name, sym);
  32 }
  33 
  34 void add_ignore_expr(int owner, struct expression *expr)
  35 {
  36         struct symbol *sym;
  37         char *name;
  38 
  39         name = expr_to_str_sym(expr, &sym);
  40         if (!name || !sym)
  41                 return;
  42         add_ignore(owner, name, sym);
  43         free_string(name);
  44 }
  45 
  46 int is_ignored_expr(int owner, struct expression *expr)
  47 {
  48         struct symbol *sym;
  49         char *name;
  50         int ret;
  51 
  52         name = expr_to_str_sym(expr, &sym);
  53         if (!name && !sym)
  54                 return 0;
  55         ret = is_ignored(owner, name, sym);
  56         free_string(name);
  57         return ret;
  58 }
  59 
  60 static void clear_ignores(void)
  61 {
  62         if (__inline_fn)
  63                 return;
  64         free_stree(&ignored);
  65 }
  66 
  67 void register_smatch_ignore(int id)
  68 {
  69         add_hook(&clear_ignores, AFTER_FUNC_HOOK);
  70 }