diff --git a/resources/Custom.stg b/resources/Custom.stg index 67de7a72..3831b149 100644 --- a/resources/Custom.stg +++ b/resources/Custom.stg @@ -84,7 +84,7 @@ string_type(ctx, string) ::= <<>> wide_string_type(ctx, wstring) ::= <<>> -array_declarator(ctx, array, array_type) ::= <<>> +array_declarator(ctx, array) ::= <<>> interface(ctx, parent, interface, export_list) ::= <<>> diff --git a/src/main/java/com/eprosima/fastcdr/idl/context/Context.java b/src/main/java/com/eprosima/fastcdr/idl/context/Context.java index 010ecf89..afeb92dd 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/context/Context.java +++ b/src/main/java/com/eprosima/fastcdr/idl/context/Context.java @@ -39,10 +39,10 @@ public interface Context public String getHeaderGuardName (); - public boolean isGenerateTypeObject(); - public boolean isGenerateTypesROS2(); + public boolean isGenerateTypeObjectSupport(); + public boolean isCdr(); public boolean isFastcdr(); diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg index 62fbec7f..675a88b3 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -56,10 +56,6 @@ $endif$ $ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$ -$if(ctx.generateTypeObject)$ -#include "$ctx.filename$TypeObject.h" -$endif$ - #if defined(_WIN32) #if defined(EPROSIMA_USER_DLL_EXPORT) #define eProsima_user_DllExport __declspec( dllexport ) @@ -104,9 +100,9 @@ $if(annotation.enums || annotation.typeDefs || annotation.constDecls)$ namespace $annotation.name$ { $annotation.enums : { enum | $enum_type(ctx=ctx, parent=annotation, enum=enum)$}; separator="\n"$ - $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef)$}; separator="\n"$ + $annotation.typeDefs : { typedef | $typedef_decl(ctx=ctx, parent=annotation, typedefs=typedef, typedefs_type="", declarator_type="")$}; separator="\n"$ - $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const)$}; separator="\n"$ + $annotation.constDecls : { const | $const_decl(ctx=ctx, parent=annotation, const=const, const_type="")$}; separator="\n"$ } // namespace $annotation.name$ $endif$ @@ -157,10 +153,6 @@ public: : $struct_inherit_default_init(struct.inheritance)$ $endif$ { - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ } /*! @@ -491,10 +483,6 @@ public: : $struct_inherit_default_init(bitset.inheritance)$ $endif$ { - $if(ctx.generateTypeObject)$ - // Just to register all known types - register$ctx.filename$Types(); - $endif$ } /*! diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index 947470eb..32ef6eb3 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -107,9 +107,6 @@ public class fastddsgen // Generates type naming compatible with ROS 2 private boolean m_type_ros2 = false; - // Generate TypeObject files? - private boolean m_type_object_files = false; - // Generate string and sequence types compatible with C? private boolean m_typesc = false; @@ -144,6 +141,9 @@ public enum LANGUAGE // Specifies whether the dependent IDL files should be processed. private boolean generate_dependencies_ = true; + // Specifies whether the TypeObject Support files should be generated. + private boolean generate_typeobjectsupport_ = true; + /* * ---------------------------------------------------------------------------------------- * @@ -307,11 +307,16 @@ else if (languageOption.equalsIgnoreCase("java")) else if (arg.equals(no_typesupport_arg)) { generate_typesupport_ = false; + generate_typeobjectsupport_ = false; } else if (arg.equals(no_dependencies_arg)) { generate_dependencies_ = false; } + else if (arg.equals(no_typeobjectsupport_arg)) + { + generate_typeobjectsupport_ = false; + } else if (arg.equals(package_arg)) { if (count < args.length) @@ -361,10 +366,6 @@ else if (arg.equals(execute_test_arg)) { m_test = true; } - else if (arg.equals(typeobject_arg)) - { - m_type_object_files = true; - } else if (arg.equals(ros2_names_arg)) { m_type_ros2 = true; @@ -579,6 +580,7 @@ private void showVersion() private static final String include_path_arg = "-I"; private static final String language_arg = "-language"; private static final String no_typesupport_arg = "-no-typesupport"; + private static final String no_typeobjectsupport_arg = "-no-typeobjectsupport"; private static final String no_dependencies_arg = "-no-dependencies"; private static final String package_arg = "-package"; private static final String disable_preprocessor_arg = "-ppDisable"; @@ -628,6 +630,8 @@ public static void printHelp() System.out.println("\t\t" + include_path_arg + " : add directory to preprocessor include paths."); System.out.println("\t\t" + language_arg + " : chooses between or languages."); System.out.println("\t\t" + no_typesupport_arg + ": avoid generating the type support files."); + System.out.println("\t\t" + no_typeobjectsupport_arg + ": avoid generating the TypeObject support specific files."); + System.out.println("\t\t\tEnabled automatically if " + no_typesupport_arg + " argument is used."); System.out.println("\t\t" + no_dependencies_arg + ": avoid processing the dependent IDL files."); System.out.println("\t\t" + package_arg + ": default package used in Java files."); System.out.println("\t\t" + disable_preprocessor_arg + ": disables the preprocessor."); @@ -635,8 +639,6 @@ public static void printHelp() System.out.println("\t\t" + python_bindings_arg + ": generates python bindings for the generated types."); System.out.println("\t\t" + replace_arg + ": replaces existing generated files."); System.out.println("\t\t" + temp_dir_arg + " : sets a specific directory as a temporary directory."); - System.out.print("\t\t" + typeobject_arg + ": generates TypeObject files to automatically register the "); - System.out.println("types as dynamic."); System.out.println("\t\t" + cnames_arg + ": generates string and sequence types compatible with C."); System.out.println("\t\t" + ros2_names_arg + ": generates type naming compatible with ROS2."); System.out.println("\t\t" + version_arg + ": shows the current version of eProsima Fast DDS gen."); @@ -730,7 +732,7 @@ private Project parseIDL( TemplateManager tmanager = new TemplateManager(); Context ctx = new Context(tmanager, idlFilename, m_includePaths, m_subscribercode, m_publishercode, - m_localAppProduct, m_type_object_files, m_typesc, m_type_ros2, gen_api_); + m_localAppProduct, m_typesc, m_type_ros2, gen_api_, generate_typeobjectsupport_); String relative_dir = ctx.getRelativeDir(dependant_idl_dir); String output_dir; @@ -769,11 +771,6 @@ private Project parseIDL( // Load common types template tmanager.addGroup("com/eprosima/fastcdr/idl/templates/TypesHeader.stg").enable_custom_property( Context.using_explicitly_modules_custom_property); - if (m_type_object_files) - { - tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg"); - tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypeObjectSource.stg"); - } // Load Types common templates if (generate_typesupport_) @@ -782,6 +779,12 @@ private Project parseIDL( tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg"); tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg"); tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg"); + + if (generate_typeobjectsupport_) + { + tmanager.addGroup("com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg"); + tmanager.addGroup("com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg"); + } } if (m_exampleOption != null) @@ -804,6 +807,12 @@ private Project parseIDL( tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationTestSource.stg"); tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationHeader.stg"); tmanager.addGroup("com/eprosima/fastdds/idl/templates/SerializationSource.stg"); + + if (generate_typeobjectsupport_) + { + // Load TypeObjectSupport test template + tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg"); + } } // Add JNI sources. @@ -852,8 +861,7 @@ private Project parseIDL( lexer.setContext(ctx); CommonTokenStream tokens = new CommonTokenStream(lexer); IDLParser parser = new IDLParser(tokens); - // Pass the finelame without the extension - + // Pass the filename without the extension Specification specification = parser.specification(ctx, tmanager, maintemplates).spec; returnedValue = specification != null && !tmanager.get_st_error();; @@ -909,32 +917,17 @@ private Project parseIDL( maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesHeader.stg"), m_replace))) { - project.addCommonIncludeFile(relative_dir + ctx.getFilename() + ".hpp"); - - if (m_type_object_files) - { - System.out.println("Generating TypeObject files..."); - if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "TypeObject.h", - maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg"), m_replace)) - { - if (returnedValue = Utils.writeFile(output_dir + ctx.getFilename() + "TypeObject.cxx", - maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypeObjectSource.stg"), m_replace)) - { - project.addCommonIncludeFile(relative_dir + ctx.getFilename() + "TypeObject.h"); - project.addCommonSrcFile(relative_dir + ctx.getFilename() + "TypeObject.cxx"); - } - } - } - if (m_python) - { - System.out.println("Generating Swig interface files..."); - if (returnedValue = - Utils.writeFile(output_dir + ctx.getFilename() + ".i", - maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg"), m_replace)) - { - - } - } + project.addCommonIncludeFile(relative_dir + ctx.getFilename() + ".hpp"); + + if (m_python) + { + System.out.println("Generating Swig interface files..."); + if (returnedValue = + Utils.writeFile(output_dir + ctx.getFilename() + ".i", + maintemplates.getTemplate("com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg"), m_replace)) + { + } + } } if (m_test) @@ -961,11 +954,34 @@ private Project parseIDL( String trimmedElement = element.substring(0, element.length() - 4);// Remove .idl project.addCommonTestingFile(trimmedElement + "Serialization.cpp"); } + + if (generate_typeobjectsupport_) + { + System.out.println("Generating TypeObjects Test file..."); + String fileNameTO = output_dir + ctx.getFilename() + "TypeObjectTestingTest.cpp"; + returnedValue = Utils.writeFile(fileNameTO, maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg"), m_replace); + project.addTypeObjectTestingFile(relative_dir + ctx.getFilename() + "TypeObjectTestingTest.cpp"); + } } System.out.println("Generating Type Support files..."); if (generate_typesupport_) { + if (generate_typeobjectsupport_) + { + System.out.println("Generating TypeObjectSupport files..."); + if (returnedValue &= Utils.writeFile(output_dir + ctx.getFilename() + "TypeObjectSupport.hpp", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg"), m_replace)) + { + if (returnedValue &= Utils.writeFile(output_dir + ctx.getFilename() + "TypeObjectSupport.cxx", + maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg"), m_replace)) + { + project.addCommonIncludeFile(relative_dir + ctx.getFilename() + "TypeObjectSupport.hpp"); + project.addCommonSrcFile(relative_dir + ctx.getFilename() + "TypeObjectSupport.cxx"); + } + } + } + if (ctx.isThereIsStructOrUnion()) { if (returnedValue &= @@ -1669,7 +1685,7 @@ public void run() } else { - // Sustituir los "\\" que pone cl.exe por "\" + // Substitute "\\" added by cl.exe for "\" if (line.startsWith(clLine)) { line = "#" + line.substring(clLine.length()); diff --git a/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java b/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java index 1a774b50..6b8ba6b8 100644 --- a/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java +++ b/src/main/java/com/eprosima/fastdds/idl/grammar/Context.java @@ -61,10 +61,10 @@ public Context( boolean subscribercode, boolean publishercode, String appProduct, - boolean generate_type_object, boolean generate_typesc, boolean generate_type_ros2, - boolean is_generating_api + boolean is_generating_api, + boolean generate_typeobjectsupport ) { super(tmanager, file, includePaths, generate_typesc); @@ -78,13 +78,13 @@ public Context( //m_protocol = protocol; //m_ddstypes = ddstypes; - m_type_object = generate_type_object; m_type_ros2 = generate_type_ros2; is_generating_api_ = is_generating_api; + generate_typeobject_support_ = generate_typeobjectsupport; // Create default @Key annotation. - AnnotationDeclaration keyann = this.createAnnotationDeclaration("Key", null); - keyann.addMember(new AnnotationMember("value", new PrimitiveTypeCode(Kind.KIND_BOOLEAN), "true")); + AnnotationDeclaration keyann = this.createAnnotationDeclaration(Annotation.eprosima_key_str, null); + keyann.addMember(new AnnotationMember(Annotation.value_str, new PrimitiveTypeCode(Kind.KIND_BOOLEAN), Annotation.true_str)); } @@ -565,20 +565,20 @@ public String getPackageUnder() private TypeDeclaration m_lastStructure = null; - private boolean m_type_object = false; - private boolean m_type_ros2 = false; + private boolean generate_typeobject_support_ = true; + @Override - public boolean isGenerateTypeObject() + public boolean isGenerateTypesROS2() { - return m_type_object; + return m_type_ros2; } @Override - public boolean isGenerateTypesROS2() + public boolean isGenerateTypeObjectSupport() { - return m_type_ros2; + return generate_typeobject_support_; } public String getHeaderGuardName () diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg b/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg index 08e5857c..ffe76cab 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg @@ -43,6 +43,10 @@ find_package(fastrtps 2.12 REQUIRED) $solution.projects : { project | $pub_sub_execs(project=project, libraries=solution.libraries, test=test)$}; separator="\n"$ +$if (test)$ +$type_object_tests(project=solution.mainProject, libraries=solution.libraries)$ +$endif$ + >> pub_sub_execs(project, libraries, test) ::= << @@ -50,12 +54,12 @@ pub_sub_execs(project, libraries, test) ::= << message(STATUS "Configuring $project.name$...") $if(!project.commonSrcFiles.empty)$ add_library($project.name$_lib $project.commonSrcFiles : { file | $file$}; separator=" "$) -target_link_libraries($project.name$_lib $solution.libraries : { library | $library$}; separator=" "$) +target_link_libraries($project.name$_lib $libraries : { library | $library$}; separator=" "$) $endif$ $if(!project.projectSrcFiles.empty)$ add_executable($project.name$ $project.projectSrcFiles : { file | $file$}; separator=" "$) -target_link_libraries($project.name$ $solution.libraries : { library | $library$}; separator=" "$ +target_link_libraries($project.name$ $libraries : { library | $library$}; separator=" "$ $project.name$_lib $project.dependencies : { dep | $dep$_lib}; separator=" "$ ) $endif$ @@ -77,11 +81,26 @@ add_executable($project.name$SerializationTest ) target_link_libraries($project.name$SerializationTest GTest::gtest_main - $solution.libraries : { library | $library$}; separator=" "$ + $libraries : { library | $library$}; separator=" "$ $project.name$_lib $project.dependencies : { dep | $dep$_lib}; separator=" "$ ) gtest_discover_tests($project.name$SerializationTest) $endif$ + +>> + +type_object_tests(project, libraries) ::= << +$if(project.typeObjectTestingFiles)$ +# $project.name$ TypeObject Test +add_executable($project.name$TypeObjectTestingTest + $project.typeObjectTestingFiles : { file | $file$}; separator="\n"$ +) +target_link_libraries($project.name$TypeObjectTestingTest + GTest::gtest_main + $libraries : { library | $library$}; separator=" "$ + $project.name$_lib $project.dependencies : { dep | $dep$_lib}; separator=" "$) +gtest_discover_tests($project.name$TypeObjectTestingTest) +$endif$ >> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg index 1e15d327..5775dfb4 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg @@ -147,6 +147,9 @@ public: eProsima_user_DllExport void deleteData( void* data) override; + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() const override; + #ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED eProsima_user_DllExport inline bool is_bounded() const override { diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg index 057eb754..dd2ed831 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg @@ -19,11 +19,15 @@ import "eprosima.stg" main(ctx, definitions) ::= << $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.cpp"], description=["This header file contains the implementation of the serialization functions."])$ +#include "$ctx.filename$PubSubTypes.h" +#include #include -#include "$ctx.filename$PubSubTypes.h" #include "$ctx.filename$CdrAux.hpp" +$if (ctx.generateTypeObjectSupport)$ +#include "$ctx.filename$TypeObjectSupport.hpp" +$endif$ using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; @@ -235,6 +239,16 @@ bool $struct.name$PubSubType::getKey( return true; } +void $struct.name$PubSubType::register_type_object_representation() const +{ + $if (ctx.generateTypeObjectSupport)$ + register_$ctx.filename$_type_objects(); + $else$ + EPROSIMA_LOG_WARNING(XTYPES_TYPE_REPRESENTATION, + "TypeObject type representation support disabled in generated code"); + $endif$ +} + >> //{ Fast DDS-Gen extensions diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg deleted file mode 100644 index 058e82b9..00000000 --- a/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectHeader.stg +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -group TypeObjectHeader; - -import "eprosima.stg" - -main(ctx, definitions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObject.h"], description=["This header file contains the declaration of the described types in the IDL file."])$ - -#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_H_ -#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_H_ - -$ctx.directIncludeDependencies : {include | #include "$include$TypeObject.h"}; separator="\n"$ - -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif -#else -#define eProsima_user_DllExport -#endif - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined($ctx.filename;format="toUpper"$_SOURCE) -#define $ctx.filename;format="toUpper"$_DllAPI __declspec( dllexport ) -#else -#define $ctx.filename;format="toUpper"$_DllAPI __declspec( dllimport ) -#endif // $ctx.filename;format="toUpper"$_SOURCE -#else -#define $ctx.filename;format="toUpper"$_DllAPI -#endif -#else -#define $ctx.filename;format="toUpper"$_DllAPI -#endif // _WIN32 - -using namespace eprosima::fastrtps::types; - -eProsima_user_DllExport void register$ctx.filename$Types(); - -$definitions; separator="\n"$ - -#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_H_ ->> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << -$declarator_type$ -$typedefs_type$ -eProsima_user_DllExport const TypeIdentifier* Get$typedefs.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$typedefs.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$typedefs.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$typedefs.name$Object(); - ->> - -enum_type(ctx, parent, enum) ::= << -eProsima_user_DllExport const TypeIdentifier* Get$enum.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$enum.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$enum.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$enum.name$Object(); - ->> - -bitmask_type(ctx, parent, bitmask) ::= << -eProsima_user_DllExport const TypeIdentifier* Get$bitmask.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$bitmask.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$bitmask.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$bitmask.name$Object(); - ->> - -struct_type(ctx, parent, struct, extensions, member_list) ::= << -$member_list$ -eProsima_user_DllExport const TypeIdentifier* Get$struct.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$struct.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$struct.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$struct.name$Object(); - ->> - -union_type(ctx, parent, union, extensions, switch_type) ::= << -$switch_type$ -eProsima_user_DllExport const TypeIdentifier* Get$union.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$union.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$union.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$union.name$Object(); - ->> - -bitset_type(ctx, parent, bitset, extensions) ::= << -eProsima_user_DllExport const TypeIdentifier* Get$bitset.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$bitset.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$bitset.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$bitset.name$Object(); - ->> - -annotation(ctx, annotation) ::= << -eProsima_user_DllExport const TypeIdentifier* Get$annotation.name$Identifier(bool complete = false); -eProsima_user_DllExport const TypeObject* Get$annotation.name$Object(bool complete = false); -eProsima_user_DllExport const TypeObject* GetMinimal$annotation.name$Object(); -eProsima_user_DllExport const TypeObject* GetComplete$annotation.name$Object(); - -namespace $annotation.name$ -{ -$annotation.enums : { it | $enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ - -$annotation.typeDefs : { it | $typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ -} - ->> - -module(ctx, parent, module, definition_list) ::= << -namespace $module.name$ { - $definition_list$ -} // namespace $module.name$ ->> - -//{ Fast DDS-Gen extensions -module_conversion(ctx, parent, modules, definition_list) ::= << -$modules : { module | -namespace $module.name$ { -}; separator="\n"$ - -$definition_list$ - -$reverse(modules) : { module | -\} // namespace $module.name$ -}; separator="\n"$ ->> -//} diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg deleted file mode 100644 index 5244b966..00000000 --- a/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectSource.stg +++ /dev/null @@ -1,1882 +0,0 @@ -// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -group TypeObjectSource; - -import "eprosima.stg" - -main(ctx, definitions) ::= << -$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObject.cpp"], description=["This source file contains the definition of the described types in the IDL file."])$ - -#ifdef _WIN32 -// Remove linker warning LNK4221 on Visual Studio -namespace { char dummy; } -#endif - -#include "$ctx.filename$.hpp" -#include "$ctx.filename$TypeObject.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::fastrtps::rtps; - -void register$ctx.filename$Types() -{ - static std::once_flag once_flag; - std::call_once(once_flag, []() - { - TypeObjectFactory *factory = TypeObjectFactory::get_instance(); - $ctx.definitions: { def | $register_type(ctx=ctx, object=def, param="type_name")$}; separator="\n"$ - }); -} - -$definitions; separator="\n"$ ->> - - -try_create(ctx, object, param) ::= << -if ($param$ == $if(ctx.GenerateTypesROS2)$"$object.ROS2Scopedname$"$else$"$if(object.hasScope)$$object.scope$::$endif$$object.name$"$endif$) return $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Identifier(complete); ->> - -try_object(ctx, object, param) ::= << -if ($param$ == $if(ctx.GenerateTypesROS2)$"$object.ROS2Scopedname$"$else$"$if(object.hasScope)$$object.scope$::$endif$$object.name$"$endif$) -{ - $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Identifier(complete); - return TypeObjectFactory::get_instance()->get_type_object($if(ctx.GenerateTypesROS2)$"$object.ROS2Scopedname$"$else$"$if(object.hasScope)$$object.scope$::$endif$$object.name$"$endif$, complete); -} ->> - -register_type(ctx, object, param) ::= << -$if(!object.isModule)$ -$if(!object.isConstDeclaration)$ -factory->add_type_object($if(ctx.GenerateTypesROS2)$"$object.ROS2Scopedname$"$else$"$if(object.hasScope)$$object.scope$::$endif$$object.name$"$endif$, $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Identifier(true), - $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Object(true)); -factory->add_type_object($if(ctx.GenerateTypesROS2)$"$object.ROS2Scopedname$"$else$"$if(object.hasScope)$$object.scope$::$endif$$object.name$"$endif$, $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Identifier(false), - $if(object.hasScope)$$object.scope$::$endif$Get$object.name$Object(false)); -$if(object.isAnnotation)$ -{ - using namespace $object.name$; - $register_annotation_types(object)$ -} -$endif$ -$endif$ -$endif$ ->> - -register_annotation_types(annotation) ::= << - -$annotation.enums : { it | $register_annotation_enum(it)$}; separator="\n"$ - -$annotation.typeDefs : { it | $register_annotation_typedef(it)$}; separator="\n"$ - ->> - -register_annotation_enum(enum) ::= << -factory->add_type_object("$enum.name$", $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Identifier(true), - $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Object(true)); -factory->add_type_object("$enum.name$", $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Identifier(false), - $if(enum.hasScope)$$enum.scope$::$endif$Get$enum.name$Object(false)); ->> - -register_annotation_typedef(typedef) ::= << -factory->add_type_object("$typedef.name$", - $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Identifier(true), - $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Object(true)); -factory->add_type_object("$typedef.name$", - $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Identifier(false), - $if(typedef.hasScope)$$typedef.scope$::$endif$Get$typedef.name$Object(false)); ->> - -module(ctx, parent, module, definition_list) ::= << -namespace $module.name$ { - $definition_list$ -} // namespace $module.name$ ->> - -annotation(ctx, annotation) ::= << -const TypeIdentifier* Get$annotation.name$Identifier(bool complete) -{ - const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$annotation.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$annotation.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$annotation.name$", complete); -} - -const TypeObject* Get$annotation.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$annotation.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$annotation.name$Object(); - } - // else - return GetMinimal$annotation.name$Object(); -} - -const TypeObject* GetMinimal$annotation.name$Object() -{ - using namespace $annotation.name$; - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$annotation.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_ANNOTATION); - - $annotation.members:{ member | $minimal_annotation_member(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().annotation_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$annotation.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$annotation.name$", false); -} - -const TypeObject* GetComplete$annotation.name$Object() -{ - using namespace $annotation.name$; - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$annotation.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_ANNOTATION); - - // No flags apply - //type_object->complete().annotation_type().annotation_flags().IS_FINAL(false); - //type_object->complete().annotation_type().annotation_flags().IS_APPENDABLE(false); - //type_object->complete().annotation_type().annotation_flags().IS_MUTABLE(false); - //type_object->complete().annotation_type().annotation_flags().IS_NESTED(false); - //type_object->complete().annotation_type().annotation_flags().IS_AUTOID_HASH(false); - - type_object->complete().annotation_type().header().annotation_name("$annotation.name$"); - - $annotation.members:{ member | $complete_annotation_member(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().annotation_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$annotation.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$annotation.name$", true); -} - -namespace $annotation.name$ -{ -$annotation.enums : { it |$enum_type(ctx=ctx, parent=annotation, enum=it)$}; separator="\n"$ - -$annotation.typeDefs : { it |$typedef_decl(ctx=ctx, parent=annotation, typedefs=it)$}; separator="\n"$ - -} // $annotation.name$ namespace ->> - -minimal_annotation_member(ctx, object) ::= << -MinimalAnnotationParameter mam_$object.name$; -TypeIdentifier* mam_$object.name$_typeId = $get_type_identifier(ctx=ctx, type=object.typecode, ek="false")$; -if (mam_$object.name$_typeId != nullptr) -{ - mam_$object.name$.common().member_type_id(*mam_$object.name$_typeId); -} -mam_$object.name$.name("$object.name$"); - -$if(object.value)$ -AnnotationParameterValue def_value_$object.name$; -def_value_$object.name$._d(mam_$object.name$.common().member_type_id()._d()); -def_value_$object.name$.from_string("$object.value$"); -mam_$object.name$.default_value(def_value_$object.name$); -$endif$ - -type_object->minimal().annotation_type().member_seq().emplace_back(mam_$object.name$); - ->> - -complete_annotation_member(ctx, object) ::= << -CompleteAnnotationParameter cam_$object.name$; -TypeIdentifier* cam_$object.name$_typeId = $get_type_identifier(ctx=ctx, type=object.typecode, ek="true")$; -if (mam_$object.name$_typeId != nullptr) -{ - cam_$object.name$.common().member_type_id(*cam_$object.name$_typeId); -} -cam_$object.name$.name("$object.name$"); - -$if(object.value)$ -AnnotationParameterValue def_value_$object.name$; -def_value_$object.name$._d(cam_$object.name$.common().member_type_id()._d()); -def_value_$object.name$.from_string("$object.value$"); -cam_$object.name$.default_value(def_value_$object.name$); -$endif$ - -type_object->complete().annotation_type().member_seq().emplace_back(cam_$object.name$); - ->> - -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << -$declarator_type$ -$typedefs_type$ -const TypeIdentifier* Get$typedefs.name$Identifier(bool complete) -{ - const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$typedefs.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$typedefs.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$typedefs.name$", complete); -} - -const TypeObject* Get$typedefs.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$typedefs.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$typedefs.name$Object(); - } - else - { - return GetMinimal$typedefs.name$Object(); - } -} - -const TypeObject* GetMinimal$typedefs.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$typedefs.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_ALIAS); - - // No flags apply - //type_object->minimal().alias_type().alias_flags().IS_FINAL(false); - //type_object->minimal().alias_type().alias_flags().IS_APPENDABLE(false); - //type_object->minimal().alias_type().alias_flags().IS_MUTABLE(false); - //type_object->minimal().alias_type().alias_flags().IS_NESTED(false); - //type_object->minimal().alias_type().alias_flags().IS_AUTOID_HASH(false); - - // type_object->minimal().alias_type().header()... Is empty - - // No flags apply - //type_object->minimal().alias_type().body().common().related_flags().TRY_CONSTRUCT1(false); - //type_object->minimal().alias_type().body().common().related_flags().TRY_CONSTRUCT2(false); - //type_object->minimal().alias_type().body().common().related_flags().IS_EXTERNAL(false); - //type_object->minimal().alias_type().body().common().related_flags().IS_OPTIONAL(false); - //type_object->minimal().alias_type().body().common().related_flags().IS_MUST_UNDERSTAND(false); - //type_object->minimal().alias_type().body().common().related_flags().IS_KEY(false); - //type_object->minimal().alias_type().body().common().related_flags().IS_DEFAULT(false); - - // Must be defined already, if don't, may be an recursive alias - const TypeIdentifier *relatedType = TypeObjectFactory::get_instance()->get_type_identifier($get_content_type(ctx=ctx, type=typedefs.typedefContentTypeCode)$, false); - - - if (relatedType != nullptr) - { - type_object->minimal().alias_type().body().common().related_type() = *relatedType; // Make a copy - } - else - { - // Cannot determine base type - delete type_object; - return nullptr; - } - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().alias_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - // Don't add our TypeIdentifier but our alias - TypeObjectFactory::get_instance()->add_alias("$typedefs.name$", $get_content_type(ctx=ctx, type=typedefs.typedefContentTypeCode)$); - - TypeObjectFactory::get_instance()->add_type_object("$typedefs.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$typedefs.name$", false); -} - -const TypeObject* GetComplete$typedefs.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$typedefs.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_ALIAS); - - // No flags apply - //type_object->complete().alias_type().alias_flags().IS_FINAL(false); - //type_object->complete().alias_type().alias_flags().IS_APPENDABLE(false); - //type_object->complete().alias_type().alias_flags().IS_MUTABLE(false); - //type_object->complete().alias_type().alias_flags().IS_NESTED(false); - //type_object->complete().alias_type().alias_flags().IS_AUTOID_HASH(false); - - //type_object->complete().alias_type().header().detail().ann_builtin().verbatim().placement("placement"); - //type_object->complete().alias_type().header().detail().ann_builtin().verbatim().language("language"); - //type_object->complete().alias_type().header().detail().ann_builtin().verbatim().text("text"); - //type_object->complete().alias_type().header().detail().ann_custom().push_back(...); - type_object->complete().alias_type().header().detail().type_name("$typedefs.name$"); - - // No flags apply - //type_object->complete().alias_type().body().common().related_flags().TRY_CONSTRUCT1(false); - //type_object->complete().alias_type().body().common().related_flags().TRY_CONSTRUCT2(false); - //type_object->complete().alias_type().body().common().related_flags().IS_EXTERNAL(false); - //type_object->complete().alias_type().body().common().related_flags().IS_OPTIONAL(false); - //type_object->complete().alias_type().body().common().related_flags().IS_MUST_UNDERSTAND(false); - //type_object->complete().alias_type().body().common().related_flags().IS_KEY(false); - //type_object->complete().alias_type().body().common().related_flags().IS_DEFAULT(false); - - //type_object->complete().alias_type().body().common().ann_builtin() - //type_object->complete().alias_type().body().common().ann_custom() - - // Must be defined already, if don't, may be an recursive alias - const TypeIdentifier *relatedType = TypeObjectFactory::get_instance()->get_type_identifier_trying_complete($get_content_type(ctx=ctx, type=typedefs.typedefContentTypeCode)$); - - - if (relatedType != nullptr) - { - type_object->complete().alias_type().body().common().related_type() = *relatedType; // Make a copy - } - else - { - // Cannot determine base type - delete type_object; - return nullptr; - } - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().alias_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - // Don't add our TypeIdentifier but our alias - TypeObjectFactory::get_instance()->add_alias("$typedefs.name$", $get_content_type(ctx=ctx, type=typedefs.typedefContentTypeCode)$); - - TypeObjectFactory::get_instance()->add_type_object("$typedefs.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$typedefs.name$", true); -} - ->> - -enum_type(ctx, parent, enum) ::= << -const TypeIdentifier* Get$enum.name$Identifier(bool complete) -{ - const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$enum.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$enum.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$enum.name$", complete); -} - -const TypeObject* Get$enum.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$enum.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$enum.name$Object(); - } - // else - return GetMinimal$enum.name$Object(); -} - -const TypeObject* GetMinimal$enum.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$enum.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_ENUM); - - // No flags apply - //type_object->minimal().enumerated_type().enum_flags().IS_FINAL(false); - //type_object->minimal().enumerated_type().enum_flags().IS_APPENDABLE(false); - //type_object->minimal().enumerated_type().enum_flags().IS_MUTABLE(false); - //type_object->minimal().enumerated_type().enum_flags().IS_NESTED(false); - //type_object->minimal().enumerated_type().enum_flags().IS_AUTOID_HASH(false); - - type_object->minimal().enumerated_type().header().common().bit_bound(32); // TODO fixed by IDL, isn't? - - uint32_t value = 0; - $enum.members:{ member | $minimal_enumerated_literal(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().enumerated_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$enum.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$enum.name$", false); -} - -const TypeObject* GetComplete$enum.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$enum.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_ENUM); - - // No flags apply - //type_object->complete().enumerated_type().enum_flags().IS_FINAL(false); - //type_object->complete().enumerated_type().enum_flags().IS_APPENDABLE(false); - //type_object->complete().enumerated_type().enum_flags().IS_MUTABLE(false); - //type_object->complete().enumerated_type().enum_flags().IS_NESTED(false); - //type_object->complete().enumerated_type().enum_flags().IS_AUTOID_HASH(false); - - type_object->complete().enumerated_type().header().common().bit_bound(32); // TODO fixed by IDL, isn't? - type_object->complete().enumerated_type().header().detail().type_name("$enum.name$"); - - $if(enum.annotationList)$ - $enum.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().enumerated_type().header().detail().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - uint32_t value = 0; - $enum.members:{ member | $complete_enumerated_literal(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().enumerated_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$enum.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$enum.name$", true); -} - ->> - -minimal_enumerated_literal(ctx, object) ::= << -MinimalEnumeratedLiteral mel_$object.name$; -mel_$object.name$.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply -mel_$object.name$.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply -mel_$object.name$.common().flags().IS_EXTERNAL(false); // Doesn't apply -mel_$object.name$.common().flags().IS_OPTIONAL(false); // Doesn't apply -mel_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply -mel_$object.name$.common().flags().IS_KEY(false); // Doesn't apply -mel_$object.name$.common().flags().IS_DEFAULT($object.annotationDefaultLiteral$); -mel_$object.name$.common().value(value++); -MD5 $object.name$_hash("$object.name$"); -for(int i = 0; i < 4; ++i) -{ - mel_$object.name$.detail().name_hash()[i] = $object.name$_hash.digest[i]; -} -type_object->minimal().enumerated_type().literal_seq().emplace_back(mel_$object.name$); - ->> - -complete_enumerated_literal(ctx, object) ::= << -CompleteEnumeratedLiteral cel_$object.name$; -cel_$object.name$.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply -cel_$object.name$.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply -cel_$object.name$.common().flags().IS_EXTERNAL(false); // Doesn't apply -cel_$object.name$.common().flags().IS_OPTIONAL(false); // Doesn't apply -cel_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply -cel_$object.name$.common().flags().IS_KEY(false); // Doesn't apply -cel_$object.name$.common().flags().IS_DEFAULT($object.annotationDefaultLiteral$); -cel_$object.name$.common().value(value++); -cel_$object.name$.detail().name("$object.name$"); - -$if(object.annotationList)$ -$object.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | - { - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - \} - };separator="\n"$ - $endif$ - cel_$object.name$.detail().ann_custom().push_back(ann); -\} -}; separator="\n"$ -$endif$ - -type_object->complete().enumerated_type().literal_seq().emplace_back(cel_$object.name$); - ->> - -struct_type(ctx, parent, struct, extensions, member_list) ::= << -$member_list$ -const TypeIdentifier* Get$struct.name$Identifier(bool complete) -{ - const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$struct.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$struct.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$struct.name$", complete); -} - -const TypeObject* Get$struct.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$struct.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$struct.name$Object(); - } - //else - return GetMinimal$struct.name$Object(); -} - -const TypeObject* GetMinimal$struct.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$struct.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_STRUCTURE); - - type_object->minimal().struct_type().struct_flags().IS_FINAL(false); - type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false); - type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false); - type_object->minimal().struct_type().struct_flags().IS_NESTED(false); - type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported - - MemberId memberId = 0; - $struct.members:{ member | $minimal_member_object_type(ctx=ctx, object=member)$}; separator="\n"$ - - // Header - // TODO Inheritance - //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL); - //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13]; - $if(struct.inheritance)$ - $minimal_struct_inheritance(struct.inheritance)$ - $endif$ - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().struct_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$struct.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$struct.name$", false); -} - -const TypeObject* GetComplete$struct.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$struct.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_STRUCTURE); - - type_object->complete().struct_type().struct_flags().IS_FINAL(false); - type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false); - type_object->complete().struct_type().struct_flags().IS_MUTABLE(false); - type_object->complete().struct_type().struct_flags().IS_NESTED(false); - type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported - - MemberId memberId = 0; - $struct.members:{ member | $complete_member_object_type(ctx=ctx, object=member)$}; separator="\n"$ - - // Header - type_object->complete().struct_type().header().detail().type_name("$struct.name$"); - // TODO inheritance - $if(struct.inheritance)$ - $complete_struct_inheritance(struct.inheritance)$ - $endif$ - - $if(struct.annotationList)$ - $struct.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().struct_type().header().detail().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().struct_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$struct.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$struct.name$", true); -} - ->> - -minimal_struct_inheritance(parent) ::= << -type_object->minimal().struct_type().header().base_type(*Get$parent.name$Identifier(false)); ->> - -complete_struct_inheritance(parent) ::= << -type_object->complete().struct_type().header().base_type(*Get$parent.name$Identifier(true)); ->> - -minimal_member_object_type(ctx, object) ::= << -MinimalStructMember mst_$object.name$; -mst_$object.name$.common().member_id(memberId++); -mst_$object.name$.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported -mst_$object.name$.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported -mst_$object.name$.common().member_flags().IS_EXTERNAL(false); // Unsupported -mst_$object.name$.common().member_flags().IS_OPTIONAL($object.annotationOptional$); -mst_$object.name$.common().member_flags().IS_MUST_UNDERSTAND($object.annotationMustUnderstand$); -mst_$object.name$.common().member_flags().IS_KEY($object.annotationKey$); -mst_$object.name$.common().member_flags().IS_DEFAULT(false); // Doesn't apply -$if(object.typecode.plainType)$ -mst_$object.name$.common().member_type_id(*$get_type_identifier(ctx=ctx, type=object.typecode, ek="false")$); -$elseif(object.typecode.objectType)$ -mst_$object.name$.common().member_type_id(*$if(object.typecode.hasScope)$$object.typecode.scope$::$endif$Get$object.typecode.name$Identifier(false)); -$else$ -mst_$object.name$.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("$object.typecode.cppTypenameForTypeId$", false)); -$endif$ - - -MD5 $object.name$_hash("$object.name$"); -for(int i = 0; i < 4; ++i) -{ - mst_$object.name$.detail().name_hash()[i] = $object.name$_hash.digest[i]; -} -type_object->minimal().struct_type().member_seq().emplace_back(mst_$object.name$); - ->> - -complete_member_object_type(ctx, object) ::= << -CompleteStructMember cst_$object.name$; -cst_$object.name$.common().member_id(memberId++); -cst_$object.name$.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported -cst_$object.name$.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported -cst_$object.name$.common().member_flags().IS_EXTERNAL(false); // Unsupported -cst_$object.name$.common().member_flags().IS_OPTIONAL($object.annotationOptional$); -cst_$object.name$.common().member_flags().IS_MUST_UNDERSTAND($object.annotationMustUnderstand$); -cst_$object.name$.common().member_flags().IS_KEY($object.annotationKey$); -cst_$object.name$.common().member_flags().IS_DEFAULT(false); // Doesn't apply -$if(object.typecode.plainType)$ -cst_$object.name$.common().member_type_id(*$get_type_identifier(ctx=ctx, type=object.typecode, ek="true")$); -$elseif(object.typecode.objectType)$ -cst_$object.name$.common().member_type_id(*$if(object.typecode.hasScope)$$object.typecode.scope$::$endif$Get$object.typecode.name$Identifier(true)); -$else$ -cst_$object.name$.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("$object.typecode.cppTypenameForTypeId$", false)); -$endif$ - - -cst_$object.name$.detail().name("$object.name$"); - -$if(object.annotationList)$ -$object.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | - { - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - \} - };separator="\n"$ - $endif$ - cst_$object.name$.detail().ann_custom().push_back(ann); -\} -}; separator="\n"$ -$endif$ - -type_object->complete().struct_type().member_seq().emplace_back(cst_$object.name$); - ->> - -get_type_identifier(ctx, type, ek) ::= <<$if(type.isSequenceType)$TypeObjectFactory::get_instance()->get_sequence_identifier($get_content_type(ctx=ctx, type=type.contentTypeCode)$, $type.maxsize$, $ek$)$elseif(type.isArrayType)$TypeObjectFactory::get_instance()->get_array_identifier($get_content_type(ctx=ctx, type=type.contentTypeCode)$, {$type.dimensions:{ dim |$dim$}; separator=", "$}, $ek$)$elseif(type.isSetType)$TypeObjectFactory::get_instance()->get_sequence_identifier($get_content_type(ctx=ctx, type=type.contentTypeCode)$, $type.maxsize$, $ek$)$elseif(type.isMapType)$TypeObjectFactory::get_instance()->get_map_identifier($get_content_type(ctx=ctx, type=type.keyTypeCode)$, $get_content_type(ctx=ctx, type=type.valueTypeCode)$, $type.maxsize$, $ek$)$elseif(type.isStringType)$TypeObjectFactory::get_instance()->get_string_identifier($type.maxsize$, false)$elseif(type.isWStringType)$TypeObjectFactory::get_instance()->get_string_identifier($type.maxsize$, true)$elseif(type.objectType)$Get$type.name$Identifier($ek$)$elseif(type.plainType)$TypeObjectFactory::get_instance()->get_type_identifier("$type.cppTypenameForTypeId$", false)$else$TypeObjectFactory::get_instance()->get_type_identifier("$type.cppTypenameForTypeId$", false)$endif$>> - -get_content_type(ctx, type) ::= <<$if(type.plainType)$$if(type.isSequenceType)$TypeNamesGenerator::get_sequence_type_name($get_content_type(ctx=ctx, type=type.contentTypeCode)$, $type.maxsize$)$elseif(type.isArrayType)$TypeNamesGenerator::get_array_type_name($get_content_type(ctx=ctx, type=type.contentTypeCode)$, {$type.dimensions:{ dim |$dim$}; separator=", "$})$elseif(type.isSetType)$TypeNamesGenerator::get_sequence_type_name($get_content_type(ctx=ctx, type=type.contentTypeCode)$, $type.maxsize$)$elseif(type.isMapType)$TypeNamesGenerator::get_map_type_name($get_content_type(ctx=ctx, type=type.keyTypeCode)$, $get_content_type(ctx=ctx, type=type.valueTypeCode)$, $type.maxsize$)$elseif(type.isStringType)$TypeNamesGenerator::get_string_type_name($type.maxsize$, false)$elseif(type.isWStringType)$TypeNamesGenerator::get_string_type_name($type.maxsize$, true)$else$"$type.cppTypenameForTypeId$"$endif$$else$"$type.cppTypenameForTypeId$"$endif$>> - -member_type(ctx, member, type_member, declarators) ::= << - -$type_member$ -$declarators$ - ->> - -union_type(ctx, parent, union, switch_type) ::= << -$switch_type$ -const TypeIdentifier* Get$union.name$Identifier(bool complete) -{ - const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$union.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$union.name$Object(complete); - return TypeObjectFactory::get_instance()->get_type_identifier("$union.name$", complete); -} - -const TypeObject* Get$union.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$union.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$union.name$Object(); - } - // else - return GetMinimal$union.name$Object(); -} - -const TypeObject* GetMinimal$union.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$union.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_UNION); - - type_object->minimal().union_type().union_flags().IS_FINAL(false); - type_object->minimal().union_type().union_flags().IS_APPENDABLE(false); - type_object->minimal().union_type().union_flags().IS_MUTABLE(false); - type_object->minimal().union_type().union_flags().IS_NESTED(false); - type_object->minimal().union_type().union_flags().IS_AUTOID_HASH(false); // Unsupported - - type_object->minimal().union_type().discriminator().common().member_flags().TRY_CONSTRUCT1(false); // Unsupported - type_object->minimal().union_type().discriminator().common().member_flags().TRY_CONSTRUCT2(false); // Unsupported - type_object->minimal().union_type().discriminator().common().member_flags().IS_EXTERNAL(false); // Doesn't apply - type_object->minimal().union_type().discriminator().common().member_flags().IS_OPTIONAL(false); // Doesn't apply - type_object->minimal().union_type().discriminator().common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply - type_object->minimal().union_type().discriminator().common().member_flags().IS_KEY(false); // Unsupported - type_object->minimal().union_type().discriminator().common().member_flags().IS_DEFAULT(false); // Doesn't apply - - type_object->minimal().union_type().discriminator().common().type_id(*$get_type_identifier(ctx=ctx, type=union.discriminator.typecode, ek="false")$); - - MemberId memberId = 0; - $union.members:{ member | $minimal_union_member_object_type(ctx=ctx, object=member, discriminator=union.discriminator.typecode)$}; separator="\n"$ - - // Header - //type_object->minimal().union_type().header().detail()... // Empty - - TypeIdentifier* identifier = new TypeIdentifier(); - identifier->_d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().union_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier->equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$union.name$", identifier, type_object); - delete type_object; - delete identifier; - return TypeObjectFactory::get_instance()->get_type_object("$union.name$", false); -} - -const TypeObject* GetComplete$union.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$union.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_UNION); - - type_object->complete().union_type().union_flags().IS_FINAL(false); - type_object->complete().union_type().union_flags().IS_APPENDABLE(false); - type_object->complete().union_type().union_flags().IS_MUTABLE(false); - type_object->complete().union_type().union_flags().IS_NESTED(false); - type_object->complete().union_type().union_flags().IS_AUTOID_HASH(false); // Unsupported - - type_object->complete().union_type().discriminator().common().member_flags().TRY_CONSTRUCT1(false); // Unsupported - type_object->complete().union_type().discriminator().common().member_flags().TRY_CONSTRUCT2(false); // Unsupported - type_object->complete().union_type().discriminator().common().member_flags().IS_EXTERNAL(false); // Doesn't apply - type_object->complete().union_type().discriminator().common().member_flags().IS_OPTIONAL(false); // Doesn't apply - type_object->complete().union_type().discriminator().common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply - type_object->complete().union_type().discriminator().common().member_flags().IS_KEY(false); // Unsupported - type_object->complete().union_type().discriminator().common().member_flags().IS_DEFAULT(false); // Doesn't apply - - type_object->complete().union_type().discriminator().common().type_id(*$get_type_identifier(ctx=ctx, type=union.discriminator.typecode, ek="true")$); - - $if(union.discriminator.typecode.annotationList)$ - $union.discriminator.typecode.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().union_type().discriminator().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - MemberId memberId = 0; - $union.members:{ member | $complete_union_member_object_type(ctx=ctx, object=member, discriminator=union.discriminator.typecode)$}; separator="\n"$ - - // Header - type_object->complete().union_type().header().detail().type_name("$union.name$"); - - $if(union.annotationList)$ - $union.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().union_type().header().detail().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - TypeIdentifier* identifier = new TypeIdentifier(); - identifier->_d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().union_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier->equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$union.name$", identifier, type_object); - delete type_object; - delete identifier; - return TypeObjectFactory::get_instance()->get_type_object("$union.name$", true); -} - ->> - -minimal_union_member_object_type(ctx, object, discriminator) ::= << -MinimalUnionMember mst_$object.name$; -mst_$object.name$.common().member_id(memberId++); -mst_$object.name$.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported -mst_$object.name$.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported -mst_$object.name$.common().member_flags().IS_EXTERNAL(false); // Unsupported -mst_$object.name$.common().member_flags().IS_OPTIONAL(false); // Doesn't apply -mst_$object.name$.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply -mst_$object.name$.common().member_flags().IS_KEY(false); // Doesn't apply -mst_$object.name$.common().member_flags().IS_DEFAULT($object.annotationDefault$); -$if(object.typecode.plainType)$ -mst_$object.name$.common().type_id(*$get_type_identifier(ctx=ctx, type=object.typecode, ek="false")$); -$elseif(object.typecode.objectType)$ -mst_$object.name$.common().type_id(*$if(object.typecode.hasScope)$$object.typecode.scope$::$endif$Get$object.typecode.name$Identifier(false)); -$else$ -mst_$object.name$.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("$object.typecode.cppTypenameForTypeId$", false)); -$endif$ - - -$if(object.labels)$ -$object.labels:{ label | mst_$object.name$.common().label_seq().emplace_back(static_cast($label$));}; separator="\n"$ -$endif$ - -MD5 $object.name$_hash("$object.name$"); -for(int i = 0; i < 4; ++i) -{ - mst_$object.name$.detail().name_hash()[i] = $object.name$_hash.digest[i]; -} -type_object->minimal().union_type().member_seq().emplace_back(mst_$object.name$); - ->> - -complete_union_member_object_type(ctx, object, discriminator) ::= << -CompleteUnionMember cst_$object.name$; -cst_$object.name$.common().member_id(memberId++); -cst_$object.name$.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported -cst_$object.name$.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported -cst_$object.name$.common().member_flags().IS_EXTERNAL(false); // Unsupported -cst_$object.name$.common().member_flags().IS_OPTIONAL(false); // Doesn't apply -cst_$object.name$.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply -cst_$object.name$.common().member_flags().IS_KEY(false); // Doesn't apply -cst_$object.name$.common().member_flags().IS_DEFAULT($object.annotationDefault$); -$if(object.typecode.plainType)$ -cst_$object.name$.common().type_id(*$get_type_identifier(ctx=ctx, type=object.typecode, ek="false")$); -$elseif(object.typecode.objectType)$ -cst_$object.name$.common().type_id(*$if(object.typecode.hasScope)$$object.typecode.scope$::$endif$Get$object.typecode.name$Identifier(true)); -$else$ -cst_$object.name$.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("$object.typecode.cppTypenameForTypeId$", false)); -$endif$ - -$if(object.labels)$ -$object.labels:{ label | cst_$object.name$.common().label_seq().emplace_back(static_cast($label$));}; separator="\n"$ -$endif$ - - -cst_$object.name$.detail().name("$object.name$"); - -$if(object.annotationList)$ -$object.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | - { - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - \} - };separator="\n"$ - $endif$ - cst_$object.name$.detail().ann_custom().push_back(ann); -\} -}; separator="\n"$ -$endif$ - -type_object->complete().union_type().member_seq().emplace_back(cst_$object.name$); - ->> - -bitmask_type(ctx, parent, bitmask) ::= << -const TypeIdentifier* Get$bitmask.name$Identifier(bool complete) -{ - const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$bitmask.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$bitmask.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$bitmask.name$", complete); -} - -const TypeObject* Get$bitmask.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitmask.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$bitmask.name$Object(); - } - // else - return GetMinimal$bitmask.name$Object(); -} - -const TypeObject* GetMinimal$bitmask.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitmask.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_BITMASK); - - type_object->minimal().bitmask_type().header().common().bit_bound($bitmask.bitBound$); - - $bitmask.bitmasks:{ member | $minimal_bitmask_flag(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().bitmask_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$bitmask.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$bitmask.name$", false); -} - -const TypeObject* GetComplete$bitmask.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitmask.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_BITMASK); - - // No flags apply - //type_object->complete().bitmask_type().bitmask_flags().IS_FINAL(false); - //type_object->complete().bitmask_type().bitmask_flags().IS_APPENDABLE(false); - //type_object->complete().bitmask_type().bitmask_flags().IS_MUTABLE(false); - //type_object->complete().bitmask_type().bitmask_flags().IS_NESTED(false); - //type_object->complete().bitmask_type().bitmask_flags().IS_AUTOID_HASH(false); - - type_object->complete().bitmask_type().header().common().bit_bound($bitmask.bitBound$); - - $if(bitmask.annotationList)$ - $bitmask.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().bitmask_type().header().detail().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - type_object->complete().bitmask_type().header().detail().type_name("$bitmask.name$"); - - $bitmask.members:{ member | $complete_bitmask_flag(ctx=ctx, object=member)$}; separator="\n"$ - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().bitmask_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$bitmask.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$bitmask.name$", true); -} - ->> - -minimal_bitmask_flag(ctx, object) ::= << -MinimalBitflag mbf_$object.name$; -mbf_$object.name$.common().flags().TRY_CONSTRUCT1(false); -mbf_$object.name$.common().flags().TRY_CONSTRUCT2(false); -mbf_$object.name$.common().flags().IS_EXTERNAL(false); -mbf_$object.name$.common().flags().IS_OPTIONAL(false); -mbf_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); -mbf_$object.name$.common().flags().IS_KEY(false); -mbf_$object.name$.common().flags().IS_DEFAULT(false); -mbf_$object.name$.common().position($object.position$); -MD5 $object.name$_hash("$object.name$"); -for(int i = 0; i < 4; ++i) -{ - mbf_$object.name$.detail().name_hash()[i] = $object.name$_hash.digest[i]; -} -type_object->minimal().bitmask_type().flag_seq().emplace_back(mbf_$object.name$); - ->> - -complete_bitmask_flag(ctx, object) ::= << -CompleteBitflag cbf_$object.name$; -cbf_$object.name$.common().flags().TRY_CONSTRUCT1(false); -cbf_$object.name$.common().flags().TRY_CONSTRUCT2(false); -cbf_$object.name$.common().flags().IS_EXTERNAL(false); -cbf_$object.name$.common().flags().IS_OPTIONAL(false); -cbf_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); -cbf_$object.name$.common().flags().IS_KEY(false); -cbf_$object.name$.common().flags().IS_DEFAULT(false); -cbf_$object.name$.common().position($object.position$); -cbf_$object.name$.detail().name("$object.name$"); - -// Position annotation always present -{ - AppliedAnnotation ann; - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("position")); - AppliedAnnotationParameter annParam; - MD5 message_hash("value"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - } - AnnotationParameterValue paramValue; - paramValue._d(TK_UINT16); - paramValue.uint_16_value($object.position$); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - - cbf_$object.name$.detail().ann_custom().push_back(ann); -} - -$if(object.annotationList)$ -$object.annotationList:{ ann | -{ - if (std::strcmp("position", "$ann.name$") != 0) - { - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | - { - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - \} - };separator="\n"$ - $endif$ - cbf_$object.name$.detail().ann_custom().push_back(ann); - \} -\} -}; separator="\n"$ -$endif$ - -type_object->complete().bitmask_type().flag_seq().emplace_back(cbf_$object.name$); - ->> - -bitset_type(ctx, parent, bitset, extensions) ::= << -const TypeIdentifier* Get$bitset.name$Identifier(bool complete) -{ - const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("$bitset.name$", complete); - if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) - { - return c_identifier; - } - - Get$bitset.name$Object(complete); // Generated inside - return TypeObjectFactory::get_instance()->get_type_identifier("$bitset.name$", complete); -} - -const TypeObject* Get$bitset.name$Object(bool complete) -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitset.name$", complete); - if (c_type_object != nullptr) - { - return c_type_object; - } - else if (complete) - { - return GetComplete$bitset.name$Object(); - } - // else - return GetMinimal$bitset.name$Object(); -} - -const TypeObject* GetMinimal$bitset.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitset.name$", false); - if (c_type_object != nullptr) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_MINIMAL); - type_object->minimal()._d(TK_BITSET); - - $bitset.bitfields:{ member | $minimal_bitfield(ctx=ctx, object=member)$}; separator="\n"$ - - $if(bitset.inheritance)$ - $minimal_bitset_inheritance(bitset.inheritance)$ - $endif$ - - TypeIdentifier identifier; - identifier._d(EK_MINIMAL); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->minimal().bitset_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$bitset.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$bitset.name$", false); -} - -const TypeObject* GetComplete$bitset.name$Object() -{ - const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("$bitset.name$", true); - if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) - { - return c_type_object; - } - - TypeObject *type_object = new TypeObject(); - type_object->_d(EK_COMPLETE); - type_object->complete()._d(TK_BITSET); - - // No flags apply - //type_object->complete().bitset_type().bitset_flags().IS_FINAL(false); - //type_object->complete().bitset_type().bitset_flags().IS_APPENDABLE(false); - //type_object->complete().bitset_type().bitset_flags().IS_MUTABLE(false); - //type_object->complete().bitset_type().bitset_flags().IS_NESTED(false); - //type_object->complete().bitset_type().bitset_flags().IS_AUTOID_HASH(false); - - $if(bitset.annotationList)$ - $bitset.annotationList:{ ann | -{ - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | -{ - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); -\} - };separator="\n"$ - $endif$ - type_object->complete().bitset_type().header().detail().ann_custom().push_back(ann); -\} - }; separator="\n"$ - $endif$ - - type_object->complete().bitset_type().header().detail().type_name("$bitset.name$"); - - $bitset.bitfields:{ member | $complete_bitfield(ctx=ctx, object=member)$}; separator="\n"$ - - $if(bitset.inheritance)$ - $complete_bitset_inheritance(bitset.inheritance)$ - $endif$ - - TypeIdentifier identifier; - identifier._d(EK_COMPLETE); - - eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1); - size_t current_alignment {0}; - SerializedPayload_t payload(static_cast( - calculator.calculate_serialized_size(type_object->complete().bitset_type(), current_alignment) + 4)); - eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); - // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) - eprosima::fastcdr::Cdr ser( - fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, - eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data. - payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - ser << *type_object; -#if FASTCDR_VERSION_MAJOR == 1 - payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length -#else - payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length -#endif // FASTCDR_VERSION_MAJOR == 1 - MD5 objectHash; - objectHash.update((char*)payload.data, payload.length); - objectHash.finalize(); - for(int i = 0; i < 14; ++i) - { - identifier.equivalence_hash()[i] = objectHash.digest[i]; - } - - TypeObjectFactory::get_instance()->add_type_object("$bitset.name$", &identifier, type_object); - delete type_object; - return TypeObjectFactory::get_instance()->get_type_object("$bitset.name$", true); -} - ->> - -minimal_bitfield(ctx, object) ::= << -$if(object.name)$ -MinimalBitfield mbf_$object.name$; -mbf_$object.name$.common().flags().TRY_CONSTRUCT1(false); -mbf_$object.name$.common().flags().TRY_CONSTRUCT2(false); -mbf_$object.name$.common().flags().IS_EXTERNAL(false); -mbf_$object.name$.common().flags().IS_OPTIONAL(false); -mbf_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); -mbf_$object.name$.common().flags().IS_KEY(false); -mbf_$object.name$.common().flags().IS_DEFAULT(false); -mbf_$object.name$.common().position($object.basePosition$); -mbf_$object.name$.common().bitcount($object.spec.bitSize$); -mbf_$object.name$.common().holder_type($object.spec.typecode.typeIdentifier$); -MD5 $object.name$_hash("$object.name$"); -for(int i = 0; i < 4; ++i) -{ - mbf_$object.name$.name_hash()[i] = $object.name$_hash.digest[i]; -} -type_object->minimal().bitset_type().field_seq().emplace_back(mbf_$object.name$); -$endif$ - ->> - -complete_bitfield(ctx, object) ::= << -$if(object.name)$ -CompleteBitfield cbf_$object.name$; -cbf_$object.name$.common().flags().TRY_CONSTRUCT1(false); -cbf_$object.name$.common().flags().TRY_CONSTRUCT2(false); -cbf_$object.name$.common().flags().IS_EXTERNAL(false); -cbf_$object.name$.common().flags().IS_OPTIONAL(false); -cbf_$object.name$.common().flags().IS_MUST_UNDERSTAND(false); -cbf_$object.name$.common().flags().IS_KEY(false); -cbf_$object.name$.common().flags().IS_DEFAULT(false); -cbf_$object.name$.common().position($object.basePosition$); -cbf_$object.name$.common().bitcount($object.spec.bitSize$); -cbf_$object.name$.common().holder_type($object.spec.typecode.typeIdentifier$); -cbf_$object.name$.detail().name("$object.name$"); - -// Position annotation always present -{ - // Position - AppliedAnnotation ann; - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("position")); - AppliedAnnotationParameter annParam; - MD5 message_hash("value"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - } - AnnotationParameterValue paramValue; - paramValue._d(TK_UINT16); - paramValue.uint_16_value($object.basePosition$); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - - cbf_$object.name$.detail().ann_custom().push_back(ann); -} - -// Use bit_bound as bitcount. -{ - // Position - AppliedAnnotation ann; - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("bit_bound")); - AppliedAnnotationParameter annParam; - MD5 message_hash("value"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - } - AnnotationParameterValue paramValue; - paramValue._d(TK_UINT16); - paramValue.uint_16_value($object.spec.bitSize$); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - - cbf_$object.name$.detail().ann_custom().push_back(ann); -} - -$if(object.annotationList)$ -$object.annotationList:{ ann | -{ - if (std::strcmp("position", "$ann.name$") != 0 && std::strcmp("bit_bound", "$ann.name$") != 0) - { - AppliedAnnotation ann; - //ann.annotation_typeid(Get$ann.name$Identifier(true)); - ann.annotation_typeid(*TypeObjectFactory::get_instance()->get_type_identifier_trying_complete("$ann.name$")); - $if(ann.valueList)$ - $ann.valueList:{ annval | - { - AppliedAnnotationParameter annParam; - MD5 message_hash("$annval.name$"); - for(int i = 0; i < 4; ++i) - { - annParam.paramname_hash()[i] = message_hash.digest[i]; - \} - AnnotationParameterValue paramValue; - paramValue._d($annval.typecode.typeIdentifier$); - paramValue.from_string("$annval.value$"); - annParam.value(paramValue); - ann.param_seq().push_back(annParam); - \} - };separator="\n"$ - $endif$ - cbf_$object.name$.detail().ann_custom().push_back(ann); - \} -\} -}; separator="\n"$ -$endif$ - -type_object->complete().bitset_type().field_seq().emplace_back(cbf_$object.name$); -$endif$ - ->> - -minimal_bitset_inheritance(parent) ::= << -type_object->minimal().bitset_type().header().base_type(*Get$parent.name$Identifier(false)); ->> - -complete_bitset_inheritance(parent) ::= << -type_object->complete().bitset_type().header().base_type(*Get$parent.name$Identifier(true)); ->> - -//{ Fast DDS-Gen extensions -module_conversion(ctx, parent, modules, definition_list) ::= << -$modules : { module | -namespace $module.name$ { -}; separator="\n"$ - -$definition_list$ - -$reverse(modules) : { module | -\} // namespace $module.name$ -}; separator="\n"$ ->> -//} diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg new file mode 100644 index 00000000..d67984e6 --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypeObjectTestingTestSource.stg @@ -0,0 +1,1437 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +group ProtocolHeader; + +import "eprosima.stg" + +main(ctx, definitions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObjectTestingTest.cpp"], description=["This file contains TypeObject test code."])$ + +#include +#include +#include +#include +#include +#include +#include +#include + +$ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$ + +#include "$ctx.filename$TypeObjectSupport.hpp" + +using ReturnCode_t = eprosima::fastdds::dds::ReturnCode_t; +using namespace eprosima::fastdds::dds::xtypes; + +class TypeObjectUtilsTest : public TypeObjectUtils +{ +public: + + static void type_identifier_consistency( + const TypeIdentifier& type_identifier) + { + TypeObjectUtils::type_identifier_consistency(type_identifier); + } + + static void complete_type_object_consistency( + const CompleteTypeObject& complete_type_object) + { + TypeObjectUtils::complete_type_object_consistency(complete_type_object); + } + +}; + +$definitions;separator="\n"$ + +int main( + int argc, + char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +>> + +fwd_decl(ctx, parent, type) ::= <<>> + +typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << +$declarator_type$ +$typedefs_type$ +$test_typedef(typedefs=typedefs)$ +>> + +struct_type(ctx, parent, struct, member_list) ::= << +namespace $struct.cScopedname$_namespace { +$member_list$ +} // $struct.cScopedname$_namespace +$test_structure(struct=struct)$ +>> + +union_type(ctx, parent, union, switch_type) ::= << +$switch_type$ +$test_union(union=union)$ +>> + +enum_type(ctx, parent, enum) ::= << +$test_enum(enum=enum)$ +>> + +bitmask_type(ctx, parent, bitmask) ::= << +$test_bitmask(bitmask=bitmask)$ +>> + +bitset_type(ctx, parent, bitset, extensions) ::= << +$test_bitset(bitset=bitset)$ +>> + +annotation(ctx, annotation) ::= << +$test_annotation(annotation=annotation)$ +>> + +module(ctx, parent, module, definition_list) ::= << +$definition_list$ +>> + +definition_list(definitions) ::= << +$definitions;separator="\n"$ +>> + +const_decl(ctx, parent, const, const_type) ::= << +$const_type$ +>> + +member_type(ctx, member, type_member, declarators) ::= << +$type_member$ +$declarators$ +>> + +element_type(ctx, element, type_element, declarator) ::= <<>> + +sequence_type(ctx, sequence, type_sequence) ::= << +$type_sequence$ +$test_sequence(sequence=sequence)$ +>> + +map_type(ctx, map, key_type, value_type) ::= << +namespace $map_name(map=map)$_namespace { +namespace key { +$key_type$ +} // namespace key +namespace value { +$value_type$ +} // namespace value +} // $map_name(map=map)$_namespace +$test_map(map=map)$ +>> + +string_type(ctx, string) ::= << +$test_string(string=string)$ +>> + +wide_string_type(ctx, wstring) ::= << +$test_wstring(wstring=wstring)$ +>> + +array_declarator(ctx, array) ::= << +$test_array(array=array)$ +>> + +get_type_identifier_registry(typename, result) ::= << +ret_code = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "$typename$", $result$); +ASSERT_EQ(eprosima::fastdds::dds::RETCODE_OK, ret_code); +EXPECT_NO_THROW(TypeObjectUtilsTest::type_identifier_consistency($result$.type_identifier1())); +if (TK_NONE != $result$.type_identifier2()._d()) +{ + EXPECT_NO_THROW(TypeObjectUtilsTest::type_identifier_consistency($result$.type_identifier2())); +} +else +{ + EXPECT_THROW(TypeObjectUtilsTest::type_identifier_consistency($result$.type_identifier2()), InvalidArgumentError); +} +>> + +get_type_object_registry(typename, result) ::= << +ret_code = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_objects( + "$typename$", $result$); +ASSERT_EQ(eprosima::fastdds::dds::RETCODE_OK, ret_code); +EXPECT_NO_THROW(TypeObjectUtilsTest::complete_type_object_consistency($result$.complete_type_object)); +>> + +get_type_identifier(type, var) ::= << +$if (type.isAliasType)$ +$get_type_identifier_registry(typename=type.scopedname, result=var)$ +$elseif (type.isByteType)$ +$get_type_identifier_registry(typename="_byte", result=var)$ +$elseif (type.primitive && !type.isEnumType)$ +$get_type_identifier_registry(typename=["_", type.cppTypenameForTypeId], result=var)$ +$elseif (type.isStringType)$ +$get_type_identifier_registry(typename=string_name(string=type), result=var)$ +$elseif (type.isWStringType)$ +$get_type_identifier_registry(typename=wstring_name(wstring=type), result=var)$ +$elseif (type.isArrayType)$ +$get_type_identifier_registry(typename=array_name(array=type), result=var)$ +$elseif (type.isSequenceType)$ +$get_type_identifier_registry(typename=sequence_name(sequence=type), result=var)$ +$elseif (type.isMapType)$ +$get_type_identifier_registry(typename=map_name(map=type), result=var)$ +$else$ +$get_type_identifier_registry(typename=type.scopedname, result=var)$ +$endif$ +>> + +check_type_detail_annotations(object, type) ::= << +$if(object.annotationList)$ +bool verbatim_annotation = false; +bool custom_annotations = false; +$object.annotationList: { annotation | +$if(annotation.isVerbatim)$ +verbatim_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().verbatim().has_value()); +$annotation.valueList : { verbatim_param | +bool placement_applied = false; +bool language_applied = false; +$if(verbatim_param.isVerbatimPlacement)$ +placement_applied = true; +EXPECT_EQ($verbatim_param.enumStringValue$, type_objects.complete_type_object.$type$.ann_builtin().value().verbatim.value().placement()); +$elseif(verbatim_param.isVerbatimLanguage)$ +language_applied = true; +EXPECT_EQ("$verbatim_param.value$", type_objects.complete_type_object.$type$.ann_builtin().value().verbatim.value().language()); +$elseif(verbatim_param.isVerbatimText)$ +EXPECT_EQ("$verbatim_param.value$", type_objects.complete_type_object.$type$.ann_builtin().value().verbatim.value().text()); +$endif$ +}; separator="\n"$ +if (!placement_applied) +{ + EXPECT_EQ(PlacementKindValue::BEFORE_DECLARATION, type_objects.complete_type_object.$type$.ann_builtin().value().verbatim.value().placement()); +\} +if (!language_applied) +{ + EXPECT_EQ("*", type_objects.complete_type_object.$type$.ann_builtin().value().verbatim.value().language()); +\} +$elseif(!annotation.isBuiltin)$ +custom_annotations = true; +$check_applied_custom_annotations(annotation=annotation, type=type)$ +for (size_t i = 1; i < type_objects.complete_type_object.$type$.ann_custom().value().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.$type$.ann_custom().value()[i-1].annotation_typeid().equivalence_hash(), + type_objects.complete_type_object.$type$.ann_custom().value()[i].annotation_typeid().equivalence_hash()); +\} +$endif$ +}; separator="\n"$ +if (!verbatim_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +} +if (!custom_annotations) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_custom().has_value()); +} +$else$ +EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_custom().has_value()); +$endif$ +>> + +check_applied_custom_annotations(annotation, type) ::= << +TypeIdentifierPair annotation_type_ids; +$get_type_identifier_registry(typename=annotation.scopedname, result="annotation_type_ids")$ +$check_direct_hash_type_identifier(typeid="annotation_type_ids")$ +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_custom().has_value()); +{ + size_t pos = 0; + bool found = false; + for(; pos < type_objects.complete_type_object.$type$.ann_custom().value().size(); ++pos) + { + if (annotation_type_ids.type_identifier1() == type_objects.complete_type_object.$type$.ann_custom().value()[pos].annotation_typeid() || + annotation_type_ids.type_identifier2() == type_objects.complete_type_object.$type$.ann_custom().value()[pos].annotation_typeid()) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + EXPECT_TRUE(annotation_type_ids.type_identifier1() == type_objects.complete_type_object.$type$.ann_custom().value()[pos].annotation_typeid() || + annotation_type_ids.type_identifier2() == type_objects.complete_type_object.$type$.ann_custom().value()[pos].annotation_typeid()); + $if (annotation.valueList)$ + ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().has_value()); + EXPECT_EQ($annotation.valuesSize$, type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value().size()); + for (size_t i = 1; i < type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value().size(); ++i) + { + EXPECT_LT(type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value()[i-1].paramname_hash(), + type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value()[i].paramname_hash()); + } + $annotation.valueList : { annotation_parameter | + $check_annotation_parameter(param=annotation_parameter, type=type)$ + }; separator="\n"$ + $else$ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().has_value()); + $endif$ +} +>> + +check_annotation_parameter(param, type) ::= << +{ + NameHash param_name_hash = TypeObjectUtils::name_hash("$param.name$"); + size_t pos_ = 0; + bool found_ = false; + for (; pos_ < type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value().size(); ++pos_) + { + if (param_name_hash == type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value()[pos_].paramname_hash()) + { + found_ = true; + break; + } + } + ASSERT_TRUE(found_); + EXPECT_EQ(param_name_hash, type_objects.complete_type_object.$type$.ann_custom().value()[pos].param_seq().value()[pos_].paramname_hash()); + $check_annotation_parameter_value(param=param, type=["complete_type_object.", type, ".ann_custom().value()[pos].param_seq().value()[pos_].value()"])$ +} +>> + +check_annotation_parameter_value(param, type) ::= << +$if (param.typecode.primitiveType)$ +$if (param.typecode.isBooleanType)$ +EXPECT_EQ(TK_BOOLEAN, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.boolean_value()); +$elseif (param.typecode.isByteType)$ +EXPECT_EQ(TK_BYTE, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.byte_value()); +$elseif (param.typecode.isInt8Type)$ +EXPECT_EQ(TK_INT8, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.int8_value()); +$elseif (param.typecode.isUint8Type)$ +EXPECT_EQ(TK_UINT8, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.uint8_value()); +$elseif (param.typecode.isInt16Type)$ +EXPECT_EQ(TK_INT16, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.int16_value()); +$elseif (param.typecode.isUint16Type)$ +EXPECT_EQ(TK_UINT16, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.uint_16_value()); +$elseif (param.typecode.isInt32Type)$ +EXPECT_EQ(TK_INT32, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.int32_value()); +$elseif (param.typecode.isUint32Type)$ +EXPECT_EQ(TK_UINT32, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.uint32_value()); +$elseif (param.typecode.isInt64Type)$ +EXPECT_EQ(TK_INT64, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.int64_value()); +$elseif (param.typecode.isUint64Type)$ +EXPECT_EQ(TK_UINT64, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.uint64_value()); +$elseif (param.typecode.isFloat32Type)$ +EXPECT_EQ(TK_FLOAT32, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.float32_value()); +$elseif (param.typecode.isFloat64Type)$ +EXPECT_EQ(TK_FLOAT64, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.float64_value()); +$elseif (param.typecode.isFloat128Type)$ +EXPECT_EQ(TK_FLOAT128, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.float128_value()); +$elseif (param.typecode.isCharType)$ +EXPECT_EQ(TK_CHAR8, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.char_value()); +$elseif (param.typecode.isWCharType)$ +EXPECT_EQ(TK_CHAR16, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.wchar_value()); +$endif$ +$elseif (param.typecode.isEnumType)$ +EXPECT_EQ(TK_ENUM, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.enumerated_value()); +$elseif (param.typecode.isStringType)$ +EXPECT_EQ(TK_STRING8, type_objects.$type$._d()); +EXPECT_EQ("$param.value$", type_objects.$type$.string8_value().to_string()); +$elseif (param.typecode.isWStringType)$ +EXPECT_EQ(TK_STRING16, type_objects.$type$._d()); +EXPECT_EQ($param.value$, type_objects.$type$.string16_value()); +$endif$ +>> + +check_member_detail_annotations(member, type, parent) ::= << +$if(member.annotationList)$ +bool unit_annotation = false; +bool min_annotation = false; +bool max_annotation = false; +bool hash_id_annotation = false; +bool custom_annotations = false; +$member.annotationList : { annotation | +$if(annotation.isUnit)$ +unit_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().unit().has_value()); +EXPECT_EQ($annotation.value$, type_objects.complete_type_object.$type$.ann_builtin().value().unit().value()) +$elseif(annotation.isMin)$ +EXPECT_FALSE(min_annotation); +min_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().min().has_value()); +$check_annotation_parameter_value(param=annotation, type=["complete_type_object.", type, ".ann_builtin().value().min().value()"])$ +$elseif(annotation.isMax)$ +EXPECT_FALSE(max_annotation); +max_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().max().has_value()); +$check_annotation_parameter_value(param=annotation, type=["complete_type_object.", type, ".ann_builtin().value().max().value()"])$ +$elseif(annotation.isRange)$ +$annotation.valueList : { range_param | +$if(range_param.isMin)$ +EXPECT_FALSE(min_annotation); +min_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().min().has_value()); +$check_annotation_parameter_value(param=range_param, type=["complete_type_object.", type, ".ann_builtin().value().min().value()"])$ +$elseif(range_param.isMax)$ +EXPECT_FALSE(max_annotation); +max_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().max().has_value()); +$check_annotation_parameter_value(param=range_param, type=["complete_type_object.", type, ".ann_builtin().value().max().value()"])$ +$endif$ +}; separator=""$ +$elseif(annotation.isHashId)$ +hash_id_annotation = true; +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +ASSERT_TRUE(type_objects.complete_type_object.$type$.ann_builtin().value().hash_id().has_value()); +EXPECT_EQ("$annotation.value$", type_objects.complete_type_object.$type$.ann_builtin().value().hash_id().value()); +$elseif(!annotation.isBuiltin && !parent.isAliasType)$ +custom_annotations = true; +$check_applied_custom_annotations(annotation=annotation, type=type)$ +$endif$ +}; separator="\n"$ +if (!unit_annotation && !max_annotation && !min_annotation && !hash_id_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +} +else if (!unit_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().value().unit().has_value()); +} +else if (!min_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().value().min().has_value()); +} +else if (!max_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().value().max().has_value()); +} +else if (!hash_id_annotation) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().value().hash_id().has_value()); +} +if (!custom_annotations) +{ + EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_custom().has_value()); +} +$else$ +EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_builtin().has_value()); +EXPECT_FALSE(type_objects.complete_type_object.$type$.ann_custom().has_value()); +$endif$ +>> + +expected_member_flags(object, typename) ::= << +MemberFlag $typename$_expected_flags = 0; +$if(object.annotationTryConstruct)$ +$if(object.annotationDiscard)$ +$typename$_expected_flags |= MemberFlagBits::TRY_CONSTRUCT1; +$elseif(object.annotationUseDefault)$ +$typename$_expected_flags |= MemberFlagBits::TRY_CONSTRUCT2; +$elseif(object.annotationTrim)$ +$typename$_expected_flags |= MemberFlagBits::TRY_CONSTRUCT1 | MemberFlagBits::TRY_CONSTRUCT2; +$endif$ +$endif$ +$if(object.annotationExternal)$ +$typename$_expected_flags |= MemberFlagBits::IS_EXTERNAL; +$endif$ +$if(object.annotationOptional)$ +$typename$_expected_flags |= MemberFlagBits::IS_OPTIONAL; +$endif$ +$if(object.annotationMustUnderstand)$ +$typename$_expected_flags |= MemberFlagBits::IS_MUST_UNDERSTAND; +$endif$ +$if(object.annotationKey)$ +$typename$_expected_flags |= MemberFlagBits::IS_KEY; +$endif$ +$if(object.annotationDefaultLiteral)$ +$typename$_expected_flags |= MemberFlagBits::IS_DEFAULT; +$endif$ +>> + +expected_type_flags(object) ::= << +TypeFlag $object.name$_expected_flags = 0; +$if(!object.annotationExtensibilityNotApplied)$ +$if(object.annotationFinal)$ +$object.name$_expected_flags |= TypeFlagBits::IS_FINAL; +$elseif(object.annotationAppendable)$ +$object.name$_expected_flags |= TypeFlagBits::IS_APPENDABLE; +$elseif(object.annotationMutable)$ +$object.name$_expected_flags |= TypeFlagBits::IS_MUTABLE; +$endif$ +$endif$ +$if(object.annotationNested)$ +$object.name$_expected_flags |= TypeFlagBits::IS_NESTED; +$endif$ +$if(object.annotationAutoidHash)$ +$object.name$_expected_flags |= TypeFlagBits::IS_AUTOID_HASH; +$endif$ +>> + +test_typedef(typedefs) ::= << +TEST(TypeObjectTests, TestTypedefTypeObject_$typedefs.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_alias_type(typedefs=typedefs)$ +} +>> + +check_alias_type(typedefs) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=typedefs.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=typedefs.scopedname, result="type_objects")$ +EXPECT_EQ(TK_ALIAS, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_ALIAS, type_objects.complete_type_object._d()); +EXPECT_EQ(0u, type_objects.minimal_type_object.alias_type().alias_flags()); +EXPECT_EQ(0u, type_objects.complete_type_object.alias_type().alias_flags()); +$check_type_detail_annotations(object=typedefs, type="alias_type().header().detail()")$ +EXPECT_EQ("$typedefs.scopedname$", type_objects.complete_type_object.alias_type().header().detail().type_name().to_string()); +EXPECT_EQ(0u, type_objects.minimal_type_object.alias_type().body().common().related_flags()); +EXPECT_EQ(0u, type_objects.complete_type_object.alias_type().body().common().related_flags()); +TypeIdentifierPair related_type_ids; +$get_type_identifier(type=typedefs.typedefContentTypeCode, var="related_type_ids")$ +EXPECT_TRUE(related_type_ids.type_identifier1() == type_objects.minimal_type_object.alias_type().body().common().related_type() || + related_type_ids.type_identifier2() == type_objects.minimal_type_object.alias_type().body().common().related_type()); +EXPECT_TRUE(related_type_ids.type_identifier1() == type_objects.complete_type_object.alias_type().body().common().related_type() || + related_type_ids.type_identifier2() == type_objects.complete_type_object.alias_type().body().common().related_type()); +$check_member_detail_annotations(member=typedefs, type="alias_type().body()", parent=typedefs)$ +>> + +test_structure(struct) ::= << +TEST(TypeObjectTests, TestStructureTypeObject_$struct.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_struct_type(struct=struct)$ +} +>> + +check_struct_type(struct) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=struct.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=struct.scopedname, result="type_objects")$ +EXPECT_EQ(TK_STRUCTURE, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_STRUCTURE, type_objects.complete_type_object._d()); +$expected_type_flags(object=struct)$ +EXPECT_EQ($struct.name$_expected_flags, type_objects.minimal_type_object.struct_type().struct_flags()); +EXPECT_EQ($struct.name$_expected_flags, type_objects.complete_type_object.struct_type().struct_flags()); +$if(struct.inheritance)$ +TypeIdentifierPair base_type_ids; +$get_type_identifier_registry(typename=struct.inheritance.scopedname, result="base_type_ids")$ +$check_direct_hash_type_identifier(typeid="base_type_ids")$ +EXPECT_TRUE(base_type_ids.type_identifier1() == type_objects.minimal_type_object.struct_type().header().base_type() || + base_type_ids.type_identifier1() == type_objects.complete_type_object.struct_type().header().base_type()); +EXPECT_TRUE(base_type_ids.type_identifier2() == type_objects.minimal_type_object.struct_type().header().base_type() || + base_type_ids.type_identifier2() == type_objects.complete_type_object.struct_type().header().base_type()); +TypeObjectPair base_type_objects; +$get_type_object_registry(typename=struct.inheritance.scopedname, result="base_type_objects")$ +$else$ +TypeIdentifier invalid_type_id; +EXPECT_EQ(invalid_type_id, type_objects.minimal_type_object.struct_type().header().base_type()); +EXPECT_EQ(invalid_type_id, type_objects.complete_type_object.struct_type().header().base_type()); +$endif$ +$check_type_detail_annotations(object=struct, type="struct_type().header().detail()")$ +EXPECT_EQ("$struct.scopedname$", type_objects.complete_type_object.struct_type().header().detail().type_name().to_string()); +$if (struct.members)$ +MemberId member_id = 0; +$if (struct.inheritance)$ + member_id = $struct.firstMember.id$; +$endif$ +$struct.members: { member | $check_struct_member(member=member, parent=struct)$}; separator="\n"$ +$endif$ +ASSERT_EQ($struct.membersSize$, type_objects.minimal_type_object.struct_type().member_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.struct_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.struct_type().member_seq()[i-1].common().member_id(), + type_objects.minimal_type_object.struct_type().member_seq()[i].common().member_id()); +} +ASSERT_EQ($struct.membersSize$, type_objects.complete_type_object.struct_type().member_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.struct_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.struct_type().member_seq()[i-1].common().member_id(), + type_objects.complete_type_object.struct_type().member_seq()[i].common().member_id()); +} +>> + +check_struct_member(member, parent) ::= << +{ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.struct_type().member_seq().size(); ++pos) + { + if (strcmp("$member.name$", type_objects.complete_type_object.struct_type().member_seq()[pos].detail().name()) == 0) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + NameHash member_name_hashed = TypeObjectUtils::name_hash("$member.name$"); + $if(member.annotationId)$ + member_id = $member.annotationIdValue$; + $elseif(member.annotationHashid)$ + std::string hashid_annotation_value("$member.annotationHashidValue$"); + if (hashid_annotation_value.empty()) + { + member_id = (member_name_hashed[3] << 24 | member_name_hashed[2] << 16 | member_name_hashed[1] << 8 | + member_name_hashed[0]) & 0x0FFFFFFF; + } + else + { + NameHash value_hash_id = TypeObjectUtils::name_hash("$member.annotationHashidValue$"); + member_id = (value_hash_id[3] << 24 | value_hash_id[2] << 16 | value_hash_id[1] << 8 | + value_hash_id[0]) & 0x0FFFFFFF; + } + $elseif(parent.annotationAutoidHash)$ + member_id = (member_name_hashed[3] << 24 | member_name_hashed[2] << 16 | member_name_hashed[1] << 8 | + member_name_hashed[0]) & 0x0FFFFFFF; + $endif$ + EXPECT_EQ(member_id, type_objects.minimal_type_object.struct_type().member_seq()[pos].common().member_id()); + EXPECT_EQ(member_id, type_objects.complete_type_object.struct_type().member_seq()[pos].common().member_id()); + member_id++; + $expected_member_flags(object=member, typename=member.name)$ + EXPECT_EQ($member.name$_expected_flags, type_objects.minimal_type_object.struct_type().member_seq()[pos].common().member_flags()); + EXPECT_EQ($member.name$_expected_flags, type_objects.complete_type_object.struct_type().member_seq()[pos].common().member_flags()); + TypeIdentifierPair member_type_ids; + $get_type_identifier(type=member.typecode, var="member_type_ids")$ + if (TK_NONE != member_type_ids.type_identifier2()._d()) + { + EXPECT_TRUE(member_type_ids.type_identifier1() == type_objects.minimal_type_object.struct_type().member_seq()[pos].common().member_type_id() || + member_type_ids.type_identifier1() == type_objects.complete_type_object.struct_type().member_seq()[pos].common().member_type_id()); + EXPECT_TRUE(member_type_ids.type_identifier2() == type_objects.minimal_type_object.struct_type().member_seq()[pos].common().member_type_id() || + member_type_ids.type_identifier2() == type_objects.complete_type_object.struct_type().member_seq()[pos].common().member_type_id()); + } + else + { + EXPECT_EQ(member_type_ids.type_identifier1(), type_objects.minimal_type_object.struct_type().member_seq()[pos].common().member_type_id()); + EXPECT_EQ(member_type_ids.type_identifier1(), type_objects.complete_type_object.struct_type().member_seq()[pos].common().member_type_id()); + } + EXPECT_EQ("$member.name$", type_objects.complete_type_object.struct_type().member_seq()[pos].detail().name().to_string()); + EXPECT_EQ(member_name_hashed, type_objects.minimal_type_object.struct_type().member_seq()[pos].detail().name_hash()); + $check_member_detail_annotations(member=member, type="struct_type().member_seq()[pos].detail()", parent=parent)$ +} +>> + +test_union(union) ::= << +TEST(TypeObjectTests, TestUnionTypeObject_$union.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_union_type(union=union)$ +} +>> + +check_union_type(union) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=union.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=union.scopedname, result="type_objects")$ +EXPECT_EQ(TK_UNION, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_UNION, type_objects.complete_type_object._d()); +$expected_type_flags(object=union)$ +EXPECT_EQ($union.name$_expected_flags, type_objects.minimal_type_object.union_type().union_flags()); +EXPECT_EQ($union.name$_expected_flags, type_objects.complete_type_object.union_type().union_flags()); +$check_type_detail_annotations(object=union, type="union_type().header().detail()")$ +EXPECT_EQ("$union.scopedname$", type_objects.complete_type_object.union_type().header().detail().type_name().to_string()); +$expected_member_flags(object=union.discriminator, typename=union.discriminator.name)$ +EXPECT_EQ($union.discriminator.name$_expected_flags, type_objects.minimal_type_object.union_type().discriminator().common().member_flags()); +EXPECT_EQ($union.discriminator.name$_expected_flags, type_objects.complete_type_object.union_type().discriminator().common().member_flags()); +TypeIdentifierPair discriminator_type_ids; +$if(union.discriminator.typecode.primitive && !union.discriminator.typecode.isEnumType && !union.discriminator.typecode.isAliasType)$ +$if (union.discriminator.typecode.isByteType)$ +$get_type_identifier_registry(typename="_byte", result="discriminator_type_ids")$ +$else$ +$get_type_identifier_registry(typename=["_", union.discriminator.typecode.cppTypenameForTypeId], result="discriminator_type_ids")$ +$endif$ +$else$ +$get_type_identifier_registry(typename=union.discriminator.typecode.scopedname, result="discriminator_type_ids")$ +$endif$ +EXPECT_TRUE(discriminator_type_ids.type_identifier1() == type_objects.minimal_type_object.union_type().discriminator().common().type_id() || + discriminator_type_ids.type_identifier1() == type_objects.complete_type_object.union_type().discriminator().common().type_id()); +if (TK_NONE == discriminator_type_ids.type_identifier2()._d()) +{ + EXPECT_EQ(type_objects.minimal_type_object.union_type().discriminator().common().type_id(), + type_objects.complete_type_object.union_type().discriminator().common().type_id()); +} +else +{ + EXPECT_TRUE(discriminator_type_ids.type_identifier2() == type_objects.minimal_type_object.union_type().discriminator().common().type_id() || + discriminator_type_ids.type_identifier2() == type_objects.complete_type_object.union_type().discriminator().common().type_id()); +} +$check_type_detail_annotations(object=union.discriminator, type="union_type().discriminator()")$ +MemberId member_id = 0; +$union.members: { member | $check_union_member(member=member, parent=union)$}; separator="\n"$ +ASSERT_EQ($union.membersSize$, type_objects.minimal_type_object.union_type().member_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.union_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.union_type().member_seq()[i-1].common().member_id(), + type_objects.minimal_type_object.union_type().member_seq()[i].common().member_id()); +} +ASSERT_EQ($union.membersSize$, type_objects.complete_type_object.union_type().member_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.union_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.union_type().member_seq()[i-1].common().member_id(), + type_objects.complete_type_object.union_type().member_seq()[i].common().member_id()); +} +>> + +check_union_member(member, parent) ::= << +{ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.union_type().member_seq().size(); ++pos) + { + if (strcmp("$member.name$", type_objects.complete_type_object.union_type().member_seq()[pos].detail().name()) == 0) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + NameHash member_name_hashed = TypeObjectUtils::name_hash("$member.name$"); + $if(member.annotationId)$ + member_id = $member.annotationIdValue$; + $elseif(member.annotationHashid)$ + $if (member.annotationHashidValue)$ + NameHash value_hash_id = TypeObjectUtils::name_hash("$member.annotationHashidValue$"); + member_id = (value_hash_id[3] << 24 | value_hash_id[2] << 16 | value_hash_id[1] << 8 | + value_hash_id[0]) & 0x0FFFFFFF; + $else$ + member_id = (member_name_hashed[3] << 24 | member_name_hashed[2] << 16 | member_name_hashed[1] << 8 | + member_name_hashed[0]) & 0x0FFFFFFF; + $endif$ + $elseif(member.annotationHashid)$ + member_id = (member_name_hashed[3] << 24 | member_name_hashed[2] << 16 | member_name_hashed[1] << 8 | + member_name_hashed[0]) & 0x0FFFFFFF; + $endif$ + EXPECT_EQ(member_id, type_objects.minimal_type_object.union_type().member_seq()[pos].common().member_id()); + EXPECT_EQ(member_id, type_objects.complete_type_object.union_type().member_seq()[pos].common().member_id()); + member_id++; + $expected_member_flags(object=member, typename=member.name)$ + $if (member.default)$ + $member.name$_expected_flags |= MemberFlagBits::IS_DEFAULT; + $endif$ + EXPECT_EQ($member.name$_expected_flags, type_objects.minimal_type_object.union_type().member_seq()[pos].common().member_flags()); + EXPECT_EQ($member.name$_expected_flags, type_objects.complete_type_object.union_type().member_seq()[pos].common().member_flags()); + TypeIdentifierPair member_type_ids; + $get_type_identifier(type=member.typecode, var="member_type_ids")$ + EXPECT_TRUE(member_type_ids.type_identifier1() == type_objects.minimal_type_object.union_type().member_seq()[pos].common().type_id() || + member_type_ids.type_identifier1() == type_objects.complete_type_object.union_type().member_seq()[pos].common().type_id()); + if (TK_NONE == member_type_ids.type_identifier2()._d()) + { + EXPECT_EQ(type_objects.minimal_type_object.union_type().member_seq()[pos].common().type_id(), + type_objects.complete_type_object.union_type().member_seq()[pos].common().type_id()); + } + else + { + EXPECT_TRUE(member_type_ids.type_identifier2() == type_objects.minimal_type_object.union_type().member_seq()[pos].common().type_id() || + member_type_ids.type_identifier2() == type_objects.complete_type_object.union_type().member_seq()[pos].common().type_id()); + } + $member.labels: { label | $check_label(label=label)$}; separator="\n"$ + ASSERT_EQ($member.labelsSize$, type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq().size()); + for (size_t i = 1; i < type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq().size(); ++i) + { + EXPECT_LT(type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq()[i-1], + type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq()[i]); + } + ASSERT_EQ($member.labelsSize$, type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq().size()); + for (size_t i = 1; i < type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq().size(); ++i) + { + EXPECT_LT(type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq()[i-1], + type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq()[i]); + } + EXPECT_EQ("$member.name$", type_objects.complete_type_object.union_type().member_seq()[pos].detail().name().to_string()); + EXPECT_EQ(member_name_hashed, type_objects.minimal_type_object.union_type().member_seq()[pos].detail().name_hash()); + $check_member_detail_annotations(member=member, type="union_type().member_seq()[pos].detail()", parent=parent)$ +} +>> + +check_label(label) ::= << +{ + EXPECT_NE(std::find(type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq().begin(), + type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq().end(), static_cast($label$)), + type_objects.complete_type_object.union_type().member_seq()[pos].common().label_seq().end()); + EXPECT_NE(std::find(type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq().begin(), + type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq().end(), static_cast($label$)), + type_objects.minimal_type_object.union_type().member_seq()[pos].common().label_seq().end()); +} +>> + +test_enum(enum) ::= << +TEST(TypeObjectTests, TestEnumTypeObject_$enum.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_enum_type(enum=enum)$ +} +>> + +check_enum_type(enum) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=enum.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=enum.scopedname, result="type_objects")$ +EXPECT_EQ(TK_ENUM, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_ENUM, type_objects.complete_type_object._d()); +EXPECT_EQ(0u, type_objects.minimal_type_object.enumerated_type().enum_flags()); +EXPECT_EQ(0u, type_objects.complete_type_object.enumerated_type().enum_flags()); +EXPECT_EQ($enum.bitBound$, type_objects.minimal_type_object.enumerated_type().header().common().bit_bound()); +EXPECT_EQ($enum.bitBound$, type_objects.complete_type_object.enumerated_type().header().common().bit_bound()); +$check_type_detail_annotations(object=enum, type="enumerated_type().header().detail()")$ +EXPECT_EQ("$enum.scopedname$", type_objects.complete_type_object.enumerated_type().header().detail().type_name().to_string()); +int32_t enum_literal_id = 0; +$enum.members: { member | $check_enum_literal(literal=member, parent=enum)$}; separator="\n"$ +ASSERT_EQ($enum.membersSize$, type_objects.minimal_type_object.enumerated_type().literal_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.enumerated_type().literal_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.enumerated_type().literal_seq()[i-1].common().value(), + type_objects.minimal_type_object.enumerated_type().literal_seq()[i].common().value()); +} +ASSERT_EQ($enum.membersSize$, type_objects.complete_type_object.enumerated_type().literal_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.enumerated_type().literal_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.enumerated_type().literal_seq()[i-1].common().value(), + type_objects.complete_type_object.enumerated_type().literal_seq()[i].common().value()); +} +>> + +check_enum_literal(literal, parent) ::= << +{ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.enumerated_type().literal_seq().size(); ++pos) + { + if (strcmp("$literal.name$", type_objects.complete_type_object.enumerated_type().literal_seq()[pos].detail().name()) == 0) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + $if (literal.annotationValue)$ + EXPECT_EQ($literal.annotationValueValue$, type_objects.complete_type_object.enumerated_type().literal_seq()[pos].common().value()); + EXPECT_EQ($literal.annotationValueValue$, type_objects.minimal_type_object.enumerated_type().literal_seq()[pos].common().value()); + enum_literal_id = $literal.annotationValueValue$; + $else$ + EXPECT_EQ(enum_literal_id, type_objects.complete_type_object.enumerated_type().literal_seq()[pos].common().value()); + EXPECT_EQ(enum_literal_id, type_objects.minimal_type_object.enumerated_type().literal_seq()[pos].common().value()); + $endif$ + $expected_member_flags(object=literal, typename=literal.name)$ + EXPECT_EQ($literal.name$_expected_flags, type_objects.minimal_type_object.enumerated_type().literal_seq()[pos].common().flags()); + EXPECT_EQ($literal.name$_expected_flags, type_objects.complete_type_object.enumerated_type().literal_seq()[pos].common().flags()); + EXPECT_EQ("$literal.name$", type_objects.complete_type_object.enumerated_type().literal_seq()[pos].detail().name().to_string()); + EXPECT_EQ(TypeObjectUtils::name_hash("$literal.name$"), type_objects.minimal_type_object.enumerated_type().literal_seq()[pos].detail().name_hash()); + $check_member_detail_annotations(member=literal, type="enumerated_type().literal_seq()[pos].detail()", parent=parent)$ + enum_literal_id++; +} +>> + +test_bitmask(bitmask) ::= << +TEST(TypeObjectTests, TestBitmaskTypeObject_$bitmask.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_bitmask_type(bitmask=bitmask)$ +} +>> + +check_bitmask_type(bitmask) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=bitmask.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=bitmask.scopedname, result="type_objects")$ +EXPECT_EQ(TK_BITMASK, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_BITMASK, type_objects.complete_type_object._d()); +EXPECT_EQ(0u, type_objects.minimal_type_object.bitmask_type().bitmask_flags()); +EXPECT_EQ(0u, type_objects.complete_type_object.bitmask_type().bitmask_flags()); +EXPECT_EQ($bitmask.bitBound$, type_objects.minimal_type_object.bitmask_type().header().common().bit_bound()); +EXPECT_EQ($bitmask.bitBound$, type_objects.complete_type_object.bitmask_type().header().common().bit_bound()); +$check_type_detail_annotations(object=bitmask, type="bitmask_type().header().detail()")$ +EXPECT_EQ("$bitmask.scopedname$", type_objects.complete_type_object.bitmask_type().header().detail().type_name().to_string()); +$bitmask.members: { member | $check_bitmask_flag(bitflag=member, parent=bitmask)$}; separator="\n"$ +ASSERT_EQ($bitmask.membersSize$, type_objects.minimal_type_object.bitmask_type().flag_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.bitmask_type().flag_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.bitmask_type().flag_seq()[i-1].common().position(), + type_objects.minimal_type_object.bitmask_type().flag_seq()[i].common().position()); +} +ASSERT_EQ($bitmask.membersSize$, type_objects.complete_type_object.bitmask_type().flag_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.bitmask_type().flag_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.bitmask_type().flag_seq()[i-1].common().position(), + type_objects.complete_type_object.bitmask_type().flag_seq()[i].common().position()); +} +>> + +check_bitmask_flag(bitflag, parent) ::= << +{ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.bitmask_type().flag_seq().size(); ++pos) + { + if (strcmp("$bitflag.name$", type_objects.complete_type_object.bitmask_type().flag_seq()[pos].detail().name()) == 0) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + EXPECT_EQ($bitflag.position$, type_objects.minimal_type_object.bitmask_type().flag_seq()[pos].common().position()); + EXPECT_EQ($bitflag.position$, type_objects.complete_type_object.bitmask_type().flag_seq()[pos].common().position()); + EXPECT_EQ(0u, type_objects.minimal_type_object.bitmask_type().flag_seq()[pos].common().flags()); + EXPECT_EQ(0u, type_objects.complete_type_object.bitmask_type().flag_seq()[pos].common().flags()); + EXPECT_EQ("$bitflag.name$", type_objects.complete_type_object.bitmask_type().flag_seq()[pos].detail().name().to_string()); + EXPECT_EQ(TypeObjectUtils::name_hash("$bitflag.name$"), type_objects.minimal_type_object.bitmask_type().flag_seq()[pos].detail().name_hash()); + $check_member_detail_annotations(member=bitflag, type="bitmask_type().flag_seq()[pos].detail()", parent=parent)$ +} +>> + +test_bitset(bitset) ::= << +TEST(TypeObjectTests, TestBitsetTypeObject_$bitset.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_bitset_type(bitset=bitset)$ +} +>> + +check_bitset_type(bitset) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=bitset.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=bitset.scopedname, result="type_objects")$ +EXPECT_EQ(TK_BITSET, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_BITSET, type_objects.complete_type_object._d()); +EXPECT_EQ(0u, type_objects.minimal_type_object.bitset_type().bitset_flags()); +EXPECT_EQ(0u, type_objects.complete_type_object.bitset_type().bitset_flags()); +$check_type_detail_annotations(object=bitset, type="bitset_type().header().detail()")$ +EXPECT_EQ("$bitset.scopedname$", type_objects.complete_type_object.bitset_type().header().detail().type_name().to_string()); +$bitset.members: { member | $check_bitfield(bitfield=member, parent=bitset)$}; separator="\n"$ +ASSERT_EQ($bitset.membersSize$, type_objects.minimal_type_object.bitset_type().field_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.bitset_type().field_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.bitset_type().field_seq()[i-1].common().position(), + type_objects.minimal_type_object.bitset_type().field_seq()[i].common().position()); +} +ASSERT_EQ($bitset.membersSize$, type_objects.complete_type_object.bitset_type().field_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.bitset_type().field_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.bitset_type().field_seq()[i-1].common().position(), + type_objects.complete_type_object.bitset_type().field_seq()[i].common().position()); +} +>> + +check_bitfield(bitfield, parent) ::= << +{ + $if(bitfield.name)$ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.bitset_type().field_seq().size(); ++pos) + { + if ($bitfield.basePosition$ == type_objects.complete_type_object.bitset_type().field_seq()[pos].common().position()) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + EXPECT_EQ($bitfield.basePosition$, type_objects.complete_type_object.bitset_type().field_seq()[pos].common().position()); + EXPECT_EQ($bitfield.basePosition$, type_objects.minimal_type_object.bitset_type().field_seq()[pos].common().position()); + EXPECT_EQ(0u, type_objects.complete_type_object.bitset_type().field_seq()[pos].common().flags()); + EXPECT_EQ(0u, type_objects.minimal_type_object.bitset_type().field_seq()[pos].common().flags()); + EXPECT_EQ($bitfield.spec.bitSize$, type_objects.complete_type_object.bitset_type().field_seq()[pos].common().bitcount()); + EXPECT_EQ($bitfield.spec.bitSize$, type_objects.minimal_type_object.bitset_type().field_seq()[pos].common().bitcount()); + EXPECT_EQ($bitfield.spec.typecode.typeIdentifier$, type_objects.complete_type_object.bitset_type().field_seq()[pos].common().holder_type()); + EXPECT_EQ($bitfield.spec.typecode.typeIdentifier$, type_objects.minimal_type_object.bitset_type().field_seq()[pos].common().holder_type()); + EXPECT_EQ("$bitfield.name$", type_objects.complete_type_object.bitset_type().field_seq()[pos].detail().name().to_string()); + EXPECT_EQ(TypeObjectUtils::name_hash("$bitfield.name$"), type_objects.minimal_type_object.bitset_type().field_seq()[pos].name_hash()); + $check_member_detail_annotations(member=bitfield, type="bitset_type().field_seq()[pos].detail()", parent=parent)$ + $endif$ +} +>> + +test_annotation(annotation) ::= << +TEST(TypeObjectTests, TestAnnotationTypeObject_$annotation.name$) +{ + register_$ctx.filename$_type_objects(); + + $check_annotation_type(annotation=annotation)$ +} +>> + +check_annotation_type(annotation) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=annotation.scopedname, result="type_ids")$ +$check_direct_hash_type_identifier(typeid="type_ids")$ +TypeObjectPair type_objects; +$get_type_object_registry(typename=annotation.scopedname, result="type_objects")$ +EXPECT_EQ(TK_ANNOTATION, type_objects.minimal_type_object._d()); +EXPECT_EQ(TK_ANNOTATION, type_objects.complete_type_object._d()); +EXPECT_EQ(0u, type_objects.minimal_type_object.annotation_type().annotation_flag()); +EXPECT_EQ(0u, type_objects.complete_type_object.annotation_type().annotation_flag()); +EXPECT_EQ("$annotation.scopedname$", type_objects.complete_type_object.annotation_type().header().annotation_name().to_string()); +$annotation.members: { member | $check_annotation_parameter_member(parameter=member)$}; separator="\n"$ +ASSERT_EQ($annotation.membersSize$, type_objects.minimal_type_object.annotation_type().member_seq().size()); +for (size_t i = 1; i < type_objects.minimal_type_object.annotation_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.minimal_type_object.annotation_type().member_seq()[i-1].name_hash(), + type_objects.minimal_type_object.annotation_type().member_seq()[i].name_hash()); +} +ASSERT_EQ($annotation.membersSize$, type_objects.complete_type_object.annotation_type().member_seq().size()); +for (size_t i = 1; i < type_objects.complete_type_object.annotation_type().member_seq().size(); ++i) +{ + EXPECT_LT(type_objects.complete_type_object.annotation_type().member_seq()[i-1].name(), + type_objects.complete_type_object.annotation_type().member_seq()[i].name()); +} +>> + +check_annotation_parameter_member(parameter) ::= << +{ + size_t pos = 0; + bool found = false; + for (; pos < type_objects.complete_type_object.annotation_type().member_seq().size(); ++pos) + { + if (strcmp("$parameter.name$", type_objects.complete_type_object.annotation_type().member_seq()[pos].name()) == 0) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + EXPECT_EQ(0u, type_objects.complete_type_object.annotation_type().member_seq()[pos].common().member_flags()); + TypeIdentifierPair parameter_type_ids; + $get_type_identifier(type=parameter.typecode, var="parameter_type_ids")$ + EXPECT_TRUE(parameter_type_ids.type_identifier1() == type_objects.complete_type_object.annotation_type().member_seq()[pos].common().member_type_id() || + parameter_type_ids.type_identifier2() == type_objects.complete_type_object.annotation_type().member_seq()[pos].common().member_type_id()); + EXPECT_EQ("$parameter.name$", type_objects.complete_type_object.annotation_type().member_seq()[pos].name().to_string()); + $check_annotation_parameter_value(param=parameter, type="complete_type_object.annotation_type().member_seq()[pos].default_value()")$ + found = false; + std::string param_name("$parameter.name$"); + NameHash param_name_hashed = TypeObjectUtils::name_hash(param_name); + for (pos = 0; pos < type_objects.minimal_type_object.annotation_type().member_seq().size(); ++pos) + { + if (param_name_hashed == type_objects.minimal_type_object.annotation_type().member_seq()[pos].name_hash()) + { + found = true; + break; + } + } + ASSERT_TRUE(found); + EXPECT_EQ(0u, type_objects.minimal_type_object.annotation_type().member_seq()[pos].common().member_flags()); + EXPECT_TRUE(parameter_type_ids.type_identifier1() == type_objects.minimal_type_object.annotation_type().member_seq()[pos].common().member_type_id() || + parameter_type_ids.type_identifier2() == type_objects.minimal_type_object.annotation_type().member_seq()[pos].common().member_type_id()); + EXPECT_EQ(param_name_hashed, type_objects.minimal_type_object.annotation_type().member_seq()[pos].name_hash()); + $check_annotation_parameter_value(param=parameter, type="minimal_type_object.annotation_type().member_seq()[pos].default_value()")$ +} +>> + +test_array(array) ::= << +TEST(TypeObjectTests, TestArrayTypeObject_$array_name(array)$) +{ + register_$ctx.filename$_type_objects(); + + $check_array_type(array=array)$ +} +>> + +check_array_type(array) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=array_name(array), result="type_ids")$ +EXPECT_TRUE(type_ids.type_identifier1()._d() == TI_PLAIN_ARRAY_SMALL || + type_ids.type_identifier1()._d() == TI_PLAIN_ARRAY_LARGE); +EXPECT_TRUE(type_ids.type_identifier2()._d() == TI_PLAIN_ARRAY_SMALL || + type_ids.type_identifier2()._d() == TI_PLAIN_ARRAY_LARGE || type_ids.type_identifier2()._d() == TK_NONE); +$! TODO: support annotations within container declarations. Not supported in the grammar yet. !$ +$! $if(array.contentTypeCode.isArrayType || array.contentTypeCode.isSequenceType || array.contentTypeCode.isMapType)$ +$expected_member_flags(object=array.contentTypeCode.contentTypeCode, typename=array_name(array))$ +$else$ !$ +MemberFlag $array_name(array=array)$_expected_flags = 0; +$! $endif$ !$ +TypeIdentifierPair element_type_ids; +$get_type_identifier(type=array.contentTypeCode, var="element_type_ids")$ +$! TODO: Annotated collections are not yet supported: no TypeObject !$ +if (type_ids.type_identifier1()._d() == TI_PLAIN_ARRAY_SMALL) +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().array_sdefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().array_sdefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().array_sdefn().element_identifier()); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().array_sdefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().array_sdefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().array_sdefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().array_sdefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().array_sdefn().header().element_flags(), + type_ids.type_identifier2().array_sdefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().array_sdefn().array_bound_seq(), + type_ids.type_identifier2().array_sdefn().array_bound_seq()); + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().array_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().array_sdefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().array_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().array_sdefn().element_identifier())); + } + EXPECT_EQ($array_name(array=array)$_expected_flags, type_ids.type_identifier1().array_sdefn().header().element_flags()); + $array.evaluatedDimensions: {dimension | $check_array_dimension(dimension=dimension, type="type_ids.type_identifier1().array_sdefn().array_bound_seq()")$}; separator="\n"$ + EXPECT_EQ($array.evaluatedDimensionsSize$, type_ids.type_identifier1().array_sdefn().array_bound_seq().size()); +} +else +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().array_ldefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().array_ldefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().array_ldefn().element_identifier()); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().array_ldefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().array_ldefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().array_ldefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().array_ldefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().array_ldefn().header().element_flags(), + type_ids.type_identifier2().array_ldefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().array_ldefn().array_bound_seq(), + type_ids.type_identifier2().array_ldefn().array_bound_seq()); + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().array_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().array_ldefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().array_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().array_ldefn().element_identifier())); + } + EXPECT_EQ($array_name(array=array)$_expected_flags, type_ids.type_identifier1().array_ldefn().header().element_flags()); + $array.evaluatedDimensions: {dimension | $check_array_dimension(dimension=dimension, type="type_ids.type_identifier1().array_ldefn().array_bound_seq()")$}; separator="\n"$ + EXPECT_EQ($array.evaluatedDimensionsSize$, type_ids.type_identifier1().array_ldefn().array_bound_seq().size()); +} +>> + +check_array_dimension(dimension, type) ::= << +EXPECT_NE(std::find($type$.begin(), $type$.end(), $dimension$), $type$.end()); +>> + +test_sequence(sequence) ::= << +TEST(TypeObjectTests, TestSequenceTypeObject_$sequence_name(sequence=sequence)$) +{ + register_$ctx.filename$_type_objects(); + + $check_sequence_type(sequence=sequence)$ +} +>> + +check_sequence_type(sequence) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=sequence_name(sequence=sequence), result="type_ids")$ +EXPECT_TRUE(type_ids.type_identifier1()._d() == TI_PLAIN_SEQUENCE_SMALL || + type_ids.type_identifier1()._d() == TI_PLAIN_SEQUENCE_LARGE); +EXPECT_TRUE(type_ids.type_identifier2()._d() == TI_PLAIN_SEQUENCE_SMALL || + type_ids.type_identifier2()._d() == TI_PLAIN_SEQUENCE_LARGE || type_ids.type_identifier2()._d() == TK_NONE); +$! TODO: support annotations within container declarations. Not supported in the grammar yet. !$ +$! $if(!sequence.contentTypeCode.primitive)$ +$expected_member_flags(object=sequence.contentTypeCode, typename=sequence_name(sequence=sequence))$ +$else$ !$ +MemberFlag $sequence_name(sequence=sequence)$_expected_flags = 0; +$! $endif$ !$ +TypeIdentifierPair element_type_ids; +$get_type_identifier(type=sequence.contentTypeCode, var="element_type_ids")$ +if (type_ids.type_identifier1()._d() == TI_PLAIN_SEQUENCE_SMALL) +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().seq_sdefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().seq_sdefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().seq_sdefn().element_identifier()); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().seq_sdefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().seq_sdefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().seq_sdefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().seq_sdefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().seq_sdefn().header().element_flags(), + type_ids.type_identifier2().seq_sdefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().seq_sdefn().bound(), type_ids.type_identifier2().seq_sdefn().bound()); + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().seq_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().seq_sdefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().seq_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().seq_sdefn().element_identifier())); + } + EXPECT_EQ($sequence_name(sequence=sequence)$_expected_flags, type_ids.type_identifier1().seq_sdefn().header().element_flags()); + EXPECT_EQ($if(sequence.unbound)$0$else$$sequence.evaluatedMaxsize$$endif$, type_ids.type_identifier1().seq_sdefn().bound()); +} +else +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().seq_ldefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().seq_ldefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().seq_ldefn().element_identifier()); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().seq_ldefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().seq_ldefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().seq_ldefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().seq_ldefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().seq_ldefn().header().element_flags(), + type_ids.type_identifier2().seq_ldefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().seq_ldefn().bound(), type_ids.type_identifier2().seq_ldefn().bound()); + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().seq_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().seq_ldefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().seq_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().seq_ldefn().element_identifier())); + } + EXPECT_EQ($sequence_name(sequence=sequence)$_expected_flags, type_ids.type_identifier1().seq_ldefn().header().element_flags()); + EXPECT_EQ($if(sequence.unbound)$0$else$$sequence.evaluatedMaxsize$$endif$, type_ids.type_identifier1().seq_ldefn().bound()); +} +>> + +test_map(map) ::= << +TEST(TypeObjectTests, TestMapTypeObject_$map_name(map)$) +{ + register_$ctx.filename$_type_objects(); + + $check_map_type(map=map)$ +} +>> + +check_map_type(map) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=map_name(map=map), result="type_ids")$ +EXPECT_TRUE(type_ids.type_identifier1()._d() == TI_PLAIN_MAP_SMALL || + type_ids.type_identifier1()._d() == TI_PLAIN_MAP_LARGE); +EXPECT_TRUE(type_ids.type_identifier2()._d() == TI_PLAIN_MAP_SMALL || + type_ids.type_identifier2()._d() == TI_PLAIN_MAP_LARGE || type_ids.type_identifier2()._d() == TK_NONE); +$! TODO: support annotations within container declarations. Not supported in the grammar yet. !$ +$! $if(!map.valueTypeCode.primitive)$ +$expected_member_flags(object=map.valueTypeCode, typename=map_name(map=map))$ +$expected_member_flags(object=map.keyTypeCode, typename=["key_", map_name(map=map)])$ +$else$ !$ +MemberFlag $map_name(map=map)$_expected_flags = 0; +MemberFlag key_$map_name(map=map)$_expected_flags = 0; +$! $endif$ !$ +TypeIdentifierPair key_type_ids; +$get_type_identifier(type=map.keyTypeCode, var="key_type_ids")$ +TypeIdentifierPair element_type_ids; +$get_type_identifier(type=map.valueTypeCode, var="element_type_ids")$ +if (type_ids.type_identifier1()._d() == TI_PLAIN_MAP_SMALL) +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().map_sdefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().element_identifier()); + EXPECT_TRUE(key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().key_identifier() || + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().key_identifier()); + } + else if (EK_BOTH == type_ids.type_identifier1().map_sdefn().header().equiv_kind()) + { + EXPECT_EQ(type_ids.type_identifier1().map_sdefn().header().equiv_kind(), + type_ids.type_identifier2().map_sdefn().header().equiv_kind()); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().element_identifier()); + EXPECT_TRUE((key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier2().map_sdefn().key_identifier()) || + (key_type_ids.type_identifier1() == *type_ids.type_identifier2().map_sdefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().key_identifier())); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().map_sdefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().map_sdefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().map_sdefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().map_sdefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().map_sdefn().header().element_flags(), + type_ids.type_identifier2().map_sdefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().map_sdefn().bound(), type_ids.type_identifier2().map_sdefn().bound()); + if (type_ids.type_identifier1().map_sdefn().element_identifier()->_d() == EK_COMPLETE || + type_ids.type_identifier1().map_sdefn().element_identifier()->_d() == EK_MINIMAL) + { + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().map_sdefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().map_sdefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().element_identifier())); + } + else + { + EXPECT_EQ(element_type_ids.type_identifier1(), *type_ids.type_identifier1().map_sdefn().element_identifier()); + EXPECT_EQ(*type_ids.type_identifier1().map_sdefn().element_identifier(), *type_ids.type_identifier2().map_sdefn().element_identifier()); + } + if (type_ids.type_identifier1().map_sdefn().key_identifier()->_d() == EK_COMPLETE || + type_ids.type_identifier1().map_sdefn().key_identifier()->_d() == EK_MINIMAL) + { + EXPECT_TRUE((key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_sdefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier2().map_sdefn().key_identifier()) || + (key_type_ids.type_identifier1() == *type_ids.type_identifier2().map_sdefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_sdefn().key_identifier())); + } + else + { + EXPECT_EQ(key_type_ids.type_identifier1(), *type_ids.type_identifier1().map_sdefn().key_identifier()); + EXPECT_EQ(*type_ids.type_identifier1().map_sdefn().key_identifier(), *type_ids.type_identifier2().map_sdefn().key_identifier()); + } + } + EXPECT_EQ($map_name(map=map)$_expected_flags, type_ids.type_identifier1().map_sdefn().header().element_flags()); + EXPECT_EQ($if(map.unbound)$0$else$$map.evaluatedMaxsize$$endif$, type_ids.type_identifier1().map_sdefn().bound()); + EXPECT_EQ(key_$map_name(map=map)$_expected_flags, type_ids.type_identifier1().map_sdefn().key_flags()); +} +else +{ + if (type_ids.type_identifier2()._d() == TK_NONE) + { + EXPECT_EQ(type_ids.type_identifier1().map_ldefn().header().equiv_kind(), EK_BOTH); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().element_identifier()); + EXPECT_TRUE(key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().key_identifier() || + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().key_identifier()); + } + else if (EK_BOTH == type_ids.type_identifier1().map_ldefn().header().equiv_kind()) + { + EXPECT_EQ(type_ids.type_identifier1().map_ldefn().header().equiv_kind(), + type_ids.type_identifier2().map_ldefn().header().equiv_kind()); + EXPECT_TRUE(element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().element_identifier() || + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().element_identifier()); + EXPECT_TRUE((key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier2().map_ldefn().key_identifier()) || + (key_type_ids.type_identifier1() == *type_ids.type_identifier2().map_ldefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().key_identifier())); + } + else + { + EXPECT_TRUE((type_ids.type_identifier1().map_ldefn().header().equiv_kind() == EK_COMPLETE && + type_ids.type_identifier2().map_ldefn().header().equiv_kind() == EK_MINIMAL) || + (type_ids.type_identifier1().map_ldefn().header().equiv_kind() == EK_MINIMAL && + type_ids.type_identifier2().map_ldefn().header().equiv_kind() == EK_COMPLETE)); + EXPECT_EQ(type_ids.type_identifier1().map_ldefn().header().element_flags(), + type_ids.type_identifier2().map_ldefn().header().element_flags()); + EXPECT_EQ(type_ids.type_identifier1().map_ldefn().bound(), type_ids.type_identifier2().map_ldefn().bound()); + if (type_ids.type_identifier1().map_ldefn().element_identifier()->_d() == EK_COMPLETE || + type_ids.type_identifier1().map_ldefn().element_identifier()->_d() == EK_MINIMAL) + { + EXPECT_TRUE((element_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier2().map_ldefn().element_identifier()) || + (element_type_ids.type_identifier1() == *type_ids.type_identifier2().map_ldefn().element_identifier() && + element_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().element_identifier())); + } + else + { + EXPECT_EQ(element_type_ids.type_identifier1(), *type_ids.type_identifier1().map_ldefn().element_identifier()); + EXPECT_EQ(*type_ids.type_identifier1().map_ldefn().element_identifier(), *type_ids.type_identifier2().map_ldefn().element_identifier()); + } + if (type_ids.type_identifier1().map_ldefn().key_identifier()->_d() == EK_COMPLETE || + type_ids.type_identifier1().map_ldefn().key_identifier()->_d() == EK_MINIMAL) + { + EXPECT_TRUE((key_type_ids.type_identifier1() == *type_ids.type_identifier1().map_ldefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier2().map_ldefn().key_identifier()) || + (key_type_ids.type_identifier1() == *type_ids.type_identifier2().map_ldefn().key_identifier() && + key_type_ids.type_identifier2() == *type_ids.type_identifier1().map_ldefn().key_identifier())); + } + else + { + EXPECT_EQ(key_type_ids.type_identifier1(), *type_ids.type_identifier1().map_ldefn().key_identifier()); + EXPECT_EQ(*type_ids.type_identifier1().map_ldefn().key_identifier(), *type_ids.type_identifier2().map_ldefn().key_identifier()); + } + } + EXPECT_EQ($map_name(map=map)$_expected_flags, type_ids.type_identifier1().map_ldefn().header().element_flags()); + EXPECT_EQ($if(map.unbound)$0$else$$map.evaluatedMaxsize$$endif$, type_ids.type_identifier1().map_ldefn().bound()); + EXPECT_EQ(key_$map_name(map=map)$_expected_flags, type_ids.type_identifier1().map_ldefn().key_flags()); +} +>> + +test_string(string) ::= << +TEST(TypeObjectTests, TestStringTypeObject_$string_name(string=string)$) +{ + register_$ctx.filename$_type_objects(); + + $check_string_type(string=string)$ +} +>> + +check_string_type(string) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=string_name(string), result="type_ids")$ +EXPECT_EQ(TK_NONE, type_ids.type_identifier2()._d()); +EXPECT_TRUE(TI_STRING8_SMALL == type_ids.type_identifier1()._d() || TI_STRING8_LARGE == type_ids.type_identifier1()._d()); +if (type_ids.type_identifier1()._d() == TI_STRING8_SMALL) +{ + EXPECT_EQ($if(string.isBounded)$$string.evaluatedMaxsize$$else$0$endif$, type_ids.type_identifier1().string_sdefn().bound()); +} +else +{ + EXPECT_EQ($if(string.isBounded)$$string.evaluatedMaxsize$$else$0$endif$, type_ids.type_identifier1().string_ldefn().bound()); +} +>> + +test_wstring(wstring) ::= << +TEST(TypeObjectTests, TestWstringTypeObject_$wstring_name(wstring=wstring)$) +{ + register_$ctx.filename$_type_objects(); + + $check_wstring_type(wstring=wstring)$ +} +>> + +check_wstring_type(wstring) ::= << +ReturnCode_t ret_code; +TypeIdentifierPair type_ids; +$get_type_identifier_registry(typename=wstring_name(wstring), result="type_ids")$ +EXPECT_EQ(TK_NONE, type_ids.type_identifier2()._d()); +EXPECT_TRUE(TI_STRING16_SMALL == type_ids.type_identifier1()._d() || TI_STRING16_LARGE == type_ids.type_identifier1()._d()); +if (type_ids.type_identifier1()._d() == TI_STRING16_SMALL) +{ + EXPECT_EQ($if(wstring.isBounded)$$wstring.evaluatedMaxsize$$else$0$endif$, type_ids.type_identifier1().string_sdefn().bound()); +} +else +{ + EXPECT_EQ($if(wstring.isBounded)$$wstring.evaluatedMaxsize$$else$0$endif$, type_ids.type_identifier1().string_ldefn().bound()); +} +>> + +check_direct_hash_type_identifier(typeid) ::= << +EXPECT_TRUE(($typeid$.type_identifier1()._d() == EK_MINIMAL && $typeid$.type_identifier2()._d() == EK_COMPLETE) || + ($typeid$.type_identifier2()._d() == EK_MINIMAL && $typeid$.type_identifier1()._d() == EK_COMPLETE)); +>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg new file mode 100644 index 00000000..e9d5a8ce --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg @@ -0,0 +1,100 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +group XTypesTypeObjectHeader; + +import "eprosima.stg" + +main(ctx, definitions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObjectSupport.hpp"], description=["Header file containing the API required to register the TypeObject representation of the described types in the IDL file"])$ + +#ifndef _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_SUPPORT_HPP_ +#define _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_SUPPORT_HPP_ + +$ctx.directIncludeDependencies : { include | #include "$include$TypeObjectSupport.hpp"}; separator="\n"$ + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +/** + * @brief Register every TypeObject representation defined in the IDL file in Fast DDS TypeObjectRegistry. + */ +$! TODO: ensure no conflict between IDL files with same name but different directory !$ +eProsima_user_DllExport void register_$ctx.filename$_type_objects(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +$definitions; separator=""$ + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // _FAST_DDS_GENERATED_$ctx.headerGuardName$_TYPE_OBJECT_SUPPORT_HPP_ + +>> + +module(ctx, parent, module, definition_list) ::= << +namespace $module.name$ { +$definition_list$ +} // namespace $module.name$ + +>> + +definition_list(definitions) ::= << +$definitions; separator="\n"$ +>> + +annotation(ctx, annotation) ::= << +$register_type_identifier(typename=annotation.CScopedname)$ +>> + +struct_type(ctx, parent, struct, member_list) ::= << +$register_type_identifier(typename=struct.CScopedname)$ +>> + +union_type(ctx, parent, union, extensions, switch_type) ::= << +$register_type_identifier(typename=union.CScopedname)$ +>> + +/***** Utils *****/ +register_type_identifier(typename) ::= << +/** + * @brief Register $typename$ related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + */ +void register_$typename$_type_identifier(); + +>> + +//{ Fast DDS-Gen extensions +module_conversion(ctx, parent, modules, definition_list) ::= << +$modules : { module | +namespace $module.name$ { +}; separator="\n"$ + +$definition_list$ + +$reverse(modules) : { module | +\} // namespace $module.name$ +}; separator="\n"$ +>> +//} diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg new file mode 100644 index 00000000..910e0917 --- /dev/null +++ b/src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg @@ -0,0 +1,1098 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +group XTypesTypeObjectSource; + +import "eprosima.stg" + +main(ctx, definitions) ::= << +$fileHeader(ctx=ctx, file=[ctx.filename, "TypeObjectSupport.cxx"], description=["Source file containing the implementation to register the TypeObject representation of the described types in the IDL file"])$ + +#include "$ctx.filename$TypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "$ctx.filename$.hpp" + +$ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$ + +using namespace eprosima::fastdds::dds::xtypes; + +void register_$ctx.filename$_type_objects() +{ + static std::once_flag once_flag; + std::call_once(once_flag, []() + { + $ctx.definitions: { def | $register_type(ctx=ctx, object=def)$}; separator=""$ + }); +} + +$definitions; separator=""$ + +>> + +module(ctx, parent, module, definition_list) ::= << +namespace $module.name$ { +$definition_list$ +} // namespace $module.name$ + +>> + +definition_list(definitions) ::= <% +$definitions; separator=""$ +%> + +annotation(ctx, annotation) ::= << +void register_$annotation.CScopedname$_type_identifier() +{ + $register_annotation_type(annotation=annotation)$ +} + +>> + +struct_type(ctx, parent, struct, member_list) ::= << +void register_$struct.CScopedname$_type_identifier() +{ + $if (struct.nonForwardedContent)$ + $register_struct_type(struct)$ + $else$ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$struct.scopedname$ contains forward declarations (not yet supported)."); + $endif$ +} + +>> + +union_type(ctx, parent, union, extensions, switch_type) ::= << +void register_$union.CScopedname$_type_identifier() +{ + $if (union.nonForwardedContent)$ + $register_union_type(union)$ + $else$ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$union.scopedname$ contains forward declarations (not yet supported)."); + $endif$ +} + +>> + +/***** Utils *****/ +register_type(ctx, object) ::= << +$if (object.isTypeDeclaration)$ +$if ((object.typeCode.isStructType || object.typeCode.isUnionType) && !object.typeCode.forwarded)$ +$if (!object.scope.empty)$$object.scope$::$endif$register_$object.CScopedname$_type_identifier(); +$endif$ +$elseif (object.isAnnotation)$ +$if (!object.scope.empty)$$object.scope$::$endif$register_$object.CScopedname$_type_identifier(); +$endif$ +>> + +get_type_identifier(type, name) ::= << +$if (type.isAliasType)$ +$get_type_identifier_registry(typename=type.scopedname, name=name)$ +$elseif (type.isByteType)$ +$get_type_identifier_registry(typename="_byte", name=name)$ +$elseif (type.primitive && !type.isEnumType)$ +$get_type_identifier_registry(typename=["_", type.cppTypenameForTypeId], name=name)$ +$elseif (type.isStringType)$ +$get_type_identifier_registry(typename=string_name(string=type), name=name)$ +$elseif (type.isWStringType)$ +$get_type_identifier_registry(typename=wstring_name(wstring=type), name=name)$ +$elseif (type.isArrayType)$ +$get_type_identifier_registry(typename=array_name(array=type), name=name)$ +$elseif (type.isSequenceType)$ +$get_type_identifier_registry(typename=sequence_name(sequence=type), name=name)$ +$elseif (type.isMapType)$ +$get_type_identifier_registry(typename=map_name(map=type), name=name)$ +$else$ +$get_type_identifier_registry(typename=type.scopedname, name=name)$ +$endif$ +>> + +get_type_identifier_registry(typename, name) ::= << +return_code_$name$ = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "$typename$", type_ids_$name$); +>> + +applied_annotation_sequence(annotation, typename, member, name) ::= << +{ + eprosima::fastcdr::optional applied_annotation_parameter_seq_$member.name$; + AppliedAnnotationParameterSeq tmp_applied_annotation_parameter_seq_$member.name$; + $if (annotation.valueList)$ +$annotation.valueList : { param | +{ + NameHash paramname_hash_$param.name$ = TypeObjectUtils::name_hash("$param.name$"); + $annotation_parameter_value(param=param, type=param.typecode)$ + AppliedAnnotationParameter applied_param_$param.name$ = TypeObjectUtils::build_applied_annotation_parameter(paramname_hash_$param.name$, + param_value_$param.name$); + TypeObjectUtils::add_applied_annotation_parameter(tmp_applied_annotation_parameter_seq_$member.name$, applied_param_$param.name$); +\} +}; separator="\n"$ +$endif$ + { + AppliedAnnotation applied_annotation_$member.name$; + $get_type_identifier_registry(typename=annotation.scopedname, name=name)$ + if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$typename$: Given Annotation TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + if (!tmp_applied_annotation_parameter_seq_$member.name$.empty()) + { + applied_annotation_parameter_seq_$member.name$ = tmp_applied_annotation_parameter_seq_$member.name$; + } + if (EK_COMPLETE == type_ids_$name$.type_identifier1()._d()) + { + applied_annotation_$member.name$ = TypeObjectUtils::build_applied_annotation(type_ids_$name$.type_identifier1(), applied_annotation_parameter_seq_$member.name$); + } + else if (EK_COMPLETE == type_ids_$name$.type_identifier2()._d()) + { + applied_annotation_$member.name$ = TypeObjectUtils::build_applied_annotation(type_ids_$name$.type_identifier2(), applied_annotation_parameter_seq_$member.name$); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$typename$: Given Annotation TypeIdentifier is inconsistent."); + return; + } + TypeObjectUtils::add_applied_annotation(tmp_ann_custom_$member.name$, applied_annotation_$member.name$); + \} +} +>> + +annotation_parameter_value(param, type) ::= << +$if (type.isAliasType)$ +$annotation_parameter_value(param=param, type=param.typecode.typedefContentTypeCode)$ +$elseif (type.isEnumType)$ +AnnotationParameterValue param_value_$param.name$ = TypeObjectUtils::build_annotation_parameter_value_enum($param.value$); +$elseif (type.isByteType)$ +AnnotationParameterValue param_value_$param.name$ = TypeObjectUtils::build_annotation_parameter_value_byte($param.value$); +$elseif (param.typecode.isStringType)$ +AnnotationParameterValue param_value_$param.name$ = TypeObjectUtils::build_annotation_parameter_value(eprosima::fastcdr::fixed_string<128>("$param.value$")); +$else$ +AnnotationParameterValue param_value_$param.name$ = TypeObjectUtils::build_annotation_parameter_value(static_cast<$type.cppTypename$>($param.value$)); +$endif$ +>> + +applied_verbatim_annotation(annotation, name) ::= << +PlacementKindValue placement_$name$ = BEFORE_DECLARATION; +eprosima::fastcdr::fixed_string<32> language_$name$ = "*"; +std::string text_$name$; +$annotation.valueList : { verbatim_param | +$if (verbatim_param.isVerbatimPlacement)$ +placement_$name$ = $verbatim_param.enumStringValue$; +$elseif (verbatim_param.isVerbatimLanguage)$ +language_$name$ = "$verbatim_param.value$"; +$elseif (verbatim_param.isVerbatimText)$ +text_$name$ = "$verbatim_param.value$"; +$endif$ +}; separator="\n"$ +verbatim_$name$ = TypeObjectUtils::build_applied_verbatim_annotation(placement_$name$, language_$name$, text_$name$); +type_ann_builtin_$annotation_name$ = TypeObjectUtils::build_applied_builtin_type_annotations(verbatim_$name$); +>> + +register_alias_type(alias, name) ::= << +$! TODO(jlbueno): annotated collections aliases are considered non-anonymous collections. + pending implementation of annotated collection support !$ +AliasTypeFlag alias_flags_$alias.name$ = 0; +$complete_type_detail(type=alias, type_kind=" Alias", name=name)$ +CompleteAliasHeader header_$alias.name$ = TypeObjectUtils::build_complete_alias_header(detail_$alias.name$); +AliasMemberFlag related_flags_$alias.name$ = 0; +$get_type_identifier(type=alias.typedefContentTypeCode, name=name)$ +$check_register_type_identifier(type=alias.typedefContentTypeCode, message=[alias.scopedname, " related"], name=name)$ +CommonAliasBody common_$alias.name$; +$check_first_returned_type_identifier_pair(name=name)$ +{ + common_$alias.name$ = TypeObjectUtils::build_common_alias_body(related_flags_$alias.name$, type_ids_$name$.type_identifier1()); +} +$check_second_returned_type_identifier_pair(name=name)$ +{ + common_$alias.name$ = TypeObjectUtils::build_common_alias_body(related_flags_$alias.name$, type_ids_$name$.type_identifier2()); +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$alias.scopedname$ related TypeIdentifier inconsistent."); + return; +} +eprosima::fastcdr::optional member_ann_builtin_$alias.name$; +ann_custom_$alias.name$.reset(); +$if (alias.annotationList)$ +eprosima::fastcdr::optional unit_$alias.name$; +eprosima::fastcdr::optional min_$alias.name$; +eprosima::fastcdr::optional max_$alias.name$; +eprosima::fastcdr::optional hash_id_$alias.name$; +$alias.annotationList : { annotation | +$if (annotation.isUnit)$ +unit_$alias.name$ = $annotation.value$; +$elseif (annotation.isMin || annotation.isMax || annotation.isRange)$ +EPROSIMA_LOG_WARNING(XTYPES_TYPE_REPRESENTATION, + "$alias.scopedname$ Alias: @min, @max, and @range builtin annotations not yet supported"); +$elseif (annotation.isHashId)$ +EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$alias.scopedname$ Alias: @hashid builtin annotation does not apply to aliases"); +return; +$endif$ +}; separator="\n"$ +if (unit_$alias.name$.has_value() || min_$alias.name$.has_value() || max_$alias.name$.has_value() || hash_id_$alias.name$.has_value()) +{ + member_ann_builtin_$alias.name$ = TypeObjectUtils::build_applied_builtin_member_annotations(unit_$alias.name$, min_$alias.name$, max_$alias.name$, hash_id_$alias.name$); +} +$endif$ +CompleteAliasBody body_$alias.name$ = TypeObjectUtils::build_complete_alias_body(common_$alias.name$, member_ann_builtin_$alias.name$, ann_custom_$alias.name$); +CompleteAliasType alias_type_$alias.name$ = TypeObjectUtils::build_complete_alias_type(alias_flags_$alias.name$, header_$alias.name$, body_$alias.name$); +if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_$alias.name$, type_name_$alias.name$.to_string())) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$alias.scopedname$ already registered in TypeObjectRegistry for a different type."); +} +$get_type_identifier_registry(typename=alias.scopedname, name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$alias.scopedname$: Given Alias TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +register_annotation_type(annotation) ::= << +AnnotationTypeFlag annotation_flag_$annotation.name$ = 0; +QualifiedTypeName annotation_name_$annotation.name$ = "$annotation.scopedname$"; +CompleteAnnotationHeader header_$annotation.name$ = TypeObjectUtils::build_complete_annotation_header(annotation_name_$annotation.name$); +CompleteAnnotationParameterSeq member_seq_$annotation.name$; +$if (annotation.members)$ +$annotation.members: { member | $annotation_parameter(param=member, parent=annotation)$}; separator="\n"$ +$endif$ +CompleteAnnotationType annotation_type_$annotation.name$ = TypeObjectUtils::build_complete_annotation_type(annotation_flag_$annotation.name$, header_$annotation.name$, + member_seq_$annotation.name$); +if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_annotation_type_object(annotation_type_$annotation.name$, annotation_name_$annotation.name$.to_string())) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$annotation.scopedname$ already registered in TypeObjectRegistry for a different type."); +} +>> + +annotation_parameter(param, parent) ::= << +{ + ReturnCode_t return_code_$param.name$; + TypeIdentifierPair type_ids_$param.name$; + AnnotationParameterFlag member_flags_$param.name$ = 0; + $get_type_identifier(type=param.typecode, name=param.name)$ + if (return_code_$param.name$ != eprosima::fastdds::dds::RETCODE_OK) + { + $if (param.typecode.isAliasType)$ + $register_alias_type(alias=param.typecode, name=param.name)$ + $elseif (param.typecode.isEnumType)$ + $register_enum_type(enum=param.typecode, name=param.name)$ + $elseif (param.typecode.isStringType)$ + $register_string_type(string=param.typecode, name=param.name)$ + $elseif (param.typecode.isWStringType)$ + $register_wstring_type(wstring=param.typecode, name=param.name)$ + $else$ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$param.name$ annotation parameter TypeIdentifier unknown to TypeObjectRegistry."); + return; + $endif$ + } + CommonAnnotationParameter common_$param.name$; + if (EK_COMPLETE == type_ids_$param.name$.type_identifier1()._d() || TK_NONE == type_ids_$param.name$.type_identifier2()._d()) + { + common_$param.name$ = TypeObjectUtils::build_common_annotation_parameter(member_flags_$param.name$, type_ids_$param.name$.type_identifier1()); + } + else if (EK_COMPLETE == type_ids_$param.name$.type_identifier2()._d()) + { + common_$param.name$ = TypeObjectUtils::build_common_annotation_parameter(member_flags_$param.name$, type_ids_$param.name$.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$param.name$ annotation parameter TypeIdentifier inconsistent."); + return; + } + MemberName name_$param.name$ = "$param.name$"; + $annotation_parameter_value(param=param, type=param.typecode)$ + CompleteAnnotationParameter param_$param.name$ = TypeObjectUtils::build_complete_annotation_parameter(common_$param.name$, name_$param.name$, param_value_$param.name$); + TypeObjectUtils::add_complete_annotation_parameter(member_seq_$parent.name$, param_$param.name$); +} +>> + +register_struct_type(struct) ::= << +{ + StructTypeFlag struct_flags_$struct.name$ = TypeObjectUtils::build_struct_type_flag($extensibility(object=struct)$ + $struct.annotationNested$, $struct.annotationAutoidHash$); + ReturnCode_t return_code_$struct.name$; + TypeIdentifierPair type_ids_$struct.name$; + $if (struct.inheritance)$ + $get_type_identifier(type=struct.inheritance, name=struct.name)$ + if (return_code_$struct.name$ != eprosima::fastdds::dds::RETCODE_OK) + { + $register_struct_type(struct.inheritance)$ + } + $endif$ + $complete_type_detail(type=struct, type_kind=" Structure", name=struct.name)$ + CompleteStructHeader header_$struct.name$; + $if (struct.inheritance)$ + if (EK_COMPLETE == type_ids_$struct.name$.type_identifier1()._d() || TK_NONE == type_ids_$struct.name$.type_identifier1()._d()) + { + header_$struct.name$ = TypeObjectUtils::build_complete_struct_header(type_ids_$struct.name$.type_identifier1(), detail_$struct.name$); + } + else if (EK_COMPLETE == type_ids_$struct.name$.type_identifier2()._d()) + { + header_$struct.name$ = TypeObjectUtils::build_complete_struct_header(type_ids_$struct.name$.type_identifier2(), detail_$struct.name$); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$struct.scopedname$ Structure: base_type TypeIdentifier registered in TypeObjectRegistry is inconsistent."); + return; + } + $else$ + header_$struct.name$ = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_$struct.name$); + $endif$ + CompleteStructMemberSeq member_seq_$struct.name$; + $if (struct.members)$ + $struct.members: { member | $struct_member(member=member, parent=struct)$}; separator="\n"$ + $endif$ + CompleteStructType struct_type_$struct.name$ = TypeObjectUtils::build_complete_struct_type(struct_flags_$struct.name$, header_$struct.name$, member_seq_$struct.name$); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_$struct.name$, type_name_$struct.name$.to_string())) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$struct.scopedname$ already registered in TypeObjectRegistry for a different type."); + } + $get_type_identifier_registry(typename=struct.scopedname, name=struct.name)$ + if (return_code_$struct.name$ != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$struct.scopedname$: Given Struct TypeIdentifier unknown to TypeObjectRegistry."); + return; + } +} +>> + +struct_member(member, parent) ::= << +{ + $get_type_identifier(type=member.typecode, name=parent.name)$ + $check_register_type_identifier(type=member.typecode, message=[member.name, " Structure member"], name=parent.name)$ + StructMemberFlag member_flags_$member.name$ = TypeObjectUtils::build_struct_member_flag($try_construct(object=member)$ + $member.annotationOptional$, $member.annotationMustUnderstand$, $member.annotationKey$, $member.annotationExternal$); + CommonStructMember common_$member.name$; + MemberId member_id_$member.name$ = $member.id$; + $check_first_returned_type_identifier_pair(name=parent.name)$ + { + common_$member.name$ = TypeObjectUtils::build_common_struct_member(member_id_$member.name$, member_flags_$member.name$, type_ids_$parent.name$.type_identifier1()); + } + $check_second_returned_type_identifier_pair(name=parent.name)$ + { + common_$member.name$ = TypeObjectUtils::build_common_struct_member(member_id_$member.name$, member_flags_$member.name$, type_ids_$parent.name$.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Structure $member.name$ member TypeIdentifier inconsistent."); + return; + } + $complete_member_detail(member=member, parent=parent, type_kind="Structure", name=parent.name)$ + CompleteStructMember member_$member.name$ = TypeObjectUtils::build_complete_struct_member(common_$member.name$, detail_$member.name$); + TypeObjectUtils::add_complete_struct_member(member_seq_$parent.name$, member_$member.name$); +} +>> + +register_union_type(union) ::= << +{ + ReturnCode_t return_code_$union.name$; + TypeIdentifierPair type_ids_$union.name$; + UnionTypeFlag union_flags_$union.name$ = TypeObjectUtils::build_union_type_flag($extensibility(object=union)$ + $union.annotationNested$, $union.annotationAutoidHash$); + $complete_type_detail(type=union, type_kind=" Union", name=union.name)$ + CompleteUnionHeader header_$union.name$ = TypeObjectUtils::build_complete_union_header(detail_$union.name$); + UnionDiscriminatorFlag member_flags_$union.name$ = TypeObjectUtils::build_union_discriminator_flag($try_construct(object=union.discriminator)$ + $union.discriminator.annotationKey$); + $get_type_identifier(type=union.discriminator.typecode, name=union.name)$ + if (return_code_$union.name$ != eprosima::fastdds::dds::RETCODE_OK) + { + $if (union.discriminator.typecode.isAliasType)$ + $register_alias_type(alias=union.discriminator.typecode, name=union.name)$ + $elseif (union.discriminator.typecode.isEnumType)$ + $register_enum_type(enum=union.discriminator.typecode, name=union.name)$ + $else$ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Union discriminator TypeIdentifier unknown to TypeObjectRegistry."); + return; + $endif$ + } + CommonDiscriminatorMember common_$union.name$; + if (EK_COMPLETE == type_ids_$union.name$.type_identifier1()._d() || TK_NONE == type_ids_$union.name$.type_identifier2()._d()) + { + common_$union.name$ = TypeObjectUtils::build_common_discriminator_member(member_flags_$union.name$, type_ids_$union.name$.type_identifier1()); + } + else if (EK_COMPLETE == type_ids_$union.name$.type_identifier2()._d()) + { + common_$union.name$ = TypeObjectUtils::build_common_discriminator_member(member_flags_$union.name$, type_ids_$union.name$.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$union.scopedname$ discriminator TypeIdentifier inconsistent."); + return; + } + type_ann_builtin_$union.name$.reset(); + ann_custom_$union.name$.reset(); + $type_annotations(type=union.discriminator, type_kind=" Union Discriminator", name=union.name)$ + CompleteDiscriminatorMember discriminator_$union.name$ = TypeObjectUtils::build_complete_discriminator_member(common_$union.name$, + type_ann_builtin_$union.name$, ann_custom_$union.name$); + CompleteUnionMemberSeq member_seq_$union.name$; + $union.members : { member | $union_member(member=member, parent=union)$}; separator="\n"$ + CompleteUnionType union_type_$union.name$ = TypeObjectUtils::build_complete_union_type(union_flags_$union.name$, header_$union.name$, discriminator_$union.name$, + member_seq_$union.name$); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_union_type_object(union_type_$union.name$, type_name_$union.name$.to_string())) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$union.scopedname$ already registered in TypeObjectRegistry for a different type."); + } + $get_type_identifier_registry(typename=union.scopedname, name=union.name)$ + if (return_code_$union.name$ != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$union.scopedname$: Given Union TypeIdentifier unknown to TypeObjectRegistry."); + return; + } +} +>> + +union_member(member, parent) ::= << +{ + $get_type_identifier(type=member.typecode, name=parent.name)$ + $check_register_type_identifier(type=member.typecode, message=[member.name, " Union member"], name=parent.name)$ + UnionMemberFlag member_flags_$member.name$ = TypeObjectUtils::build_union_member_flag($try_construct(object=member)$ + $member.default$, $member.annotationExternal$); + UnionCaseLabelSeq label_seq_$member.name$; + $if (member.labels)$ + $member.labels : { label | TypeObjectUtils::add_union_case_label(label_seq_$member.name$, static_cast($label$));}; separator="\n"$ + $endif$ + CommonUnionMember common_$member.name$; + MemberId member_id_$member.name$ = $member.id$; + $check_first_returned_type_identifier_pair(name=parent.name)$ + { + common_$member.name$ = TypeObjectUtils::build_common_union_member(member_id_$member.name$, member_flags_$member.name$, type_ids_$parent.name$.type_identifier1(), + label_seq_$member.name$); + } + $check_second_returned_type_identifier_pair(name=parent.name)$ + { + common_$member.name$ = TypeObjectUtils::build_common_union_member(member_id_$member.name$, member_flags_$member.name$, type_ids_$parent.name$.type_identifier2(), + label_seq_$member.name$); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Union $member.name$ member TypeIdentifier inconsistent."); + return; + } + $complete_member_detail(member=member, parent=parent, type_kind="Union", name=parent.name)$ + CompleteUnionMember member_$member.name$ = TypeObjectUtils::build_complete_union_member(common_$member.name$, detail_$member.name$); + TypeObjectUtils::add_complete_union_member(member_seq_$parent.name$, member_$member.name$); +} +>> + +register_bitset_type(bitset, name) ::= << +BitsetTypeFlag bitset_flags_$bitset.name$ = 0; +$complete_type_detail(type=bitset, type_kind= " Bitset", name=name)$ +CompleteBitsetHeader header_$bitset.name$ = TypeObjectUtils::build_complete_bitset_header(detail_$bitset.name$); +CompleteBitfieldSeq field_seq_$bitset.name$; +$bitset.bitfields: { bitfield | $bitfield_member(bitfield=bitfield, parent=bitset, name=name)$}; separator="\n"$ +CompleteBitsetType bitset_type_$bitset.name$ = TypeObjectUtils::build_complete_bitset_type(bitset_flags_$bitset.name$, header_$bitset.name$, field_seq_$bitset.name$); +if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_bitset_type_object(bitset_type_$bitset.name$, type_name_$bitset.name$.to_string())) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$bitset.scopedname$ already registered in TypeObjectRegistry for a different type."); +} +$get_type_identifier_registry(typename=bitset.scopedname, name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$bitset.scopedname$: Given Bitset TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +bitfield_member(bitfield, parent, name) ::= << +{ + uint16_t position_$bitfield.name$ = $bitfield.basePosition$; + BitsetMemberFlag flags_$bitfield.name$ = 0; + uint8_t bitcount_$bitfield.name$ = $bitfield.spec.bitSize$; + TypeKind holder_type_$bitfield.name$ = $bitfield.spec.typecode.typeIdentifier$; + CommonBitfield common_$bitfield.name$ = TypeObjectUtils::build_common_bitfield(position_$bitfield.name$, flags_$bitfield.name$, bitcount_$bitfield.name$, holder_type_$bitfield.name$); + $empty_ann_builtin_complete_member_detail(member=bitfield, parent=parent, message=[parent.scopedname, " Bitset ", bitfield.name, " bitfield: no builtin annotation applies to bitfield declaration"], name=name)$ + CompleteBitfield bitfield_$bitfield.name$ = TypeObjectUtils::build_complete_bitfield(common_$bitfield.name$, detail_$bitfield.name$); + TypeObjectUtils::add_complete_bitfield(field_seq_$parent.name$, bitfield_$bitfield.name$); +} +>> + +register_sequence_type(sequence, name) ::= << +$! TODO(jlbueno): annotated collections generate TypeObject instead of TypeIdentifier + pending implementation of annotated collection support !$ +$plain_collection_header(type=sequence.contentTypeCode, message="Sequence element", name=name, collection_name=sequence_name(sequence))$ +std::string type_id_kind_$sequence_name(sequence)$("$sequence.typeIdentifier$"); +if (type_id_kind_$sequence_name(sequence)$ == "TI_PLAIN_SEQUENCE_SMALL") +{ + SBound bound = $if (!sequence.isBounded)$0$else$static_cast($sequence.evaluatedMaxsize$)$endif$; + PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_$sequence_name(sequence)$, bound, + eprosima::fastcdr::external(element_identifier_$sequence_name(sequence)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "$sequence_name(sequence)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$sequence_name(sequence)$ already registered in TypeObjectRegistry for a different type."); + } +} +else +{ + LBound bound = $sequence.evaluatedMaxsize$; + PlainSequenceLElemDefn seq_ldefn = TypeObjectUtils::build_plain_sequence_l_elem_defn(header_$sequence_name(sequence)$, bound, + eprosima::fastcdr::external(element_identifier_$sequence_name(sequence)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_sequence_type_identifier(seq_ldefn, "$sequence_name(sequence)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$sequence_name(sequence)$ already registered in TypeObjectRegistry for a different type."); + } +} +$get_type_identifier_registry(typename=sequence_name(sequence), name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$sequence_name(sequence)$: Given Sequence TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +register_array_type(array, name) ::= << +$! TODO(jlbueno): annotated collections generate TypeObject instead of TypeIdentifier + pending implementation of annotated collection support !$ +$plain_collection_header(type=array.contentTypeCode, message="Array element", name=name, collection_name=array_name(array))$ +std::string type_id_kind_$array_name(array)$("$array.typeIdentifier$"); +if (type_id_kind_$array_name(array)$ == "TI_PLAIN_ARRAY_SMALL") +{ + SBoundSeq array_bound_seq; + $array.evaluatedDimensions: { dimension | + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast($dimension$)); + }; separator="\n"$ + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_$array_name(array)$, array_bound_seq, + eprosima::fastcdr::external(element_identifier_$array_name(array)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "$array_name(array)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$array_name(array)$ already registered in TypeObjectRegistry for a different type."); + } +} +else +{ + LBoundSeq array_bound_seq; + $array.evaluatedDimensions: { dimension | + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast($dimension$)); + }; separator="\n"$ + PlainArrayLElemDefn array_ldefn = TypeObjectUtils::build_plain_array_l_elem_defn(header_$array_name(array)$, array_bound_seq, + eprosima::fastcdr::external(element_identifier_$array_name(array)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_array_type_identifier(array_ldefn, "$array_name(array)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$array_name(array)$ already registered in TypeObjectRegistry for a different type."); + } +} +$get_type_identifier_registry(typename=array_name(array), name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$array_name(array)$: Given Array TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +register_map_type(map, name) ::= << +$! TODO(jlbueno): annotated collections generate TypeObject instead of TypeIdentifier + pending implementation of annotated collection support !$ +$get_type_identifier(type=map.valueTypeCode, name=name)$ +$check_register_type_identifier(type=map.valueTypeCode, message="Map element", name=name)$ +TypeIdentifier* element_identifier_$map_name(map)$ {nullptr}; +$check_first_returned_type_identifier_pair(name=name)$ +{ + element_identifier_$map_name(map)$ = new TypeIdentifier(type_ids_$name$.type_identifier1()); +} +$check_second_returned_type_identifier_pair(name=name)$ +{ + element_identifier_$map_name(map)$ = new TypeIdentifier(type_ids_$name$.type_identifier2()); +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$map_name(map)$ inconsistent element TypeIdentifier."); + return; +} +$get_type_identifier(type=map.keyTypeCode, name=name)$ +$check_register_type_identifier(type=map.keyTypeCode, message="Map key", name=name)$ +TypeIdentifier* key_identifier_$map_name(map)$ {nullptr}; +$check_first_returned_type_identifier_pair(name=name)$ +{ + key_identifier_$map_name(map)$ = new TypeIdentifier(type_ids_$name$.type_identifier1()); +} +$check_second_returned_type_identifier_pair(name=name)$ +{ + key_identifier_$map_name(map)$ = new TypeIdentifier(type_ids_$name$.type_identifier2()); +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$map_name(map)$ inconsistent key TypeIdentifier."); + return; +} +EquivalenceKind equiv_kind_$map_name(map)$ = EK_BOTH; +if (EK_COMPLETE == element_identifier_$map_name(map)$->_d() || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->map_sdefn().header().equiv_kind()) || + (TI_PLAIN_MAP_LARGE == element_identifier_$map_name(map)$->_d() && EK_COMPLETE == element_identifier_$map_name(map)$->map_ldefn().header().equiv_kind())) +{ + equiv_kind_$map_name(map)$ = EK_COMPLETE; +} +$! TODO(jlbueno) Annotated collections not yet supported !$ +CollectionElementFlag element_flags_$map_name(map)$ = 0; +CollectionElementFlag key_flags_$map_name(map)$ = 0; +PlainCollectionHeader header_$map_name(map)$ = TypeObjectUtils::build_plain_collection_header(equiv_kind_$map_name(map)$, element_flags_$map_name(map)$); +std::string type_id_kind_$map_name(map)$("$map.typeIdentifier$"); +if (type_id_kind_$map_name(map)$ == "TI_PLAIN_MAP_SMALL") +{ + SBound bound = $if (!map.isBounded)$0$else$static_cast($map.evaluatedMaxsize$)$endif$; + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_$map_name(map)$, bound, + eprosima::fastcdr::external(element_identifier_$map_name(map)$), key_flags_$map_name(map)$, + eprosima::fastcdr::external(key_identifier_$map_name(map)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "$map_name(map)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$map_name(map)$ already registered in TypeObjectRegistry for a different type."); + } +} +else +{ + LBound bound = $map.evaluatedMaxsize$; + PlainMapLTypeDefn map_ldefn = TypeObjectUtils::build_plain_map_l_type_defn(header_$map_name(map)$, bound, + eprosima::fastcdr::external(element_identifier_$map_name(map)$), key_flags_$map_name(map)$, + eprosima::fastcdr::external(key_identifier_$map_name(map)$)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_map_type_identifier(map_ldefn, "$map_name(map)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$map_name(map)$ already registered in TypeObjectRegistry for a different type."); + } +} +$get_type_identifier_registry(typename=map_name(map), name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$map_name(map)$: Given Map TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +register_enum_type(enum, name) ::= << +EnumTypeFlag enum_flags_$enum.name$ = 0; +BitBound bit_bound_$enum.name$ = $enum.bitBound$; +CommonEnumeratedHeader common_$enum.name$ = TypeObjectUtils::build_common_enumerated_header(bit_bound_$enum.name$); +$complete_type_detail(type=enum, type_kind=" Enum", name=name)$ +CompleteEnumeratedHeader header_$enum.name$ = TypeObjectUtils::build_complete_enumerated_header(common_$enum.name$, detail_$enum.name$); +CompleteEnumeratedLiteralSeq literal_seq_$enum.name$; +$enum.members: { member | $enum_literal(literal=member, parent=enum, name=name)$}; separator="\n"$ +CompleteEnumeratedType enumerated_type_$enum.name$ = TypeObjectUtils::build_complete_enumerated_type(enum_flags_$enum.name$, header_$enum.name$, + literal_seq_$enum.name$); +if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_$enum.name$, type_name_$enum.name$.to_string())) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$enum.scopedname$ already registered in TypeObjectRegistry for a different type."); +} +$get_type_identifier_registry(typename=enum.scopedname, name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$enum.scopedname$: Given Enum TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +enum_literal(literal, parent, name) ::= << +{ + EnumeratedLiteralFlag flags_$literal.name$ = TypeObjectUtils::build_enumerated_literal_flag($literal.annotationDefaultLiteral$); + CommonEnumeratedLiteral common_$literal.name$ = TypeObjectUtils::build_common_enumerated_literal($literal.index$, flags_$literal.name$); + $empty_ann_builtin_complete_member_detail(member=literal, parent=parent, message=[parent.scopedname, " Enumerated ", literal.name, " literal: only @default_literal and @value builtin annotations apply to literals"], name=name)$ + CompleteEnumeratedLiteral literal_$literal.name$ = TypeObjectUtils::build_complete_enumerated_literal(common_$literal.name$, detail_$literal.name$); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_$parent.name$, literal_$literal.name$); +} +>> + +register_bitmask_type(bitmask, name) ::= << +BitmaskTypeFlag bitmask_flags_$bitmask.name$ = 0; +BitBound bit_bound_$bitmask.name$ = $bitmask.bitBound$; +CommonEnumeratedHeader common_$bitmask.name$ = TypeObjectUtils::build_common_enumerated_header(bit_bound_$bitmask.name$, true); +$complete_type_detail(type=bitmask, type_kind=" Bitmask", name=name)$ +CompleteEnumeratedHeader header_$bitmask.name$ = TypeObjectUtils::build_complete_enumerated_header(common_$bitmask.name$, detail_$bitmask.name$, true); +CompleteBitflagSeq flag_seq_$bitmask.name$; +$bitmask.bitmasks: { bitflag | $bitflag_member(bitflag=bitflag, parent=bitmask, name=name)$}; separator="\n"$ +CompleteBitmaskType bitmask_type_$bitmask.name$ = TypeObjectUtils::build_complete_bitmask_type(bitmask_flags_$bitmask.name$, header_$bitmask.name$, flag_seq_$bitmask.name$); +if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_bitmask_type_object(bitmask_type_$bitmask.name$, type_name_$bitmask.name$.to_string())) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$bitmask.scopedname$ already registered in TypeObjectRegistry for a different type."); +} +$get_type_identifier_registry(typename=bitmask.scopedname, name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$bitmask.scopedname$: Given Enum TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +bitflag_member(bitflag, parent, name) ::= << +{ + uint16_t position_$bitflag.name$ = $bitflag.position$; + BitflagFlag flags_$bitflag.name$ = 0; + CommonBitflag common_$bitflag.name$ = TypeObjectUtils::build_common_bitflag(position_$bitflag.name$, flags_$bitflag.name$); + $empty_ann_builtin_complete_member_detail(member=bitflag, parent=parent, message=[parent.scopedname, " Bitmask ", bitflag.name, " bitflag: only @position builtin annotation apply to bitmask bitflags"], name=name)$ + CompleteBitflag bitflag_$bitflag.name$ = TypeObjectUtils::build_complete_bitflag(common_$bitflag.name$, detail_$bitflag.name$); + TypeObjectUtils::add_complete_bitflag(flag_seq_$parent.name$, bitflag_$bitflag.name$); +} +>> + +register_wstring_type(wstring, name) ::= << +std::string type_id_kind_$wstring_name(wstring)$("$wstring.typeIdentifier$"); +if (type_id_kind_$wstring_name(wstring)$ == "TI_STRING16_SMALL") +{ + SBound bound = $if (!wstring.isBounded)$0$else$static_cast($wstring.evaluatedMaxsize$)$endif$; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "$wstring_name(wstring)$", true)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$wstring_name(wstring)$ already registered in TypeObjectRegistry for a different type."); + } +} +else if (type_id_kind_$wstring_name(wstring)$ == "TI_STRING16_LARGE") +{ + LBound bound = $wstring.evaluatedMaxsize$; + StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn, + "$wstring_name(wstring)$", true)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$wstring_name(wstring)$ already registered in TypeObjectRegistry for a different type."); + } +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$wstring_name(wstring)$: Unknown WString kind."); + return; +} +$get_type_identifier_registry(typename=wstring_name(wstring), name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$wstring_name(wstring)$: Given WString TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +register_string_type(string, name) ::= << +std::string type_id_kind_$string_name(string)$("$string.typeIdentifier$"); +if (type_id_kind_$string_name(string)$ == "TI_STRING8_SMALL") +{ + SBound bound = $if (!string.isBounded)$0$else$static_cast($string.evaluatedMaxsize$)$endif$; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "$string_name(string)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$string_name(string)$ already registered in TypeObjectRegistry for a different type."); + } +} +else if (type_id_kind_$string_name(string)$ == "TI_STRING8_LARGE") +{ + LBound bound = $string.evaluatedMaxsize$; + StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn, + "$string_name(string)$")) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$string_name(string)$ already registered in TypeObjectRegistry for a different type."); + } +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$string_name(string)$: Unknown String kind."); + return; +} +$get_type_identifier_registry(typename=string_name(string), name=name)$ +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$string_name(string)$: Given String TypeIdentifier unknown to TypeObjectRegistry."); + return; +} +>> + +complete_type_detail(type, type_kind, name) ::= << +QualifiedTypeName type_name_$type.name$ = "$type.scopedname$"; +eprosima::fastcdr::optional type_ann_builtin_$type.name$; +eprosima::fastcdr::optional ann_custom_$type.name$; +$type_annotations(type=type, type_kind=type_kind, name=name)$ +CompleteTypeDetail detail_$type.name$ = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_$type.name$, ann_custom_$type.name$, type_name_$type.name$.to_string()); +>> + +complete_member_detail(member, parent, type_kind, name) ::= << +MemberName name_$member.name$ = "$member.name$"; +eprosima::fastcdr::optional member_ann_builtin_$member.name$; +ann_custom_$parent.name$.reset(); +$if (member.annotationList)$ +AppliedAnnotationSeq tmp_ann_custom_$member.name$; +eprosima::fastcdr::optional unit_$member.name$; +eprosima::fastcdr::optional min_$member.name$; +eprosima::fastcdr::optional max_$member.name$; +eprosima::fastcdr::optional hash_id_$member.name$; +$member.annotationList : { annotation | +$if (annotation.isUnit)$ +unit_$member.name$ = $annotation.value$; +$elseif (annotation.isMin || annotation.isMax || annotation.isRange)$ +EPROSIMA_LOG_WARNING(XTYPES_TYPE_REPRESENTATION, + "$parent.scopedname$ $type_kind$ $member.name$ member: @min, @max, and @range builtin annotations not yet supported"); +$elseif (annotation.isHashId)$ +$if (annotation.value)$ +hash_id_$member.name$ = "$annotation.value$"; +$endif$ +$elseif (!annotation.isBuiltin)$ +$applied_annotation_sequence(annotation=annotation, typename=[parent.scopedname, " ", member.name, " member"], member=member, name=name)$ +$endif$ +}; separator="\n"$ +if (unit_$member.name$.has_value() || min_$member.name$.has_value() || max_$member.name$.has_value() || hash_id_$member.name$.has_value()) +{ + member_ann_builtin_$member.name$ = TypeObjectUtils::build_applied_builtin_member_annotations(unit_$member.name$, min_$member.name$, max_$member.name$, hash_id_$member.name$); +} +if (!tmp_ann_custom_$member.name$.empty()) +{ + ann_custom_$parent.name$ = tmp_ann_custom_$member.name$; +} +$endif$ +CompleteMemberDetail detail_$member.name$ = TypeObjectUtils::build_complete_member_detail(name_$member.name$, member_ann_builtin_$member.name$, ann_custom_$parent.name$); +>> + +empty_ann_builtin_complete_member_detail(member, parent, message, name) ::= << +eprosima::fastcdr::optional member_ann_builtin_$member.name$; +ann_custom_$parent.name$.reset(); +$if (member.annotationList)$ +AppliedAnnotationSeq tmp_ann_custom_$member.name$; +$member.annotationList : { annotation | +$if (annotation.isUnit || annotation.isMin || annotation.isMax || annotation.isRange || annotation.isHashId)$ +EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$message$"); +return; +$elseif (!annotation.isBuiltin)$ +$applied_annotation_sequence(annotation=annotation, typename=[parent.scopedname, " ", member.name, " member"], member=member, name=name)$ +$endif$ +}; separator="\n"$ +if (!tmp_ann_custom_$member.name$.empty()) +{ + ann_custom_$parent.name$ = tmp_ann_custom_$member.name$; +} +$endif$ +MemberName name_$member.name$ = "$member.name$"; +CompleteMemberDetail detail_$member.name$ = TypeObjectUtils::build_complete_member_detail(name_$member.name$, member_ann_builtin_$member.name$, ann_custom_$parent.name$); +>> + +type_annotations(type, type_kind, name) ::= << +$if (type.annotationList)$ +AppliedAnnotationSeq tmp_ann_custom_$type.name$; +eprosima::fastcdr::optional verbatim_$type.name$; +$type.annotationList : { annotation | +$if (annotation.isVerbatim)$ +$applied_verbatim_annotation(annotation=annotation, name=type.name)$ +$elseif (!annotation.isBuiltin)$ +$applied_annotation_sequence(annotation=annotation, typename=[type.scopedname, type_kind], member=type, name=name)$ +$endif$ +}; separator="\n"$ +if (!tmp_ann_custom_$type.name$.empty()) +{ + ann_custom_$type.name$ = tmp_ann_custom_$type.name$; +} +$endif$ +>> + +check_first_returned_type_identifier_pair(name) ::= << +if (EK_COMPLETE == type_ids_$name$.type_identifier1()._d() || TK_NONE == type_ids_$name$.type_identifier2()._d() || + (TI_PLAIN_SEQUENCE_SMALL == type_ids_$name$.type_identifier1()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier1().seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == type_ids_$name$.type_identifier1()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier1().seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == type_ids_$name$.type_identifier1()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier1().array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == type_ids_$name$.type_identifier1()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier1().array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == type_ids_$name$.type_identifier1()._d() && + (EK_COMPLETE == type_ids_$name$.type_identifier1().map_sdefn().header().equiv_kind() || + EK_COMPLETE == type_ids_$name$.type_identifier1().map_sdefn().key_identifier()->_d())) || + (TI_PLAIN_MAP_LARGE == type_ids_$name$.type_identifier1()._d() && + (EK_COMPLETE == type_ids_$name$.type_identifier1().map_ldefn().header().equiv_kind() || + EK_COMPLETE == type_ids_$name$.type_identifier1().map_ldefn().key_identifier()->_d()))) +>> + +check_second_returned_type_identifier_pair(name) ::= << +else if (EK_COMPLETE == type_ids_$name$.type_identifier2()._d() || + (TI_PLAIN_SEQUENCE_SMALL == type_ids_$name$.type_identifier2()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier2().seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == type_ids_$name$.type_identifier2()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier2().seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == type_ids_$name$.type_identifier2()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier2().array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == type_ids_$name$.type_identifier2()._d() && + EK_COMPLETE == type_ids_$name$.type_identifier2().array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == type_ids_$name$.type_identifier2()._d() && + (EK_COMPLETE == type_ids_$name$.type_identifier2().map_sdefn().header().equiv_kind() || + EK_COMPLETE == type_ids_$name$.type_identifier2().map_sdefn().key_identifier()->_d())) || + (TI_PLAIN_MAP_LARGE == type_ids_$name$.type_identifier2()._d() && + (EK_COMPLETE == type_ids_$name$.type_identifier2().map_ldefn().header().equiv_kind() || + EK_COMPLETE == type_ids_$name$.type_identifier2().map_ldefn().key_identifier()->_d()))) +>> + +check_register_type_identifier(type, message, name) ::= << +if (return_code_$name$ != eprosima::fastdds::dds::RETCODE_OK) +{ + $if (type.isAliasType)$ + $register_alias_type(alias=type, name=name)$ + $elseif (type.isStructType)$ + $register_struct_type(struct=type)$ + $elseif (type.isUnionType)$ + $register_union_type(union=type)$ + $elseif (type.isBitsetType)$ + $register_bitset_type(bitset=type, name=name)$ + $elseif (type.isSequenceType)$ + $register_sequence_type(sequence=type, name=name)$ + $elseif (type.isArrayType)$ + $register_array_type(array=type, name=name)$ + $elseif (type.isMapType)$ + $register_map_type(map=type, name=name)$ + $elseif (type.isEnumType)$ + $register_enum_type(enum=type, name=name)$ + $elseif (type.isBitmaskType)$ + $register_bitmask_type(bitmask=type, name=name)$ + $elseif (type.isStringType)$ + $register_string_type(string=type, name=name)$ + $elseif (type.isWStringType)$ + $register_wstring_type(wstring=type, name=name)$ + $else$ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$message$ TypeIdentifier unknown to TypeObjectRegistry."); + return; + $endif$ +} +>> + +extensibility(object) ::= <% +$if (object.annotationExtensibilityNotApplied)$ + eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, +$elseif (object.annotationAppendable)$ + eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, +$elseif (object.annotationFinal)$ + eprosima::fastdds::dds::xtypes::ExtensibilityKind::FINAL, +$elseif (object.annotationMutable)$ + eprosima::fastdds::dds::xtypes::ExtensibilityKind::MUTABLE, +$endif$ +%> + +try_construct(object) ::= <% +$if (!object.annotationTryConstruct)$ + eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, +$elseif (object.annotationDiscard)$ + eprosima::fastdds::dds::xtypes::TryConstructKind::DISCARD, +$elseif (object.annotationUseDefault)$ + eprosima::fastdds::dds::xtypes::TryConstructKind::USE_DEFAULT, +$elseif (object.annotationTrim)$ + eprosima::fastdds::dds::xtypes::TryConstructKind::TRIM, +$endif$ +%> + +plain_collection_header(type, message, name, collection_name) ::= << +$get_type_identifier(type=type, name=name)$ +$check_register_type_identifier(type=type, message=message, name=name)$ +TypeIdentifier* element_identifier_$collection_name$ {nullptr}; +$check_first_returned_type_identifier_pair(name=name)$ +{ + element_identifier_$collection_name$ = new TypeIdentifier(type_ids_$name$.type_identifier1()); +} +$check_second_returned_type_identifier_pair(name=name)$ +{ + element_identifier_$collection_name$ = new TypeIdentifier(type_ids_$name$.type_identifier2()); +} +else +{ + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "$message$ TypeIdentifier inconsistent."); + return; +} +EquivalenceKind equiv_kind_$collection_name$ = EK_COMPLETE; +if (TK_NONE == type_ids_$name$.type_identifier2()._d()) +{ + equiv_kind_$collection_name$ = EK_BOTH; +} +$! TODO(jlbueno) Annotated collections not yet supported !$ +CollectionElementFlag element_flags_$collection_name$ = 0; +PlainCollectionHeader header_$collection_name$ = TypeObjectUtils::build_plain_collection_header(equiv_kind_$collection_name$, element_flags_$collection_name$); +>> + +//{ Fast DDS-Gen extensions +module_conversion(ctx, parent, modules, definition_list) ::= << +$modules : { module | +namespace $module.name$ { +}; separator="\n"$ + +$definition_list$ + +$reverse(modules) : { module | +\} // namespace $module.name$ +}; separator="\n"$ +>> +//} diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg b/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg index af75fb28..618cb18f 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/eprosima.stg @@ -56,7 +56,7 @@ indexName(name, loopvar) ::= <<$name$[$loopvar$]>> //{ IDL-parser templates annotation(ctx, annotation) ::= <<>> -array_declarator(ctx, array, array_type) ::= <<>> +array_declarator(ctx, array) ::= <<>> bitmask_type(ctx, parent, bitmask) ::= <<>> @@ -70,19 +70,18 @@ definition_list(definitions) ::= << $definitions; separator="\n"$ >> -element_type(ctx, element, type_element, declarator) ::= << +element_type(ctx, element, type_element, declarator) ::= <% $type_element$ - $declarator$ ->> +%> enum_type(ctx, parent, enum) ::= <<>> exception(ctx, parent, exception) ::= <<>> -export_list(exports) ::= << +export_list(exports) ::= <% $exports; separator="\n"$ ->> +%> fwd_decl(ctx, parent, type) ::= <<>> @@ -90,59 +89,149 @@ interface(ctx, parent, interface, export_list) ::= << $export_list$ >> -map_type(ctx, map, key_type, value_type) ::= << +map_type(ctx, map, key_type, value_type) ::= <% $key_type$ - $value_type$ ->> +%> -member_type(ctx, member, type_member, declarators) ::= << +member_type(ctx, member, type_member, declarators) ::= <% $type_member$ - $declarators$ ->> +%> -module(ctx, parent, module, definition_list) ::= << +module(ctx, parent, module, definition_list) ::= <% $definition_list$ ->> +%> -operation(ctx, parent, operation, param_list, operation_type) ::= << +operation(ctx, parent, operation, param_list, operation_type) ::= <% $operation_type$ - $param_list$ ->> +%> param_list(parameters) ::= <<>> -param(parameter, parameter_type) ::= << +param(parameter, parameter_type) ::= <% $parameter_type$ ->> +%> -sequence_type(ctx, sequence, type_sequence) ::= << +sequence_type(ctx, sequence, type_sequence) ::= <% $type_sequence$ ->> +%> string_type(ctx, string) ::= <<>> -struct_type(ctx, parent, struct, member_list) ::= << +struct_type(ctx, parent, struct, member_list) ::= <% $member_list$ ->> +%> -typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= << +typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= <% $declarator_type$ - $typedefs_type$ ->> +%> -union_type(ctx, parent, union, extensions, switch_type) ::= << +union_type(ctx, parent, union, extensions, switch_type) ::= <% $switch_type$ ->> +%> wide_string_type(ctx, wstring) ::= <<>> //} //{ Fast DDS-Gen extensions -module_conversion(ctx, parent, modules, definition_list) ::= << +module_conversion(ctx, parent, modules, definition_list) ::= <% $definition_list$ +%> +//} + +//{ Anonymous collections generator name +sequence_name(sequence) ::= <% +$if(sequence.contentTypeCode.primitive && !sequence.contentTypeCode.isEnumType)$ +anonymous_sequence_$sequence.contentTypeCode.cppTypenameForTypeId$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$elseif (sequence.contentTypeCode.isStringType)$ +anonymous_sequence_$string_name(string=sequence.contentTypeCode)$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$elseif (sequence.contentTypeCode.isWStringType)$ +anonymous_sequence_$wstring_name(wstring=sequence.contentTypeCode)$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$elseif (sequence.contentTypeCode.isArrayType)$ +anonymous_sequence_$array_name(array=sequence.contentTypeCode)$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$elseif (sequence.contentTypeCode.isSequenceType)$ +anonymous_sequence_$sequence_name(sequence=sequence.contentTypeCode)$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$elseif (sequence.contentTypeCode.isMapType)$ +anonymous_sequence_$map_name(map=sequence.contentTypeCode)$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$else$ +anonymous_sequence_$sequence.contentTypeCode.CScopedname$_$if(sequence.unbound)$unbounded$else$$sequence.evaluatedMaxsize$$endif$ +$endif$ +%> + +map_name(map) ::= <% +$if(map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.primitive && !map.valueTypeCode.isEnumType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$map.valueTypeCode.cppTypenameForTypeId$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.isStringType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$string_name(string=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.isWStringType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$wstring_name(wstring=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.isArrayType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$array_name(array=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.isSequenceType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$sequence_name(sequence=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType && map.valueTypeCode.isMapType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$map_name(map=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.primitive && !map.keyTypeCode.isEnumType)$ +anonymous_map_$map.keyTypeCode.cppTypenameForTypeId$_$map.valueTypeCode.CScopedname$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif(map.keyTypeCode.isStringType && map.valueTypeCode.primitive && !map.valueTypeCode.isEnumType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$map.valueTypeCode.cppTypenameForTypeId$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType && map.valueTypeCode.isStringType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$string_name(string=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType && map.valueTypeCode.isWStringType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$wstring_name(wstring=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType && map.valueTypeCode.isArrayType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$array_name(array=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType && map.valueTypeCode.isSequenceType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$sequence_name(sequence=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType && map.valueTypeCode.isMapType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$map_name(map=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isStringType)$ +anonymous_map_$string_name(string=map.keyTypeCode)$_$map.valueTypeCode.CScopedname$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif(map.keyTypeCode.isWStringType && map.valueTypeCode.primitive && !map.valueTypeCode.isEnumType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$map.valueTypeCode.cppTypenameForTypeId$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType && map.valueTypeCode.isStringType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$string_name(string=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType && map.valueTypeCode.isWStringType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$wstring_name(wstring=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType && map.valueTypeCode.isArrayType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$array_name(array=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType && map.valueTypeCode.isSequenceType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$sequence_name(sequence=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType && map.valueTypeCode.isMapType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$map_name(map=map.valueTypeCode)$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$elseif (map.keyTypeCode.isWStringType)$ +anonymous_map_$wstring_name(wstring=map.keyTypeCode)$_$map.valueTypeCode.CScopedname$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$else$ +anonymous_map_$map.keyTypeCode.CScopedname$_$map.valueTypeCode.CScopedname$_$if(map.isBounded)$$map.evaluatedMaxsize$$else$unbounded$endif$ +$endif$ +%> + +array_name(array) ::= <% +$if(array.contentTypeCode.primitive && !array.contentTypeCode.isEnumType)$ +anonymous_array_$array.contentTypeCode.cppTypenameForTypeId$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$elseif (array.contentTypeCode.isStringType)$ +anonymous_array_$string_name(string=array.contentTypeCode)$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$elseif (array.contentTypeCode.isWStringType)$ +anonymous_array_$wstring_name(wstring=array.contentTypeCode)$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$elseif (array.contentTypeCode.isArrayType)$ +anonymous_array_$array_name(array=array.contentTypeCode)$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$elseif (array.contentTypeCode.isSequenceType)$ +anonymous_array_$sequence_name(sequence=array.contentTypeCode)$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$elseif (array.contentTypeCode.isMapType)$ +anonymous_array_$map_name(map=array.contentTypeCode)$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$else$ +anonymous_array_$array.contentTypeCode.CScopedname$$array.evaluatedDimensions : { dimension | _$dimension$}$ +$endif$ +%> + +string_name(string) ::= << +anonymous_string_$if(string.isBounded)$$string.evaluatedMaxsize$$else$unbounded$endif$ +>> + +wstring_name(wstring) ::= << +anonymous_wstring_$if(wstring.isBounded)$$wstring.evaluatedMaxsize$$else$unbounded$endif$ >> //}