ast_t* symtab_find_case(symtab_t* symtab, const char* name, sym_status_t* status) { // Same as symtab_get, but is partially case insensitive. That is, type names // are compared as uppercase and other symbols are compared as lowercase. symbol_t s1 = {name, NULL, SYM_NONE, 0}; symbol_t* s2 = symtab_get(symtab, &s1); if(s2 != NULL) { if(status != NULL) *status = s2->status; return s2->def; } const char* no_case = name_without_case(name); if(no_case != name) return symtab_find_case(symtab, no_case, status); if(status != NULL) *status = SYM_NONE; return NULL; }
bool symtab_add(symtab_t* symtab, const char* name, ast_t* def, sym_status_t status) { const char* no_case = name_without_case(name); if(no_case != name) { symbol_t s1 = {no_case, def, SYM_NOCASE, 0}; symbol_t* s2 = symtab_get(symtab, &s1); if(s2 != NULL) return false; symtab_put(symtab, sym_dup(&s1)); } symbol_t s1 = {name, def, status, 0}; symbol_t* s2 = symtab_get(symtab, &s1); if(s2 != NULL) return false; symtab_put(symtab, sym_dup(&s1)); return true; }
bool symtab_add(symtab_t* symtab, const char* name, ast_t* def, sym_status_t status) { const char* no_case = name_without_case(name); if(no_case != name) { symbol_t s1 = {no_case, def, SYM_NOCASE, 0}; size_t index = HASHMAP_UNKNOWN; symbol_t* s2 = symtab_get(symtab, &s1, &index); if(s2 != NULL) return false; // didn't find it in the map but index is where we can put the // new one without another search symtab_putindex(symtab, sym_dup(&s1), index); } symbol_t s1 = {name, def, status, 0}; size_t index = HASHMAP_UNKNOWN; symbol_t* s2 = symtab_get(symtab, &s1, &index); if(s2 != NULL) return false; // didn't find it in the map but index is where we can put the // new one without another search symtab_putindex(symtab, sym_dup(&s1), index); return true; }