-
Notifications
You must be signed in to change notification settings - Fork 196
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
[WIP] Yarp types names #2231
base: master
Are you sure you want to change the base?
[WIP] Yarp types names #2231
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,7 +316,9 @@ class t_yarp_generator : public t_oop_generator | |
void generate_struct_read_connectionreader(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_write_wirereader(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_write_connectionreader(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_typeconstexpr(t_struct* tstruct, std::ostringstream& f_h_, const std::string& type, const std::string& version); | ||
void generate_struct_tostring(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_gettype(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_unwrapped_helper(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_editor(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
void generate_struct_editor_default_constructor(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_); | ||
|
@@ -1840,6 +1842,22 @@ void t_yarp_generator::generate_struct(t_struct* tstruct) | |
yarp_api_keyword = annotations.at("yarp.api.keyword"); | ||
} | ||
|
||
std::string yarp_type_name{}; | ||
if (annotations.find("yarp.type.name") != annotations.end()) { | ||
yarp_type_name = annotations.at("yarp.type.name"); | ||
} | ||
else { | ||
yarp_type_name = "yarp/"+name; | ||
} | ||
|
||
std::string yarp_type_version{}; | ||
if (annotations.find("yarp.type.version") != annotations.end()) { | ||
yarp_type_version = annotations.at("yarp.type.version"); | ||
} | ||
else { | ||
yarp_type_version = "1.0"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same about the default version, 1.0 is not a good value, since an unstable type with no annotation defined will have a stable version. I'd stick with enabling this part only if explicitly added by the user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.0? or empty string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'd just leave it empty, and add the relative calls when generating the code only if it is defined |
||
} | ||
|
||
// Open header file | ||
std::string f_header_name = get_out_dir() + get_include_prefix(program_) + name + ".h"; | ||
ofstream_with_content_based_conditional_update f_h_; | ||
|
@@ -1874,6 +1892,7 @@ void t_yarp_generator::generate_struct(t_struct* tstruct) | |
|
||
f_h_ << "#include <yarp/os/Wire.h>\n"; | ||
f_h_ << "#include <yarp/os/idl/WireTypes.h>\n"; | ||
f_h_ << "#include <yarp/os/Type.h>\n"; | ||
if (need_common_) { | ||
f_h_ << '\n'; | ||
f_h_ << "#include <" << get_include_prefix(program_) << program_->get_name() << "_common.h>" << '\n'; | ||
|
@@ -1915,7 +1934,9 @@ void t_yarp_generator::generate_struct(t_struct* tstruct) | |
generate_struct_read_connectionreader(tstruct, f_h_, f_cpp_); | ||
generate_struct_write_wirereader(tstruct, f_h_, f_cpp_); | ||
generate_struct_write_connectionreader(tstruct, f_h_, f_cpp_); | ||
generate_struct_typeconstexpr(tstruct, f_h_, yarp_type_name, yarp_type_version); | ||
generate_struct_tostring(tstruct, f_h_, f_cpp_); | ||
generate_struct_gettype(tstruct, f_h_, f_cpp_); | ||
generate_struct_unwrapped_helper(tstruct, f_h_, f_cpp_); | ||
|
||
// Add editor class, if not disabled | ||
|
@@ -2218,6 +2239,48 @@ void t_yarp_generator::generate_struct_tostring(t_struct* tstruct, std::ostrings | |
assert(indent_count_cpp() == 0); | ||
} | ||
|
||
void t_yarp_generator::generate_struct_typeconstexpr(t_struct* tstruct, std::ostringstream& f_h_, const std::string& yarp_type_name, const std::string& yarp_type_version) | ||
{ | ||
THRIFT_DEBUG_COMMENT(f_h_); | ||
|
||
const auto& name = tstruct->get_name(); | ||
|
||
f_h_ << indent_h() << "//The name and the version for this message\n"; | ||
f_h_ << indent_h() << "static constexpr const char* typeName = \"" << yarp_type_name << "\";\n"; | ||
f_h_ << indent_h() << "static constexpr const char* typeVersion = \"" << "1.0" << "\";\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.0 shouldn't be hardcoded here |
||
f_h_ << '\n'; | ||
|
||
assert(indent_count_h() == 1); | ||
} | ||
|
||
void t_yarp_generator::generate_struct_gettype(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_) | ||
{ | ||
THRIFT_DEBUG_COMMENT(f_h_); | ||
THRIFT_DEBUG_COMMENT(f_cpp_); | ||
|
||
const auto& name = tstruct->get_name(); | ||
|
||
f_h_ << indent_h() << "// Get the message type\n"; | ||
f_h_ << indent_h() << "yarp::os::Type getType() const;\n"; | ||
f_h_ << '\n'; | ||
|
||
f_cpp_ << indent_cpp() << "// Convert to a printable string\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment seems a copy-paste from somewhere else |
||
f_cpp_ << indent_cpp() << "yarp::os::Type " << name << "::getType() const\n"; | ||
f_cpp_ << indent_cpp() << "{\n"; | ||
indent_up_cpp(); | ||
{ | ||
f_cpp_ << indent_cpp() << " yarp::os::Type typ = yarp::os::Type::byNameOnWire(typeName);\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extra space before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
f_cpp_ << indent_cpp() << "typ.setVersion(typeVersion);\n"; | ||
f_cpp_ << indent_cpp() << " return typ;\n"; | ||
} | ||
indent_down_cpp(); | ||
f_cpp_ << indent_cpp() << "}\n"; | ||
f_cpp_ << '\n'; | ||
|
||
assert(indent_count_h() == 1); | ||
assert(indent_count_cpp() == 0); | ||
} | ||
|
||
void t_yarp_generator::generate_struct_unwrapped_helper(t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_) | ||
{ | ||
THRIFT_DEBUG_COMMENT(f_h_); | ||
|
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'm not convinced about this default value, I'd rather enable this only if specified by the user (at least for now), or everyone who defined some type in some other repo will have some "yarp" types.
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 see. Better
name
? or just an empty 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.
Empty string and do not add the type part if not defined