Skip to content

Commit 71ede28

Browse files
committed
fix: enforce 100-line hard limit on functions (CLAUDE.md compliance)
Two functions violated the 100-line hard limit: - generate_grouped_body: 144 lines -> 77 lines - generate_grouped_body_with_params: 389 lines -> 42 lines Changes: - Extract statement processing helpers in codegen_grouped_body - Create codegen_grouped_body_params_helpers module - Split massive parameter processing into focused subroutines - All tests pass, functionality preserved Resolves CLAUDE.md ZERO TOLERANCE violation.
1 parent cb5ae59 commit 71ede28

File tree

3 files changed

+439
-398
lines changed

3 files changed

+439
-398
lines changed

src/codegen/codegen_grouped_body.f90

Lines changed: 33 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ module codegen_grouped_body
3232

3333
contains
3434

35+
subroutine process_single_statement(arena, idx, indent, code)
36+
type(ast_arena_t), intent(in) :: arena
37+
integer, intent(in) :: idx
38+
integer, intent(in) :: indent
39+
character(len=:), allocatable, intent(inout) :: code
40+
character(len=:), allocatable :: stmt_code
41+
42+
stmt_code = generate_code_from_arena(arena, idx)
43+
code = code // indent_lines(stmt_code, indent) // new_line('A')
44+
end subroutine process_single_statement
45+
46+
subroutine process_procedure_def(arena, idx, indent_str, in_contains, i, &
47+
code)
48+
type(ast_arena_t), intent(in) :: arena
49+
integer, intent(in) :: idx
50+
character(len=*), intent(in) :: indent_str
51+
logical, intent(in) :: in_contains
52+
integer, intent(in) :: i
53+
character(len=:), allocatable, intent(inout) :: code
54+
character(len=:), allocatable :: stmt_code
55+
56+
if (in_contains .and. i > 1) code = code // new_line('A')
57+
stmt_code = generate_code_from_arena(arena, idx)
58+
code = code // indent_str // stmt_code // new_line('A')
59+
end subroutine process_procedure_def
60+
3561
function generate_grouped_body(arena, body_indices, indent) result(code)
3662
type(ast_arena_t), intent(in) :: arena
3763
integer, intent(in) :: body_indices(:)
@@ -67,19 +93,13 @@ function generate_grouped_body(arena, body_indices, indent) result(code)
6793
i = i + 1
6894

6995
type is (function_def_node)
70-
if (in_contains_section .and. i > 1) then
71-
code = code // new_line('A')
72-
end if
73-
stmt_code = generate_code_from_arena(arena, body_indices(i))
74-
code = code // indent_str // stmt_code // new_line('A')
96+
call process_procedure_def(arena, body_indices(i), indent_str, &
97+
in_contains_section, i, code)
7598
i = i + 1
7699

77100
type is (subroutine_def_node)
78-
if (in_contains_section .and. i > 1) then
79-
code = code // new_line('A')
80-
end if
81-
stmt_code = generate_code_from_arena(arena, body_indices(i))
82-
code = code // indent_str // stmt_code // new_line('A')
101+
call process_procedure_def(arena, body_indices(i), indent_str, &
102+
in_contains_section, i, code)
83103
i = i + 1
84104

85105
type is (declaration_node)
@@ -91,8 +111,8 @@ function generate_grouped_body(arena, body_indices, indent) result(code)
91111
call process_grouped_declarations(arena, body_indices, i, &
92112
indent_str, code)
93113
else
94-
stmt_code = generate_code_from_arena(arena, body_indices(i))
95-
code = code // indent_lines(stmt_code, indent) // new_line('A')
114+
call process_single_statement(arena, body_indices(i), indent, &
115+
code)
96116
i = i + 1
97117
end if
98118

@@ -109,69 +129,8 @@ function generate_grouped_body(arena, body_indices, indent) result(code)
109129
code = code // new_line('A')
110130
i = i + 1
111131

112-
type is (write_statement_node)
113-
stmt_code = generate_code_from_arena(arena, body_indices(i))
114-
code = code // indent_lines(stmt_code, indent) // new_line('A')
115-
i = i + 1
116-
117-
type is (print_statement_node)
118-
stmt_code = generate_code_from_arena(arena, body_indices(i))
119-
code = code // indent_lines(stmt_code, indent) // new_line('A')
120-
i = i + 1
121-
122-
type is (read_statement_node)
123-
stmt_code = generate_code_from_arena(arena, body_indices(i))
124-
code = code // indent_lines(stmt_code, indent) // new_line('A')
125-
i = i + 1
126-
127-
type is (format_statement_node)
128-
stmt_code = generate_code_from_arena(arena, body_indices(i))
129-
code = code // indent_lines(stmt_code, indent) // new_line('A')
130-
i = i + 1
131-
132-
type is (goto_node)
133-
stmt_code = generate_code_from_arena(arena, body_indices(i))
134-
code = code // indent_lines(stmt_code, indent) // new_line('A')
135-
i = i + 1
136-
137-
type is (return_node)
138-
stmt_code = generate_code_from_arena(arena, body_indices(i))
139-
code = code // indent_lines(stmt_code, indent) // new_line('A')
140-
i = i + 1
141-
142-
type is (entry_node)
143-
stmt_code = generate_code_from_arena(arena, body_indices(i))
144-
code = code // indent_lines(stmt_code, indent) // new_line('A')
145-
i = i + 1
146-
147-
type is (continue_node)
148-
stmt_code = generate_code_from_arena(arena, body_indices(i))
149-
code = code // indent_lines(stmt_code, indent) // new_line('A')
150-
i = i + 1
151-
152-
type is (stop_node)
153-
stmt_code = generate_code_from_arena(arena, body_indices(i))
154-
code = code // indent_lines(stmt_code, indent) // new_line('A')
155-
i = i + 1
156-
157-
type is (error_stop_node)
158-
stmt_code = generate_code_from_arena(arena, body_indices(i))
159-
code = code // indent_lines(stmt_code, indent) // new_line('A')
160-
i = i + 1
161-
162-
type is (cycle_node)
163-
stmt_code = generate_code_from_arena(arena, body_indices(i))
164-
code = code // indent_lines(stmt_code, indent) // new_line('A')
165-
i = i + 1
166-
167-
type is (exit_node)
168-
stmt_code = generate_code_from_arena(arena, body_indices(i))
169-
code = code // indent_lines(stmt_code, indent) // new_line('A')
170-
i = i + 1
171-
172132
class default
173-
stmt_code = generate_code_from_arena(arena, body_indices(i))
174-
code = code // indent_lines(stmt_code, indent) // new_line('A')
133+
call process_single_statement(arena, body_indices(i), indent, code)
175134
i = i + 1
176135
end select
177136
end do

0 commit comments

Comments
 (0)