Commit a96242d4301c8b82be3c46ba336090560303abb6

Thomas de Grivel 2023-08-02T12:55:29

fix buf_inspect_call

diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 6c0e593..f38a9fc 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -337,13 +337,30 @@ sw buf_inspect_call_args (s_buf *buf, const s_list *args)
 
 sw buf_inspect_call_args_size (const s_list *args)
 {
-  return buf_inspect_list_size(args);
+  sw r;
+  sw result = 0;
+  result += strlen("(");
+  while (args) {
+    if ((r = buf_inspect_tag_size(&args->tag)) < 0)
+      return r;
+    result += r;
+    if ((args = list_next(args))) {
+      result += strlen(", ");
+    }
+  }
+  result += strlen(")");
+  return result;
 }
 
 sw buf_inspect_call_size (const s_call *call)
 {
+  s8 op_precedence;
   sw r;
   sw result = 0;
+  if (operator_is_unary(&call->ident))
+    return buf_inspect_call_op_unary_size(call);
+  if ((op_precedence = operator_precedence(&call->ident)) > 0)
+    return buf_inspect_call_op_size(call, op_precedence);
   if ((r = buf_inspect_ident_size(&call->ident)) < 0)
     return r;
   result += r;
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index c5557f5..19f3feb 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -57,7 +57,9 @@ sw buf_inspect_call (s_buf *buf, const s_call *call);
 sw buf_inspect_call_args (s_buf *buf, const s_list *args);
 sw buf_inspect_call_op (s_buf *buf, const s_call *call,
                         s8 op_precedence);
+sw buf_inspect_call_op_size (const s_call *call, s8 op_precedence);
 sw buf_inspect_call_op_unary (s_buf *buf, const s_call *call);
+sw buf_inspect_call_op_unary_size (const s_call *call);
 sw buf_inspect_call_size (const s_call *call);
 sw buf_inspect_cfn (s_buf *buf, const s_cfn *cfn);
 sw buf_inspect_cfn_size (const s_cfn *cfn);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 88eda60..3fded86 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -1370,7 +1370,6 @@ sw buf_parse_ident (s_buf *buf, s_ident *dest)
     goto clean;
   }
   r = 0;
-  goto clean;
  restore:
   buf_save_restore_rpos(buf, &save);
  clean:
diff --git a/test/call_test.c b/test/call_test.c
index 58c7227..4a29a13 100644
--- a/test/call_test.c
+++ b/test/call_test.c
@@ -29,8 +29,8 @@
     s_str result;                                                      \
     call_init_1(&call, (test));                                        \
     TEST_EQ(call_inspect(&call, &result), &result);                    \
-    TEST_EQ(result.size, strlen(test));                                \
     TEST_STRNCMP(result.ptr.p, (test), result.size);                   \
+    TEST_EQ(result.size, strlen(test));                                \
     call_clean(&call);						       \
     str_clean(&result);						       \
   } while (0)