Skip to content

Commit e3f92d5

Browse files
committed
Added support for determining if a function is callable. (IE: Its return and parameter types are all complete.)
1 parent 51aad86 commit e3f92d5

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

ClangSharp.Pathogen/ClangSharpExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ClangSharp.Interop;
22
using System;
3+
using System.Collections.Immutable;
34
using System.Runtime.InteropServices;
45
using System.Text;
56

@@ -99,5 +100,33 @@ public static unsafe string GetSpellingWithPlaceholder(this CXType type, string
99100

100101
public static string GetSpellingWithPlaceholder(this Type type, string placeholder)
101102
=> GetSpellingWithPlaceholder(type.Handle, placeholder);
103+
104+
private unsafe static bool IsCallableImplementation(CXStringSet* diagnosticsSet, out ImmutableArray<string> diagnostics)
105+
{
106+
if (diagnosticsSet == null)
107+
{
108+
diagnostics = ImmutableArray<string>.Empty;
109+
return true;
110+
}
111+
112+
try
113+
{
114+
ImmutableArray<string>.Builder diagnosticsBuilder = ImmutableArray.CreateBuilder<string>((int)diagnosticsSet->Count);
115+
116+
for (uint i = 0; i < diagnosticsSet->Count; i++)
117+
{ diagnosticsBuilder.Add(diagnosticsSet->Strings[i].ToString()); }
118+
119+
diagnostics = diagnosticsBuilder.MoveToImmutable();
120+
return false;
121+
}
122+
finally
123+
{ diagnosticsSet->Dispose(); }
124+
}
125+
126+
public unsafe static bool IsCallable(this FunctionDecl function, out ImmutableArray<string> diagnostics)
127+
=> IsCallableImplementation(PathogenExtensions.pathogen_IsFunctionCallable(function.Handle), out diagnostics);
128+
129+
public unsafe static bool IsComplete(this FunctionProtoType functionType, out ImmutableArray<string> diagnostics)
130+
=> IsCallableImplementation(PathogenExtensions.pathogen_IsFunctionTypeCallable(functionType.Handle), out diagnostics);
102131
}
103132
}

ClangSharp.Pathogen/PathogenExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,11 @@ public static extern unsafe void pathogen_EnumerateAllSpecializedClassTemplates
149149

150150
[DllImport(LibraryFileName, ExactSpelling = true)]
151151
internal unsafe static extern void pathogen_DisposeArrangedFunction(PathogenArrangedFunction.RawArrangedFunction* function);
152+
153+
[DllImport(LibraryFileName, ExactSpelling = true)]
154+
public unsafe static extern CXStringSet* pathogen_IsFunctionCallable(CXCursor cursor);
155+
156+
[DllImport(LibraryFileName, ExactSpelling = true)]
157+
public unsafe static extern CXStringSet* pathogen_IsFunctionTypeCallable(CXType type);
152158
}
153159
}

external/llvm-project

0 commit comments

Comments
 (0)