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/CXCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,8 @@ public readonly ReadOnlySpan<CXCursor> OverriddenCursors

public readonly CXPrintingPolicy PrintingPolicy => (kind != default) ? (CXPrintingPolicy)clang.getCursorPrintingPolicy(this) : default;

public readonly CXString QualifiedName => clangsharp.Cursor_getQualifiedName(this);

public readonly CXString RawCommentText => clang.Cursor_getRawCommentText(this);

public readonly CXType ReceiverType => !IsExpression ? default : clang.Cursor_getReceiverType(this);
Expand Down
3 changes: 3 additions & 0 deletions sources/ClangSharp.Interop/clangsharp/clangsharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,9 @@ public static unsafe partial class @clangsharp
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getProtocol", ExactSpelling = true)]
public static extern CXCursor Cursor_getProtocol(CXCursor C, [NativeTypeName("unsigned int")] uint i);

[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getQualifiedName", ExactSpelling = true)]
public static extern CXString Cursor_getQualifiedName(CXCursor C);

[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getRedeclContext", ExactSpelling = true)]
public static extern CXCursor Cursor_getRedeclContext(CXCursor C);

Expand Down
2 changes: 2 additions & 0 deletions sources/ClangSharp/Cursors/Decls/NamedDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private protected NamedDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX

public string Name => Spelling;

public string QualifiedName => Handle.QualifiedName.ToString();

public NamedDecl UnderlyingDecl => _underlyingDecl.Value;

public CXVisibilityKind Visibility => Handle.Visibility;
Expand Down
12 changes: 12 additions & 0 deletions sources/libClangSharp/ClangSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,18 @@ CXCursor clangsharp_Cursor_getProtocol(CXCursor C, unsigned i) {
return clang_getNullCursor();
}

CXString clangsharp_Cursor_getQualifiedName(CXCursor C) {
if (isDeclOrTU(C.kind)) {
const Decl* D = getCursorDecl(C);

if (const NamedDecl* ND = dyn_cast<NamedDecl>(D)) {
return createDup(ND->getQualifiedNameAsString());
}
}

return createEmpty();
}

CXCursor clangsharp_Cursor_getRedeclContext(CXCursor C) {
if (isDeclOrTU(C.kind)) {
const Decl* D = getCursorDecl(C);
Expand Down
2 changes: 2 additions & 0 deletions sources/libClangSharp/ClangSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getPropertyAttributes(CXCursor C);

CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getProtocol(CXCursor C, unsigned i);

CLANGSHARP_LINKAGE CXString clangsharp_Cursor_getQualifiedName(CXCursor C);

CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getRedeclContext(CXCursor C);

CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getReferenced(CXCursor C);
Expand Down
33 changes: 33 additions & 0 deletions tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,39 @@ struct B {
Assert.That(structB.IsPOD, Is.False, "struct B should be not POD");
}


[Test]
public void QualifiedNameTest()
{
AssertNeedNewClangSharp();

var inputContents = """
class C {
void M();
int F;
};

struct S {
void M();
int F;
};
""";

using var translationUnit = CreateTranslationUnit(inputContents);

var records = translationUnit.TranslationUnitDecl.Decls.OfType<CXXRecordDecl>().ToArray();
var classDecl = records.Single(v => v.Name == "C");
var structDecl = records.Single(v => v.Name == "S");
var classM = classDecl.Decls.OfType<FunctionDecl>().Single();
var structM = structDecl.Decls.OfType<FunctionDecl>().Single();

Assert.That(classDecl.QualifiedName, Is.EqualTo("C"), "Class");
Assert.That(classM.QualifiedName, Is.EqualTo("C::M"), "Class Method");

Assert.That(structDecl.QualifiedName, Is.EqualTo("S"), "Struct");
Assert.That(structM.QualifiedName, Is.EqualTo("S::M"), "Struct Method");
}

[Test]
public void UnsignedValue()
{
Expand Down