macro_table: do not include smatch.h
[smatch.git] / macro_table.c
blob6106f6699a82253d4688ef9652d54d08acc3828e
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);
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;
37 void store_macro_pos(struct token *token)
39 if (!macro_table)
40 macro_table = create_hashtable(5000, position_hash, equalkeys);
42 do_insert_macro(macro_table, &token->pos, token->ident->name);
45 char *get_macro_name(struct position *pos)
47 return do_search_macro(macro_table, pos);