//===--- ReflectionContext.h - Swift Type Reflection Context ----*- C++ -*-===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See http://swift.org/LICENSE.txt for license information // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // // Implements the context for allocations and management of structures related // to reflection, such as TypeRefs. // //===----------------------------------------------------------------------===// #ifndef SWIFT_REFLECTION_REFLECTIONCONTEXT_H #define SWIFT_REFLECTION_REFLECTIONCONTEXT_H #include "swift/Remote/MemoryReader.h" #include "swift/Remote/MetadataReader.h" #include "swift/Reflection/Records.h" #include "swift/Reflection/TypeLowering.h" #include "swift/Reflection/TypeRef.h" #include "swift/Reflection/TypeRefBuilder.h" #include #include #include namespace swift { namespace reflection { using swift::remote::MemoryReader; using swift::remote::RemoteAddress; template class ReflectionContext : public remote::MetadataReader { using super = remote::MetadataReader; public: using super::getBuilder; using super::readTypeFromMetadata; using typename super::StoredPointer; public: explicit ReflectionContext(std::shared_ptr reader) : super(std::move(reader)) {} ReflectionContext(const ReflectionContext &other) = delete; ReflectionContext &operator=(const ReflectionContext &other) = delete; MemoryReader &getReader() { return *this->Reader; } void dumpAllSections(std::ostream &OS) { getBuilder().dumpAllSections(); } std::vector> getFieldTypeRefs(const TypeRef *TR) { TypeRefBuilder &Builder = getBuilder(); auto *FD = Builder.getFieldTypeInfo(TR); if (FD == nullptr) return {}; return Builder.getFieldTypeRefs(TR, FD); } std::vector> getFieldTypeRefs(StoredPointer MetadataAddress) { auto TR = readTypeFromMetadata(MetadataAddress); return getFieldTypeRefs(TR); } void addReflectionInfo(ReflectionInfo I) { getBuilder().addReflectionInfo(I); } const TypeInfo *getTypeInfo(const TypeRef *TR) { return getBuilder().getTypeConverter().getTypeInfo(TR); } }; } // end namespace reflection } // end namespace swift #endif // SWIFT_REFLECTION_REFLECTIONCONTEXT_H