Skip to content

Conversation

@kio-watanabe
Copy link
Contributor

Summary

Fixed that if an unimplemented subroutine is called, an error message is output and a precompile error occurs.

Example

COBOL:

           CALL "CBL_CHANGE_DIR" USING "sample".

error message:

prog.cbl:5: Error: CBL_CHANGE_DIR not implemented

Copy link
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

This PR ensures that if an unimplemented subroutine is invoked, a clear error message is displayed and a precompile error is triggered.

  • Introduces a dedicated switch block to check for various unimplemented subroutines based on their index in the system table.
  • Refactors the code to use a local variable for the literal data for clarity.

cobj/typeck.c Outdated
Comment on lines 3106 to 3134
case 2: // CBL_CHANGE_DIR
case 3: // CBL_CHECK_FILE_EXIST
case 4: // CBL_CLOSE_FILE
case 5: // CBL_COPY_FILE
case 6: // CBL_CREATE_DIR
case 7: // CBL_CREATE_FILE
case 8: // CBL_DELETE_DIR
case 9: // CBL_DELETE_FILE
case 11: // CBL_ERROR_PROC
case 12: // CBL_EXIT_PROC
case 13: // CBL_FLUSH_FILE
case 14: // CBL_GET_CURRENT_DIR
case 15: // CBL_IMP
case 20: // CBL_OPEN_FILE
case 22: // CBL_READ_FILE
case 23: // CBL_RENAME_FILE
case 26: // CBL_WRITE_FILE
case 28: // CBL_OC_KEISEN
case 29: // CBL_OC_ATTRIBUTE
case 30: // C$CHDIR
case 31: // C$COPY
case 32: // C$DELETE
case 33: // C$FILEINFO
case 35: // C$GETPID
case 36: // C$JUSTIFY
case 38: // C$MAKEDIR
case 39: // C$NARG
case 40: // C$SLEEP
case 41: // C$PARAMSIZE
Copy link

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The switch-case relies on hardcoded index values to identify unimplemented subroutines, which could be error-prone if the 'system_tab' ordering changes. Consider using named constants or an enumeration for these indices to improve code clarity and maintainability.

Suggested change
case 2: // CBL_CHANGE_DIR
case 3: // CBL_CHECK_FILE_EXIST
case 4: // CBL_CLOSE_FILE
case 5: // CBL_COPY_FILE
case 6: // CBL_CREATE_DIR
case 7: // CBL_CREATE_FILE
case 8: // CBL_DELETE_DIR
case 9: // CBL_DELETE_FILE
case 11: // CBL_ERROR_PROC
case 12: // CBL_EXIT_PROC
case 13: // CBL_FLUSH_FILE
case 14: // CBL_GET_CURRENT_DIR
case 15: // CBL_IMP
case 20: // CBL_OPEN_FILE
case 22: // CBL_READ_FILE
case 23: // CBL_RENAME_FILE
case 26: // CBL_WRITE_FILE
case 28: // CBL_OC_KEISEN
case 29: // CBL_OC_ATTRIBUTE
case 30: // C$CHDIR
case 31: // C$COPY
case 32: // C$DELETE
case 33: // C$FILEINFO
case 35: // C$GETPID
case 36: // C$JUSTIFY
case 38: // C$MAKEDIR
case 39: // C$NARG
case 40: // C$SLEEP
case 41: // C$PARAMSIZE
case CBL_CHANGE_DIR: // CBL_CHANGE_DIR
case CBL_CHECK_FILE_EXIST: // CBL_CHECK_FILE_EXIST
case CBL_CLOSE_FILE: // CBL_CLOSE_FILE
case CBL_COPY_FILE: // CBL_COPY_FILE
case CBL_CREATE_DIR: // CBL_CREATE_DIR
case CBL_CREATE_FILE: // CBL_CREATE_FILE
case CBL_DELETE_DIR: // CBL_DELETE_DIR
case CBL_DELETE_FILE: // CBL_DELETE_FILE
case CBL_ERROR_PROC: // CBL_ERROR_PROC
case CBL_EXIT_PROC: // CBL_EXIT_PROC
case CBL_FLUSH_FILE: // CBL_FLUSH_FILE
case CBL_GET_CURRENT_DIR: // CBL_GET_CURRENT_DIR
case CBL_IMP: // CBL_IMP
case CBL_OPEN_FILE: // CBL_OPEN_FILE
case CBL_READ_FILE: // CBL_READ_FILE
case CBL_RENAME_FILE: // CBL_RENAME_FILE
case CBL_WRITE_FILE: // CBL_WRITE_FILE
case CBL_OC_KEISEN: // CBL_OC_KEISEN
case CBL_OC_ATTRIBUTE: // CBL_OC_ATTRIBUTE
case C$CHDIR: // C$CHDIR
case C$COPY: // C$COPY
case C$DELETE: // C$DELETE
case C$FILEINFO: // C$FILEINFO
case C$GETPID: // C$GETPID
case C$JUSTIFY: // C$JUSTIFY
case C$MAKEDIR: // C$MAKEDIR
case C$NARG: // C$NARG
case C$SLEEP: // C$SLEEP
case C$PARAMSIZE: // C$PARAMSIZE

Copilot uses AI. Check for mistakes.
@kio-watanabe kio-watanabe changed the title Add error message if unimplemented subroutins are used Add error message if unimplemented subroutines are used Apr 30, 2025
Copy link
Contributor

@yutaro-sakamoto yutaro-sakamoto left a comment

Choose a reason for hiding this comment

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

Please see another example of kio-watanabe#6

@yutaro-sakamoto yutaro-sakamoto merged commit dd31671 into opensourcecobol:develop May 1, 2025
139 checks passed
@yutaro-sakamoto yutaro-sakamoto mentioned this pull request May 30, 2025
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.

2 participants