Skip to content

Commit 193cf0d

Browse files
committed
Code review feedback from @davidungar
1 parent 4a62800 commit 193cf0d

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ class SourceFile final : public FileUnit {
236236
}
237237

238238
/// Add a hoisted declaration. See Decl::isHoisted().
239-
void addHoistedDecl(Decl *d) {
240-
Hoisted.push_back(d);
241-
}
239+
void addHoistedDecl(Decl *d);
242240

243241
/// Retrieves an immutable view of the list of top-level decls in this file.
244242
ArrayRef<Decl *> getTopLevelDecls() const;

lib/AST/Module.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,12 @@ bool SourceFile::hasDelayedBodyParsing() const {
23372337
return true;
23382338
}
23392339

2340+
/// Add a hoisted declaration. See Decl::isHoisted().
2341+
void SourceFile::addHoistedDecl(Decl *d) {
2342+
assert(d->isHoisted());
2343+
Hoisted.push_back(d);
2344+
}
2345+
23402346
ArrayRef<Decl *> SourceFile::getTopLevelDecls() const {
23412347
auto &ctx = getASTContext();
23422348
auto *mutableThis = const_cast<SourceFile *>(this);

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,24 @@ namespace {
104104
template <typename T>
105105
ParserResult<T>
106106
fixupParserResult(T *D) {
107-
if (movedToTopLevel()) {
108-
D->setHoisted();
109-
SF->addHoistedDecl(D);
110-
getDebuggerClient()->didGlobalize(D);
111-
}
107+
if (movedToTopLevel())
108+
hoistDecl(D);
112109
return ParserResult<T>(D);
113110
}
114111

115112
template <typename T>
116113
ParserResult<T>
117114
fixupParserResult(ParserStatus Status, T *D) {
118-
if (movedToTopLevel()) {
119-
D->setHoisted();
120-
SF->addHoistedDecl(D);
121-
getDebuggerClient()->didGlobalize(D);
122-
}
115+
if (movedToTopLevel())
116+
hoistDecl(D);
123117
return makeParserResult(Status, D);
124118
}
125119

126120
// The destructor doesn't need to do anything, the CC's destructor will
127121
// pop the context if we set it.
128122
~DebuggerContextChange () {}
129-
protected:
130-
123+
124+
private:
131125
DebuggerClient *getDebuggerClient() {
132126
ModuleDecl *M = P.CurDeclContext->getParentModule();
133127
return M->getDebugClient();
@@ -152,6 +146,13 @@ namespace {
152146
SF = P.CurDeclContext->getParentSourceFile();
153147
CC.emplace(P, SF);
154148
}
149+
150+
template<typename T>
151+
void hoistDecl(T *D) {
152+
D->setHoisted();
153+
SF->addHoistedDecl(D);
154+
getDebuggerClient()->didGlobalize(D);
155+
}
155156
};
156157
} // end anonymous namespace
157158

0 commit comments

Comments
 (0)