V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
badboy
V2EX  ›  问与答

一个关于使用eclipse cdt插件的调用语法分析功能的问题

  •  
  •   badboy · Jul 23, 2013 · 3621 views
    This topic created in 4661 days ago, the information mentioned may be changed or developed.
    最近在做一个C++的代码相似检测,需要用到语法分析,想用eclipse的这个cdt插件实现,以下是网上给出的代码,我想请问下
    (1) IFile 是个什么东东?如何使用?C++源代码怎么转化成IFile类型
    (2) 最后return的ast变量要怎么使用?
    (3) index是什么?怎么使用?
    (4) 这段代码处理完后生成的语法分析树,怎么转化为纯文本供后面代码使用?
    谢谢

    public static IASTTranslationUnit getAST( IFile file) {
    ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);
    ICProject project= tu.getCProject();
    IASTTranslationUnit ast=null;
    try {
    IIndex index = CCorePlugin.getIndexManager().getIndex(project,
    IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);

    index.acquireReadLock();
    try {

    ast=tu.getAST(index, 0);

    } finally {
    index.releaseReadLock();
    }

    } catch (InterruptedException e) {
    //log(e);
    } catch (CoreException e) {
    //log(e);
    }
    return ast;
    }
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4085 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 05:13 · PVG 13:13 · LAX 22:13 · JFK 01:13
    ♥ Do have faith in what you're doing.