Skip to content

Commit c54c9c7

Browse files
committed
[Gardening] Extract basic source info structs from RawComment.h
1 parent eae6c00 commit c54c9c7

28 files changed

+197
-127
lines changed

include/swift/AST/FileUnit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define SWIFT_AST_FILEUNIT_H
1515

1616
#include "swift/AST/Module.h"
17+
#include "swift/AST/RawComment.h"
18+
#include "swift/Basic/BasicSourceInfo.h"
1719

1820
namespace swift {
1921
static inline unsigned alignOfFileUnit();

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "swift/AST/Identifier.h"
2424
#include "swift/AST/Import.h"
2525
#include "swift/AST/LookupKinds.h"
26-
#include "swift/AST/RawComment.h"
2726
#include "swift/AST/Type.h"
27+
#include "swift/Basic/BasicSourceInfo.h"
2828
#include "swift/Basic/Compiler.h"
2929
#include "swift/Basic/OptionSet.h"
3030
#include "swift/Basic/STLExtras.h"

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/Basic/Debug.h"
2626
#include "swift/Basic/NullablePtr.h"
2727
#include "swift/Basic/SourceLoc.h"
28+
#include "swift/Basic/SourceManager.h"
2829

2930
namespace swift {
3031
class ASTContext;

include/swift/AST/RawComment.h

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#ifndef SWIFT_AST_RAW_COMMENT_H
1414
#define SWIFT_AST_RAW_COMMENT_H
1515

16-
#include "swift/Basic/Fingerprint.h"
17-
#include "swift/Basic/LLVM.h"
1816
#include "swift/Basic/SourceLoc.h"
19-
#include "swift/Basic/SourceManager.h"
17+
#include "llvm/ADT/ArrayRef.h"
18+
#include "llvm/ADT/StringRef.h"
2019

2120
namespace swift {
2221

2322
class SourceFile;
23+
class SourceManager;
2424

2525
struct SingleRawComment {
2626
enum class CommentKind {
@@ -82,78 +82,6 @@ struct CommentInfo {
8282
uint32_t SourceOrder;
8383
};
8484

85-
struct LineColumn {
86-
uint32_t Line = 0;
87-
uint32_t Column = 0;
88-
bool isValid() const { return Line && Column; }
89-
};
90-
91-
struct BasicDeclLocs {
92-
StringRef SourceFilePath;
93-
SmallVector<std::pair<LineColumn, uint32_t>, 4> DocRanges;
94-
LineColumn Loc;
95-
LineColumn StartLoc;
96-
LineColumn EndLoc;
97-
};
98-
99-
class BasicSourceFileInfo {
100-
/// If this is non-null, fields other than 'FilePath' hasn't been populated.
101-
/// The 'getInt()' part indicates this instance is constructed with a
102-
/// SourceFile.
103-
llvm::PointerIntPair<const SourceFile *, 1, bool> SFAndIsFromSF;
104-
105-
StringRef FilePath;
106-
Fingerprint InterfaceHashIncludingTypeMembers = Fingerprint::ZERO();
107-
/// Does *not* include the type-body hashes of the top level types.
108-
/// Just the `SourceFile` hashes.
109-
/// Used for incremental imports.
110-
Fingerprint InterfaceHashExcludingTypeMembers = Fingerprint::ZERO();
111-
llvm::sys::TimePoint<> LastModified = {};
112-
uint64_t FileSize = 0;
113-
114-
// Populate the from 'SF' member if exist. 'SF' will be cleared.
115-
void populateWithSourceFileIfNeeded();
116-
117-
public:
118-
BasicSourceFileInfo(StringRef FilePath,
119-
Fingerprint InterfaceHashIncludingTypeMembers,
120-
Fingerprint InterfaceHashExcludingTypeMembers,
121-
llvm::sys::TimePoint<> LastModified, uint64_t FileSize)
122-
: FilePath(FilePath),
123-
InterfaceHashIncludingTypeMembers(InterfaceHashIncludingTypeMembers),
124-
InterfaceHashExcludingTypeMembers(InterfaceHashExcludingTypeMembers),
125-
LastModified(LastModified), FileSize(FileSize) {}
126-
127-
/// Construct with a `SourceFile`. `getInterfaceHashIncludingTypeMembers()`,
128-
/// `getInterfaceHashExcludingTypeMembers()`, `getLastModified()` and `getFileSize()` are laizily
129-
/// populated when accessed.
130-
BasicSourceFileInfo(const SourceFile *SF);
131-
132-
bool isFromSourceFile() const;
133-
134-
StringRef getFilePath() const { return FilePath; }
135-
136-
Fingerprint getInterfaceHashIncludingTypeMembers() const {
137-
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
138-
return InterfaceHashIncludingTypeMembers;
139-
}
140-
141-
Fingerprint getInterfaceHashExcludingTypeMembers() const {
142-
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
143-
return InterfaceHashExcludingTypeMembers;
144-
}
145-
146-
llvm::sys::TimePoint<> getLastModified() const {
147-
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
148-
return LastModified;
149-
}
150-
151-
uint64_t getFileSize() const {
152-
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
153-
return FileSize;
154-
}
155-
};
156-
15785
} // namespace swift
15886

15987
#endif // LLVM_SWIFT_AST_RAW_COMMENT_H

include/swift/Basic/BasicSourceInfo.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//===--- BasicSourceInfo.h - Simple source information ----------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_BASIC_SOURCE_INFO_H
14+
#define SWIFT_BASIC_BASIC_SOURCE_INFO_H
15+
16+
#include "swift/Basic/Fingerprint.h"
17+
#include "swift/Basic/LLVM.h"
18+
#include "llvm/ADT/PointerIntPair.h"
19+
#include "llvm/Support/Chrono.h"
20+
21+
namespace swift {
22+
23+
class SourceFile;
24+
25+
struct SourcePosition {
26+
uint32_t Line = 0;
27+
uint32_t Column = 0;
28+
bool isValid() const { return Line && Column; }
29+
};
30+
31+
struct BasicDeclLocs {
32+
StringRef SourceFilePath;
33+
SmallVector<std::pair<SourcePosition, uint32_t>, 4> DocRanges;
34+
SourcePosition Loc;
35+
SourcePosition StartLoc;
36+
SourcePosition EndLoc;
37+
};
38+
39+
class BasicSourceFileInfo {
40+
/// If this is non-null, fields other than 'FilePath' hasn't been populated.
41+
/// The 'getInt()' part indicates this instance is constructed with a
42+
/// SourceFile.
43+
llvm::PointerIntPair<const SourceFile *, 1, bool> SFAndIsFromSF;
44+
45+
StringRef FilePath;
46+
Fingerprint InterfaceHashIncludingTypeMembers = Fingerprint::ZERO();
47+
/// Does *not* include the type-body hashes of the top level types.
48+
/// Just the `SourceFile` hashes.
49+
/// Used for incremental imports.
50+
Fingerprint InterfaceHashExcludingTypeMembers = Fingerprint::ZERO();
51+
llvm::sys::TimePoint<> LastModified = {};
52+
uint64_t FileSize = 0;
53+
54+
// Populate the from 'SF' member if exist. 'SF' will be cleared.
55+
void populateWithSourceFileIfNeeded();
56+
57+
public:
58+
BasicSourceFileInfo(StringRef FilePath,
59+
Fingerprint InterfaceHashIncludingTypeMembers,
60+
Fingerprint InterfaceHashExcludingTypeMembers,
61+
llvm::sys::TimePoint<> LastModified, uint64_t FileSize)
62+
: FilePath(FilePath),
63+
InterfaceHashIncludingTypeMembers(InterfaceHashIncludingTypeMembers),
64+
InterfaceHashExcludingTypeMembers(InterfaceHashExcludingTypeMembers),
65+
LastModified(LastModified), FileSize(FileSize) {}
66+
67+
/// Construct with a `SourceFile`. `getInterfaceHashIncludingTypeMembers()`,
68+
/// `getInterfaceHashExcludingTypeMembers()`, `getLastModified()` and
69+
/// `getFileSize()` are laizily populated when accessed.
70+
BasicSourceFileInfo(const SourceFile *SF);
71+
72+
bool isFromSourceFile() const;
73+
74+
StringRef getFilePath() const { return FilePath; }
75+
76+
Fingerprint getInterfaceHashIncludingTypeMembers() const {
77+
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
78+
return InterfaceHashIncludingTypeMembers;
79+
}
80+
81+
Fingerprint getInterfaceHashExcludingTypeMembers() const {
82+
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
83+
return InterfaceHashExcludingTypeMembers;
84+
}
85+
86+
llvm::sys::TimePoint<> getLastModified() const {
87+
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
88+
return LastModified;
89+
}
90+
91+
uint64_t getFileSize() const {
92+
const_cast<BasicSourceFileInfo *>(this)->populateWithSourceFileIfNeeded();
93+
return FileSize;
94+
}
95+
};
96+
97+
} // namespace swift
98+
99+
#endif // SWIFT_BASIC_BASIC_SOURCE_INFO_H
100+

include/swift/IDE/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/IDE/SourceEntityWalker.h"
2323
#include "swift/Parse/Token.h"
2424
#include "llvm/ADT/StringRef.h"
25+
#include "llvm/Support/VirtualFileSystem.h"
2526
#include <memory>
2627
#include <string>
2728
#include <functional>

include/swift/SIL/SILRemarkStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SWIFT_SIL_SILREMARKSTREAMER_H
2020
#define SWIFT_SIL_SILREMARKSTREAMER_H
2121

22+
#include "swift/Basic/SourceManager.h"
2223
#include "swift/SIL/OptimizationRemark.h"
2324
#include "llvm/Remarks/RemarkStreamer.h"
2425

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/AST/TypeWalker.h"
3737
#include "swift/Basic/Debug.h"
3838
#include "swift/Basic/Defer.h"
39+
#include "swift/Basic/SourceManager.h"
3940
#include "swift/Basic/Statistic.h"
4041
#include "llvm/ADT/GraphTraits.h"
4142
#include "llvm/ADT/DenseMap.h"

lib/AST/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,12 @@ SourceFile::getBasicLocsForDecl(const Decl *D) const {
880880

881881
for (const auto &SRC : D->getRawComment(/*SerializedOK*/false).Comments) {
882882
Result.DocRanges.push_back(std::make_pair(
883-
LineColumn { SRC.StartLine, SRC.StartColumn },
883+
SourcePosition { SRC.StartLine, SRC.StartColumn },
884884
SRC.Range.getByteLength())
885885
);
886886
}
887887

888-
auto setLineColumn = [&SM](LineColumn &Home, SourceLoc Loc) {
888+
auto setLineColumn = [&SM](SourcePosition &Home, SourceLoc Loc) {
889889
if (Loc.isValid()) {
890890
std::tie(Home.Line, Home.Column) = SM.getPresumedLineAndColumnForLoc(Loc);
891891
}

lib/AST/ModuleLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/ModuleLoader.h"
2121
#include "swift/Basic/FileTypes.h"
2222
#include "swift/Basic/Platform.h"
23+
#include "swift/Basic/SourceManager.h"
2324
#include "clang/Frontend/Utils.h"
2425
#include "swift/ClangImporter/ClangImporter.h"
2526

0 commit comments

Comments
 (0)