ClassDeclarationSyntax PortClass(CXCursor cursor) { if (cursor.kind != CXCursorKind.CXCursor_ObjCImplementationDecl) throw new ArgumentException (); ImplContext = new ObjCImplementationDeclContext (cursor); TypePorter = new ObjCTypePorter (ImplContext.ClassName); ClassDeclarationSyntax classDecl = SF.ClassDeclaration (ImplContext.ClassName); classDecl = classDecl.AddModifiers (SF.Token (SyntaxKind.PublicKeyword)); classDecl = classDecl.AddBaseListTypes (SF.SimpleBaseType (SF.ParseTypeName(ImplContext.SuperClassName))); var propDecls = ImplContext.DeclCursor.GetChildren ().Where (c => c.kind == CXCursorKind.CXCursor_ObjCPropertyDecl); foreach (var pDecl in propDecls) classDecl = classDecl.AddMembers (CreatePropertyFromPropertyDecl (pDecl)); var unrecognized = new List<CXCursor> (); IEnumerable<CXCursor> children = cursor.GetChildren (); foreach (var m in children) { if (m.kind == CXCursorKind.CXCursor_ObjCInstanceMethodDecl || m.kind == CXCursorKind.CXCursor_ObjCClassMethodDecl) classDecl = classDecl.AddMembers(PortMethod (m)); else unrecognized.Add (m); } // TODO: warn about unrecognized cursors return classDecl; }
ClassDeclarationSyntax PortCategory(CXCursor cursor) { if (cursor.kind != CXCursorKind.CXCursor_ObjCCategoryImplDecl) throw new ArgumentException (); CategoryImplContext = new ObjCCategoryImplDeclContext (cursor); TypePorter = new ObjCTypePorter (CategoryImplContext.ExtendedClassName); string className = string.Format ("{0}{1}Extensions", CategoryImplContext.ExtendedClassName, CategoryImplContext.CategoryName); ClassDeclarationSyntax classDecl = SF.ClassDeclaration (className); classDecl = classDecl.AddModifiers (SF.Token (SyntaxKind.PublicKeyword), SF.Token (SyntaxKind.StaticKeyword)); var unrecognized = new List<CXCursor> (); IEnumerable<CXCursor> children = cursor.GetChildren (); foreach (var m in children) { if (m.kind == CXCursorKind.CXCursor_ObjCInstanceMethodDecl || m.kind == CXCursorKind.CXCursor_ObjCClassMethodDecl) classDecl = classDecl.AddMembers(PortCategoryMethod (m)); else unrecognized.Add (m); } // TODO: warn about unrecognized cursors return classDecl; }