diff --git a/bindings/python/TypeBindings.cpp b/bindings/python/TypeBindings.cpp index 86d8ec9a1..14c30ee8d 100644 --- a/bindings/python/TypeBindings.cpp +++ b/bindings/python/TypeBindings.cpp @@ -125,7 +125,8 @@ void registerTypes(py::module_& m) { .def_readwrite("printAKA", &TypePrintingOptions::printAKA) .def_readwrite("anonymousTypeStyle", &TypePrintingOptions::anonymousTypeStyle) .def_readwrite("skipScopedTypeNames", &TypePrintingOptions::skipScopedTypeNames) - .def_readwrite("fullEnumType", &TypePrintingOptions::anonymousTypeStyle); + .def_readwrite("fullEnumType", &TypePrintingOptions::fullEnumType) + .def_readwrite("skipTypeDefs", &TypePrintingOptions::skipTypeDefs); py::enum_(typePrintingOptions, "AnonymousTypeStyle") .value("SystemName", TypePrintingOptions::SystemName) diff --git a/include/slang/ast/types/TypePrinter.h b/include/slang/ast/types/TypePrinter.h index 2cc3b24e5..f5aed7a61 100644 --- a/include/slang/ast/types/TypePrinter.h +++ b/include/slang/ast/types/TypePrinter.h @@ -33,6 +33,9 @@ struct SLANG_EXPORT TypePrintingOptions { /// Skip over scoped type names completely. bool skipScopedTypeNames = false; + /// Skip expanding typedefs. + bool skipTypeDefs = false; + /// Include the enum's base type. bool fullEnumType = false; diff --git a/source/ast/types/TypePrinter.cpp b/source/ast/types/TypePrinter.cpp index 75abeb717..bffa527e4 100644 --- a/source/ast/types/TypePrinter.cpp +++ b/source/ast/types/TypePrinter.cpp @@ -390,17 +390,25 @@ void TypePrinter::visit(const VirtualInterfaceType& type, std::string_view) { } void TypePrinter::visit(const TypeAliasType& type, std::string_view overrideName) { + std::string downstreamOverrideName; if (!overrideName.empty()) { - type.targetType.getType().visit(*this, overrideName); + downstreamOverrideName = overrideName; } else if (options.elideScopeNames || options.anonymousTypeStyle == TypePrintingOptions::FriendlyName) { - type.targetType.getType().visit(*this, type.name); + downstreamOverrideName = type.name; } else { std::string path = getLexicalPath(type.getParentScope()); path.append(type.name); - type.targetType.getType().visit(*this, path); + downstreamOverrideName = path; + } + + if (options.skipTypeDefs) { + buffer->append(downstreamOverrideName); + } + else { + type.targetType.getType().visit(*this, downstreamOverrideName); } }