struct Package {
char *name;
+ char *unqualified_name;
Scope *scope;
Scope *private_scope;
};
+typedef struct OnyxDocInfo {
+ bh_arr(AstFunction *) procedures;
+} OnyxDocInfo;
+
+
typedef struct CompileOptions CompileOptions;
struct CompileOptions {
bh_allocator allocator;
bh_arr(AstNode *) tag_locations;
struct SymbolInfoTable *symbol_info;
+ struct OnyxDocInfo *doc_info;
u32 cycle_almost_detected : 2;
b32 cycle_detected : 1;
func->type = type_build_function_type(context.ast_alloc, func);
if (func->type == NULL) YIELD(func->token->pos, "Waiting for function type to be constructed");
+ // TODO nocheckin move this.
+ if (context.doc_info && func->entity_header && !func->generated_from) {
+ bh_arr_push(context.doc_info->procedures, func);
+ }
+
return Check_Success;
}
// to serve as indicies into the array.
bh_buffer_write_u32(&doc_buffer, p->id - 1);
- write_cstring(&doc_buffer, p->name);
+ write_cstring(&doc_buffer, p->unqualified_name);
write_cstring(&doc_buffer, package_qualified_name);
bh_buffer_write_u32(&doc_buffer, bh_arr_length(p->sub_packages));
fori (j, 0, bh_arr_length(p->sub_packages)) {
- bh_buffer_write_u32(&doc_buffer, (u32) p->sub_packages[j]);
+ bh_buffer_write_u32(&doc_buffer, (u32) p->sub_packages[j] - 1);
}
}
//
- // Entity Info
+ // Procedure Info
//
*((u32 *) bh_pointer_add(doc_buffer.data, offset_table_index + 4)) = doc_buffer.length;
+ u32 proc_count_patch = doc_buffer.length;
bh_buffer_write_u32(&doc_buffer, 0);
+ u32 proc_count = 0;
+ bh_arr(AstFunction *) procs = context.doc_info->procedures;
+ bh_arr_each(AstFunction *, pfunc, procs) {
+ AstFunction *func = *pfunc;
+
+ if (!func->intrinsic_name) continue;
+
+ write_string(&doc_buffer, func->intrinsic_name->length, func->intrinsic_name->text);
+ assert(func->entity_header && func->entity_header->package);
+
+ bh_buffer_write_u32(&doc_buffer, func->entity_header->package->id - 1);
+
+ // TODO: Location
+ bh_buffer_write_u32(&doc_buffer, 0);
+ bh_buffer_write_u32(&doc_buffer, 0);
+ bh_buffer_write_u32(&doc_buffer, 0);
+
+ write_cstring(&doc_buffer, "");
+
+ // TODO: Flags
+ bh_buffer_write_u32(&doc_buffer, 0);
+
+ proc_count++;
+ }
+
+ *((u32 *) bh_pointer_add(doc_buffer.data, proc_count_patch)) = proc_count;
+
//
// File Info
bh_arr_new(global_heap_allocator, context.symbol_info->symbols_resolutions, 128);
sh_new_arena(context.symbol_info->files);
}
+
+ if (context.options->documentation_file) {
+ context.doc_info = bh_alloc_item(global_heap_allocator, OnyxDocInfo);
+ bh_arr_new(global_heap_allocator, context.doc_info->procedures, 128);
+ }
}
static void context_free() {
pac_name[strlen(package_name)] = '\0';
package->name = pac_name;
+ package->unqualified_name = pac_name + bh_str_last_index_of(pac_name, '.');
package->use_package_entities = NULL;
package->id = next_package_id++;
bh_arr_new(global_heap_allocator, package->sub_packages, 4);
Doc :: struct {
header: Doc_Header;
- packages: [] Doc_Package;
- entities: [] Doc_Entity;
- files: [] Doc_File;
+ packages: [] Doc_Package;
+ procedures: [] Doc_Procedure;
+ files: [] Doc_File;
}
build_time: u32;
packages_info_start: u32;
- entities_info_start: u32;
+ procedures_info_start: u32;
files_info_start: u32;
}
subpackages: [] Id;
}
-
-Doc_Entity_Kind :: enum {
- Procedure :: 1;
-}
-
-Doc_Entity :: struct {
- kind: Doc_Entity_Kind;
+Doc_Procedure :: struct {
+ name: str;
package_id: Doc_Package.Id;
location: Doc_Location;
- name: str;
notes: str;
+
+ Flags :: enum #flags (u32) {
+ Is_Macro :: 1;
+ Is_Foreign :: 2;
+ }
+ flags: Flags;
}
#load "./runtime/common"
+#load "./doc/doc"
+
#if runtime.platform.Supports_Files {
#load "./os/file"
}
b32 bh_str_starts_with(char* str, char* start);
b32 bh_str_ends_with(char* str, char* end);
b32 bh_str_contains(char *str, char *needle);
+u32 bh_str_last_index_of(char *str, char needle);
char* bh_strdup(bh_allocator a, char* str);
return 0;
}
+u32 bh_str_last_index_of(char *str, char needle) {
+ u32 count = strlen(str);
+ char *end = str + count - 1;
+
+ while (end != str) {
+ if (*end == needle) break;
+ count -= 1;
+ end--;
+ }
+
+ if (end == str) count = 0;
+
+ return count;
+}
+
char* bh_strdup(bh_allocator a, char* str) {
u32 len = strlen(str);
char* buf = bh_alloc(a, len + 1);