【问题标题】:Flushing AST CDT冲洗 AST CDT
【发布时间】:2018-10-14 11:11:13
【问题描述】:

我通过 ASTRewrite 对 AST 进行了一些更改,并通过 Change.perform 应用了更改,C 文件已正确更新为新更改(插入新节点),但在调试模式下,AST 对象感觉不到这些更改

    ast.getRawSignature(); // C file code as text
    ASTRewrite rewriter = ASTRewrite.create(ast);
    addNewNode(node, ast, rewriter); //Inserting some node
    Change c = rewriter.rewriteAST();
            try {
                c.perform(new NullProgressMonitor());
            } catch (CoreException e) {
                e.printStackTrace();
            }
    /**WHAT I WANT TO FLUSH THE AST HERE TO FEEL THE CHANGES**/
    ast.getRawSignature(); //it still the same C old code and the C file already updated

我需要刷新 AST 以感受 AST 对象本身的变化,我该如何实现?

【问题讨论】:

    标签: eclipse-cdt abstract-syntax-tree flush


    【解决方案1】:

    在最初构造 AST 之后,它不再是可变的(在其上调用IASTTranslationUnit.freeze(),并且任何进一步尝试在该 AST 中的节点上调用 setter 都将失败)。

    这意味着Change.perform() 不能对 AST 进行更改,只能对文件进行更改。要获得反映更改的 AST,您需要构建一个新的。

    【讨论】:

    • 这就是我在提供的代码中所做的,更改出现在它自己的文件中,而不是 ast 对象中
    • @MostafaHassan:我的错,我忽略了这一点。请查看我编辑的答案。
    • 在提交这个问题之前我已经完成的构建新的 AST,只是想确保我在思考正确的方向。谢谢@HighCommander4
    猜你喜欢
    • 2011-11-10
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 2012-06-19
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多