From 5590716b3578c6b97a63bc90c844f7c5896a7da5 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 11:38:26 -0500 Subject: [PATCH 01/17] Step 1. --- cpp/src/slice2cs/CsUtil.cpp | 23 ++-- cpp/src/slice2cs/CsUtil.h | 10 ++ cpp/src/slice2cs/DotNetNames.cpp | 111 ------------------ cpp/src/slice2cs/DotNetNames.h | 23 ---- cpp/src/slice2cs/Gen.cpp | 3 +- cpp/src/slice2cs/msbuild/slice2cs.vcxproj | 2 - .../slice2cs/msbuild/slice2cs.vcxproj.filters | 6 - 7 files changed, 22 insertions(+), 156 deletions(-) delete mode 100644 cpp/src/slice2cs/DotNetNames.cpp delete mode 100644 cpp/src/slice2cs/DotNetNames.h diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index d5d56365993..1dee48df5bf 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -3,7 +3,6 @@ #include "CsUtil.h" #include "../Slice/MetadataValidation.h" #include "../Slice/Util.h" -#include "DotNetNames.h" #include "Ice/StringUtil.h" #include @@ -48,9 +47,9 @@ namespace } if (mangleCasts && (name == "checkedCast" || name == "uncheckedCast")) { - return string(DotNet::manglePrefix) + name; + return "ice_" + name; } - return Slice::DotNet::mangleName(name, baseTypes); + return name; } } @@ -151,7 +150,7 @@ Slice::CsGenerator::getUnqualified( // if so, prefix it with ice_; otherwise, return the name unchanged. // string -Slice::CsGenerator::fixId(const string& name, unsigned int baseTypes, bool mangleCasts) +Slice::CsGenerator::fixId(const string& name, unsigned int baseTypes, bool mangleCasts) // TODOAUSTIN { if (name.empty()) { @@ -200,7 +199,7 @@ Slice::CsGenerator::getStaticId(const TypePtr& type) } else { - return getUnqualified(cl) + ".ice_staticId()"; + return getUnqualified(cl, "") + ".ice_staticId()"; } } @@ -254,7 +253,7 @@ Slice::CsGenerator::typeToString(const TypePtr& type, const string& package, boo InterfaceDeclPtr proxy = dynamic_pointer_cast(type); if (proxy) { - return getUnqualified(proxy, package, "", "Prx?"); + return getUnqualified(proxy, package) + "Prx?"; } SequencePtr seq = dynamic_pointer_cast(type); @@ -309,7 +308,7 @@ Slice::CsGenerator::resultType(const OperationPtr& op, const string& package, bo InterfaceDefPtr interface = op->interface(); if (dispatch && op->hasMarshaledResult()) { - return getUnqualified(interface, package, "", resultStructName("", op->name(), true)); + return getUnqualified(interface, package) + resultStructName("", op->name(), true); } string t; @@ -322,7 +321,7 @@ Slice::CsGenerator::resultType(const OperationPtr& op, const string& package, bo } else if (op->returnType() || outParams.size() > 1) { - t = getUnqualified(interface, package, "", resultStructName("", op->name())); + t = getUnqualified(interface, package) + resultStructName("", op->name()); } else { @@ -654,7 +653,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode( DictionaryPtr d = dynamic_pointer_cast(type); if (d) { - helperName = getUnqualified(d, package, "", "Helper"); + helperName = getUnqualified(d, package) + "Helper"; } else { @@ -1025,7 +1024,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode( assert(cont); if (useHelper) { - string helperName = getUnqualified(seq, scope, "", "Helper"); + string helperName = getUnqualified(seq, scope) + "Helper"; if (marshal) { out << nl << helperName << ".write(" << stream << ", " << param << ");"; @@ -1551,11 +1550,11 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode( string helperName; if (dynamic_pointer_cast(type)) { - helperName = getUnqualified(dynamic_pointer_cast(type), scope, "", "PrxHelper"); + helperName = getUnqualified(dynamic_pointer_cast(type), scope) + "PrxHelper"; } else { - helperName = getUnqualified(dynamic_pointer_cast(type), scope, "", "Helper"); + helperName = getUnqualified(dynamic_pointer_cast(type), scope) + "Helper"; } string func; diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 77dd557a2d7..0c92ab5abac 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -8,6 +8,16 @@ namespace Slice { + namespace DotNet + { + enum BaseType + { + Object = 1, + ICloneable = 2, + Exception = 4, + }; + } + class CsGenerator { public: diff --git a/cpp/src/slice2cs/DotNetNames.cpp b/cpp/src/slice2cs/DotNetNames.cpp deleted file mode 100644 index ec84b72ae71..00000000000 --- a/cpp/src/slice2cs/DotNetNames.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "DotNetNames.h" -#include -#include - -using namespace std; - -namespace Slice::DotNet -{ - struct Node - { - const char** names; - const Node** parents; - }; - - static const char* ObjectNames[] = - {"Equals", "Finalize", "GetHashCode", "GetType", "MemberwiseClone", "ReferenceEquals", "ToString", nullptr}; - static const Node* ObjectParents[] = {nullptr}; - static const Node ObjectNode = {ObjectNames, &ObjectParents[0]}; - - static const char* ICloneableNames[] = {"Clone", nullptr}; - static const Node* ICloneableParents[] = {&ObjectNode, nullptr}; - static const Node ICloneableNode = {ICloneableNames, &ICloneableParents[0]}; - - static const char* ExceptionNames[] = { - "Data", - "GetBaseException", - "GetObjectData", - "HelpLink", - "HResult", - "InnerException", - "Message", - "Source", - "StackTrace", - "TargetSite", - nullptr}; - static const Node* ExceptionParents[] = {&ObjectNode, nullptr}; - static const Node ExceptionNode = {ExceptionNames, &ExceptionParents[0]}; - - // - // Must be kept in same order as definition of BaseType in header file! - // - static const Node* nodes[] = {&ObjectNode, &ICloneableNode, &ExceptionNode}; - - static bool ciEquals(const string& s, const char* p) - { - if (s.size() != strlen(p)) - { - return false; - } - string::const_iterator i = s.begin(); - while (i != s.end()) - { - if (tolower(static_cast(*i++)) != tolower(static_cast(*p++))) - { - return false; - } - } - return true; - } - - const char* manglePrefix = "ice_"; - const char* mangleSuffix = "_"; - - static bool mangle(const string& s, const Node* np, string& newName) - { - const char** namep = np->names; - while (*namep) - { - if (ciEquals(s, *namep)) - { - newName = manglePrefix + s + mangleSuffix; - return true; - } - ++namep; - } - const Node** parentp = np->parents; - while (*parentp) - { - if (mangle(s, *parentp, newName)) - { - return true; - } - ++parentp; - } - return false; - } - -} - -string -Slice::DotNet::mangleName(const string& s, unsigned int baseTypes) -{ - if (baseTypes == 0) - { - return s; - } - string newName; - for (unsigned int mask = 1, i = 0; mask < END; mask <<= 1, ++i) - { - if (baseTypes & mask) - { - if (mangle(s, nodes[i], newName)) - { - return newName; - } - } - } - return s; -} diff --git a/cpp/src/slice2cs/DotNetNames.h b/cpp/src/slice2cs/DotNetNames.h deleted file mode 100644 index e579c5788d4..00000000000 --- a/cpp/src/slice2cs/DotNetNames.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef DOTNETNAMES_H -#define DOTNETNAMES_H - -#include - -namespace Slice::DotNet -{ - enum BaseType - { - Object = 1, - ICloneable = 2, - Exception = 4, - END = 8 - }; - - extern const char* manglePrefix; - - std::string mangleName(const std::string&, unsigned int baseTypes = 0); -} - -#endif diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 60fc123410f..bb90c3069e8 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -13,7 +13,6 @@ #include "../Slice/FileTracker.h" #include "../Slice/Util.h" -#include "DotNetNames.h" #include "Ice/UUID.h" #include #include @@ -1809,7 +1808,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) vector baseInterfaces; for (const auto& base : bases) { - baseInterfaces.push_back(getUnqualified(base, ns, "", "Prx")); + baseInterfaces.push_back(getUnqualified(base, ns) + "Prx"); } if (baseInterfaces.empty()) diff --git a/cpp/src/slice2cs/msbuild/slice2cs.vcxproj b/cpp/src/slice2cs/msbuild/slice2cs.vcxproj index 920b25ce3e0..eff133751d0 100644 --- a/cpp/src/slice2cs/msbuild/slice2cs.vcxproj +++ b/cpp/src/slice2cs/msbuild/slice2cs.vcxproj @@ -111,7 +111,6 @@ - @@ -119,7 +118,6 @@ - diff --git a/cpp/src/slice2cs/msbuild/slice2cs.vcxproj.filters b/cpp/src/slice2cs/msbuild/slice2cs.vcxproj.filters index a1c8e3d7b1d..3816c655bd5 100644 --- a/cpp/src/slice2cs/msbuild/slice2cs.vcxproj.filters +++ b/cpp/src/slice2cs/msbuild/slice2cs.vcxproj.filters @@ -24,9 +24,6 @@ Source Files - - Source Files - @@ -40,9 +37,6 @@ Header Files - - Header Files - From 01dc1cb2ee9317a879e2349a457681c714ad1098 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 11:47:24 -0500 Subject: [PATCH 02/17] Let's just always qualift built-in our types with 'global::' --- cpp/src/slice2cs/CsUtil.cpp | 35 +++++++---------------------------- cpp/src/slice2cs/CsUtil.h | 8 ++------ 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index 1dee48df5bf..ae01e6a7209 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -106,30 +106,9 @@ Slice::CsGenerator::getNamespace(const ContainedPtr& cont) } string -Slice::CsGenerator::getUnqualified(const string& type, const string& scope, bool builtin) +Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) { - if (type.find('.') != string::npos && type.find(scope) == 0 && type.find('.', scope.size() + 1) == string::npos) - { - return type.substr(scope.size() + 1); - } - else if (builtin) - { - return type.find('.') == string::npos ? type : "global::" + type; - } - else - { - return "global::" + type; - } -} - -string -Slice::CsGenerator::getUnqualified( - const ContainedPtr& p, - const string& package, - const string& prefix, - const string& suffix) -{ - string name = fixId(prefix + p->name() + suffix); + string name = fixId(p->name()); string contPkg = getNamespace(p); if (contPkg == package || contPkg.empty()) { @@ -227,20 +206,20 @@ Slice::CsGenerator::typeToString(const TypePtr& type, const string& package, boo "float", "double", "string", - "Ice.Object", // not used anymore - "Ice.ObjectPrx?", - "Ice.Value?"}; + "global::Ice.Object", // not used anymore + "global::Ice.ObjectPrx?", + "global::Ice.Value?"}; BuiltinPtr builtin = dynamic_pointer_cast(type); if (builtin) { if (builtin->kind() == Builtin::KindObject) { - return getUnqualified(builtinTable[Builtin::KindValue], package, true); + return builtinTable[Builtin::KindValue]; } else { - return getUnqualified(builtinTable[builtin->kind()], package, true); + return builtinTable[builtin->kind()]; } } diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 0c92ab5abac..66e3dbd1814 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -8,6 +8,7 @@ namespace Slice { + // TODO remove this temporary. namespace DotNet { enum BaseType @@ -39,12 +40,7 @@ namespace Slice // static std::string getNamespace(const ContainedPtr&); - static std::string getUnqualified(const std::string&, const std::string&, bool builtin = false); - static std::string getUnqualified( - const ContainedPtr&, - const std::string& package = "", - const std::string& prefix = "", - const std::string& suffix = ""); + static std::string getUnqualified(const ContainedPtr&, const std::string& package); static std::string fixId(const std::string&, unsigned int = 0, bool = false); From 710f44be86530228914df12f45b1fcdd64aeef88 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 14:15:46 -0500 Subject: [PATCH 03/17] Remapping calls and removing dead code part 1. --- cpp/src/Slice/Parser.cpp | 34 ----------- cpp/src/Slice/Parser.h | 2 - cpp/src/slice2cs/CsUtil.cpp | 2 +- cpp/src/slice2cs/Gen.cpp | 118 +++++++++++++++--------------------- cpp/src/slice2cs/Gen.h | 2 +- cpp/src/slice2java/Gen.cpp | 8 --- 6 files changed, 50 insertions(+), 116 deletions(-) diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 66f93e5a953..4403cbc0f5d 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -2628,22 +2628,6 @@ Slice::ClassDef::classDataMembers() const return result; } -// Return the class data members of this class and its parent classes, in base-to-derived order. -DataMemberList -Slice::ClassDef::allClassDataMembers() const -{ - DataMemberList result; - if (_base) - { - result = _base->allClassDataMembers(); - } - - // Append this class's class members. - DataMemberList myMembers = classDataMembers(); - result.splice(result.end(), myMembers); - return result; -} - bool Slice::ClassDef::canBeCyclic() const { @@ -3709,24 +3693,6 @@ Slice::Exception::classDataMembers() const return result; } -// Return the class data members of this exception and its parent exceptions, in base-to-derived order. -DataMemberList -Slice::Exception::allClassDataMembers() const -{ - DataMemberList result; - - // Check if we have a base exception. If so, recursively get the class data members of the base exception(s). - if (base()) - { - result = base()->allClassDataMembers(); - } - - // Append this exceptions's class data members. - DataMemberList myMembers = classDataMembers(); - result.splice(result.end(), myMembers); - return result; -} - ExceptionPtr Slice::Exception::base() const { diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 6bc2d0ee59e..9a2d2acde25 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -605,7 +605,6 @@ namespace Slice [[nodiscard]] DataMemberList orderedOptionalDataMembers() const; [[nodiscard]] DataMemberList allDataMembers() const; [[nodiscard]] DataMemberList classDataMembers() const; - [[nodiscard]] DataMemberList allClassDataMembers() const; [[nodiscard]] bool canBeCyclic() const; void visit(ParserVisitor* visitor) final; [[nodiscard]] int compactId() const; @@ -787,7 +786,6 @@ namespace Slice [[nodiscard]] DataMemberList orderedOptionalDataMembers() const; [[nodiscard]] DataMemberList allDataMembers() const; [[nodiscard]] DataMemberList classDataMembers() const; - [[nodiscard]] DataMemberList allClassDataMembers() const; [[nodiscard]] ExceptionPtr base() const; [[nodiscard]] ExceptionList allBases() const; [[nodiscard]] bool isBaseOf(const ExceptionPtr& otherException) const; diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index ae01e6a7209..da906233241 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -23,7 +23,7 @@ using namespace IceInternal; namespace { - string lookupKwd(const string& name, unsigned int baseTypes, bool mangleCasts = false) + string lookupKwd(const string& name, unsigned int, bool mangleCasts = false) { // // Keyword list. *Must* be kept in alphabetical order. diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index bb90c3069e8..d3ee542bca0 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -38,6 +38,7 @@ namespace } } + // TODO: this function is being replaced anyways. /// Returns a C# formatted link to the provided Slice identifier. /// TODO: this is temporary and will be replaced when we add 'cs:identifier' support. string csLinkFormatter(const string& rawLink, const ContainedPtr&, const SyntaxTreeBasePtr&) @@ -61,6 +62,7 @@ namespace return result + "\" />"; } + // TODO we should also replace this function too! string toCsIdent(const string& s) { string::size_type pos = s.find('#'); @@ -378,18 +380,14 @@ Slice::CsVisitor::writeUnmarshalDataMember( void Slice::CsVisitor::writeMarshaling(const ClassDefPtr& p) { - string name = fixId(p->name()); - string scoped = p->scoped(); string ns = getNamespace(p); ClassDefPtr base = p->base(); // // Marshaling support // - DataMemberList allClassMembers = p->allClassDataMembers(); DataMemberList members = p->dataMembers(); DataMemberList optionalMembers = p->orderedOptionalDataMembers(); - DataMemberList classMembers = p->classDataMembers(); _out << sp; _out << nl << "protected override void iceWriteImpl(Ice.OutputStream ostr_)"; @@ -399,12 +397,12 @@ Slice::CsVisitor::writeMarshaling(const ClassDefPtr& p) { if (!member->optional()) { - writeMarshalDataMember(member, fixId(member->name(), DotNet::ICloneable, true), ns); + writeMarshalDataMember(member, member->mappedName(), ns); } } for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::ICloneable, true), ns); + writeMarshalDataMember(optionalMember, optionalMember->mappedName(), ns); } _out << nl << "ostr_.endSlice();"; if (base) @@ -421,12 +419,12 @@ Slice::CsVisitor::writeMarshaling(const ClassDefPtr& p) { if (!member->optional()) { - writeUnmarshalDataMember(member, fixId(member->name(), DotNet::ICloneable, true), ns); + writeUnmarshalDataMember(member, member->mappedName(), ns); } } for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::ICloneable, true), ns); + writeUnmarshalDataMember(optionalMember, optionalMember->mappedName(), ns); } _out << nl << "istr_.endSlice();"; if (base) @@ -463,7 +461,7 @@ Slice::CsVisitor::getParams(const OperationPtr& op, const string& ns) { param += "out "; } - param += typeToString(q->type(), ns, q->optional()) + " " + fixId(q->name()); + param += typeToString(q->type(), ns, q->optional()) + " " + q->mappedName(); params.push_back(param); } return params; @@ -473,15 +471,11 @@ vector Slice::CsVisitor::getInParams(const OperationPtr& op, const string& ns, bool internal) { vector params; - - string name = fixId(op->name()); - InterfaceDefPtr interface = op->interface(); - ParameterList paramList = op->inParameters(); - for (const auto& q : paramList) + for (const auto& q : op->inParameters()) { params.push_back( getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + - (internal ? "iceP_" + q->name() : fixId(q->name()))); + (internal ? "iceP_" + q->mappedName() : q->mappedName())); } return params; } @@ -507,7 +501,7 @@ Slice::CsVisitor::getOutParams(const OperationPtr& op, const string& ns, bool re { s += "out "; } - s += typeToString(q->type(), ns, q->optional()) + ' ' + fixId(q->name()); + s += typeToString(q->type(), ns, q->optional()) + ' ' + q->mappedName(); params.push_back(s); } @@ -521,7 +515,7 @@ Slice::CsVisitor::getArgs(const OperationPtr& op) ParameterList paramList = op->parameters(); for (const auto& q : paramList) { - string arg = fixId(q->name()); + string arg = q->mappedName(); if (q->isOutParam()) { arg = "out " + arg; @@ -540,7 +534,7 @@ Slice::CsVisitor::getInArgs(const OperationPtr& op, bool internal) { if (!q->isOutParam()) { - args.push_back(internal ? "iceP_" + q->name() : fixId(q->name())); + args.push_back(internal ? "iceP_" + q->mappedName() : q->mappedName()); } } return args; @@ -554,13 +548,13 @@ Slice::CsVisitor::getDispatchParams( vector& args, const string& ns) { - string name; + string name = op->mappedName(); InterfaceDefPtr interface = op->interface(); ParameterList parameterss; if (interface->hasMetadata("amd") || op->hasMetadata("amd")) { - name = op->name() + "Async"; + name += "Async"; params = getInParams(op, ns); args = getInArgs(op); parameterss = op->inParameters(); @@ -568,7 +562,6 @@ Slice::CsVisitor::getDispatchParams( } else if (op->hasMarshaledResult()) { - name = fixId(op->name(), DotNet::Object, true); params = getInParams(op, ns); args = getInArgs(op); parameterss = op->inParameters(); @@ -576,7 +569,6 @@ Slice::CsVisitor::getDispatchParams( } else { - name = fixId(op->name(), DotNet::Object, true); params = getParams(op, ns); args = getArgs(op); parameterss = op->parameters(); @@ -652,7 +644,7 @@ Slice::CsVisitor::writeValue(const TypePtr& type, const string& ns) EnumPtr en = dynamic_pointer_cast(type); if (en) { - return typeToString(type, ns) + "." + fixId((*en->enumerators().begin())->name()); + return typeToString(type, ns) + "." + (*en->enumerators().begin())->mappedName(); } StructPtr st = dynamic_pointer_cast(type); @@ -691,7 +683,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt { EnumeratorPtr lte = dynamic_pointer_cast(valueType); assert(lte); - _out << fixId(lte->scoped()); + _out << lte->mappedScoped(); } else { @@ -701,7 +693,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt } void -Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& dataMembers, unsigned int baseTypes) +Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& dataMembers) { // Generates "= null!" for each required field. This wouldn't be necessary if we actually generated required // fields and properties. @@ -709,7 +701,7 @@ Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& dataMembers, { if (isMappedToRequiredField(q)) { - _out << nl << "this." << fixId(q->name(), baseTypes) << " = null!;"; + _out << nl << "this." << q->mappedName() << " = null!;"; } } } @@ -1003,10 +995,8 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) void Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) { - string name = fixId(p->name()); + string name = p->mappedName(); string ns = getNamespace(p); - DataMemberList classMembers = p->classDataMembers(); - DataMemberList allClassMembers = p->allClassDataMembers(); DataMemberList dataMembers = p->dataMembers(); DataMemberList allDataMembers = p->allDataMembers(); ClassDefPtr base = p->base(); @@ -1032,7 +1022,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) vector secondaryCtorBaseParamNames; for (const auto& q : allDataMembers) { - string memberName = fixId(q->name(), DotNet::ICloneable); + string memberName = q->mappedName(); string memberType = typeToString(q->type(), ns, q->optional()); parameters.push_back(memberType + " " + memberName); @@ -1057,7 +1047,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) DataMemberList baseDataMembers = base->allDataMembers(); for (const auto& q : baseDataMembers) { - string memberName = fixId(q->name(), DotNet::ICloneable); + string memberName = q->mappedName(); baseParamNames.push_back(memberName); // Look for required fields @@ -1071,7 +1061,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) _out << sb; for (const auto& q : dataMembers) { - const string memberName = fixId(q->name(), DotNet::ICloneable); + const string memberName = q->mappedName(); if (isMappedToNonNullableReference(q)) { _out << nl << "global::System.ArgumentNullException.ThrowIfNull(" << memberName << ");"; @@ -1108,7 +1098,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) emitNonBrowsableAttribute(); _out << nl << "public " << name << "()"; _out << sb; - writeDataMemberInitializers(dataMembers, DotNet::ICloneable); + writeDataMemberInitializers(dataMembers); _out << nl << "ice_initialize();"; _out << eb; } @@ -1126,8 +1116,6 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) bool Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - string name = p->name(); - string scoped = fixId(p->scoped()); string ns = getNamespace(p); InterfaceList bases = p->bases(); @@ -1137,7 +1125,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) emitAttributes(p); _out << nl << "[Ice.SliceTypeId(\"" << p->scoped() << "\")]"; - _out << nl << "public partial interface " << fixId(name); + _out << nl << "public partial interface " << p->mappedName(); for (const auto& q : bases) { @@ -1175,7 +1163,6 @@ void Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& op) { InterfaceDefPtr interface = op->interface(); - string interfaceName = fixId(interface->name()); string ns = getNamespace(interface); const bool amd = interface->hasMetadata("amd") || op->hasMetadata("amd"); @@ -1202,7 +1189,6 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr&) bool Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) { - string name = fixId(p->name()); string ns = getNamespace(p); ExceptionPtr base = p->base(); @@ -1211,7 +1197,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) emitObsoleteAttribute(p, _out); emitAttributes(p); _out << nl << "[Ice.SliceTypeId(\"" << p->scoped() << "\")]"; - _out << nl << "public partial class " << name << " : "; + _out << nl << "public partial class " << p->mappedName() << " : "; if (base) { _out << getUnqualified(base, ns); @@ -1227,12 +1213,10 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) void Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { - string name = fixId(p->name()); + string name = p->mappedName(); string ns = getNamespace(p); DataMemberList allDataMembers = p->allDataMembers(); DataMemberList dataMembers = p->dataMembers(); - DataMemberList allClassMembers = p->allClassDataMembers(); - DataMemberList classMembers = p->classDataMembers(); DataMemberList optionalMembers = p->orderedOptionalDataMembers(); ExceptionPtr base = p->base(); @@ -1249,7 +1233,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) for (const auto& q : allDataMembers) { - string memberName = fixId(q->name(), DotNet::Exception); + string memberName = q->mappedName(); string memberType = typeToString(q->type(), ns, q->optional()); parameters.push_back(memberType + " " + memberName); @@ -1274,7 +1258,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) DataMemberList baseDataMembers = base->allDataMembers(); for (const auto& q : baseDataMembers) { - string memberName = fixId(q->name(), DotNet::Exception); + string memberName = q->mappedName(); baseParamNames.push_back(memberName); // Look for required fields @@ -1288,7 +1272,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << sb; for (const auto& q : dataMembers) { - const string memberName = fixId(q->name(), DotNet::Exception); + const string memberName = q->mappedName(); if (isMappedToNonNullableReference(q)) { _out << nl << "global::System.ArgumentNullException.ThrowIfNull(" << memberName << ");"; @@ -1323,16 +1307,16 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) emitNonBrowsableAttribute(); _out << nl << "public " << name << "()"; _out << sb; - writeDataMemberInitializers(dataMembers, DotNet::Exception); + writeDataMemberInitializers(dataMembers); _out << eb; } } - _out << sp; - _out << nl << "public override string ice_id() => \"" << p->scoped() << "\";"; - string scoped = p->scoped(); + _out << sp; + _out << nl << "public override string ice_id() => \"" << scoped << "\";"; + _out << sp; _out << nl << "protected override void iceWriteImpl(Ice.OutputStream ostr_)"; _out << sb; @@ -1341,13 +1325,13 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { if (!dataMember->optional()) { - writeMarshalDataMember(dataMember, fixId(dataMember->name(), DotNet::Exception), ns); + writeMarshalDataMember(dataMember, dataMember->mappedName(), ns); } } for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::Exception), ns); + writeMarshalDataMember(optionalMember, optionalMember->mappedName(), ns); } _out << nl << "ostr_.endSlice();"; @@ -1366,13 +1350,13 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { if (!dataMember->optional()) { - writeUnmarshalDataMember(dataMember, fixId(dataMember->name(), DotNet::Exception), ns); + writeUnmarshalDataMember(dataMember, dataMember->mappedName(), ns); } } for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::Exception), ns); + writeUnmarshalDataMember(optionalMember, optionalMember->mappedName(), ns); } _out << nl << "istr_.endSlice();"; if (base) @@ -1396,10 +1380,9 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) bool Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) { - string name = fixId(p->name()); - string ns = getNamespace(p); - _out << sp; const bool classMapping = isMappedToClass(p); + string name = p->mappedName(); + _out << sp; emitObsoleteAttribute(p, _out); @@ -1412,16 +1395,13 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) void Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) { - string name = fixId(p->name()); - string scope = fixId(p->scope()); + string name = p->mappedName(); string ns = getNamespace(p); - DataMemberList classMembers = p->classDataMembers(); DataMemberList dataMembers = p->dataMembers(); - const bool classMapping = isMappedToClass(p); _out << sp << nl << "partial void ice_initialize();"; - if (classMapping) + if (isMappedToClass(p)) { // We generate a constructor that initializes all required fields (collections and structs mapped to // classes). It can be parameterless. @@ -1432,7 +1412,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) { if (isMappedToRequiredField(q)) { - string memberName = fixId(q->name(), DotNet::ICloneable); + string memberName = q->mappedName(); string memberType = typeToString(q->type(), ns, false); ctorParams.push_back(memberType + " " + memberName); ctorParamNames.push_back(memberName); @@ -1461,15 +1441,13 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) vector parameters; for (const auto& q : dataMembers) { - string memberName = fixId(q->name(), classMapping ? DotNet::ICloneable : 0); - string memberType = typeToString(q->type(), ns, false); - parameters.push_back(memberType + " " + memberName); + parameters.push_back(typeToString(q->type(), ns, false) + " " + q->mappedName()); } _out << parameters << epar; _out << sb; for (const auto& q : dataMembers) { - string paramName = fixId(q->name(), classMapping ? DotNet::ICloneable : 0); + string paramName = q->mappedName(); if (isMappedToNonNullableReference(q)) { _out << nl << "global::System.ArgumentNullException.ThrowIfNull(" << paramName << ");"; @@ -1485,7 +1463,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for (const auto& q : dataMembers) { - writeUnmarshalDataMember(q, fixId(q->name(), classMapping ? DotNet::ICloneable : 0), ns, true); + writeUnmarshalDataMember(q, q->mappedName(), ns, true); } _out << nl << "ice_initialize();"; _out << eb; @@ -1495,7 +1473,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for (const auto& dataMember : dataMembers) { - writeMarshalDataMember(dataMember, fixId(dataMember->name(), classMapping ? DotNet::ICloneable : 0), ns, true); + writeMarshalDataMember(dataMember, dataMember->mappedName(), ns, true); } _out << eb; @@ -2603,7 +2581,7 @@ Slice::Gen::DispatcherVisitor::visitModuleStart(const ModulePtr& p) } moduleStart(p); - _out << sp << nl << "namespace " << fixId(p->name()); + _out << sp << nl << "namespace " << p->mappedName(); _out << sb; return true; } @@ -2655,7 +2633,7 @@ Slice::Gen::DispatcherVisitor::visitInterfaceDefEnd(const InterfaceDefPtr&) void Slice::Gen::DispatcherVisitor::writeDispatch(const InterfaceDefPtr& p) { - string name = fixId(p->name()); + string name = p->mappedName(); string scoped = p->scoped(); string ns = getNamespace(p); diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index 06da56d9abc..0f31bda38fb 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -49,7 +49,7 @@ namespace Slice void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const std::string&); // Generates "= null!" for non-nullable fields (Slice class and exception only). - void writeDataMemberInitializers(const DataMemberList&, unsigned int); + void writeDataMemberInitializers(const DataMemberList&); void writeDocComment(const ContainedPtr&); diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 673746cc4c6..fb488687f91 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -1626,9 +1626,6 @@ Slice::JavaVisitor::writeMarshaling(Output& out, const ClassDefPtr& p) } out << eb; - DataMemberList classMembers = p->classDataMembers(); - DataMemberList allClassMembers = p->allClassDataMembers(); - out << sp; writeHiddenDocComment(out); out << nl << "@Override"; @@ -2707,9 +2704,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } out << eb; - DataMemberList classMembers = p->classDataMembers(); - DataMemberList allClassMembers = p->allClassDataMembers(); - out << sp; writeHiddenDocComment(out); out << nl << "@Override"; @@ -2966,8 +2960,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } out << eb; - DataMemberList classMembers = p->classDataMembers(); - out << sp << nl << "public void ice_readMembers(com.zeroc.Ice.InputStream istr)"; out << sb; iter = 0; From 3bdafa4133e5374db022134810cb780eeaa0ac5f Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 14:53:46 -0500 Subject: [PATCH 04/17] Finished fixing all the calls and removing some dead code. --- cpp/src/slice2cs/CsUtil.cpp | 79 +--------------- cpp/src/slice2cs/Gen.cpp | 184 +++++++++++++----------------------- 2 files changed, 72 insertions(+), 191 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index da906233241..ced85211833 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -21,38 +21,6 @@ using namespace std; using namespace Slice; using namespace IceInternal; -namespace -{ - string lookupKwd(const string& name, unsigned int, bool mangleCasts = false) - { - // - // Keyword list. *Must* be kept in alphabetical order. - // - static const string keywordList[] = { - "abstract", "as", "async", "await", "base", "bool", "break", "byte", - "case", "catch", "char", "checked", "class", "const", "continue", "decimal", - "default", "delegate", "do", "double", "else", "enum", "event", "explicit", - "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", - "if", "implicit", "in", "int", "interface", "internal", "is", "lock", - "long", "namespace", "new", "null", "object", "operator", "out", "override", - "params", "private", "protected", "public", "readonly", "record", "ref", "required", - "return", "sbyte", "scoped", "sealed", "short", "sizeof", "stackalloc", "static", - "string", "struct", "switch", "this", "throw", "true", "try", "typeof", - "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "var", "virtual", - "void", "volatile", "while"}; - bool found = binary_search(&keywordList[0], &keywordList[sizeof(keywordList) / sizeof(*keywordList)], name); - if (found) - { - return "@" + name; - } - if (mangleCasts && (name == "checkedCast" || name == "uncheckedCast")) - { - return "ice_" + name; - } - return name; - } -} - string Slice::CsGenerator::getNamespacePrefix(const ContainedPtr& cont) { @@ -84,7 +52,7 @@ Slice::CsGenerator::getNamespacePrefix(const ContainedPtr& cont) string Slice::CsGenerator::getNamespace(const ContainedPtr& cont) { - string scope = fixId(cont->scope()); + string scope = cont->mappedScope(); if (scope.rfind('.') == scope.size() - 1) { scope = scope.substr(0, scope.size() - 1); @@ -108,7 +76,7 @@ Slice::CsGenerator::getNamespace(const ContainedPtr& cont) string Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) { - string name = fixId(p->name()); + string name = p->mappedName(); string contPkg = getNamespace(p); if (contPkg == package || contPkg.empty()) { @@ -120,44 +88,6 @@ Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) } } -// -// If the passed name is a scoped name, return the identical scoped name, -// but with all components that are C# keywords replaced by -// their "@"-prefixed version; otherwise, if the passed name is -// not scoped, but a C# keyword, return the "@"-prefixed name; -// otherwise, check if the name is one of the method names of baseTypes; -// if so, prefix it with ice_; otherwise, return the name unchanged. -// -string -Slice::CsGenerator::fixId(const string& name, unsigned int baseTypes, bool mangleCasts) // TODOAUSTIN -{ - if (name.empty()) - { - return name; - } - if (name[0] != ':') - { - return lookupKwd(name, baseTypes, mangleCasts); - } - vector ids = splitScopedName(name); - vector newIds; - newIds.reserve(ids.size()); - for (const auto& id : ids) - { - newIds.push_back(lookupKwd(id, baseTypes)); - } - stringstream result; - for (auto j = newIds.begin(); j != newIds.end(); ++j) - { - if (j != newIds.begin()) - { - result << '.'; - } - result << *j; - } - return result.str(); -} - string Slice::CsGenerator::getOptionalFormat(const TypePtr& type) { @@ -287,7 +217,7 @@ Slice::CsGenerator::resultType(const OperationPtr& op, const string& package, bo InterfaceDefPtr interface = op->interface(); if (dispatch && op->hasMarshaledResult()) { - return getUnqualified(interface, package) + resultStructName("", op->name(), true); + return getUnqualified(interface, package) + resultStructName("", op->mappedName(), true); } string t; @@ -300,7 +230,7 @@ Slice::CsGenerator::resultType(const OperationPtr& op, const string& package, bo } else if (op->returnType() || outParams.size() > 1) { - t = getUnqualified(interface, package) + resultStructName("", op->name()); + t = getUnqualified(interface, package) + resultStructName("", op->mappedName()); } else { @@ -1306,7 +1236,6 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode( } out << nl << "for (int ix = 0; ix < szx; ++ix)"; out << sb; - string scoped = dynamic_pointer_cast(type)->scoped(); // Remove trailing '?' string nonNullableTypeS = typeS.substr(0, typeS.size() - 1); out << nl << stream << ".readValue(" << patcherName << '<' << nonNullableTypeS << ">(" << param diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index d3ee542bca0..16e6e2f7cbd 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -38,7 +38,6 @@ namespace } } - // TODO: this function is being replaced anyways. /// Returns a C# formatted link to the provided Slice identifier. /// TODO: this is temporary and will be replaced when we add 'cs:identifier' support. string csLinkFormatter(const string& rawLink, const ContainedPtr&, const SyntaxTreeBasePtr&) @@ -50,14 +49,14 @@ namespace { if (hashPos != 0) { - result += Slice::CsGenerator::fixId(rawLink.substr(0, hashPos)); + result += rawLink.substr(0, hashPos); result += "."; } - result += Slice::CsGenerator::fixId(rawLink.substr(hashPos + 1)); + result += rawLink.substr(hashPos + 1); } else { - result += Slice::CsGenerator::fixId(rawLink); + result += rawLink; } return result + "\" />"; } @@ -159,7 +158,7 @@ namespace for (const auto& param : params) { - if (param->name() == name) + if (param->mappedName() == name) { return name + "_"; } @@ -171,7 +170,7 @@ namespace { for (const auto& outParam : outParams) { - if (outParam->name() == "returnValue") + if (outParam->mappedName() == "returnValue") { return "returnValue_"; } @@ -210,7 +209,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( for (const auto& pli : params) { - string param = paramPrefix.empty() && !publicNames ? "iceP_" + pli->name() : fixId(pli->name()); + string param = paramPrefix.empty() && !publicNames ? "iceP_" + pli->mappedName() : pli->mappedName(); TypePtr type = pli->type(); if (!marshal && type->isClassType()) { @@ -289,7 +288,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( checkReturnType = false; } - string param = paramPrefix.empty() && !publicNames ? "iceP_" + optional->name() : fixId(optional->name()); + string param = paramPrefix.empty() && !publicNames ? "iceP_" + optional->mappedName() : optional->mappedName(); TypePtr type = optional->type(); if (!marshal && type->isClassType()) { @@ -662,7 +661,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt ConstPtr constant = dynamic_pointer_cast(valueType); if (constant) { - _out << fixId(constant->scoped()) << ".value"; + _out << constant->mappedScoped() << ".value"; } else { @@ -771,9 +770,8 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector ExceptionPtr ex = op->container()->lookupException(exceptionName, false); if (ex) { - name = ex->scoped(); + name = ex->mappedScoped(); } - name = fixId(name); if (!exceptionLines.empty()) { @@ -795,7 +793,7 @@ Slice::CsVisitor::writeParameterDocComments(const DocComment& comment, const Par auto q = commentParameters.find(param->name()); if (q != commentParameters.end()) { - _out << nl << "/// name()) << "\">"; + _out << nl << "/// mappedName() << "\">"; writeDocLines(_out, q->second); _out << nl << "/// "; } @@ -808,7 +806,6 @@ Slice::CsVisitor::moduleStart(const ModulePtr& p) if (!dynamic_pointer_cast(p->container())) { string ns = getNamespacePrefix(p); - string name = fixId(p->name()); if (!ns.empty()) { _out << sp; @@ -942,10 +939,9 @@ bool Slice::Gen::TypesVisitor::visitModuleStart(const ModulePtr& p) { moduleStart(p); - string name = fixId(p->name()); _out << sp; emitAttributes(p); - _out << nl << "namespace " << name; + _out << nl << "namespace " << p->mappedName(); _out << sb; @@ -962,11 +958,8 @@ Slice::Gen::TypesVisitor::visitModuleEnd(const ModulePtr& p) bool Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) { - string name = p->name(); - string scoped = fixId(p->scoped()); string ns = getNamespace(p); ClassDefPtr base = p->base(); - StringList baseNames; _out << sp; emitAttributes(p); @@ -976,7 +969,7 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << nl << "[Ice.CompactSliceTypeId(" << p->compactId() << ")]"; } - _out << nl << "public partial class " << fixId(name) << " : "; + _out << nl << "public partial class " << p->mappedName() << " : "; if (base) { @@ -1117,9 +1110,6 @@ bool Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { string ns = getNamespace(p); - InterfaceList bases = p->bases(); - - list baseNames; _out << sp; emitAttributes(p); @@ -1127,7 +1117,8 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "[Ice.SliceTypeId(\"" << p->scoped() << "\")]"; _out << nl << "public partial interface " << p->mappedName(); - for (const auto& q : bases) + list baseNames; + for (const auto& q : p->bases()) { baseNames.push_back(getUnqualified(q, ns)); } @@ -1491,9 +1482,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) void Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) { - string name = fixId(p->name()); + string name = p->mappedName(); string ns = getNamespace(p); - string scoped = fixId(p->scoped()); EnumeratorList enumerators = p->enumerators(); const bool hasExplicitValues = p->hasExplicitValues(); @@ -1511,7 +1501,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) } writeDocComment(*en); emitAttributes(*en); - _out << nl << fixId((*en)->name()); + _out << nl << (*en)->mappedName(); if (hasExplicitValues) { _out << " = " << (*en)->value(); @@ -1520,7 +1510,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) _out << eb; _out << sp; - _out << nl << "public sealed class " << p->name() << "Helper"; + _out << nl << "public sealed class " << name << "Helper"; _out << sb; _out << sp; _out << nl << "public static void write(Ice.OutputStream ostr, " << name << " v)"; @@ -1542,10 +1532,9 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) void Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) { - string name = fixId(p->name()); _out << sp; emitAttributes(p); - _out << nl << "public abstract class " << name; + _out << nl << "public abstract class " << p->mappedName(); _out << sb; _out << sp << nl << "public const " << typeToString(p->type(), "") << " value = "; writeConstantValue(p->type(), p->valueType(), p->value()); @@ -1556,45 +1545,20 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) void Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) { - unsigned int baseTypes = 0; - bool isClass = false; - const bool isOptional = p->optional(); - ContainedPtr cont = dynamic_pointer_cast(p->container()); assert(cont); bool isProperty = cont->hasMetadata("cs:property"); - StructPtr st = dynamic_pointer_cast(cont); - ExceptionPtr ex = dynamic_pointer_cast(cont); - ClassDefPtr cl = dynamic_pointer_cast(cont); string ns = getNamespace(cont); - if (st) - { - if (isMappedToClass(st)) - { - baseTypes = DotNet::ICloneable; - } - } - else if (ex) - { - baseTypes = DotNet::Exception; - } - else - { - assert(cl); - baseTypes = DotNet::ICloneable; - isClass = true; - } _out << sp; emitObsoleteAttribute(p, _out); - string type = typeToString(p->type(), ns, isOptional); - string dataMemberName = fixId(p->name(), baseTypes, isClass); + string type = typeToString(p->type(), ns, p->optional()); emitAttributes(p); - _out << nl << "public" << ' ' << type << ' ' << dataMemberName; + _out << nl << "public" << ' ' << type << ' ' << p->mappedName(); bool addSemicolon = true; if (isProperty) @@ -1669,7 +1633,7 @@ Slice::Gen::ResultVisitor::visitModuleStart(const ModulePtr& p) if (hasResultType(p)) { moduleStart(p); - _out << sp << nl << "namespace " << fixId(p->name()); + _out << sp << nl << "namespace " << p->mappedName(); _out << sb; return true; } @@ -1693,7 +1657,7 @@ Slice::Gen::ResultVisitor::visitOperation(const OperationPtr& p) if (outParams.size() > 1 || (ret && outParams.size() > 0)) { - string name = resultStructName(interface->name(), p->name()); + string name = resultStructName(interface->mappedName(), p->mappedName()); string retS; string retSName; @@ -1713,7 +1677,7 @@ Slice::Gen::ResultVisitor::visitOperation(const OperationPtr& p) for (const auto& q : outParams) { - _out << (typeToString(q->type(), ns, q->optional()) + " " + fixId(q->name())); + _out << (typeToString(q->type(), ns, q->optional()) + " " + q->mappedName()); } _out << epar; _out << ";"; @@ -1721,7 +1685,7 @@ Slice::Gen::ResultVisitor::visitOperation(const OperationPtr& p) if (p->hasMarshaledResult()) { - string name = resultStructName(interface->name(), p->name(), true); + string name = resultStructName(interface->mappedName(), p->mappedName(), true); _out << sp; _out << nl << "public readonly record struct " << name << " : Ice.MarshaledResult"; @@ -1760,7 +1724,7 @@ Slice::Gen::ProxyVisitor::visitModuleStart(const ModulePtr& p) } moduleStart(p); - _out << sp << nl << "namespace " << fixId(p->name()); + _out << sp << nl << "namespace " << p->mappedName(); _out << sb; return true; } @@ -1775,16 +1739,14 @@ Slice::Gen::ProxyVisitor::visitModuleEnd(const ModulePtr& p) bool Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - string name = p->name(); string ns = getNamespace(p); - InterfaceList bases = p->bases(); _out << sp; writeDocComment(p); - _out << nl << "public interface " << name << "Prx : "; + _out << nl << "public interface " << p->mappedName() << "Prx : "; vector baseInterfaces; - for (const auto& base : bases) + for (const auto& base : p->bases()) { baseInterfaces.push_back(getUnqualified(base, ns) + "Prx"); } @@ -1816,11 +1778,9 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr&) void Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { - InterfaceDefPtr interface = p->interface(); - string ns = getNamespace(interface); - string name = fixId(p->name(), DotNet::ICloneable, true); + string ns = getNamespace(p->interface();); + string name = p->mappedName(); vector inParams = getInParams(p, ns); - ParameterList inParameters = p->inParameters(); string retS = typeToString(p->returnType(), ns, p->returnIsOptional()); { @@ -1856,7 +1816,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) true); emitObsoleteAttribute(p, _out); _out << nl << taskResultType(p, ns); - _out << " " << p->name() << "Async" << spar << inParams + _out << " " << name << "Async" << spar << inParams << ("global::System.Collections.Generic.Dictionary? " + context + " = null") << ("global::System.IProgress? " + progress + " = null") << ("global::System.Threading.CancellationToken " + cancel + " = default") << epar << ";"; @@ -1874,7 +1834,7 @@ Slice::Gen::DispatchAdapterVisitor::visitModuleStart(const ModulePtr& p) } moduleStart(p); - _out << sp << nl << "namespace " << fixId(p->name()); + _out << sp << nl << "namespace " << p->mappedName(); _out << sb; return true; } @@ -1895,7 +1855,7 @@ Slice::Gen::DispatchAdapterVisitor::visitInterfaceDefStart(const InterfaceDefPtr } _out << sp; - _out << nl << "public partial interface " << fixId(p->name()); + _out << nl << "public partial interface " << p->mappedName(); _out << sb; return true; } @@ -1911,14 +1871,14 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) { InterfaceDefPtr interface = op->interface(); string ns = getNamespace(interface); - string interfaceName = fixId(interface->name()); + string opName = op->mappedName(); const bool amd = interface->hasMetadata("amd") || op->hasMetadata("amd"); _out << sp; _out << nl << "protected static " << (amd ? "async " : "") - << "global::System.Threading.Tasks.ValueTask iceD_" << op->name() << "Async("; + << "global::System.Threading.Tasks.ValueTask iceD_" << opName << "Async("; _out.inc(); - _out << nl << interfaceName << " obj,"; + _out << nl << interface->mappedName() << " obj,"; _out << nl << "Ice.IncomingRequest request)"; _out.dec(); _out << sb; @@ -1935,7 +1895,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << nl << "istr.startEncapsulation();"; for (const auto& pli : inParams) { - string param = "iceP_" + pli->name(); + string param = "iceP_" + pli->mappedName(); string typeS = typeToString(pli->type(), ns, pli->optional()); _out << nl << typeS << ' ' << param << (pli->type()->isClassType() ? " = null;" : ";"); @@ -1955,27 +1915,26 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) vector inArgs; for (const auto& pli : inParams) { - inArgs.push_back("iceP_" + pli->name()); + inArgs.push_back("iceP_" + pli->mappedName()); } if (op->hasMarshaledResult()) { if (amd) { - _out << nl << "var result = await obj." << op->name() << "Async" << spar << inArgs << "request.current" + _out << nl << "var result = await obj." << opName << "Async" << spar << inArgs << "request.current" << epar << ".ConfigureAwait(false);"; _out << nl << "return new Ice.OutgoingResponse(result.outputStream);"; } else { - _out << nl << "var result = obj." << fixId(op->name(), DotNet::ICloneable, true) << spar << inArgs + _out << nl << "var result = obj." << opName << spar << inArgs << "request.current" << epar << ";"; _out << nl << "return new (new Ice.OutgoingResponse(result.outputStream));"; } } else if (amd) { - string opName = op->name() + "Async"; string retS = resultType(op, ns); _out << nl; @@ -1984,7 +1943,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << "var result = "; } - _out << "await obj." << opName << spar << inArgs << "request.current" << epar << ".ConfigureAwait(false);"; + _out << "await obj." << opName << "Async" << spar << inArgs << "request.current" << epar << ".ConfigureAwait(false);"; if (retS.empty()) { @@ -1993,7 +1952,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) else { // Adapt to marshaling helper below. - string resultParam = !ret && outParams.size() == 1 ? "iceP_" + outParams.front()->name() : "ret"; + string resultParam = !ret && outParams.size() == 1 ? "iceP_" + outParams.front()->mappedName() : "ret"; _out << nl << "return Ice.CurrentExtensions.createOutgoingResponse("; _out.inc(); @@ -2017,21 +1976,20 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) } else { - string opName = op->name(); for (const auto& pli : outParams) { string typeS = typeToString(pli->type(), ns, pli->optional()); - _out << nl << typeS << ' ' << "iceP_" + pli->name() << ";"; + _out << nl << typeS << ' ' << "iceP_" + pli->mappedName() << ";"; } _out << nl; if (ret) { _out << "var ret = "; } - _out << "obj." << fixId(opName, DotNet::ICloneable, true) << spar << inArgs; + _out << "obj." << opName << spar << inArgs; for (const auto& pli : outParams) { - _out << "out iceP_" + pli->name(); + _out << "out iceP_" + pli->mappedName(); } _out << "request.current" << epar << ";"; @@ -2066,7 +2024,7 @@ Slice::Gen::HelperVisitor::visitModuleStart(const ModulePtr& p) } moduleStart(p); - _out << sp << nl << "namespace " << fixId(p->name()); + _out << sp << nl << "namespace " << p->mappedName(); _out << sb; return true; } @@ -2081,9 +2039,8 @@ Slice::Gen::HelperVisitor::visitModuleEnd(const ModulePtr& p) bool Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - string name = p->name(); + string name = p->mappedName(); string ns = getNamespace(p); - InterfaceList bases = p->bases(); _out << sp; _out << nl << "public sealed class " << name << "PrxHelper : " @@ -2094,7 +2051,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) for (const auto& op : ops) { - string opName = fixId(op->name(), DotNet::ICloneable, true); + string opName = op->mappedName(); TypePtr ret = op->returnType(); string retS = typeToString(ret, ns, op->returnIsOptional()); @@ -2126,10 +2083,10 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - _out << fixId(outParams.front()->name()) << " = "; + _out << outParams.front()->mappedName() << " = "; } } - _out << "_iceI_" << op->name() << "Async" << spar << argsAMI << context << "null" + _out << "_iceI_" << opName << "Async" << spar << argsAMI << context << "null" << "global::System.Threading.CancellationToken.None" << "true" << epar; @@ -2146,7 +2103,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { for (const auto& param : outParams) { - _out << nl << fixId(param->name()) << " = result_." << fixId(param->name()) << ";"; + string paramName = param->mappedName(); + _out << nl << paramName << " = result_." << paramName << ";"; } if (ret) @@ -2168,7 +2126,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) vector paramsAMI = getInParams(op, ns); vector argsAMI = getInArgs(op); - string opName = op->name(); + string opName = op->mappedName(); ParameterList inParams = op->inParameters(); ParameterList outParams = op->outParameters(); @@ -2250,7 +2208,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Write the common invoke method // _out << sp << nl; - _out << "private void _iceI_" << op->name() << spar << getInParams(op, ns, true) + _out << "private void _iceI_" << opName << spar << getInParams(op, ns, true) << "global::System.Collections.Generic.Dictionary? context" << "bool synchronous" << "Ice.Internal.OutgoingAsyncCompletionCallback completed" << epar; @@ -2329,7 +2287,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { TypePtr t = outParams.front()->type(); _out << nl << typeToString(t, ns, (outParams.front()->optional())) << " iceP_" - << outParams.front()->name() << (t->isClassType() ? " = null;" : ";"); + << outParams.front()->mappedName() << (t->isClassType() ? " = null;" : ";"); } writeMarshalUnmarshalParams(outParams, op, false, ns, true); @@ -2340,7 +2298,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!ret && outParams.size() == 1) { - _out << nl << "return iceP_" << outParams.front()->name() << ";"; + _out << nl << "return iceP_" << outParams.front()->mappedName() << ";"; } else { @@ -2385,15 +2343,13 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "uncheckedCast(b?.ice_facet(f));"; _out.dec(); - string scoped = p->scoped(); - StringList ids = p->ids(); - // // Need static-readonly for arrays in C# (not const) // _out << sp << nl << "private static readonly string[] _ids ="; _out << sb; + StringList ids = p->ids(); { auto q = ids.begin(); while (q != ids.end()) @@ -2407,7 +2363,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } _out << eb << ";"; - _out << sp << nl << "public static string ice_staticId() => \"" << scoped << "\";"; + _out << sp << nl << "public static string ice_staticId() => \"" << p->scoped() << "\";"; _out << sp << nl << "public static void write(Ice.OutputStream ostr, " << name << "Prx? v)"; _out << sb; @@ -2425,7 +2381,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) void Slice::Gen::HelperVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) { - string name = p->name(); + string name = p->mappedName(); _out << sp; _out << nl << "protected override Ice.ObjectPrxHelperBase iceNewInstance(Ice.Internal.Reference reference) => new " @@ -2454,9 +2410,11 @@ void Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) { string ns = getNamespace(p); + string name = p->mappedName(); + string typeS = typeToString(p, ns); _out << sp; - _out << nl << "public sealed class " << p->name() << "Helper"; + _out << nl << "public sealed class " << name << "Helper"; _out << sb; _out << sp << nl << "public static void write(Ice.OutputStream ostr, " << typeS << " v)"; @@ -2491,9 +2449,9 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) // custom sequence type does not implement an indexer. // _out << sp; - _out << nl << "public class " << p->name() << "_Tester"; + _out << nl << "public class " << name << "_Tester"; _out << sb; - _out << nl << p->name() << "_Tester()"; + _out << nl << name << "_Tester()"; _out << sb; _out << nl << typeS << " test = new " << typeS << "();"; _out << nl << "test[0] = null;"; @@ -2516,7 +2474,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) string name = "global::System.Collections.Generic." + genericType + "<" + keyS + ", " + valueS + ">"; _out << sp; - _out << nl << "public sealed class " << p->name() << "Helper"; + _out << nl << "public sealed class " << p->mappedName() << "Helper"; _out << sb; _out << sp << nl << "public static void write("; @@ -2596,14 +2554,11 @@ Slice::Gen::DispatcherVisitor::visitModuleEnd(const ModulePtr& p) bool Slice::Gen::DispatcherVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - InterfaceList bases = p->bases(); - string name = p->name(); + string name = p->mappedName(); string ns = getNamespace(p); _out << sp; - _out << nl << "public abstract class " << name << "Disp_ : Ice.ObjectImpl, "; - - _out << fixId(name); + _out << nl << "public abstract class " << name << "Disp_ : Ice.ObjectImpl, " << name; _out << sb; for (const auto& op : p->allOperations()) @@ -2633,8 +2588,6 @@ Slice::Gen::DispatcherVisitor::visitInterfaceDefEnd(const InterfaceDefPtr&) void Slice::Gen::DispatcherVisitor::writeDispatch(const InterfaceDefPtr& p) { - string name = p->mappedName(); - string scoped = p->scoped(); string ns = getNamespace(p); OperationList allOps = p->allOperations(); @@ -2649,9 +2602,8 @@ Slice::Gen::DispatcherVisitor::writeDispatch(const InterfaceDefPtr& p) _out << sb; for (const auto& op : allOps) { - string opName = op->name(); - _out << nl << '"' << opName << "\" => " << getUnqualified(op->interface(), ns) << ".iceD_" << opName - << "Async(this, request),"; + _out << nl << '"' << op->name() << "\" => " << getUnqualified(op->interface(), ns) << ".iceD_" + << op->mappedName()<< "Async(this, request),"; } for (const auto& opName : {"ice_id", "ice_ids", "ice_isA", "ice_ping"}) { From 55c9addec69a19b6fb3e12112020fe49da45920d Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 14:54:10 -0500 Subject: [PATCH 05/17] Fixed the header file. --- cpp/src/slice2cs/CsUtil.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 66e3dbd1814..6c3f1bc1c52 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -42,8 +42,6 @@ namespace Slice static std::string getUnqualified(const ContainedPtr&, const std::string& package); - static std::string fixId(const std::string&, unsigned int = 0, bool = false); - protected: // // Returns the namespace prefix of a Contained entity. From efa50313016b84c109c1ba5d633494718d2e12d5 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 14:59:33 -0500 Subject: [PATCH 06/17] Added support for 'cs:identifier' metadata. --- cpp/src/slice2cs/CsUtil.cpp | 19 +++++++++++++++++++ cpp/src/slice2cs/Gen.cpp | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index ced85211833..e92eefb9ccd 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -1828,6 +1828,25 @@ Slice::CsGenerator::validateMetadata(const UnitPtr& u) }; knownMetadata.emplace("cs:generic", genericInfo); + // "cs:identifier" + MetadataInfo identifierInfo = { + .validOn = + {typeid(InterfaceDecl), + typeid(Operation), + typeid(ClassDecl), + typeid(Slice::Exception), + typeid(Struct), + typeid(Sequence), + typeid(Dictionary), + typeid(Enum), + typeid(Enumerator), + typeid(Const), + typeid(Parameter), + typeid(DataMember)}, + .acceptedArgumentKind = MetadataArgumentKind::SingleArgument, + }; + knownMetadata.emplace("cs:identifier", std::move(identifierInfo)); + // "cs:namespace" MetadataInfo namespaceInfo = { .validOn = {typeid(Module)}, diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 16e6e2f7cbd..ce87e4b5789 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -1778,7 +1778,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr&) void Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { - string ns = getNamespace(p->interface();); + string ns = getNamespace(p->interface()); string name = p->mappedName(); vector inParams = getInParams(p, ns); string retS = typeToString(p->returnType(), ns, p->returnIsOptional()); From 1d4042093b349abbab127fe7e9a28a434ddfe103 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 15:02:53 -0500 Subject: [PATCH 07/17] Fixed the C#/Ice/servantLocator test. --- csharp/test/Ice/servantLocator/Test.ice | 4 ++-- csharp/test/Ice/servantLocator/TestAMD.ice | 4 ++-- csharp/test/Ice/servantLocator/TestAMDI.cs | 8 ++++---- csharp/test/Ice/servantLocator/TestI.cs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/csharp/test/Ice/servantLocator/Test.ice b/csharp/test/Ice/servantLocator/Test.ice index e78e72043bd..cc248aa95d9 100644 --- a/csharp/test/Ice/servantLocator/Test.ice +++ b/csharp/test/Ice/servantLocator/Test.ice @@ -26,8 +26,8 @@ interface TestIntf void unknownExceptionWithServantException(); - string impossibleException(bool throw) throws TestImpossibleException; - string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + string impossibleException(["cs:identifier:shouldThrow"] bool throw) throws TestImpossibleException; + string intfUserException(["cs:identifier:shouldThrow"] bool throw) throws TestIntfUserException, TestImpossibleException; void asyncResponse() throws TestIntfUserException, TestImpossibleException; void asyncException() throws TestIntfUserException, TestImpossibleException; diff --git a/csharp/test/Ice/servantLocator/TestAMD.ice b/csharp/test/Ice/servantLocator/TestAMD.ice index 9523b478091..34441713fc8 100644 --- a/csharp/test/Ice/servantLocator/TestAMD.ice +++ b/csharp/test/Ice/servantLocator/TestAMD.ice @@ -26,8 +26,8 @@ exception TestImpossibleException void unknownExceptionWithServantException(); - string impossibleException(bool throw) throws TestImpossibleException; - string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + string impossibleException(["cs:identifier:shouldThrow"] bool throw) throws TestImpossibleException; + string intfUserException(["cs:identifier:shouldThrow"] bool throw) throws TestIntfUserException, TestImpossibleException; void asyncResponse() throws TestIntfUserException, TestImpossibleException; void asyncException() throws TestIntfUserException, TestImpossibleException; diff --git a/csharp/test/Ice/servantLocator/TestAMDI.cs b/csharp/test/Ice/servantLocator/TestAMDI.cs index dcab21a0fe2..acac4bacad0 100644 --- a/csharp/test/Ice/servantLocator/TestAMDI.cs +++ b/csharp/test/Ice/servantLocator/TestAMDI.cs @@ -50,9 +50,9 @@ public override Task } public override Task - impossibleExceptionAsync(bool @throw, Ice.Current current) + impossibleExceptionAsync(bool shouldThrow, Ice.Current current) { - if (@throw) + if (shouldThrow) { throw new Test.TestImpossibleException(); } @@ -67,9 +67,9 @@ public override Task } public override Task - intfUserExceptionAsync(bool @throw, Ice.Current current) + intfUserExceptionAsync(bool shouldThrow, Ice.Current current) { - if (@throw) + if (shouldThrow) { throw new Test.TestIntfUserException(); } diff --git a/csharp/test/Ice/servantLocator/TestI.cs b/csharp/test/Ice/servantLocator/TestI.cs index 6ea3f8eea88..adcef38d142 100644 --- a/csharp/test/Ice/servantLocator/TestI.cs +++ b/csharp/test/Ice/servantLocator/TestI.cs @@ -39,9 +39,9 @@ public override void unknownExceptionWithServantException(Ice.Current current) throw new Ice.ObjectNotExistException(); } - public override string impossibleException(bool @throw, Ice.Current current) + public override string impossibleException(bool shouldThrow, Ice.Current current) { - if (@throw) + if (shouldThrow) { throw new Test.TestImpossibleException(); } @@ -52,9 +52,9 @@ public override string impossibleException(bool @throw, Ice.Current current) return "Hello"; } - public override string intfUserException(bool @throw, Ice.Current current) + public override string intfUserException(bool shouldThrow, Ice.Current current) { - if (@throw) + if (shouldThrow) { throw new Test.TestIntfUserException(); } From 768ff58f44ea73a86549d60fcc71b1fd304c46d6 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 15:55:18 -0500 Subject: [PATCH 08/17] Finished changes to the 'slice2cs'. --- cpp/src/slice2cs/CsUtil.cpp | 41 ++++++++++++++++++++++++++++++++----- cpp/src/slice2cs/CsUtil.h | 32 ++++++++--------------------- cpp/src/slice2cs/Gen.cpp | 6 +++--- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index e92eefb9ccd..e1926e30871 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -52,17 +52,28 @@ Slice::CsGenerator::getNamespacePrefix(const ContainedPtr& cont) string Slice::CsGenerator::getNamespace(const ContainedPtr& cont) { + // Convert '::' into '.' and remove leading/trailing separators. + stringstream result; + string scope = cont->mappedScope(); - if (scope.rfind('.') == scope.size() - 1) + bool isFirst = true; + for (const auto& id : splitScopedName(scope, false)) { - scope = scope.substr(0, scope.size() - 1); + if (!isFirst) + { + result << '.'; + } + isFirst = false; + result << id; } + + string fixedScope = result.str(); string prefix = getNamespacePrefix(cont); if (!prefix.empty()) { - if (!scope.empty()) + if (!fixedScope.empty()) { - return prefix + "." + scope; + return prefix + "." + fixedScope; } else { @@ -70,7 +81,7 @@ Slice::CsGenerator::getNamespace(const ContainedPtr& cont) } } - return scope; + return fixedScope; } string @@ -88,6 +99,26 @@ Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) } } +string +Slice::CsGenerator::getMappedScoped(const ContainedPtr& p) +{ + stringstream result; + + string name = p->mappedScoped(); + bool isFirst = true; + for (const auto& id : splitScopedName(name, false)) + { + if (!isFirst) + { + result << '.'; + } + isFirst = false; + result << id; + } + + return result.str(); +} + string Slice::CsGenerator::getOptionalFormat(const TypePtr& type) { diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 6c3f1bc1c52..dfbc439eafa 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -8,17 +8,6 @@ namespace Slice { - // TODO remove this temporary. - namespace DotNet - { - enum BaseType - { - Object = 1, - ICloneable = 2, - Exception = 4, - }; - } - class CsGenerator { public: @@ -28,24 +17,21 @@ namespace Slice CsGenerator& operator=(const CsGenerator&) = delete; - // - // Convert a dimension-less array declaration to one with a dimension. - // - static std::string toArrayAlloc(const std::string& decl, const std::string& sz); + /// Convert a dimension-less array declaration to one with a dimension. + [[nodiscard]] static std::string toArrayAlloc(const std::string& decl, const std::string& sz); static void validateMetadata(const UnitPtr&); - // - // Returns the namespace of a Contained entity. - // - static std::string getNamespace(const ContainedPtr&); + /// Returns the namespace of a Contained entity. + [[nodiscard]] static std::string getNamespace(const ContainedPtr&); + + [[nodiscard]] static std::string getUnqualified(const ContainedPtr&, const std::string& package); - static std::string getUnqualified(const ContainedPtr&, const std::string& package); + /// Returns the fully-qualified C# identifier of the provided Slice element. + [[nodiscard]] static std::string getMappedScoped(const ContainedPtr&); protected: - // - // Returns the namespace prefix of a Contained entity. - // + /// Returns the namespace prefix of a Contained entity. static std::string getNamespacePrefix(const ContainedPtr&); static std::string resultStructName(const std::string&, const std::string&, bool = false); diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index ce87e4b5789..cb4b747c9a2 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -661,7 +661,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt ConstPtr constant = dynamic_pointer_cast(valueType); if (constant) { - _out << constant->mappedScoped() << ".value"; + _out << getMappedScoped(constant) << ".value"; } else { @@ -682,7 +682,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt { EnumeratorPtr lte = dynamic_pointer_cast(valueType); assert(lte); - _out << lte->mappedScoped(); + _out << getMappedScoped(lte); } else { @@ -770,7 +770,7 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector ExceptionPtr ex = op->container()->lookupException(exceptionName, false); if (ex) { - name = ex->mappedScoped(); + name = getMappedScoped(ex); } if (!exceptionLines.empty()) From fda72a1f25b8e2dcd10b049155220eb9638cc3d7 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Tue, 28 Jan 2025 16:48:12 -0500 Subject: [PATCH 09/17] Final self-review. --- cpp/src/slice2cs/CsUtil.h | 2 +- cpp/src/slice2cs/Gen.cpp | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index dfbc439eafa..74c710d8065 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -27,7 +27,7 @@ namespace Slice [[nodiscard]] static std::string getUnqualified(const ContainedPtr&, const std::string& package); - /// Returns the fully-qualified C# identifier of the provided Slice element. + /// Returns the fully-qualified C# identifier for the provided Slice element. [[nodiscard]] static std::string getMappedScoped(const ContainedPtr&); protected: diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index cb4b747c9a2..bb2ecf886da 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -61,7 +61,7 @@ namespace return result + "\" />"; } - // TODO we should also replace this function too! + // TODO: this function should probably use the link formatter. string toCsIdent(const string& s) { string::size_type pos = s.find('#'); @@ -154,9 +154,7 @@ namespace string getEscapedParamName(const OperationPtr& p, const string& name) { - ParameterList params = p->parameters(); - - for (const auto& param : params) + for (const auto& param : p->parameters()) { if (param->mappedName() == name) { @@ -209,7 +207,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( for (const auto& pli : params) { - string param = paramPrefix.empty() && !publicNames ? "iceP_" + pli->mappedName() : pli->mappedName(); + string param = (paramPrefix.empty() && !publicNames ? "iceP_" : "") + pli->mappedName(); TypePtr type = pli->type(); if (!marshal && type->isClassType()) { @@ -288,7 +286,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( checkReturnType = false; } - string param = paramPrefix.empty() && !publicNames ? "iceP_" + optional->mappedName() : optional->mappedName(); + string param = (paramPrefix.empty() && !publicNames ? "iceP_" : "") + optional->mappedName(); TypePtr type = optional->type(); if (!marshal && type->isClassType()) { @@ -474,7 +472,7 @@ Slice::CsVisitor::getInParams(const OperationPtr& op, const string& ns, bool int { params.push_back( getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + - (internal ? "iceP_" + q->mappedName() : q->mappedName())); + (internal ? "iceP_" : "") + q->mappedName()); } return params; } @@ -533,7 +531,7 @@ Slice::CsVisitor::getInArgs(const OperationPtr& op, bool internal) { if (!q->isOutParam()) { - args.push_back(internal ? "iceP_" + q->mappedName() : q->mappedName()); + args.push_back((internal ? "iceP_" : "") + q->mappedName()); } } return args; @@ -1876,7 +1874,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << sp; _out << nl << "protected static " << (amd ? "async " : "") - << "global::System.Threading.Tasks.ValueTask iceD_" << opName << "Async("; + << "global::System.Threading.Tasks.ValueTask iceD_" << op->name() << "Async("; _out.inc(); _out << nl << interface->mappedName() << " obj,"; _out << nl << "Ice.IncomingRequest request)"; @@ -2602,8 +2600,9 @@ Slice::Gen::DispatcherVisitor::writeDispatch(const InterfaceDefPtr& p) _out << sb; for (const auto& op : allOps) { - _out << nl << '"' << op->name() << "\" => " << getUnqualified(op->interface(), ns) << ".iceD_" - << op->mappedName()<< "Async(this, request),"; + string opName = op->name(); + _out << nl << '"' << opName << "\" => " << getUnqualified(op->interface(), ns) << ".iceD_" << opName + << "Async(this, request),"; } for (const auto& opName : {"ice_id", "ice_ids", "ice_isA", "ice_ping"}) { From e031cd549635d640a01b4868942b06d2740fa696 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 10:59:07 -0500 Subject: [PATCH 10/17] Eat any leading '@' characters when prefixing things. --- cpp/src/slice2cs/CsUtil.cpp | 9 ++- cpp/src/slice2cs/CsUtil.h | 3 + cpp/src/slice2cs/Gen.cpp | 108 +++++++++++------------------------- cpp/src/slice2cs/Gen.h | 2 - 4 files changed, 42 insertions(+), 80 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index e1926e30871..3bca19e6579 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -119,6 +119,12 @@ Slice::CsGenerator::getMappedScoped(const ContainedPtr& p) return result.str(); } +string +addPrefixToIdentifier(const string& prefix, const string& ident) +{ + return prefix + (ident.find('@') == 0 ? ident.substr(1) : ident); +} + string Slice::CsGenerator::getOptionalFormat(const TypePtr& type) { @@ -237,7 +243,8 @@ string Slice::CsGenerator::resultStructName(const string& className, const string& opName, bool marshaledResult) { ostringstream s; - s << className << "_" << IceInternal::toUpper(opName.substr(0, 1)) << opName.substr(1) + string fixedOpName = addPrefixToIdentifier("", opName); // Strip any leading '@' from the name. + s << className << "_" << IceInternal::toUpper(fixedOpName.substr(0, 1)) << fixedOpName.substr(1) << (marshaledResult ? "MarshaledResult" : "Result"); return s.str(); } diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 74c710d8065..1d1f97c8254 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -30,6 +30,9 @@ namespace Slice /// Returns the fully-qualified C# identifier for the provided Slice element. [[nodiscard]] static std::string getMappedScoped(const ContainedPtr&); + /// Prepends to the provided prefix to `ident`, removing any leading '@' character from `ident` if necessary. + [[nodiscard]] static std::string addPrefixToIdentifier(const std::string& prefix, const std::string& ident); + protected: /// Returns the namespace prefix of a Contained entity. static std::string getNamespacePrefix(const ContainedPtr&); diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index bb2ecf886da..f93dc85be37 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -207,7 +207,11 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( for (const auto& pli : params) { - string param = (paramPrefix.empty() && !publicNames ? "iceP_" : "") + pli->mappedName(); + string param = pli->mappedName(); + if (paramPrefix.empty() && !publicNames) + { + param = addPrefixToIdentifier("iceP_", param); + } TypePtr type = pli->type(); if (!marshal && type->isClassType()) { @@ -286,7 +290,11 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( checkReturnType = false; } - string param = (paramPrefix.empty() && !publicNames ? "iceP_" : "") + optional->mappedName(); + string param = optional->mappedName(); + if (paramPrefix.empty() && !publicNames) + { + param = addPrefixToIdentifier("iceP_", param); + } TypePtr type = optional->type(); if (!marshal && type->isClassType()) { @@ -470,9 +478,8 @@ Slice::CsVisitor::getInParams(const OperationPtr& op, const string& ns, bool int vector params; for (const auto& q : op->inParameters()) { - params.push_back( - getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + - (internal ? "iceP_" : "") + q->mappedName()); + string param = (internal ? addPrefixToIdentifier("iceP_", q->mappedName()) : q->mappedName()); + params.push_back(getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + param); } return params; } @@ -531,7 +538,8 @@ Slice::CsVisitor::getInArgs(const OperationPtr& op, bool internal) { if (!q->isOutParam()) { - args.push_back((internal ? "iceP_" : "") + q->mappedName()); + string param = (internal ? addPrefixToIdentifier("iceP_", q->mappedName()) : q->mappedName()); + args.push_back(param); } } return args; @@ -597,62 +605,6 @@ Slice::CsVisitor::emitNonBrowsableAttribute() << "[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"; } -string -Slice::CsVisitor::writeValue(const TypePtr& type, const string& ns) -{ - assert(type); - - BuiltinPtr builtin = dynamic_pointer_cast(type); - if (builtin) - { - switch (builtin->kind()) - { - case Builtin::KindBool: - { - return "false"; - break; - } - case Builtin::KindByte: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindLong: - { - return "0"; - break; - } - case Builtin::KindFloat: - { - return "0.0f"; - break; - } - case Builtin::KindDouble: - { - return "0.0"; - break; - } - default: - { - return "null"; - break; - } - } - } - - EnumPtr en = dynamic_pointer_cast(type); - if (en) - { - return typeToString(type, ns) + "." + (*en->enumerators().begin())->mappedName(); - } - - StructPtr st = dynamic_pointer_cast(type); - if (st && !isMappedToClass(st)) - { - return "default"; - } - - return "null"; -} - void Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, const string& value) { @@ -773,6 +725,7 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector if (!exceptionLines.empty()) { + // TODOAUSTIN do we want a leading '@' here or not? _out << nl << "/// "; writeDocLines(_out, exceptionLines); _out << nl << "/// "; @@ -791,6 +744,7 @@ Slice::CsVisitor::writeParameterDocComments(const DocComment& comment, const Par auto q = commentParameters.find(param->name()); if (q != commentParameters.end()) { + // TODOAUSTIN do we want a leading '@' here or not? _out << nl << "/// mappedName() << "\">"; writeDocLines(_out, q->second); _out << nl << "/// "; @@ -1893,7 +1847,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << nl << "istr.startEncapsulation();"; for (const auto& pli : inParams) { - string param = "iceP_" + pli->mappedName(); + string param = addPrefixToIdentifier("iceP_", pli->mappedName()); string typeS = typeToString(pli->type(), ns, pli->optional()); _out << nl << typeS << ' ' << param << (pli->type()->isClassType() ? " = null;" : ";"); @@ -1913,7 +1867,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) vector inArgs; for (const auto& pli : inParams) { - inArgs.push_back("iceP_" + pli->mappedName()); + inArgs.push_back(addPrefixToIdentifier("iceP_", pli->mappedName())); } if (op->hasMarshaledResult()) @@ -1950,7 +1904,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) else { // Adapt to marshaling helper below. - string resultParam = !ret && outParams.size() == 1 ? "iceP_" + outParams.front()->mappedName() : "ret"; + string resultParam = !ret && outParams.size() == 1 ? addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) : "ret"; _out << nl << "return Ice.CurrentExtensions.createOutgoingResponse("; _out.inc(); @@ -1977,7 +1931,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) for (const auto& pli : outParams) { string typeS = typeToString(pli->type(), ns, pli->optional()); - _out << nl << typeS << ' ' << "iceP_" + pli->mappedName() << ";"; + _out << nl << typeS << ' ' << addPrefixToIdentifier("iceP_", pli->mappedName()) << ";"; } _out << nl; if (ret) @@ -1987,7 +1941,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << "obj." << opName << spar << inArgs; for (const auto& pli : outParams) { - _out << "out iceP_" + pli->mappedName(); + _out << "out " << addPrefixToIdentifier("iceP_", pli->mappedName()); } _out << "request.current" << epar << ";"; @@ -2084,7 +2038,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << outParams.front()->mappedName() << " = "; } } - _out << "_iceI_" << opName << "Async" << spar << argsAMI << context << "null" + _out << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << argsAMI << context << "null" << "global::System.Threading.CancellationToken.None" << "true" << epar; @@ -2157,8 +2111,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << ("global::System.Threading.CancellationToken " + cancel + " = default") << epar; _out << sb; - _out << nl << "return _iceI_" << opName << "Async" << spar << argsAMI << context << progress << cancel - << "false" << epar << ";"; + _out << nl << "return " << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << argsAMI << context + << progress << cancel << "false" << epar << ";"; _out << eb; // @@ -2170,14 +2124,14 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << "<" << returnTypeS << ">"; } - _out << " _iceI_" << opName << "Async" << spar << getInParams(op, ns, true) + _out << " " << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << getInParams(op, ns, true) << "global::System.Collections.Generic.Dictionary? context" << "global::System.IProgress? progress" << "global::System.Threading.CancellationToken cancel" << "bool synchronous" << epar; _out << sb; - string flatName = "_" + opName + "_name"; + string flatName = addPrefixToIdentifier("_", opName) + "_name"; if (op->returnsData()) { _out << nl << "iceCheckTwowayOnly(" << flatName << ");"; @@ -2193,7 +2147,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << "new Ice.Internal.OperationTaskCompletionCallback<" << returnTypeS << ">(progress, cancel);"; } - _out << nl << "_iceI_" << opName << spar << getInArgs(op, true) << "context" + _out << nl << addPrefixToIdentifier("_iceI_", opName) << spar << getInArgs(op, true) << "context" << "synchronous" << "completed" << epar << ";"; _out << nl << "return completed.Task;"; @@ -2206,7 +2160,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Write the common invoke method // _out << sp << nl; - _out << "private void _iceI_" << opName << spar << getInParams(op, ns, true) + _out << "private void " << addPrefixToIdentifier("_iceI_", opName) << spar << getInParams(op, ns, true) << "global::System.Collections.Generic.Dictionary? context" << "bool synchronous" << "Ice.Internal.OutgoingAsyncCompletionCallback completed" << epar; @@ -2284,8 +2238,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) else { TypePtr t = outParams.front()->type(); - _out << nl << typeToString(t, ns, (outParams.front()->optional())) << " iceP_" - << outParams.front()->mappedName() << (t->isClassType() ? " = null;" : ";"); + _out << nl << typeToString(t, ns, (outParams.front()->optional())) + << addPrefixToIdentifier(" iceP_", outParams.front()->mappedName()) << (t->isClassType() ? " = null;" : ";"); } writeMarshalUnmarshalParams(outParams, op, false, ns, true); @@ -2296,7 +2250,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!ret && outParams.size() == 1) { - _out << nl << "return iceP_" << outParams.front()->mappedName() << ";"; + _out << nl << "return " << addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) << ";"; } else { diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index 0f31bda38fb..7dc124436d8 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -44,8 +44,6 @@ namespace Slice static std::string getParamAttributes(const ParameterPtr&); - std::string writeValue(const TypePtr&, const std::string&); - void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const std::string&); // Generates "= null!" for non-nullable fields (Slice class and exception only). From 13ab236dc66cb736c9e850e9356fee9b2558b8ac Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 11:19:51 -0500 Subject: [PATCH 11/17] Bug fixes. --- cpp/src/slice2cs/CsUtil.cpp | 2 +- cpp/src/slice2cs/Gen.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index 3bca19e6579..5da1e3908fe 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -120,7 +120,7 @@ Slice::CsGenerator::getMappedScoped(const ContainedPtr& p) } string -addPrefixToIdentifier(const string& prefix, const string& ident) +Slice::CsGenerator::addPrefixToIdentifier(const string& prefix, const string& ident) { return prefix + (ident.find('@') == 0 ? ident.substr(1) : ident); } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index f93dc85be37..918f6639304 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -1941,7 +1941,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << "obj." << opName << spar << inArgs; for (const auto& pli : outParams) { - _out << "out " << addPrefixToIdentifier("iceP_", pli->mappedName()); + _out << "out " + addPrefixToIdentifier("iceP_", pli->mappedName()); } _out << "request.current" << epar << ";"; From 72d093bb2c648570b5ec9db7ebf28a118ed81bd0 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 11:20:55 -0500 Subject: [PATCH 12/17] Fixed the escape tests. --- csharp/test/Slice/escape/Clash.ice | 6 +- csharp/test/Slice/escape/Client.cs | 60 +++++----- csharp/test/Slice/escape/Key.ice | 171 ++++++++++++++--------------- js/test/Slice/escape/Key.ice | 19 ---- 4 files changed, 109 insertions(+), 147 deletions(-) diff --git a/csharp/test/Slice/escape/Clash.ice b/csharp/test/Slice/escape/Clash.ice index 0d053b3d893..614694ce045 100644 --- a/csharp/test/Slice/escape/Clash.ice +++ b/csharp/test/Slice/escape/Clash.ice @@ -37,11 +37,11 @@ class Cls string istr; string ostr; string inS; - string in; + ["cs:identifier:@in"] string in; string proxy; int obj; int getCookie; - string clone; + ["cs:identifier:ice_clone_"] string clone; } struct St @@ -51,7 +51,7 @@ struct St int ostr; int rhs; string hashCode; - int clone; + ["cs:identifier:ice_clone_"] int clone; } exception Ex diff --git a/csharp/test/Slice/escape/Client.cs b/csharp/test/Slice/escape/Client.cs index de430f94d10..a7e72bc0b42 100644 --- a/csharp/test/Slice/escape/Client.cs +++ b/csharp/test/Slice/escape/Client.cs @@ -2,7 +2,7 @@ public class Client : Test.TestHelper { - public sealed class caseI : @abstract.caseDisp_ + public sealed class caseI : cs_abstract.caseDisp_ { public override Task catchAsync(int @checked, Ice.Current current) @@ -11,14 +11,14 @@ public override Task } } - public sealed class decimalI : @abstract.decimalDisp_ + public sealed class decimalI : cs_abstract.decimalDisp_ { public override void @default(Ice.Current current) { } } - public sealed class explicitI : @abstract.explicitDisp_ + public sealed class TotallyDifferentI : cs_abstract.TotallyDifferentDisp_ { public override Task catchAsync(int @checked, Ice.Current current) @@ -32,17 +32,7 @@ public override void @default(Ice.Current current) } } - public sealed class implicitI : @abstract.@implicitDisp_ - { - public override @abstract.@as @in(@abstract.@break @internal, @abstract.@delegate @is, @abstract.explicitPrx @lock, - @abstract.casePrx @namespace, @abstract.decimalPrx @new, @abstract.@delegate @null, - int @override, int @params, int @private, Ice.Current current) - { - return @abstract.@as.@base; - } - } - - public sealed class Test1I : @abstract.System.TestDisp_ + public sealed class Test1I : cs_abstract.System.TestDisp_ { public override void op(Ice.Current c) { @@ -59,53 +49,53 @@ public override void op(Ice.Current c) private static void testtypes() { - @abstract.@as a = @abstract.@as.@base; - test(a == @abstract.@as.@base); - @abstract.@break b = new @abstract.@break(); + cs_abstract.@as a = cs_abstract.@as.@base; + test(a == cs_abstract.@as.@base); + cs_abstract.@break b = new cs_abstract.@break(); b.@readonly = 0; test(b.@readonly == 0); - @abstract.@case c = new caseI(); + cs_abstract.@case c = new caseI(); test(c != null); - @abstract.@casePrx c1 = null; + cs_abstract.@casePrx c1 = null; test(c1 == null); int c2 = 0; if (c1 != null) { c1.@catch(0, out c2); } - @abstract.@decimal d = new decimalI(); + cs_abstract.@decimal d = new decimalI(); test(d != null); - @abstract.@decimalPrx d1 = null; + cs_abstract.@decimalPrx d1 = null; if (d1 != null) { d1.@default(); } test(d1 == null); - @abstract.@delegate e = new @abstract.@delegate(); + cs_abstract.@delegate e = new cs_abstract.@delegate(); test(e != null); - @abstract.@delegate e1 = null; + cs_abstract.@delegate e1 = null; test(e1 == null); - @abstract.@explicitPrx f1 = null; + cs_abstract.@TotallyDifferentPrx f1 = null; if (f1 != null) { f1.@catch(0, out c2); f1.@default(); } test(f1 == null); - Dictionary g2 = new Dictionary(); + Dictionary g2 = new Dictionary(); test(g2 != null); - @abstract.@fixed h = new @abstract.@fixed(); + cs_abstract.@fixed h = new cs_abstract.@fixed(); h.@for = 0; test(h != null); - @abstract.@foreach i = new @abstract.@foreach(); + cs_abstract.@foreach i = new cs_abstract.@foreach(); i.@for = 0; i.@goto = 1; i.@if = 2; test(i != null); - @abstract.@implicit j = new implicitI(); - test(j != null); - int k = @abstract.@protected.value; - test(k == 0); + int j = cs_abstract.@protected.value; + test(j == 0); + int k = cs_abstract.@struct.value; + test(k == 1); } public override void run(string[] args) @@ -121,15 +111,15 @@ public override void run(string[] args) Console.Out.Write("testing operation name... "); Console.Out.Flush(); - @abstract.@decimalPrx p = - @abstract.@decimalPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("test"))); + cs_abstract.@decimalPrx p = + cs_abstract.@decimalPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("test"))); p.@default(); Console.Out.WriteLine("ok"); Console.Out.Write("testing System as module name... "); Console.Out.Flush(); - @abstract.System.TestPrx t1 = - @abstract.System.TestPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("test1"))); + cs_abstract.System.TestPrx t1 = + cs_abstract.System.TestPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("test1"))); t1.op(); System.TestPrx t2 = diff --git a/csharp/test/Slice/escape/Key.ice b/csharp/test/Slice/escape/Key.ice index 915ed11cc03..af504847b62 100644 --- a/csharp/test/Slice/escape/Key.ice +++ b/csharp/test/Slice/escape/Key.ice @@ -2,140 +2,131 @@ #pragma once -module abstract +// TODO: figure out a better way to map module names. +module cs_abstract { +["cs:identifier:@as"] enum as { - base + ["cs:identifier:@base"] base } +["cs:identifier:@break"] struct break { - int readonly; + ["cs:identifier:@readonly"] int readonly; } +["cs:identifier:@fixed"] +exception fixed +{ + ["cs:identifier:@for"] int for; +} + +["cs:identifier:@foreach"] +exception foreach extends fixed +{ + ["cs:identifier:@goto"] int goto; + ["cs:identifier:@if"] int Message; +} + +["cs:identifier:@case"] interface case { - ["amd"] void catch(int checked, out int continue); + ["amd", "cs:identifier:@catch"] void catch( + ["cs:identifier:@checked"] int checked, + out ["cs:identifier:@continue"] int continue + ); } +["cs:identifier:@decimal"] interface decimal { - void default(); + ["cs:identifier:@default"] + void default() throws foreach; } +["cs:identifier:@delegate"] class delegate { - int if; - case* else; - int event; + ["cs:identifier:@if"] int if; + ["cs:identifier:@else"] case* else; } +["cs:identifier:TotallyDifferent"] interface explicit extends decimal, case { } +["cs:identifier:@while"] dictionary while; class optionalMembers { - optional(1) break for; - optional(2) as goto; - optional(3) explicit* if; - optional(5) while internal; - optional(7) string namespace; + ["cs:identifier:@for"] optional(1) break for; + ["cs:identifier:@goto"] optional(2) as goto; + ["cs:identifier:@if"] optional(3) explicit* if; + ["cs:identifier:@internal"] optional(5) while internal; + ["cs:identifier:@namespace"] optional(7) string namespace; } interface optionalParams { - optional(1) break for(optional(2) as goto, - optional(3) explicit* if, - optional(5) while internal, - optional(7) string namespace); - - ["amd"] - optional(1) break continue(optional(2) as goto, - optional(3) explicit* if, - optional(5) while internal, - optional(7) string namespace); - - optional(1) break in(out optional(2) as goto, - out optional(3) explicit* if, - out optional(5) while internal, - out optional(7) string namespace); - - ["amd"] - optional(1) break foreach(out optional(2) as goto, - out optional(3) explicit* if, - out optional(5) while internal, - out optional(7) string namespace); -} - -exception fixed -{ - int for; -} - -exception foreach extends fixed -{ - int goto; - int if; -} - -exception BaseMethods -{ - int Data; - int HelpLink; - int InnerException; - int Message; - int Source; - int StackTrace; - int TargetSite; - int HResult; - int Equals; - int GetBaseException; - int GetHashCode; - int GetObjectData; - int GetType; - int ReferenceEquals; - int ToString; -} - -interface implicit -{ - as in(break internal, delegate is, explicit* lock, case* namespace, decimal* new, delegate null, - int override, int params, int private) - throws fixed, foreach; -} - + ["cs:identifier:@for"] + optional(1) break for( + ["cs:identifier:@goto"] optional(2) as goto, + ["cs:identifier:@if"] optional(3) explicit* if, + ["cs:identifier:@internal"] optional(5) while internal, + optional(7) string context + ); + + ["amd", "cs:identifier:@continue"] + optional(1) break continue( + ["cs:identifier:@goto"] optional(2) as goto, + ["cs:identifier:@if"] optional(3) explicit* if, + ["cs:identifier:@internal"] optional(5) while internal, + optional(7) string context + ); + + ["cs:identifier:@in"] + optional(1) break in( + out ["cs:identifier:@goto"] optional(2) as goto, + out ["cs:identifier:@if"] optional(3) explicit* if, + out ["cs:identifier:@internal"] optional(5) while internal, + out optional(7) string context + ); + + ["amd", "cs:identifier:@foreach"] + optional(1) break foreach( + out ["cs:identifier:@goto"] optional(2) as goto, + out ["cs:identifier:@if"] optional(3) explicit* if, + out ["cs:identifier:@internal"] optional(5) while internal, + out optional(7) string context + ); +} + +["cs:identifier:@protected"] const int protected = 0; -const int public = 0; +["cs:identifier:@struct"] +const int \struct = 1; -// // System as inner module. -// module System { - -interface Test -{ - void op(); -} - + interface Test + { + void op(); + } } } -// // System as outer module. -// module System { - -interface Test -{ - void op(); -} - + interface Test + { + void op(); + } } diff --git a/js/test/Slice/escape/Key.ice b/js/test/Slice/escape/Key.ice index 7b1fae14b30..8d46f15f8cd 100644 --- a/js/test/Slice/escape/Key.ice +++ b/js/test/Slice/escape/Key.ice @@ -96,25 +96,6 @@ exception foreach extends fixed int if; } -exception BaseMethods -{ - int Data; - int HelpLink; - int InnerException; - int Message; - int Source; - int StackTrace; - int TargetSite; - int HResult; - int Equals; - int GetBaseException; - int GetHashCode; - int GetObjectData; - int GetType; - int ReferenceEquals; - int ToString; -} - interface implicit { var in(break internal, delete is, explicit* lock, case* namespace, typeof* new, delete null, From d684620dc91daee6133156fb8a3a910d2ae5fe07 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 12:02:05 -0500 Subject: [PATCH 13/17] Formatting and added some doc-comment testing. --- cpp/src/slice2cs/Gen.cpp | 21 +++++++++++---------- csharp/test/Slice/escape/Key.ice | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 918f6639304..2caf39a3e4d 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -725,7 +725,6 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector if (!exceptionLines.empty()) { - // TODOAUSTIN do we want a leading '@' here or not? _out << nl << "/// "; writeDocLines(_out, exceptionLines); _out << nl << "/// "; @@ -744,8 +743,8 @@ Slice::CsVisitor::writeParameterDocComments(const DocComment& comment, const Par auto q = commentParameters.find(param->name()); if (q != commentParameters.end()) { - // TODOAUSTIN do we want a leading '@' here or not? - _out << nl << "/// mappedName() << "\">"; + string fixedParamName = addPrefixToIdentifier("", param->mappedName()); // Strip off any leading '@'s. + _out << nl << "/// "; writeDocLines(_out, q->second); _out << nl << "/// "; } @@ -1874,14 +1873,13 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) { if (amd) { - _out << nl << "var result = await obj." << opName << "Async" << spar << inArgs << "request.current" - << epar << ".ConfigureAwait(false);"; + _out << nl << "var result = await obj." << opName << "Async" << spar << inArgs << "request.current" << epar + << ".ConfigureAwait(false);"; _out << nl << "return new Ice.OutgoingResponse(result.outputStream);"; } else { - _out << nl << "var result = obj." << opName << spar << inArgs - << "request.current" << epar << ";"; + _out << nl << "var result = obj." << opName << spar << inArgs << "request.current" << epar << ";"; _out << nl << "return new (new Ice.OutgoingResponse(result.outputStream));"; } } @@ -1895,7 +1893,8 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << "var result = "; } - _out << "await obj." << opName << "Async" << spar << inArgs << "request.current" << epar << ".ConfigureAwait(false);"; + _out << "await obj." << opName << "Async" << spar << inArgs << "request.current" << epar + << ".ConfigureAwait(false);"; if (retS.empty()) { @@ -1904,7 +1903,8 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) else { // Adapt to marshaling helper below. - string resultParam = !ret && outParams.size() == 1 ? addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) : "ret"; + string resultParam = + !ret && outParams.size() == 1 ? addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) : "ret"; _out << nl << "return Ice.CurrentExtensions.createOutgoingResponse("; _out.inc(); @@ -2239,7 +2239,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { TypePtr t = outParams.front()->type(); _out << nl << typeToString(t, ns, (outParams.front()->optional())) - << addPrefixToIdentifier(" iceP_", outParams.front()->mappedName()) << (t->isClassType() ? " = null;" : ";"); + << addPrefixToIdentifier(" iceP_", outParams.front()->mappedName()) + << (t->isClassType() ? " = null;" : ";"); } writeMarshalUnmarshalParams(outParams, op, false, ns, true); diff --git a/csharp/test/Slice/escape/Key.ice b/csharp/test/Slice/escape/Key.ice index af504847b62..32ad8b91da2 100644 --- a/csharp/test/Slice/escape/Key.ice +++ b/csharp/test/Slice/escape/Key.ice @@ -34,6 +34,7 @@ exception foreach extends fixed ["cs:identifier:@case"] interface case { + /// @param continue make sure the parameter doc-comment is mapped without a leading '@'. ["amd", "cs:identifier:@catch"] void catch( ["cs:identifier:@checked"] int checked, out ["cs:identifier:@continue"] int continue @@ -44,6 +45,7 @@ interface case interface decimal { ["cs:identifier:@default"] + /// @throws foreach make sure the link is correctly generated. void default() throws foreach; } From fd8d0096dd50d507d3b2672abf8c2bc3dccddb19 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 14:13:58 -0500 Subject: [PATCH 14/17] You can specify which separator you want 'mappedScoped' to use now. --- cpp/src/Slice/Parser.cpp | 10 +++---- cpp/src/Slice/Parser.h | 6 ++-- cpp/src/slice2cpp/Gen.cpp | 1 + cpp/src/slice2cs/CsUtil.cpp | 57 ++++--------------------------------- cpp/src/slice2cs/CsUtil.h | 3 -- cpp/src/slice2cs/Gen.cpp | 6 ++-- 6 files changed, 18 insertions(+), 65 deletions(-) diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 4403cbc0f5d..9f1fd5ef419 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -931,20 +931,20 @@ Slice::Contained::mappedName() const } string -Slice::Contained::mappedScoped() const +Slice::Contained::mappedScoped(const string& separator) const { - return mappedScope() + mappedName(); + return mappedScope(separator) + mappedName(); } string -Slice::Contained::mappedScope() const +Slice::Contained::mappedScope(const string& separator) const { string scoped; if (auto container = dynamic_pointer_cast(_container)) { - scoped = container->mappedScoped(); + scoped = container->mappedScoped(separator); } - return scoped + "::"; + return scoped + separator; } string diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 9a2d2acde25..650c240b602 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -397,10 +397,10 @@ namespace Slice /// Returns the mapped identifier that this element will use in the target language. [[nodiscard]] std::string mappedName() const; /// Returns the mapped scope that this element will be generated in in the target language. - [[nodiscard]] std::string mappedScoped() const; + /// (equivalent to `mappedScope(separator) + mappedName()`). + [[nodiscard]] std::string mappedScoped(const std::string& separator = "::") const; /// Returns the mapped fully-scoped identifier that this element will use in the target language. - /// (equivalent to `mappedScoped() + mappedName()`). - [[nodiscard]] std::string mappedScope() const; + [[nodiscard]] std::string mappedScope(const std::string& separator = "::") const; [[nodiscard]] std::string file() const; [[nodiscard]] int line() const; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 38057190499..ad3225d5237 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -237,6 +237,7 @@ namespace return stName; } + // TODO replace this with mappedScoped("_"); /// Returns the fully scoped name of the provided Slice definition, but scope separators will be replaced with /// '_' characters (converting a scoped identifier into a single identifier). string flattenedScopedName(const ContainedPtr& p) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index 5da1e3908fe..d000044246a 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -52,36 +52,11 @@ Slice::CsGenerator::getNamespacePrefix(const ContainedPtr& cont) string Slice::CsGenerator::getNamespace(const ContainedPtr& cont) { - // Convert '::' into '.' and remove leading/trailing separators. - stringstream result; + assert(!dynamic_pointer_cast(cont)); - string scope = cont->mappedScope(); - bool isFirst = true; - for (const auto& id : splitScopedName(scope, false)) - { - if (!isFirst) - { - result << '.'; - } - isFirst = false; - result << id; - } - - string fixedScope = result.str(); + string scope = cont->mappedScope("."); string prefix = getNamespacePrefix(cont); - if (!prefix.empty()) - { - if (!fixedScope.empty()) - { - return prefix + "." + fixedScope; - } - else - { - return prefix; - } - } - - return fixedScope; + return (prefix.empty() ? scope : prefix + "." + scope); } string @@ -99,26 +74,6 @@ Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) } } -string -Slice::CsGenerator::getMappedScoped(const ContainedPtr& p) -{ - stringstream result; - - string name = p->mappedScoped(); - bool isFirst = true; - for (const auto& id : splitScopedName(name, false)) - { - if (!isFirst) - { - result << '.'; - } - isFirst = false; - result << id; - } - - return result.str(); -} - string Slice::CsGenerator::addPrefixToIdentifier(const string& prefix, const string& ident) { @@ -173,9 +128,9 @@ Slice::CsGenerator::typeToString(const TypePtr& type, const string& package, boo "float", "double", "string", - "global::Ice.Object", // not used anymore - "global::Ice.ObjectPrx?", - "global::Ice.Value?"}; + "Ice.Object", // not used anymore + "Ice.ObjectPrx?", + "Ice.Value?"}; BuiltinPtr builtin = dynamic_pointer_cast(type); if (builtin) diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 1d1f97c8254..21cec45ee22 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -27,9 +27,6 @@ namespace Slice [[nodiscard]] static std::string getUnqualified(const ContainedPtr&, const std::string& package); - /// Returns the fully-qualified C# identifier for the provided Slice element. - [[nodiscard]] static std::string getMappedScoped(const ContainedPtr&); - /// Prepends to the provided prefix to `ident`, removing any leading '@' character from `ident` if necessary. [[nodiscard]] static std::string addPrefixToIdentifier(const std::string& prefix, const std::string& ident); diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 2caf39a3e4d..be3b82f8dd9 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -611,7 +611,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt ConstPtr constant = dynamic_pointer_cast(valueType); if (constant) { - _out << getMappedScoped(constant) << ".value"; + _out << constant->mappedScoped(".") << ".value"; } else { @@ -632,7 +632,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt { EnumeratorPtr lte = dynamic_pointer_cast(valueType); assert(lte); - _out << getMappedScoped(lte); + _out << lte->mappedScoped("."); } else { @@ -720,7 +720,7 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector ExceptionPtr ex = op->container()->lookupException(exceptionName, false); if (ex) { - name = getMappedScoped(ex); + name = ex->mappedScoped("."); } if (!exceptionLines.empty()) From c16f28fb974a53cf5904ac19546ec42a49e40bda Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 14:28:51 -0500 Subject: [PATCH 15/17] Review fixes. --- cpp/src/slice2cs/CsUtil.cpp | 6 +++--- cpp/src/slice2cs/CsUtil.h | 4 ++-- cpp/src/slice2cs/Gen.cpp | 37 ++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index d000044246a..d248ad1771e 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -75,9 +75,9 @@ Slice::CsGenerator::getUnqualified(const ContainedPtr& p, const string& package) } string -Slice::CsGenerator::addPrefixToIdentifier(const string& prefix, const string& ident) +Slice::CsGenerator::removeEscapePrefix(const string& identifier) { - return prefix + (ident.find('@') == 0 ? ident.substr(1) : ident); + return identifier.find('@') == 0 ? identifier.substr(1) : identifier; } string @@ -198,7 +198,7 @@ string Slice::CsGenerator::resultStructName(const string& className, const string& opName, bool marshaledResult) { ostringstream s; - string fixedOpName = addPrefixToIdentifier("", opName); // Strip any leading '@' from the name. + string fixedOpName = removeEscapePrefix(opName); s << className << "_" << IceInternal::toUpper(fixedOpName.substr(0, 1)) << fixedOpName.substr(1) << (marshaledResult ? "MarshaledResult" : "Result"); return s.str(); diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 21cec45ee22..0c9cc1f76f4 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -27,8 +27,8 @@ namespace Slice [[nodiscard]] static std::string getUnqualified(const ContainedPtr&, const std::string& package); - /// Prepends to the provided prefix to `ident`, removing any leading '@' character from `ident` if necessary. - [[nodiscard]] static std::string addPrefixToIdentifier(const std::string& prefix, const std::string& ident); + /// Removes a leading '@' character from the provided identifier (if one is present). + [[nodiscard]] static std::string removeEscapePrefix(const std::string& identifier); protected: /// Returns the namespace prefix of a Contained entity. diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index be3b82f8dd9..9b99cb6e074 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -210,7 +210,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( string param = pli->mappedName(); if (paramPrefix.empty() && !publicNames) { - param = addPrefixToIdentifier("iceP_", param); + param = "iceP_" + removeEscapePrefix(param); } TypePtr type = pli->type(); if (!marshal && type->isClassType()) @@ -293,7 +293,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( string param = optional->mappedName(); if (paramPrefix.empty() && !publicNames) { - param = addPrefixToIdentifier("iceP_", param); + param = "iceP_" + removeEscapePrefix(param); } TypePtr type = optional->type(); if (!marshal && type->isClassType()) @@ -478,7 +478,7 @@ Slice::CsVisitor::getInParams(const OperationPtr& op, const string& ns, bool int vector params; for (const auto& q : op->inParameters()) { - string param = (internal ? addPrefixToIdentifier("iceP_", q->mappedName()) : q->mappedName()); + string param = (internal ? ("iceP_" + removeEscapePrefix(q->mappedName())) : q->mappedName()); params.push_back(getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + param); } return params; @@ -538,7 +538,7 @@ Slice::CsVisitor::getInArgs(const OperationPtr& op, bool internal) { if (!q->isOutParam()) { - string param = (internal ? addPrefixToIdentifier("iceP_", q->mappedName()) : q->mappedName()); + string param = (internal ? ("iceP_" + removeEscapePrefix(q->mappedName())) : q->mappedName()); args.push_back(param); } } @@ -743,8 +743,7 @@ Slice::CsVisitor::writeParameterDocComments(const DocComment& comment, const Par auto q = commentParameters.find(param->name()); if (q != commentParameters.end()) { - string fixedParamName = addPrefixToIdentifier("", param->mappedName()); // Strip off any leading '@'s. - _out << nl << "/// "; + _out << nl << "/// mappedName()) << "\">"; writeDocLines(_out, q->second); _out << nl << "/// "; } @@ -1846,7 +1845,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << nl << "istr.startEncapsulation();"; for (const auto& pli : inParams) { - string param = addPrefixToIdentifier("iceP_", pli->mappedName()); + string param = "iceP_" + removeEscapePrefix(pli->mappedName()); string typeS = typeToString(pli->type(), ns, pli->optional()); _out << nl << typeS << ' ' << param << (pli->type()->isClassType() ? " = null;" : ";"); @@ -1866,7 +1865,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) vector inArgs; for (const auto& pli : inParams) { - inArgs.push_back(addPrefixToIdentifier("iceP_", pli->mappedName())); + inArgs.push_back("iceP_" + removeEscapePrefix(pli->mappedName())); } if (op->hasMarshaledResult()) @@ -1904,7 +1903,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) { // Adapt to marshaling helper below. string resultParam = - !ret && outParams.size() == 1 ? addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) : "ret"; + !ret && outParams.size() == 1 ? ("iceP_" + removeEscapePrefix(outParams.front()->mappedName())) : "ret"; _out << nl << "return Ice.CurrentExtensions.createOutgoingResponse("; _out.inc(); @@ -1931,7 +1930,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) for (const auto& pli : outParams) { string typeS = typeToString(pli->type(), ns, pli->optional()); - _out << nl << typeS << ' ' << addPrefixToIdentifier("iceP_", pli->mappedName()) << ";"; + _out << nl << typeS << " iceP_" << removeEscapePrefix(pli->mappedName()) << ";"; } _out << nl; if (ret) @@ -1941,7 +1940,7 @@ Slice::Gen::DispatchAdapterVisitor::visitOperation(const OperationPtr& op) _out << "obj." << opName << spar << inArgs; for (const auto& pli : outParams) { - _out << "out " + addPrefixToIdentifier("iceP_", pli->mappedName()); + _out << "out iceP_" + removeEscapePrefix(pli->mappedName()); } _out << "request.current" << epar << ";"; @@ -2038,7 +2037,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << outParams.front()->mappedName() << " = "; } } - _out << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << argsAMI << context << "null" + _out << "_iceI_" << removeEscapePrefix(opName) << "Async" << spar << argsAMI << context << "null" << "global::System.Threading.CancellationToken.None" << "true" << epar; @@ -2111,7 +2110,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << ("global::System.Threading.CancellationToken " + cancel + " = default") << epar; _out << sb; - _out << nl << "return " << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << argsAMI << context + _out << nl << "return _iceI_" << removeEscapePrefix(opName) << "Async" << spar << argsAMI << context << progress << cancel << "false" << epar << ";"; _out << eb; @@ -2124,14 +2123,14 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << "<" << returnTypeS << ">"; } - _out << " " << addPrefixToIdentifier("_iceI_", opName) << "Async" << spar << getInParams(op, ns, true) + _out << " _iceI_" << removeEscapePrefix(opName) << "Async" << spar << getInParams(op, ns, true) << "global::System.Collections.Generic.Dictionary? context" << "global::System.IProgress? progress" << "global::System.Threading.CancellationToken cancel" << "bool synchronous" << epar; _out << sb; - string flatName = addPrefixToIdentifier("_", opName) + "_name"; + string flatName = "_" + removeEscapePrefix(opName) + "_name"; if (op->returnsData()) { _out << nl << "iceCheckTwowayOnly(" << flatName << ");"; @@ -2147,7 +2146,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << "new Ice.Internal.OperationTaskCompletionCallback<" << returnTypeS << ">(progress, cancel);"; } - _out << nl << addPrefixToIdentifier("_iceI_", opName) << spar << getInArgs(op, true) << "context" + _out << nl << "_iceI_" << removeEscapePrefix(opName) << spar << getInArgs(op, true) << "context" << "synchronous" << "completed" << epar << ";"; _out << nl << "return completed.Task;"; @@ -2160,7 +2159,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Write the common invoke method // _out << sp << nl; - _out << "private void " << addPrefixToIdentifier("_iceI_", opName) << spar << getInParams(op, ns, true) + _out << "private void _iceI_" << removeEscapePrefix(opName) << spar << getInParams(op, ns, true) << "global::System.Collections.Generic.Dictionary? context" << "bool synchronous" << "Ice.Internal.OutgoingAsyncCompletionCallback completed" << epar; @@ -2239,7 +2238,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { TypePtr t = outParams.front()->type(); _out << nl << typeToString(t, ns, (outParams.front()->optional())) - << addPrefixToIdentifier(" iceP_", outParams.front()->mappedName()) + << " iceP_" << removeEscapePrefix(outParams.front()->mappedName()) << (t->isClassType() ? " = null;" : ";"); } @@ -2251,7 +2250,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!ret && outParams.size() == 1) { - _out << nl << "return " << addPrefixToIdentifier("iceP_", outParams.front()->mappedName()) << ";"; + _out << nl << "return iceP_" << removeEscapePrefix(outParams.front()->mappedName()) << ";"; } else { From 87313caa75c38cfa6b9075bf4b322bf02d61abbd Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 14:33:25 -0500 Subject: [PATCH 16/17] Forgot to strip leading scope separator in some places. --- cpp/src/slice2cs/CsUtil.cpp | 2 +- cpp/src/slice2cs/Gen.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index d248ad1771e..e655af5a12b 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -54,7 +54,7 @@ Slice::CsGenerator::getNamespace(const ContainedPtr& cont) { assert(!dynamic_pointer_cast(cont)); - string scope = cont->mappedScope("."); + string scope = cont->mappedScope(".").substr(1); string prefix = getNamespacePrefix(cont); return (prefix.empty() ? scope : prefix + "." + scope); } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 9b99cb6e074..a8197238cf9 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -611,7 +611,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt ConstPtr constant = dynamic_pointer_cast(valueType); if (constant) { - _out << constant->mappedScoped(".") << ".value"; + _out << constant->mappedScoped(".").substr(1) << ".value"; } else { @@ -632,7 +632,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt { EnumeratorPtr lte = dynamic_pointer_cast(valueType); assert(lte); - _out << lte->mappedScoped("."); + _out << lte->mappedScoped(".").substr(1); } else { @@ -720,7 +720,7 @@ Slice::CsVisitor::writeOpDocComment(const OperationPtr& op, const vector ExceptionPtr ex = op->container()->lookupException(exceptionName, false); if (ex) { - name = ex->mappedScoped("."); + name = ex->mappedScoped(".").substr(1); } if (!exceptionLines.empty()) From fb54fcf306d6e8db351a80a0d794b2c2e33ffb32 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Wed, 29 Jan 2025 14:42:35 -0500 Subject: [PATCH 17/17] More formatting... --- cpp/src/slice2cs/CsUtil.cpp | 1 + cpp/src/slice2cs/Gen.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index e655af5a12b..90d8078f843 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -55,6 +55,7 @@ Slice::CsGenerator::getNamespace(const ContainedPtr& cont) assert(!dynamic_pointer_cast(cont)); string scope = cont->mappedScope(".").substr(1); + scope.pop_back(); // Remove the trailing '.' on the scope. string prefix = getNamespacePrefix(cont); return (prefix.empty() ? scope : prefix + "." + scope); } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index a8197238cf9..98a167b3bbc 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -2110,8 +2110,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << ("global::System.Threading.CancellationToken " + cancel + " = default") << epar; _out << sb; - _out << nl << "return _iceI_" << removeEscapePrefix(opName) << "Async" << spar << argsAMI << context - << progress << cancel << "false" << epar << ";"; + _out << nl << "return _iceI_" << removeEscapePrefix(opName) << "Async" << spar << argsAMI << context << progress + << cancel << "false" << epar << ";"; _out << eb; // @@ -2237,9 +2237,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) else { TypePtr t = outParams.front()->type(); - _out << nl << typeToString(t, ns, (outParams.front()->optional())) - << " iceP_" << removeEscapePrefix(outParams.front()->mappedName()) - << (t->isClassType() ? " = null;" : ";"); + _out << nl << typeToString(t, ns, (outParams.front()->optional())) << " iceP_" + << removeEscapePrefix(outParams.front()->mappedName()) << (t->isClassType() ? " = null;" : ";"); } writeMarshalUnmarshalParams(outParams, op, false, ns, true);