This document described the style rules for the development of the AWS project. The goal is to have a consistent style used for all AWS codes.
As the Ada 2005 support on GNAT is maturing, it is possible to use some Ada 2005 constructs for AWS development. We list here the features that can be used:
Constructs that are not ready for use:
In addition, all constructs should be compatible with GNAT 6.2 and GPL 2009.
————————————————————————————————————
The end-of-line sequence used must be the standard UNIX end-of-line character, a single LF (16#0A#).
1_000_000
16#8000_000#
3.14159_26535_89793_23846
return else procedure
-- (ie -- followed by two spaces).
The only exception to this rule (i.e. one space is tolerated) is when the
comment ends with --.
It also accepted to have only one space between -- and the start
of the comment when the comment is at the end of a line,
after an Ada statement.
Z : Integer;
-- Integer value for storing value of Z
--
-- The previous line was a blank line
begin
-- Comment for the next statement
A := 5;
-- Comment for the B statement
B := 6;
My_Identifier := 5; -- First comment
Other_Id := 6; -- Second comment
Entity1 : Integer;
My_Entity : Integer;
E := A * B**2 + 3 * (C - D);
(A / B) * C
if <condition> then
...
elsif <condition> then
...
else
...
end if;
When the above layout is not possible, "then" should be aligned with "if", and conditions should preferably be split before an "and" or "or" keyword a follows:
if <long_condition_that_has_to_be_split>
and then <continued_on_the_next_line>
then
...
end if;
The "elsif", "else" and "end if" always line up with the "if" keyword. The preferred location for splitting the line is before "and" or "or". The continuation of a condition is indented with two spaces or as many as needed to make nesting clear.
if x = lakdsjfhlkashfdlkflkdsalkhfsalkdhflkjdsahf
or else
x = asldkjhalkdsjfhhfd
or else
x = asdfadsfadsf
then
if this_complex_condition
and then that_other_one
and then one_last_one
then
...
A := 5;
if A = 5 then
null;
end if;
A := 6;
case <expression> is
when <condition> =>
...
when <condition> =>
...
end case;
If the condition and the code for the case section is small, it is possible to put the code for each when section right after the condition without a new-line.
case <expression> is
when <condition> => ...
when <condition> => ...
end case;
for J in S'Range loop
...
end loop;
If the condition is too long, split the condition (see if_statement) and align "loop" with the "for" or "while" keyword.
while <long_condition_that_has_to_be_split>
and then <continued_on_the_next_line>
loop
...
end loop;
If the loop_statement has an identifier, it is layout as follows:
Outer : while not <condition> loop
...
end Outer;
Some_Block : declare
...
begin
...
end Some_Block;
function Length (S : String) return Integer;
procedure My_Proc
(First : Integer;
Second : out Character;
Third : access String;
Fourth : in out Float);
function Head
(Source : String;
Count : Natural;
Pad : Character := Space)
return String;
function Head
(Source : String;
Count : Natural;
Pad : Character := Space) return String;
procedure Func (A : in out Integer);
-----------------
-- My_Function --
-----------------
procedure My_Function is
begin
Note that the name in the header is preceded by a single space, not two spaces as for other comments.
procedure My_Function (X : Integer) is
X : Float;
begin
procedure My_Function
(X : Integer;
Y : Float)
is
A : Character;
begin
-- Start of processing for bla bla
begin
package P is
...
end P;
with Ada.Strings;
with Ada.Strings.Unbounded;
but the equivalent form:
with Ada.Strings.Unbounded;
package Entity is
type Entity_Kind is ...;
...
end Entity;
It is good to group the context clauses in 3 parts. The Ada standard clauses, the components from other projects and then the project's clauses. In each group it is required to sort the clauses by alphabetical order.
with Ada.Exceptions;
with Ada.Strings;
with Lists;
with Ordered_Set;
with AWS.Server;
with AWS.URL;