Skip to content

Commit

Permalink
[ffigen] Fix ObjC @Class declarations (dart-lang#352)
Browse files Browse the repository at this point in the history
* WIP: NSData bug repro

* Fix forward declaration bug

* Remove unused clang_isDeclaration function

* Format
  • Loading branch information
liamappelbe authored May 11, 2022
1 parent f22e746 commit 60883c9
Show file tree
Hide file tree
Showing 8 changed files with 1,593 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Type? parseObjCInterfaceDeclaration(

void fillObjCInterfaceMethodsIfNeeded(
ObjCInterface itf, clang_types.CXCursor cursor) {
if (_isClassDeclaration(cursor)) {
// @class declarations are ObjC's way of forward declaring classes. In that
// case there's nothing to fill yet.
return;
}

if (itf.filled) return;
itf.filled = true; // Break cycles.

Expand All @@ -75,6 +81,27 @@ void fillObjCInterfaceMethodsIfNeeded(
'Name: ${itf.originalName}, ${cursor.completeStringRepr()}');
}

bool _isClassDeclarationResult = false;
bool _isClassDeclaration(clang_types.CXCursor cursor) {
// It's a class declaration if it has no children other than ObjCClassRef.
_isClassDeclarationResult = true;
clang.clang_visitChildren(
cursor,
Pointer.fromFunction(
_isClassDeclarationVisitor, exceptional_visitor_return),
nullptr);
return _isClassDeclarationResult;
}

int _isClassDeclarationVisitor(clang_types.CXCursor cursor,
clang_types.CXCursor parent, Pointer<Void> clientData) {
if (cursor.kind == clang_types.CXCursorKind.CXCursor_ObjCClassRef) {
return clang_types.CXChildVisitResult.CXChildVisit_Continue;
}
_isClassDeclarationResult = false;
return clang_types.CXChildVisitResult.CXChildVisit_Break;
}

int _parseInterfaceVisitor(clang_types.CXCursor cursor,
clang_types.CXCursor parent, Pointer<Void> clientData) {
switch (cursor.kind) {
Expand Down
Loading

0 comments on commit 60883c9

Please sign in to comment.