sval: update smatch_math.c to use range_list_sval
[smatch.git] / macro_table.c
blob921494d9743bb5c6cdb623b4110914da20ff3bb9
1 /*
2 * smatch/macro_table.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include "lib.h"
14 #include "parse.h"
15 #include "cwchash/hashtable.h"
17 static struct hashtable *macro_table;
19 static DEFINE_HASHTABLE_INSERT(do_insert_macro, struct position, char);
20 static DEFINE_HASHTABLE_SEARCH(do_search_macro, struct position, char);
22 static inline unsigned int position_hash(void *_pos)
24 struct position *pos = _pos;
26 return pos->line | (pos->pos << 22) | (pos->stream << 18);
29 static inline int equalkeys(void *_pos1, void *_pos2)
31 struct position *pos1 = _pos1;
32 struct position *pos2 = _pos2;
34 return pos1->line == pos2->line && pos1->pos == pos2->pos &&
35 pos1->stream == pos2->stream;
38 void store_macro_pos(struct token *token)
40 if (!macro_table)
41 macro_table = create_hashtable(5000, position_hash, equalkeys);
43 if (get_macro_name(token->pos))
44 return;
46 do_insert_macro(macro_table, &token->pos, token->ident->name);
49 char *get_macro_name(struct position pos)
51 return do_search_macro(macro_table, &pos);