From d99543d37b384c1f07a7fca12d101e3c02d629b0 Mon Sep 17 00:00:00 2001
From: "James K. Lowden" <jklowden@symas.com>
Date: Fri, 22 Dec 2023 14:19:36 -0500
Subject: [PATCH] local tests work again

---
 gcc/cobol/parse.y      |  2 ++
 gcc/cobol/parse_ante.h | 11 ++++++++++-
 gcc/cobol/symbols.h    | 12 ++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index dd354aea8821..bbff5b765409 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -7699,6 +7699,7 @@ call:           call_impl end_call
 call_impl:      CALL call_body[body] 
                 {
                   ffi_args_t *params = $body.using_params;
+		  if( yydebug ) params->dump();
                   size_t narg = params? params->elems.size() : 0;
                   cbl_ffi_arg_t args[1 + narg], *pargs = NULL;
                   if( narg > 0 ) {
@@ -7712,6 +7713,7 @@ call_impl:      CALL call_body[body]
 call_cond:      CALL call_body[body] call_excepts[except]
                 {
                   ffi_args_t *params = $body.using_params;
+		  if( yydebug ) params->dump();
                   size_t narg = params? params->elems.size() : 0;
                   cbl_ffi_arg_t args[1 + narg], *pargs = NULL;
                   if( narg > 0 ) {
diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index 7de44a83a6ae..0849760cb072 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -1148,7 +1148,7 @@ struct ffi_args_t {
 
   // set explicitly, or assume
   ffi_args_t * push_back( cbl_ffi_arg_t *arg ) {
-    if( arg->crv < by_reference_e ) {
+    if( arg->crv == cbl_ffi_crv_t(0) ) {
       arg->crv = elems.empty()? by_reference_e : elems.back().crv;
     }
     elems.push_back(*arg);
@@ -1164,6 +1164,15 @@ struct ffi_args_t {
     elems.push_back(arg);
     return this;
   }
+  void dump() const {
+    int i=0;
+    for( const auto& arg : elems ) {
+      warnx( "%8d) %-10s %-16s %s", i++,
+             cbl_ffi_crv_str(arg.crv),
+             3 + cbl_field_type_str(arg.refer.field->type),
+             arg.refer.field->pretty_name() );
+    }
+  }
 };
 
 struct relop_abbr_t {
diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h
index c6a7c34d3d48..32cc2511c288 100644
--- a/gcc/cobol/symbols.h
+++ b/gcc/cobol/symbols.h
@@ -889,6 +889,18 @@ struct cbl_num_result_t {
 enum cbl_ffi_arg_attr_t { none_of_e, address_of_e, length_of_e };
 enum cbl_ffi_crv_t { by_reference_e = 'R', by_content_e = 'C', by_value_e = 'E' };
 
+static inline const char *
+cbl_ffi_crv_str( cbl_ffi_crv_t crv ) {
+  switch (crv) {
+  case by_reference_e: return "REFERENCE";
+  case by_content_e: return "CONTENT";
+  case by_value_e: return "VALUE";
+  }
+  if( crv == cbl_ffi_crv_t(0) ) return "<none>";
+  return "???";
+}
+
+
 void parser_symbol_add( struct cbl_field_t *new_var );
 void parser_local_add( struct cbl_field_t *new_var );
 
-- 
GitLab