Verilog Parser
verilog_ast_common.h
Go to the documentation of this file.
1 
7 #include "stdarg.h"
8 #include "stdlib.h"
9 #include "string.h"
10 
11 #include "verilog_ast_mem.h"
12 
13 #ifndef VERILOG_AST_COMMON_H
14 #define VERILOG_AST_COMMON_H
15 
16 
17 // --------------- Linked List ------------------------
18 
26 typedef struct ast_list_element_t ast_list_element;
28 
33  ast_list_element * next;
34  void * data;
35 };
36 
37 
41 typedef struct ast_list_t {
42  ast_list_element * head;
43  ast_list_element * tail;
44  ast_list_element * walker;
45  unsigned int items;
46  unsigned int current_item;
47 } ast_list;
48 
49 
54 
60 void ast_list_free(ast_list * list);
61 
65 void ast_list_append(ast_list * list, void * data);
66 
67 
71 void ast_list_preappend(ast_list * list, void * data);
72 
78 void * ast_list_get(ast_list * list, unsigned int item);
79 
83 void ast_list_remove_at(ast_list * list, unsigned int i);
84 
93 ast_list * ast_list_concat(ast_list * head, ast_list * tail);
94 
95 
104  ast_list * list,
105  void * data
106 );
107 
108 
111 // ----------------------- Stack --------------------------------------
112 
119 typedef struct ast_stack_element_t ast_stack_element;
121 
126  ast_stack_element * next;
127  void * data;
128 };
129 
131 typedef struct ast_stack_t{
132  unsigned int depth;
133  ast_stack_element * items;
134 } ast_stack;
135 
140 
144 void ast_stack_free(ast_stack * stack);
145 
151 void ast_stack_push(
152  ast_stack * stack,
153  void * item
154 );
155 
160 void * ast_stack_pop(
161  ast_stack * stack
162 );
163 
168 void * ast_stack_peek(
169  ast_stack * stack
170 );
171 
176 void * ast_stack_peek2(
177  ast_stack * stack
178 );
179 
183 // ----------------------- Hash Table ---------------------------------
184 
185 
201 typedef struct ast_hashtable_element_t{
203  char * key;
204  void * data;
206 
207 
209 typedef struct ast_hashtable_t{
211  unsigned int size;
212 } ast_hashtable;
213 
214 typedef enum ast_hashtable_result_e{
215  HASH_SUCCESS = 0,
216  HASH_FAIL = 1,
217  HASH_KEY_COLLISION = 2,
218  HASH_KEY_NOT_FOUND = 3
219 } ast_hashtable_result;
220 
223 
225 void ast_hashtable_free(
226  ast_hashtable * table
227 );
228 
230 ast_hashtable_result ast_hashtable_insert(
231  ast_hashtable * table,
232  char * key,
233  void * value
234 );
235 
237 ast_hashtable_result ast_hashtable_get(
238  ast_hashtable * table,
239  char * key,
240  void ** value
241 );
242 
244 ast_hashtable_result ast_hashtable_delete(
245  ast_hashtable * table,
246  char * key
247 );
248 
250 ast_hashtable_result ast_hashtable_update(
251  ast_hashtable * table,
252  char * key,
253  void * value
254 );
255 
256 #endif
void ast_list_free(ast_list *list)
Frees the memory of the supplied linked list.
Definition: verilog_ast_common.c:34
ast_list * elements
The items.
Definition: verilog_ast_common.h:210
ast_list * ast_list_concat(ast_list *head, ast_list *tail)
concatenates the two supplied lists into one.
Definition: verilog_ast_common.c:235
int ast_list_contains(ast_list *list, void *data)
Searches the list, returning true or false if the data item supplied is contained within it...
Definition: verilog_ast_common.c:195
void ast_stack_push(ast_stack *stack, void *item)
Push a new item to the top of the stack.
Definition: verilog_ast_common.c:302
ast_hashtable_result ast_hashtable_insert(ast_hashtable *table, char *key, void *value)
Inserts a new item into the hashtable.
Definition: verilog_ast_common.c:417
void ast_list_remove_at(ast_list *list, unsigned int i)
Removes the i'th item from a linked list.
Definition: verilog_ast_common.c:86
void ast_list_preappend(ast_list *list, void *data)
Adds a new item to the front of a linked list.
Definition: verilog_ast_common.c:124
void ast_hashtable_free(ast_hashtable *table)
Frees an existing hashtable, but not it's contents, only the structure.
Definition: verilog_ast_common.c:408
ast_list * ast_list_new()
Creates and returns a pointer to a new linked list.
Definition: verilog_ast_common.c:18
A hash table object.
Definition: verilog_ast_common.h:209
A single element in the hash table.
Definition: verilog_ast_common.h:202
ast_list_element * head
The "front" of the list.
Definition: verilog_ast_common.h:42
char * key
The key for the element.
Definition: verilog_ast_common.h:203
Contains Declarations of datastructures and functions for helping to manage dynamic memory allocation...
ast_hashtable_result ast_hashtable_update(ast_hashtable *table, char *key, void *value)
Updates an existing item in the hashtable.
Definition: verilog_ast_common.c:486
Storage container for a single element in the linked list.
Definition: verilog_ast_common.h:32
ast_list_element * walker
Used to "walk" along the list.
Definition: verilog_ast_common.h:44
void * ast_stack_pop(ast_stack *stack)
Pop the top item from the top of the stack.
Definition: verilog_ast_common.c:329
unsigned int items
Number of items in the list.
Definition: verilog_ast_common.h:45
void ast_list_append(ast_list *list, void *data)
Adds a new item to the end of a linked list.
Definition: verilog_ast_common.c:59
void * ast_stack_peek2(ast_stack *stack)
Peek at the item below the top item on the top of the stack.
Definition: verilog_ast_common.c:374
ast_stack_element * items
The stack of items.
Definition: verilog_ast_common.h:133
ast_hashtable_result ast_hashtable_get(ast_hashtable *table, char *key, void **value)
Returns an item from the hashtable.
Definition: verilog_ast_common.c:445
void * ast_stack_peek(ast_stack *stack)
Peek at the top item on the top of the stack.
Definition: verilog_ast_common.c:354
Container struct for the linked list data structure.
Definition: verilog_ast_common.h:41
A very simple stack.
Definition: verilog_ast_common.h:131
void * data
The data associated with they key.
Definition: verilog_ast_common.h:204
ast_stack * ast_stack_new()
Creates and returns a new stack object.
Definition: verilog_ast_common.c:276
Storage container for a single element in the stack.
Definition: verilog_ast_common.h:125
void ast_stack_free(ast_stack *stack)
Free the stack, but not it's contents.
Definition: verilog_ast_common.c:285
ast_hashtable * ast_hashtable_new()
Creates and returns a new hashtable.
Definition: verilog_ast_common.c:398
void * ast_list_get(ast_list *list, unsigned int item)
Finds and returns the i'th item in the linked list.
Definition: verilog_ast_common.c:155
ast_list_element * tail
The "end" of the list.
Definition: verilog_ast_common.h:43
unsigned int size
The number of elements in the table.
Definition: verilog_ast_common.h:211
unsigned int depth
How many items are on the stack?
Definition: verilog_ast_common.h:132
ast_hashtable_result ast_hashtable_delete(ast_hashtable *table, char *key)
Removes a key value pair from the hashtable.
Definition: verilog_ast_common.c:466