Skip to content

Commit

Permalink
Merge pull request RemedyIT#298 from jwillemsen/jwi-structinheritance
Browse files Browse the repository at this point in the history
Some more code generation for struct inheritance, with some more test cases
  • Loading branch information
jwillemsen committed Aug 2, 2023
2 parents 95f6688 + 55fcfd8 commit 22ec39a
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_post.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// generated from <%= ridl_template_path %>
<%= cxxname %> () = default;
~<%= cxxname %> () = default;
% unless base.nil?
using <%= base.cxxname %>::<%= base.cxxname %>;
% end
<%= cxxname %> (<%= cxx_in_type %>) = default;
<%= cxxname %> (<%= cxx_move_type %>) = default;
% if member_count > 0
% if member_count > 0 || !base.nil?
% _ms = members.dup
/// Constructor which accepts value for all members
explicit inline <%= cxxname %> (
% unless base.nil?
<%= base.cxxname %> _base<%= _ms.empty? ? ');' : ',' %>
% end
% unless _ms.empty?
% while !_ms.empty?
% _m = _ms.shift
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_pre.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// generated from <%= ridl_template_path %>
/// @copydoc <%= doc_scoped_name %>
class <%= stub_export_macro %><%= cxxname %>
class <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %>
{
public:
10 changes: 9 additions & 1 deletion ridlbe/c++11/templates/cli/inl/struct_inl.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
%# Constructor inlines
%#
%# Initializer CTOR
% if member_count > 0
% if member_count > 0 || !base.nil?
% _ms = members.dup
inline <%= scoped_cxxtype %>::<%= cxxname %> (
% unless base.nil?
<%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %>
% end
% unless _ms.empty?
% while !_ms.empty?
% _m = _ms.shift
Expand All @@ -18,6 +21,10 @@ inline <%= scoped_cxxtype %>::<%= cxxname %> (
% end
% end
% _pfx = nil
% unless base.nil?
: <%= base.cxxname %> (std::move(_base))<% unless _ms.empty? %>,<% end %>
% _pfx = ', ' unless _pfx
% end
% members.each do |_m|
<%= _pfx || ': ' %><%= _m.cxxname %>_ (std::move (<%= _m.cxxname %>))
% _pfx = ', ' unless _pfx
Expand All @@ -28,6 +35,7 @@ inline <%= scoped_cxxtype %>::<%= cxxname %> (
% end
inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %><% if member_count > 0 %> s<% end %>)
{
%# Add support for base
% members.each do |_m|
std::swap (this-><%= _m.cxxname %>_, s.<%= _m.cxxname %>_);
% end
Expand Down
5 changes: 5 additions & 0 deletions ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def is_exception?
false
end

# Return the base of this struct, nil in case of no base struct
def base
node.base
end

# template mapping

map_template :typecode, :typecode
Expand Down
2 changes: 1 addition & 1 deletion tests/idl4/illegal_idl/run_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
open (STDERR, ">&STDOUT");

# Compile the IDL
system ("$ridl", "--idl-version 4 $input_file");
system ("$ridl", "--idl-version=4", "$input_file");

#Redirect the null device output back to the screen
open (STDOUT, ">&OLDOUT");
Expand Down
15 changes: 15 additions & 0 deletions tests/idl4/illegal_idl/struct_circular_inheritance.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file struct_circular_inheritance.idl
* @author Johnny Willemsen
*
* ridlc shall reject the use of circular inheritance
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

struct Foo;

struct Foo : Foo
{
long x;
};
17 changes: 17 additions & 0 deletions tests/idl4/illegal_idl/struct_inherit_interface.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file struct_inherit_interface.idl
* @author Johnny Willemsen
*
* ridlc shall reject the inheritance of a non struct type
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

interface Foo
{
};

struct Bar : Foo
{
long x;
};
23 changes: 23 additions & 0 deletions tests/idl4/illegal_idl/struct_multiple_inheritance.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file struct_multiple_inheritance.idl
* @author Johnny Willemsen
*
* ridlc shall reject the use of multiple inheritance
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

struct Base1
{
long a;
};

struct Base2
{
long b;
};

struct Foo : Base1, Base2
{
long x;
};
22 changes: 22 additions & 0 deletions tests/idl4/struct_inheritance/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ struct Point3D : Point2D
long z;
};

struct Point4D : Point3D
{
long super;
};

struct EmptyStruct
{
};

struct DeriveEmpty : EmptyStruct
{
};

struct DeriveEmptyWithMember : EmptyStruct
{
long x;
};

struct EmptyFromDerived : Point2D
{
};

struct EmptyFromDerivedDerived : Point3D
{
};

0 comments on commit 22ec39a

Please sign in to comment.