[cfe-dev] Loading a saved ObjC Index file with clang_createTranslationUnit
Alexey
soniccat at list.ru
Thu Jan 24 10:56:16 PST 2013
I have:
clang version 3.3 (trunk 171404)
Target: i386-apple-darwin12.2.0
Thread model: posix
I want to load an Objective-C file and save its index on a disk to be able to
load it again. I loaded the saved version of the index file and have a assertion
fail check when visiting childs.
In more detail:
To load ViewUtils.m I use this commands:
CXIndex Index = clang_createIndex(0, 1);
CXTranslationUnit TU;
TU = clang_parseTranslationUnit(Index, NULL, argv, argc, 0, 0,
CXTranslationUnit_ForSerialization);
and this arguments:
-x objective-c -arch i386 -I/usr/bin/../lib/clang/4.0/include
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms
/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -
mios-simulator-version-min=4.0 ViewUtils.m -v
Then I visit all childs:
CXCursor cursor = clang_getTranslationUnitCursor(TU);
clang_visitChildren(cursor, visitFunc, 0);
where visitFunc doesn't do any special
CXChildVisitResult visitFunc(CXCursor cursor,
CXCursor parent,
CXClientData client_data)
{
return CXChildVisit_Recurse;
}
then I save the file without error and dispose resources:
int code = clang_saveTranslationUnit(TU, "tuOut.txt",
clang_defaultSaveOptions(TU));
cout << "clang_saveTranslationUnit code " << code << endl;
clang_disposeTranslationUnit(TU);
clang_disposeIndex(Index);
When I want to load "tuOut.txt" I call:
CXTranslationUnit TU;
TU = clang_createTranslationUnit(Index, "tuOut.txt");
it finished, but when I run:
CXCursor cursor = clang_getTranslationUnitCursor(TU);
clang_visitChildren(cursor, visitFunc, 0);
I have:
Assertion failed: (S && TU && "Invalid arguments!"),
function MakeCXCursor, file /Users/
alexeyglushkov/iPhoneProjects/llvm/tools/
clang/tools/libclang/CXCursor.cpp, line 94.
What does it mean? And how can I use loaded index file without asserions?
More information about the cfe-dev
mailing list