Add style checks to debug GPR and enforce them
While here, remove the C flags from the compiler package, including the -I flag, and replace the latter with an additional entry in Source_Dirs so that the project is buildable with GPRbuild. The debug flag (-g) is removed from compiler flags because it comes from Builder flags. Styles corrected include: * Enforce at least one space between comment marker ("--") and the comment * Capitalize "True" and "False" * Enforce closing name at end of functions * Use "or else" instead of "or" when appropriate * Use "and then" instead of "and" when appropriate * Move "then" to new line if condition covers multiple lines * Enforce 79-character line limit
This commit is contained in:
parent
3c01e14ef5
commit
091ae71647
|
@ -1,23 +1,22 @@
|
|||
library project AdaID_Debug is
|
||||
for Library_Name use "adaid_debug";
|
||||
for Object_Dir use "obj/debug";
|
||||
for Source_Dirs use ("src");
|
||||
for Library_Dir use "lib";
|
||||
for Library_Kind use "static";
|
||||
for Library_ALI_Dir use "ali/debug";
|
||||
|
||||
package Builder is
|
||||
for Default_Switches("Ada") use ("-g",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-gnatQ");
|
||||
end Builder;
|
||||
package Compiler is
|
||||
for Default_Switches("Ada") use ("-g",
|
||||
"-Wall",
|
||||
"--pedantic-errors",
|
||||
"-Wextra",
|
||||
"-I./include");
|
||||
end Compiler;
|
||||
|
||||
end AdaID_Debug;
|
||||
library project AdaID_Debug is
|
||||
|
||||
for Library_Name use "adaid_debug";
|
||||
for Object_Dir use "obj/debug";
|
||||
for Source_Dirs use ("src", "include");
|
||||
for Library_Dir use "lib";
|
||||
for Library_Kind use "static";
|
||||
for Library_Ali_Dir use "ali/debug";
|
||||
|
||||
package Builder is
|
||||
for Default_Switches ("ada") use ("-g");
|
||||
end Builder;
|
||||
|
||||
package Compiler is
|
||||
for Default_Switches ("ada") use ("-gnatyabBCeiklmnpxAfh");
|
||||
end Compiler;
|
||||
|
||||
package Linker is
|
||||
end Linker;
|
||||
|
||||
end AdaID_Debug;
|
||||
|
||||
|
|
|
@ -50,24 +50,24 @@ package AdaID is
|
|||
-- The main type for the package
|
||||
|
||||
function Is_Nil(This: in UUID) return Boolean;
|
||||
--Determine if UUID is NIL (All Zeros)
|
||||
-- Determine if UUID is NIL (All Zeros)
|
||||
|
||||
function Get_Version(This: in UUID) return VersionType;
|
||||
--Get the UUID Version
|
||||
-- Get the UUID Version
|
||||
|
||||
function Get_Variant(This: in UUID) return VariantType;
|
||||
--Get the UUID Variant
|
||||
-- Get the UUID Variant
|
||||
|
||||
function "="(Left, Right: in UUID) return Boolean;
|
||||
--Test for equality between Left and Right
|
||||
-- Test for equality between Left and Right
|
||||
|
||||
function Get_Hash_Value(This: in UUID) return HashType;
|
||||
--Get the hash code for the UUID
|
||||
-- Get the hash code for the UUID
|
||||
|
||||
function To_String(This: in UUID) return String;
|
||||
--Convert the UUID to a common string representation
|
||||
-- Convert the UUID to a common string representation
|
||||
|
||||
private
|
||||
overriding procedure Initialize (This: in out UUID);
|
||||
--Default "constructor", initializes to NIL
|
||||
-- Default "constructor", initializes to NIL
|
||||
end AdaID;
|
||||
|
|
|
@ -14,7 +14,7 @@ package body AdaID.Generate is
|
|||
package RNG is new Ada.Numerics.Discrete_Random(Result_Subtype =>
|
||||
Unsigned_32);
|
||||
generator: RNG.Generator;
|
||||
generator_is_set: Boolean := false;
|
||||
generator_is_set: Boolean := False;
|
||||
|
||||
|
||||
procedure Seed_RNG is
|
||||
|
@ -34,12 +34,12 @@ package body AdaID.Generate is
|
|||
when others =>
|
||||
RNG.Reset(generator); -- Fallback to time-based
|
||||
end;
|
||||
generator_is_set := true;
|
||||
generator_is_set := True;
|
||||
end if;
|
||||
end Seed_RNG;
|
||||
|
||||
|
||||
--Reset a UUID to Nil
|
||||
-- Reset a UUID to Nil
|
||||
procedure Nil(id : in out UUID) is
|
||||
begin
|
||||
Initialize(id);
|
||||
|
@ -69,12 +69,12 @@ package body AdaID.Generate is
|
|||
-- Set the variant
|
||||
id.data(8) := (id.data(8) and 16#BF#) or 16#80#;
|
||||
|
||||
--Set the version to random-number-based
|
||||
-- Set the version to random-number-based
|
||||
id.data(6) := (id.data(6) and 16#4F#) or 16#40#;
|
||||
end;
|
||||
end Random;
|
||||
|
||||
|
||||
--Generate a UUID based on a name
|
||||
-- Generate a UUID based on a name
|
||||
procedure From_Name(namespace: in UUID; name: in String; id: in out UUID) is
|
||||
use SHA.Process_Data;
|
||||
|
||||
|
@ -93,7 +93,7 @@ package body AdaID.Generate is
|
|||
Add(SHA.Process_Data.Byte(Character'Pos(name(i))), c);
|
||||
end loop;
|
||||
|
||||
--Get the digest
|
||||
-- Get the digest
|
||||
Finalize(d, c);
|
||||
|
||||
-- Now make the UUID from the hash
|
||||
|
@ -107,7 +107,7 @@ package body AdaID.Generate is
|
|||
-- set variant
|
||||
id.data(8) := (id.data(8) and 16#BF#) or 16#80#;
|
||||
|
||||
--set version
|
||||
-- set version
|
||||
id.data(6) := (id.data(6) and 16#5F#) or 16#50#;
|
||||
end From_Name;
|
||||
|
||||
|
@ -120,10 +120,10 @@ package body AdaID.Generate is
|
|||
close : constant Character := '}';
|
||||
|
||||
-- expect dashes if str is 36 or 38 in length
|
||||
dashed: constant Boolean := str'Length = 36 or str'Length = 38;
|
||||
dashed: constant Boolean := str'Length = 36 or else str'Length = 38;
|
||||
|
||||
-- check to see if braces surround the string
|
||||
braced: constant Boolean := str(str'First) = open and
|
||||
braced: constant Boolean := str(str'First) = open and then
|
||||
str(str'Last) = close;
|
||||
|
||||
-- track where to read from/write to
|
||||
|
@ -132,14 +132,15 @@ package body AdaID.Generate is
|
|||
begin
|
||||
|
||||
-- Check that length is valid
|
||||
if not dashed and str'Length /= 32 and str'Length /= 34 then
|
||||
if not dashed and then str'Length /= 32 and then str'Length /= 34 then
|
||||
raise Invalid_String;
|
||||
end if;
|
||||
|
||||
-- Check that brace are valid
|
||||
start := str'First;
|
||||
if not braced and
|
||||
(str(str'First) = open or str(str'Last) = close) then
|
||||
if not braced and then
|
||||
(str(str'First) = open or else str(str'Last) = close)
|
||||
then
|
||||
raise Invalid_String; -- only one brace present
|
||||
elsif braced then
|
||||
start := str'First + 1;
|
||||
|
@ -150,7 +151,9 @@ package body AdaID.Generate is
|
|||
-- Grab each pair and stuff into byte
|
||||
for i in ByteArray'Range loop
|
||||
rel := idx - start;
|
||||
if dashed and (rel = 8 or rel = 13 or rel = 18 or rel = 23) then
|
||||
if dashed and then
|
||||
(rel = 8 or else rel = 13 or else rel = 18 or else rel = 23)
|
||||
then
|
||||
if str(idx) /= delim then
|
||||
raise Invalid_String; -- expected '-'
|
||||
end if;
|
||||
|
|
|
@ -10,20 +10,20 @@ package body AdaID is
|
|||
for i in ByteArray'Range loop
|
||||
This.data(i) := 0;
|
||||
end loop;
|
||||
end;
|
||||
end Initialize;
|
||||
|
||||
-- Determine if the UUID is NIL
|
||||
function Is_Nil(This: in UUID) return Boolean is
|
||||
begin
|
||||
for i in ByteArray'Range loop
|
||||
if This.data(i) /= 0 then
|
||||
return false;
|
||||
return False;
|
||||
end if;
|
||||
end loop;
|
||||
return true;
|
||||
return True;
|
||||
end Is_Nil;
|
||||
|
||||
--Get the UUID Version
|
||||
-- Get the UUID Version
|
||||
function Get_Version(This: in UUID) return VersionType is
|
||||
-- version type in octet 7
|
||||
b : constant Byte := This.data(6) and Byte(16#F0#);
|
||||
|
@ -38,7 +38,7 @@ package body AdaID is
|
|||
end case;
|
||||
end Get_Version;
|
||||
|
||||
--Get the UUID Variant
|
||||
-- Get the UUID Variant
|
||||
function Get_Variant(This: in UUID) return VariantType is
|
||||
-- variant type in octet 9
|
||||
b : constant Byte := This.data(8);
|
||||
|
@ -54,19 +54,19 @@ package body AdaID is
|
|||
end if;
|
||||
end Get_Variant;
|
||||
|
||||
--Test for equality
|
||||
-- Test for equality
|
||||
function "="(Left, Right: in UUID) return Boolean is
|
||||
begin
|
||||
for i in ByteArray'Range loop
|
||||
if Left.data(i) /= Right.data(i) then
|
||||
return false;
|
||||
return False;
|
||||
end if;
|
||||
end loop;
|
||||
return true;
|
||||
return True;
|
||||
end "=";
|
||||
|
||||
|
||||
--Get the hash value for the UUID
|
||||
-- Get the hash value for the UUID
|
||||
function Get_Hash_Value(This: in UUID) return HashType is
|
||||
seed : HashType := 0;
|
||||
begin
|
||||
|
@ -83,7 +83,7 @@ package body AdaID is
|
|||
return seed;
|
||||
end Get_Hash_Value;
|
||||
|
||||
--Convert the UUID to a string
|
||||
-- Convert the UUID to a string
|
||||
function To_String(This: in UUID) return String is
|
||||
result : String(1 .. 36);
|
||||
index : Integer := 1;
|
||||
|
@ -98,7 +98,7 @@ package body AdaID is
|
|||
index := index + 2;
|
||||
|
||||
-- insert dashes
|
||||
if i = 3 or i = 5 or i = 7 or i = 9 then
|
||||
if i = 3 or else i = 5 or else i = 7 or else i = 9 then
|
||||
result(index) := '-';
|
||||
index := index + 1;
|
||||
end if;
|
||||
|
|
|
@ -168,7 +168,8 @@ package body SHA.Process_Data is
|
|||
-- We may have to make room for the count to be put on the last block.
|
||||
if Given.Next_Word >= Given.Data'Last - 1 then -- Room for the count?
|
||||
if not (Given.Next_Word = Given.Data'Last - 1
|
||||
and Given.Remaining_Bits = 32) then
|
||||
and then Given.Remaining_Bits = 32)
|
||||
then
|
||||
Transform (Given);
|
||||
end if;
|
||||
end if;
|
||||
|
|
Loading…
Reference in New Issue