Skip to content

Commit 8918d35

Browse files
authored
[clang][Modules] Move ASTSourceDescriptor into its own file (#67930)
1 parent 09c0607 commit 8918d35

File tree

11 files changed

+105
-45
lines changed

11 files changed

+105
-45
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===- ASTSourceDescriptor.h -----------------------------*- 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+
/// \file
10+
/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules
11+
/// and precompiled header files
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
16+
#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
17+
18+
#include "clang/Basic/Module.h"
19+
#include "llvm/ADT/StringRef.h"
20+
#include <string>
21+
#include <utility>
22+
23+
namespace clang {
24+
25+
/// Abstracts clang modules and precompiled header files and holds
26+
/// everything needed to generate debug info for an imported module
27+
/// or PCH.
28+
class ASTSourceDescriptor {
29+
StringRef PCHModuleName;
30+
StringRef Path;
31+
StringRef ASTFile;
32+
ASTFileSignature Signature;
33+
Module *ClangModule = nullptr;
34+
35+
public:
36+
ASTSourceDescriptor() = default;
37+
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
38+
ASTFileSignature Signature)
39+
: PCHModuleName(std::move(Name)), Path(std::move(Path)),
40+
ASTFile(std::move(ASTFile)), Signature(Signature) {}
41+
ASTSourceDescriptor(Module &M);
42+
43+
std::string getModuleName() const;
44+
StringRef getPath() const { return Path; }
45+
StringRef getASTFile() const { return ASTFile; }
46+
ASTFileSignature getSignature() const { return Signature; }
47+
Module *getModuleOrNull() const { return ClangModule; }
48+
};
49+
50+
} // namespace clang
51+
52+
#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H

clang/include/clang/Basic/Module.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -868,32 +868,6 @@ class VisibleModuleSet {
868868
unsigned Generation = 0;
869869
};
870870

871-
/// Abstracts clang modules and precompiled header files and holds
872-
/// everything needed to generate debug info for an imported module
873-
/// or PCH.
874-
class ASTSourceDescriptor {
875-
StringRef PCHModuleName;
876-
StringRef Path;
877-
StringRef ASTFile;
878-
ASTFileSignature Signature;
879-
Module *ClangModule = nullptr;
880-
881-
public:
882-
ASTSourceDescriptor() = default;
883-
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
884-
ASTFileSignature Signature)
885-
: PCHModuleName(std::move(Name)), Path(std::move(Path)),
886-
ASTFile(std::move(ASTFile)), Signature(Signature) {}
887-
ASTSourceDescriptor(Module &M);
888-
889-
std::string getModuleName() const;
890-
StringRef getPath() const { return Path; }
891-
StringRef getASTFile() const { return ASTFile; }
892-
ASTFileSignature getSignature() const { return Signature; }
893-
Module *getModuleOrNull() const { return ClangModule; }
894-
};
895-
896-
897871
} // namespace clang
898872

899873
#endif // LLVM_CLANG_BASIC_MODULE_H

clang/lib/AST/ExternalASTSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include "clang/AST/ExternalASTSource.h"
1616
#include "clang/AST/ASTContext.h"
1717
#include "clang/AST/DeclarationName.h"
18+
#include "clang/Basic/ASTSourceDescriptor.h"
1819
#include "clang/Basic/FileManager.h"
1920
#include "clang/Basic/IdentifierTable.h"
2021
#include "clang/Basic/LLVM.h"
21-
#include "clang/Basic/Module.h"
2222
#include "clang/Basic/SourceManager.h"
2323
#include "llvm/Support/ErrorHandling.h"
2424
#include <cstdint>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- ASTSourceDescriptor.cpp -------------------------------------===//
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+
/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules
10+
/// and precompiled header files
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "clang/Basic/ASTSourceDescriptor.h"
15+
16+
namespace clang {
17+
18+
ASTSourceDescriptor::ASTSourceDescriptor(Module &M)
19+
: Signature(M.Signature), ClangModule(&M) {
20+
if (M.Directory)
21+
Path = M.Directory->getName();
22+
if (auto File = M.getASTFile())
23+
ASTFile = File->getName();
24+
}
25+
26+
std::string ASTSourceDescriptor::getModuleName() const {
27+
if (ClangModule)
28+
return ClangModule->Name;
29+
else
30+
return std::string(PCHModuleName);
31+
}
32+
33+
} // namespace clang

clang/lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if(CLANG_VENDOR)
5555
endif()
5656

5757
add_clang_library(clangBasic
58+
ASTSourceDescriptor.cpp
5859
Attributes.cpp
5960
Builtins.cpp
6061
CLWarnings.cpp

clang/lib/Basic/Module.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -724,18 +724,3 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc,
724724
};
725725
VisitModule({M, nullptr});
726726
}
727-
728-
ASTSourceDescriptor::ASTSourceDescriptor(Module &M)
729-
: Signature(M.Signature), ClangModule(&M) {
730-
if (M.Directory)
731-
Path = M.Directory->getName();
732-
if (auto File = M.getASTFile())
733-
ASTFile = File->getName();
734-
}
735-
736-
std::string ASTSourceDescriptor::getModuleName() const {
737-
if (ClangModule)
738-
return ClangModule->Name;
739-
else
740-
return std::string(PCHModuleName);
741-
}

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "clang/AST/PrettyPrinter.h"
2121
#include "clang/AST/Type.h"
2222
#include "clang/AST/TypeOrdering.h"
23+
#include "clang/Basic/ASTSourceDescriptor.h"
2324
#include "clang/Basic/CodeGenOptions.h"
24-
#include "clang/Basic/Module.h"
2525
#include "clang/Basic/SourceLocation.h"
2626
#include "llvm/ADT/DenseMap.h"
2727
#include "llvm/ADT/DenseSet.h"
@@ -38,6 +38,7 @@ class MDNode;
3838
namespace clang {
3939
class ClassTemplateSpecializationDecl;
4040
class GlobalDecl;
41+
class Module;
4142
class ModuleMap;
4243
class ObjCInterfaceDecl;
4344
class UsingDecl;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "clang/AST/TypeLoc.h"
4141
#include "clang/AST/TypeLocVisitor.h"
4242
#include "clang/AST/UnresolvedSet.h"
43+
#include "clang/Basic/ASTSourceDescriptor.h"
4344
#include "clang/Basic/CommentOptions.h"
4445
#include "clang/Basic/Diagnostic.h"
4546
#include "clang/Basic/DiagnosticError.h"

lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
1010
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
1111

12-
#include "clang/Basic/Module.h"
12+
#include "clang/Basic/ASTSourceDescriptor.h"
1313
#include "clang/Sema/Lookup.h"
1414
#include "clang/Sema/MultiplexExternalSemaSource.h"
1515
#include "clang/Sema/Sema.h"
1616
#include "clang/Sema/SemaConsumer.h"
1717
#include <optional>
1818

19+
namespace clang {
20+
21+
class Module;
22+
23+
} // namespace clang
24+
1925
namespace lldb_private {
2026

2127
/// Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take

lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "clang/AST/Decl.h"
1313
#include "clang/AST/DeclObjC.h"
14+
#include "clang/Basic/Module.h"
1415
#include <optional>
1516

1617
using namespace lldb_private;

lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H
1111

1212
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
13-
#include "clang/Basic/Module.h"
13+
#include "clang/Basic/ASTSourceDescriptor.h"
1414
#include <optional>
1515

16+
namespace clang {
17+
18+
class Module;
19+
20+
} // namespace clang
21+
1622
namespace lldb_private {
1723

1824
class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {

0 commit comments

Comments
 (0)