REFACTOR: change code convention to strict C89 #1

Merged
dalmurii merged 11 commits from kenter7317/Preproc:main into main 2026-04-21 11:15:18 +00:00
Contributor

this is for refactoring for new domain-specific library(served by repo-owner)-standard

this pull request is proposing variable name refactoring and macro reproduction

variable name renamed following rule

if the variable name is start with single or multiple _, it will be under the process of trim

now some macro has updated

following macros work style is changed

#define prm_cmt PRM_CMT
#define prm_space_found PRM_SPACE_FOUND
#define prm_first PRM_FIRST

orginally refer prm_bool's variable value, but in this refactor has deleted that struct and changed bit-masking, now this refactor macros refer bit-masking-code value and will be work like some operation index and the parameter value is stored in unsigned prm_bool

Example code
original code : prmbool.m_is_bypassing_arg = 1
refactored code : prm_bool |= PRM_IS_BYPASSING_ARG;

following macros are added

8 | #define	STRLEN(a)	((int)(sizeof(a) - 1))

55 | #define BOOL_AND(u, m) ((u) & (m))
56 | #define BOOL_NAND(u, m) ~(BOOL_AND(u, m))

STRLEN(a) is produced for c89's null-terminated size counter
following code has changed :

const char INCLUDE[sizeof("#include")] = "#include";
			char SEE_INC[STRLEN(INCLUDE)];
			size_t i = 1;
			SEE_INC[0] = '#';
			fputc('#', stdout);
			for (; i < (size_t)STRLEN(INCLUDE); i++) {
				SEE_INC[i] = (char)fgetc(stdin);
				fputc(SEE_INC[i], stdout);

				if (SEE_INC[i] != INCLUDE[i]) {
					break;
				}
			}

			if (i == STRLEN(INCLUDE)) {
				while ((c = fgetc(stdin)) != EOF && !isNewLine(c)) {
					fputc(c, stdout);
				}

				puts("\n#undef __ae2f_MACRO_GENERATED\n"
						"#define __ae2f_MACRO_GENERATED 1");
			}
		}

BOOL_AND(u, m) BOOL_NAND(u, m) is macro, for bit-checking and bit adding opeartion

## this is for refactoring for new domain-specific library(served by repo-owner)-standard ## this pull request is proposing variable name refactoring and macro reproduction variable name renamed following rule > if the variable name is start with single or multiple _, it will be under the process of trim ## now some macro has updated following macros work style is changed ``` #define prm_cmt PRM_CMT #define prm_space_found PRM_SPACE_FOUND #define prm_first PRM_FIRST ``` orginally refer prm_bool's variable value, but in this refactor has deleted that struct and changed bit-masking, now this refactor macros refer bit-masking-code value and will be work like some operation index and the parameter value is stored in ```unsigned prm_bool``` > Example code > original code : prmbool.m_is_bypassing_arg = 1 > refactored code : prm_bool |= PRM_IS_BYPASSING_ARG; following macros are added ``` 8 | #define STRLEN(a) ((int)(sizeof(a) - 1)) 55 | #define BOOL_AND(u, m) ((u) & (m)) 56 | #define BOOL_NAND(u, m) ~(BOOL_AND(u, m)) ``` ```STRLEN(a)``` is produced for c89's null-terminated size counter following code has changed : ``` const char INCLUDE[sizeof("#include")] = "#include"; char SEE_INC[STRLEN(INCLUDE)]; size_t i = 1; SEE_INC[0] = '#'; fputc('#', stdout); for (; i < (size_t)STRLEN(INCLUDE); i++) { SEE_INC[i] = (char)fgetc(stdin); fputc(SEE_INC[i], stdout); if (SEE_INC[i] != INCLUDE[i]) { break; } } if (i == STRLEN(INCLUDE)) { while ((c = fgetc(stdin)) != EOF && !isNewLine(c)) { fputc(c, stdout); } puts("\n#undef __ae2f_MACRO_GENERATED\n" "#define __ae2f_MACRO_GENERATED 1"); } } ``` BOOL_AND(u, m) BOOL_NAND(u, m) is macro, for bit-checking and bit adding opeartion
Author
Contributor

i review this commit, some logical error has produced by human trans-logic process, then i fix such error

i review this commit, some logical error has produced by human trans-logic process, then i fix such error
dalmurii left a comment

Review 0

Review 0
Macro/main.c Outdated
@ -23,1 +22,3 @@
#define prm_first prmbool.m_first
#define prm_cmt PRM_CMT
#define prm_space_found PRM_SPACE_FOUND
#define prm_first PRM_FIRST
Owner

For simple lowercase macros seem not to be relevant | required.

