Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20129] TypeObject generation #280

Merged
merged 57 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b816783
Typeobjects with tests (#255)
adriancampo Nov 28, 2023
3e9d586
Refs #19906: introduce new templates to generate TypeObject code
JLBuenoLopez Nov 13, 2023
36acca2
Refs #19906: TypeObject header implementation
JLBuenoLopez Nov 14, 2023
3a49617
Refs #19906: minor fixes
JLBuenoLopez Nov 28, 2023
895fc1d
Refs #19906: move anonymous collection name generator to common code
JLBuenoLopez Nov 28, 2023
a61cb1d
Refs #19906: skeleton
JLBuenoLopez Nov 28, 2023
e4ff723
Refs #19906: improve verbatim annotation test. Alias custom annotatio…
JLBuenoLopez Nov 29, 2023
e6cc28e
Refs #19906: fix typo
JLBuenoLopez Nov 30, 2023
3ee3610
Refs #19906: alias type implementation
JLBuenoLopez Nov 30, 2023
7021a7a
Refs #19906: struct_type implementation
JLBuenoLopez Nov 30, 2023
740670d
Refs #19906: fix sequential member id
JLBuenoLopez Dec 4, 2023
fd5699b
Refs #19906: struct members
JLBuenoLopez Dec 4, 2023
f4378b3
Refs #19906: refactor TypeObjectSupport infrastructure
JLBuenoLopez Dec 4, 2023
19e0e4b
Refs #19906: refactor TypeObjectSupport
JLBuenoLopez Dec 4, 2023
628f201
Refs #19906: do not execute code in main function
JLBuenoLopez Dec 4, 2023
af4b0da
Refs #19906: assign proper member id with inheritance
JLBuenoLopez Dec 5, 2023
7943d57
Refs #19906: refactor register struct type
JLBuenoLopez Dec 5, 2023
84173b8
Refs #19906: fix calling templates with proper parameters
JLBuenoLopez Dec 5, 2023
2f79737
Refs #19906: annotation impl
JLBuenoLopez Dec 5, 2023
2e667a1
Refs #19906: enum impl
JLBuenoLopez Dec 5, 2023
307d613
Refs #19906: w/string impl
JLBuenoLopez Dec 5, 2023
70ce7aa
Refs #19906: several fixes in tests
JLBuenoLopez Dec 7, 2023
4f577c4
Refs #19906: alias impl. Annotation refactor
JLBuenoLopez Dec 7, 2023
0b46ef3
Refs #19906: fix get TypeObject template
JLBuenoLopez Dec 7, 2023
7bd6a43
Refs #19906: union impl
JLBuenoLopez Dec 7, 2023
5f06776
Refs #19906: union member impl
JLBuenoLopez Dec 11, 2023
b6b2acb
Refs #19906: bitset impl
JLBuenoLopez Dec 11, 2023
24b8945
Refs #19906: bitmask impl
JLBuenoLopez Dec 11, 2023
cd24fe2
Refs #19906: sequences impl
JLBuenoLopez Dec 12, 2023
7c5e442
Refs #19906: small refactor to adapt to new throwing API
JLBuenoLopez Dec 12, 2023
ae95254
Refs #19906: update unbounded collections name
JLBuenoLopez Dec 12, 2023
6668db9
Refs #19906: arrays impl
JLBuenoLopez Dec 12, 2023
07e3311
Refs #19906: map impl
JLBuenoLopez Dec 12, 2023
4b54b3f
Refs #20129: support for not applied annotations
JLBuenoLopez Dec 13, 2023
0619084
Refs #20129: generate TypeObject tests only for main dependency
JLBuenoLopez Dec 13, 2023
5b65237
Refs #20129: fix expected flags
JLBuenoLopez Dec 13, 2023
8b775c9
Refs #20129: option to avoid generating type object support files
JLBuenoLopez Dec 19, 2023
205325e
Refs #20129: delete legacy TypeObject template
JLBuenoLopez Dec 20, 2023
69c917b
Refs #20129: integration, fix use of external and other minor bugs/typos
JLBuenoLopez Dec 20, 2023
b380084
Refs #20129: test integration: fix unbounded collections, correctly t…
JLBuenoLopez Dec 20, 2023
fbfddfe
Refs #20129: use variables
JLBuenoLopez Dec 20, 2023
b645951
Refs #20129: fix conflicts after rebase
JLBuenoLopez Dec 20, 2023
4fc97fc
Refs #20129: no type support option disables also TypeObject support …
JLBuenoLopez Dec 21, 2023
a87fad9
Refs #20129: fix Fast DDS include
JLBuenoLopez Dec 21, 2023
0d24e7e
Refs #20129: avoid warning
JLBuenoLopez Dec 21, 2023
e6258e8
Refs #20129: use genapi module conversion in TypeObject templates
JLBuenoLopez Dec 29, 2023
5009e93
Refs #20129: apply review suggestions
JLBuenoLopez Jan 9, 2024
e51a9e7
Refs #20129: create register_type_object_representation method in Typ…
JLBuenoLopez Jan 9, 2024
2e546a4
Refs #20129: fix map keys
JLBuenoLopez Jan 11, 2024
388c157
Refs #20129: add sequence order check and fixes in map keys and minim…
JLBuenoLopez Jan 11, 2024
e6c0e73
Refs #20129: update IDL Parser submodule
JLBuenoLopez Jan 15, 2024
da2bfad
Refs #20129: fix Windows warnings C4456: declararion hides previous l…
JLBuenoLopez Jan 16, 2024
74fae95
Refs #20129: fix collection name in case of enum types
JLBuenoLopez Jan 16, 2024
27f47fc
Refs #20129: update IDL Parser submodule
JLBuenoLopez Jan 16, 2024
16fea83
Refs #20129: fix Windows warning
JLBuenoLopez Jan 16, 2024
5e50497
Refs #20129: update IDL Parser submodule
JLBuenoLopez Jan 16, 2024
1cd7945
Refs #20129: apply review suggestions
JLBuenoLopez Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/Custom.stg
Original file line number Diff line number Diff line change
Expand Up @@ -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) ::= <<>>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/eprosima/fastcdr/idl/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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$
}

