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

[21397] Parse IDL string for xtypes #4943

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d78d835
Implement idl parser (in progress)
YangboLong Jun 13, 2024
f376d22
Adapt literals and expressions parsing to new xtype APIs
YangboLong Jun 15, 2024
7c71784
Compile code in Windows
YangboLong Jun 24, 2024
ef38637
Fix alias parsing
YangboLong Jun 30, 2024
8e6f98c
Fix code to run through example in Linux
YangboLong Jul 1, 2024
fc768ab
Fix format and compile warnings
YangboLong Aug 1, 2024
8a2c2ac
Fix type for parsing integer literals
YangboLong Aug 1, 2024
dbf3db1
Fix union default label parsing
YangboLong Aug 3, 2024
110a0bc
Support create_type_w_document
YangboLong Aug 10, 2024
20aa84b
Remove example
YangboLong Aug 10, 2024
6fada1a
Capture exceptions before return to user code
YangboLong Aug 10, 2024
2080ec7
Implement get_temporary_file
YangboLong Aug 12, 2024
c055b5e
Build with EPROSIMA_BUILD_TESTS=ON
YangboLong Aug 18, 2024
e15b0a4
Add unit tests
YangboLong Sep 6, 2024
56adb68
Build and run tests on Linux
YangboLong Sep 28, 2024
e010e6b
Parse basic_inner_types.idl
YangboLong Oct 4, 2024
6229f42
Parse structures.idl (in progress)
YangboLong Oct 8, 2024
34b7b2d
Fix struct member type/name parsing and const parsing
YangboLong Oct 10, 2024
449b37a
Fix struct parsing when struct members have arrays
YangboLong Oct 12, 2024
576bc26
Skip sequence and map parsing
YangboLong Oct 12, 2024
e15abf3
Test structures.idl with proper comments
YangboLong Oct 12, 2024
4b4c219
Test alases.idl
YangboLong Oct 13, 2024
36e4b77
Try fixing ci/cd
YangboLong Oct 15, 2024
19f06de
Fix struct parsing with member being array
YangboLong Oct 18, 2024
371976e
Allow positive_int_const to be const_expr
YangboLong Oct 23, 2024
acb0497
Parse arrays.idl (in progress)
YangboLong Oct 25, 2024
237e27d
Handle scoped names in arithmetic expressions
YangboLong Oct 30, 2024
d7eeaab
Finish arrays.idl testing
YangboLong Nov 3, 2024
6617989
Test relative_path_include.idl
YangboLong Nov 4, 2024
3cec731
Start to test unions.idl
YangboLong Nov 9, 2024
64189c7
Fix union case label parsing
YangboLong Nov 9, 2024
cf3fcee
Finish unions.idl testing
YangboLong Nov 10, 2024
d9a1abb
Fix internal error spews
YangboLong Nov 23, 2024
3c16ba5
Try fixing ci/cd errors
YangboLong Dec 5, 2024
64d50f4
Address PR comments
YangboLong Dec 22, 2024
4e9793f
Escape separator in CMake path variable
MiguelCompany Jan 3, 2025
fe2b456
Add API to set preprocessor path.
MiguelCompany Jan 7, 2025
3722f66
Split preprocessor and flags.
MiguelCompany Jan 7, 2025
09035d8
Pass preprocessor to IDL parser.
MiguelCompany Jan 7, 2025
d8229c5
Set preprocessor on tests
MiguelCompany Jan 7, 2025
de5b3d3
Move idl parser implementation to create_type_w_uri
YangboLong Jan 9, 2025
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(MSVC OR MSVC_IDE)
# C4715: 'Test': not all control paths return a value
# C5038 data member 'member1' will be initialized after data member 'member2'
# C4100 'identifier' : unreferenced formal parameter (matches clang -Wunused-lambda-capture)
add_compile_options(/w34101 /w34189 /w34555 /w34715 /w35038 /w44100)
add_compile_options(/w34101 /w34189 /w34555 /w34715 /w35038 /w44100 /bigobj)

if(EPROSIMA_BUILD)
string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ class DynamicTypeBuilderFactory : public std::enable_shared_from_this<DynamicTyp
FASTDDS_EXPORTED_API virtual traits<DynamicTypeBuilder>::ref_type create_bitmask_type(
uint32_t bound) = 0;

/*!
* Sets the path to the preprocessor executable to be used when parsing type descriptions.
* @param [in] preprocessor path to the preprocessor executable.
*/
FASTDDS_EXPORTED_API virtual void set_preprocessor(
const std::string& preprocessor) = 0;

