/* Try to find a class. If 'module' is NULL, then search through both the current module AND the builtin module. In all other cases, search just the module given. */ lily_class *lily_find_class(lily_symtab *symtab, lily_module_entry *module, const char *name) { uint64_t shorthash = shorthash_for_name(name); lily_class *result; if (module == NULL) { if (name[1] != '\0') { result = find_class(symtab->builtin_module->class_chain, name, shorthash); if (result == NULL) result = find_class(symtab->active_module->class_chain, name, shorthash); } else { lily_type *generic_type = lookup_generic(symtab, name); if (generic_type) { /* It's rather silly to make a different class for each generic type. Instead, write out whatever generic type was found as the default type. The generic class is written to have no subtypes, so this is okay. ts and other modules always special case the generic class, and won't be bothered by this little trick. */ result = symtab->generic_class; result->type = generic_type; } else result = NULL; } } else result = find_class(module->class_chain, name, shorthash); return result; }
static char *lookup_generic_by_id(const char *path, int id) { struct userinfo u[1]; if(lookup_generic(path, id, NULL, u)) return u->name; else return NULL; }
static int lookup_generic_by_name(const char *what, const char *path, const char *name) { struct userinfo u[1]; if(lookup_generic(path, -1, name, u)) return u->id; else fatal(0, "unknown %s '%s'", what, name); }