Skip to content

[NFC] Hide SourceFile::Decls #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ bool SwiftASTManipulator::RewriteResult() {
// First step, walk the function body converting returns to assignments to
// temp variables + return:

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

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

if (auto last_top_level_code_decl =
llvm::dyn_cast<swift::TopLevelCodeDecl>(last_decl)) {
Expand Down Expand Up @@ -754,7 +754,7 @@ void SwiftASTManipulator::FindVariableDeclarations(
};

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

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

redirected_var_decl->setImplicit(true);

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

variable.m_decl = redirected_var_decl;

Expand Down Expand Up @@ -1402,7 +1406,7 @@ swift::ValueDecl *SwiftASTManipulator::MakeGlobalTypealias(
if (make_private) {
type_alias_decl->overwriteAccess(swift::AccessLevel::Private);
}
m_source_file.Decls.push_back(type_alias_decl);
m_source_file.addTopLevelDecl(type_alias_decl);
}

return type_alias_decl;
Expand Down