Example #1
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
    );
}