clang 22.0.0git
ModuleMapFile.h
Go to the documentation of this file.
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"
17#include "llvm/ADT/StringRef.h"
18
19#include <optional>
20#include <variant>
21
22namespace clang {
23
24class DiagnosticsEngine;
25class SourceManager;
26
27namespace modulemap {
28
29struct ExportDecl;
30
31/// All declarations that can appear in a `module` declaration.
32using Decl =
33 std::variant<struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl,
34 struct ModuleDecl, struct ExcludeDecl, struct ExportDecl,
35 struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl,
36 struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl>;
37
39 StringRef Feature;
41 bool RequiredState = true; /// False if preceded by '!'.
42};
43
46 std::vector<RequiresFeature> Features;
47};
48
49struct HeaderDecl {
50 StringRef Path;
53 std::optional<int64_t> Size;
54 std::optional<int64_t> MTime;
55 LLVM_PREFERRED_TYPE(bool)
57 LLVM_PREFERRED_TYPE(bool)
58 unsigned Textual : 1;
59 LLVM_PREFERRED_TYPE(bool)
60 unsigned Umbrella : 1;
61 LLVM_PREFERRED_TYPE(bool)
62 unsigned Excluded : 1;
63};
64
66 StringRef Path;
68};
69
70struct ModuleDecl {
72 SourceLocation Location; /// Points to the first keyword in the decl.
74 std::vector<Decl> Decls;
75
76 LLVM_PREFERRED_TYPE(bool)
77 unsigned Explicit : 1;
78 LLVM_PREFERRED_TYPE(bool)
79 unsigned Framework : 1;
80};
81
84 StringRef Module;
85};
86
87struct ExportDecl {
90 bool Wildcard; /// True if the last element of the ModuleId is '*'.
91};
92
96};
97
101 StringRef Path;
102};
103
104struct UseDecl {
107};
108
109struct LinkDecl {
110 StringRef Library;
112 LLVM_PREFERRED_TYPE(bool)
113 unsigned Framework : 1;
114};
115
117 std::vector<StringRef> Macros;
119 LLVM_PREFERRED_TYPE(bool)
120 unsigned Exhaustive : 1;
121};
122
126 StringRef Message;
127};
128
129using TopLevelDecl = std::variant<ModuleDecl, ExternModuleDecl>;
130
131/// Represents the parsed form of a module map file.
132///
133/// This holds many reference types (StringRef, SourceLocation, etc.) whose
134/// lifetimes are bound by the SourceManager and FileManager used.
136 /// The FileID used to parse this module map. This is always a local ID.
138
139 /// The directory in which the module map was discovered. Declarations in
140 /// the module map are relative to this directory.
142
143 /// Beginning of the file, used for moduleMapFileRead callback.
145
147 std::vector<TopLevelDecl> Decls;
148
149 void dump(llvm::raw_ostream &out) const;
150};
151
152/// Parse a module map file into an in memory representation.
153///
154/// \param ID a valid local FileID.
155/// \param Dir the directory in which this module map was found.
156/// \param SM the SourceManager for \a ID.
157/// \param Diags where to send the diagnostics.
158/// \param IsSystem was this module map found in a system search path.
159/// \param Offset optional offset into the buffer associated with \a ID. This is
160/// used for handling `#pragma clang module build`. Set to the end
161/// of the module map on return.
162///
163/// \returns The parsed ModuleMapFile if successful, std::nullopt otherwise.
164std::optional<ModuleMapFile>
166 DiagnosticsEngine &Diags, bool IsSystem, unsigned *Offset);
167
168} // namespace modulemap
169} // namespace clang
170
171#endif
static char ID
Definition: Arena.cpp:183
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::Module class, which describes a module in the source code.
#define SM(sm)
Definition: OffloadArch.cpp:16
Defines the clang::SourceLocation class and associated facilities.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Encodes a location in the source.
This class handles loading and caching of source files into memory.
std::optional< ModuleMapFile > parseModuleMap(FileID ID, clang::DirectoryEntryRef Dir, SourceManager &SM, DiagnosticsEngine &Diags, bool IsSystem, unsigned *Offset)
Parse a module map file into an in memory representation.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
std::variant< ModuleDecl, ExternModuleDecl > TopLevelDecl
The JSON file list parser is used to communicate input to InstallAPI.
The set of attributes that can be attached to a module.
Definition: Module.h:109
std::vector< StringRef > Macros
std::optional< int64_t > Size
Definition: ModuleMapFile.h:53
std::optional< int64_t > MTime
Definition: ModuleMapFile.h:54
ModuleAttributes Attrs
Points to the first keyword in the decl.
Definition: ModuleMapFile.h:73
std::vector< Decl > Decls
Definition: ModuleMapFile.h:74
Represents the parsed form of a module map file.
SourceLocation Start
Beginning of the file, used for moduleMapFileRead callback.
std::vector< TopLevelDecl > Decls
FileID ID
The FileID used to parse this module map. This is always a local ID.
OptionalDirectoryEntryRef Dir
The directory in which the module map was discovered.
std::vector< RequiresFeature > Features
Definition: ModuleMapFile.h:46