@@ -540,7 +540,7 @@ bool SwiftASTManipulator::RewriteResult() {
540
540
// First step, walk the function body converting returns to assignments to
541
541
// temp variables + return:
542
542
543
- for (swift::Decl *decl : m_source_file.Decls ) {
543
+ for (swift::Decl *decl : m_source_file.getTopLevelDecls () ) {
544
544
if (auto top_level_code_decl =
545
545
llvm::dyn_cast<swift::TopLevelCodeDecl>(decl)) {
546
546
return_finder.SetDeclContext (top_level_code_decl);
@@ -551,8 +551,8 @@ bool SwiftASTManipulator::RewriteResult() {
551
551
// Second step, fetch the last expression, and if it is non-null, set it to
552
552
// a temp result as well:
553
553
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 );
556
556
557
557
if (auto last_top_level_code_decl =
558
558
llvm::dyn_cast<swift::TopLevelCodeDecl>(last_decl)) {
@@ -754,7 +754,7 @@ void SwiftASTManipulator::FindVariableDeclarations(
754
754
};
755
755
756
756
if (m_repl) {
757
- for (swift::Decl *decl : m_source_file.Decls ) {
757
+ for (swift::Decl *decl : m_source_file.getTopLevelDecls () ) {
758
758
if (swift::VarDecl *var_decl = llvm::dyn_cast<swift::VarDecl>(decl)) {
759
759
if (!var_decl->getName ().str ().startswith (" $" )) {
760
760
register_one_var (var_decl);
@@ -797,7 +797,7 @@ void SwiftASTManipulator::FindNonVariableDeclarations(
797
797
if (!m_repl)
798
798
return ; // we don't do this for non-REPL expressions... yet
799
799
800
- for (swift::Decl *decl : m_source_file.Decls ) {
800
+ for (swift::Decl *decl : m_source_file.getTopLevelDecls () ) {
801
801
if (swift::ValueDecl *value_decl = llvm::dyn_cast<swift::ValueDecl>(decl)) {
802
802
if (!llvm::isa<swift::VarDecl>(value_decl) && value_decl->hasName ()) {
803
803
non_variables.push_back (value_decl);
@@ -1125,9 +1125,13 @@ bool SwiftASTManipulator::AddExternalVariables(
1125
1125
1126
1126
redirected_var_decl->setImplicit (true );
1127
1127
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);
1131
1135
1132
1136
variable.m_decl = redirected_var_decl;
1133
1137
@@ -1402,7 +1406,7 @@ swift::ValueDecl *SwiftASTManipulator::MakeGlobalTypealias(
1402
1406
if (make_private) {
1403
1407
type_alias_decl->overwriteAccess (swift::AccessLevel::Private);
1404
1408
}
1405
- m_source_file.Decls . push_back (type_alias_decl);
1409
+ m_source_file.addTopLevelDecl (type_alias_decl);
1406
1410
}
1407
1411
1408
1412
return type_alias_decl;
0 commit comments