Skip to content

Migrate to the prototype visitor API - #1

Draft
liamappelbe wants to merge 1 commit into
mainfrom
ffigen_visitor_api_migration
Draft

Migrate to the prototype visitor API#1
liamappelbe wants to merge 1 commit into
mainfrom
ffigen_visitor_api_migration

Conversation

@liamappelbe

Copy link
Copy Markdown
Owner


const Sqlite3Visitor([this.nameFilter]);

bool _matches(String name) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't provide any other values right? Would it make sense to inline everything inside the visitor class so that everything is in one place?

@@ -3,96 +3,96 @@

// dart format off
const usedSqliteSymbols = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the definition order change with a newer ffigen version?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I started aggressively sorting AST elements to make the generation more deterministic across machines. That would probably explain this diff.


@ffi.Native<ffi.Pointer<sqlite3_char>>()
external ffi.Pointer<sqlite3_char> sqlite3_temp_directory;
@ffi.Native<

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these only reorderings? I see we added more than we removed? Is there something we can't quite capture with the new API?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear. I searched for a few of these functions that look added, but all the ones I checked have just been moved. If there are any added symbols that's a bug. We should be able to make the new API behave the same. Maybe gemini can write me an analyzer script to list all the symbols defined in a file.

@override
void visitFunc(Func node) {
if (node.originalName.startsWith('pkg_sqlite3_connection_pool')) {
node.isExcluded = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be a double-negative? Or could this be node.isIncluded = true?

Comment on lines +30 to +34
if (_structNames.contains(node.originalName)) {
node.isExcluded = false;
} else {
node.isExcluded = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just be:

Suggested change
if (_structNames.contains(node.originalName)) {
node.isExcluded = false;
} else {
node.isExcluded = true;
}
node.IsExcluded = !_structNames.contains(node.originalName);

But removing the double negative would make this easier to reason about.

Logger.root.onRecord.listen(print);

final generator = FfiGenerator(
visitors: const [Sqlite3ConnectionPoolVisitor()],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcharkes mentioned this in another place, it is a little unfortunate that configuration is now spread out across two places. Since we don't have anonoumous classes, I like his suggestion of using some sort of base class where you define the visitor callbacks as argument in its constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants