mcld::sys::fs::Path* SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType)
{
  std::string file;
  SpecToFilename(pNamespec, file);
  // for all MCLDDirectorys
  DirList::iterator mcld_dir, mcld_dir_end = m_DirList.end();
  for (mcld_dir=m_DirList.begin(); mcld_dir!=mcld_dir_end; ++mcld_dir) {
    // for all entries in MCLDDirectory
    MCLDDirectory::iterator entry = (*mcld_dir)->begin();
    MCLDDirectory::iterator enEnd = (*mcld_dir)->end();

    switch(pType) {
      case Input::DynObj: {
        while (entry!=enEnd) {
          if (file == entry.path()->stem().native() ) {
            if(mcld::sys::fs::detail::shared_library_extension == entry.path()->extension().native()) {
              return entry.path();
            }
          }

          ++entry;
        }
      }

      case Input::Archive : {
        entry = (*mcld_dir)->begin();
        enEnd = (*mcld_dir)->end();
        while ( entry!=enEnd ) {
          if (file == entry.path()->stem().native() &&
            mcld::sys::fs::detail::static_library_extension == entry.path()->extension().native()) {
            return entry.path();
          }
          ++entry;
       }
     }
     default: {
       llvm::report_fatal_error(llvm::Twine("SearchDir can not recoginize namespec: `") +
                                pNamespec +
                                llvm::Twine("'."));
     }
    }
  }
  return 0;
}
const mcld::sys::fs::Path*
SearchDirs::find(const std::string& pNamespec, mcld::Input::Type pType) const
{
  assert(Input::DynObj == pType || Input::Archive == pType);

  std::string file;
  SpecToFilename(pNamespec, file);
  // for all MCLDDirectorys
  DirList::const_iterator mcld_dir, mcld_dir_end = m_DirList.end();
  for (mcld_dir=m_DirList.begin(); mcld_dir!=mcld_dir_end; ++mcld_dir) {
    // for all entries in MCLDDirectory
    MCLDDirectory::iterator entry = (*mcld_dir)->begin();
    MCLDDirectory::iterator enEnd = (*mcld_dir)->end();

    switch(pType) {
      case Input::DynObj: {
        while (entry!=enEnd) {
          if (file == entry.path()->stem().native() ) {
            if(mcld::sys::fs::detail::shared_library_extension == entry.path()->extension().native()) {
              return entry.path();
            }
          }
          ++entry;
        }
      }
      /** Fall through **/
      case Input::Archive : {
        entry = (*mcld_dir)->begin();
        enEnd = (*mcld_dir)->end();
        while ( entry!=enEnd ) {
          if (file == entry.path()->stem().native() &&
            mcld::sys::fs::detail::static_library_extension == entry.path()->extension().native()) {
            return entry.path();
          }
          ++entry;
        }
      }
      default:
        break;
    } // end of switch
  } // end of while
  return NULL;
}