문제

I generate some c++ codes, and store it in string, I want to construct an AST tree from the string using libclang. How to do it? I don't want to string into extra files.

도움이 되었습니까?

해결책

You can use CXUnsavedFile to pass in-memory buffer to libclang.

다른 팁

you can try such as the next code:

std::unique_ptr<ASTUnit> AST(tooling::buildASTFromCode("int x=10;x++;"));
TranslationUnitDecl *DC = AST->getASTContext().getTranslationUnitDecl();
if (DC) {
    llvm::errs() << "---------dump begin----------\n";
    DC->dump();
    llvm::errs() << "---------dump end----------\n";
    visitor.TraverseDecl(DC);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top