13
13
#ifndef liblldb_SwiftASTManipulator_h
14
14
#define liblldb_SwiftASTManipulator_h
15
15
16
- #include " lldb/Utility/Stream.h"
17
16
#include " lldb/Expression/Expression.h"
18
17
#include " lldb/Symbol/CompilerType.h"
18
+ #include " lldb/Utility/Status.h"
19
+ #include " lldb/Utility/Stream.h"
19
20
20
21
#include " swift/AST/Decl.h"
21
22
#include " swift/Basic/SourceLoc.h"
@@ -103,9 +104,11 @@ class SwiftASTManipulatorBase {
103
104
struct VariableInfo {
104
105
CompilerType GetType () const { return m_type; }
105
106
swift::Identifier GetName () const { return m_name; }
107
+ VariableMetadata *GetMetadata () const { return m_metadata.get (); }
108
+ void TakeMetadata (VariableMetadata *vmd) { m_metadata.reset (vmd); }
106
109
swift::VarDecl *GetDecl () const { return m_decl; }
107
110
swift::VarDecl::Introducer GetVarIntroducer () const ;
108
- bool GetIsCaptureList () const ;
111
+ bool IsCaptureList () const ;
109
112
bool IsMetadataPointer () const { return m_name.str ().startswith (" $τ" ); }
110
113
bool IsOutermostMetadataPointer () const {
111
114
return m_name.str ().startswith (" $τ_0_" );
@@ -118,33 +121,41 @@ class SwiftASTManipulatorBase {
118
121
}
119
122
bool IsUnboundPack () const { return m_is_unbound_pack; }
120
123
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,
124
126
VariableMetadataSP metadata,
125
127
swift::VarDecl::Introducer introducer,
126
128
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()),
128
131
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()) {}
130
138
131
139
void Print (Stream &stream) const ;
132
140
133
141
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 (); }
134
146
135
147
friend class SwiftASTManipulator ;
136
148
137
149
protected:
138
150
CompilerType m_type;
139
151
swift::Identifier m_name;
152
+ VariableMetadataSP m_metadata;
140
153
swift::VarDecl *m_decl = nullptr ;
141
154
swift::VarDecl::Introducer m_var_introducer =
142
155
swift::VarDecl::Introducer::Var;
156
+ Status m_lookup_error;
143
157
bool m_is_capture_list = false ;
144
158
bool m_is_unbound_pack = false ;
145
-
146
- public:
147
- VariableMetadataSP m_metadata;
148
159
};
149
160
150
161
SwiftASTManipulatorBase (swift::SourceFile &source_file,
@@ -205,16 +216,16 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
205
216
void FindSpecialNames (llvm::SmallVectorImpl<swift::Identifier> &names,
206
217
llvm::StringRef prefix);
207
218
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);
211
222
212
223
swift::FuncDecl *GetFunctionToInjectVariableInto (
213
224
const SwiftASTManipulator::VariableInfo &variable) const ;
214
- swift::VarDecl *GetVarDeclForVariableInFunction (
225
+ llvm::Expected< swift::VarDecl *> GetVarDeclForVariableInFunction (
215
226
const SwiftASTManipulator::VariableInfo &variable,
216
227
swift::FuncDecl *containing_function);
217
- std::optional <swift::Type> GetSwiftTypeForVariable (
228
+ llvm::Expected <swift::Type> GetSwiftTypeForVariable (
218
229
const SwiftASTManipulator::VariableInfo &variable) const ;
219
230
220
231
bool AddExternalVariables (llvm::MutableArrayRef<VariableInfo> variables);
@@ -234,12 +245,12 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
234
245
235
246
// / Makes a typealias binding name to type in the scope of the decl_ctx. If
236
247
// / 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 );
241
252
242
- bool FixupResultAfterTypeChecking (Status &error );
253
+ llvm::Error FixupResultAfterTypeChecking ();
243
254
244
255
static const char *GetArgumentName () { return " $__lldb_arg" ; }
245
256
static const char *GetResultName () { return " $__lldb_result" ; }
0 commit comments