Skip to content

Commit 60573ae

Browse files
committed
Remove Expr.h include from ASTContext.h, NFC
ASTContext.h is popular, prune its includes. Expr.h brings in Attr.h, which is also expensive. Move BlockVarCopyInit to Expr.h to accomplish this.
1 parent 6555995 commit 60573ae

25 files changed

+67
-49
lines changed

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ClangTidyOptions.h"
2020
#include "GlobList.h"
2121
#include "clang/AST/ASTDiagnostic.h"
22+
#include "clang/AST/Attr.h"
2223
#include "clang/Basic/Diagnostic.h"
2324
#include "clang/Basic/DiagnosticOptions.h"
2425
#include "clang/Frontend/DiagnosticRenderer.h"

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "clang/AST/Decl.h"
2323
#include "clang/AST/DeclBase.h"
2424
#include "clang/AST/DeclarationName.h"
25-
#include "clang/AST/Expr.h"
2625
#include "clang/AST/ExternalASTSource.h"
2726
#include "clang/AST/NestedNameSpecifier.h"
2827
#include "clang/AST/PrettyPrinter.h"
@@ -124,6 +123,7 @@ class UnresolvedSetIterator;
124123
class UsingShadowDecl;
125124
class VarTemplateDecl;
126125
class VTableContextBase;
126+
struct BlockVarCopyInit;
127127

128128
namespace Builtin {
129129

@@ -158,22 +158,6 @@ struct TypeInfo {
158158
/// Holds long-lived AST nodes (such as types and decls) that can be
159159
/// referred to throughout the semantic analysis of a file.
160160
class ASTContext : public RefCountedBase<ASTContext> {
161-
public:
162-
/// Copy initialization expr of a __block variable and a boolean flag that
163-
/// indicates whether the expression can throw.
164-
struct BlockVarCopyInit {
165-
BlockVarCopyInit() = default;
166-
BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
167-
: ExprAndFlag(CopyExpr, CanThrow) {}
168-
void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
169-
ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
170-
}
171-
Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
172-
bool canThrow() const { return ExprAndFlag.getInt(); }
173-
llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag;
174-
};
175-
176-
private:
177161
friend class NestedNameSpecifier;
178162

179163
mutable SmallVector<Type *, 0> Types;

clang/include/clang/AST/ASTFwd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class Type;
2626
#define TYPE(DERIVED, BASE) class DERIVED##Type;
2727
#include "clang/AST/TypeNodes.inc"
2828
class CXXCtorInitializer;
29+
class OMPClause;
30+
#define OPENMP_CLAUSE(KIND, CLASSNAME) class CLASSNAME;
31+
#include "clang/Basic/OpenMPKinds.def"
32+
2933

3034
} // end namespace clang
3135

clang/include/clang/AST/ASTTypeTraits.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#define LLVM_CLANG_AST_ASTTYPETRAITS_H
1717

1818
#include "clang/AST/ASTFwd.h"
19-
#include "clang/AST/Decl.h"
2019
#include "clang/AST/NestedNameSpecifier.h"
21-
#include "clang/AST/OpenMPClause.h"
22-
#include "clang/AST/Stmt.h"
2320
#include "clang/AST/TemplateBase.h"
2421
#include "clang/AST/TypeLoc.h"
2522
#include "clang/Basic/LLVM.h"

clang/include/clang/AST/Expr.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5610,6 +5610,20 @@ class BlockExpr : public Expr {
56105610
}
56115611
};
56125612

5613+
/// Copy initialization expr of a __block variable and a boolean flag that
5614+
/// indicates whether the expression can throw.
5615+
struct BlockVarCopyInit {
5616+
BlockVarCopyInit() = default;
5617+
BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
5618+
: ExprAndFlag(CopyExpr, CanThrow) {}
5619+
void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
5620+
ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
5621+
}
5622+
Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
5623+
bool canThrow() const { return ExprAndFlag.getInt(); }
5624+
llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag;
5625+
};
5626+
56135627
/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
56145628
/// This AST node provides support for reinterpreting a type to another
56155629
/// type of the same size.

clang/include/clang/AST/TypeLoc.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_AST_TYPELOC_H
1515
#define LLVM_CLANG_AST_TYPELOC_H
1616

17-
#include "clang/AST/Attr.h"
1817
#include "clang/AST/Decl.h"
1918
#include "clang/AST/NestedNameSpecifier.h"
2019
#include "clang/AST/TemplateBase.h"
@@ -33,6 +32,7 @@
3332

3433
namespace clang {
3534

35+
class Attr;
3636
class ASTContext;
3737
class CXXRecordDecl;
3838
class Expr;
@@ -878,18 +878,7 @@ class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
878878
return dyn_cast_or_null<T>(getAttr());
879879
}
880880

