【问题标题】:How do I get AST as string using libclang?如何使用 libclang 将 AST 作为字符串?
【发布时间】:2021-11-10 04:45:17
【问题描述】:

我需要使用 libclang 横向 AST。 我找到的所有解决方案都告诉我将 AST 转储到 .ast 文件中,然后使用该文件创建 translationUnit 以进行横向处理。

如果能够做到以下几点就太好了: 以编程方式为某些代码生成 AST,然后使用 CXUnsavedFile 来创建 translationUnit

【问题讨论】:

    标签: compiler-construction clang libclang


    【解决方案1】:

    为了避免依赖转储在文件中的 AST, clang_parseTranslationUnit 可以如下使用

    CXTranslationUnit unit = clang_parseTranslationUnit(
    CXIndex index,
    "path to file with code", nullptr, 0,
    nullptr, 0,
    CXTranslationUnit_None);
    

    【讨论】:

      猜你喜欢
      • 2013-05-05
      • 2019-03-11
      • 2021-11-30
      • 1970-01-01
      • 2011-06-16
      • 2016-09-13
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多