Skip to content

Commit 84e5f96

Browse files
Merge pull request #264 from PathogenDavid/fix-clangsharp_Cursor_getDefinition
Fix clangsharp_Cursor_getDefinition not handling declarations with no definition
2 parents 2ce66e8 + 1a2f53c commit 84e5f96

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

sources/libClangSharp/ClangSharp.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,29 +1032,26 @@ CXType clangsharp_Cursor_getDefaultArgType(CXCursor C) {
10321032
CXCursor clangsharp_Cursor_getDefinition(CXCursor C) {
10331033
if (isDeclOrTU(C.kind)) {
10341034
const Decl* D = getCursorDecl(C);
1035+
const Decl* DD = nullptr;
10351036

10361037
if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
1037-
return MakeCXCursor(FD->getDefinition(), getCursorTU(C));
1038-
}
1039-
1040-
if (const ObjCInterfaceDecl* OCID = dyn_cast<ObjCInterfaceDecl>(D)) {
1041-
return MakeCXCursor(OCID->getDefinition(), getCursorTU(C));
1042-
}
1043-
1044-
if (const ObjCProtocolDecl* OCPD = dyn_cast<ObjCProtocolDecl>(D)) {
1045-
return MakeCXCursor(OCPD->getDefinition(), getCursorTU(C));
1046-
}
1047-
1048-
if (const TagDecl* TD = dyn_cast<TagDecl>(D)) {
1049-
return MakeCXCursor(TD->getDefinition(), getCursorTU(C));
1050-
}
1051-
1052-
if (const VarDecl* VD = dyn_cast<VarDecl>(D)) {
1053-
return MakeCXCursor(VD->getDefinition(), getCursorTU(C));
1054-
}
1038+
DD = FD->getDefinition();
1039+
} else if (const ObjCInterfaceDecl* OCID = dyn_cast<ObjCInterfaceDecl>(D)) {
1040+
DD = OCID->getDefinition();
1041+
} else if (const ObjCProtocolDecl* OCPD = dyn_cast<ObjCProtocolDecl>(D)) {
1042+
DD = OCPD->getDefinition();
1043+
} else if (const TagDecl* TD = dyn_cast<TagDecl>(D)) {
1044+
DD = TD->getDefinition();
1045+
} else if (const VarDecl* VD = dyn_cast<VarDecl>(D)) {
1046+
DD = VD->getDefinition();
1047+
} else {
1048+
return clang_getCursorDefinition(C);
1049+
}
1050+
1051+
return DD ? MakeCXCursor(DD, getCursorTU(C)) : clang_getNullCursor();
1052+
} else {
1053+
return clang_getCursorDefinition(C);
10551054
}
1056-
1057-
return clang_getCursorDefinition(C);
10581055
}
10591056

10601057
CXCursor clangsharp_Cursor_getDependentLambdaCallOperator(CXCursor C) {

0 commit comments

Comments
 (0)