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(
127
127
if (printKind != NullabilityPrintKind::After)
128
128
os << ' ' ;
129
129
}
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 {
77
77
static bool isClangKeyword (StringRef name);
78
78
static bool isClangKeyword (Identifier name);
79
79
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
+
80
87
protected:
81
88
raw_ostream &os;
82
89
};
Original file line number Diff line number Diff line change @@ -115,10 +115,12 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
115
115
printer.printBaseName (SD);
116
116
os << " () {\n " ;
117
117
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 " ;
122
124
os << " vwTable->destroy(_getOpaquePointer(), metadata._0);\n " ;
123
125
os << " }\n " ;
124
126
@@ -128,10 +130,12 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
128
130
printer.printBaseName (SD);
129
131
os << " &other) {\n " ;
130
132
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 " ;
135
139
os << " vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char "
136
140
" *>(other._getOpaquePointer()), metadata._0);\n " ;
137
141
os << " }\n " ;
You can’t perform that action at this time.
0 commit comments