Skip to content

Commit b36c19b

Browse files
committed
[AST] Remove DeclCXX.h dep on ASTContext.h
Saves only 36 includes of ASTContext.h and related headers. There are two deps on ASTContext.h: - C++ method overrides iterator types (TinyPtrVector) - getting LangOptions For #1, duplicate the iterator type, which is TinyPtrVector<>::const_iterator. For #2, add an out-of-line accessor to get the language options. Getting the ASTContext from a Decl is already an out of line method that loops over the parent DeclContexts, so if it is ever performance critical, the proper fix is to pass the context (or LangOpts) into the predicate in question. Other changes are just header fixups.
1 parent 2c31aa2 commit b36c19b

File tree

11 files changed

+31
-14
lines changed

11 files changed

+31
-14
lines changed

clang/include/clang/AST/DeclBase.h

+4
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ class alignas(8) Decl {
465465

466466
ASTContext &getASTContext() const LLVM_READONLY;
467467

468+
/// Helper to get the language options from the ASTContext.
469+
/// Defined out of line to avoid depending on ASTContext.h.
470+
const LangOptions &getLangOpts() const LLVM_READONLY;
471+
468472
void setAccess(AccessSpecifier AS) {
469473
Access = AS;
470474
assert(AccessDeclContextSanity());

clang/include/clang/AST/DeclCXX.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef LLVM_CLANG_AST_DECLCXX_H
1616
#define LLVM_CLANG_AST_DECLCXX_H
1717

18-
#include "clang/AST/ASTContext.h"
1918
#include "clang/AST/ASTUnresolvedSet.h"
2019
#include "clang/AST/Decl.h"
2120
#include "clang/AST/DeclBase.h"
@@ -40,6 +39,7 @@
4039
#include "llvm/ADT/PointerIntPair.h"
4140
#include "llvm/ADT/PointerUnion.h"
4241
#include "llvm/ADT/STLExtras.h"
42+
#include "llvm/ADT/TinyPtrVector.h"
4343
#include "llvm/ADT/iterator_range.h"
4444
#include "llvm/Support/Casting.h"
4545
#include "llvm/Support/Compiler.h"
@@ -53,6 +53,7 @@
5353

5454
namespace clang {
5555

56+
class ASTContext;
5657
class ClassTemplateDecl;
5758
class ConstructorUsingShadowDecl;
5859
class CXXBasePath;
@@ -1166,7 +1167,7 @@ class CXXRecordDecl : public RecordDecl {
11661167
bool defaultedDefaultConstructorIsConstexpr() const {
11671168
return data().DefaultedDefaultConstructorIsConstexpr &&
11681169
(!isUnion() || hasInClassInitializer() || !hasVariantMembers() ||
1169-
getASTContext().getLangOpts().CPlusPlus2a);
1170+
getLangOpts().CPlusPlus2a);
11701171
}
11711172

11721173
/// Determine whether this class has a constexpr default constructor.
@@ -1258,7 +1259,7 @@ class CXXRecordDecl : public RecordDecl {
12581259
/// would be constexpr.
12591260
bool defaultedDestructorIsConstexpr() const {
12601261
return data().DefaultedDestructorIsConstexpr &&
1261-
getASTContext().getLangOpts().CPlusPlus2a;
1262+
getLangOpts().CPlusPlus2a;
12621263
}
12631264

12641265
/// Determine whether this class has a constexpr destructor.
@@ -1355,10 +1356,10 @@ class CXXRecordDecl : public RecordDecl {
13551356
///
13561357
/// Only in C++17 and beyond, are lambdas literal types.
13571358
bool isLiteral() const {
1358-
ASTContext &Ctx = getASTContext();
1359-
return (Ctx.getLangOpts().CPlusPlus2a ? hasConstexprDestructor()
1359+
const LangOptions &LangOpts = getLangOpts();
1360+
return (LangOpts.CPlusPlus2a ? hasConstexprDestructor()
13601361
: hasTrivialDestructor()) &&
1361-
(!isLambda() || Ctx.getLangOpts().CPlusPlus17) &&
1362+
(!isLambda() || LangOpts.CPlusPlus17) &&
13621363
!hasNonLiteralTypeFieldsOrBases() &&
13631364
(isAggregate() || isLambda() ||
13641365
hasConstexprNonCopyMoveConstructor() ||
@@ -2035,7 +2036,8 @@ class CXXMethodDecl : public FunctionDecl {
20352036
method_iterator end_overridden_methods() const;
20362037
unsigned size_overridden_methods() const;
20372038

2038-
using overridden_method_range= ASTContext::overridden_method_range;
2039+
using overridden_method_range = llvm::iterator_range<
2040+
llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>;
20392041

20402042
overridden_method_range overridden_methods() const;
20412043

clang/include/clang/AST/GlobalDecl.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ class GlobalDecl {
150150
}
151151

152152
static KernelReferenceKind getDefaultKernelReference(const FunctionDecl *D) {
153-
return D->getASTContext().getLangOpts().CUDAIsDevice
154-
? KernelReferenceKind::Kernel
155-
: KernelReferenceKind::Stub;
153+
return D->getLangOpts().CUDAIsDevice ? KernelReferenceKind::Kernel
154+
: KernelReferenceKind::Stub;
156155
}
157156

158157
GlobalDecl getWithDecl(const Decl *D) {

clang/include/clang/Serialization/ASTRecordReader.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CLANG_SERIALIZATION_ASTRECORDREADER_H
1515
#define LLVM_CLANG_SERIALIZATION_ASTRECORDREADER_H
1616

17+
#include "clang/AST/ASTContext.h"
1718
#include "clang/AST/AbstractBasicReader.h"
1819
#include "clang/Lex/Token.h"
1920
#include "clang/Serialization/ASTReader.h"

clang/lib/AST/CommentSema.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
691691
FD->doesThisDeclarationHaveABody())
692692
return;
693693

694-
const LangOptions &LO = FD->getASTContext().getLangOpts();
694+
const LangOptions &LO = FD->getLangOpts();
695695
const bool DoubleSquareBracket = LO.CPlusPlus14 || LO.C2x;
696696
StringRef AttributeSpelling =
697697
DoubleSquareBracket ? "[[deprecated]]" : "__attribute__((deprecated))";

clang/lib/AST/ComparisonCategories.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/AST/ComparisonCategories.h"
15+
#include "clang/AST/ASTContext.h"
1516
#include "clang/AST/Decl.h"
1617
#include "clang/AST/DeclCXX.h"
1718
#include "clang/AST/Type.h"

clang/lib/AST/DeclBase.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ ASTContext &Decl::getASTContext() const {
378378
return getTranslationUnitDecl()->getASTContext();
379379
}
380380

381+
/// Helper to get the language options from the ASTContext.
382+
/// Defined out of line to avoid depending on ASTContext.h.
383+
const LangOptions &Decl::getLangOpts() const {
384+
return getASTContext().getLangOpts();
385+
}
386+
381387
ASTMutationListener *Decl::getASTMutationListener() const {
382388
return getASTContext().getASTMutationListener();
383389
}

clang/lib/Analysis/PathDiagnostic.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/AST/ExprCXX.h"
2121
#include "clang/AST/OperationKinds.h"
2222
#include "clang/AST/ParentMap.h"
23+
#include "clang/AST/PrettyPrinter.h"
2324
#include "clang/AST/Stmt.h"
2425
#include "clang/AST/Type.h"
2526
#include "clang/Analysis/AnalysisDeclContext.h"
@@ -909,7 +910,7 @@ static void describeClass(raw_ostream &Out, const CXXRecordDecl *D,
909910
Out << Prefix << '\'' << *D;
910911
if (const auto T = dyn_cast<ClassTemplateSpecializationDecl>(D))
911912
describeTemplateParameters(Out, T->getTemplateArgs().asArray(),
912-
D->getASTContext().getLangOpts(), "<", ">");
913+
D->getLangOpts(), "<", ">");
913914

914915
Out << '\'';
915916
}
@@ -975,8 +976,8 @@ static bool describeCodeDecl(raw_ostream &Out, const Decl *D,
975976
if (const auto FD = dyn_cast<FunctionDecl>(D))
976977
if (const TemplateArgumentList *TAList =
977978
FD->getTemplateSpecializationArgs())
978-
describeTemplateParameters(Out, TAList->asArray(),
979-
FD->getASTContext().getLangOpts(), "<", ">");
979+
describeTemplateParameters(Out, TAList->asArray(), FD->getLangOpts(), "<",
980+
">");
980981

981982
Out << '\'';
982983
return true;

clang/lib/Analysis/ProgramPoint.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/Analysis/ProgramPoint.h"
15+
#include "clang/AST/ASTContext.h"
1516
#include "clang/Basic/JsonSupport.h"
1617

1718
using namespace clang;

clang/lib/CodeGen/CGDebugInfo.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/DeclCXX.h"
1818
#include "clang/AST/Expr.h"
1919
#include "clang/AST/ExternalASTSource.h"
20+
#include "clang/AST/PrettyPrinter.h"
2021
#include "clang/AST/Type.h"
2122
#include "clang/AST/TypeOrdering.h"
2223
#include "clang/Basic/CodeGenOptions.h"

clang/lib/Tooling/Core/Lookup.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/Tooling/Core/Lookup.h"
14+
#include "clang/AST/ASTContext.h"
1415
#include "clang/AST/Decl.h"
1516
#include "clang/AST/DeclCXX.h"
1617
#include "clang/AST/DeclarationName.h"

0 commit comments

Comments
 (0)