From 90de91d5d35883a621b72136e48defa32fab382a Mon Sep 17 00:00:00 2001 From: Steve Otteson Date: Tue, 23 Mar 2021 19:14:23 -0700 Subject: [PATCH] A couple fixes for the win32metadata project (#218) * Required fix for win32metadata project. * If we can't find an expression in the args of its parent, try looking at each arg to see if it's an implicit cast, and then check its expression for a match Avoid adding anonymous helper properties if the config option is set Co-authored-by: Steve Otteson --- .../PInvokeGenerator.VisitDecl.cs | 5 +++++ .../PInvokeGenerator.VisitStmt.cs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 64cb5ff3..1a05e9b3 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -310,6 +310,11 @@ private void VisitEnumConstantDecl(EnumConstantDecl enumConstantDecl) private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) { + if (_config.ExcludeAnonymousFieldHelpers) + { + return; + } + if (IsPrevContextDecl(out var prevContext) && prevContext.IsAnonymousStructOrUnion) { // We shouldn't process indirect fields where the prev context is an anonymous record decl diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index cbf374eb..8b11eae8 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -1635,6 +1635,21 @@ private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrT if (IsPrevContextStmt(out var callExpr)) { var index = callExpr.Args.IndexOf(unaryExprOrTypeTraitExpr); + + // If we didn't find the expression, try and find it under an implicit cast + if (index == -1) + { + for (int i = 0; i < callExpr.Args.Count; i++) + { + var arg = callExpr.Args[i]; + if (arg is ImplicitCastExpr implicitCastExpr && implicitCastExpr.SubExprAsWritten == unaryExprOrTypeTraitExpr) + { + index = i; + break; + } + } + } + var calleeDecl = callExpr.CalleeDecl; if (calleeDecl is FunctionDecl functionDecl)