Просмотр исходного кода

Worked on reducing the scope used for variable types. This to prevent having to write out template parameters of parent scopes.

Bart Hertog 5 лет назад
Родитель
Сommit
286d2ab207
3 измененных файлов с 19 добавлено и 9 удалено
  1. 10 1
      generator/support/Field.py
  2. 2 2
      test/proto/nested_message.proto
  3. 7 6
      test/test_NestedMessage.cpp

+ 10 - 1
generator/support/Field.py

@@ -415,7 +415,16 @@ class FieldMessage(Field):
 
     # Get the scope relevant compared to the scope this field is used in.
     def get_reduced_scope(self):
-        return self.get_scope()
+        parent_scope = self.parent.scope.get()
+        def_scope = self.definition.scope.get()
+        start_index = 0
+        for ds, ps in zip(def_scope[:-1], parent_scope):
+            if ds == ps:
+                start_index += 1
+            else:
+                break
+        reduced_scope = def_scope[start_index:]
+        return reduced_scope
 
     def render_get_set(self, jinja_env):
         return self.render("FieldMsg_GetSet.h", jinja_environment=jinja_env)

+ 2 - 2
test/proto/nested_message.proto

@@ -32,7 +32,7 @@
 
 syntax = "proto3";
 
-package demo.namespace;
+package demo.space;
 
 message message_a 
 {
@@ -52,7 +52,7 @@ message message_c
 {
   message message_d
   {
-    uint32 d = 1;
+    repeated uint32 d = 1;
   }
 
   message_b nested_b = 1;

+ 7 - 6
test/test_NestedMessage.cpp

@@ -50,12 +50,13 @@ namespace test_EmbeddedAMS_NestedMessage
 {
 
 constexpr uint32_t SIZE_MSG_A = 3;
+constexpr uint32_t SIZE_MSG_D = 5;
 
 TEST(NestedMessage, serialize_zero) 
 {
   // Test if a unset message results in zero bytes in the buffer.
 
-  ::message_b<SIZE_MSG_A> msg;
+  ::demo::space::message_b<SIZE_MSG_A> msg;
   Mocks::WriteBufferMock buffer;
   EXPECT_CALL(buffer, push(_)).Times(0);
   EXPECT_CALL(buffer, push(_,_)).Times(0);
@@ -70,7 +71,7 @@ TEST(NestedMessage, serialize_one)
 {
   InSequence s;
 
-  ::message_b<SIZE_MSG_A> msg;
+  ::demo::space::message_b<SIZE_MSG_A> msg;
   Mocks::WriteBufferMock buffer;
   ON_CALL(buffer, get_size()).WillByDefault(Return(25));
 
@@ -117,7 +118,7 @@ TEST(NestedMessage, serialize_max)
 {
   InSequence s;
 
-  ::message_b<SIZE_MSG_A> msg;
+  ::demo::space::message_b<SIZE_MSG_A> msg;
   Mocks::WriteBufferMock buffer;
 
   // Test if a nested message can be serialized with values set to one.
@@ -163,7 +164,7 @@ TEST(NestedMessage, serialize_nested_in_nested_max)
 {
   InSequence s;
 
-  ::message_c<SIZE_MSG_A> msg;
+  ::demo::space::message_c<SIZE_MSG_A, SIZE_MSG_D> msg;
   Mocks::WriteBufferMock buffer;
 
   // Test if a nested message in a nested message with some data works.
@@ -209,7 +210,7 @@ TEST(NestedMessage, deserialize_one)
 {
   InSequence s;
 
-  ::message_b<SIZE_MSG_A> msg;
+  ::demo::space::message_b<SIZE_MSG_A> msg;
   Mocks::ReadBufferMock buffer;
 
 
@@ -246,7 +247,7 @@ TEST(NestedMessage, deserialize_nested_in_nested_max)
 {
   InSequence s;
 
-  ::message_c<SIZE_MSG_A> msg;
+  ::demo::space::message_c<SIZE_MSG_A, SIZE_MSG_D> msg;
   Mocks::ReadBufferMock buffer;