For simple lowercase macros seem not to be relevant | required.
Macro/main.c Outdated
@ -75,0 +76,4 @@
* unsigned m_is_fn_arg : 1;
* unsigned m_is_bypassing_arg : 1;
* } prmbool = { 0, 0, 0, 0, 0 };
***/
Owner

Original code could be checked via commit.
On comments it is irrelevant.

Original code could be checked via commit. On comments it is irrelevant.
Macro/main.c Outdated
@ -209,2 +219,3 @@
prm_bool |= PRM_CMT | PRM_FIRST;
stack = 0;
prmbool.m_is_fn_arg = 0;
prm_bool = BOOL_NAND(prm_bool, PRM_IS_FN_ARG);
Owner

Logic is wrong.

BOOL_NAND(A, B) is defined ~((A) & (B)) where B is (1 << n).
Which wants to get A's nth bit, and bitnot it.
That will lead ~(1 << n) or ~0(all bit set 1)

Logic is wrong. BOOL_NAND(A, B) is defined ~((A) & (B)) where `B` is `(1 << n)`. Which wants to get `A`'s `n`th bit, and bitnot it. That will lead ~(1 << n) or ~0(all bit set 1)
Macro/main.c Outdated
@ -52,2 +49,4 @@
#define isNewLine(c) ((c) == '\n' || (c) == '\r')
#define BOOL_AND(u, m) ((u) & (m))
#define BOOL_NAND(u, m) !(BOOL_AND(u, m))
Owner

First, that is LOGICAL NOT. The result will be normalised.
Second. pure NAND is not the solution to set a bit 1. See #1 (comment)

First, that is LOGICAL NOT. The result will be normalised. Second. pure NAND is not the solution to set a bit 1. See https://talkischeap.work.gd/ae2f/Preproc/pulls/1#issuecomment-6
Author
Contributor

after this comment I resolved Logical problem originated at Macro BOOL_NAND and base branch's struct variable's set_zero code that refactored with bit method. See #commit_14ed96dcf8

after this comment I resolved Logical problem originated at Macro BOOL_NAND and base branch's struct variable's set_zero code that refactored with bit method. See [#commit_14ed96dcf8](https://talkischeap.work.gd/ae2f/Preproc/pulls/1/commits/14ed96dcf80794c1feaf8d97a2170c9e05688eff)
break before fall-through
Author
Contributor

there are some fall-through porblem only occured at strictC89 until commit #commit_14ed96dcf8, I missed out that problem caused by using bundled gcc and now fixed this problem since commit #commit_20bd4c5031

there are some fall-through porblem only occured at strictC89 until commit [#commit_14ed96dcf8](https://talkischeap.work.gd/ae2f/Preproc/pulls/1/commits/14ed96dcf80794c1feaf8d97a2170c9e05688eff), I missed out that problem caused by using bundled gcc and now fixed this problem since commit [#commit_20bd4c5031](https://talkischeap.work.gd/ae2f/Preproc/pulls/1/commits/20bd4c5031fe11b6999f7c71fd8f9c8c5ecd4ced)
Macro/main.c Outdated
@ -390,3 +387,3 @@
fputc(c, stdout);
c = fgetc(stdin);
break;
Owner

You are adding a break line without handling the default branch.

That could lead to false positives.

You are adding a break line without handling the default branch. That could lead to false positives.
Owner

Rest of the changes also seem to be adding just break which leads logic to skip the branch which process was to be fallen through, resulting to false positives… fix it.

Rest of the changes also seem to be adding just break which leads logic to skip the branch which process was to be fallen through, resulting to false positives… fix it.
break before fall-through and goto fall
Macro/main.c Outdated
@ -51,29 +48,29 @@ casenewlines
#define isVarName(c) ((isAlph(c) || isNumber(c)) || (c) == '_')
#define isNewLine(c) ((c) == '\n' || (c) == '\r')
#define BOOL_AND(u, m) ((u) & (m))
Owner

Inconsistent style. Either use BOOL_OR also or remove this and use pure macro.

Inconsistent style. Either use `BOOL_OR` also or remove this and use pure macro.
Macro/main.c Outdated
@ -53,1 +50,4 @@
#define BOOL_AND(u, m) ((u) & (m))
#define SET_ZERO(u, m) ((u) & ~((unsigned)m))
#define BOOL_OR(u, m) ((u) | (m))
Owner

Unused macro. Remove this or use it.

Unused macro. Remove this or use it.
Macro/main.c Outdated
@ -391,2 +391,3 @@
c = fgetc(stdin);
goto FALL_STRING_DEFUALT;
break;
Owner

goto does not necessarily require break after itself (it effectively marks the end of the branch)

goto does not necessarily require `break` after itself (it effectively marks the end of the branch)
Owner

Approved

Approved
Sign in to join this conversation.
No description provided.