This is my first real deep dive into the clang guts, so I am submitting this patch to the dev list rather than commits so that it can get extra reviewing and critiquing.
Cursors created from translation unit declarations will now be of kind CXCursor_TranslationUnit rather than the default CXCursor_UnexposedDecl
Cursor created by clang_getTranslationUnitCursor is now created with MakeCXCursor and includes the translation unit decl. This ensures that the cursor returned by clang_getTranslationUnitCursor and clang_getCursorLexicalParent in the case of a translation unit compare correctly via clang_equalCursors. The code to fetch the translation decl is based on code inside CursorVisitor::VisitChildren.
I did not add any additional tests for this, but did re-run the current test suite. If someone could point me toward the best place to add said tests I would be happy to create some.
clang_lexical_parent.diff (1.05 KB)