4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
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
)
41 macro_table
= create_hashtable(5000, position_hash
, equalkeys
);
43 if (get_macro_name(token
->pos
))
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
);