[cfe-dev] How to get source text after preprocessing
Vladimir
VladimirPlyashkun at yandex.ru
Fri Feb 14 11:57:35 PST 2014
Hello, everyone. I have some trouble. Earlier i'm using Lexer module to
getting source text. This sample code works fine, if my source file doesnt
have any #include directive:
clang::SourceLocation b(d->getLocStart()), _e(d->getLocEnd());
clang::SourceLocation e(clang::Lexer::getLocForEndOfToken(_e, 0, *sm,
lopt));
return std::string(sm->getCharacterData(b),
sm->getCharacterData(e)-sm->getCharacterData(b));
But when i'm trying to get some location on file(which have some includes)
this code always returns trash. For example, attempt to get source filename
'sourceManager->getFilename(location)' returns null string.
Moreover, above code also returns incorrect values. I know that this fact
caused by preprocessor macroses and different files, but i dont know correct
way to get source text of AST (which represent preprocessed file). Do you
have any ideas?
--
View this message in context: http://clang-developers.42468.n3.nabble.com/How-to-get-source-text-after-preprocessing-tp4037854.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list