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;