Skip to content

Fix C-style code generation for intrinsic function data in CALL statements#797

Merged
yutaro-sakamoto merged 4 commits into
opensourcecobol:developfrom
tsh-hashimoto:fix/intrinsic-cob-procedure-params
Mar 5, 2026
Merged

Fix C-style code generation for intrinsic function data in CALL statements#797
yutaro-sakamoto merged 4 commits into
opensourcecobol:developfrom
tsh-hashimoto:fix/intrinsic-cob-procedure-params

Conversation

@tsh-hashimoto
Copy link
Copy Markdown
Contributor

@tsh-hashimoto tsh-hashimoto commented Mar 2, 2026

#785 に関する修正

概要

  • joutput_data()CB_TAG_INTRINSIC ケースで、C言語スタイルのコード生成(module.cob_procedure_parameters[%d]->data)を正しいJavaスタイル(CobolModule.getCurrentModule().cob_procedure_parameters.get(%d).getDataStorage())に変換
  • joutput_call() の引数出力ループで field_iteration が更新されていなかったバグを修正。複数のINTRINSIC引数を持つCALL文で誤ったインデックスが生成される問題を解消
    • field_iterationsetParameters ループでのみ更新され、後続の引数出力ループでは更新されていなかったため、複数引数のCALL文で常に最後のインデックスが使われる問題があった。

変更点

cobj/codegen.c

  1. joutput_data()CB_TAG_INTRINSIC ケース
  • module.cob_procedure_parameters[%d]->dataCobolModule.getCurrentModule().cob_procedure_parameters.get(%d).getDataStorage() に変換
  1. joutput_call() の引数出力ループ
  • field_iteration = (int)n - 1; を追加。joutput_data() 内の CB_TAG_INTRINSIC ケースが正しいインデックスを参照できるようにした。

テスト

  • CALL USING FUNCTION UPPER-CASE — 単一の英数字型INTRINSIC引数
  • CALL USING mixed fields and FUNCTION UPPER-CASE — 通常フィールドと複数INTRINSIC引数の混在
  • CALL USING FUNCTION LENGTH — 数値型INTRINSIC(スキップ、既存制限)
  • CALL USING FUNCTION MEAN — 数値型INTRINSIC(スキップ、既存制限)

Warning

数値型INTRINSIC関数(FUNCTION LENGTH, FUNCTION MEANなど)の結果をCALL引数として渡す場合、INTRINSIC関数がCOB_TYPE_NUMERIC_BINARY 形式でデータを格納するのに対し、callee側がCOB_TYPE_NUMERIC_DISPLAY(ASCII数字)として解釈するため、正しく表示されない。これはopensource COBOLでも同様の動作であり、本PRのスコープ外とする。該当テストはスキップすることにした。

* Fix invalid C-style code generation for intrinsic function arguments in CALL statements
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Java/C-style code generation mismatch for intrinsic-function data when used in CALL ... USING ... so generated Java references the runtime module parameter storage instead of emitting C pointer syntax.

Changes:

  • Update cobj/codegen.c to emit Java access for CB_TAG_INTRINSIC data storage.
  • Add an integration test for CALL ... USING FUNCTION UPPER-CASE(...).
  • Add (currently skipped) additional test cases for CALL ... USING FUNCTION LENGTH(...) and MEAN(...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
cobj/codegen.c Switch intrinsic data emission from C-style parameter access to Java CobolModule.getCurrentModule().cob_procedure_parameters.get(i).getDataStorage()
tests/run.src/functions.at Add CALL/USING intrinsic-function tests (1 enabled, 2 currently skipped)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/run.src/functions.at
Comment thread tests/run.src/functions.at
Comment thread cobj/codegen.c
Comment thread tests/run.src/functions.at
@tsh-hashimoto tsh-hashimoto marked this pull request as ready for review March 4, 2026 05:18
@yutaro-sakamoto yutaro-sakamoto merged commit 2c2ca16 into opensourcecobol:develop Mar 5, 2026
154 checks passed
@yutaro-sakamoto
Copy link
Copy Markdown
Contributor

@tsh-hashimoto
今回スコープ外とした問題はIssueに起票するようにお願いします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants