Skip to content

Commit 55ebb2b

Browse files
committed
Limit number of lines of array initialization expression.
1 parent b10cc31 commit 55ebb2b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

source/gnatdoc-comments-extractor-code_snippets.adb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,99 @@ package body GNATdoc.Comments.Extractor.Code_Snippets is
272272
end;
273273
end if;
274274

275+
-- Object declaration of array type with default expression: limit
276+
-- number of lines of the aggregate to 4.
277+
278+
if Node.Kind = Ada_Object_Decl
279+
and then not Node.As_Object_Decl.F_Default_Expr.Is_Null
280+
then
281+
declare
282+
Is_Array : Boolean := False;
283+
284+
begin
285+
286+
if Node.As_Object_Decl.F_Type_Expr.Kind = Ada_Anonymous_Type
287+
and then Node.As_Object_Decl.F_Type_Expr.As_Anonymous_Type
288+
.F_Type_Decl.Kind = Ada_Anonymous_Type_Decl
289+
and then Node.As_Object_Decl.F_Type_Expr.As_Anonymous_Type
290+
.F_Type_Decl.As_Anonymous_Type_Decl.F_Type_Def.Kind
291+
= Ada_Array_Type_Def
292+
then
293+
-- A : array (<range>) of <type> := (<value>, ..., <value>)
294+
-- A : array (<range>) of <type> := [<value>, ..., <value>]
295+
296+
Is_Array := True;
297+
298+
elsif Node.As_Object_Decl.F_Type_Expr.Kind
299+
= Ada_Subtype_Indication
300+
and then Node.As_Object_Decl.F_Type_Expr.P_Designated_Type_Decl
301+
.Kind = Ada_Concrete_Type_Decl
302+
and then Node.As_Object_Decl.F_Type_Expr.P_Designated_Type_Decl
303+
.As_Concrete_Type_Decl.F_Type_Def.Kind = Ada_Array_Type_Def
304+
then
305+
-- A : <array_type> := (<value>, ..., <value>)
306+
-- A : <array_type> := [<value>, ..., <value>]
307+
308+
Is_Array := True;
309+
310+
else
311+
raise Program_Error;
312+
end if;
313+
314+
if Is_Array then
315+
declare
316+
Offset : constant Line_Number :=
317+
Sloc_Range (Data (First_Token)).Start_Line - 1;
318+
319+
First_Token : Token_Reference;
320+
Last_Token : Token_Reference;
321+
First_Line : Line_Number;
322+
First_Column : Column_Number;
323+
Last_Line : Line_Number;
324+
325+
begin
326+
if Node.As_Object_Decl.F_Default_Expr.Kind
327+
= Ada_Bracket_Aggregate
328+
then
329+
First_Token :=
330+
Node.As_Object_Decl.F_Default_Expr.As_Bracket_Aggregate
331+
.Token_Start;
332+
Last_Token :=
333+
Node.As_Object_Decl.F_Default_Expr.As_Bracket_Aggregate
334+
.Token_End;
335+
336+
elsif Node.As_Object_Decl.F_Default_Expr.Kind
337+
= Ada_Aggregate
338+
then
339+
First_Token :=
340+
Node.As_Object_Decl.F_Default_Expr.As_Aggregate
341+
.Token_Start;
342+
Last_Token :=
343+
Node.As_Object_Decl.F_Default_Expr.As_Aggregate
344+
.Token_End;
345+
346+
else
347+
raise Program_Error;
348+
end if;
349+
350+
First_Line := Sloc_Range (Data (First_Token)).Start_Line;
351+
First_Column := Sloc_Range (Data (First_Token)).Start_Column;
352+
Last_Line := Sloc_Range (Data (Last_Token)).End_Line;
353+
354+
if Last_Line - First_Line >= 4 then
355+
for J in First_Line + 2 .. Last_Line - 2 loop
356+
Text.Delete (Positive (First_Line - Offset + 2));
357+
end loop;
358+
359+
Text.Replace
360+
(Positive (First_Line - Offset + 2),
361+
Character_Count (First_Column) * ' ' & "");
362+
end if;
363+
end;
364+
end if;
365+
end;
366+
end if;
367+
275368
-- For record type add ';' at the end
276369

277370
if Node.Kind = Ada_Concrete_Type_Decl

0 commit comments

Comments
 (0)