Skip to content

Commit e1b786a

Browse files
Merge pull request #8503 from adrian-prantl/125613361
Thread llvm::Expected through SwiftASTContext::Reconstruct type
2 parents 7d518af + 50d7430 commit e1b786a

File tree

13 files changed

+476
-354
lines changed

13 files changed

+476
-354
lines changed

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

Lines changed: 142 additions & 139 deletions
Large diffs are not rendered by default.

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
#ifndef liblldb_SwiftASTManipulator_h
1414
#define liblldb_SwiftASTManipulator_h
1515

16-
#include "lldb/Utility/Stream.h"
1716
#include "lldb/Expression/Expression.h"
1817
#include "lldb/Symbol/CompilerType.h"
18+
#include "lldb/Utility/Status.h"
19+
#include "lldb/Utility/Stream.h"
1920

2021
#include "swift/AST/Decl.h"
2122
#include "swift/Basic/SourceLoc.h"
@@ -103,9 +104,11 @@ class SwiftASTManipulatorBase {
103104
struct VariableInfo {
104105
CompilerType GetType() const { return m_type; }
105106
swift::Identifier GetName() const { return m_name; }
107+
VariableMetadata *GetMetadata() const { return m_metadata.get(); }
108+
void TakeMetadata(VariableMetadata *vmd) { m_metadata.reset(vmd); }
106109
swift::VarDecl *GetDecl() const { return m_decl; }
107110
swift::VarDecl::Introducer GetVarIntroducer() const;
108-
bool GetIsCaptureList() const;
111+
bool IsCaptureList() const;
109112
bool IsMetadataPointer() const { return m_name.str().startswith(""); }
110113
bool IsOutermostMetadataPointer() const {
111114
return m_name.str().startswith("$τ_0_");
@@ -118,33 +121,41 @@ class SwiftASTManipulatorBase {
118121
}
119122
bool IsUnboundPack() const { return m_is_unbound_pack; }
120123

121-
VariableInfo() : m_type(), m_name(), m_metadata() {}
122-
123-
VariableInfo(CompilerType &type, swift::Identifier name,
124+
VariableInfo() : m_lookup_error(llvm::Error::success()) {}
125+
VariableInfo(CompilerType type, swift::Identifier name,
124126
VariableMetadataSP metadata,
125127
swift::VarDecl::Introducer introducer,
126128
bool is_capture_list = false, bool is_unbound_pack = false)
127-
: m_type(type), m_name(name), m_var_introducer(introducer),
129+
: m_type(type), m_name(name), m_metadata(metadata),
130+
m_var_introducer(introducer), m_lookup_error(llvm::Error::success()),
128131
m_is_capture_list(is_capture_list),
129-
m_is_unbound_pack(is_unbound_pack), m_metadata(metadata) {}
132+
m_is_unbound_pack(is_unbound_pack) {}
133+
134+
VariableInfo(CompilerType type, swift::Identifier name,
135+
swift::VarDecl *decl)
136+
: m_type(type), m_name(name), m_decl(decl),
137+
m_lookup_error(llvm::Error::success()) {}
130138

131139
void Print(Stream &stream) const;
132140

133141
void SetType(CompilerType new_type) { m_type = new_type; }
142+
void SetLookupError(llvm::Error &&error) {
143+
m_lookup_error = std::move(error);
144+
}
145+
llvm::Error TakeLookupError() { return m_lookup_error.ToError(); }
134146

135147
friend class SwiftASTManipulator;
136148

137149
protected:
138150
CompilerType m_type;
139151
swift::Identifier m_name;
152+
VariableMetadataSP m_metadata;
140153
swift::VarDecl *m_decl = nullptr;
141154
swift::VarDecl::Introducer m_var_introducer =
142155
swift::VarDecl::Introducer::Var;
156+
Status m_lookup_error;
143157
bool m_is_capture_list = false;
144158
bool m_is_unbound_pack = false;
145-
146-
public:
147-
VariableMetadataSP m_metadata;
148159
};
149160

150161
SwiftASTManipulatorBase(swift::SourceFile &source_file,
@@ -205,16 +216,16 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
205216
void FindSpecialNames(llvm::SmallVectorImpl<swift::Identifier> &names,
206217
llvm::StringRef prefix);
207218

208-
swift::VarDecl *AddExternalVariable(swift::Identifier name,
209-
CompilerType &type,
210-
VariableMetadataSP &metadata_sp);
219+
llvm::Expected<swift::VarDecl *>
220+
AddExternalVariable(swift::Identifier name, CompilerType &type,
221+
VariableMetadataSP &metadata_sp);
211222

212223
swift::FuncDecl *GetFunctionToInjectVariableInto(
213224
const SwiftASTManipulator::VariableInfo &variable) const;
214-
swift::VarDecl *GetVarDeclForVariableInFunction(
225+
llvm::Expected<swift::VarDecl *> GetVarDeclForVariableInFunction(
215226
const SwiftASTManipulator::VariableInfo &variable,
216227
swift::FuncDecl *containing_function);
217-
std::optional<swift::Type> GetSwiftTypeForVariable(
228+
llvm::Expected<swift::Type> GetSwiftTypeForVariable(
218229
const SwiftASTManipulator::VariableInfo &variable) const;
219230

220231
bool AddExternalVariables(llvm::MutableArrayRef<VariableInfo> variables);
@@ -234,12 +245,12 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
234245

235246
/// Makes a typealias binding name to type in the scope of the decl_ctx. If
236247
/// decl_ctx is a nullptr this is a global typealias.
237-
swift::TypeAliasDecl *MakeTypealias(swift::Identifier name,
238-
CompilerType &type,
239-
bool make_private = true,
240-
swift::DeclContext *decl_ctx = nullptr);
248+
llvm::Expected<swift::TypeAliasDecl *>
249+
MakeTypealias(swift::Identifier name, CompilerType &type,
250+
bool make_private = true,
251+
swift::DeclContext *decl_ctx = nullptr);
241252

242-
bool FixupResultAfterTypeChecking(Status &error);
253+
llvm::Error FixupResultAfterTypeChecking();
243254

244255
static const char *GetArgumentName() { return "$__lldb_arg"; }
245256
static const char *GetResultName() { return "$__lldb_result"; }

0 commit comments

Comments
 (0)