Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sources/ClangSharp.Interop/Extensions/CXType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public unsafe partial struct CXType : IEquatable<CXType>

public readonly bool IsFunctionTypeVariadic => clang.isFunctionTypeVariadic(this) != 0;

public readonly bool IsObjCInstanceType => (kind != CXType_Invalid) && clangsharp.Type_getIsObjCInstanceType(this) != 0;

public readonly bool IsPODType => clang.isPODType(this) != 0;

public readonly bool IsRestrictQualified => clang.isRestrictQualifiedType(this) != 0;
Expand Down
4 changes: 4 additions & 0 deletions sources/ClangSharp.Interop/clangsharp/clangsharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ public static partial class @clangsharp
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getInjectedTST", ExactSpelling = true)]
public static extern CXType Type_getInjectedTST(CXType CT);

[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getIsObjCInstanceType", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")]
public static extern uint Type_getIsObjCInstanceType(CXType CT);

[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getIsSigned", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")]
public static extern uint Type_getIsSigned(CXType CT);
Expand Down
2 changes: 2 additions & 0 deletions sources/ClangSharp/Types/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public bool IsIntegralOrEnumerationType

public bool IsLocalConstQualified => Handle.IsConstQualified;

public bool IsObjCInstanceType => Handle.IsObjCInstanceType;

public bool IsObjCObjectPointerType => CanonicalType is ObjCObjectPointerType;

public bool IsPointerType => CanonicalType is PointerType;
Expand Down
7 changes: 7 additions & 0 deletions sources/libClangSharp/ClangSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5291,6 +5291,13 @@ CXType clangsharp_Type_getInjectedTST(CXType CT) {
return MakeCXType(QualType(), GetTypeTU(CT));
}

unsigned clangsharp_Type_getIsObjCInstanceType(CXType CT) {
QualType T = GetQualType(CT);
CXTranslationUnit tu = GetTypeTU(CT);
ASTContext& ctx = getASTUnit(tu)->getASTContext();
return ctx.getObjCInstanceType() == T;
}

unsigned clangsharp_Type_getIsSigned(CXType CT) {
QualType T = GetQualType(CT);
const Type* TP = T.getTypePtrOrNull();
Expand Down
2 changes: 2 additions & 0 deletions sources/libClangSharp/ClangSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ CLANGSHARP_LINKAGE CXType clangsharp_Type_getInjectedSpecializationType(CXType C

CLANGSHARP_LINKAGE CXType clangsharp_Type_getInjectedTST(CXType CT);

CLANGSHARP_LINKAGE unsigned clangsharp_Type_getIsObjCInstanceType(CXType CT);

CLANGSHARP_LINKAGE unsigned clangsharp_Type_getIsSigned(CXType CT);

CLANGSHARP_LINKAGE unsigned clangsharp_Type_getIsSugared(CXType CT);
Expand Down
28 changes: 28 additions & 0 deletions tests/ClangSharp.UnitTests/ObjectiveCTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ namespace ClangSharp.UnitTests;
[Platform("macosx")]
public sealed class ObjectiveCTest : TranslationUnitTest
{
[Test]
public void Type_IsObjCInstanceType()
{
AssertNeedNewClangSharp();

var inputContents = $@"
@interface MyClass
-(instancetype) instanceMethod;
+(MyClass*) staticMethod;
@end
";

using var translationUnit = CreateTranslationUnit(inputContents, "objective-c++");

var classes = translationUnit.TranslationUnitDecl.Decls.OfType<ObjCInterfaceDecl>().ToList();
Assert.That(classes.Count, Is.GreaterThanOrEqualTo(1), $"At least one class");
var myClass = classes.SingleOrDefault(v => v.Name == "MyClass")!;
Assert.That(myClass, Is.Not.Null, "MyClass");

var methodInstanceMethod = myClass.Methods.SingleOrDefault(v => v.Name == "instanceMethod")!;
Assert.That(methodInstanceMethod, Is.Not.Null, "methodInstanceMethod");
Assert.That(methodInstanceMethod.ReturnType.IsObjCInstanceType, Is.True, "methodInstanceMethod.ReturnType.IsObjCInstanceType");

var methodStaticMethod = myClass.Methods.SingleOrDefault(v => v.Name == "staticMethod")!;
Assert.That(methodStaticMethod, Is.Not.Null, "methodStaticMethod");
Assert.That(methodStaticMethod.ReturnType.IsObjCInstanceType, Is.False, "methodStaticMethod.ReturnType.IsObjCInstanceType");
}

[Test]
public void Method_Selector()
{
Expand Down