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 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3f13f8a
Implement idl parser (in progress)
YangboLong Jun 13, 2024
e6c25e5
Adapt literals and expressions parsing to new xtype APIs
YangboLong Jun 15, 2024
f02c44e
Compile code in Windows
YangboLong Jun 24, 2024
6718735
Fix alias parsing
YangboLong Jun 30, 2024
7027ee8
Fix code to run through example in Linux
YangboLong Jul 1, 2024
e611e00
Fix format and compile warnings
YangboLong Aug 1, 2024
eec4d6e
Fix type for parsing integer literals
YangboLong Aug 1, 2024
e02b580
Fix union default label parsing
YangboLong Aug 3, 2024
10d8644
Support create_type_w_document
YangboLong Aug 10, 2024
09db307
Remove example
YangboLong Aug 10, 2024
733f6a7
Capture exceptions before return to user code
YangboLong Aug 10, 2024
a548593
Implement get_temporary_file
YangboLong Aug 12, 2024
bf7a913
Build with EPROSIMA_BUILD_TESTS=ON
YangboLong Aug 18, 2024
156e2f7
Add unit tests
YangboLong Sep 6, 2024
fee563d
Build and run tests on Linux
YangboLong Sep 28, 2024
ecf902b
Parse basic_inner_types.idl
YangboLong Oct 4, 2024
76d3f4e
Parse structures.idl (in progress)
YangboLong Oct 8, 2024
3266ce6
Fix struct member type/name parsing and const parsing
YangboLong Oct 10, 2024
311dd2e
Fix struct parsing when struct members have arrays
YangboLong Oct 12, 2024
4302d64
Skip sequence and map parsing
YangboLong Oct 12, 2024
324c70c
Test structures.idl with proper comments
YangboLong Oct 12, 2024
eea1733
Test alases.idl
YangboLong Oct 13, 2024
0c5855a
Try fixing ci/cd
YangboLong Oct 15, 2024
47d848b
Fix struct parsing with member being array
YangboLong Oct 18, 2024
ca48b16
Allow positive_int_const to be const_expr
YangboLong Oct 23, 2024
0cf90de
Parse arrays.idl (in progress)
YangboLong Oct 25, 2024
f5d585e
Handle scoped names in arithmetic expressions
YangboLong Oct 30, 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 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 @@ -31,6 +31,8 @@
#include <fastdds/xtypes/type_representation/TypeObjectRegistry.hpp>
#include <rtps/RTPSDomainImpl.hpp>

#include "idl_parser/Idl.hpp"

namespace eprosima {
namespace fastdds {
namespace dds {
Expand Down Expand Up @@ -65,11 +67,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);
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, type_name, include_paths);
ret_val = context.builder;
}
catch (const std::exception& e)
{
EPROSIMA_LOG_ERROR(IDLPARSER, e.what());
ret_val.reset();
}

return ret_val;
}

traits<DynamicTypeBuilder>::ref_type DynamicTypeBuilderFactoryImpl::create_type_w_type_object(
Expand Down
99 changes: 99 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,99 @@
// 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)
{
return Parser::instance()->parse_file(idl_file, type_name, include_paths);
}

/// \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