Example #1
0
/*
 * Adds a new offset list entry with the unique id and offset to an offsetList
 */
struct symbol_list_t *add_to_symbol_list(struct symbol_list_t **offsetList, const char *id, int offset) {

	// List was empty so initialize
	if(*offsetList == NULL) {
		*offsetList = new_symbol_list();
		(*offsetList)->id = new_identifier(id);
		(*offsetList)->offset = offset;

		return *offsetList;
	} else {
		struct symbol_list_t *end = *offsetList;
		
		// Ensures only unique ids are added
		while(end->next != NULL) {
			if(strcmp(end->id, id) == 0)
				return end;
			end = end->next;
		}
		
		end->next = new_symbol_list();
		end->next->id = new_identifier(id);
		end->next->offset = offset;

		return end->next;
	}

}
Example #2
0
/*
 * Walk hash table and construct a list. If any symbols
 * already belong to a list, the old list will become
 * invalid.
 */
SymbolList *
symtab_to_symlist(SymbolTable * st)
{
   Symbol * sym, * next;
   int i;
   SymbolList * list = new_symbol_list();
   sym = NULL;
   for (i = 0; i < SYMTAB_HASHSIZE; i++) {
      for (next = st->table[i]; next; next = next->nextintable) {
         if (!list->head)
            list->head = next;
         if (sym)
            sym->nextinlist = next;

         sym = next;
         sym->nextinlist = NULL;
      }
   }

   list->tail = sym;
   return list;
}