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

1

2

3

4

5

6

7

8

9

10

11

12

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

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

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

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

21

22using namespace clang;

23

24namespace {

25

27 ModuleDependencyCollector &Collector;

28 FileManager &FileMgr;

29public:

30 ModuleDependencyListener(ModuleDependencyCollector &Collector,

31 FileManager &FileMgr)

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

33 bool needsInputFileVisitation() override { return true; }

34 bool needsSystemInputFileVisitation() override { return true; }

35 bool visitInputFile(StringRef Filename, bool IsSystem, bool IsOverridden,

36 bool IsExplicitModule) override {

37

38

39 if (auto FE = FileMgr.getOptionalFileRef(Filename))

40 Filename = FE->getName();

41 Collector.addFile(Filename);

42 return true;

43 }

44};

45

46struct ModuleDependencyPPCallbacks : public PPCallbacks {

47 ModuleDependencyCollector &Collector;

48 SourceManager &SM;

49 ModuleDependencyPPCallbacks(ModuleDependencyCollector &Collector,

50 SourceManager &SM)

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

52

53 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,

54 StringRef FileName, bool IsAngled,

55 CharSourceRange FilenameRange,

57 StringRef RelativePath, const Module *SuggestedModule,

58 bool ModuleImported,

61 return;

62 Collector.addFile(File->getName());

63 }

64};

65

67 ModuleDependencyCollector &Collector;

68 ModuleDependencyMMCallbacks(ModuleDependencyCollector &Collector)

69 : Collector(Collector) {}

70

71 void moduleMapAddHeader(StringRef HeaderPath) override {

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

73 Collector.addFile(HeaderPath);

74 }

75 void moduleMapAddUmbrellaHeader(FileEntryRef Header) override {

77 }

78};

79

80}

81

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

85}

86

88 PP.addPPCallbacks(std::make_unique(

91 std::make_unique(*this));

92}

93

96

97 if (VFS.getRealPath(Path, TmpDest))

98 return true;

99 Path = TmpDest;

100

101

102

103

104

105 for (auto &C : Path)

107 if (!VFS.getRealPath(UpperDest, RealDest) && Path == RealDest)

108 return false;

109 return true;

110}

111

113 if (Seen.empty())

114 return;

115

116 StringRef VFSDir = getDest();

117

118

119

120 VFSWriter.setOverlayDir(VFSDir);

121

122

123

124 VFSWriter.setCaseSensitivity(

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 (!Canonicalizer.getFileSystem().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(llvm::vfs::FileSystem &VFS, StringRef Path)

Definition ModuleDependencyCollector.cpp:94

Defines the clang::Preprocessor interface.

Abstract interface for callback invocations by the ASTReader.

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

StringRef getNameAsRequested() const

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

void attachToASTReader(ASTReader &R) override

Definition ModuleDependencyCollector.cpp:82

virtual void addFileMapping(StringRef VPath, StringRef RPath)

void attachToPreprocessor(Preprocessor &PP) override

Definition ModuleDependencyCollector.cpp:87

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

Definition ModuleDependencyCollector.cpp:179

virtual bool insertSeen(StringRef Filename)

virtual void writeFileMap()

Definition ModuleDependencyCollector.cpp:112

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

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

Add a module map callback.

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

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.

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

@ Module

Module linkage, which indicates that the entity can be referred to from other translation units withi...

LLVM_READONLY char toUppercase(char c)

Converts the given ASCII character to its uppercase equivalent.