881-
SourceRange getLocalSourceRange() const {
882-
// Note that this does *not* include the range of the attribute
883-
// enclosure, e.g.:
884-
// __attribute__((foo(bar)))
885-
// ^~~~~~~~~~~~~~~ ~~
886-
// or
887-
// [[foo(bar)]]
888-
// ^~ ~~
889-
// That enclosure doesn't necessarily belong to a single attribute
890-
// anyway.
891-
return getAttr() ? getAttr()->getRange() : SourceRange();
892-
}
881+
SourceRange getLocalSourceRange() const;
893882

894883
void initializeLocal(ASTContext &Context, SourceLocation loc) {
895884
setAttr(nullptr);

clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H
1616
#define LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H
1717

18+
#include "clang/AST/Attr.h"
1819
#include "clang/AST/DeclCXX.h"
1920
#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
2021

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,8 +2678,7 @@ const ObjCInterfaceDecl *ASTContext::getObjContainingInterface(
26782678

26792679
/// Get the copy initialization expression of VarDecl, or nullptr if
26802680
/// none exists.
2681-
ASTContext::BlockVarCopyInit
2682-
ASTContext::getBlockVarCopyInit(const VarDecl*VD) const {
2681+
BlockVarCopyInit ASTContext::getBlockVarCopyInit(const VarDecl *VD) const {
26832682
assert(VD && "Passed null params");
26842683
assert(VD->hasAttr<BlocksAttr>() &&
26852684
"getBlockVarCopyInits - not __block var");

clang/lib/AST/ASTTypeTraits.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/AST/ASTContext.h"
1717
#include "clang/AST/DeclCXX.h"
1818
#include "clang/AST/NestedNameSpecifier.h"
19+
#include "clang/AST/OpenMPClause.h"
1920

2021
namespace clang {
2122
namespace ast_type_traits {

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "clang/AST/ASTDiagnostic.h"
1717
#include "clang/AST/ASTLambda.h"
1818
#include "clang/AST/ASTMutationListener.h"
19+
#include "clang/AST/Attr.h"
1920
#include "clang/AST/CanonicalType.h"
2021
#include "clang/AST/DeclBase.h"
2122
#include "clang/AST/DeclCXX.h"
@@ -55,8 +56,8 @@
5556
#include "llvm/ADT/Optional.h"
5657
#include "llvm/ADT/STLExtras.h"
5758
#include "llvm/ADT/SmallVector.h"
58-
#include "llvm/ADT/StringSwitch.h"
5959
#include "llvm/ADT/StringRef.h"
60+
#include "llvm/ADT/StringSwitch.h"
6061
#include "llvm/ADT/Triple.h"
6162
#include "llvm/Support/Casting.h"
6263
#include "llvm/Support/ErrorHandling.h"

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "clang/AST/ASTLambda.h"
1616
#include "clang/AST/ASTMutationListener.h"
1717
#include "clang/AST/ASTUnresolvedSet.h"
18+
#include "clang/AST/Attr.h"
1819
#include "clang/AST/CXXInheritance.h"
1920
#include "clang/AST/DeclBase.h"
2021
#include "clang/AST/DeclTemplate.h"

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
//
3333
//===----------------------------------------------------------------------===//
3434

35-
#include <cstring>
36-
#include <functional>
3735
#include "Interp/Context.h"
3836
#include "Interp/Frame.h"
3937
#include "Interp/State.h"
4038
#include "clang/AST/APValue.h"
4139
#include "clang/AST/ASTContext.h"
4240
#include "clang/AST/ASTDiagnostic.h"
4341
#include "clang/AST/ASTLambda.h"
42+
#include "clang/AST/Attr.h"
4443
#include "clang/AST/CXXInheritance.h"
4544
#include "clang/AST/CharUnits.h"
4645
#include "clang/AST/CurrentSourceLocExprScope.h"
@@ -57,6 +56,8 @@
5756
#include "llvm/ADT/SmallBitVector.h"
5857
#include "llvm/Support/SaveAndRestore.h"
5958
#include "llvm/Support/raw_ostream.h"
59+
#include <cstring>
60+
#include <functional>
6061

6162
#define DEBUG_TYPE "exprconstant"
6263

clang/lib/AST/TypeLoc.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "clang/AST/TypeLoc.h"
1414
#include "clang/AST/ASTContext.h"
15+
#include "clang/AST/Attr.h"
1516
#include "clang/AST/Expr.h"
1617
#include "clang/AST/NestedNameSpecifier.h"
1718
#include "clang/AST/TemplateBase.h"
@@ -467,6 +468,19 @@ void ObjCObjectTypeLoc::initializeLocal(ASTContext &Context,
467468
setProtocolLoc(i, Loc);
468469
}
469470

471+
SourceRange AttributedTypeLoc::getLocalSourceRange() const {
472+
// Note that this does *not* include the range of the attribute
473+
// enclosure, e.g.:
474+
// __attribute__((foo(bar)))
475+
// ^~~~~~~~~~~~~~~ ~~
476+
// or
477+
// [[foo(bar)]]
478+
// ^~ ~~
479+
// That enclosure doesn't necessarily belong to a single attribute
480+
// anyway.
481+
return getAttr() ? getAttr()->getRange() : SourceRange();
482+
}
483+
470484
void TypeOfTypeLoc::initializeLocal(ASTContext &Context,
471485
SourceLocation Loc) {
472486
TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo>

clang/lib/Analysis/CloneDetection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/Analysis/CloneDetection.h"
14-
14+
#include "clang/AST/Attr.h"
1515
#include "clang/AST/DataCollection.h"
1616
#include "clang/AST/DeclTemplate.h"
1717
#include "llvm/Support/MD5.h"

clang/lib/Index/IndexDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "IndexingContext.h"
10-
#include "clang/Index/IndexDataConsumer.h"
10+
#include "clang/AST/Attr.h"
1111
#include "clang/AST/DeclVisitor.h"
12+
#include "clang/Index/IndexDataConsumer.h"
1213

1314
using namespace clang;
1415
using namespace index;

clang/lib/Index/IndexSymbol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Index/IndexSymbol.h"
10+
#include "clang/AST/Attr.h"
1011
#include "clang/AST/DeclCXX.h"
1112
#include "clang/AST/DeclObjC.h"
1213
#include "clang/AST/DeclTemplate.h"

clang/lib/Index/IndexingContext.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "IndexingContext.h"
10-
#include "clang/Basic/SourceLocation.h"
11-
#include "clang/Index/IndexDataConsumer.h"
1210
#include "clang/AST/ASTContext.h"
13-
#include "clang/AST/DeclTemplate.h"
11+
#include "clang/AST/Attr.h"
1412
#include "clang/AST/DeclObjC.h"
13+
#include "clang/AST/DeclTemplate.h"
14+
#include "clang/Basic/SourceLocation.h"
1515
#include "clang/Basic/SourceManager.h"
16+
#include "clang/Index/IndexDataConsumer.h"
1617

1718
using namespace clang;
1819
using namespace index;

clang/lib/Index/USRGeneration.cpp

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

99
#include "clang/Index/USRGeneration.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/Attr.h"
1112
#include "clang/AST/DeclTemplate.h"
1213
#include "clang/AST/DeclVisitor.h"
1314
#include "clang/Lex/PreprocessingRecord.h"

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "ASTCommon.h"
14+
#include "clang/AST/Attr.h"
1415
#include "clang/AST/DeclCXX.h"
1516
#include "clang/AST/DeclContextInternals.h"
1617
#include "clang/AST/DeclTemplate.h"
@@ -986,7 +987,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
986987
}
987988

988989
if (D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) {
989-
ASTContext::BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
990+
BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
990991
Record.AddStmt(Init.getCopyExpr());
991992
if (Init.getCopyExpr())
992993
Record.push_back(Init.canThrow());

clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//
2222
//===----------------------------------------------------------------------===//
2323

24+
#include "clang/AST/Attr.h"
2425
#include "clang/Analysis/AnyCall.h"
2526
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
2627
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"

clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
17+
#include "clang/AST/Attr.h"
1818
#include "clang/Basic/TargetInfo.h"
19+
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
1920
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
2021
#include "clang/StaticAnalyzer/Core/Checker.h"
2122
#include "clang/StaticAnalyzer/Core/CheckerManager.h"

clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "clang/AST/Attr.h"
1516
#include "clang/AST/ExprCXX.h"
1617
#include "clang/Driver/DriverDiagnostic.h"
1718
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"

clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
14+
#include "clang/AST/Attr.h"
1515
#include "clang/AST/DeclCXX.h"
16+
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
1617
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
1718
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
1819
#include "clang/StaticAnalyzer/Core/Checker.h"

clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
1616
#include "clang/AST/ASTContext.h"
17+
#include "clang/AST/Attr.h"
1718
#include "clang/AST/Decl.h"
1819
#include "clang/AST/DeclBase.h"
1920
#include "clang/AST/DeclCXX.h"
@@ -29,20 +30,20 @@
2930
#include "clang/Analysis/CFGStmtMap.h"
3031
#include "clang/Analysis/PathDiagnostic.h"
3132
#include "clang/Analysis/ProgramPoint.h"
32-
#include "clang/CrossTU/CrossTranslationUnit.h"
3333
#include "clang/Basic/IdentifierTable.h"
3434
#include "clang/Basic/LLVM.h"
3535
#include "clang/Basic/SourceLocation.h"
3636
#include "clang/Basic/SourceManager.h"
3737
#include "clang/Basic/Specifiers.h"
38+
#include "clang/CrossTU/CrossTranslationUnit.h"
3839
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
39-
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
4040
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
41+
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
4142
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
4243
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
4344
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
44-
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
4545
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
46+
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
4647
#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
4748
#include "llvm/ADT/ArrayRef.h"
4849
#include "llvm/ADT/DenseMap.h"

clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
10+
#include "clang/AST/Attr.h"
1011

1112
using namespace clang;
1213
using namespace tooling;

0 commit comments

Comments
 (0)