|
| 1 | +//===- ModuleMapFile.h - Parsing and representation -------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_CLANG_LEX_MODULEMAPFILE_H |
| 10 | +#define LLVM_CLANG_LEX_MODULEMAPFILE_H |
| 11 | + |
| 12 | +#include "clang/Basic/LLVM.h" |
| 13 | +// TODO: Consider moving ModuleId to another header, parsing a modulemap file is |
| 14 | +// intended to not depend on anything about the clang::Module class. |
| 15 | +#include "clang/Basic/Module.h" |
| 16 | +#include "clang/Basic/SourceLocation.h" |
| 17 | +#include "llvm/ADT/StringRef.h" |
| 18 | + |
| 19 | +#include <optional> |
| 20 | +#include <variant> |
| 21 | + |
| 22 | +namespace clang { |
| 23 | + |
| 24 | +class DiagnosticsEngine; |
| 25 | +class SourceManager; |
| 26 | + |
| 27 | +namespace modulemap { |
| 28 | + |
| 29 | +using Decl = |
| 30 | + std::variant<struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, |
| 31 | + struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, |
| 32 | + struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, |
| 33 | + struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl>; |
| 34 | + |
| 35 | +struct RequiresFeature { |
| 36 | + SourceLocation Location; |
| 37 | + StringRef Feature; |
| 38 | + bool RequiredState = true; |
| 39 | +}; |
| 40 | + |
| 41 | +struct RequiresDecl { |
| 42 | + SourceLocation Location; |
| 43 | + std::vector<RequiresFeature> Features; |
| 44 | +}; |
| 45 | + |
| 46 | +struct HeaderDecl { |
| 47 | + SourceLocation Location; |
| 48 | + StringRef Path; |
| 49 | + SourceLocation PathLoc; |
| 50 | + std::optional<int64_t> Size; |
| 51 | + std::optional<int64_t> MTime; |
| 52 | + LLVM_PREFERRED_TYPE(bool) |
| 53 | + unsigned Private : 1; |
| 54 | + LLVM_PREFERRED_TYPE(bool) |
| 55 | + unsigned Textual : 1; |
| 56 | + LLVM_PREFERRED_TYPE(bool) |
| 57 | + unsigned Umbrella : 1; |
| 58 | + LLVM_PREFERRED_TYPE(bool) |
| 59 | + unsigned Excluded : 1; |
| 60 | +}; |
| 61 | + |
| 62 | +struct UmbrellaDirDecl { |
| 63 | + SourceLocation Location; |
| 64 | + StringRef Path; |
| 65 | +}; |
| 66 | + |
| 67 | +struct ModuleDecl { |
| 68 | + SourceLocation Location; /// Points to the first keyword in the decl. |
| 69 | + ModuleId Id; |
| 70 | + ModuleAttributes Attrs; |
| 71 | + std::vector<Decl> Decls; |
| 72 | + |
| 73 | + LLVM_PREFERRED_TYPE(bool) |
| 74 | + unsigned Explicit : 1; |
| 75 | + LLVM_PREFERRED_TYPE(bool) |
| 76 | + unsigned Framework : 1; |
| 77 | +}; |
| 78 | + |
| 79 | +struct ExcludeDecl { |
| 80 | + SourceLocation Location; |
| 81 | + StringRef Module; |
| 82 | +}; |
| 83 | + |
| 84 | +struct ExportDecl { |
| 85 | + SourceLocation Location; |
| 86 | + ModuleId Id; |
| 87 | + bool Wildcard; |
| 88 | +}; |
| 89 | + |
| 90 | +struct ExportAsDecl { |
| 91 | + SourceLocation Location; |
| 92 | + ModuleId Id; |
| 93 | +}; |
| 94 | + |
| 95 | +struct ExternModuleDecl { |
| 96 | + SourceLocation Location; |
| 97 | + ModuleId Id; |
| 98 | + StringRef Path; |
| 99 | +}; |
| 100 | + |
| 101 | +struct UseDecl { |
| 102 | + SourceLocation Location; |
| 103 | + ModuleId Id; |
| 104 | +}; |
| 105 | + |
| 106 | +struct LinkDecl { |
| 107 | + SourceLocation Location; |
| 108 | + StringRef Library; |
| 109 | + LLVM_PREFERRED_TYPE(bool) |
| 110 | + unsigned Framework : 1; |
| 111 | +}; |
| 112 | + |
| 113 | +struct ConfigMacrosDecl { |
| 114 | + SourceLocation Location; |
| 115 | + std::vector<StringRef> Macros; |
| 116 | + LLVM_PREFERRED_TYPE(bool) |
| 117 | + unsigned Exhaustive : 1; |
| 118 | +}; |
| 119 | + |
| 120 | +struct ConflictDecl { |
| 121 | + SourceLocation Location; |
| 122 | + ModuleId Id; |
| 123 | + StringRef Message; |
| 124 | +}; |
| 125 | + |
| 126 | +using TopLevelDecl = std::variant<ModuleDecl, ExternModuleDecl>; |
| 127 | + |
| 128 | +struct ModuleMapFile { |
| 129 | + std::vector<TopLevelDecl> Decls; |
| 130 | +}; |
| 131 | + |
| 132 | +std::optional<ModuleMapFile> parseModuleMap(FileEntryRef File, |
| 133 | + SourceManager &SM, |
| 134 | + DiagnosticsEngine &Diags, |
| 135 | + bool IsSystem, unsigned *Offset); |
| 136 | +void dumpModuleMapFile(ModuleMapFile &MMF, llvm::raw_ostream &out); |
| 137 | + |
| 138 | +} // namespace modulemap |
| 139 | +} // namespace clang |
| 140 | + |
| 141 | +#endif |
0 commit comments