-
Notifications
You must be signed in to change notification settings - Fork 837
[23128] Support builtin annotations in IDL Parser #5908
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
base: master
Are you sure you want to change the base?
Conversation
71ea547
to
7c8a32c
Compare
test/feature/idl_parser/idl_extra_cases/builtin_annotations.idl
Outdated
Show resolved
Hide resolved
src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlParserTags.hpp
Outdated
Show resolved
Hide resolved
src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlAnnotations.hpp
Outdated
Show resolved
Hide resolved
src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlAnnotations.hpp
Outdated
Show resolved
Hide resolved
src/cpp/fastdds/xtypes/dynamic_types/idl_parser/IdlAnnotations.hpp
Outdated
Show resolved
Hide resolved
using TypeDescriptorAnnotationHandler = std::function<bool (TypeDescriptor::_ref_type& /* descriptor */, | ||
const std::map<std::string, std::string>&) /* annotation's member values */>; | ||
using MemberDescriptorAnnotationHandler = std::function<bool (MemberDescriptor::_ref_type& /* descriptor */, | ||
const std::map<std::string, std::string>& /* annotation's member values */)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor these into two virtual methods, and create a class for each built-in annotation:
using TypeDescriptorAnnotationHandler = std::function<bool (TypeDescriptor::_ref_type& /* descriptor */, | |
const std::map<std::string, std::string>&) /* annotation's member values */>; | |
using MemberDescriptorAnnotationHandler = std::function<bool (MemberDescriptor::_ref_type& /* descriptor */, | |
const std::map<std::string, std::string>& /* annotation's member values */)>; | |
virtual bool apply_to_type( | |
TypeDescriptor::_ref_type& /* descriptor */, | |
const std::map<std::string, std::string>& /* annotation_member_values */) | |
{ | |
return true; | |
} | |
virtual bool apply_to_member( | |
MemberDescriptor::_ref_type& /* descriptor */, | |
const std::map<std::string, std::string>& /* annotation_member_values */) | |
{ | |
return true; | |
} |
/** | ||
* @brief Check if the annotation is a builtin annotation | ||
*/ | ||
bool is_builtin() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be converted into a virtual method, that returns false
by default.
We can then have a BuiltinAnnotation
class that just overloads this method, and then make the builtin annotations inherit from that one to customize the apply_to_xxx
methods.
c99f9a2
to
7effe6a
Compare
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
…ions Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
…p as AnnotationsList's container Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
94991d9
to
b787c9f
Compare
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
} // namespace dds | ||
} // namespace fastdds | ||
} // namespace eprosima | ||
/* Built-in annotations related tags */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Built-in annotations related tags */ |
struct id_ann_duplicated_ids | ||
{ | ||
@id(0) long first; | ||
@id(0) string second; | ||
@id(1) float third; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct id_ann_duplicated_ids | |
{ | |
@id(0) long first; | |
@id(0) string second; | |
@id(1) float third; | |
}; | |
struct id_ann_duplicated_ids | |
{ | |
@id(0) long first; | |
@id(0) string second; | |
@id(1) float third; | |
}; | |
struct id_ann_implicit_duplicated_ids | |
{ | |
@id(3) long first; | |
string second; | |
@id(4) float third; | |
}; | |
|
||
@id(1) union id_ann_on_union switch(long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@id(1) union id_ann_on_union switch(long) | |
union id_ann_on_union_discriminator switch(@id(1) long) | |
{ | |
case 0: | |
long first; | |
default: | |
string second; | |
}; | |
@id(1) union id_ann_on_union switch(long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, for now modifying discriminator's descriptor properties using annotations will be kept as unsupported. I will update the documentation with this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we can also make the parser fail with an error log when applying annotations to a discriminator.
@key(value = FALSE) string second; | ||
@key(FALSE) float third; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
union key_ann_valid_union switch(@key long) | |
{ | |
case 0: | |
long first; | |
default: | |
string second; | |
}; | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
@optional(value = FALSE) string second; | ||
@optional(FALSE) float third; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
union optional_ann_invalid_union switch(long) | |
{ | |
case 0: | |
@optional long first; | |
default: | |
string second; | |
}; | |
@@ -0,0 +1,20 @@ | |||
struct value_ann_valid_struct | |||
{ | |||
@value("foo") string first; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation @value
is only valid for enumeration members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is difficult to treat, due to both @default
and @value
annotations can be used to configure MemberDescriptor::default_value
property, and IDL/XTypes specifications impose restrictions over the parent kind of a @value
annotated member, but not in the @default
case, i.e:
struct valid_struct
{
@default(1) long valid_member;
};
should be valid, but:
struct invalid_struct
{
@value(1) long invalid_member;
};
not. Both cases should be handled when adding the member to the constructed type (before adding it, we don't know the member's parent kind), but I think there is not a way to address the problem calling MemberDescriptor::is_consistent()
method. There are two possibilities:
- Modify
is_consistent()
logic to allow configuringMemberDescriptor::default_value()
if and only ifMemberDescriptorImpl::parent_kind_ == TK_ENUM
, making both described cases to fail, but restricting@value
to enumerations. - Keep
is_consistent()
logic, which makes both described cases to be parsed as the same.
Is there a better approach for this? @MiguelCompany @richiware
@value(8) struct value_ann_on_struct | ||
{ | ||
long first; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing files for:
- non_serialized
- hashid
- default_literal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New is_default_literal
member added in MemberDescriptor/DynamicTypeBuilder/DynamicType related classes and DefaultLiteralAnnotation
updated to modify it.
TODO: non_serialized, hashid, autoid implementations in DynTypes API
@@ -160,7 +261,7 @@ class Context | |||
std::map<std::string, std::string>& state, | |||
const std::string& type); | |||
|
|||
std::vector<std::string> split_string( | |||
static std::vector<std::string> split_string( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we move this to IdlParserUtils.hpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it's unrelated to the context
@@ -174,19 +275,38 @@ class Context | |||
return tokens; | |||
} | |||
|
|||
static std::string join_strings( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we move this to IdlParserUtils.hpp
?
#include "../TypeValueConverter.hpp" | ||
#include "IdlParserTags.hpp" | ||
#include "IdlParserUtils.hpp" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve readability and maintainability by having each declared type in a separate file.
Then include all files here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will wait for this refactor to take place before reviewing this
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Signed-off-by: Carlosespicur <carlosespicur@proton.me>
…otated without parameters Signed-off-by: Carlosespicur <carlosespicur@proton.me>
…nd tests Signed-off-by: Carlosespicur <carlosespicur@proton.me>
…eral type in type descriptor Signed-off-by: Carlosespicur <carlosespicur@proton.me>
e6f0c92
to
00e9f3d
Compare
…e member in MemberDescriptor Signed-off-by: Carlosespicur <carlosespicur@proton.me>
Description
This PR add support for builtin annotations in IDL Parser:
Annotation
class, which provides an interface to simplify the annotations parsing.AnnotationsList::from_builtin()
, that defines each supported builtin annotationIDLParserUtils
file, for genericstd::string
transformationsIDLParserTags
file to avoid hardcoding annotations values and names@Mergifyio backport 3.3.x
Contributor Checklist
versions.md
file (if applicable).Related documentation PR:
Reviewer Checklist