4 #include "symbol_table.h"
7 symbol_new(char const * name
)
9 Symbol
* symbol
= (Symbol
*) malloc (sizeof(Symbol
));
10 symbol
->type
= NONE_TYPE
;
11 value_set(&symbol
->value
, symbol
->type
, NULL
);
12 symbol
->decl_linenum
= 0;
14 symbol
->param_types
= (int *) malloc (sizeof(int) * 10);
19 symbol
->name
= strdup(name
);
26 /* Insere um simbolo na tabela indicada.
27 * Caso o simbolo ja exista, a memoria do
28 * simbolo do parametro sera liberada.
29 * Returns: O simbolo passado como parametro,
30 * caso este ainda nao esteja na tabela,
31 * ou um ponteiro para o simbolo encontrado.
34 symbol_insert(Symbol
*symtab
, Symbol
*symbol
)
41 sym
= symbol_lookup(symtab
, symbol
->name
);
49 symbol
->next
= symtab
->next
;
50 symtab
->next
= symbol
;
56 symbol_lookup(Symbol
*symtab
, char const *name
)
60 for (temp
= symtab
->next
; temp
!= NULL
; temp
= temp
->next
) {
61 if (!strcmp (temp
->name
, name
))
69 symbol_table_destroy(Symbol
*symtab
)
76 while (first
!= NULL
) {
79 if (to_kill
->name
!= NULL
)
86 symbol_print(Symbol
*symbol
)
93 printf("Symbol: %x\n", symbol
);
94 printf("name: %s\n", symbol
->name
);
95 printf("type: %d\n", symbol
->type
);
97 value_print(&symbol
->value
, symbol
->type
);
98 printf("\ndeclaration line: %d\n", symbol
->decl_linenum
);
99 printf("next: %x\n\n", symbol
->next
);
103 symbol_table_dump(Symbol
*symtab
)
105 Symbol
*temp
= symtab
;
107 for (temp
= symtab
->next
; temp
!= NULL
; temp
= temp
->next
)