/*!
* Creates a new @ref DynamicTypeBuilder reference by parsing the type description at the given URL.
* @remark Not implemented yet.
* @param [in] document_url pointing to the url containing the type description.
* @param [in] type_name Fully qualified name of the type to be loaded from the document.
* @param [in] include_paths A collection of URLs to directories to be searched for additional type description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@
#include <fastdds/xtypes/type_representation/TypeObjectRegistry.hpp>
#include <rtps/RTPSDomainImpl.hpp>

#include "idl_parser/Idl.hpp"

namespace eprosima {
namespace fastdds {
namespace dds {

traits<DynamicTypeBuilderFactoryImpl>::ref_type DynamicTypeBuilderFactoryImpl::instance_;

//{{{ Utility functions

void DynamicTypeBuilderFactoryImpl::set_preprocessor(
const std::string& preprocessor)
{
preprocessor_ = preprocessor;
}

//}}}

//{{{ Functions to create types

traits<DynamicTypeBuilder>::ref_type DynamicTypeBuilderFactoryImpl::create_type(
Expand Down Expand Up @@ -175,11 +187,20 @@ traits<DynamicTypeBuilder>::ref_type DynamicTypeBuilderFactoryImpl::create_type_
const std::string& type_name,
const IncludePathSeq& include_paths) noexcept
{
traits<DynamicTypeBuilder>::ref_type nil;
static_cast<void>(document_url);
static_cast<void>(type_name);
static_cast<void>(include_paths);
return nil;
traits<DynamicTypeBuilder>::ref_type ret_val;

try
{
idlparser::Context context = idlparser::parse_file(document_url, type_name, include_paths, preprocessor_);
ret_val = context.builder;
}
catch (const std::exception& e)
{
EPROSIMA_LOG_ERROR(IDLPARSER, e.what());
ret_val.reset();
}

return ret_val;
}

//}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class DynamicTypeBuilderFactoryImpl : public traits<DynamicTypeBuilderFactory>::
{
public:

//{{{ Utility functions

void set_preprocessor(
const std::string& preprocessor) override;

//}}}

//{{{ Functions to create types

traits<DynamicTypeBuilder>::ref_type create_type(
Expand Down Expand Up @@ -197,6 +204,9 @@ class DynamicTypeBuilderFactoryImpl : public traits<DynamicTypeBuilderFactory>::
traits<DynamicTypeImpl>::ref_type char16_type_ {std::make_shared<DynamicTypeImpl>(TypeDescriptorImpl{TK_CHAR16,
""})};
//}}}

//! Path to the preprocessor executable to be used when parsing type descriptions.
std::string preprocessor_{};
};

} // namespace dds
Expand Down
100 changes: 100 additions & 0 deletions src/cpp/fastdds/xtypes/dynamic_types/idl_parser/Idl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2024 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.

#ifndef FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDL_HPP
#define FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDL_HPP

#include "IdlParser.hpp"

#include <sstream>

namespace eprosima {
namespace fastdds {
namespace dds {
namespace idlparser {

/// \brief Parse IDL string input, conforming to IDL specification V4.2.
/// \param[in] idl An IDL string to parse into DynamicTypes
/// \return A Context object with data related to the parse output
inline Context parse(
const std::string& idl)
{
return Parser::instance()->parse_string(idl);
}

/// \brief Parse IDL string input with an existent context, conforming to IDL specification V4.2.
/// \param[in] idl An IDL string to parse into DynamicTypes
/// \param[in] context An existent Context object
/// \return A Context object with data related to the parse output
inline Context& parse(
const std::string& idl,
Context& context)
{
Parser::instance()->parse_string(idl, context);
return context;
}

/// \brief Parse IDL file input, conforming to IDL specification V4.2.
/// \param[in] idl_file Path to the IDL file
/// \return A Context object with data related to the parse output
inline Context parse_file(
const std::string& idl_file)
{
return Parser::instance()->parse_file(idl_file);
}

/// \brief Parse IDL file input with an existent context, conforming to IDL specification V4.2.
/// \param[in] idl_file Path to the IDL file
/// \param[in] context An existent Context object
/// \return A Context object with data related to the parse output
inline Context& parse_file(
const std::string& idl_file,
Context& context)
{
Parser::instance()->parse_file(idl_file, context);
return context;
}

/// \brief Parse IDL file input and save the DynamicTypeBuilder object corresponding to the given target type name,
/// conforming to IDL specification V4.2.
/// \param[in] idl_file Path to the IDL file
/// \param[in] type_name Fully qualified target type name to load from the IDL file
/// \param[in] include_paths A collection of directories to search for additional type description
/// \return A Context object with data related to the parse output
inline Context parse_file(
const std::string& idl_file,
const std::string& type_name,
const IncludePathSeq& include_paths,
const std::string& preprocessor)
{
return Parser::instance()->parse_file(idl_file, type_name, include_paths, preprocessor);
}

/// \brief Preprocess IDL file.
/// \param[in] idl_file Path to the IDL file
/// \param[in] includes A collection of directories to search for additional type description
/// \return Preprocessed IDL string
inline std::string preprocess(
const std::string& idl_file,
const std::vector<std::string>& includes)
{
return Parser::preprocess(idl_file, includes);
}

} //namespace idlparser
} //namespace dds
} //namespace fastdds
} //namespace eprosima

#endif //FASTDDS_XTYPES_DYNAMIC_TYPES_IDL_PARSER_IDL_HPP
Loading
Loading