@@ -22,31 +22,31 @@ std::string constructName(const swift::DeclName& declName) {
22
22
}
23
23
} // namespace
24
24
25
- std::optional<codeql::ConcreteFuncDecl> DeclVisitor::translateFuncDecl (
26
- const swift::FuncDecl& decl) {
27
- if (auto entry = createNamedEntry (decl)) {
25
+ std::variant<codeql::ConcreteFuncDecl, codeql::ConcreteFuncDeclsTrap>
26
+ DeclVisitor::translateFuncDecl (const swift::FuncDecl& decl) {
27
+ auto ret = createNamedEntryOr<ConcreteFuncDeclsTrap>(decl);
28
+ if (auto entry = get_if<ConcreteFuncDecl>(&ret)) {
28
29
fillAbstractFunctionDecl (decl, *entry);
29
- return entry;
30
30
}
31
- return std::nullopt ;
31
+ return ret ;
32
32
}
33
33
34
- std::optional<codeql::ConstructorDecl> DeclVisitor::translateConstructorDecl (
35
- const swift::ConstructorDecl& decl) {
36
- if (auto entry = createNamedEntry (decl)) {
34
+ std::variant<codeql::ConstructorDecl, codeql::ConstructorDeclsTrap>
35
+ DeclVisitor::translateConstructorDecl (const swift::ConstructorDecl& decl) {
36
+ auto ret = createNamedEntryOr<ConstructorDeclsTrap>(decl);
37
+ if (auto entry = get_if<ConstructorDecl>(&ret)) {
37
38
fillAbstractFunctionDecl (decl, *entry);
38
- return entry;
39
39
}
40
- return std::nullopt ;
40
+ return ret ;
41
41
}
42
42
43
- std::optional<codeql::DestructorDecl> DeclVisitor::translateDestructorDecl (
44
- const swift::DestructorDecl& decl) {
45
- if (auto entry = createNamedEntry (decl)) {
43
+ std::variant<codeql::DestructorDecl, codeql::DestructorDeclsTrap>
44
+ DeclVisitor::translateDestructorDecl (const swift::DestructorDecl& decl) {
45
+ auto ret = createNamedEntryOr<DestructorDeclsTrap>(decl);
46
+ if (auto entry = get_if<DestructorDecl>(&ret)) {
46
47
fillAbstractFunctionDecl (decl, *entry);
47
- return entry;
48
48
}
49
- return std::nullopt ;
49
+ return ret ;
50
50
}
51
51
52
52
codeql::PrefixOperatorDecl DeclVisitor::translatePrefixOperatorDecl (
@@ -124,37 +124,40 @@ std::optional<codeql::ConcreteVarDecl> DeclVisitor::translateVarDecl(const swift
124
124
return entry;
125
125
}
126
126
127
- std::optional<codeql::StructDecl> DeclVisitor::translateStructDecl (const swift::StructDecl& decl) {
128
- if (auto entry = createNamedEntry (decl)) {
127
+ std::variant<codeql::StructDecl, codeql::StructDeclsTrap> DeclVisitor::translateStructDecl (
128
+ const swift::StructDecl& decl) {
129
+ auto ret = createNamedEntryOr<StructDeclsTrap>(decl);
130
+ if (auto entry = get_if<StructDecl>(&ret)) {
129
131
fillNominalTypeDecl (decl, *entry);
130
- return entry;
131
132
}
132
- return std::nullopt ;
133
+ return ret ;
133
134
}
134
135
135
- std::optional<codeql::ClassDecl> DeclVisitor::translateClassDecl (const swift::ClassDecl& decl) {
136
- if (auto entry = createNamedEntry (decl)) {
136
+ std::variant<codeql::ClassDecl, codeql::ClassDeclsTrap> DeclVisitor::translateClassDecl (
137
+ const swift::ClassDecl& decl) {
138
+ auto ret = createNamedEntryOr<ClassDeclsTrap>(decl);
139
+ if (auto entry = get_if<ClassDecl>(&ret)) {
137
140
fillNominalTypeDecl (decl, *entry);
138
- return entry;
139
141
}
140
- return std::nullopt ;
142
+ return ret ;
141
143
}
142
144
143
- std::optional<codeql::EnumDecl> DeclVisitor::translateEnumDecl (const swift::EnumDecl& decl) {
144
- if (auto entry = createNamedEntry (decl)) {
145
+ std::variant<codeql::EnumDecl, codeql::EnumDeclsTrap> DeclVisitor::translateEnumDecl (
146
+ const swift::EnumDecl& decl) {
147
+ auto ret = createNamedEntryOr<EnumDeclsTrap>(decl);
148
+ if (auto entry = get_if<EnumDecl>(&ret)) {
145
149
fillNominalTypeDecl (decl, *entry);
146
- return entry;
147
150
}
148
- return std::nullopt ;
151
+ return ret ;
149
152
}
150
153
151
- std::optional <codeql::ProtocolDecl> DeclVisitor::translateProtocolDecl (
154
+ std::variant <codeql::ProtocolDecl, codeql::ProtocolDeclsTrap > DeclVisitor::translateProtocolDecl (
152
155
const swift::ProtocolDecl& decl) {
153
- if (auto entry = createNamedEntry (decl)) {
156
+ auto ret = createNamedEntryOr<ProtocolDeclsTrap>(decl);
157
+ if (auto entry = get_if<ProtocolDecl>(&ret)) {
154
158
fillNominalTypeDecl (decl, *entry);
155
- return entry;
156
159
}
157
- return std::nullopt ;
160
+ return ret ;
158
161
}
159
162
160
163
codeql::EnumCaseDecl DeclVisitor::translateEnumCaseDecl (const swift::EnumCaseDecl& decl) {
@@ -163,18 +166,17 @@ codeql::EnumCaseDecl DeclVisitor::translateEnumCaseDecl(const swift::EnumCaseDec
163
166
return entry;
164
167
}
165
168
166
- std::optional <codeql::EnumElementDecl> DeclVisitor::translateEnumElementDecl (
167
- const swift::EnumElementDecl& decl) {
168
- auto entry = createNamedEntry (decl);
169
- if (! entry) {
170
- return std::nullopt;
171
- }
172
- entry->name = decl. getNameStr (). str ( );
173
- if (decl. hasParameterList ()) {
174
- entry-> params = dispatcher_. fetchRepeatedLabels (* decl. getParameterList () );
169
+ std::variant <codeql::EnumElementDecl, codeql::EnumElementDeclsTrap>
170
+ DeclVisitor::translateEnumElementDecl ( const swift::EnumElementDecl& decl) {
171
+ auto ret = createNamedEntryOr<EnumElementDeclsTrap> (decl);
172
+ std::visit ([&]( auto & entry) { entry. name = decl. getNameStr (). str (); }, ret);
173
+ if ( auto entry = get_if<EnumElementDecl>(&ret)) {
174
+ if (decl. hasParameterList ()) {
175
+ entry->params = dispatcher_. fetchRepeatedLabels (*decl. getParameterList () );
176
+ }
177
+ fillValueDecl ( decl, *entry );
175
178
}
176
- fillValueDecl (decl, *entry);
177
- return entry;
179
+ return ret;
178
180
}
179
181
180
182
codeql::GenericTypeParamDecl DeclVisitor::translateGenericTypeParamDecl (
@@ -185,46 +187,45 @@ codeql::GenericTypeParamDecl DeclVisitor::translateGenericTypeParamDecl(
185
187
return entry;
186
188
}
187
189
188
- std::optional<codeql::AssociatedTypeDecl> DeclVisitor::translateAssociatedTypeDecl (
189
- const swift::AssociatedTypeDecl& decl) {
190
- if (auto entry = createNamedEntry (decl)) {
190
+ std::variant<codeql::AssociatedTypeDecl, codeql::AssociatedTypeDeclsTrap>
191
+ DeclVisitor::translateAssociatedTypeDecl (const swift::AssociatedTypeDecl& decl) {
192
+ auto ret = createNamedEntryOr<AssociatedTypeDeclsTrap>(decl);
193
+ if (auto entry = get_if<AssociatedTypeDecl>(&ret)) {
191
194
fillTypeDecl (decl, *entry);
192
- return entry;
193
195
}
194
- return std::nullopt ;
196
+ return ret ;
195
197
}
196
198
197
- std::optional <codeql::TypeAliasDecl> DeclVisitor::translateTypeAliasDecl (
199
+ std::variant <codeql::TypeAliasDecl, codeql::TypeAliasDeclsTrap > DeclVisitor::translateTypeAliasDecl (
198
200
const swift::TypeAliasDecl& decl) {
199
- if (auto entry = createNamedEntry (decl)) {
201
+ auto ret = createNamedEntryOr<TypeAliasDeclsTrap>(decl);
202
+ if (auto entry = get_if<TypeAliasDecl>(&ret)) {
200
203
fillTypeDecl (decl, *entry);
201
- return entry;
202
204
}
203
- return std::nullopt ;
205
+ return ret ;
204
206
}
205
207
206
- std::optional <codeql::AccessorDecl> DeclVisitor::translateAccessorDecl (
208
+ std::variant <codeql::AccessorDecl, codeql::AccessorDeclsTrap > DeclVisitor::translateAccessorDecl (
207
209
const swift::AccessorDecl& decl) {
208
- auto entry = createNamedEntry (decl);
209
- if (! entry) {
210
- return std::nullopt;
211
- }
212
- switch (decl. getAccessorKind ()) {
213
- case swift::AccessorKind::Get:
214
- entry-> is_getter = true ;
215
- break ;
216
- case swift::AccessorKind::Set:
217
- entry-> is_setter = true ;
218
- break ;
219
- case swift::AccessorKind::WillSet:
220
- entry-> is_will_set = true ;
221
- break ;
222
- case swift::AccessorKind::DidSet:
223
- entry-> is_did_set = true ;
224
- break ;
210
+ auto ret = createNamedEntryOr<AccessorDeclsTrap> (decl);
211
+ if (auto entry = get_if<AccessorDecl>(&ret) ) {
212
+ switch (decl. getAccessorKind ()) {
213
+ case swift::AccessorKind::Get:
214
+ entry-> is_getter = true ;
215
+ break ;
216
+ case swift::AccessorKind::Set:
217
+ entry-> is_setter = true ;
218
+ break ;
219
+ case swift::AccessorKind::WillSet:
220
+ entry-> is_will_set = true ;
221
+ break ;
222
+ case swift::AccessorKind::DidSet:
223
+ entry-> is_did_set = true ;
224
+ break ;
225
+ }
226
+ fillAbstractFunctionDecl (decl, *entry) ;
225
227
}
226
- fillAbstractFunctionDecl (decl, *entry);
227
- return entry;
228
+ return ret;
228
229
}
229
230
230
231
std::optional<codeql::SubscriptDecl> DeclVisitor::translateSubscriptDecl (
0 commit comments