Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/macro_table.c
          +++ new/usr/src/tools/smatch/src/macro_table.c
↓ open down ↓ 23 lines elided ↑ open up ↑
  24   24  
  25   25  #include <stdlib.h>
  26   26  #include <stdio.h>
  27   27  #include <string.h>
  28   28  #include "lib.h"
  29   29  #include "parse.h"
  30   30  #include "cwchash/hashtable.h"
  31   31  
  32   32  static struct hashtable *macro_table;
  33   33  
  34      -static DEFINE_HASHTABLE_INSERT(do_insert_macro, struct position, char);
  35      -static DEFINE_HASHTABLE_SEARCH(do_search_macro, struct position, char);
       34 +static DEFINE_HASHTABLE_INSERT(do_insert_macro, struct position, struct string_list);
       35 +static DEFINE_HASHTABLE_SEARCH(do_search_macro, struct position, struct string_list);
  36   36  
  37   37  static inline unsigned int position_hash(void *_pos)
  38   38  {
  39   39          struct position *pos = _pos;
  40   40  
  41      -        return pos->line | (pos->pos << 22) | (pos->stream << 18); 
       41 +        return pos->line | (pos->pos << 22) | (pos->stream << 18);
  42   42  }
  43   43  
  44   44  static inline int equalkeys(void *_pos1, void *_pos2)
  45   45  {
  46   46          struct position *pos1 = _pos1;
  47   47          struct position *pos2 = _pos2;
  48   48  
  49   49          return pos1->line == pos2->line && pos1->pos == pos2->pos &&
  50   50                  pos1->stream == pos2->stream;
  51   51  }
  52   52  
       53 +static void insert_macro_string(struct string_list **str_list, char *new)
       54 +{
       55 +        add_ptr_list(str_list, new);
       56 +}
       57 +
  53   58  void store_macro_pos(struct token *token)
  54   59  {
       60 +        struct string_list *list;
       61 +
  55   62          if (!macro_table)
  56   63                  macro_table = create_hashtable(5000, position_hash, equalkeys);
  57   64  
  58      -        if (get_macro_name(token->pos))
  59      -                return;
       65 +        list = do_search_macro(macro_table, &token->pos);
       66 +        insert_macro_string(&list, token->ident->name);
  60   67  
  61      -        do_insert_macro(macro_table, &token->pos, token->ident->name);
       68 +        do_insert_macro(macro_table, &token->pos, list);
  62   69  }
  63   70  
  64   71  char *get_macro_name(struct position pos)
  65   72  {
       73 +        struct string_list *list;
       74 +
       75 +        if (!macro_table)
       76 +                return NULL;
       77 +        list = do_search_macro(macro_table, &pos);
       78 +        return first_ptr_list((struct ptr_list *)list);
       79 +}
       80 +
       81 +char *get_inner_macro(struct position pos)
       82 +{
       83 +        struct string_list *list;
       84 +
       85 +        if (!macro_table)
       86 +                return NULL;
       87 +        list = do_search_macro(macro_table, &pos);
       88 +        return last_ptr_list((struct ptr_list *)list);
       89 +}
       90 +
       91 +struct string_list *get_all_macros(struct position pos)
       92 +{
       93 +        if (!macro_table)
       94 +                return NULL;
  66   95          return do_search_macro(macro_table, &pos);
  67   96  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX