Skip to content

Commit 1f73ecd

Browse files
authored
Merge pull request #525 from CodaFi/absolutely-path-ological
[NFC] Hide SourceFile::Decls
2 parents 6331cb7 + 42b0be7 commit 1f73ecd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ bool SwiftASTManipulator::RewriteResult() {
540540
// First step, walk the function body converting returns to assignments to
541541
// temp variables + return:
542542

543-
for (swift::Decl *decl : m_source_file.Decls) {
543+
for (swift::Decl *decl : m_source_file.getTopLevelDecls()) {
544544
if (auto top_level_code_decl =
545545
llvm::dyn_cast<swift::TopLevelCodeDecl>(decl)) {
546546
return_finder.SetDeclContext(top_level_code_decl);
@@ -551,8 +551,8 @@ bool SwiftASTManipulator::RewriteResult() {
551551
// Second step, fetch the last expression, and if it is non-null, set it to
552552
// a temp result as well:
553553

554-
if (!m_source_file.Decls.empty()) {
555-
swift::Decl *last_decl = *(m_source_file.Decls.end() - 1);
554+
if (!m_source_file.getTopLevelDecls().empty()) {
555+
swift::Decl *last_decl = *(m_source_file.getTopLevelDecls().end() - 1);
556556

557557
if (auto last_top_level_code_decl =
558558
llvm::dyn_cast<swift::TopLevelCodeDecl>(last_decl)) {
@@ -754,7 +754,7 @@ void SwiftASTManipulator::FindVariableDeclarations(
754754
};
755755

756756
if (m_repl) {
757-
for (swift::Decl *decl : m_source_file.Decls) {
757+
for (swift::Decl *decl : m_source_file.getTopLevelDecls()) {
758758
if (swift::VarDecl *var_decl = llvm::dyn_cast<swift::VarDecl>(decl)) {
759759
if (!var_decl->getName().str().startswith("$")) {
760760
register_one_var(var_decl);
@@ -797,7 +797,7 @@ void SwiftASTManipulator::FindNonVariableDeclarations(
797797
if (!m_repl)
798798
return; // we don't do this for non-REPL expressions... yet
799799

800-
for (swift::Decl *decl : m_source_file.Decls) {
800+
for (swift::Decl *decl : m_source_file.getTopLevelDecls()) {
801801
if (swift::ValueDecl *value_decl = llvm::dyn_cast<swift::ValueDecl>(decl)) {
802802
if (!llvm::isa<swift::VarDecl>(value_decl) && value_decl->hasName()) {
803803
non_variables.push_back(value_decl);
@@ -1125,9 +1125,13 @@ bool SwiftASTManipulator::AddExternalVariables(
11251125

11261126
redirected_var_decl->setImplicit(true);
11271127

1128-
m_source_file.Decls.insert(m_source_file.Decls.begin(), top_level_code);
1129-
m_source_file.Decls.insert(m_source_file.Decls.begin(),
1130-
redirected_var_decl);
1128+
// FIXME: This should use SourceFile::addTopLevelDecl, but if these decls
1129+
// are not inserted at the beginning of the source file then
1130+
// SwiftREPL/FoundationTypes.test fails.
1131+
//
1132+
// See rdar://58355191
1133+
m_source_file.prependTopLevelDecl(top_level_code);
1134+
m_source_file.prependTopLevelDecl(redirected_var_decl);
11311135

11321136
variable.m_decl = redirected_var_decl;
11331137

@@ -1402,7 +1406,7 @@ swift::ValueDecl *SwiftASTManipulator::MakeGlobalTypealias(
14021406
if (make_private) {
14031407
type_alias_decl->overwriteAccess(swift::AccessLevel::Private);
14041408
}
1405-
m_source_file.Decls.push_back(type_alias_decl);
1409+
m_source_file.addTopLevelDecl(type_alias_decl);
14061410
}
14071411

14081412
return type_alias_decl;

0 commit comments

Comments
 (0)