Ejemplo n.º 1
0
bool ReverseFindMatchingChars(const llvm::StringRef &s,
                              const llvm::StringRef &left_right_chars,
                              size_t &left_pos, size_t &right_pos,
                              size_t pos = llvm::StringRef::npos) {
  assert(left_right_chars.size() == 2);
  left_pos = llvm::StringRef::npos;
  const char left_char = left_right_chars[0];
  const char right_char = left_right_chars[1];
  pos = s.find_last_of(left_right_chars, pos);
  if (pos == llvm::StringRef::npos || s[pos] == left_char)
    return false;
  right_pos = pos;
  uint32_t depth = 1;
  while (pos > 0 && depth > 0) {
    pos = s.find_last_of(left_right_chars, pos);
    if (pos == llvm::StringRef::npos)
      return false;
    if (s[pos] == left_char) {
      if (--depth == 0) {
        left_pos = pos;
        return left_pos < right_pos;
      }
    } else if (s[pos] == right_char) {
      ++depth;
    }
  }
  return false;
}
Ejemplo n.º 2
0
void HeaderTracker::inclusionDirective( llvm::StringRef searchPath, llvm::StringRef relativePath, llvm::StringRef fileName, bool isAngled, clang::FileEntry const * entry )
{
    commitMacros();
    assert( !fileStack_.empty() );
    bool const relativeToParent( !isAngled && ( fileStack_.back().file->getDir()->getName() == searchPath ) );

    Dir dir;
    HeaderName headerName;

    if ( relativeToParent )
    {
        dir =  Dir( fileStack_.back().dir );
        llvm::StringRef const parentFilename = fileStack_.back().name.get();
        std::size_t const slashPos = parentFilename.find_last_of('/');
        if ( slashPos == llvm::StringRef::npos )
            headerName = HeaderName( relativePath );
        else
        {
            llvm::SmallString<512> fileName( parentFilename.data(), parentFilename.data() + slashPos + 1 );
            fileName.append( relativePath );
            headerName = HeaderName( fileName.str() );
        }
    }
    else
    {
        dir = Dir( searchPath );
        headerName = HeaderName( relativePath );
    }

    fileStack_.emplace_back
    (
        dir,
        headerName,
        relativeToParent,
        entry
    );
}