当前位置: 首页>>代码示例>>C++>>正文


C++ DiagnosticManager::Diagnostics方法代码示例

本文整理汇总了C++中DiagnosticManager::Diagnostics方法的典型用法代码示例。如果您正苦于以下问题:C++ DiagnosticManager::Diagnostics方法的具体用法?C++ DiagnosticManager::Diagnostics怎么用?C++ DiagnosticManager::Diagnostics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DiagnosticManager的用法示例。


在下文中一共展示了DiagnosticManager::Diagnostics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rewriter

bool
ClangExpressionParser::RewriteExpression(DiagnosticManager &diagnostic_manager)
{
    clang::SourceManager &source_manager = m_compiler->getSourceManager();
    clang::edit::EditedSource editor(source_manager, m_compiler->getLangOpts(), nullptr);
    clang::edit::Commit commit(editor);
    clang::Rewriter rewriter(source_manager, m_compiler->getLangOpts());
    
    class RewritesReceiver : public edit::EditsReceiver {
      Rewriter &rewrite;

    public:
      RewritesReceiver(Rewriter &in_rewrite) : rewrite(in_rewrite) { }

      void insert(SourceLocation loc, StringRef text) override {
        rewrite.InsertText(loc, text);
      }
      void replace(CharSourceRange range, StringRef text) override {
        rewrite.ReplaceText(range.getBegin(), rewrite.getRangeSize(range), text);
      }
    };
    
    RewritesReceiver rewrites_receiver(rewriter);
    
    const DiagnosticList &diagnostics = diagnostic_manager.Diagnostics();
    size_t num_diags = diagnostics.size();
    if (num_diags == 0)
        return false;
    
    for (const Diagnostic *diag : diagnostic_manager.Diagnostics())
    {
        const ClangDiagnostic *diagnostic = llvm::dyn_cast<ClangDiagnostic>(diag);
        if (diagnostic && diagnostic->HasFixIts())
        {
             for (const FixItHint &fixit : diagnostic->FixIts())
             {
                // This is cobbed from clang::Rewrite::FixItRewriter.
                if (fixit.CodeToInsert.empty())
                {
                  if (fixit.InsertFromRange.isValid())
                  {
                      commit.insertFromRange(fixit.RemoveRange.getBegin(),
                                             fixit.InsertFromRange, /*afterToken=*/false,
                                             fixit.BeforePreviousInsertions);
                  }
                  else
                    commit.remove(fixit.RemoveRange);
                }
                else
                {
                  if (fixit.RemoveRange.isTokenRange() ||
                      fixit.RemoveRange.getBegin() != fixit.RemoveRange.getEnd())
                    commit.replace(fixit.RemoveRange, fixit.CodeToInsert);
                  else
                    commit.insert(fixit.RemoveRange.getBegin(), fixit.CodeToInsert,
                                /*afterToken=*/false, fixit.BeforePreviousInsertions);
                }
            }
        }
    }
    
    // FIXME - do we want to try to propagate specific errors here?
    if (!commit.isCommitable())
        return false;
    else if (!editor.commit(commit))
        return false;
    
    // Now play all the edits, and stash the result in the diagnostic manager.
    editor.applyRewrites(rewrites_receiver);
    RewriteBuffer &main_file_buffer = rewriter.getEditBuffer(source_manager.getMainFileID());

    std::string fixed_expression;
    llvm::raw_string_ostream out_stream(fixed_expression);
    
    main_file_buffer.write(out_stream);
    out_stream.flush();
    diagnostic_manager.SetFixedExpression(fixed_expression);
    
    return true;
}
开发者ID:Aj0Ay,项目名称:lldb,代码行数:80,代码来源:ClangExpressionParser.cpp


注:本文中的DiagnosticManager::Diagnostics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。