Compiler construction 使用libclang从字符串构造AST < >我生成了一些C++代码,并将其存储在字符串中,我想使用LIbCLANN从字符串中构造AST树。怎么做?我不想串入额外的文件。

Compiler construction 使用libclang从字符串构造AST < >我生成了一些C++代码,并将其存储在字符串中,我想使用LIbCLANN从字符串中构造AST树。怎么做?我不想串入额外的文件。,compiler-construction,llvm,clang,jit,libclang,Compiler Construction,Llvm,Clang,Jit,Libclang,您可以使用将内存缓冲区传递到libclang。您可以尝试以下代码: std::unique_ptr<ASTUnit> AST(tooling::buildASTFromCode("int x=10;x++;")); TranslationUnitDecl *DC = AST->getASTContext().getTranslationUnitDecl(); if (DC) { llvm::errs() << "---------dump begin----

您可以使用将内存缓冲区传递到libclang。

您可以尝试以下代码:

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);
}
std::unique_ptr AST(工具::buildASTFromCode(“intx=10;x++”);
TranslationUnitDecl*DC=AST->getASTContext().getTranslationUnitDecl();
国际单项体育联合会(DC){
llvm::errs()dump();
llvm::errs()