|
17 | 17 | #include "swift/Basic/LLVM.h"
|
18 | 18 | #include "swift/Basic/Lazy.h"
|
19 | 19 | #include "swift/Demangling/Demangler.h"
|
| 20 | +#include "swift/Demangling/TypeDecoder.h" |
20 | 21 | #include "swift/Runtime/Concurrent.h"
|
21 | 22 | #include "swift/Runtime/HeapObject.h"
|
22 | 23 | #include "swift/Runtime/Metadata.h"
|
@@ -244,3 +245,127 @@ _getTypeByName(const char *typeName, size_t typeNameLength) {
|
244 | 245 | llvm::StringRef name(typeName, typeNameLength);
|
245 | 246 | return _classByName(name);
|
246 | 247 | }
|
| 248 | + |
| 249 | +#pragma mark Metadata lookup via mangled name |
| 250 | + |
| 251 | +namespace { |
| 252 | +/// Constructs metadata by decoding a mangled type name, for use with |
| 253 | +/// \c TypeDecoder. |
| 254 | +class DecodedMetadataBuilder { |
| 255 | +public: |
| 256 | + using BuiltType = const Metadata *; |
| 257 | + using BuiltNominalTypeDecl = const NominalTypeDescriptor *; |
| 258 | + |
| 259 | + BuiltNominalTypeDecl createNominalTypeDecl( |
| 260 | + const Demangle::NodePointer &node) const { |
| 261 | + // FIXME: Implement. |
| 262 | + return BuiltNominalTypeDecl(); |
| 263 | + } |
| 264 | + |
| 265 | + BuiltType createNominalType(BuiltNominalTypeDecl typeDecl, |
| 266 | + BuiltType parent) const { |
| 267 | + // FIXME: Implement. |
| 268 | + return BuiltType(); |
| 269 | + } |
| 270 | + |
| 271 | + BuiltType createBoundGenericType(BuiltNominalTypeDecl typeDecl, |
| 272 | + ArrayRef<BuiltType> genericArgs, |
| 273 | + BuiltType parent) const { |
| 274 | + // FIXME: Implement. |
| 275 | + return BuiltType(); |
| 276 | + } |
| 277 | + |
| 278 | + BuiltType createBuiltinType(StringRef mangledName) const { |
| 279 | + // FIXME: Implement. |
| 280 | + return BuiltType(); |
| 281 | + } |
| 282 | + |
| 283 | + BuiltType createMetatypeType(BuiltType instance, bool wasAbstract) const { |
| 284 | + // FIXME: Implement. |
| 285 | + return BuiltType(); |
| 286 | + } |
| 287 | + |
| 288 | + BuiltType createExistentialMetatypeType(BuiltType instance) const { |
| 289 | + // FIXME: Implement. |
| 290 | + return BuiltType(); |
| 291 | + } |
| 292 | + |
| 293 | + BuiltType createProtocolCompositionType(ArrayRef<BuiltType> protocols, |
| 294 | + bool hasExplicitAnyObject) const { |
| 295 | + // FIXME: Implement. |
| 296 | + // NOTE: protocols.back() could be a class type. Clean up this API. |
| 297 | + return BuiltType(); |
| 298 | + } |
| 299 | + |
| 300 | + BuiltType createProtocolType(StringRef mangledName, StringRef moduleName, |
| 301 | + StringRef privateDiscriminator, |
| 302 | + StringRef name) const { |
| 303 | + // FIXME: Implement. |
| 304 | + return BuiltType(); |
| 305 | + } |
| 306 | + |
| 307 | + BuiltType createGenericTypeParameterType(unsigned depth, |
| 308 | + unsigned index) const { |
| 309 | + // FIXME: Implement. |
| 310 | + return BuiltType(); |
| 311 | + } |
| 312 | + |
| 313 | + BuiltType createFunctionType( |
| 314 | + ArrayRef<Demangle::FunctionParam<BuiltType>> params, |
| 315 | + BuiltType result, FunctionTypeFlags flags) const { |
| 316 | + // FIXME: Implement. |
| 317 | + return BuiltType(); |
| 318 | + } |
| 319 | + |
| 320 | + BuiltType createTupleType(ArrayRef<BuiltType> elements, |
| 321 | + std::string labels, |
| 322 | + bool variadic) const { |
| 323 | + // TODO: 'variadic' should no longer exist |
| 324 | + return swift_getTupleTypeMetadata(elements.size(), elements.data(), |
| 325 | + labels.empty() ? nullptr : labels.c_str(), |
| 326 | + /*proposedWitnesses=*/nullptr); |
| 327 | + } |
| 328 | + |
| 329 | + BuiltType createDependentMemberType(StringRef name, BuiltType base, |
| 330 | + BuiltType protocol) const { |
| 331 | + // FIXME: Implement. |
| 332 | + return BuiltType(); |
| 333 | + } |
| 334 | + |
| 335 | + BuiltType createUnownedStorageType(BuiltType base) const { |
| 336 | + // FIXME: Implement. |
| 337 | + return BuiltType(); |
| 338 | + } |
| 339 | + |
| 340 | + BuiltType createUnmanagedStorageType(BuiltType base) const { |
| 341 | + // FIXME: Implement. |
| 342 | + return BuiltType(); |
| 343 | + } |
| 344 | + |
| 345 | + BuiltType createWeakStorageType(BuiltType base) const { |
| 346 | + // FIXME: Implement. |
| 347 | + return BuiltType(); |
| 348 | + } |
| 349 | + |
| 350 | + BuiltType createSILBoxType(BuiltType base) const { |
| 351 | + // FIXME: Implement. |
| 352 | + return BuiltType(); |
| 353 | + } |
| 354 | +}; |
| 355 | + |
| 356 | +} |
| 357 | + |
| 358 | +SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL |
| 359 | +const Metadata * _Nullable |
| 360 | +swift_getTypeByMangledName(const char *typeNameStart, size_t typeNameLength) { |
| 361 | + // Demangle the type name. |
| 362 | + llvm::StringRef typeName(typeNameStart, typeNameLength); |
| 363 | + Demangler demangler; |
| 364 | + NodePointer node = demangler.demangleType(typeName); |
| 365 | + if (!node) { |
| 366 | + return nullptr; |
| 367 | + } |
| 368 | + |
| 369 | + DecodedMetadataBuilder builder; |
| 370 | + return Demangle::decodeMangledType(builder, node); |
| 371 | +} |
0 commit comments