// Create a package AST, set up its state and add it to the given program ast_t* create_package(ast_t* program, const char* name, const char* qualified_name, pass_opt_t* opt) { ast_t* package = ast_blank(TK_PACKAGE); uint32_t pkg_id = program_assign_pkg_id(program); package_t* pkg = POOL_ALLOC(package_t); pkg->path = name; pkg->qualified_name = qualified_name; pkg->id = id_to_string(NULL, pkg_id); const char* p = strrchr(pkg->path, PATH_SLASH); if(p == NULL) p = pkg->path; else p = p + 1; pkg->filename = stringtab(p); if(pkg_id > 1) pkg->symbol = create_package_symbol(program, pkg->filename); else pkg->symbol = NULL; pkg->ast = package; package_set_init(&pkg->dependencies, 1); pkg->group = NULL; pkg->group_index = -1; pkg->next_hygienic_id = 0; pkg->low_index = -1; ast_setdata(package, pkg); ast_scope(package); ast_append(program, package); ast_set(program, pkg->path, package, SYM_NONE, false); ast_set(program, pkg->id, package, SYM_NONE, false); strlist_t* safe = opt->safe_packages; if((safe != NULL) && (strlist_find(safe, pkg->path) == NULL)) pkg->allow_ffi = false; else pkg->allow_ffi = true; pkg->on_stack = false; return package; }
// Create a package AST, set up its state and add it to the given program static ast_t* create_package(ast_t* program, const char* name) { ast_t* package = ast_blank(TK_PACKAGE); uint32_t pkg_id = program_assign_pkg_id(program); package_t* pkg = POOL_ALLOC(package_t); pkg->path = name; pkg->id = id_to_string(NULL, pkg_id); const char* p = strrchr(pkg->path, PATH_SLASH); if(p == NULL) p = pkg->path; else p = p + 1; pkg->filename = stringtab(p); if(pkg_id > 1) pkg->symbol = create_package_symbol(program, pkg->filename); else pkg->symbol = NULL; pkg->next_hygienic_id = 0; ast_setdata(package, pkg); ast_scope(package); ast_append(program, package); ast_set(program, pkg->path, package, SYM_NONE); ast_set(program, pkg->id, package, SYM_NONE); if((safe != NULL) && (strlist_find(safe, pkg->path) == NULL)) pkg->allow_ffi = false; else pkg->allow_ffi = true; return package; }