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

Rewriters to move to Ada202x code #11

Open
pjljvandelaar opened this issue Feb 4, 2022 · 2 comments
Open

Rewriters to move to Ada202x code #11

pjljvandelaar opened this issue Feb 4, 2022 · 2 comments

Comments

@pjljvandelaar
Copy link
Collaborator

See https://blog.adacore.com/ada-202x-support-in-gnat

e.g. replace

for E of Some_Array loop
   if E /= 0 then
      Put_Line (E'Image);
   end if;
end loop;

by

for E of Some_Array when E /= 0 loop
   Put_Line (E'Image);
end loop;
@pjljvandelaar
Copy link
Collaborator Author

pjljvandelaar commented Jul 1, 2022

Vector initialization

Replace

for I in 1..N loop Append (V, I*2); end loop;

by

V = [for I in 1..N => I * 2];

@pjljvandelaar
Copy link
Collaborator Author

Use reduce

Replace

declare
   sum : Integer := $S_Initial;
begin
   for E of $S_Container loop
        sum := sum + $S_Add;
   end loop;
   $M_Stmts;
end;

by

declare
   sum : Integer := [for E of $S_Container => $S_Add].Reduce ("+", $S_Initial);
begin
   $M_Stmts;
end;

And we even might check whether we can add the constant keyword to the declaration of sum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant