File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -127,3 +127,15 @@ void ClangSyntaxPrinter::printNullability(
127127 if (printKind != NullabilityPrintKind::After)
128128 os << ' ' ;
129129}
130+
131+ void ClangSyntaxPrinter::printSwiftTypeMetadataAccessFunctionCall (
132+ StringRef name) {
133+ os << name << " (0)" ;
134+ }
135+
136+ void ClangSyntaxPrinter::printValueWitnessTableAccessFromTypeMetadata (
137+ StringRef metadataVariable) {
138+ os << " *(reinterpret_cast<" ;
139+ printSwiftImplQualifier ();
140+ os << " ValueWitnessTable **>(" << metadataVariable << " ._0) - 1)" ;
141+ }
Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ class ClangSyntaxPrinter {
7777 static bool isClangKeyword (StringRef name);
7878 static bool isClangKeyword (Identifier name);
7979
80+ // / Print the call expression to the Swift type metadata access function.
81+ void printSwiftTypeMetadataAccessFunctionCall (StringRef name);
82+
83+ // / Print the expression to access the value witness table pointer from the
84+ // / given type metadata variable.
85+ void printValueWitnessTableAccessFromTypeMetadata (StringRef metadataVariable);
86+
8087protected:
8188 raw_ostream &os;
8289};
Original file line number Diff line number Diff line change @@ -115,10 +115,12 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
115115 printer.printBaseName (SD);
116116 os << " () {\n " ;
117117 os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName ()
118- << " ::" << typeMetadataFuncName << " (0);\n " ;
119- os << " auto *vwTable = "
120- " *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - "
121- " 1);\n " ;
118+ << " ::" ;
119+ printer.printSwiftTypeMetadataAccessFunctionCall (typeMetadataFuncName);
120+ os << " ;\n " ;
121+ os << " auto *vwTable = " ;
122+ printer.printValueWitnessTableAccessFromTypeMetadata (" metadata" );
123+ os << " ;\n " ;
122124 os << " vwTable->destroy(_getOpaquePointer(), metadata._0);\n " ;
123125 os << " }\n " ;
124126
@@ -128,10 +130,12 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
128130 printer.printBaseName (SD);
129131 os << " &other) {\n " ;
130132 os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName ()
131- << " ::" << typeMetadataFuncName << " (0);\n " ;
132- os << " auto *vwTable = "
133- " *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - "
134- " 1);\n " ;
133+ << " ::" ;
134+ printer.printSwiftTypeMetadataAccessFunctionCall (typeMetadataFuncName);
135+ os << " ;\n " ;
136+ os << " auto *vwTable = " ;
137+ printer.printValueWitnessTableAccessFromTypeMetadata (" metadata" );
138+ os << " ;\n " ;
135139 os << " vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char "
136140 " *>(other._getOpaquePointer()), metadata._0);\n " ;
137141 os << " }\n " ;
You can’t perform that action at this time.
0 commit comments