Warning, /frameworks/ktexteditor/autotests/input/indent/ada/longtest/expected is written in an unsupported language. File is not indexed.

0001 --
0002 --
0003 
0004 
0005 --
0006 
0007 with text_io;
0008 use text_io;
0009 
0010 with Ada.Integer_Text_IO;
0011 use  Ada.Integer_Text_IO;
0012 
0013 
0014 package Package_With_Private is
0015 
0016    type Private_Type is private;
0017 
0018 private
0019 
0020    type Private_Type is array (1 .. 10) of Integer;
0021 
0022 end Package_With_Private;
0023 
0024 
0025 procedure Range_1( i : integer );   -- forward declaration
0026 
0027 
0028 Block_Name :   -- CHECK: block labels are handled sensibly
0029 declare
0030    A_Variable : The_Type;
0031 begin
0032    Use A_Variable
0033 end Block_Name;
0034 
0035 generic
0036    Max: Positive;
0037    type Element_T is private;
0038 package Generic_Stack is
0039    procedure Push (E: Element_T);
0040    function Pop return Element_T;
0041 end Generic_Stack;
0042 
0043 
0044 procedure Generic_Swap is
0045    generic
0046       type Item is private;
0047    procedure Exchange(X, Y: in out Item);
0048    procedure Exchange(X, Y: in out Item) is
0049       Temp: Item;
0050    begin
0051       Temp := X;
0052       Result.Elements (i, Result.Elements'Last (2))
0053          := 3 + Right.Elements (i);
0054       a := long_expression
0055            + another_long_expression;     -- CHECK: this should be indented
0056       func
0057          ( a,
0058            b
0059          );
0060       Y := func
0061               ( a,
0062                 b
0063               );
0064       Y :=
0065          func
0066             ( a,
0067               b
0068             );
0069    end;
0070 
0071    A, B : Integer;
0072    procedure Swap is new Exchange(integer);
0073 
0074 begin
0075    A := 1;
0076    B := 2;
0077    Swap(A,B);
0078    Ada.Float_Text_IO.put                        --  Float literal
0079       (Item => gamma(i), Fore => 1, Aft => 1, Exp => 0);
0080    new_line;
0081    Ada.Float_Text_IO.put(                        --  Float literal
0082                            Item => gamma(i), Fore => 1, Aft => 1, Exp => 0);
0083    new_line;
0084    return( a+b );
0085    return(
0086             a+b );
0087    return
0088       ( a
0089         +b);
0090 
0091 end Generic_Swap;
0092 
0093 
0094 function SUBSTRING (DSTR: DYN_STRING;   -- this is a forward reference
0095                     START  : natural;
0096                     LENGTH : natural := 0)
0097    return DYN_STRING;
0098 
0099 function SUBSTRING (DSTR: DYN_STRING;
0100                     LENGTH : natural := 0)
0101    return DYN_STRING is
0102    DS: DYN_STRING;
0103    L : natural := LENGTH;
0104 
0105    type Degrees is new Float range -273.15 .. Float'Last;
0106    Temperature : Degrees;
0107 
0108    type Car is record
0109       Identity       : Long_Long_Integer;
0110       Number_Wheels  : Positive range 1 .. 10;
0111       Paint          : Color;
0112       Horse_Power_kW : Float range 0.0 .. 2_000.0;
0113       Consumption    : Float range 0.0 .. 100.0;
0114    end record;
0115 
0116    BMW : Car :=
0117       (Identity       => 2007_752_83992434,
0118        Number_Wheels  => 5,
0119        Horse_Power_kW => 190.0,
0120        Consumption    => 10.1,
0121        Paint          => Blue);
0122 
0123    type Directions is (North, South, East, West);
0124    Heading : Directions;
0125 
0126 begin
0127    put_line("It works!");
0128 
0129    case long_expression
0130       + Another_long_expression is
0131       when 89 ==>
0132          s1;
0133          s2;
0134 <<lab>>         -- CHECK: label should be aligned with begin
0135 #
0136       when 1 =>
0137          Walk_The_Dog;
0138 
0139       when 16#5# ==>
0140          a := 5;
0141          a := 9;
0142          f(18);
0143          s1;
0144 
0145 #include "fred"
0146 
0147       when 5 =>
0148          case Heading is
0149             when North =>
0150                Y := Y + 1;
0151             when South =>
0152                Y := Y - 1;
0153             when East =>
0154                X := X + 1;
0155             when West =>
0156                X := X - 1;
0157          end case;
0158 
0159       when 8 | 10 =>
0160 
0161          Sell_All_Stock;
0162 
0163       when others =>
0164 
0165          if Temperature >= 40.0 then
0166             Put_Line ("Wow!");
0167             Put_Line ("It's extremely hot");
0168          elsif Temperature >= 30.0 then
0169             Put_Line ("It's hot");
0170          elsif Temperature >= 20.0 then
0171             Put_Line ("It's warm");
0172          elsif Temperature >= 10.0 then
0173             Put_Line ("It's cool");
0174          elsif Temperature >= 0.0 then
0175             Put_Line ("It's cold");
0176          else
0177             Put_Line ("It's freezing");
0178          end if;
0179 
0180    end case;
0181 
0182    DS3.DATA(1..DS3.SIZE):=   DS1.DATA(1..DS1.SIZE)
0183                              & DS2.DATA(1..DS2.SIZE);
0184    return DS3;  -- CHECK: should align with DS3 above
0185 end main;
0186 
0187 
0188 procedure Quadratic_Equation
0189              (A, B, C :     Float;   -- By default it is "in".
0190               R1, R2  : out Float;
0191               Valid   : out Boolean)
0192 is
0193    Z : Float;
0194 
0195    type Discriminated_Record (Size : Natural) is
0196       record
0197          A : String (1 .. Size);
0198          B : Integer;
0199       end record;
0200 
0201 begin
0202    Z := B**2 - 4.0 * A * C;
0203 
0204    if At_Location > In_Text'Last
0205       or else At_Location + Pattern'Length - 1 >
0206       In_Text'Last
0207       or else Slided_Text_T (In_Text (
0208                                         At_Location .. At_Location + Pattern'Length - 1)) /=
0209          Slided_Pattern
0210    then
0211       Valid := False;  -- Being out parameter, it should be modified at least once.
0212       R1    := 0.0;
0213       R2    := 0.0;
0214 <<lab>>
0215    else
0216       Valid := True;
0217       R1    := (-B + Sqrt (Z)) / (2.0 * A);
0218       R2    := (-B - Sqrt (Z)) / (2.0 * A);
0219    end if;
0220 end Quadratic_Equation;
0221 
0222 
0223 procedure Error_Handling_4 is
0224 
0225    Float_Error : exception;
0226 
0227    type DEVICE is (PRINTER, DISK, DRUM);
0228    type STATE  is (OPEN, CLOSED);
0229 
0230    type PERIPHERAL(UNIT : DEVICE := DISK) is
0231       record
0232          STATUS : STATE;
0233          case UNIT is
0234             when PRINTER =>
0235                LINE_COUNT : INTEGER range 1 .. PAGE_SIZE;
0236             when others =>
0237                CYLINDER   : CYLINDER_INDEX;
0238                TRACK      : TRACK_NUMBER;
0239          end case;
0240       end record;
0241 
0242 
0243    function Square_Root (X : in Float) return Float is
0244       use Ada.Numerics.Elementary_Functions;
0245    begin
0246       if (X < 0.0) then
0247          raise Float_Error;
0248       else
0249          return Sqrt (X);
0250       end if;
0251    end Square_Root;
0252 
0253 begin
0254 
0255    begin
0256       C := Square_Root (A ** 2 + B ** 2);
0257 
0258       T_IO.Put ("C is ");
0259       F_IO.Put
0260          (Item => C,
0261           Fore => (F_IO.Default_Fore +
0262                    1 ),
0263           Aft  => F_IO.Default_Aft,
0264           Exp  => F_IO.Default_Exp);
0265    exception
0266       when Constraint_Error =>
0267          T_IO.Put ("C cannot be calculated!");
0268    end;
0269 
0270    return;
0271 end Error_Handling_4;
0272 
0273 
0274 procedure Range_1 is
0275    type Range_Type is range -5 .. 10;
0276 
0277    Default_String : constant String := "This is the long string returned by" &
0278                                        " default.  It is broken into multiple" &
0279                                        " Ada source lines for convenience.";
0280 
0281    Another_Default_String : constant String :=
0282       "This is the long string returned by" &
0283       " default.  It is broken into multiple" &
0284       " Ada source lines for convenience.";
0285 
0286    type Op_Codes_In_Column is
0287            ( Push,
0288              Pop,
0289              Add );
0290 
0291    package T_IO renames Ada.Text_IO;
0292    package I_IO is
0293       new  Ada.Text_IO.Integer_IO (Range_Type);
0294 
0295    a: real;
0296 
0297 
0298 begin
0299    for A in Range_Type loop
0300       I_IO.Put (Item  => A,
0301                 Width => 3,                   -- CHECK: params should line up
0302                 Base  => 10);
0303 
0304       if A < Range_Type'Last then
0305          Process_Each_Page:
0306          loop
0307 
0308             declare
0309                package Float_100_Stack is new Generic_Stack (100, Float);
0310                use Float_100_Stack;
0311             begin
0312                Push (45.8);
0313             end;
0314 
0315             Process_All_The_Lines_On_This_Page:
0316             loop
0317                s1;
0318                exit Process_All_The_Lines_On_This_Page when Line_Number = Max_Lines_On_Page;
0319                s2;
0320                Look_For_Sentinel_Value:
0321                loop
0322                   s3;
0323                   exit Look_For_Sentinel_Value when Current_Symbol = Sentinel;
0324                   s4;
0325                end loop Look_For_Sentinel_Value;
0326                s5;
0327             end loop Process_All_The_Lines_On_This_Page;
0328             s6;
0329             exit Process_Each_Page when Page_Number = Maximum_Pages;
0330             s7;
0331          end loop Process_Each_Page;
0332       else
0333          T_IO.New_Line;
0334 
0335          -- comment below scans back to here !!??
0336          for I in  A'Range (1) loop
0337             for J in  A'Range (2) loop
0338                Sum := 0.0;
0339                for R in  A'Range (2) loop
0340                   Sum := Sum + A.all (I, R) * B.all (R, J);
0341                end loop;
0342                C.all (I, J) := Sum +
0343                                second_part_of_long_expression +
0344                                third_part_of_long_expression;
0345                if Input_Found then
0346                   Count_Characters;
0347 
0348                else  --not Input_Found
0349                   Reset_State;
0350                   Character_Total :=
0351                      First_Part_Total  * First_Part_Scale_Factor  +
0352                      Second_Part_Total * Second_Part_Scale_Factor +
0353                      Default_String'Length + Delimiter_Size;
0354                end if;
0355 
0356             end loop;
0357          end loop;
0358       end if;
0359    end loop;
0360 end Range_1;
0361 
0362 -- generic instantiation   -- TODO: wrong, ...
0363 -- ... statementIndent() scans back to for R in A'Range ... ??? ...
0364 -- ... because it skips over the ends
0365 
0366 package Day_Of_Month_IO is  -- TODO: scans back to beginning of file: generic? should have stopped at 'procedure'
0367    new Ada.Text_IO.Integer_IO (Day_Of_Month);
0368 
0369 procedure f;
0370 
0371 -- CHECK: these should be recognised as forward procedures ...
0372 procedure Day_Of (Day, Month, Year : in Integer;
0373                   Result           : out Integer);
0374 procedure x;
0375 procedure x1;
0376 
0377 procedure TRAVERSE_TREE;
0378 procedure INCREMENT(X : in out INTEGER);
0379 procedure RIGHT_INDENT(MARGIN : out LINE_SIZE);          --  see 3.5.4
0380 procedure SWITCH(FROM, TO : in out LINK);                --  see 3.8.1
0381 
0382 function RANDOM return PROBABILITY;                      --  see 3.5.7
0383 
0384 function MIN_CELL(X : LINK) return CELL;                 --  see 3.8.1
0385 function NEXT_FRAME(K : POSITIVE) return FRAME;          --  see 3.8
0386 function DOT_PRODUCT(LEFT,RIGHT: VECTOR) return REAL;    --  see 3.6
0387 
0388 function "*"(LEFT,RIGHT : MATRIX) return MATRIX;         --  see 3.6
0389 
0390 procedure Nesting is
0391 
0392    procedure Triple is
0393 
0394       procedure Second_Layer(Persistence : in out Persistence_View;
0395                              Stream      : not null access Root_Stream_Type'Class)
0396       is
0397 
0398          procedure Bottom_Layer is
0399          begin
0400             Put_Line("This is the Bottom Layer talking.");
0401             Do_Something;
0402 
0403             if Test then
0404                goto Exit_Use_Goto;
0405             end if;
0406             Do_Something_Else;
0407          <<Label>>
0408 
0409          <<Exit_Use_Goto>>  -- CHECK: should align with 'begin'
0410             return;
0411          end Bottom_Layer;
0412 
0413       begin -- Second_Layer
0414          Put_Line("This is the Second Layer talking.");
0415          Bottom_Layer;
0416       <<Exit_Use_Goto>>  -- CHECK: should align with 'begin'
0417          Put_Line("We are back up to the Second Layer.");
0418       end Second_Layer;
0419 
0420    begin -- Triple
0421       Put_Line("This is procedure Triple talking to you.");
0422       Second_Layer;
0423       Put_Line("We are back up to the procedure named Triple.");
0424    end Triple;
0425 
0426 begin -- Nesting
0427    Put_Line("Start the triple nesting here.");
0428    Triple;
0429    Put_Line("Finished, and back to the top level.");
0430 end Nesting;
0431 
0432 
0433 procedure Proced3 is
0434 
0435    Dogs, Cats, Animals : INTEGER;
0436 
0437    -- This is a procedure specification
0438    procedure Total_Number_Of_Animals(Variety1 : in     INTEGER;
0439                                      Variety2 : in     INTEGER;
0440                                      Total    :    out INTEGER);
0441 
0442    -- This is a procedure body
0443    procedure Total_Number_Of_Animals(Variety1 : in     INTEGER;
0444                                      Variety2 : in     INTEGER;
0445                                      Total    :    out INTEGER) is
0446    begin
0447       Total := Variety1 + Variety2;
0448    end Total_Number_Of_Animals;
0449 
0450 begin
0451    Dogs := 3;
0452    Cats := 4;
0453    if some_condition
0454       or some_other_condition
0455       or yet_another_condition
0456    then
0457       action( a,
0458               b+c,
0459               c + d
0460               + e +f +g,  -- would be nice if this was indented
0461             );
0462 
0463    end if;
0464 
0465    Total_Number_Of_Animals(Dogs, Cats, Animals);
0466    Put("The total number of animals is");
0467    Put(Animals, 3);
0468    if cond then
0469       while c loop
0470          for i in integer  -- multiline for loop
0471             range 1..1000
0472          loop
0473             a := long_expression
0474                  + long_expression
0475                  + long_expression;
0476             a(i) := 10;
0477          end loop;
0478          a := long_expression
0479               + long_expression
0480               + long_expression;
0481 
0482          while x > 0
0483             and x <= 100
0484          loop                -- CHECK: not indented
0485             loop             -- CHECK: indented
0486                a := q1 +
0487                     q2 +
0488                     q3;
0489             end loop;
0490          end loop;
0491 
0492          while x > 0 loop
0493             loop -- forever loop
0494                aaaaaaa :=
0495                   q1 +
0496                   q2 +
0497                   q3;
0498             end loop;
0499          end loop;
0500       end loop;
0501 
0502       end loop;
0503 
0504       fredzarmplezzzzzzzzzzzz(       arg1,
0505                                      arg1,
0506                                      arg2,
0507                                      arg3
0508                              );
0509       x := f(a) + f(b);
0510       fffffffffffff(    func0(  func1(    func2( f3(       arg1,
0511                                                            arg2,
0512                                                            arg3,
0513                                                            arg4
0514                                                    ),
0515                                                  a1,  -- should be aligned with arg f3, not '('
0516                                                  a2,
0517                                                  a3,
0518                                                  a4
0519                                                ),
0520 
0521                                           aa2,
0522                                           aa3,
0523                                           aa4,
0524                                           aa5
0525                                      ),
0526                                 bb1,
0527                                 bb2,
0528                                 bb3,
0529                                 bb4
0530                              ),
0531                         cc1,
0532                         cc2,
0533                         cc3,
0534                         cc4
0535                    );
0536 
0537       s1;
0538    end if;
0539 
0540    New_Line;
0541 end Proced3;
0542 
0543 
0544 procedure Main is
0545    task Sub is
0546       entry Wake_Up(I: Integer);
0547    end Sub;
0548 
0549    task body Sub is
0550       Stop: Boolean := False;
0551    begin
0552       while not Stop loop
0553          Put("Sub:  Wait"); New_Line(1);
0554          accept Wake_Up(I: Integer) do
0555             Put("Sub:  "); Put(I); New_Line(1);
0556             if I = 0 then
0557                Stop := True;
0558             end if;
0559          end Wake_Up;
0560       end loop;
0561       Put("Sub:  Stop"); New_Line(1);
0562    end Sub;
0563 begin
0564    Extract_Publisher:
0565    for Index in Base_11_Digits (Item.Country + 1) ..
0566       Base_11_Digits (Item.Publisher) loop
0567       declare
0568 
0569          Digit : constant Natural range 0 .. 9
0570             := Natural (Item.Number (Index));
0571          Power : constant Natural range 0 .. 9
0572             := Item.Publisher - Natural (Index);
0573 
0574       begin
0575          Publisher := Publisher + Digit * (10 ** Power);
0576       end;
0577    end loop Extract_Publisher;   -- CHECK: matches 'for' above
0578 
0579    Put("Main: Stop"); New_Line(1);
0580    declare
0581    begin
0582    end;
0583    if c
0584       and c2
0585    then
0586       s1;
0587       for i in a'range
0588       loop
0589          loop
0590             s12;
0591             s13;
0592          end lop;
0593       end loop;
0594    elsif c05
0595       or c06
0596    then
0597       s12;
0598    elsif c1 then
0599       s2;
0600    else
0601       s3;
0602       a12 :=
0603          f(13);
0604    end if;
0605 end;
0606 end;
0607 
0608 
0609 package Utilities is
0610    generic
0611       type Item is private;
0612    procedure Swap(L, R : in out Item);
0613    -- A handy package at the project-specific level
0614    -- A constrained generic formal parameter
0615    generic
0616       type Item is (<>);
0617    function Next (Data : Item) return Item;
0618    -- A discrete type generic formal parameter
0619    generic
0620       type Item is (<>);
0621       -- A discrete type generic formal parameter
0622    function Prev (Data : Item) return Item;
0623    -- more generic subprograms as appropriate to your particular project needs
0624 end Utilities;
0625 
0626 
0627 // kate: line-numbers true; indent-width 3; replace-tabs on
0628 // kate: debugMode off