Skip to content

Commit

Permalink
add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfouilleul committed May 29, 2024
1 parent 75d4dec commit eb4ca30
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 61 deletions.
40 changes: 27 additions & 13 deletions scripts/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def gen_type(typeSpec, typeName, indent):
s += "[" + str(typeSpec["count"]) + "]"
elif typeKind == "namedType":
s += typeSpec["name"]
elif typeKind == "proc":
s += gen_type(typeSpec["return"], None, 0)
if typeName != None:
s += f" (*{typeName})"
s += "("
s += gen_param_list(typeSpec)
s += ")"
else:
s += typeKind

Expand All @@ -137,8 +144,20 @@ def gen_typename(spec):
s = f"typedef "
s += gen_type(typeSpec, typeName, 0)

s += f" {typeName};\n"
if typeSpec["kind"] != "proc":
s += f" {typeName};"
s += "\n"

return s

def gen_param_list(spec):
s = "("
for i, param in enumerate(spec["params"]):
s += gen_type(param["type"], None, 0)
s += " " + param["name"]
if i != len(spec["params"])-1:
s += ", "
s += ")"
return s

def gen_proc(spec):
Expand All @@ -150,13 +169,8 @@ def gen_proc(spec):
s += gen_type(spec["return"], None, 0)
s += " "
s += spec["name"]
s += "("
for i, param in enumerate(spec["params"]):
s += gen_type(param["type"], None, 0)
s += " " + param["name"]
if i != len(spec["params"])-1:
s += ", "
s += ");\n"
s += gen_param_list(spec)
s += ";\n"

return s

Expand Down Expand Up @@ -219,7 +233,7 @@ def doc_type(desc):
s += "```\n"
s += "typedef "
s += gen_type(desc["type"], name, 0)
if name != "":
if name != "" and desc["type"]["kind"] != "proc":
s += f" {name};"
else:
s += ";"
Expand Down Expand Up @@ -450,7 +464,7 @@ def doc_module(outDir, module, dump):

ok = True
if ok and len(modules):
s += "### Modules\n\n"
s += "## Modules\n\n"
subDir = os.path.join(outDir, make_dir_name(moduleName))

for subModule in modules:
Expand All @@ -466,22 +480,22 @@ def doc_module(outDir, module, dump):
s += "\n---\n\n"

if ok and len(types):
s += "### Types\n\n"
s += "## Types\n\n"
for e in types:
if not find_entry_match(e, dump):
ok = False
break
s += doc_type(e)

if ok and len(macros):
s += "### Macros\n\n"
s += "## Macros\n\n"
for e in macros:
#if not find_entry_match(e, dump):
# return ("", False)
s += doc_macro(e)

if ok and len(procs):
s += "### Functions\n\n"
s += "## Functions\n\n"
for e in procs:
if not find_entry_match(e, dump):
ok = False
Expand Down
Loading

0 comments on commit eb4ca30

Please sign in to comment.