// Document the given package static void doc_package(docgen_t* docgen, ast_t* ast) { assert(ast != NULL); assert(ast_id(ast) == TK_PACKAGE); assert(docgen->package_file == NULL); ast_list_t types = { NULL, NULL, NULL }; ast_t* package_doc = NULL; // Find and sort package contents for(ast_t* m = ast_child(ast); m != NULL; m = ast_sibling(m)) { if(ast_id(m) == TK_STRING) { // Package docstring assert(package_doc == NULL); package_doc = m; } else { assert(ast_id(m) == TK_MODULE); for(ast_t* t = ast_child(m); t != NULL; t = ast_sibling(t)) { if(ast_id(t) != TK_USE) { assert(ast_id(t) == TK_TYPE || ast_id(t) == TK_INTERFACE || ast_id(t) == TK_TRAIT || ast_id(t) == TK_PRIMITIVE || ast_id(t) == TK_STRUCT || ast_id(t) == TK_CLASS || ast_id(t) == TK_ACTOR); // We have a type doc_list_add_named(&types, t, 0, true, true); } } } } doc_package_home(docgen, ast, package_doc); // Process types for(ast_list_t* p = types.next; p != NULL; p = p->next) doc_entity(docgen, p->ast, ast); fclose(docgen->package_file); docgen->package_file = NULL; }
// Document the given package static void doc_package(docgen_t* docgen, ast_t* ast) { assert(ast != NULL); assert(ast_id(ast) == TK_PACKAGE); assert(docgen->package_file == NULL); assert(docgen->test_types == NULL); assert(docgen->public_types == NULL); assert(docgen->private_types == NULL); ast_list_t types = { NULL, NULL, NULL }; ast_t* package_doc = NULL; // Find and sort package contents for(ast_t* m = ast_child(ast); m != NULL; m = ast_sibling(m)) { if(ast_id(m) == TK_STRING) { // Package docstring assert(package_doc == NULL); package_doc = m; } else { assert(ast_id(m) == TK_MODULE); for(ast_t* t = ast_child(m); t != NULL; t = ast_sibling(t)) { if(ast_id(t) != TK_USE) { assert(ast_id(t) == TK_TYPE || ast_id(t) == TK_INTERFACE || ast_id(t) == TK_TRAIT || ast_id(t) == TK_PRIMITIVE || ast_id(t) == TK_STRUCT || ast_id(t) == TK_CLASS || ast_id(t) == TK_ACTOR); // We have a type doc_list_add_named(&types, t, 0, true, true); } } } } doc_package_home(docgen, ast, package_doc); // Process types for(ast_list_t* p = types.next; p != NULL; p = p->next) doc_entity(docgen, p->ast); // Add listing of subpackages and links if(docgen->public_types->offset > 0) { fprintf(docgen->package_file, "\n\n## Public Types\n\n"); fprintf(docgen->package_file, "%s", docgen->public_types->m); } if(docgen->private_types->offset > 0) { fprintf(docgen->package_file, "\n\n## Private Types\n\n"); fprintf(docgen->package_file, "%s", docgen->private_types->m); } if(docgen->test_types->offset > 0) { fprintf(docgen->package_file, "\n\n## Test Types\n\n"); fprintf(docgen->package_file, "%s", docgen->test_types->m); } fclose(docgen->package_file); docgen->package_file = NULL; printbuf_free(docgen->test_types); printbuf_free(docgen->public_types); printbuf_free(docgen->private_types); docgen->test_types = NULL; docgen->public_types = NULL; docgen->private_types = NULL; }