diff --git a/cpp/src/IceGrid/DescriptorBuilder.cpp b/cpp/src/IceGrid/DescriptorBuilder.cpp index 91294459481..2d7031188ee 100644 --- a/cpp/src/IceGrid/DescriptorBuilder.cpp +++ b/cpp/src/IceGrid/DescriptorBuilder.cpp @@ -408,7 +408,7 @@ ApplicationDescriptorBuilder::isOverride(const string& name) ServerInstanceDescriptorBuilder::ServerInstanceDescriptorBuilder(const XmlAttributesHelper& attrs) { - _descriptor._cpp_template = attrs("template"); + _descriptor.templateName = attrs("template"); _descriptor.parameterValues = attrs.asMap(); _descriptor.parameterValues.erase("template"); } @@ -724,7 +724,7 @@ CommunicatorDescriptorBuilder::addProperty(PropertyDescriptorSeq& properties, co ServiceInstanceDescriptorBuilder::ServiceInstanceDescriptorBuilder(const XmlAttributesHelper& attrs) { - _descriptor._cpp_template = attrs("template"); + _descriptor.templateName = attrs("template"); _descriptor.parameterValues = attrs.asMap(); _descriptor.parameterValues.erase("template"); } diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index 26e541698de..f194c067d62 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -1729,7 +1729,7 @@ ServiceInstanceHelper::ServiceInstanceHelper(ServiceInstanceDescriptor desc, boo // descriptor must be set and contain the definition of the // service. // - if (_def._cpp_template.empty() && !_def.descriptor) + if (_def.templateName.empty() && !_def.descriptor) { throw DeploymentException("invalid service instance: no template defined"); } @@ -1743,13 +1743,13 @@ ServiceInstanceHelper::ServiceInstanceHelper(ServiceInstanceDescriptor desc, boo bool ServiceInstanceHelper::operator==(const ServiceInstanceHelper& helper) const { - if (_def._cpp_template.empty()) + if (_def.templateName.empty()) { return _service == helper._service; } else { - return _def._cpp_template == helper._def._cpp_template && _def.parameterValues == helper._def.parameterValues && + return _def.templateName == helper._def.templateName && _def.parameterValues == helper._def.parameterValues && _def.propertySet == helper._def.propertySet; } } @@ -1767,12 +1767,12 @@ ServiceInstanceHelper::instantiate(const Resolver& resolve, const PropertySetDes std::map parameterValues; if (!def.getDescriptor()) { - assert(!_def._cpp_template.empty()); - TemplateDescriptor tmpl = resolve.getServiceTemplate(_def._cpp_template); + assert(!_def.templateName.empty()); + TemplateDescriptor tmpl = resolve.getServiceTemplate(_def.templateName); def = ServiceHelper(dynamic_pointer_cast(tmpl.descriptor)); parameterValues = instantiateParams( resolve, - _def._cpp_template, + _def.templateName, _def.parameterValues, tmpl.parameters, tmpl.parameterDefaults); @@ -1797,7 +1797,7 @@ ServiceInstanceHelper::instantiate(const Resolver& resolve, const PropertySetDes // the template + parameters which would be wrong (if the template // changed the instance also changed.) // - // desc._cpp_template = _template; + // desc.templateName = _template; // desc.parameterValues = _parameters; return desc; } @@ -1825,10 +1825,10 @@ ServiceInstanceHelper::print(const shared_ptr& communicator, } else { - assert(!_def._cpp_template.empty()); + assert(!_def.templateName.empty()); out << "service instance"; out << sb; - out << nl << "template = '" << _def._cpp_template << "'"; + out << nl << "template = '" << _def.templateName << "'"; out << nl << "parameters"; out << sb; for (const auto& parameterValue : _def.parameterValues) @@ -1865,7 +1865,7 @@ ServerInstanceHelper::init(const shared_ptr& definition, const std::map parameterValues; if (!def) { - if (_def._cpp_template.empty()) + if (_def.templateName.empty()) { resolve.exception("invalid server instance: template is not defined"); } @@ -1873,11 +1873,11 @@ ServerInstanceHelper::init(const shared_ptr& definition, const // // Get the server definition and the template property sets. // - TemplateDescriptor tmpl = resolve.getServerTemplate(_def._cpp_template); + TemplateDescriptor tmpl = resolve.getServerTemplate(_def.templateName); def = dynamic_pointer_cast(tmpl.descriptor); parameterValues = instantiateParams( resolve, - _def._cpp_template, + _def.templateName, _def.parameterValues, tmpl.parameters, tmpl.parameterDefaults); @@ -1916,9 +1916,9 @@ ServerInstanceHelper::init(const shared_ptr& definition, const // Instantiate the server instance definition (we use the server // resolver above, so using parameters in properties is possible). // - if (!_def._cpp_template.empty()) + if (!_def.templateName.empty()) { - _instance._cpp_template = _def._cpp_template; + _instance.templateName = _def.templateName; _instance.parameterValues = parameterValues; _instance.propertySet = svrResolve(_def.propertySet); for (const auto& servicePropertySet : _def.servicePropertySets) @@ -1939,13 +1939,13 @@ ServerInstanceHelper::init(const shared_ptr& definition, const bool ServerInstanceHelper::operator==(const ServerInstanceHelper& helper) const { - if (_def._cpp_template.empty()) + if (_def.templateName.empty()) { return *_serverDefinition == *helper._serverDefinition; } else { - return _def._cpp_template == helper._def._cpp_template && _def.parameterValues == helper._def.parameterValues && + return _def.templateName == helper._def.templateName && _def.parameterValues == helper._def.parameterValues && _def.propertySet == helper._def.propertySet && _def.servicePropertySets == helper._def.servicePropertySets; } @@ -1966,21 +1966,21 @@ ServerInstanceHelper::getId() const ServerInstanceDescriptor ServerInstanceHelper::getDefinition() const { - assert(!_def._cpp_template.empty()); + assert(!_def.templateName.empty()); return _def; } ServerInstanceDescriptor ServerInstanceHelper::getInstance() const { - assert(!_def._cpp_template.empty() && !_instance._cpp_template.empty()); + assert(!_def.templateName.empty() && !_instance.templateName.empty()); return _instance; } shared_ptr ServerInstanceHelper::getServerDefinition() const { - assert(_def._cpp_template.empty()); + assert(_def.templateName.empty()); return _serverDefinition->getDescriptor(); } diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index 9a0e545245d..1ca4051d700 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -821,7 +821,7 @@ Parser::instantiateServerTemplate(const list& args) } ServerInstanceDescriptor desc; - desc._cpp_template = templ; + desc.templateName = templ; desc.parameterValues = vars; _admin->instantiateServer(application, node, desc); } diff --git a/cpp/src/Slice/MetadataValidation.cpp b/cpp/src/Slice/MetadataValidation.cpp index 3a845e44f1d..54012cc866d 100644 --- a/cpp/src/Slice/MetadataValidation.cpp +++ b/cpp/src/Slice/MetadataValidation.cpp @@ -83,9 +83,9 @@ Slice::validateMetadata(const UnitPtr& p, string_view prefix, maptag() < rhs->tag(); } +// NOTE: It is important that this list is kept in alphabetical order! +constexpr string_view languages[] = {"cpp", "cs", "java", "js", "matlab", "php", "python", "ruby", "swift"}; + // Forward declare things from Bison and Flex the parser can use. extern int slice_parse(); extern int slice_lineno; @@ -104,8 +107,6 @@ Slice::Metadata::Metadata(string rawMetadata, string file, int line) : GrammarBa if (firstColonPos != string::npos) { // Check if the metadata starts with a language prefix. - // NOTE: It is important that this list is kept in alphabetical order! - constexpr string_view languages[] = {"cpp", "cs", "java", "js", "matlab", "php", "python", "rb", "swift"}; string prefix = rawMetadata.substr(0, firstColonPos); bool hasLangPrefix = binary_search(&languages[0], &languages[sizeof(languages) / sizeof(*languages)], prefix); if (hasLangPrefix) @@ -562,27 +563,52 @@ Slice::Contained::name() const string Slice::Contained::scoped() const { - return _scoped; + return scope() + name(); } string Slice::Contained::scope() const { - string::size_type idx = _scoped.rfind("::"); - assert(idx != string::npos); - return string(_scoped, 0, idx + 2); + string scoped; + if (auto container = dynamic_pointer_cast(_container)) + { + scoped = container->scoped(); + } + return scoped + "::"; } string -Slice::Contained::flattenedScope() const +Slice::Contained::mappedName() const { - string s = scope(); - string::size_type pos = 0; - while ((pos = s.find("::", pos)) != string::npos) + const string languageName = _unit->languageName(); + assert(!languageName.empty()); + + // First check if any 'xxx:identifier' has been applied to this element. + // If so, we return that instead of the element's Slice identifier. + const string metadata = languageName + ":identifier"; + if (auto customName = getMetadataArgs(metadata)) { - s.replace(pos, 2, "_"); + return *customName; } - return s; + + return _name; +} + +string +Slice::Contained::mappedScoped() const +{ + return mappedScope() + mappedName(); +} + +string +Slice::Contained::mappedScope() const +{ + string scoped; + if (auto container = dynamic_pointer_cast(_container)) + { + scoped = container->mappedScoped(); + } + return scoped + "::"; } string @@ -1050,12 +1076,6 @@ Slice::Contained::Contained(const ContainerPtr& container, string name) _container(container), _name(std::move(name)) { - ContainedPtr cont = dynamic_pointer_cast(_container); - if (cont) - { - _scoped = cont->scoped(); - } - _scoped += "::" + _name; assert(_unit); _file = _unit->currentFile(); _line = _unit->currentLine(); @@ -4544,7 +4564,7 @@ Slice::DataMember::DataMember( // ---------------------------------------------------------------------- UnitPtr -Slice::Unit::createUnit(bool all, const StringList& defaultFileMetadata) +Slice::Unit::createUnit(string languageName, bool all, const StringList& defaultFileMetadata) { MetadataList defaultMetadata; for (const auto& metadataString : defaultFileMetadata) @@ -4552,11 +4572,17 @@ Slice::Unit::createUnit(bool all, const StringList& defaultFileMetadata) defaultMetadata.push_back(make_shared(metadataString, "", 0)); } - UnitPtr unit{new Unit{all, std::move(defaultMetadata)}}; + UnitPtr unit{new Unit{std::move(languageName), all, std::move(defaultMetadata)}}; unit->_unit = unit; return unit; } +string +Slice::Unit::languageName() const +{ + return _languageName; +} + void Slice::Unit::setDocComment(const string& comment) { @@ -5006,15 +5032,19 @@ Slice::Unit::getTopLevelModules(const string& file) const } } -Slice::Unit::Unit(bool all, MetadataList defaultFileMetadata) +Slice::Unit::Unit(string languageName, bool all, MetadataList defaultFileMetadata) : SyntaxTreeBase(nullptr), Container(nullptr), + _languageName(std::move(languageName)), _all(all), _defaultFileMetadata(std::move(defaultFileMetadata)), _errors(0), _currentIncludeLevel(0) - { + if (!languageName.empty()) + { + assert(binary_search(&languages[0], &languages[sizeof(languages) / sizeof(*languages)], _languageName)); + } } // ---------------------------------------------------------------------- diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 27e5b48c24d..03edcc0ac60 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -363,10 +363,22 @@ namespace Slice { public: [[nodiscard]] ContainerPtr container() const; + + /// Returns the Slice identifier of this element. [[nodiscard]] std::string name() const; - [[nodiscard]] std::string scoped() const; + /// Returns the Slice scope that this element is contained within (with a trailing '::'). [[nodiscard]] std::string scope() const; - [[nodiscard]] std::string flattenedScope() const; + /// Returns the fully-scoped Slice identifier of this element (equivalent to `scope() + name()`). + [[nodiscard]] std::string scoped() const; + + /// 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; + /// 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 file() const; [[nodiscard]] int line() const; @@ -401,7 +413,6 @@ namespace Slice ContainerPtr _container; std::string _name; - std::string _scoped; std::string _file; int _line; std::string _docComment; @@ -419,33 +430,35 @@ namespace Slice Container(const UnitPtr& unit); void destroy() override; ModulePtr createModule(const std::string& name); - ClassDefPtr createClassDef(const std::string& name, int id, const ClassDefPtr& base); - ClassDeclPtr createClassDecl(const std::string& name); - InterfaceDefPtr createInterfaceDef(const std::string& name, const InterfaceList& bases); - InterfaceDeclPtr createInterfaceDecl(const std::string& name); - ExceptionPtr createException(const std::string& name, const ExceptionPtr& base, NodeType nodeType = Real); - StructPtr createStruct(const std::string& name, NodeType nodeType = Real); - SequencePtr + [[nodiscard]] ClassDefPtr createClassDef(const std::string& name, int id, const ClassDefPtr& base); + [[nodiscard]] ClassDeclPtr createClassDecl(const std::string& name); + [[nodiscard]] InterfaceDefPtr createInterfaceDef(const std::string& name, const InterfaceList& bases); + [[nodiscard]] InterfaceDeclPtr createInterfaceDecl(const std::string& name); + [[nodiscard]] ExceptionPtr + createException(const std::string& name, const ExceptionPtr& base, NodeType nodeType = Real); + [[nodiscard]] StructPtr createStruct(const std::string& name, NodeType nodeType = Real); + [[nodiscard]] SequencePtr createSequence(const std::string& name, const TypePtr& type, MetadataList metadata, NodeType nodeType = Real); - DictionaryPtr createDictionary( + [[nodiscard]] DictionaryPtr createDictionary( const std::string& name, const TypePtr& keyType, MetadataList keyMetadata, const TypePtr& valueType, MetadataList valueMetadata, NodeType nodeType = Real); - EnumPtr createEnum(const std::string& name, NodeType nodeType = Real); - ConstPtr createConst( + [[nodiscard]] EnumPtr createEnum(const std::string& name, NodeType nodeType = Real); + [[nodiscard]] ConstPtr createConst( const std::string name, const TypePtr& constType, MetadataList metadata, const SyntaxTreeBasePtr& valueType, const std::string& value, NodeType nodeType = Real); - TypeList lookupType(const std::string& identifier); - TypeList lookupTypeNoBuiltin(const std::string& identifier, bool emitErrors, bool ignoreUndefined = false); - ContainedList lookupContained(const std::string& identifier, bool emitErrors); - ExceptionPtr lookupException(const std::string& identifier, bool emitErrors); + [[nodiscard]] TypeList lookupType(const std::string& identifier); + [[nodiscard]] TypeList + lookupTypeNoBuiltin(const std::string& identifier, bool emitErrors, bool ignoreUndefined = false); + [[nodiscard]] ContainedList lookupContained(const std::string& identifier, bool emitErrors); + [[nodiscard]] ExceptionPtr lookupException(const std::string& identifier, bool emitErrors); [[nodiscard]] UnitPtr unit() const; [[nodiscard]] ModuleList modules() const; [[nodiscard]] InterfaceList interfaces() const; @@ -453,7 +466,6 @@ namespace Slice [[nodiscard]] EnumeratorList enumerators() const; [[nodiscard]] EnumeratorList enumerators(const std::string& identifier) const; [[nodiscard]] ContainedList contents() const; - [[nodiscard]] std::string thisScope() const; void visit(ParserVisitor* visitor) override; bool checkIntroduced(const std::string& scopedName, ContainedPtr namedThing = nullptr); @@ -483,6 +495,8 @@ namespace Slice } protected: + [[nodiscard]] std::string thisScope() const; + bool validateConstant( const std::string& name, const TypePtr& type, @@ -987,7 +1001,10 @@ namespace Slice class Unit final : public virtual Container { public: - static UnitPtr createUnit(bool all, const StringList& defaultFileMetadata = StringList()); + static UnitPtr + createUnit(std::string languageName, bool all, const StringList& defaultFileMetadata = StringList()); + + [[nodiscard]] std::string languageName() const; void setDocComment(const std::string& comment); void addToDocComment(const std::string& comment); @@ -1039,11 +1056,12 @@ namespace Slice [[nodiscard]] std::set getTopLevelModules(const std::string& file) const; private: - Unit(bool all, MetadataList defaultFileMetadata); + Unit(std::string languageName, bool all, MetadataList defaultFileMetadata); void pushDefinitionContext(); void popDefinitionContext(); + const std::string _languageName; bool _all; MetadataList _defaultFileMetadata; int _errors; diff --git a/cpp/src/ice2slice/Main.cpp b/cpp/src/ice2slice/Main.cpp index b57ebedcaf2..de36ca667b7 100644 --- a/cpp/src/ice2slice/Main.cpp +++ b/cpp/src/ice2slice/Main.cpp @@ -176,7 +176,7 @@ compile(const vector& argv) } else { - UnitPtr p = Unit::createUnit(false); + UnitPtr p = Unit::createUnit("", false); int parseStatus = p->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.cpp b/cpp/src/slice2cpp/CPlusPlusUtil.cpp index 41a59ead5bf..fd20814eee9 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.cpp +++ b/cpp/src/slice2cpp/CPlusPlusUtil.cpp @@ -99,7 +99,7 @@ namespace } else { - return getUnqualified(fixKwd(seq->scoped()), scope); + return getUnqualified(seq->mappedScoped(), scope); } } @@ -112,7 +112,7 @@ namespace const string dictType = findMetadata(metadata, typeCtx); if (dictType.empty()) { - return getUnqualified(fixKwd(dict->scoped()), scope); + return getUnqualified(dict->mappedScoped(), scope); } else { @@ -176,19 +176,6 @@ namespace return false; } - void writeParamAllocateCode( - Output& out, - const TypePtr& type, - bool optional, - const string& scope, - const string& fixedName, - const MetadataList& metadata, - TypeContext typeCtx) - { - string s = typeToString(type, optional, scope, metadata, typeCtx); - out << nl << s << ' ' << fixedName << ';'; - } - void writeMarshalUnmarshalParams(Output& out, const ParameterList& params, const OperationPtr& op, bool marshal) { const string returnValueS = "ret"; @@ -228,17 +215,17 @@ namespace out << stream << "->readAll"; } out << spar; - for (const auto& requiredParam : requiredParams) + for (const auto& param : requiredParams) { if (tuple) { - auto index = std::distance(params.begin(), std::find(params.begin(), params.end(), requiredParam)) + - retOffset; + auto index = + std::distance(params.begin(), std::find(params.begin(), params.end(), param)) + retOffset; out << "::std::get<" + std::to_string(index) + ">(v)"; } else { - out << fixKwd(paramPrefix + requiredParam->name()); + out << paramPrefix + param->mappedName(); } } if (op && op->returnType() && !op->returnIsOptional()) @@ -313,9 +300,9 @@ namespace // Parameters // bool checkReturnType = op && op->returnIsOptional(); - for (const auto& optional : optionals) + for (const auto& param : optionals) { - if (checkReturnType && op->returnTag() < optional->tag()) + if (checkReturnType && op->returnTag() < param->tag()) { if (tuple) { @@ -330,13 +317,13 @@ namespace if (tuple) { - auto index = std::distance(params.begin(), std::find(params.begin(), params.end(), optional)) + - retOffset; + auto index = + std::distance(params.begin(), std::find(params.begin(), params.end(), param)) + retOffset; out << "::std::get<" + std::to_string(index) + ">(v)"; } else { - out << fixKwd(paramPrefix + optional->name()); + out << paramPrefix + param->mappedName(); } } if (checkReturnType) @@ -543,25 +530,25 @@ Slice::typeToString( ClassDeclPtr cl = dynamic_pointer_cast(type); if (cl) { - return getUnqualified(fixKwd(cl->scoped() + "Ptr"), scope); + return getUnqualified(cl->mappedScoped() + "Ptr", scope); } StructPtr st = dynamic_pointer_cast(type); if (st) { - return getUnqualified(fixKwd(st->scoped()), scope); + return getUnqualified(st->mappedScoped(), scope); } InterfaceDeclPtr proxy = dynamic_pointer_cast(type); if (proxy) { - return "::std::optional<" + getUnqualified(fixKwd(proxy->scoped() + "Prx"), scope) + ">"; + return "::std::optional<" + getUnqualified(proxy->mappedScoped() + "Prx", scope) + ">"; } EnumPtr en = dynamic_pointer_cast(type); if (en) { - return getUnqualified(fixKwd(en->scoped()), scope); + return getUnqualified(en->mappedScoped(), scope); } SequencePtr seq = dynamic_pointer_cast(type); @@ -664,140 +651,6 @@ Slice::opFormatTypeToString(const OperationPtr& op) } } -/// If the passed name is a keyword, return the name with a "_cpp_" prefix; -/// otherwise, return the name unchanged. -static string -lookupKwd(const string& name) -{ - // Keyword list. *Must* be kept in alphabetical order. - // - // Note that this keyword list unnecessarily contains C++ keywords - // that are illegal Slice identifiers -- namely identifiers that - // are Slice keywords (class, int, etc.). They have not been removed - // so that the keyword list is kept complete. - static const string keywordList[] = { - "alignas", - "alignof", - "and", - "and_eq", - "asm", - "auto", - "bitand", - "bitor", - "bool", - "break", - "case", - "catch", - "char", - "char16_t", - "char32_t", - "char8_t", - "class", - "co_await", - "co_return", - "co_yield", - "compl", - "concept", - "const", - "const_cast", - "consteval", - "constexpr", - "constinit", - "continue", - "decltype", - "default", - "delete", - "do", - "double", - "dynamic_cast", - "else", - "enum", - "explicit", - "export", - "extern", - "false", - "final", - "float", - "for", - "friend", - "goto", - "if", - "import", - "inline", - "int", - "long", - "module", - "mutable", - "namespace", - "new", - "noexcept", - "not", - "not_eq", - "nullptr", - "operator", - "or", - "or_eq", - "override", - "private", - "protected", - "public", - "register", - "reinterpret_cast", - "requires", - "return", - "short", - "signed", - "sizeof", - "static", - "static_assert", - "static_cast", - "struct", - "switch", - "template", - "this", - "thread_local", - "throw", - "true", - "try", - "typedef", - "typeid", - "typename", - "union", - "unsigned", - "using", - "virtual", - "void", - "volatile", - "wchar_t", - "while", - "xor", - "xor_eq"}; - bool found = binary_search(&keywordList[0], &keywordList[sizeof(keywordList) / sizeof(*keywordList)], name); - return found ? "_cpp_" + name : name; -} - -/// If the passed name is a scoped name, return the identical scoped name, -/// but with all components that are C++ keywords replaced by -/// their "_cpp_"-prefixed version; otherwise, if the passed name is -/// not scoped, but a C++ keyword, return the "_cpp_"-prefixed name; -/// otherwise, return the name unchanged. -string -Slice::fixKwd(const string& name) -{ - if (name[0] != ':') - { - return lookupKwd(name); - } - vector ids = splitScopedName(name); - transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); - stringstream result; - for (const auto& id : ids) - { - result << "::" + id; - } - return result.str(); -} - void Slice::writeMarshalCode(Output& out, const ParameterList& params, const OperationPtr& op) { @@ -820,26 +673,14 @@ Slice::writeAllocateCode( { for (const auto& param : params) { - writeParamAllocateCode( - out, - param->type(), - param->optional(), - clScope, - fixKwd(paramPrefix + param->name()), - param->getMetadata(), - typeCtx); + string s = typeToString(param->type(), param->optional(), clScope, param->getMetadata(), typeCtx); + out << nl << s << ' ' << paramPrefix << param->mappedName() << ';'; } if (op && op->returnType()) { - writeParamAllocateCode( - out, - op->returnType(), - op->returnIsOptional(), - clScope, - "ret", - op->getMetadata(), - typeCtx); + string s = typeToString(op->returnType(), op->returnIsOptional(), clScope, op->getMetadata(), typeCtx); + out << nl << s << " ret;"; } } @@ -883,9 +724,9 @@ Slice::writeMarshalUnmarshalAllInHolder( out << os.str(); } - for (const auto& q : dataMembers) + for (const auto& member : dataMembers) { - out << holder + fixKwd(q->name()); + out << holder + member->mappedName(); } out << epar << ";"; @@ -894,7 +735,7 @@ Slice::writeMarshalUnmarshalAllInHolder( void Slice::writeStreamReader(Output& out, const StructPtr& p, const DataMemberList& dataMembers) { - string fullName = fixKwd(p->scoped()); + string fullName = p->mappedScoped(); out << nl << "template<>"; out << nl << "struct StreamReader<" << fullName << ">"; @@ -957,7 +798,7 @@ Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembe { out << ", "; } - out << fixKwd((*pi)->name()); + out << (*pi)->mappedName(); } out << ");" << eb; } diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.h b/cpp/src/slice2cpp/CPlusPlusUtil.h index 80b57d2111f..a7543435a2c 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.h +++ b/cpp/src/slice2cpp/CPlusPlusUtil.h @@ -55,8 +55,6 @@ namespace Slice std::string operationModeToString(Operation::Mode); std::string opFormatTypeToString(const OperationPtr&); - std::string fixKwd(const std::string&); - void writeMarshalCode(::IceInternal::Output&, const ParameterList&, const OperationPtr&); void writeUnmarshalCode(::IceInternal::Output&, const ParameterList&, const OperationPtr&); void writeAllocateCode( diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index d2830c433d1..93de0cacf8b 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -101,7 +101,7 @@ namespace ConstPtr constant = dynamic_pointer_cast(valueType); if (constant) { - out << getUnqualified(fixKwd(constant->scoped()), scope); + out << getUnqualified(constant->mappedScoped(), scope); } else { @@ -140,7 +140,7 @@ namespace { EnumeratorPtr enumerator = dynamic_pointer_cast(valueType); assert(enumerator); - out << getUnqualified(fixKwd(enumerator->scoped()), scope); + out << getUnqualified(enumerator->mappedScoped(), scope); } else if (!ep) { @@ -222,7 +222,7 @@ namespace // Generate a catch block for each legal user exception. for (const auto& ex : throws) { - C << nl << "catch(const " << getUnqualified(fixKwd(ex->scoped()), scope) << "&)"; + C << nl << "catch(const " << getUnqualified(ex->mappedScoped(), scope) << "&)"; C << sb; C << nl << "throw;"; C << eb; @@ -242,33 +242,47 @@ namespace return stName; } + /// 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) + { + string s = p->mappedScoped(); + string::size_type pos = 0; + while ((pos = s.find("::", pos)) != string::npos) + { + s.replace(pos, 2, "_"); + } + return s; + } + string condMove(bool moveIt, const string& str) { return moveIt ? string("::std::move(") + str + ")" : str; } + /// Ensures that there is no collision between 'name' and any of the parameters in the provided 'params' list. + /// If a collision exists, we return 'name' with an underscore appended to it. Otherwise we return 'name' as-is. string escapeParam(const ParameterList& params, const string& name) { - string r = name; for (const auto& param : params) { - if (fixKwd(param->name()) == name) + if (param->mappedName() == name) { - r = name + "_"; - break; + return name + "_"; } } - return r; + return name; } /// Returns a doxygen formatted link to the provided Slice identifier. + /// TODO we need to add a way for the doc-comment generation to use 'cpp' identifier! string cppLinkFormatter(string identifier, string memberComponent) { string result = "{@link "; if (!identifier.empty()) { - result += fixKwd(identifier); + result += identifier; } if (!memberComponent.empty()) { - result += "#" + fixKwd(memberComponent); + result += "#" + memberComponent; } return result + "}"; } @@ -451,10 +465,12 @@ namespace map paramDoc = doc->parameters(); for (const auto& param : params) { + // We want to lookup the parameter by its slice identifier, ignoring any 'cpp:identifier' metadata. auto q = paramDoc.find(param->name()); if (q != paramDoc.end()) { - out << nl << "/// @param " << fixKwd(q->first) << " "; + // But when we emit the parameter's name, we want it to take 'cpp:identifier' metadata into account. + out << nl << "/// @param " << param->mappedName() << " "; writeDocLines(out, q->second, false); } } @@ -474,7 +490,7 @@ namespace ExceptionPtr ex = op->container()->lookupException(name, false); if (ex) { - scopedName = ex->scoped().substr(2); + scopedName = ex->mappedScoped().substr(2); } out << nl << "/// @throws " << scopedName << " "; writeDocLines(out, lines, false); @@ -896,6 +912,25 @@ Slice::Gen::validateMetadata(const UnitPtr& u) }; knownMetadata.emplace("cpp:ice_print", std::move(icePrintInfo)); + // "cpp: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("cpp:identifier", std::move(identifierInfo)); + // "cpp:include" MetadataInfo includeInfo = { .validOn = {typeid(Unit)}, @@ -1041,7 +1076,7 @@ bool Slice::Gen::ForwardDeclVisitor::visitModuleStart(const ModulePtr& p) { _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - H << sp << nl << "namespace " << fixKwd(p->name()) << nl << '{'; + H << sp << nl << "namespace " << p->mappedName() << nl << '{'; H.inc(); return true; } @@ -1057,30 +1092,29 @@ Slice::Gen::ForwardDeclVisitor::visitModuleEnd(const ModulePtr&) void Slice::Gen::ForwardDeclVisitor::visitClassDecl(const ClassDeclPtr& p) { - string name = fixKwd(p->name()); + const string name = p->mappedName(); H << nl << "class " << name << ';'; - H << nl << "using " << p->name() << "Ptr " << getDeprecatedAttribute(p) << "= ::std::shared_ptr<" << name << ">;" - << sp; + H << nl << "using " << name << "Ptr " << getDeprecatedAttribute(p) << "= ::std::shared_ptr<" << name << ">;" << sp; } bool Slice::Gen::ForwardDeclVisitor::visitStructStart(const StructPtr& p) { - H << nl << "struct " << getDeprecatedAttribute(p) << fixKwd(p->name()) << ';' << sp; + H << nl << "struct " << getDeprecatedAttribute(p) << p->mappedName() << ';' << sp; return false; } void Slice::Gen::ForwardDeclVisitor::visitInterfaceDecl(const InterfaceDeclPtr& p) { - H << nl << "class " << getDeprecatedAttribute(p) << p->name() << "Prx;" << sp; + H << nl << "class " << getDeprecatedAttribute(p) << p->mappedName() << "Prx;" << sp; } void Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p) { writeDocSummary(H, p); - H << nl << "enum class " << getDeprecatedAttribute(p) << fixKwd(p->name()); + H << nl << "enum class " << getDeprecatedAttribute(p) << p->mappedName(); H << " : ::std::" << (p->maxValue() <= numeric_limits::max() ? "uint8_t" : "int32_t"); if (p->maxValue() > numeric_limits::max() && p->maxValue() <= numeric_limits::max()) @@ -1095,7 +1129,7 @@ Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p) for (auto en = enumerators.begin(); en != enumerators.end();) { writeDocSummary(H, *en); - H << nl << fixKwd((*en)->name()); + H << nl << (*en)->mappedName(); string deprecatedAttribute = getDeprecatedAttribute(*en); if (!deprecatedAttribute.empty()) @@ -1123,11 +1157,11 @@ Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p) void Slice::Gen::ForwardDeclVisitor::visitSequence(const SequencePtr& p) { - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - TypePtr type = p->type(); - TypeContext typeCtx = _useWstring; - MetadataList metadata = p->getMetadata(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const TypePtr type = p->type(); + const TypeContext typeCtx = _useWstring; + const MetadataList metadata = p->getMetadata(); string seqType = findMetadata(metadata, _useWstring); writeDocSummary(H, p); @@ -1157,10 +1191,10 @@ Slice::Gen::ForwardDeclVisitor::visitSequence(const SequencePtr& p) void Slice::Gen::ForwardDeclVisitor::visitDictionary(const DictionaryPtr& p) { - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string dictType = findMetadata(p->getMetadata()); - TypeContext typeCtx = _useWstring; + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const string dictType = findMetadata(p->getMetadata()); + const TypeContext typeCtx = _useWstring; writeDocSummary(H, p); @@ -1187,10 +1221,11 @@ Slice::Gen::ForwardDeclVisitor::visitDictionary(const DictionaryPtr& p) void Slice::Gen::ForwardDeclVisitor::visitConst(const ConstPtr& p) { - const string scope = fixKwd(p->scope()); + const string name = p->mappedName(); + const string scope = p->mappedScope(); writeDocSummary(H, p); H << nl << (isConstexprType(p->type()) ? "constexpr " : "const ") - << typeToString(p->type(), false, scope, p->typeMetadata(), _useWstring) << " " << fixKwd(p->name()) << " " + << typeToString(p->type(), false, scope, p->typeMetadata(), _useWstring) << " " << name << " " << getDeprecatedAttribute(p) << "= "; writeConstantValue(H, p->type(), p->valueType(), p->value(), _useWstring, p->typeMetadata(), scope); H << ';'; @@ -1229,6 +1264,9 @@ Slice::Gen::DefaultFactoryVisitor::visitUnitEnd(const UnitPtr&) bool Slice::Gen::DefaultFactoryVisitor::visitClassDefStart(const ClassDefPtr& p) { + const string scopedName = p->mappedScoped(); + const string flatScopedName = flattenedScopedName(p); + if (!_factoryTableInitDone) { // Make sure the global factory table is initialized before we use it. @@ -1236,13 +1274,13 @@ Slice::Gen::DefaultFactoryVisitor::visitClassDefStart(const ClassDefPtr& p) _factoryTableInitDone = true; } - C << nl << "const ::IceInternal::DefaultValueFactoryInit<" << fixKwd(p->scoped()) << "> "; - C << "iceC" + p->flattenedScope() + p->name() + "_init" << "(\"" << p->scoped() << "\");"; + C << nl << "const ::IceInternal::DefaultValueFactoryInit<" << scopedName << "> "; + C << "iceC" + flatScopedName + "_init" << "(\"" << scopedName << "\");"; if (p->compactId() >= 0) { - string n = "iceC" + p->flattenedScope() + p->name() + "_compactIdInit "; - C << nl << "const ::IceInternal::CompactIdInit " << n << "(\"" << p->scoped() << "\", " << p->compactId() + string n = "iceC" + flatScopedName + "_compactIdInit "; + C << nl << "const ::IceInternal::CompactIdInit " << n << "(\"" << scopedName << "\", " << p->compactId() << ");"; } return false; @@ -1251,14 +1289,17 @@ Slice::Gen::DefaultFactoryVisitor::visitClassDefStart(const ClassDefPtr& p) bool Slice::Gen::DefaultFactoryVisitor::visitExceptionStart(const ExceptionPtr& p) { + const string scopedName = p->mappedScoped(); + const string flatScopedName = flattenedScopedName(p); + if (!_factoryTableInitDone) { // Make sure the global factory table is initialized before we use it. C << nl << "const ::IceInternal::FactoryTableInit iceC_factoryTableInit;"; _factoryTableInitDone = true; } - C << nl << "const ::IceInternal::DefaultUserExceptionFactoryInit<" << fixKwd(p->scoped()) << "> "; - C << "iceC" + p->flattenedScope() + p->name() + "_init" << "(\"" << p->scoped() << "\");"; + C << nl << "const ::IceInternal::DefaultUserExceptionFactoryInit<" << scopedName << "> "; + C << "iceC" + flatScopedName + "_init" << "(\"" << scopedName << "\");"; return false; } @@ -1280,7 +1321,7 @@ Slice::Gen::ProxyVisitor::visitModuleStart(const ModulePtr& p) _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - H << sp << nl << "namespace " << fixKwd(p->name()) << nl << '{'; + H << sp << nl << "namespace " << p->mappedName() << nl << '{'; return true; } @@ -1297,13 +1338,14 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - const string scope = fixKwd(p->scope()); - InterfaceList bases = p->bases(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const InterfaceList bases = p->bases(); H << sp; writeDocSummary(H, p); - H << nl << "class " << _dllExport << getDeprecatedAttribute(p) << p->name() << "Prx : public " - << getUnqualified("::Ice::Proxy", scope) << "<" << fixKwd(p->name() + "Prx") << ", "; + H << nl << "class " << _dllExport << getDeprecatedAttribute(p) << name << "Prx : public " + << getUnqualified("::Ice::Proxy", scope) << "<" << name + "Prx, "; if (bases.empty()) { H << getUnqualified("::Ice::ObjectPrx", scope); @@ -1313,7 +1355,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) auto q = bases.begin(); while (q != bases.end()) { - H << getUnqualified(fixKwd((*q)->scoped() + "Prx"), scope); + H << getUnqualified((*q)->mappedScoped() + "Prx", scope); if (++q != bases.end()) { H << ", "; @@ -1333,9 +1375,10 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) void Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) { - const string prx = fixKwd(p->name() + "Prx"); - const string scoped = fixKwd(p->scoped() + "Prx"); - InterfaceList bases = p->allBases(); + const string scopedName = p->mappedScoped(); + const string prx = p->mappedName() + "Prx"; + const string scopedPrx = scopedName + "Prx"; + const InterfaceList bases = p->allBases(); H << sp; H << nl << "/// Obtains the Slice type ID of this interface."; @@ -1414,9 +1457,9 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) H << eb << ';'; C << sp; - C << nl << "const char*" << nl << scoped.substr(2) << "::ice_staticId() noexcept"; + C << nl << "const char*" << nl << scopedPrx.substr(2) << "::ice_staticId() noexcept"; C << sb; - C << nl << "return \"" << p->scoped() << "\";"; + C << nl << "return \"" << scopedName << "\";"; C << eb; _useWstring = resetUseWstring(_useWstringHist); @@ -1425,15 +1468,20 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) void Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { - string name = p->name(); - InterfaceDefPtr interface = p->interface(); - string interfaceScope = fixKwd(interface->scope()); + const InterfaceDefPtr container = p->interface(); + const string opName = p->mappedName(); + const string interfaceScope = container->mappedScope(); + const string interfaceName = container->mappedName(); - TypePtr ret = p->returnType(); + const string scopedPrxPrefix = (interfaceScope + interfaceName + "Prx::").substr(2); + const string prxScopedOpName = scopedPrxPrefix + opName; + const string scopedPrxFutureImplPrefix = interfaceName + "Prx::_iceI_"; + const string prxFutureImplScopedOpName = scopedPrxFutureImplPrefix + opName; - bool retIsOpt = p->returnIsOptional(); - string retS = ret ? typeToString(ret, retIsOpt, interfaceScope, p->getMetadata(), _useWstring) : "void"; - string retSImpl = ret ? typeToString(ret, retIsOpt, "", p->getMetadata(), _useWstring) : "void"; + const TypePtr ret = p->returnType(); + const bool retIsOpt = p->returnIsOptional(); + const string retS = ret ? typeToString(ret, retIsOpt, interfaceScope, p->getMetadata(), _useWstring) : "void"; + const string retSImpl = ret ? typeToString(ret, retIsOpt, "", p->getMetadata(), _useWstring) : "void"; // All parameters vector paramsDecl; @@ -1457,8 +1505,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) for (const auto& q : paramList) { - string paramName = fixKwd(q->name()); - MetadataList metadata = q->getMetadata(); + const string paramName = q->mappedName(); + const string prefixedParamName = paramPrefix + paramName; + const MetadataList metadata = q->getMetadata(); if (q->isOutParam()) { @@ -1466,23 +1515,21 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) outputTypeToString(q->type(), q->optional(), interfaceScope, metadata, _useWstring); paramsDecl.push_back(outputTypeString + ' ' + paramName); - paramsImplDecl.push_back(outputTypeString + ' ' + paramPrefix + q->name()); + paramsImplDecl.push_back(outputTypeString + ' ' + prefixedParamName); } else { string typeString = inputTypeToString(q->type(), q->optional(), interfaceScope, metadata, _useWstring); paramsDecl.push_back(typeString + ' ' + paramName); - paramsImplDecl.push_back(typeString + ' ' + paramPrefix + q->name()); + paramsImplDecl.push_back(typeString + ' ' + prefixedParamName); inParamsDecl.push_back(typeString + ' ' + paramName); - inParamsImplDecl.push_back(typeString + ' ' + paramPrefix + q->name()); - inParamsImpl.push_back(paramPrefix + q->name()); + inParamsImplDecl.push_back(typeString + ' ' + prefixedParamName); + inParamsImpl.push_back(prefixedParamName); } } - string scoped = fixKwd(interface->scope() + interface->name() + "Prx" + "::").substr(2); - const string contextParam = escapeParam(paramList, "context"); const string contextDef = "const " + getUnqualified("::Ice::Context&", interfaceScope) + " " + contextParam; const string contextDecl = contextDef + " = " + getUnqualified("::Ice::noExplicitContext", interfaceScope); @@ -1516,8 +1563,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) postParams, comment->returns()); } - H << nl << deprecatedAttribute << retS << ' ' << fixKwd(name) << spar << paramsDecl << contextDecl << epar - << " const;"; + H << nl << deprecatedAttribute << retS << ' ' << opName << spar << paramsDecl << contextDecl << epar << " const;"; // We don't want to add [[nodiscard]] to proxy member functions. if (ret && p->outParameters().empty()) @@ -1526,8 +1572,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) } C << sp; - C << nl << retSImpl << nl << scoped << fixKwd(name) << spar << paramsImplDecl << "const ::Ice::Context& context" - << epar << " const"; + C << nl << retSImpl << nl << prxScopedOpName << spar << paramsImplDecl << "const ::Ice::Context& context" << epar + << " const"; C << sb; C << nl; if (futureOutParams.size() == 1) @@ -1538,7 +1584,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) } else { - C << paramPrefix << (*outParams.begin())->name() << " = "; + C << paramPrefix << (*outParams.begin())->mappedName() << " = "; } } else if (futureOutParams.size() > 1) @@ -1549,8 +1595,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) // We call makePromiseOutgoing with the "sync" parameter set to true; the Promise/future implementation later on // calls makePromiseOutgoing with this parameter set to false. This parameter is useful for collocated calls. C << "::IceInternal::makePromiseOutgoing<" << futureT << ">"; - C << spar << "true, this" - << "&" + interface->name() + "Prx::_iceI_" + name; + C << spar << "true, this" << "&" + prxFutureImplScopedOpName; C << inParamsImpl; C << "context" << epar << ".get();"; if (futureOutParams.size() > 1) @@ -1558,7 +1603,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) int index = ret ? 1 : 0; for (const auto& q : outParams) { - C << nl << paramPrefix << q->name() << " = "; + C << nl << paramPrefix << q->mappedName() << " = "; C << condMove(isMovable(q->type()), "::std::get<" + std::to_string(index++) + ">(result)") << ";"; } if (ret) @@ -1589,17 +1634,17 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) returns); } - H << nl << deprecatedAttribute << "[[nodiscard]] ::std::future<" << futureT << "> " << name << "Async" << spar + H << nl << deprecatedAttribute << "[[nodiscard]] ::std::future<" << futureT << "> " << opName << "Async" << spar << inParamsDecl << contextDecl << epar << " const;"; C << sp; C << nl << "::std::future<" << futureTAbsolute << ">"; C << nl; - C << scoped << name << "Async" << spar << inParamsImplDecl << "const ::Ice::Context& context" << epar << " const"; + C << prxScopedOpName << "Async" << spar << inParamsImplDecl << "const ::Ice::Context& context" << epar << " const"; C << sb; C << nl << "return ::IceInternal::makePromiseOutgoing<" << futureT << ">" << spar; - C << "false, this" << string("&" + interface->name() + "Prx::_iceI_" + name); + C << "false, this" << string("&" + prxFutureImplScopedOpName); C << inParamsImpl; C << "context" << epar << ";"; C << eb; @@ -1638,7 +1683,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) H << "::std::function // NOLINT(modernize-use-nodiscard)"; // TODO: need "nl" version of spar/epar - H << nl << name << "Async" << spar; + H << nl << opName << "Async" << spar; H.useCurrentPosAsIndent(); H << inParamsDecl; @@ -1650,7 +1695,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << sp; C << nl << "::std::function"; - C << nl << scoped << name << "Async" << spar; + C << nl << prxScopedOpName << "Async" << spar; C.useCurrentPosAsIndent(); C << inParamsImplDecl; C << lambdaResponse + " response"; @@ -1673,7 +1718,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << "::std::move(" + (lambdaOutParams.size() > 1 ? string("responseCb") : "response") + ")" << "::std::move(ex)" << "::std::move(sent)" << "this"; - C << string("&" + getUnqualified(scoped, interfaceScope.substr(2)) + lambdaImplPrefix + name); + C << string("&" + getUnqualified(scopedPrxPrefix, interfaceScope.substr(2)) + lambdaImplPrefix + opName); C << inParamsImpl; C << "context" << epar << ";"; C << eb; @@ -1694,15 +1739,13 @@ Slice::Gen::ProxyVisitor::emitOperationImpl( const string& prefix, const std::vector& outgoingAsyncParams) { - string name = p->name(); - InterfaceDefPtr interface = p->interface(); - string interfaceScope = fixKwd(interface->scope()); - - TypePtr ret = p->returnType(); + const InterfaceDefPtr container = p->interface(); + const string opName = p->mappedName(); + const string opImplName = prefix + opName; + const string interfaceScope = container->mappedScope(); + const string scopedPrxPrefix = (container->mappedScoped() + "Prx" + "::").substr(2); - bool retIsOpt = p->returnIsOptional(); - string retS = ret ? typeToString(ret, retIsOpt, interfaceScope, p->getMetadata(), _useWstring) : "void"; - string retSImpl = ret ? typeToString(ret, retIsOpt, "", p->getMetadata(), _useWstring) : "void"; + const TypePtr ret = p->returnType(); vector inParamsS; vector inParamsImplDecl; @@ -1725,18 +1768,14 @@ Slice::Gen::ProxyVisitor::emitOperationImpl( string typeString = inputTypeToString(q->type(), q->optional(), interfaceScope, q->getMetadata(), _useWstring); inParamsS.push_back(typeString); - inParamsImplDecl.push_back(typeString + ' ' + paramPrefix + q->name()); + inParamsImplDecl.push_back(typeString + ' ' + paramPrefix + q->mappedName()); } - string scoped = fixKwd(interface->scope() + interface->name() + "Prx" + "::").substr(2); - string returnT = createOutgoingAsyncTypeParam(outgoingAsyncParams); - string implName = prefix + name; - H << sp; H << nl << "/// \\cond INTERNAL"; - H << nl << "void " << implName << spar; + H << nl << "void " << opImplName << spar; H << "const ::std::shared_ptr<::IceInternal::OutgoingAsyncT<" + returnT + ">>&"; H << inParamsS; H << ("const " + getUnqualified("::Ice::Context&", interfaceScope)); @@ -1744,12 +1783,12 @@ Slice::Gen::ProxyVisitor::emitOperationImpl( H << nl << "/// \\endcond"; C << sp; - C << nl << "void" << nl << scoped << implName << spar; + C << nl << "void" << nl << scopedPrxPrefix << opImplName << spar; C << "const ::std::shared_ptr<::IceInternal::OutgoingAsyncT<" + returnT + ">>& outAsync"; C << inParamsImplDecl << ("const " + getUnqualified("::Ice::Context&", interfaceScope) + " context"); C << epar << " const"; C << sb; - C << nl << "static constexpr ::std::string_view operationName = \"" << name << "\";"; + C << nl << "static constexpr ::std::string_view operationName = \"" << p->name() << "\";"; C << sp; if (p->returnsData()) { @@ -1805,7 +1844,7 @@ Slice::Gen::ProxyVisitor::emitOperationImpl( } else { - C << nl << "return " << fixKwd(paramPrefix + outParams.front()->name()) << ";"; + C << nl << "return " << paramPrefix + outParams.front()->mappedName() << ";"; } C << eb; } @@ -1833,7 +1872,7 @@ Slice::Gen::DataDefVisitor::visitModuleStart(const ModulePtr& p) } _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - H << sp << nl << "namespace " << fixKwd(p->name()) << nl << '{'; + H << sp << nl << "namespace " << p->mappedName() << nl << '{'; return true; } @@ -1863,7 +1902,7 @@ Slice::Gen::DataDefVisitor::visitStructStart(const StructPtr& p) H << sp; writeDocSummary(H, p); - H << nl << "struct " << getDeprecatedAttribute(p) << fixKwd(p->name()); + H << nl << "struct " << getDeprecatedAttribute(p) << p->mappedName(); H << sb; return true; @@ -1896,28 +1935,22 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) { _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string scoped = fixKwd(p->scoped()); - ExceptionPtr base = p->base(); - DataMemberList dataMembers = p->dataMembers(); - DataMemberList allDataMembers = p->allDataMembers(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const string scoped = p->mappedScoped(); + const ExceptionPtr base = p->base(); + const DataMemberList dataMembers = p->dataMembers(); + const DataMemberList allDataMembers = p->allDataMembers(); DataMemberList baseDataMembers; - vector params; vector allParameters; map allDocComments; - for (const auto& dataMember : dataMembers) - { - params.push_back(fixKwd(dataMember->name())); - } - for (const auto& dataMember : allDataMembers) { string typeName = typeToString(dataMember->type(), dataMember->optional(), scope, dataMember->getMetadata(), _useWstring); - allParameters.push_back(typeName + " " + fixKwd(dataMember->name())); + allParameters.push_back(typeName + " " + dataMember->mappedName()); if (DocCommentPtr comment = dataMember->parseDocComment(cppLinkFormatter)) { @@ -1930,9 +1963,9 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) baseDataMembers = base->allDataMembers(); } - string baseClass = - base ? getUnqualified(fixKwd(base->scoped()), scope) : getUnqualified("::Ice::UserException", scope); - string baseName = base ? fixKwd(base->name()) : "UserException"; + const string baseClass = + base ? getUnqualified(base->mappedScoped(), scope) : getUnqualified("::Ice::UserException", scope); + const string baseName = base ? base->mappedName() : "UserException"; H << sp; writeDocSummary(H, p); @@ -1962,7 +1995,8 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) auto r = allDocComments.find(dataMember->name()); if (r != allDocComments.end()) { - H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second->overview()); + H << nl << "/// @param " << dataMember->mappedName() << " " + << getDocSentence(r->second->overview()); } } H << nl << name << "("; @@ -1987,7 +2021,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) { H << ", "; } - string memberName = fixKwd((*q)->name()); + string memberName = (*q)->mappedName(); TypePtr memberType = (*q)->type(); H << condMove(isMovable(memberType), memberName); } @@ -2001,7 +2035,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) for (auto q = dataMembers.begin(); q != dataMembers.end(); ++q) { - string memberName = fixKwd((*q)->name()); + string memberName = (*q)->mappedName(); TypePtr memberType = (*q)->type(); if (q != dataMembers.begin()) @@ -2088,14 +2122,13 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) void Slice::Gen::DataDefVisitor::visitExceptionEnd(const ExceptionPtr& p) { - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string scoped = fixKwd(p->scoped()); - DataMemberList dataMembers = p->dataMembers(); + const string scope = p->mappedScope(); + const string scoped = p->mappedScoped(); + const DataMemberList dataMembers = p->dataMembers(); - ExceptionPtr base = p->base(); - string baseClass = - base ? getUnqualified(fixKwd(base->scoped()), scope) : getUnqualified("::Ice::UserException", scope); + const ExceptionPtr base = p->base(); + const string baseClass = + base ? getUnqualified(base->mappedScoped(), scope) : getUnqualified("::Ice::UserException", scope); H.dec(); H << sp << nl << "protected:"; @@ -2142,12 +2175,12 @@ Slice::Gen::DataDefVisitor::visitClassDefStart(const ClassDefPtr& p) { _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string scoped = fixKwd(p->scoped()); - ClassDefPtr base = p->base(); - DataMemberList dataMembers = p->dataMembers(); - DataMemberList allDataMembers = p->allDataMembers(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const string scoped = p->mappedScoped(); + const ClassDefPtr base = p->base(); + const DataMemberList dataMembers = p->dataMembers(); + const DataMemberList allDataMembers = p->allDataMembers(); H << sp; writeDocSummary(H, p); @@ -2159,23 +2192,16 @@ Slice::Gen::DataDefVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - H << getUnqualified(fixKwd(base->scoped()), scope); + H << getUnqualified(base->mappedScoped(), scope); } H << sb; H.dec(); H << nl << "public:"; H.inc(); - vector params; - - for (const auto& dataMember : dataMembers) - { - params.push_back(fixKwd(dataMember->name())); - } - if (base && dataMembers.empty()) { - H << "using " << getUnqualified(fixKwd(base->scoped()), scope) << "::" << fixKwd(base->name()) << ";"; + H << "using " << getUnqualified(base->mappedScoped(), scope) << "::" << base->mappedName() << ";"; } else { @@ -2216,7 +2242,7 @@ Slice::Gen::DataDefVisitor::visitClassDefStart(const ClassDefPtr& p) H << sp; H << nl << "/// Creates a shallow polymorphic copy of this instance."; H << nl << "/// @return The cloned value."; - H << nl << "[[nodiscard]] " << p->name() << "Ptr ice_clone() const { return ::std::static_pointer_cast<" << name + H << nl << "[[nodiscard]] " << name << "Ptr ice_clone() const { return ::std::static_pointer_cast<" << name << ">(_iceCloneImpl()); }"; return true; @@ -2225,15 +2251,15 @@ Slice::Gen::DataDefVisitor::visitClassDefStart(const ClassDefPtr& p) void Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) { - string name = fixKwd(p->name()); - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - ClassDefPtr base = p->base(); + const string name = p->mappedName(); + const string scoped = p->mappedScoped(); + const string scope = p->mappedScope(); + const ClassDefPtr base = p->base(); // Emit data members. Access visibility may be specified by metadata. + const DataMemberList dataMembers = p->dataMembers(); + const bool prot = p->hasMetadata("protected"); bool inProtected = false; - DataMemberList dataMembers = p->dataMembers(); - bool prot = p->hasMetadata("protected"); bool needSp = true; for (const auto& dataMember : dataMembers) @@ -2290,7 +2316,7 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "return CloneEnabler<" << name << ">::clone(*this);"; C << eb; - string baseClass = base ? getUnqualified(fixKwd(base->scoped()), scope) : getUnqualified("::Ice::Value", scope); + const string baseClass = base ? getUnqualified(base->mappedScoped(), scope) : getUnqualified("::Ice::Value", scope); H << nl << _dllMemberExport << "void _iceWriteImpl(::Ice::OutputStream*) const override;"; C << sp << nl << "void" << nl << scoped.substr(2) << "::_iceWriteImpl(::Ice::OutputStream* ostr) const"; @@ -2343,12 +2369,10 @@ Slice::Gen::DataDefVisitor::emitBaseInitializers(const ClassDefPtr& p) return false; } - const string scope = fixKwd(p->scope()); - string upcall = "("; for (auto q = allBaseDataMembers.begin(); q != allBaseDataMembers.end(); ++q) { - string memberName = fixKwd((*q)->name()); + string memberName = (*q)->mappedName(); TypePtr memberType = (*q)->type(); if (q != allBaseDataMembers.begin()) { @@ -2358,7 +2382,7 @@ Slice::Gen::DataDefVisitor::emitBaseInitializers(const ClassDefPtr& p) } upcall += ")"; - H << nl << getUnqualified(fixKwd(base->scoped()), scope) << upcall; + H << nl << getUnqualified(base->mappedScoped(), p->mappedScope()) << upcall; return true; } @@ -2379,7 +2403,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) { string typeName = typeToString(dataMember->type(), dataMember->optional(), scope, dataMember->getMetadata(), _useWstring); - allParameters.push_back(typeName + " " + fixKwd(dataMember->name())); + allParameters.push_back(typeName + " " + dataMember->mappedName()); if (DocCommentPtr comment = dataMember->parseDocComment(cppLinkFormatter)) { allDocComments[dataMember->name()] = comment; @@ -2393,7 +2417,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) auto r = allDocComments.find(dataMember->name()); if (r != allDocComments.end()) { - H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second->overview()); + H << nl << "/// @param " << dataMember->mappedName() << " " << getDocSentence(r->second->overview()); } } H << nl; @@ -2401,7 +2425,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) { H << "explicit "; } - H << fixKwd(p->name()) << spar << allParameters << epar << " noexcept :"; + H << p->mappedName() << spar << allParameters << epar << " noexcept :"; H.inc(); if (emitBaseInitializers(p)) @@ -2423,7 +2447,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) { H << ',' << nl; } - string memberName = fixKwd((*q)->name()); + string memberName = (*q)->mappedName(); TypePtr memberType = (*q)->type(); H << memberName << "(" << condMove(isMovable(memberType), memberName) << ')'; } @@ -2437,9 +2461,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) void Slice::Gen::DataDefVisitor::emitDataMember(const DataMemberPtr& p) { - string name = fixKwd(p->name()); - ContainerPtr container = p->container(); - ClassDefPtr cl = dynamic_pointer_cast(container); + const string name = p->mappedName(); // Use empty scope to get full qualified names in types used with future declarations. string scope = ""; @@ -2485,8 +2507,7 @@ Slice::Gen::InterfaceVisitor::visitModuleStart(const ModulePtr& p) } _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - string name = fixKwd(p->name()); - H << sp << nl << "namespace " << name << nl << '{'; + H << sp << nl << "namespace " << p->mappedName() << nl << '{'; return true; } @@ -2503,10 +2524,10 @@ bool Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string scoped = fixKwd(p->scope() + p->name()); - InterfaceList bases = p->bases(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const string scoped = p->mappedScoped(); + const InterfaceList bases = p->bases(); H << sp; writeDocSummary(H, p, GenerateDeprecated::No); @@ -2521,9 +2542,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) auto q = bases.begin(); while (q != bases.end()) { - string baseScoped = fixKwd((*q)->scope() + (*q)->name()); - - H << "public virtual " << getUnqualified(baseScoped, scope); + H << "public virtual " << getUnqualified((*q)->mappedScoped(), scope); if (++q != bases.end()) { H << ',' << nl; @@ -2540,7 +2559,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // In C++, a nested type cannot have the same name as the enclosing type if (name != "ProxyType") { - H << nl << "using ProxyType = " << p->name() << "Prx;"; + H << nl << "using ProxyType = " << p->mappedName() << "Prx;"; } StringList ids = p->ids(); @@ -2598,11 +2617,8 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) void Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) { - string scoped = fixKwd(p->scope() + p->name()); - - string scope = fixKwd(p->scope()); - string name = fixKwd(p->name()); - InterfaceList bases = p->bases(); + const string scoped = p->mappedScoped(); + const string name = p->mappedName(); OperationList allOps = p->allOperations(); if (!allOps.empty()) @@ -2682,7 +2698,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) H << eb << ';'; - H << sp << nl << "using " << p->name() << "Ptr = ::std::shared_ptr<" << name << ">;"; + H << sp << nl << "using " << name << "Ptr = ::std::shared_ptr<" << name << ">;"; _useWstring = resetUseWstring(_useWstringHist); } @@ -2690,7 +2706,10 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) void Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) { - string name = p->name(); + const string name = p->mappedName(); + const string scope = p->mappedScope(); + const InterfaceDefPtr container = p->interface(); + const string interfaceScope = container->mappedScope(); TypePtr ret = p->returnType(); @@ -2701,16 +2720,12 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) vector responseParamsDecl; vector responseParamsImplDecl; - InterfaceDefPtr interface = p->interface(); - string interfaceScope = fixKwd(interface->scope()); + const ParameterList inParams = p->inParameters(); + const ParameterList outParams = p->outParameters(); + const ParameterList paramList = p->parameters(); - string scope = fixKwd(interface->scope() + interface->name() + "::"); - - ParameterList inParams = p->inParameters(); - ParameterList outParams = p->outParameters(); - ParameterList paramList = p->parameters(); - - const bool amd = (interface->hasMetadata("amd") || p->hasMetadata("amd")); + const bool amd = (container->hasMetadata("amd") || p->hasMetadata("amd")); + const string opName = amd ? (name + "Async") : name; const string returnValueParam = escapeParam(outParams, "returnValue"); const string responsecbParam = escapeParam(inParams, "response"); @@ -2757,7 +2772,8 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) for (const auto& param : paramList) { TypePtr type = param->type(); - string paramName = fixKwd(param->name()); + string paramName = param->mappedName(); + string prefixedParamName = paramPrefix + paramName; bool isOutParam = param->isOutParam(); if (!isOutParam) @@ -2770,7 +2786,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) param->getMetadata(), _useWstring | TypeContext::UnmarshalParamZeroCopy) + " " + paramName); - args.push_back(condMove(isMovable(type), paramPrefix + param->name())); + args.push_back(condMove(isMovable(type), prefixedParamName)); } else { @@ -2779,14 +2795,14 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) params.push_back( outputTypeToString(type, param->optional(), interfaceScope, param->getMetadata(), _useWstring) + " " + paramName); - args.push_back(condMove(isMovable(type) && !isOutParam, paramPrefix + param->name())); + args.push_back(condMove(isMovable(type) && !isOutParam, prefixedParamName)); } string responseTypeS = inputTypeToString(param->type(), param->optional(), interfaceScope, param->getMetadata(), _useWstring); responseParams.push_back(responseTypeS + " " + paramName); - responseParamsDecl.push_back(responseTypeS + " " + paramPrefix + param->name()); - responseParamsImplDecl.push_back(responseTypeS + " " + paramPrefix + param->name()); + responseParamsDecl.push_back(responseTypeS + " " + prefixedParamName); + responseParamsImplDecl.push_back(responseTypeS + " " + prefixedParamName); } } if (amd) @@ -2822,7 +2838,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) { string resultName = marshaledResultStructName(name); H << sp; - H << nl << "/// Marshaled result structure for operation " << (amd ? name + "Async" : fixKwd(name)) << "."; + H << nl << "/// Marshaled result structure for operation " << opName << "."; H << nl << "class " << resultName << " : public " << getUnqualified("::Ice::MarshaledResult", interfaceScope); H << sb; H.dec(); @@ -2844,7 +2860,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) auto r = paramComments.find(param->name()); if (r != paramComments.end()) { - H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second); + H << nl << "/// @param " << param->mappedName() << " " << getDocSentence(r->second); } } H << nl << "/// @param " << mrcurrent << " The Current object for the invocation."; @@ -2869,8 +2885,6 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) C << eb; } - string opName = amd ? (name + "Async") : fixKwd(name); - H << sp; if (comment) { @@ -2894,15 +2908,14 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) } H << nl << noDiscard << "virtual " << retS << ' ' << opName << spar << params << epar << isConst << " = 0;"; H << nl << "/// \\cond INTERNAL"; - H << nl << "void _iceD_" << name << "(::Ice::IncomingRequest&, ::std::function)" + H << nl << "void _iceD_" << p->name() << "(::Ice::IncomingRequest&, ::std::function)" << isConst << ';'; H << nl << "/// \\endcond"; C << sp; C << nl << "/// \\cond INTERNAL"; C << nl << "void"; - C << nl << scope.substr(2); - C << "_iceD_" << name << "("; + C << nl << scope.substr(2) << "_iceD_" << p->name() << "("; C.inc(); C << nl << "::Ice::IncomingRequest& request," << nl << "::std::function sendResponse)" << isConst; @@ -3067,10 +3080,8 @@ Slice::Gen::StreamVisitor::visitModuleEnd(const ModulePtr& m) bool Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) { - string scoped = fixKwd(p->scoped()); - H << nl << "template<>"; - H << nl << "struct StreamableTraits<" << scoped << ">"; + H << nl << "struct StreamableTraits<" << p->mappedScoped() << ">"; H << sb; H << nl << "static const StreamHelperCategory helper = StreamHelperCategoryStruct;"; H << nl << "static const int minWireSize = " << p->minWireSize() << ";"; @@ -3084,9 +3095,8 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) void Slice::Gen::StreamVisitor::visitEnum(const EnumPtr& p) { - string scoped = fixKwd(p->scoped()); H << nl << "template<>"; - H << nl << "struct StreamableTraits< " << scoped << ">"; + H << nl << "struct StreamableTraits< " << p->mappedScoped() << ">"; H << sb; H << nl << "static const StreamHelperCategory helper = StreamHelperCategoryEnum;"; H << nl << "static const int minValue = " << p->minValue() << ";"; diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 8788d175d2b..30c8cdab2d3 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -205,7 +205,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("cpp", false); int parseStatus = u->parse(*i, cppHandle, debug); DefinitionContextPtr dc = u->findDefinitionContext(u->topLevelFile()); @@ -261,7 +261,7 @@ compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("cpp", false); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 167878a257b..96237460b06 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -183,7 +183,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("cs", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -232,7 +232,7 @@ compile(const vector& argv) } else { - UnitPtr p = Unit::createUnit(false); + UnitPtr p = Unit::createUnit("cs", false); int parseStatus = p->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index c982ba2c271..b124561985c 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -192,7 +192,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("java", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -246,7 +246,7 @@ compile(const vector& argv) } else { - UnitPtr p = Unit::createUnit(false, fileMetadata); + UnitPtr p = Unit::createUnit("java", false, fileMetadata); int parseStatus = p->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index 509bc3ac93f..1114884970f 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -216,7 +216,7 @@ compile(const vector& argv) if (depend || dependJSON || dependXml) { - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("js", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -270,7 +270,7 @@ compile(const vector& argv) } else { - UnitPtr p = Unit::createUnit(false); + UnitPtr p = Unit::createUnit("js", false); int parseStatus = p->parse(*i, cppHandle, debug); if (!preprocessor->close()) diff --git a/cpp/src/slice2matlab/Main.cpp b/cpp/src/slice2matlab/Main.cpp index 431d0a30b4d..a59920e6a5d 100644 --- a/cpp/src/slice2matlab/Main.cpp +++ b/cpp/src/slice2matlab/Main.cpp @@ -4205,7 +4205,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("matlab", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -4257,7 +4257,7 @@ compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(all); + UnitPtr u = Unit::createUnit("matlab", all); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index ffc4baf15d6..13a9047018c 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1442,7 +1442,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("php", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -1492,7 +1492,7 @@ compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(all); + UnitPtr u = Unit::createUnit("php", all); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2py/Python.cpp b/cpp/src/slice2py/Python.cpp index 545884fd2f8..99a24bf746a 100644 --- a/cpp/src/slice2py/Python.cpp +++ b/cpp/src/slice2py/Python.cpp @@ -563,7 +563,7 @@ Slice::Python::compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("python", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -614,7 +614,7 @@ Slice::Python::compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(all); + UnitPtr u = Unit::createUnit("python", all); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2rb/Ruby.cpp b/cpp/src/slice2rb/Ruby.cpp index bbee2a7a459..740d2d0b78d 100644 --- a/cpp/src/slice2rb/Ruby.cpp +++ b/cpp/src/slice2rb/Ruby.cpp @@ -172,7 +172,7 @@ Slice::Ruby::compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("ruby", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -222,7 +222,7 @@ Slice::Ruby::compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(all); + UnitPtr u = Unit::createUnit("ruby", all); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/src/slice2rb/RubyUtil.cpp b/cpp/src/slice2rb/RubyUtil.cpp index 9be419e8b26..4707a576b9f 100644 --- a/cpp/src/slice2rb/RubyUtil.cpp +++ b/cpp/src/slice2rb/RubyUtil.cpp @@ -1313,7 +1313,7 @@ Slice::Ruby::generate(const UnitPtr& un, bool all, const vector& include // 'slice2rb' doesn't have any language-specific metadata, so we call `validateMetadata` with an empty list. // This ensures that the validation still runs, and will reject any 'rb' metadata the user might think exists. - Slice::validateMetadata(un, "rb", {}); + Slice::validateMetadata(un, "ruby", {}); if (!all) { diff --git a/cpp/src/slice2swift/Main.cpp b/cpp/src/slice2swift/Main.cpp index f7431c75e00..42712493384 100644 --- a/cpp/src/slice2swift/Main.cpp +++ b/cpp/src/slice2swift/Main.cpp @@ -186,7 +186,7 @@ compile(const vector& argv) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("swift", false); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -236,7 +236,7 @@ compile(const vector& argv) } else { - UnitPtr u = Unit::createUnit(false); + UnitPtr u = Unit::createUnit("swift", false); int parseStatus = u->parse(*i, cppHandle, debug); if (!icecpp->close()) diff --git a/cpp/test/Ice/servantLocator/Test.ice b/cpp/test/Ice/servantLocator/Test.ice index 06e8847084c..73a08353aac 100644 --- a/cpp/test/Ice/servantLocator/Test.ice +++ b/cpp/test/Ice/servantLocator/Test.ice @@ -28,8 +28,9 @@ interface TestIntf void unknownExceptionWithServantException(); - string impossibleException(bool throw) throws TestImpossibleException; - string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + // TODO rename the throw variable in all language mappings before adding more 'xxx:identifier'. + string impossibleException(["cpp:identifier:shouldThrow"] bool throw) throws TestImpossibleException; + string intfUserException(["cpp:identifier:shouldThrow"] bool throw) throws TestIntfUserException, TestImpossibleException; void asyncResponse() throws TestIntfUserException, TestImpossibleException; void asyncException() throws TestIntfUserException, TestImpossibleException; diff --git a/cpp/test/Ice/servantLocator/TestAMD.ice b/cpp/test/Ice/servantLocator/TestAMD.ice index 8edd53636a3..5889a636c26 100644 --- a/cpp/test/Ice/servantLocator/TestAMD.ice +++ b/cpp/test/Ice/servantLocator/TestAMD.ice @@ -28,8 +28,9 @@ exception TestImpossibleException void unknownExceptionWithServantException(); - string impossibleException(bool throw) throws TestImpossibleException; - string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + // TODO rename the throw variable in all language mappings before adding more 'xxx:identifier'. + string impossibleException(["cpp:identifier:shouldThrow"] bool throw) throws TestImpossibleException; + string intfUserException(["cpp:identifier:shouldThrow"] bool throw) throws TestIntfUserException, TestImpossibleException; void asyncResponse() throws TestIntfUserException, TestImpossibleException; void asyncException() throws TestIntfUserException, TestImpossibleException; diff --git a/cpp/test/Ice/servantLocator/TestAMDI.cpp b/cpp/test/Ice/servantLocator/TestAMDI.cpp index e95b65c137d..444035f9ce8 100644 --- a/cpp/test/Ice/servantLocator/TestAMDI.cpp +++ b/cpp/test/Ice/servantLocator/TestAMDI.cpp @@ -74,12 +74,12 @@ TestAMDI::unknownExceptionWithServantExceptionAsync( void TestAMDI::impossibleExceptionAsync( - bool _cpp_throw, + bool shouldThrow, function response, function error, const Current&) { - if (_cpp_throw) + if (shouldThrow) { try { @@ -102,12 +102,12 @@ TestAMDI::impossibleExceptionAsync( void TestAMDI::intfUserExceptionAsync( - bool _cpp_throw, + bool shouldThrow, function response, function error, const Current&) { - if (_cpp_throw) + if (shouldThrow) { try { diff --git a/cpp/test/Ice/servantLocator/TestI.cpp b/cpp/test/Ice/servantLocator/TestI.cpp index 6223e186a8b..79ee1d4fa6d 100644 --- a/cpp/test/Ice/servantLocator/TestI.cpp +++ b/cpp/test/Ice/servantLocator/TestI.cpp @@ -55,9 +55,9 @@ TestI::unknownExceptionWithServantException(const Current&) } string -TestI::impossibleException(bool _cpp_throw, const Current&) +TestI::impossibleException(bool shouldThrow, const Current&) { - if (_cpp_throw) + if (shouldThrow) { throw Test::TestImpossibleException(); } @@ -69,9 +69,9 @@ TestI::impossibleException(bool _cpp_throw, const Current&) } string -TestI::intfUserException(bool _cpp_throw, const Current&) +TestI::intfUserException(bool shouldThrow, const Current&) { - if (_cpp_throw) + if (shouldThrow) { throw Test::TestIntfUserException(); } diff --git a/cpp/test/IceGrid/activation/AllTests.cpp b/cpp/test/IceGrid/activation/AllTests.cpp index 009396b0281..50f2444b909 100644 --- a/cpp/test/IceGrid/activation/AllTests.cpp +++ b/cpp/test/IceGrid/activation/AllTests.cpp @@ -744,7 +744,7 @@ allTests(Test::TestHelper* helper) ostringstream id; id << "server-" << i; IceGrid::ServerInstanceDescriptor server; - server._cpp_template = "Server"; + server.templateName = "Server"; server.parameterValues["id"] = id.str(); testApp.nodes["localnode"].serverInstances.push_back(server); } diff --git a/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp b/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp index e4fe820000b..f8df6d10927 100644 --- a/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp +++ b/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp @@ -250,7 +250,7 @@ allTests(Test::TestHelper* helper) update.variables["server.dir"] = properties->getProperty("ServerDir"); update.variables["variable"] = ""; instance = ServerInstanceDescriptor(); - instance._cpp_template = "ServerTemplate"; + instance.templateName = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try @@ -381,7 +381,7 @@ allTests(Test::TestHelper* helper) update = empty; update.serverTemplates["ServerTemplate"] = templ; instance = ServerInstanceDescriptor(); - instance._cpp_template = "ServerTemplate"; + instance.templateName = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); admin->updateApplicationWithoutRestart(update); diff --git a/cpp/test/IceGrid/replicaGroup/AllTests.cpp b/cpp/test/IceGrid/replicaGroup/AllTests.cpp index fe10a91e5d5..e6765ecef7a 100644 --- a/cpp/test/IceGrid/replicaGroup/AllTests.cpp +++ b/cpp/test/IceGrid/replicaGroup/AllTests.cpp @@ -26,7 +26,7 @@ instantiateServer( bool startServer = true) { ServerInstanceDescriptor desc; - desc._cpp_template = templ; + desc.templateName = templ; desc.parameterValues = params; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = node; diff --git a/cpp/test/IceGrid/replication/AllTests.cpp b/cpp/test/IceGrid/replication/AllTests.cpp index 046454a2008..62ff08205da 100644 --- a/cpp/test/IceGrid/replication/AllTests.cpp +++ b/cpp/test/IceGrid/replication/AllTests.cpp @@ -128,7 +128,7 @@ namespace void instantiateServer(const optional& admin, string templ, const map& params) { ServerInstanceDescriptor desc; - desc._cpp_template = std::move(templ); + desc.templateName = std::move(templ); desc.parameterValues = params; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "localnode"; diff --git a/cpp/test/IceGrid/update/AllTests.cpp b/cpp/test/IceGrid/update/AllTests.cpp index 70e67284df9..5456d77a72d 100644 --- a/cpp/test/IceGrid/update/AllTests.cpp +++ b/cpp/test/IceGrid/update/AllTests.cpp @@ -186,7 +186,7 @@ allTests(Test::TestHelper* helper) update = empty; ServerInstanceDescriptor instance; - instance._cpp_template = "ServerTemplate"; + instance.templateName = "ServerTemplate"; update.nodes[0].serverInstances.push_back(instance); try { @@ -207,7 +207,7 @@ allTests(Test::TestHelper* helper) update.variables["test.dir"] = properties->getProperty("ServerDir"); update.variables["variable"] = ""; instance = ServerInstanceDescriptor(); - instance._cpp_template = "ServerTemplate"; + instance.templateName = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try @@ -333,7 +333,7 @@ allTests(Test::TestHelper* helper) update = empty; update.serverTemplates["ServerTemplate"] = templ; instance = ServerInstanceDescriptor(); - instance._cpp_template = "ServerTemplate"; + instance.templateName = "ServerTemplate"; instance.parameterValues["name"] = "Server1"; update.nodes[0].serverInstances.push_back(instance); try @@ -736,7 +736,7 @@ allTests(Test::TestHelper* helper) node.variables["nodevar"] = "NodeValue"; ServerInstanceDescriptor serverInstance; - serverInstance._cpp_template = "ServerTemplate"; + serverInstance.templateName = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; serverInstance.parameterValues["serverparamvar"] = "ServerParamValue"; node.serverInstances.push_back(serverInstance); @@ -801,7 +801,7 @@ allTests(Test::TestHelper* helper) update = empty; serverInstance = ServerInstanceDescriptor(); - serverInstance._cpp_template = "ServerTemplate"; + serverInstance.templateName = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node1"; @@ -882,7 +882,7 @@ allTests(Test::TestHelper* helper) svcTempl.descriptor = service; ServiceInstanceDescriptor serviceInstance; - serviceInstance._cpp_template = "ServiceTemplate"; + serviceInstance.templateName = "ServiceTemplate"; serviceInstance.parameterValues["name"] = "Service"; serviceInstance.propertySet.properties.push_back(createProperty("ServiceInstanceProp", "test")); @@ -915,7 +915,7 @@ allTests(Test::TestHelper* helper) node.propertySets["NodePropertySet1"].properties.push_back(createProperty("NodeProp", "test")); ServerInstanceDescriptor serverInstance; - serverInstance._cpp_template = "ServerTemplate"; + serverInstance.templateName = "ServerTemplate"; serverInstance.parameterValues["name"] = "Server"; serverInstance.propertySet.properties.push_back(createProperty("ServerInstanceProp", "test")); node.serverInstances.push_back(serverInstance); @@ -1109,7 +1109,7 @@ allTests(Test::TestHelper* helper) nodeApp.serverTemplates["nodeTemplate"].parameters.emplace_back("index"); ServerInstanceDescriptor instance; - instance._cpp_template = "nodeTemplate"; + instance.templateName = "nodeTemplate"; instance.parameterValues["index"] = "1"; nodeApp.nodes["localnode"].serverInstances.push_back(instance); instance.parameterValues["index"] = "2"; diff --git a/cpp/test/Slice/escape/Client.cpp b/cpp/test/Slice/escape/Client.cpp index 31281e2d49e..011aae40583 100644 --- a/cpp/test/Slice/escape/Client.cpp +++ b/cpp/test/Slice/escape/Client.cpp @@ -9,19 +9,15 @@ using namespace std; -class breakI : public _cpp_and::_cpp_break +class breakI : public cpp_and::_cpp_break { public: - void - caseAsync(::int32_t, function response, function, const ::Ice::Current&) override + void _cpp_caseAsync(::int32_t, function response, function, const ::Ice::Current&) + override { response(0); } -}; -class charI : public _cpp_and::_cpp_char -{ -public: #ifndef NDEBUG void _cpp_explicit(const ::Ice::Current& current) override #else @@ -32,45 +28,40 @@ class charI : public _cpp_and::_cpp_char } }; -class switchI : public _cpp_and::_cpp_switch +class switchI : public cpp_and::_cpp_switch { public: - virtual void foo(optional<_cpp_and::charPrx>, int32_t&, const ::Ice::Current&) {} + virtual void foo(optional, int32_t&, const ::Ice::Current&) {} }; -class doI : public _cpp_and::_cpp_do +class doI : public cpp_and::_cpp_do { public: - void caseAsync(int, ::std::function, ::std::function, const ::Ice::Current&) + void + _cpp_caseAsync(int, ::std::function, ::std::function, const ::Ice::Current&) override { } void _cpp_explicit(const ::Ice::Current&) override {} - virtual void foo(const _cpp_and::charPrx&, int32_t&, const ::Ice::Current&) {} + virtual void foo(const cpp_and::_cpp_breakPrx&, int32_t&, const ::Ice::Current&) {} }; -class friendI : public _cpp_and::_cpp_friend +class friendI : public cpp_and::_cpp_friend { public: - _cpp_and::_cpp_auto _cpp_goto( - _cpp_and::_cpp_continue, - _cpp_and::_cpp_auto, - _cpp_and::_cpp_delete, - _cpp_and::switchPtr, - optional<_cpp_and::doPrx>, - optional<_cpp_and::breakPrx>, - optional<_cpp_and::charPrx>, - _cpp_and::switchPtr, - optional<_cpp_and::doPrx>, - ::int32_t, - ::int32_t, - ::int32_t, + cpp_and::_cpp_auto _cpp_goto( + cpp_and::_cpp_continue, + cpp_and::_cpp_auto, + cpp_and::_cpp_switchPtr, + optional, + optional, + cpp_and::_cpp_switchPtr, ::int32_t, const ::Ice::Current&) override { - return _cpp_and::_cpp_auto(); + return cpp_and::_cpp_auto(); } }; @@ -81,29 +72,23 @@ class friendI : public _cpp_and::_cpp_friend void testtypes(const Ice::CommunicatorPtr& communicator) { - _cpp_and::_cpp_continue a = _cpp_and::_cpp_continue::_cpp_asm; - test(a == _cpp_and::_cpp_continue::_cpp_asm); + cpp_and::_cpp_continue a = cpp_and::_cpp_continue::_cpp_asm; + test(a == cpp_and::_cpp_continue::_cpp_asm); - _cpp_and::_cpp_auto b, b2; + cpp_and::_cpp_auto b, b2; b._cpp_default = 0; b2._cpp_default = b._cpp_default; b._cpp_default = b2._cpp_default; - _cpp_and::_cpp_delete c; - c._cpp_else = ""; - - _cpp_and::breakPrx d(communicator, "hello:tcp -h 127.0.0.1 -p 12010"); + cpp_and::_cpp_breakPrx d(communicator, "hello:tcp -h 127.0.0.1 -p 12010"); int d2; d->_cpp_case(0, d2); - _cpp_and::breakPtr d1 = std::make_shared(); - - _cpp_and::charPrx e(communicator, "hello:tcp -h 127.0.0.1 -p 12010"); - e->_cpp_explicit(); - _cpp_and::charPtr e1 = std::make_shared(); + d->_cpp_explicit(); + cpp_and::_cpp_breakPtr d1 = std::make_shared(); - _cpp_and::switchPtr f1 = std::make_shared(); + cpp_and::_cpp_switchPtr f1 = std::make_shared(); - optional<_cpp_and::doPrx> g; + optional g; // Work-around for: // error: array subscript -6 is outside array bounds of ‘int (* [1152921504606846975])(...)’ [-Werror=array-bounds] @@ -116,23 +101,22 @@ testtypes(const Ice::CommunicatorPtr& communicator) #if defined(NDEBUG) && defined(__GNUC__) # pragma GCC diagnostic pop #endif - _cpp_and::doPtr g1 = std::make_shared(); + cpp_and::_cpp_doPtr g1 = std::make_shared(); - _cpp_and::_cpp_extern h; - _cpp_and::_cpp_for i; - _cpp_and::_cpp_return j; + cpp_and::_cpp_extern h; + cpp_and::_cpp_for i; + cpp_and::_cpp_return j; j._cpp_signed = 0; - _cpp_and::_cpp_sizeof k; + cpp_and::_cpp_sizeof k; k._cpp_static = 0; k._cpp_switch = 1; k._cpp_signed = 2; - _cpp_and::friendPtr l = std::make_shared(); - - const int m = _cpp_and::_cpp_template; - test(m == _cpp_and::_cpp_template); + cpp_and::_cpp_friendPtr l = std::make_shared(); - test(_cpp_and::_cpp_xor_eq == 0); + const int m = cpp_and::_cpp_template; + test(m == cpp_and::_cpp_template); + test(cpp_and::_cpp_template == 0); } class Client : public Test::TestHelper @@ -147,11 +131,11 @@ Client::run(int argc, char** argv) Ice::CommunicatorHolder communicator = initialize(argc, argv); communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); - adapter->add(std::make_shared(), Ice::stringToIdentity("test")); + adapter->add(std::make_shared(), Ice::stringToIdentity("test")); adapter->activate(); cout << "Testing operation name... " << flush; - auto p = adapter->createProxy<_cpp_and::charPrx>(Ice::stringToIdentity("test")); + auto p = adapter->createProxy(Ice::stringToIdentity("test")); p->_cpp_explicit(); cout << "ok" << endl; } diff --git a/cpp/test/Slice/escape/Key.ice b/cpp/test/Slice/escape/Key.ice index af79588eaec..5c92b4a186f 100644 --- a/cpp/test/Slice/escape/Key.ice +++ b/cpp/test/Slice/escape/Key.ice @@ -1,77 +1,85 @@ // Copyright (c) ZeroC, Inc. -module and +// TODO figure out how to escape identifiers on modules! +//["cpp:identifier:_cpp_and"] This should be `module and` which is mapped to `_cpp_and`. +module cpp_and { +["cpp:identifier:_cpp_continue"] enum continue { + ["cpp:identifier:_cpp_asm"] asm } +["cpp:identifier:_cpp_auto"] struct auto { + ["cpp:identifier:_cpp_default"] int default; } -struct delete -{ - string else; -} - +["cpp:identifier:_cpp_break"] interface break { - ["amd"] void case(int catch, out int try); -} + ["amd", "cpp:identifier:_cpp_case"] void case( + ["cpp:identifier:_cpp_catch"] int catch, + out ["cpp:identifier:_cpp_try"] int try + ); -interface char -{ - void explicit(); + ["cpp:identifier:_cpp_explicit"] void explicit(); } +["cpp:identifier:_cpp_switch"] class switch { - int if; - char* export; - int volatile; + ["cpp:identifier:_cpp_if"] int if; + ["cpp:identifier:_cpp_export"] break* export; + ["cpp:identifier:_cpp_volatile"] int volatile; } -interface do extends char, break +["cpp:identifier:_cpp_do"] +interface do extends break { } +["cpp:identifier:_cpp_extern"] sequence extern; +["cpp:identifier:_cpp_for"] dictionary for; +["cpp:identifier:_cpp_return"] exception return { + ["cpp:identifier:_cpp_signed"] int signed; } +["cpp:identifier:_cpp_sizeof"] exception sizeof extends return { - int static; int switch; + ["cpp:identifier:_cpp_static"] int static; + ["cpp:identifier:_cpp_switch"] int switch; } +["cpp:identifier:_cpp_friend"] interface friend { - auto goto(continue if, auto d, delete inline, switch private, do* mutable, break* namespace, - char* new, switch not, do* operator, int or, int protected, int public, int register) - throws return, sizeof; + ["cpp:identifier:_cpp_goto"] + auto goto( + ["cpp:identifier:_cpp_if"] continue if, + ["cpp:identifier:_cpp_d"] auto d, + ["cpp:identifier:_cpp_private"] switch private, + ["cpp:identifier:_cpp_mutable"] do* mutable, + ["cpp:identifier:_cpp_namespace"] break* namespace, + ["cpp:identifier:_cpp_not"] switch not, + ["cpp:identifier:_cpp_or"] int or + ) + throws return, sizeof; } +["cpp:identifier:_cpp_template"] const int template = 0; -const int this = 0; -const int throw = 0; -const int typedef = 0; -const int typeid = 0; -const int typename = 0; -const int union = 0; -const int unsigned = 0; -const int using = 0; -const int virtual = 0; -const int while = 0; -const int xor = 0; -const int xor_eq = 0; } diff --git a/python/modules/IcePy/Slice.cpp b/python/modules/IcePy/Slice.cpp index ed2590b1ed9..fb2e7c3302c 100644 --- a/python/modules/IcePy/Slice.cpp +++ b/python/modules/IcePy/Slice.cpp @@ -127,7 +127,7 @@ IcePy_loadSlice(PyObject* /*self*/, PyObject* args) return nullptr; } - UnitPtr u = Slice::Unit::createUnit(all); + UnitPtr u = Slice::Unit::createUnit("python", all); int parseStatus = u->parse(file, cppHandle, debug); if (!icecpp->close() || parseStatus == EXIT_FAILURE) diff --git a/ruby/src/IceRuby/Slice.cpp b/ruby/src/IceRuby/Slice.cpp index 1bfe5927059..50a6e7ac3f2 100644 --- a/ruby/src/IceRuby/Slice.cpp +++ b/ruby/src/IceRuby/Slice.cpp @@ -117,7 +117,7 @@ IceRuby_loadSlice(int argc, VALUE* argv, VALUE /*self*/) throw RubyException(rb_eArgError, "Slice preprocessing failed for `%s'", cmd.c_str()); } - UnitPtr u = Slice::Unit::createUnit(all); + UnitPtr u = Slice::Unit::createUnit("ruby", all); int parseStatus = u->parse(file, cppHandle, debug); if (!icecpp->close() || parseStatus == EXIT_FAILURE) diff --git a/slice/IceGrid/Descriptor.ice b/slice/IceGrid/Descriptor.ice index bc26e6c1ceb..cf06aa7c753 100644 --- a/slice/IceGrid/Descriptor.ice +++ b/slice/IceGrid/Descriptor.ice @@ -197,6 +197,7 @@ module IceGrid struct ServerInstanceDescriptor { /// The template used by this instance. + ["cpp:identifier:templateName"] string template; /// The template parameter values. @@ -234,6 +235,7 @@ module IceGrid struct ServiceInstanceDescriptor { /// The template used by this instance. + ["cpp:identifier:templateName"] string template; /// The template parameter values.