From 76ccce2942a0d527be5693ff5bedbf92a5de5eb2 Mon Sep 17 00:00:00 2001
From: gingerBill Directories
")
+
+ fmt.wprintln(w, "\t")
+ fmt.wprintln(w, "\t\t")
+
+ for dir := root.first_child; dir != nil; dir = dir.next {
+ if dir.first_child != nil {
+ fmt.wprint(w, `
")
+}
+
+is_entity_blank :: proc(e: doc.Entity_Index) -> bool {
+ name := str(entities[e].name)
+ return name == "" || name == "_"
+}
+
+Write_Type_Flag :: enum {
+ Is_Results,
+ Variadic,
+}
+Write_Type_Flags :: distinct bit_set[Write_Type_Flag]
+
+write_type :: proc(w: io.Writer, pkg: doc.Pkg_Index, type: doc.Type, flags: Write_Type_Flags) {
+ type_entites := array(type.entities)
+ type_types := array(type.types)
+ switch type.kind {
+ case .Invalid:
+ // ignore
+ case .Basic:
+ type_flags := transmute(doc.Type_Flags_Basic)type.flags
+ if .Untyped in type_flags {
+ io.write_string(w, str(type.name))
+ } else {
+ fmt.wprintf(w, `%s`, str(type.name))
+ }
+ case .Named:
+ e := entities[type_entites[0]]
+ name := str(type.name)
+ fmt.wprintf(w, ``)
+ tn_pkg := files[e.pos.file].pkg
+ if tn_pkg != pkg {
+ fmt.wprintf(w, `%s.`, str(pkgs[pkg].name))
+ }
+ fmt.wprintf(w, `{1:s}`, pkg_to_path[&pkgs[tn_pkg]], name)
+ case .Generic:
+ name := str(type.name)
+ io.write_byte(w, '$')
+ io.write_string(w, name)
+ if len(array(type.types)) == 1 {
+ io.write_byte(w, '/')
+ write_type(w, pkg, types[type_types[0]], flags)
+ }
+ case .Pointer:
+ io.write_byte(w, '^')
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Array:
+ assert(type.elem_count_len == 1)
+ io.write_byte(w, '[')
+ io.write_uint(w, uint(type.elem_counts[0]))
+ io.write_byte(w, ']')
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Enumerated_Array:
+ io.write_byte(w, '[')
+ write_type(w, pkg, types[type_types[0]], flags)
+ io.write_byte(w, ']')
+ write_type(w, pkg, types[type_types[1]], flags)
+ case .Slice:
+ if .Variadic in flags {
+ io.write_string(w, "..")
+ } else {
+ io.write_string(w, "[]")
+ }
+ write_type(w, pkg, types[type_types[0]], flags - {.Variadic})
+ case .Dynamic_Array:
+ io.write_string(w, "[dynamic]")
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Map:
+ io.write_string(w, "map[")
+ write_type(w, pkg, types[type_types[0]], flags)
+ io.write_byte(w, ']')
+ write_type(w, pkg, types[type_types[1]], flags)
+ case .Struct:
+ type_flags := transmute(doc.Type_Flags_Struct)type.flags
+ io.write_string(w, "struct {}")
+ case .Union:
+ type_flags := transmute(doc.Type_Flags_Union)type.flags
+ io.write_string(w, "union {}")
+ case .Enum:
+ io.write_string(w, "enum {}")
+ case .Tuple:
+ entity_indices := type_entites
+ if len(entity_indices) == 0 {
+ return
+ }
+ require_parens := (.Is_Results in flags) && (len(entity_indices) > 1 || !is_entity_blank(entity_indices[0]))
+ if require_parens { io.write_byte(w, '(') }
+ for entity_index, i in entity_indices {
+ e := &entities[entity_index]
+ name := str(e.name)
+
+ if i > 0 {
+ io.write_string(w, ", ")
+ }
+ if .Param_Using in e.flags { io.write_string(w, "using ") }
+ if .Param_Const in e.flags { io.write_string(w, "#const ") }
+ if .Param_Auto_Cast in e.flags { io.write_string(w, "#auto_cast ") }
+ if .Param_CVararg in e.flags { io.write_string(w, "#c_vararg ") }
+ if .Param_No_Alias in e.flags { io.write_string(w, "#no_alias ") }
+ if .Param_Any_Int in e.flags { io.write_string(w, "#any_int ") }
+
+ if name != "" {
+ io.write_string(w, name)
+ io.write_string(w, ": ")
+ }
+ param_flags := flags - {.Is_Results}
+ if .Param_Ellipsis in e.flags {
+ param_flags += {.Variadic}
+ }
+ write_type(w, pkg, types[e.type], param_flags)
+ }
+ if require_parens { io.write_byte(w, ')') }
+
+ case .Proc:
+ type_flags := transmute(doc.Type_Flags_Proc)type.flags
+ io.write_string(w, "proc")
+ cc := str(type.calling_convention)
+ if cc != "" {
+ io.write_byte(w, ' ')
+ io.write_quoted_string(w, cc)
+ io.write_byte(w, ' ')
+ }
+ params := array(type.types)[0]
+ results := array(type.types)[1]
+ io.write_byte(w, '(')
+ write_type(w, pkg, types[params], flags)
+ io.write_byte(w, ')')
+ if results != 0 {
+ assert(.Diverging not_in type_flags)
+ io.write_string(w, " -> ")
+ write_type(w, pkg, types[results], flags+{.Is_Results})
+ }
+ if .Diverging in type_flags {
+ io.write_string(w, " -> !")
+ }
+ if .Optional_Ok in type_flags {
+ io.write_string(w, " #optional_ok")
+ }
+
+ case .Bit_Set:
+ type_flags := transmute(doc.Type_Flags_Bit_Set)type.flags
+ case .Simd_Vector:
+ io.write_string(w, "#simd[")
+ io.write_uint(w, uint(type.elem_counts[0]))
+ io.write_byte(w, ']')
+ case .SOA_Struct_Fixed:
+ io.write_string(w, "#soa[")
+ io.write_uint(w, uint(type.elem_counts[0]))
+ io.write_byte(w, ']')
+ case .SOA_Struct_Slice:
+ io.write_string(w, "#soa[]")
+ case .SOA_Struct_Dynamic:
+ io.write_string(w, "#soa[dynamic]")
+ case .Relative_Pointer:
+ io.write_string(w, "#relative(")
+ write_type(w, pkg, types[type_types[1]], flags)
+ io.write_string(w, ") ")
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Relative_Slice:
+ io.write_string(w, "#relative(")
+ write_type(w, pkg, types[type_types[1]], flags)
+ io.write_string(w, ") ")
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Multi_Pointer:
+ io.write_string(w, "[^]")
+ write_type(w, pkg, types[type_types[0]], flags)
+ case .Matrix:
+ io.write_string(w, "matrix[")
+ io.write_uint(w, uint(type.elem_counts[0]))
+ io.write_string(w, ", ")
+ io.write_uint(w, uint(type.elem_counts[1]))
+ io.write_string(w, "]")
+ write_type(w, pkg, types[type_types[0]], flags)
+ }
+}
+
+write_docs :: proc(w: io.Writer, pkg: ^doc.Pkg, docs: string) {
+ if docs == "" {
+ return
+ }
+ it := docs
+ was_code := true
+ was_paragraph := true
+ for line in strings.split_iterator(&it, "\n") {
+ if strings.has_prefix(line, "\t") {
+ if !was_code {
+ was_code = true;
+ fmt.wprint(w, ``, dir.dir)
+ } else {
+ fmt.wprintf(w, ` \n")
+
+ for child := dir.first_child; child != nil; child = child.next {
+ assert(child.pkg != nil)
+ fmt.wprintf(w, ``, dir.dir)
+ }
+
+ if dir.pkg != nil {
+ fmt.wprintf(w, `%s`, dir.path, dir.name)
+ } else {
+ fmt.wprintf(w, "%s", dir.name)
+ }
+ fmt.wprintf(w, " ")
+ if dir.pkg != nil {
+ line_doc, _, _ := strings.partition(str(dir.pkg.docs), "\n")
+ line_doc = strings.trim_space(line_doc)
+ if line_doc != "" {
+ fmt.wprintf(w, `%s `, line_doc)
+ }
+ }
+ fmt.wprintf(w, " \n")
+ }
+ }
+
+ fmt.wprintln(w, "\t\t")
+ fmt.wprintln(w, "\t`, str(child.pkg.name))
+ fmt.wprintf(w, `%s`, child.path, child.name)
+ fmt.wprintf(w, " ")
+
+ line_doc, _, _ := strings.partition(str(child.pkg.docs), "\n")
+ line_doc = strings.trim_space(line_doc)
+ if line_doc != "" {
+ fmt.wprintf(w, `%s `, line_doc)
+ }
+
+ fmt.wprintf(w, "
")
+ }
+ text := strings.trim_space(line)
+ if text == "" {
+ if was_paragraph {
+ was_paragraph = false
+ fmt.wprintln(w, "`)
+ }
+ fmt.wprintf(w, "%s\n", strings.trim_prefix(line, "\t"))
+ continue
+ } else if was_code {
+ was_code = false
+ fmt.wprintln(w, "
") + } + assert(!was_code) + was_paragraph = true + fmt.wprintln(w, text) + } + if was_code { + // assert(!was_paragraph, str(pkg.name)) + was_code = false + fmt.wprintln(w, "") + } else if was_paragraph { + fmt.wprintln(w, "
") + } +} + +write_pkg :: proc(w: io.Writer, path: string, pkg: ^doc.Pkg) { + fmt.wprintf(w, "")
+ fmt.wprintf(w, "%s :: ", name)
+ write_type(w, files[e.pos.file].pkg, types[e.type], nil)
+ where_clauses := array(e.where_clauses)
+ if len(where_clauses) != 0 {
+ io.write_string(w, " where ")
+ for clause, i in where_clauses {
+ if i > 0 {
+ io.write_string(w, ", ")
+ }
+ io.write_string(w, str(clause))
+ }
+ }
+
+ fmt.wprint(w, " {…}")
+ fmt.wprintln(w, "")
+ case .Proc_Group:
+ }
+
+ write_docs(w, pkg, strings.trim_space(str(e.docs)))
+ }
+ print_entities :: proc(w: io.Writer, title: string, entities: []^doc.Entity) {
+ fmt.wprintf(w, "