MCPcopy Create free account
hub / github.com/KDE/kdevelop / stripType

Function stripType

plugins/clang/codegen/codegenhelper.cpp:198–304  ·  view source on GitHub ↗

Returns a type that has all template types replaced with DelayedType's that have their template default parameters stripped away, and all scope prefixes removed that are redundant within the given context The returned type should not actively be used in the type-system, but rather only for displaying.

Source from the content-addressed store, hash-verified

196///and all scope prefixes removed that are redundant within the given context
197///The returned type should not actively be used in the type-system, but rather only for displaying.
198AbstractType::Ptr stripType(const AbstractType::Ptr& type, DUContext* ctx)
199{
200 if (!type) {
201 return AbstractType::Ptr();
202 }
203
204 struct ShortenTemplateDefaultParameter
205 : public TypeExchanger
206 {
207 DUContext* ctx;
208 explicit ShortenTemplateDefaultParameter(DUContext* _ctx)
209 : ctx(_ctx) {
210 Q_ASSERT(ctx);
211 }
212
213 AbstractType::Ptr exchange(const AbstractType::Ptr& type) override {
214 if (!type) {
215 return type;
216 }
217
218 AbstractType::Ptr newType(type->clone());
219
220 if (const auto * idType = dynamic_cast<const IdentifiedType*>(type.data())) {
221 Declaration* decl = idType->declaration(ctx->topContext());
222 if (!decl) {
223 return type;
224 }
225
226 QualifiedIdentifier newTypeName;
227
228#if 0 // from oldcpp
229 if (TemplateDeclaration * tempDecl = dynamic_cast<TemplateDeclaration*>(decl)) {
230 if (decl->context()->type() == DUContext::Class && decl->context()->owner()) {
231 //Strip template default-parameters from the parent class
232 AbstractType::Ptr parentType = stripType(decl->context()->owner()->abstractType(), ctx);
233 if (parentType) {
234 newTypeName = QualifiedIdentifier(parentType->toString(), true);
235 }
236 }
237 if (newTypeName.isEmpty()) {
238 newTypeName = decl->context()->scopeIdentifier(true);
239 }
240
241 Identifier currentId;
242 if (!idType->qualifiedIdentifier().isEmpty()) {
243 currentId = idType->qualifiedIdentifier().last();
244 }
245 currentId.clearTemplateIdentifiers();
246
247 InstantiationInformation instantiationInfo = tempDecl->instantiatedWith().information();
248 InstantiationInformation newInformation(instantiationInfo);
249 newInformation.templateParametersList().clear();
250
251 for (uint neededParameters = 0; neededParameters < instantiationInfo.templateParametersSize(); ++neededParameters) {
252 newInformation.templateParametersList().append(instantiationInfo.templateParameters()[neededParameters]);
253 AbstractType::Ptr niceParam = stripType(instantiationInfo.templateParameters()[neededParameters].abstractType(), ctx);
254 if (niceParam) {
255 currentId.appendTemplateIdentifier(IndexedTypeIdentifier(niceParam->toString(), true));

Callers 2

exchangeMethod · 0.85
shortenedTypeIdentifierFunction · 0.85

Calls 1

exchangeMethod · 0.45

Tested by

no test coverage detected