From 43d1eed895a804ef9fe334875bfd8ad9370d5756 Mon Sep 17 00:00:00 2001
From: Bob Dubner <rdubner@symas.com>
Date: Tue, 26 Dec 2023 22:44:19 -0500
Subject: [PATCH] WIP: function call parameters

---
 gcc/cobol/genapi.cc | 25 +++++++++++++++++++++++++
 gcc/cobol/symbols.h |  8 ++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index fd7b26e981d4..fc7c6a062fb0 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -10830,6 +10830,26 @@ parser_call(   cbl_refer_t name,
         {
         case by_reference_e:
           {
+          //  CALL BY REFERENCE <group item>
+          //        The pointer gets passed; 14.8.2.2 1) Requires that the 
+          //        receiving formal parameter has the same number or fewer
+          //        bytes then the sending argument.
+          //
+          //  CALL BY REFERENCE <pointer>
+          //        Both the sending argument and the receiving formal parameter
+          //        have to be pointers (14.8.2.3.2)  (In our implementation,
+          //        pointers can be handled like any other data-item)
+          //
+          //  CALL BY REFERENCE <data-item> 
+          //        The activated element is not in the REPOSITORY paragraph:
+          //        the receiving formal argument ahsll be the same length as
+          //        the sending argument.
+          //
+          //  UDF FUNCTION BY REFERENCE
+          //        The definitions of the formal parameter and the argument
+          //        shall have the same ALIGN, BLANK WHEN ZERO, DYNAMIC LENGTH,
+          //        JUSTIFIED, PICTURE, SIGN, and USAGE clauses
+
           // Pass the pointer to the data location, so that the called program
           // can both access and change the data.
           arguments[i] = location;
@@ -10843,6 +10863,11 @@ parser_call(   cbl_refer_t name,
 
         case by_content_e:
           {
+          // The ISO spec doesn't distinguish between by_content and by_value
+
+          // There are differences based on whether this is a CALL <program-id>
+          // or a user-defined function activation:
+
           // BY CONTENT means that the called program gets a copy of the data.
 
           // We'll free this copy after the called program returns.
diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h
index 32cc2511c288..bddd5f3154f5 100644
--- a/gcc/cobol/symbols.h
+++ b/gcc/cobol/symbols.h
@@ -189,18 +189,22 @@ is_numeric( cbl_field_type_t type ) {
   case FldClass:
   case FldConditional:
   case FldForward:
-  case FldIndex:
   case FldSwitch:
   case FldDisplay:
-  case FldPointer:
   case FldBlob:
     return false;
+  // Dubner's definition of is_numeric are variable types that have to be 
+  // converted from their COBOL form to a little-endian binary representation
+  // so that they can be conveyed BY CONTENT/BY VALUE in a CALL or
+  // user-defined function activation.
   case FldNumericDisplay:
   case FldNumericBinary:
   case FldFloat:
   case FldPacked:
   case FldNumericBin5:
   case FldLiteralN:
+  case FldPointer:
+  case FldIndex:
     return true;
   }
   warnx( "%s:%d: invalid symbol_type_t %d", __func__, __LINE__, type );
-- 
GitLab