Skip to content

Commit

Permalink
Adds a type printing option so that type printer will avoid decending…
Browse files Browse the repository at this point in the history
… into the typedefs. (#1176)
  • Loading branch information
Badhi authored Nov 17, 2024
1 parent 5d55b0a commit 3029cf4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bindings/python/TypeBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(typePrintingOptions, "AnonymousTypeStyle")
.value("SystemName", TypePrintingOptions::SystemName)
Expand Down
3 changes: 3 additions & 0 deletions include/slang/ast/types/TypePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 11 additions & 3 deletions source/ast/types/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,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);
}
}

Expand Down

0 comments on commit 3029cf4

Please sign in to comment.