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


C++ SourceManager::GetMessage方法代码示例

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


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

示例1: handleDiagnostic

void PrintingDiagnosticConsumer::handleDiagnostic(
    SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
    StringRef FormatString, ArrayRef<DiagnosticArgument> FormatArgs,
    const DiagnosticInfo &Info) {
  // Determine what kind of diagnostic we're emitting.
  llvm::SourceMgr::DiagKind SMKind;
  switch (Kind) {
    case DiagnosticKind::Error:
      SMKind = llvm::SourceMgr::DK_Error;
      break;
    case DiagnosticKind::Warning: 
      SMKind = llvm::SourceMgr::DK_Warning; 
      break;

    case DiagnosticKind::Note:
      SMKind = llvm::SourceMgr::DK_Note;
      break;

    case DiagnosticKind::Remark:
      SMKind = llvm::SourceMgr::DK_Remark;
      break;
  }

  if (Kind == DiagnosticKind::Error) {
    DidErrorOccur = true;
  }
  
  // Translate ranges.
  SmallVector<llvm::SMRange, 2> Ranges;
  for (auto R : Info.Ranges)
    Ranges.push_back(getRawRange(SM, R));

  // Translate fix-its.
  SmallVector<llvm::SMFixIt, 2> FixIts;
  for (DiagnosticInfo::FixIt F : Info.FixIts)
    FixIts.push_back(getRawFixIt(SM, F));

  // Display the diagnostic.
  ColoredStream coloredErrs{Stream};
  raw_ostream &out = ForceColors ? coloredErrs : Stream;
  const llvm::SourceMgr &rawSM = SM.getLLVMSourceMgr();
  
  // Actually substitute the diagnostic arguments into the diagnostic text.
  llvm::SmallString<256> Text;
  {
    llvm::raw_svector_ostream Out(Text);
    DiagnosticEngine::formatDiagnosticText(Out, FormatString, FormatArgs);
  }
  
  auto Msg = SM.GetMessage(Loc, SMKind, Text, Ranges, FixIts);
  rawSM.PrintMessage(out, Msg);
}
开发者ID:PiersonBro,项目名称:swift,代码行数:52,代码来源:PrintingDiagnosticConsumer.cpp

示例2: switch

void
PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM, SourceLoc Loc,
        DiagnosticKind Kind,
        StringRef Text,
        const DiagnosticInfo &Info) {
    // Determine what kind of diagnostic we're emitting.
    llvm::SourceMgr::DiagKind SMKind;
    switch (Kind) {
    case DiagnosticKind::Error:
        SMKind = llvm::SourceMgr::DK_Error;
        break;
    case DiagnosticKind::Warning:
        SMKind = llvm::SourceMgr::DK_Warning;
        break;

    case DiagnosticKind::Note:
        SMKind = llvm::SourceMgr::DK_Note;
        break;
    }

    if (Kind == DiagnosticKind::Error) {
        DidErrorOccur = true;
    }

    // Translate ranges.
    SmallVector<llvm::SMRange, 2> Ranges;
    for (auto R : Info.Ranges)
        Ranges.push_back(getRawRange(SM, R));

    // Translate fix-its.
    SmallVector<llvm::SMFixIt, 2> FixIts;
    for (DiagnosticInfo::FixIt F : Info.FixIts)
        FixIts.push_back(getRawFixIt(SM, F));

    // Display the diagnostic.
    ColoredStream coloredErrs{Stream};
    raw_ostream &out = ForceColors ? coloredErrs : Stream;
    const llvm::SourceMgr &rawSM = SM.getLLVMSourceMgr();
    auto Msg = SM.GetMessage(Loc, SMKind, Text, Ranges, FixIts);
    rawSM.PrintMessage(out, Msg);
}
开发者ID:fengweijp,项目名称:swift,代码行数:41,代码来源:PrintingDiagnosticConsumer.cpp


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