/*!
Expand Down Expand Up @@ -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$
}

/*!
Expand Down
104 changes: 60 additions & 44 deletions src/main/java/com/eprosima/fastdds/fastddsgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

/*
* ----------------------------------------------------------------------------------------
*
Expand Down Expand Up @@ -307,11 +307,16 @@ else if (languageOption.equalsIgnoreCase("java"))
else if (arg.equals(no_typesupport_arg))
{
generate_typesupport_ = false;
generate_typeobjectsupport_ = false;
adriancampo marked this conversation as resolved.
Show resolved Hide resolved
}
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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -627,15 +629,15 @@ public static void printHelp()
System.out.println("\t\t" + include_path_arg + " <path>: add directory to preprocessor include paths.");
System.out.println("\t\t" + language_arg + " <lang>: chooses between <c++> or <java> 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.");
richiware marked this conversation as resolved.
Show resolved Hide resolved
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.");
System.out.println("\t\t" + preprocessor_path_arg + ": specifies the preprocessor path.");
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 + " <temp dir>: 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.");
Expand Down Expand Up @@ -729,7 +731,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;
Expand Down Expand Up @@ -768,11 +770,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_)
Expand All @@ -781,6 +778,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)
Expand All @@ -803,6 +806,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.
Expand Down Expand Up @@ -851,8 +860,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();;

Expand Down Expand Up @@ -908,32 +916,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)
Expand All @@ -960,11 +953,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 &=
Expand Down Expand Up @@ -1668,7 +1684,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());
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));

}

Expand Down Expand Up @@ -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 ()
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ 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) ::= <<

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$
Expand All @@ -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$
>>
Loading
Loading