clang: lib/Frontend/ModuleDependencyCollector.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

17#include "llvm/ADT/iterator_range.h"

18#include "llvm/Config/llvm-config.h"

19#include "llvm/Support/FileSystem.h"

20#include "llvm/Support/Path.h"

21#include "llvm/Support/raw_ostream.h"

22

23using namespace clang;

24

25namespace {

26

30public:

33 : Collector(Collector), FileMgr(FileMgr) {}

37 bool IsExplicitModule) override {

38

39

43 return true;

44 }

45};

46

47struct ModuleDependencyPPCallbacks : public PPCallbacks {

52 : Collector(Collector), SM(SM) {}

53

55 StringRef FileName, bool IsAngled,

58 StringRef RelativePath, const Module *SuggestedModule,

59 bool ModuleImported,

62 return;

64 }

65};

66

70 : Collector(Collector) {}

71

73 if (llvm::sys::path::is_absolute(HeaderPath))

74 Collector.addFile(HeaderPath);

75 }

78 }

79};

80

81}

82

85 std::make_unique(*this, R.getFileManager()));

86}

87

89 PP.addPPCallbacks(std::make_unique(

92 std::make_unique(*this));

93}

94

97

98 if (llvm::sys::fs::real_path(Path, TmpDest))

99 return true;

100 Path = TmpDest;

101

102

103

104

105

106 for (auto &C : Path)

108 if (!llvm::sys::fs::real_path(UpperDest, RealDest) && Path == RealDest)

109 return false;

110 return true;

111}

112

114 if (Seen.empty())

115 return;

116

117 StringRef VFSDir = getDest();

118

119

120

121 VFSWriter.setOverlayDir(VFSDir);

122

123

124

126

127

128

129 VFSWriter.setUseExternalNames(false);

130

131 std::error_code EC;

133 llvm::sys::path::append(YAMLPath, "vfs.yaml");

134 llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::OF_TextWithCRLF);

135 if (EC) {

136 HasErrors = true;

137 return;

138 }

139 VFSWriter.write(OS);

140}

141

142std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src,

143 StringRef Dst) {

144 using namespace llvm::sys;

145 llvm::FileCollector::PathCanonicalizer::PathStorage Paths =

146 Canonicalizer.canonicalize(Src);

147

149

150 if (Dst.empty()) {

151

152

153 path::append(CacheDst, path::relative_path(Paths.CopyFrom));

154 } else {

155

156

157 if (!fs::exists(Dst))

158 return std::error_code();

159 path::append(CacheDst, Dst);

160 Paths.CopyFrom = Dst;

161 }

162

163

164 if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst),

165 true))

166 return EC;

167 if (std::error_code EC = fs::copy_file(Paths.CopyFrom, CacheDst))

168 return EC;

169

170

171

172

173

174

176 return std::error_code();

177}

178

181 if (copyToRoot(Filename, FileDst))

182 HasErrors = true;

183}

llvm::MachO::FileType FileType

static bool isCaseSensitivePath(StringRef Path)

Defines the clang::Preprocessor interface.

Abstract interface for callback invocations by the ASTReader.

virtual bool needsInputFileVisitation()

Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...

virtual bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule)

if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...

virtual bool needsSystemInputFileVisitation()

Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...

Reads an AST files chain containing the contents of a translation unit.

void addListener(std::unique_ptr< ASTReaderListener > L)

Add an AST callback listener.

FileManager & getFileManager() const

Represents a character-granular source range.

A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...

StringRef getNameAsRequested() const

The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...

Implements support for file system lookup, file system caching, and directory search management.

OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)

Get a FileEntryRef if it exists, without doing anything on error.

Record the location of an inclusion directive, such as an #include or #import statement.

Collects the dependencies for imported modules into a directory.

void attachToASTReader(ASTReader &R) override

virtual void addFileMapping(StringRef VPath, StringRef RPath)

void attachToPreprocessor(Preprocessor &PP) override

virtual void addFile(StringRef Filename, StringRef FileDst={})

virtual bool insertSeen(StringRef Filename)

virtual void writeFileMap()

A mechanism to observe the actions of the module map parser as it reads module map files.

virtual void moduleMapAddHeader(StringRef Filename)

Called when a header is added during module map parsing.

virtual void moduleMapAddUmbrellaHeader(FileEntryRef Header)

Called when an umbrella header is added during module map parsing.

void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)

Add a module map callback.

Describes a module or submodule.

This interface provides a way to observe the actions of the preprocessor as it does its thing.

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

void addPPCallbacks(std::unique_ptr< PPCallbacks > C)

SourceManager & getSourceManager() const

HeaderSearch & getHeaderSearchInfo() const

Encodes a location in the source.

This class handles loading and caching of source files into memory.

Token - This structure provides full information about a lexed token.

CharacteristicKind

Indicates whether a file or directory holds normal user code, system code, or system code which is im...

The JSON file list parser is used to communicate input to InstallAPI.

LLVM_READONLY char toUppercase(char c)

Converts the given ASCII character to its uppercase equivalent.