Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the DirectoryLookup interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
0014 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
0015 
0016 #include "clang/Basic/LLVM.h"
0017 #include "clang/Basic/FileManager.h"
0018 #include "clang/Basic/SourceManager.h"
0019 #include "clang/Lex/ModuleMap.h"
0020 
0021 namespace clang {
0022 class HeaderMap;
0023 class HeaderSearch;
0024 class Module;
0025 
0026 /// DirectoryLookup - This class represents one entry in the search list that
0027 /// specifies the search order for directories in \#include directives.  It
0028 /// represents either a directory, a framework, or a headermap.
0029 ///
0030 class DirectoryLookup {
0031 public:
0032   enum LookupType_t {
0033     LT_NormalDir,
0034     LT_Framework,
0035     LT_HeaderMap
0036   };
0037 private:
0038   union DLU { // This union is discriminated by isHeaderMap.
0039     /// Dir - This is the actual directory that we're referring to for a normal
0040     /// directory or a framework.
0041     DirectoryEntryRef Dir;
0042 
0043     /// Map - This is the HeaderMap if this is a headermap lookup.
0044     ///
0045     const HeaderMap *Map;
0046 
0047     DLU(DirectoryEntryRef Dir) : Dir(Dir) {}
0048     DLU(const HeaderMap *Map) : Map(Map) {}
0049   } u;
0050 
0051   /// DirCharacteristic - The type of directory this is: this is an instance of
0052   /// SrcMgr::CharacteristicKind.
0053   LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
0054   unsigned DirCharacteristic : 3;
0055 
0056   /// LookupType - This indicates whether this DirectoryLookup object is a
0057   /// normal directory, a framework, or a headermap.
0058   LLVM_PREFERRED_TYPE(LookupType_t)
0059   unsigned LookupType : 2;
0060 
0061   /// Whether we've performed an exhaustive search for module maps
0062   /// within the subdirectories of this directory.
0063   LLVM_PREFERRED_TYPE(bool)
0064   unsigned SearchedAllModuleMaps : 1;
0065 
0066 public:
0067   /// This ctor *does not take ownership* of 'Dir'.
0068   DirectoryLookup(DirectoryEntryRef Dir, SrcMgr::CharacteristicKind DT,
0069                   bool isFramework)
0070       : u(Dir), DirCharacteristic(DT),
0071         LookupType(isFramework ? LT_Framework : LT_NormalDir),
0072         SearchedAllModuleMaps(false) {}
0073 
0074   /// This ctor *does not take ownership* of 'Map'.
0075   DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
0076       : u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
0077         SearchedAllModuleMaps(false) {}
0078 
0079   /// getLookupType - Return the kind of directory lookup that this is: either a
0080   /// normal directory, a framework path, or a HeaderMap.
0081   LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
0082 
0083   /// getName - Return the directory or filename corresponding to this lookup
0084   /// object.
0085   StringRef getName() const;
0086 
0087   /// getDir - Return the directory that this entry refers to.
0088   ///
0089   const DirectoryEntry *getDir() const {
0090     return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
0091   }
0092 
0093   OptionalDirectoryEntryRef getDirRef() const {
0094     return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
0095   }
0096 
0097   /// getFrameworkDir - Return the directory that this framework refers to.
0098   ///
0099   const DirectoryEntry *getFrameworkDir() const {
0100     return isFramework() ? &u.Dir.getDirEntry() : nullptr;
0101   }
0102 
0103   OptionalDirectoryEntryRef getFrameworkDirRef() const {
0104     return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
0105   }
0106 
0107   /// getHeaderMap - Return the directory that this entry refers to.
0108   ///
0109   const HeaderMap *getHeaderMap() const {
0110     return isHeaderMap() ? u.Map : nullptr;
0111   }
0112 
0113   /// isNormalDir - Return true if this is a normal directory, not a header map.
0114   bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
0115 
0116   /// isFramework - True if this is a framework directory.
0117   ///
0118   bool isFramework() const { return getLookupType() == LT_Framework; }
0119 
0120   /// isHeaderMap - Return true if this is a header map, not a normal directory.
0121   bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
0122 
0123   /// Determine whether we have already searched this entire
0124   /// directory for module maps.
0125   bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
0126 
0127   /// Specify whether we have already searched all of the subdirectories
0128   /// for module maps.
0129   void setSearchedAllModuleMaps(bool SAMM) {
0130     SearchedAllModuleMaps = SAMM;
0131   }
0132 
0133   /// DirCharacteristic - The type of directory this is, one of the DirType enum
0134   /// values.
0135   SrcMgr::CharacteristicKind getDirCharacteristic() const {
0136     return (SrcMgr::CharacteristicKind)DirCharacteristic;
0137   }
0138 
0139   /// Whether this describes a system header directory.
0140   bool isSystemHeaderDirectory() const {
0141     return getDirCharacteristic() != SrcMgr::C_User;
0142   }
0143 
0144   /// LookupFile - Lookup the specified file in this search path, returning it
0145   /// if it exists or returning null if not.
0146   ///
0147   /// \param Filename The file to look up relative to the search paths.
0148   ///
0149   /// \param HS The header search instance to search with.
0150   ///
0151   /// \param IncludeLoc the source location of the #include or #import
0152   /// directive.
0153   ///
0154   /// \param SearchPath If not NULL, will be set to the search path relative
0155   /// to which the file was found.
0156   ///
0157   /// \param RelativePath If not NULL, will be set to the path relative to
0158   /// SearchPath at which the file was found. This only differs from the
0159   /// Filename for framework includes.
0160   ///
0161   /// \param RequestingModule The module in which the lookup was performed.
0162   ///
0163   /// \param SuggestedModule If non-null, and the file found is semantically
0164   /// part of a known module, this will be set to the module that should
0165   /// be imported instead of preprocessing/parsing the file found.
0166   ///
0167   /// \param [out] InUserSpecifiedSystemFramework If the file is found,
0168   /// set to true if the file is located in a framework that has been
0169   /// user-specified to be treated as a system framework.
0170   ///
0171   /// \param [out] IsFrameworkFound For a framework directory set to true if
0172   /// specified '.framework' directory is found.
0173   ///
0174   /// \param [out] MappedName if this is a headermap which maps the filename to
0175   /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
0176   /// vector and point Filename to it.
0177   OptionalFileEntryRef
0178   LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
0179              SmallVectorImpl<char> *SearchPath,
0180              SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
0181              ModuleMap::KnownHeader *SuggestedModule,
0182              bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
0183              bool &IsInHeaderMap, SmallVectorImpl<char> &MappedName,
0184              bool OpenFile = true) const;
0185 
0186 private:
0187   OptionalFileEntryRef DoFrameworkLookup(
0188       StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
0189       SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
0190       ModuleMap::KnownHeader *SuggestedModule,
0191       bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound) const;
0192 };
0193 
0194 }  // end namespace clang
0195 
0196 #endif