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


C++ MemoryBuffer::getBufferIdentifier方法代码示例

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


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

示例1: GetMessage

/// GetMessage - Return an SMDiagnostic at the specified location with the
/// specified string.
///
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
                                   const Twine &Msg,
                                   ArrayRef<SMRange> Ranges) const {

  // First thing to do: find the current buffer containing the specified
  // location.
  int CurBuf = FindBufferContainingLoc(Loc);
  assert(CurBuf != -1 && "Invalid or unspecified location!");

  MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;

  // Scan backward to find the start of the line.
  const char *LineStart = Loc.getPointer();
  while (LineStart != CurMB->getBufferStart() &&
         LineStart[-1] != '\n' && LineStart[-1] != '\r')
    --LineStart;

  // Get the end of the line.
  const char *LineEnd = Loc.getPointer();
  while (LineEnd != CurMB->getBufferEnd() &&
         LineEnd[0] != '\n' && LineEnd[0] != '\r')
    ++LineEnd;
  std::string LineStr(LineStart, LineEnd);

  // Convert any ranges to column ranges that only intersect the line of the
  // location.
  SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
  for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
    SMRange R = Ranges[i];
    if (!R.isValid()) continue;
    
    // If the line doesn't contain any part of the range, then ignore it.
    if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
      continue;
   
    // Ignore pieces of the range that go onto other lines.
    if (R.Start.getPointer() < LineStart)
      R.Start = SMLoc::getFromPointer(LineStart);
    if (R.End.getPointer() > LineEnd)
      R.End = SMLoc::getFromPointer(LineEnd);
    
    // Translate from SMLoc ranges to column ranges.
    ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
                                       R.End.getPointer()-LineStart));
  }
  
  return SMDiagnostic(*this, Loc,
                      CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
                      Loc.getPointer()-LineStart, Kind, Msg.str(),
                      LineStr, ColRanges);
}
开发者ID:Blei,项目名称:llvm-dcpu16,代码行数:56,代码来源:SourceMgr.cpp

示例2: GetMessage

/// GetMessage - Return an SMDiagnostic at the specified location with the
/// specified string.
///
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg,
                                   const char *Type, bool ShowLine) const {

  // First thing to do: find the current buffer containing the specified
  // location.
  int CurBuf = FindBufferContainingLoc(Loc);
  assert(CurBuf != -1 && "Invalid or unspecified location!");

  MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;

  // Scan backward to find the start of the line.
  const char *LineStart = Loc.getPointer();
  while (LineStart != CurMB->getBufferStart() &&
         LineStart[-1] != '\n' && LineStart[-1] != '\r')
    --LineStart;

  std::string LineStr;
  if (ShowLine) {
    // Get the end of the line.
    const char *LineEnd = Loc.getPointer();
    while (LineEnd != CurMB->getBufferEnd() &&
           LineEnd[0] != '\n' && LineEnd[0] != '\r')
      ++LineEnd;
    LineStr = std::string(LineStart, LineEnd);
  }

  std::string PrintedMsg;
  raw_string_ostream OS(PrintedMsg);
  if (Type)
    OS << Type << ": ";
  OS << Msg;

  return SMDiagnostic(*this, Loc,
                      CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
                      Loc.getPointer()-LineStart, OS.str(),
                      LineStr, ShowLine);
}
开发者ID:5432935,项目名称:crossbridge,代码行数:42,代码来源:SourceMgr.cpp


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