Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor return expression causing trouble with GNAT 13 #1557

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 71 additions & 72 deletions src/alire/alire-properties-from_toml.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,92 +17,91 @@ package body Alire.Properties.From_TOML is
Strict : Boolean)
return Conditional.Properties
is
Props : Conditional.Properties;
begin
return Props : Conditional.Properties do
loop
declare
function Is_Valid is
new AAA.Enum_Tools.Is_Valid (Property_Keys);
Val : TOML.TOML_Value;
Key : constant String := From.Pop (Val);
Prop : Property_Keys;
Ada_Key : constant String := TOML_Adapters.Adafy (Key);
begin
if Key = "" then
return; -- No more keys
end if;
loop
declare
function Is_Valid is
new AAA.Enum_Tools.Is_Valid (Property_Keys);
Val : TOML.TOML_Value;
Key : constant String := From.Pop (Val);
Prop : Property_Keys;
Ada_Key : constant String := TOML_Adapters.Adafy (Key);
begin
if Key = "" then
return Props; -- No more keys
end if;

-- Extract property name from string

Process_Property : -- Single-pass loop to emulate Continue
loop
if Is_Valid (Ada_Key) then
Prop := Property_Keys'Value (TOML_Adapters.Adafy (Key));

-- Check that the property is expected in this section.
if Loaders (Prop) in null then
From.Recoverable_Error
("property '" & Key
& "' must not appear in section "
& AAA.Strings.To_Lower_Case (Section'Image));
exit Process_Property;
end if;

-- Extract property name from string

Process_Property : -- Single-pass loop to emulate Continue
loop
if Is_Valid (Ada_Key) then
Prop := Property_Keys'Value (TOML_Adapters.Adafy (Key));

-- Check that the property is expected in this section.
if Loaders (Prop) in null then
From.Recoverable_Error
("property '" & Key
& "' must not appear in section "
& AAA.Strings.To_Lower_Case (Section'Image));
exit Process_Property;
end if;

-- If the property is an array of tables (e.g. actions),
-- reconstruct items as a single table to redispatch.
-- This ensures that properties that can have dynamic
-- expressions within each array entry are transparently
-- managed before they reach the actual property loader.

if Val.Kind = TOML_Array
and then
(for all I in 1 .. Val.Length =>
Val.Item (I).Kind = TOML_Table)
then

-- Load each array entry individually

for I in 1 .. Val.Length loop
Props.Append
(Prop_Loader.Load
(From => From.Descend
(Key => Key,
Value => Val.Item (I),
Context => Key & " (array item"
& I'Image & ")"),
Loader => Loaders (Prop),
Resolve => Is_Dynamic (Prop),
Strict => Strict));
end loop;

else

-- Load a single property once we know its exact name,
-- allowing expressions were appropriate.
-- If the property is an array of tables (e.g. actions),
-- reconstruct items as a single table to redispatch.
-- This ensures that properties that can have dynamic
-- expressions within each array entry are transparently
-- managed before they reach the actual property loader.

if Val.Kind = TOML_Array
and then
(for all I in 1 .. Val.Length =>
Val.Item (I).Kind = TOML_Table)
then

-- Load each array entry individually

for I in 1 .. Val.Length loop
Props.Append
(Prop_Loader.Load
(From => From.Descend
(Key => Key,
Value => Val,
Context => Key),
Value => Val.Item (I),
Context => Key & " (array item"
& I'Image & ")"),
Loader => Loaders (Prop),
Resolve => Is_Dynamic (Prop),
Strict => Strict));

end if;
end loop;

else
From.Recoverable_Error
("invalid property: '" & Key &
"'." & Property_Keys_Suggestion (Key));

-- Load a single property once we know its exact name,
-- allowing expressions were appropriate.

Props.Append
(Prop_Loader.Load
(From => From.Descend
(Key => Key,
Value => Val,
Context => Key),
Loader => Loaders (Prop),
Resolve => Is_Dynamic (Prop),
Strict => Strict));

end if;

exit Process_Property;
end loop Process_Property;
end;
end loop;
end return;
else
From.Recoverable_Error
("invalid property: '" & Key &
"'." & Property_Keys_Suggestion (Key));
end if;

exit Process_Property;
end loop Process_Property;
end;
end loop;
end Loader;

end Alire.Properties.From_TOML;
Loading