| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <assert.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "sym.h"
- sym_t *sym_get(symtab_t *st, const char *name)
- {
- size_t i;
- for (i = 0; i < st->len; i++) {
- if (!strcmp(st->sym[i].name, name))
- return &st->sym[i];
- }
- return NULL;
- }
- int sym_add(symtab_t *st, const char *name, tid_t tid, sym_t **new)
- {
- sym_t *sym;
- sym = sym_get(st, name);
- if (sym) {
- /* if there is no type info, accept anything */
- if (!sym->tid)
- sym->tid = tid;
- /* otherwise, if specified, it must match */
- else if (tid && (sym->tid != tid))
- return -EINVAL;
- goto found;
- }
- st->sym = realloc(st->sym, ++st->len * sizeof(*st->sym));
- assert(st->sym);
- sym = &st->sym[st->len-1];
- sym->name = name;
- sym->tid = tid;
- found:
- if (new)
- *new = sym;
- return 0;
- }
|