This page contains some Badly Formatted Ada code, and its Ada Formatted Version, formatted by SD's Ada formatter, a member of SD's family of source language formatters.
Badly Formatted Ada Code
This code is a maintenance programmer's nightmare. Most programmers will reformat it by hand before attempting anything else. There goes half an hour of productivity.
package body Bags.Set_Operations is function "=" (Left, Right : Bag) return Boolean is begin return Left <= Right and then Right <= Left; end "="; function "<" (Left, Right : Bag) return Boolean is function Subtree_Not_In_Left (L : Link) return Boolean is begin return L /= null and then (not Member(Key_Of(L.Val), Of_Bag => Left) or else Subtree_Not_In_Left(L.Left) or else Subtree_Not_In_Left (L.Right)); end; begin return Left <= Right and then Subtree_Not_In_Left (Right.Root); end "<"; function ">" (Left, Right : Bag) return Boolean is begin return Right < Left; end ">"; function "<=" (Left, Right : Bag) return Boolean is function Subtree_In_Right (L : Link) return Boolean is begin return L = null or else (Member(Key_Of(L.Val), Of_Bag => Right) and then Subtree_In_Right(L.Left) and then Subtree_In_Right(L.Right)); end; begin return Subtree_In_Right(Left.Root); end "<="; function ">=" (Left, Right : Bag) return Boolean is begin return Right <= Left; end ">="; end Bags.Set_Operations;
Ada Formatted Version
This is the result of using SD's AdaFormatter tool on the sample badly formatted Ada. A programmer might actually be able to work on this version.
package body Bags.Set_Operations is
function "=" (Left,Right: Bag) return Boolean is
begin
return Left <= Right
and then Right <= Left;
end "=";
function "<" (Left,Right: Bag) return Boolean is
function Subtree_Not_In_Left(L: Link) return Boolean is
begin
return L /= null
and then ( not Member(Key_Of(L.Val),Of_Bag => Left)
or else Subtree_Not_In_Left(L.Left)
or else Subtree_Not_In_Left(L.Right));
end;
begin
return Left <= Right
and then Subtree_Not_In_Left(Right.Root);
end "<";
function ">" (Left,Right: Bag) return Boolean is
begin
return Right < Left;
end ">";
function "<=" (Left,Right: Bag) return Boolean is
function Subtree_In_Right(L: Link) return Boolean is
begin
return L = null
or else (Member(Key_Of(L.Val),Of_Bag => Right)
and then Subtree_In_Right(L.Left)
and then Subtree_In_Right(L.Right));
end;
begin
return Subtree_In_Right(Left.Root);
end "<=";
function ">=" (Left,Right: Bag) return Boolean is
begin
return Right <= Left;
end ">=";
end Bags.Set_Operations;
Copyright © 1995-2008 Semantic Designs, Incorporated
DMS and "Design Maintenance System" are registered trademarks of Semantic Designs, Inc.
The SD logo and "Semantic Designs" are registered service marks of Semantic Designs, Inc.
CloneDR, PARLANSE and Thicket are trademarks of Semantic Designs, Inc.
The OMG logo is a registered trademark of the Object Management Group, Inc. in the United States and other countries.
To view our Privacy Policy, click here
Comments or problems: webmaster@semdesigns.com
