Skip to content

Commit

Permalink
fix: add C comments to bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Bühler committed Jun 25, 2024
1 parent a578960 commit 63723de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 29 additions & 4 deletions ast-mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@
for p in func.get("inner", [])
if p.get("kind") == "ParmVarDecl" and p.get("name") is not None
],
[
"\n".join(
[
text.get("text", "")
for text in para.get("inner", [])
if text.get("kind") == "TextComment"
]
)
for para in (
next(
(
c.get("inner", [])
for c in func.get("inner", [])
if c.get("kind") == "FullComment"
),
[],
)
)
],
)
for func in ast["inner"]
if func["kind"] == "FunctionDecl"
Expand All @@ -55,15 +74,21 @@
out.write(prelim_header)
for file, funcs in functions.items():
out.write(f'#include "pdfium/{file}"\n')
for name, type, params in funcs:
out.write(
f"FFI_PLUGIN_EXPORT {type} PDFIUM_{name}({','.join(map(lambda p : f"{p[1]} {p[0]}", params))});\n"
for name, type, params, comment in funcs:
out.writelines(
[
"".join(
"".join(map(lambda i: f"// {i}\n", line))
for line in (c.split("\n") for c in comment)
),
f"FFI_PLUGIN_EXPORT {type} PDFIUM_{name}({','.join(map(lambda p : f"{p[1]} {p[0]}", params))});\n",
]
)

with open(os.path.join("./", "src", "flutter_pdfium.c"), "w") as out:
out.write(prelim_impl)
for file, funcs in functions.items():
for name, type, params in funcs:
for name, type, params, _ in funcs:
out.writelines(
[
f"FFI_PLUGIN_EXPORT {type} PDFIUM_{name}({','.join(map(lambda p : f"{p[1]} {p[0]}", params))}){{\n",
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version := "6276"
mkdir -p ./.tmp/ast
for header in $(find ./.tmp/release/include -name "*.h" -maxdepth 1 -type f); do
echo "Create AST for $header"
clang -Xclang -ast-dump=json -fsyntax-only $header > ./.tmp/ast/$(basename $header).json
clang -Xclang -ast-dump=json -fsyntax-only -fparse-all-comments $header > ./.tmp/ast/$(basename $header).json
done

@create-mapping:
Expand Down

0 comments on commit 63723de

Please sign in to comment.