4 #include "symbol_table.h"
7 symbol_new(char const * name
)
9 Symbol
* symbol
= (Symbol
*) malloc (sizeof(Symbol
));
11 value_set(&symbol
->value
, symbol
->type
, NULL
);
13 symbol
->param_types
= NULL
;
14 symbol
->decl_linenum
= 0;
15 symbol
->is_global
= FALSE
;
16 symbol
->stack_index
= -1;
21 symbol
->name
= strdup(name
);
28 /* Insere um simbolo na tabela indicada.
29 * Caso o simbolo ja exista, a memoria do
30 * simbolo do parametro sera liberada.
31 * Returns: O simbolo passado como parametro,
32 * caso este ainda nao esteja na tabela,
33 * ou um ponteiro para o simbolo encontrado.
36 symbol_insert(Symbol
*symtab
, Symbol
*symbol
)
43 sym
= symbol_lookup(symtab
, symbol
->name
);
51 symbol
->next
= symtab
->next
;
52 symtab
->next
= symbol
;
58 symbol_lookup(Symbol
*symtab
, char const *name
)
65 for (temp
= symtab
->next
; temp
!= NULL
; temp
= temp
->next
) {
66 if (!strcmp (temp
->name
, name
))
74 symbol_table_destroy(Symbol
*symtab
)
81 while (first
!= NULL
) {
84 if (to_kill
->name
!= NULL
)
91 symbol_create_params(Symbol
*symbol
, int quantity
)
93 symbol
->params
= quantity
;
95 symbol
->param_types
= (int *) malloc (sizeof(int) * quantity
);
99 symbol_is_procfunc(Symbol
*symbol
)
101 return (symbol
->params
> -1);
105 symbol_print(Symbol
*symbol
)
107 if (symbol
== NULL
) {
112 printf("Symbol: %x\n", symbol
);
113 printf("name: %s\n", symbol
->name
);
114 printf("type: %d\n", symbol
->type
);
116 value_print(stdout
, &symbol
->value
, symbol
->type
);
117 printf("\ndeclaration line: %d\n", symbol
->decl_linenum
);
118 printf("next: %x\n\n", symbol
->next
);
122 symbol_table_dump(Symbol
*symtab
)
124 Symbol
*temp
= symtab
;
126 for (temp
= symtab
->next
; temp
!= NULL
; temp
= temp
->next
)