Skip to content

Commit

Permalink
Cleanup Type-String Generation in slice2swift (zeroc-ice#2789)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Sep 30, 2024
1 parent 2846e40 commit e00f874
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 172 deletions.
34 changes: 17 additions & 17 deletions cpp/src/slice2swift/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ bool
Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule));
const string traits = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + "Traits");
const string name = fixIdent(getRelativeTypeString(p, swiftModule));
const string traits = fixIdent(getRelativeTypeString(p, swiftModule) + "Traits");

StringList allIds = p->ids();
ostringstream ids;
Expand Down Expand Up @@ -339,7 +339,7 @@ bool
Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);

ExceptionPtr base = p->base();

Expand Down Expand Up @@ -387,7 +387,7 @@ Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
out << nl << "open class " << fixIdent(name) << ": ";
if (base)
{
out << fixIdent(getUnqualified(getAbsolute(base), swiftModule));
out << fixIdent(getRelativeTypeString(base, swiftModule));
}
else
{
Expand Down Expand Up @@ -489,7 +489,7 @@ bool
Gen::TypesVisitor::visitStructStart(const StructPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule));
const string name = fixIdent(getRelativeTypeString(p, swiftModule));
bool isLegalKeyType = Dictionary::isLegalKeyType(p);
const DataMemberList members = p->dataMembers();
const string optionalFormat = getOptionalFormat(p);
Expand Down Expand Up @@ -606,7 +606,7 @@ void
Gen::TypesVisitor::visitSequence(const SequencePtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);

const TypePtr type = p->type();
BuiltinPtr builtin = dynamic_pointer_cast<Builtin>(p->type());
Expand Down Expand Up @@ -763,7 +763,7 @@ void
Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);

const string keyType = typeToString(p->keyType(), p, p->keyMetadata(), false);
const string valueType = typeToString(p->valueType(), p, p->valueMetadata(), false);
Expand Down Expand Up @@ -914,7 +914,7 @@ void
Gen::TypesVisitor::visitEnum(const EnumPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule));
const string name = fixIdent(getRelativeTypeString(p, swiftModule));
const EnumeratorList enumerators = p->enumerators();
const string enumType = p->maxValue() <= 0xFF ? "Swift.UInt8" : "Swift.Int32";
const string optionalFormat = getOptionalFormat(p);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
InterfaceList bases = p->bases();

const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);
const string traits = name + "Traits";
const string prx = name + "Prx";
const string prxI = name + "PrxI";
Expand All @@ -1055,7 +1055,7 @@ Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
for (InterfaceList::const_iterator i = bases.begin(); i != bases.end();)
{
out << " " << getUnqualified(getAbsolute(*i), swiftModule) << "Prx";
out << " " << getRelativeTypeString(*i, swiftModule) << "Prx";
if (++i != bases.end())
{
out << ",";
Expand Down Expand Up @@ -1227,7 +1227,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p)
{
const string prefix = getClassResolverPrefix(p->unit());
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);

ClassDefPtr base = p->base();

Expand Down Expand Up @@ -1288,7 +1288,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p)
out << nl << "open class " << fixIdent(name) << ": ";
if (base)
{
out << fixIdent(getUnqualified(getAbsolute(base), swiftModule));
out << fixIdent(getRelativeTypeString(base, swiftModule));
}
else
{
Expand Down Expand Up @@ -1384,9 +1384,9 @@ bool
Gen::ObjectVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string disp = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + "Disp");
const string traits = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + "Traits");
const string servant = fixIdent(getUnqualified(getAbsolute(p), swiftModule));
const string disp = fixIdent(getRelativeTypeString(p, swiftModule) + "Disp");
const string traits = fixIdent(getRelativeTypeString(p, swiftModule) + "Traits");
const string servant = fixIdent(getRelativeTypeString(p, swiftModule));

//
// Disp struct
Expand Down Expand Up @@ -1463,7 +1463,7 @@ Gen::ObjectVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
StringList baseNames;
for (InterfaceList::const_iterator i = bases.begin(); i != bases.end(); ++i)
{
baseNames.push_back(fixIdent(getUnqualified(getAbsolute(*i), swiftModule)));
baseNames.push_back(fixIdent(getRelativeTypeString(*i, swiftModule)));
}

//
Expand Down Expand Up @@ -1542,7 +1542,7 @@ bool
Gen::ObjectExtVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
const string name = getRelativeTypeString(p, swiftModule);

out << sp;
writeServantDocSummary(out, p, swiftModule);
Expand Down
Loading

0 comments on commit e00f874

Please sign in to comment.