OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [styleg.adb] - Blame information for rev 718

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 706 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--                               S T Y L E G                                --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
10
--                                                                          --
11
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12
-- terms of the  GNU General Public License as published  by the Free Soft- --
13
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17
-- for  more details.  You should have  received  a copy of the GNU General --
18
-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19
-- http://www.gnu.org/licenses for a complete copy of the license.          --
20
--                                                                          --
21
-- GNAT was originally developed  by the GNAT team at  New York University. --
22
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23
--                                                                          --
24
------------------------------------------------------------------------------
25
 
26
--  This version of the Style package implements the standard GNAT style
27
--  checking rules. For documentation of these rules, see comments on the
28
--  individual procedures.
29
 
30
with Atree;    use Atree;
31
with Casing;   use Casing;
32
with Csets;    use Csets;
33
with Einfo;    use Einfo;
34
with Err_Vars; use Err_Vars;
35
with Opt;      use Opt;
36
with Scans;    use Scans;
37
with Sinfo;    use Sinfo;
38
with Sinput;   use Sinput;
39
with Stylesw;  use Stylesw;
40
 
41
package body Styleg is
42
 
43
   use ASCII;
44
 
45
   Blank_Lines : Nat := 0;
46
   --  Counts number of empty lines seen. Reset to zero if a non-empty line
47
   --  is encountered. Used to check for trailing blank lines in Check_EOF,
48
   --  and for multiple blank lines.
49
 
50
   Blank_Line_Location : Source_Ptr;
51
   --  Remembers location of first blank line in a series. Used to issue an
52
   --  appropriate diagnostic if subsequent blank lines or the end of file
53
   --  is encountered.
54
 
55
   -----------------------
56
   -- Local Subprograms --
57
   -----------------------
58
 
59
   procedure Check_No_Space_After;
60
   --  Checks that there is a non-white space character after the current
61
   --  token, or white space followed by a comment, or the end of line.
62
   --  Issue error message if not.
63
 
64
   procedure Check_No_Space_Before;
65
   --  Check that token is first token on line, or else is not preceded
66
   --  by white space. Signal error of space not allowed if not.
67
 
68
   procedure Check_Separate_Stmt_Lines_Cont;
69
   --  Non-inlined continuation of Check_Separate_Stmt_Lines
70
 
71
   function Determine_Token_Casing return Casing_Type;
72
   --  Determine casing of current token
73
 
74
   procedure Error_Space_Not_Allowed (S : Source_Ptr);
75
   --  Posts an error message indicating that a space is not allowed
76
   --  at the given source location.
77
 
78
   procedure Error_Space_Required (S : Source_Ptr);
79
   --  Posts an error message indicating that a space is required at
80
   --  the given source location.
81
 
82
   function Is_White_Space (C : Character) return Boolean;
83
   pragma Inline (Is_White_Space);
84
   --  Returns True for space, HT, VT or FF, False otherwise
85
 
86
   procedure Require_Following_Space;
87
   pragma Inline (Require_Following_Space);
88
   --  Require token to be followed by white space. Used only if in GNAT
89
   --  style checking mode.
90
 
91
   procedure Require_Preceding_Space;
92
   pragma Inline (Require_Preceding_Space);
93
   --  Require token to be preceded by white space. Used only if in GNAT
94
   --  style checking mode.
95
 
96
   ----------------------
97
   -- Check_Abs_Or_Not --
98
   ----------------------
99
 
100
   --  In check tokens mode (-gnatyt), ABS/NOT must be followed by a space
101
 
102
   procedure Check_Abs_Not is
103
   begin
104
      if Style_Check_Tokens then
105
         if Source (Scan_Ptr) > ' ' then
106
            Error_Space_Required (Scan_Ptr);
107
         end if;
108
      end if;
109
   end Check_Abs_Not;
110
 
111
   ----------------------
112
   -- Check_Apostrophe --
113
   ----------------------
114
 
115
   --  Do not allow space before or after apostrophe
116
 
117
   procedure Check_Apostrophe is
118
   begin
119
      if Style_Check_Tokens then
120
         Check_No_Space_After;
121
      end if;
122
   end Check_Apostrophe;
123
 
124
   -----------------
125
   -- Check_Arrow --
126
   -----------------
127
 
128
   --  In check tokens mode (-gnatys), arrow must be surrounded by spaces
129
 
130
   procedure Check_Arrow is
131
   begin
132
      if Style_Check_Tokens then
133
         Require_Preceding_Space;
134
         Require_Following_Space;
135
      end if;
136
   end Check_Arrow;
137
 
138
   --------------------------
139
   -- Check_Attribute_Name --
140
   --------------------------
141
 
142
   --  In check attribute casing mode (-gnatya), attribute names must be
143
   --  mixed case, i.e. start with an upper case letter, and otherwise
144
   --  lower case, except after an underline character.
145
 
146
   procedure Check_Attribute_Name (Reserved : Boolean) is
147
      pragma Warnings (Off, Reserved);
148
   begin
149
      if Style_Check_Attribute_Casing then
150
         if Determine_Token_Casing /= Mixed_Case then
151
            Error_Msg_SC -- CODEFIX
152
              ("(style) bad capitalization, mixed case required");
153
         end if;
154
      end if;
155
   end Check_Attribute_Name;
156
 
157
   ---------------------------
158
   -- Check_Binary_Operator --
159
   ---------------------------
160
 
161
   --  In check token mode (-gnatyt), binary operators other than the special
162
   --  case of exponentiation require surrounding space characters.
163
 
164
   procedure Check_Binary_Operator is
165
   begin
166
      if Style_Check_Tokens then
167
         Require_Preceding_Space;
168
         Require_Following_Space;
169
      end if;
170
   end Check_Binary_Operator;
171
 
172
   ----------------------------
173
   -- Check_Boolean_Operator --
174
   ----------------------------
175
 
176
   procedure Check_Boolean_Operator (Node : Node_Id) is
177
 
178
      function OK_Boolean_Operand (N : Node_Id) return Boolean;
179
      --  Returns True for simple variable, or "not X1" or "X1 and X2" or
180
      --  "X1 or X2" where X1, X2 are recursively OK_Boolean_Operand's.
181
 
182
      ------------------------
183
      -- OK_Boolean_Operand --
184
      ------------------------
185
 
186
      function OK_Boolean_Operand (N : Node_Id) return Boolean is
187
      begin
188
         if Nkind_In (N, N_Identifier, N_Expanded_Name) then
189
            return True;
190
 
191
         elsif Nkind (N) = N_Op_Not then
192
            return OK_Boolean_Operand (Original_Node (Right_Opnd (N)));
193
 
194
         elsif Nkind_In (N, N_Op_And, N_Op_Or) then
195
            return OK_Boolean_Operand (Original_Node (Left_Opnd (N)))
196
                     and then
197
                   OK_Boolean_Operand (Original_Node (Right_Opnd (N)));
198
 
199
         else
200
            return False;
201
         end if;
202
      end OK_Boolean_Operand;
203
 
204
   --  Start of processing for Check_Boolean_Operator
205
 
206
   begin
207
      if Style_Check_Boolean_And_Or
208
        and then Comes_From_Source (Node)
209
      then
210
         declare
211
            Orig : constant Node_Id := Original_Node (Node);
212
 
213
         begin
214
            if Nkind_In (Orig, N_Op_And, N_Op_Or) then
215
               declare
216
                  L : constant Node_Id := Original_Node (Left_Opnd  (Orig));
217
                  R : constant Node_Id := Original_Node (Right_Opnd (Orig));
218
 
219
               begin
220
                  --  First OK case, simple boolean constants/identifiers
221
 
222
                  if OK_Boolean_Operand (L)
223
                       and then
224
                     OK_Boolean_Operand (R)
225
                  then
226
                     return;
227
 
228
                  --  Second OK case, modular types
229
 
230
                  elsif Is_Modular_Integer_Type (Etype (Node)) then
231
                     return;
232
 
233
                  --  Third OK case, array types
234
 
235
                  elsif Is_Array_Type (Etype (Node)) then
236
                     return;
237
 
238
                  --  Otherwise we have an error
239
 
240
                  elsif Nkind (Orig) = N_Op_And then
241
                     Error_Msg -- CODEFIX
242
                       ("(style) `AND THEN` required", Sloc (Orig));
243
                  else
244
                     Error_Msg -- CODEFIX
245
                       ("(style) `OR ELSE` required", Sloc (Orig));
246
                  end if;
247
               end;
248
            end if;
249
         end;
250
      end if;
251
   end Check_Boolean_Operator;
252
 
253
   ---------------
254
   -- Check_Box --
255
   ---------------
256
 
257
   --  In check token mode (-gnatyt), box must be preceded by a space or by
258
   --  a left parenthesis. Spacing checking on the surrounding tokens takes
259
   --  care of the remaining checks.
260
 
261
   procedure Check_Box is
262
   begin
263
      if Style_Check_Tokens then
264
         if Prev_Token /= Tok_Left_Paren then
265
            Require_Preceding_Space;
266
         end if;
267
      end if;
268
   end Check_Box;
269
 
270
   -----------------
271
   -- Check_Colon --
272
   -----------------
273
 
274
   --  In check token mode (-gnatyt), colon must be surrounded by spaces
275
 
276
   procedure Check_Colon is
277
   begin
278
      if Style_Check_Tokens then
279
         Require_Preceding_Space;
280
         Require_Following_Space;
281
      end if;
282
   end Check_Colon;
283
 
284
   -----------------------
285
   -- Check_Colon_Equal --
286
   -----------------------
287
 
288
   --  In check token mode (-gnatyt), := must be surrounded by spaces
289
 
290
   procedure Check_Colon_Equal is
291
   begin
292
      if Style_Check_Tokens then
293
         Require_Preceding_Space;
294
         Require_Following_Space;
295
      end if;
296
   end Check_Colon_Equal;
297
 
298
   -----------------
299
   -- Check_Comma --
300
   -----------------
301
 
302
   --  In check token mode (-gnatyt), comma must be either the first
303
   --  token on a line, or be preceded by a non-blank character.
304
   --  It must also always be followed by a blank.
305
 
306
   procedure Check_Comma is
307
   begin
308
      if Style_Check_Tokens then
309
         Check_No_Space_Before;
310
 
311
         if Source (Scan_Ptr) > ' ' then
312
            Error_Space_Required (Scan_Ptr);
313
         end if;
314
      end if;
315
   end Check_Comma;
316
 
317
   -------------------
318
   -- Check_Comment --
319
   -------------------
320
 
321
   --  In check comment mode (-gnatyc) there are several requirements on the
322
   --  format of comments. The following are permissible comment formats:
323
 
324
   --    1. Any comment that is not at the start of a line, i.e. where the
325
   --       initial minuses are not the first non-blank characters on the
326
   --       line must have at least one blank after the second minus or a
327
   --       special character as defined in rule 5.
328
 
329
   --    2. A row of all minuses of any length is permitted (see procedure
330
   --       box above in the source of this routine).
331
 
332
   --    3. A comment line starting with two minuses and a space, and ending
333
   --       with a space and two minuses. Again see the procedure title box
334
   --       immediately above in the source.
335
 
336
   --    4. A full line comment where two spaces follow the two minus signs.
337
   --       This is the normal comment format in GNAT style, as typified by
338
   --       the comments you are reading now.
339
 
340
   --    5. A full line comment where the first character after the second
341
   --       minus is a special character, i.e. a character in the ASCII
342
   --       range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special
343
   --       comments, such as those generated by gnatprep, or those that
344
   --       appear in the SPARK annotation language to be accepted.
345
 
346
   --       Note: for GNAT internal files (-gnatg switch set on for the
347
   --       compilation), the only special sequence recognized and allowed
348
   --       is --! as generated by gnatprep.
349
 
350
   --    6. In addition, the comment must be properly indented if comment
351
   --       indentation checking is active (Style_Check_Indentation non-zero).
352
   --       Either the start column must be a multiple of this indentation,
353
   --       or the indentation must match that of the next non-blank line.
354
 
355
   procedure Check_Comment is
356
      S : Source_Ptr;
357
      C : Character;
358
 
359
      function Is_Box_Comment return Boolean;
360
      --  Returns True if the last two characters on the line are -- which
361
      --  characterizes a box comment (as for example follows this spec).
362
 
363
      function Is_Special_Character (C : Character) return Boolean;
364
      --  Determines if C is a special character (see rule 5 above)
365
 
366
      function Same_Column_As_Next_Non_Blank_Line return Boolean;
367
      --  Called for a full line comment. If the indentation of this comment
368
      --  matches that of the next non-blank line in the source, then True is
369
      --  returned, otherwise False.
370
 
371
      --------------------
372
      -- Is_Box_Comment --
373
      --------------------
374
 
375
      function Is_Box_Comment return Boolean is
376
         S : Source_Ptr;
377
 
378
      begin
379
         --  Do we need to worry about UTF_32 line terminators here ???
380
 
381
         S := Scan_Ptr + 3;
382
         while Source (S) not in Line_Terminator loop
383
            S := S + 1;
384
         end loop;
385
 
386
         return Source (S - 1) = '-' and then Source (S - 2) = '-';
387
      end Is_Box_Comment;
388
 
389
      --------------------------
390
      -- Is_Special_Character --
391
      --------------------------
392
 
393
      function Is_Special_Character (C : Character) return Boolean is
394
      begin
395
         if GNAT_Mode then
396
            return C = '!';
397
         else
398
            return
399
              Character'Pos (C) in 16#21# .. 16#2F#
400
                or else
401
              Character'Pos (C) in 16#3A# .. 16#3F#;
402
         end if;
403
      end Is_Special_Character;
404
 
405
      ----------------------------------------
406
      -- Same_Column_As_Next_Non_Blank_Line --
407
      ----------------------------------------
408
 
409
      function Same_Column_As_Next_Non_Blank_Line return Boolean is
410
         P : Source_Ptr;
411
 
412
      begin
413
         --  Step to end of line
414
 
415
         P := Scan_Ptr + 2;
416
         while Source (P) not in Line_Terminator loop
417
            P := P + 1;
418
         end loop;
419
 
420
         --  Step past blanks, and line terminators (UTF_32 case???)
421
 
422
         while Source (P) <= ' ' and then Source (P) /= EOF loop
423
            P := P + 1;
424
         end loop;
425
 
426
         --  Compare columns
427
 
428
         return Get_Column_Number (Scan_Ptr) = Get_Column_Number (P);
429
      end Same_Column_As_Next_Non_Blank_Line;
430
 
431
   --  Start of processing for Check_Comment
432
 
433
   begin
434
      --  Can never have a non-blank character preceding the first minus
435
 
436
      if Style_Check_Comments then
437
         if Scan_Ptr > Source_First (Current_Source_File)
438
           and then Source (Scan_Ptr - 1) > ' '
439
         then
440
            Error_Msg_S -- CODEFIX
441
              ("(style) space required");
442
         end if;
443
      end if;
444
 
445
      --  For a comment that is not at the start of the line, the only
446
      --  requirement is that we cannot have a non-blank character after
447
      --  the second minus sign or a special character.
448
 
449
      if Scan_Ptr /= First_Non_Blank_Location then
450
         if Style_Check_Comments then
451
            if Source (Scan_Ptr + 2) > ' '
452
              and then not Is_Special_Character (Source (Scan_Ptr + 2))
453
            then
454
               Error_Msg -- CODEFIX
455
                 ("(style) space required", Scan_Ptr + 2);
456
            end if;
457
         end if;
458
 
459
         return;
460
 
461
      --  Case of a comment that is at the start of a line
462
 
463
      else
464
         --  First check, must be in appropriately indented column
465
 
466
         if Style_Check_Indentation /= 0 then
467
            if Start_Column rem Style_Check_Indentation /= 0 then
468
               if not Same_Column_As_Next_Non_Blank_Line then
469
                  Error_Msg_S -- CODEFIX
470
                    ("(style) bad column");
471
               end if;
472
 
473
               return;
474
            end if;
475
         end if;
476
 
477
         --  If we are not checking comments, nothing more to do
478
 
479
         if not Style_Check_Comments then
480
            return;
481
         end if;
482
 
483
         --  Case of not followed by a blank. Usually wrong, but there are
484
         --  some exceptions that we permit.
485
 
486
         if Source (Scan_Ptr + 2) /= ' ' then
487
            C := Source (Scan_Ptr + 2);
488
 
489
            --  Case of -- all on its own on a line is OK
490
 
491
            if C < ' ' then
492
               return;
493
            end if;
494
 
495
            --  Case of --x, x special character is OK (gnatprep/SPARK/etc.)
496
            --  This is not permitted in internal GNAT implementation units
497
            --  except for the case of --! as used by gnatprep output.
498
 
499
            if Is_Special_Character (C) then
500
               return;
501
            end if;
502
 
503
            --  The only other case in which we allow a character after
504
            --  the -- other than a space is when we have a row of minus
505
            --  signs (case of header lines for a box comment for example).
506
 
507
            S := Scan_Ptr + 2;
508
            while Source (S) >= ' ' loop
509
               if Source (S) /= '-' then
510
                  if Is_Box_Comment
511
                    or else Style_Check_Comments_Spacing = 1
512
                  then
513
                     Error_Space_Required (Scan_Ptr + 2);
514
                  else
515
                     Error_Msg -- CODEFIX
516
                       ("(style) two spaces required", Scan_Ptr + 2);
517
                  end if;
518
 
519
                  return;
520
               end if;
521
 
522
               S := S + 1;
523
            end loop;
524
 
525
         --  If we are followed by a blank, then the comment is OK if the
526
         --  character following this blank is another blank or a format
527
         --  effector, or if the required comment spacing is 1.
528
 
529
         elsif Source (Scan_Ptr + 3) <= ' '
530
           or else Style_Check_Comments_Spacing = 1
531
         then
532
            return;
533
 
534
         --  Here is the case where we only have one blank after the two minus
535
         --  signs, with Style_Check_Comments_Spacing set to 2, which is an
536
         --  error unless the line ends with two minus signs, the case of a
537
         --  box comment.
538
 
539
         elsif not Is_Box_Comment then
540
            Error_Space_Required (Scan_Ptr + 3);
541
         end if;
542
      end if;
543
   end Check_Comment;
544
 
545
   -------------------
546
   -- Check_Dot_Dot --
547
   -------------------
548
 
549
   --  In check token mode (-gnatyt), colon must be surrounded by spaces
550
 
551
   procedure Check_Dot_Dot is
552
   begin
553
      if Style_Check_Tokens then
554
         Require_Preceding_Space;
555
         Require_Following_Space;
556
      end if;
557
   end Check_Dot_Dot;
558
 
559
   ---------------
560
   -- Check_EOF --
561
   ---------------
562
 
563
   --  In check blanks at end mode, check no blank lines precede the EOF
564
 
565
   procedure Check_EOF is
566
   begin
567
      if Style_Check_Blank_Lines then
568
 
569
         --  We expect one blank line, from the EOF, but no more than one
570
 
571
         if Blank_Lines = 2 then
572
            Error_Msg -- CODEFIX
573
              ("(style) blank line not allowed at end of file",
574
               Blank_Line_Location);
575
 
576
         elsif Blank_Lines >= 3 then
577
            Error_Msg -- CODEFIX
578
              ("(style) blank lines not allowed at end of file",
579
               Blank_Line_Location);
580
         end if;
581
      end if;
582
   end Check_EOF;
583
 
584
   -----------------------------------
585
   -- Check_Exponentiation_Operator --
586
   -----------------------------------
587
 
588
   --  No spaces are required for the ** operator in GNAT style check mode
589
 
590
   procedure Check_Exponentiation_Operator is
591
   begin
592
      null;
593
   end Check_Exponentiation_Operator;
594
 
595
   --------------
596
   -- Check_HT --
597
   --------------
598
 
599
   --  In check horizontal tab mode (-gnatyh), tab characters are not allowed
600
 
601
   procedure Check_HT is
602
   begin
603
      if Style_Check_Horizontal_Tabs then
604
         Error_Msg_S -- CODEFIX
605
           ("(style) horizontal tab not allowed");
606
      end if;
607
   end Check_HT;
608
 
609
   -----------------------
610
   -- Check_Indentation --
611
   -----------------------
612
 
613
   --  In check indentation mode (-gnatyn for n a digit), a new statement or
614
   --  declaration is required to start in a column that is a multiple of the
615
   --  indentation amount.
616
 
617
   procedure Check_Indentation is
618
   begin
619
      if Style_Check_Indentation /= 0 then
620
         if Token_Ptr = First_Non_Blank_Location
621
           and then Start_Column rem Style_Check_Indentation /= 0
622
         then
623
            Error_Msg_SC -- CODEFIX
624
              ("(style) bad indentation");
625
         end if;
626
      end if;
627
   end Check_Indentation;
628
 
629
   ----------------------
630
   -- Check_Left_Paren --
631
   ----------------------
632
 
633
   --  In tone check mode (-gnatyt), left paren must not be preceded by an
634
   --  identifier character or digit (a separating space is required) and
635
   --  may never be followed by a space.
636
 
637
   procedure Check_Left_Paren is
638
   begin
639
      if Style_Check_Tokens then
640
         if Token_Ptr > Source_First (Current_Source_File)
641
           and then Identifier_Char (Source (Token_Ptr - 1))
642
         then
643
            Error_Space_Required (Token_Ptr);
644
         end if;
645
 
646
         Check_No_Space_After;
647
      end if;
648
   end Check_Left_Paren;
649
 
650
   ---------------------------
651
   -- Check_Line_Max_Length --
652
   ---------------------------
653
 
654
   --  In check max line length mode (-gnatym), the line length must
655
   --  not exceed the permitted maximum value.
656
 
657
   procedure Check_Line_Max_Length (Len : Int) is
658
   begin
659
      if Style_Check_Max_Line_Length then
660
         if Len > Style_Max_Line_Length then
661
            Error_Msg
662
              ("(style) this line is too long",
663
               Current_Line_Start + Source_Ptr (Style_Max_Line_Length));
664
         end if;
665
      end if;
666
   end Check_Line_Max_Length;
667
 
668
   ---------------------------
669
   -- Check_Line_Terminator --
670
   ---------------------------
671
 
672
   --  In check blanks at end mode (-gnatyb), lines may not end with a
673
   --  trailing space.
674
 
675
   --  In check form feeds mode (-gnatyf), the line terminator may not
676
   --  be either of the characters FF or VT.
677
 
678
   --  In check DOS line terminators node (-gnatyd), the line terminator
679
   --  must be a single LF, without a following CR.
680
 
681
   procedure Check_Line_Terminator (Len : Int) is
682
      S : Source_Ptr;
683
 
684
      L : Int := Len;
685
      --  Length of line (adjusted down for blanks at end of line)
686
 
687
   begin
688
      --  Reset count of blank lines if first line
689
 
690
      if Get_Logical_Line_Number (Scan_Ptr) = 1 then
691
         Blank_Lines := 0;
692
      end if;
693
 
694
      --  Check FF/VT terminators
695
 
696
      if Style_Check_Form_Feeds then
697
         if Source (Scan_Ptr) = ASCII.FF then
698
            Error_Msg_S -- CODEFIX
699
              ("(style) form feed not allowed");
700
         elsif Source (Scan_Ptr) = ASCII.VT then
701
            Error_Msg_S -- CODEFIX
702
              ("(style) vertical tab not allowed");
703
         end if;
704
      end if;
705
 
706
      --  Check DOS line terminator
707
 
708
      if Style_Check_DOS_Line_Terminator then
709
 
710
      --  Ignore EOF, since we only get called with an EOF if it is the last
711
      --  character in the buffer (and was therefore not in the source file),
712
      --  since the terminating EOF is added to stop the scan.
713
 
714
         if Source (Scan_Ptr) = EOF then
715
            null;
716
 
717
         --  Bad terminator if we don't have an LF
718
 
719
         elsif Source (Scan_Ptr) /= LF then
720
            Error_Msg_S ("(style) incorrect line terminator");
721
         end if;
722
      end if;
723
 
724
      --  Remove trailing spaces
725
 
726
      S := Scan_Ptr;
727
      while L > 0 and then Is_White_Space (Source (S - 1)) loop
728
         S := S - 1;
729
         L := L - 1;
730
      end loop;
731
 
732
      --  Issue message for blanks at end of line if option enabled
733
 
734
      if Style_Check_Blanks_At_End and then L < Len then
735
         Error_Msg -- CODEFIX
736
           ("(style) trailing spaces not permitted", S);
737
      end if;
738
 
739
      --  Deal with empty (blank) line
740
 
741
      if L = 0 then
742
 
743
         --  Increment blank line count
744
 
745
         Blank_Lines := Blank_Lines + 1;
746
 
747
         --  If first blank line, record location for later error message
748
 
749
         if Blank_Lines = 1 then
750
            Blank_Line_Location := Scan_Ptr;
751
         end if;
752
 
753
      --  Non-blank line, check for previous multiple blank lines
754
 
755
      else
756
         if Style_Check_Blank_Lines and then Blank_Lines > 1 then
757
            Error_Msg -- CODEFIX
758
              ("(style) multiple blank lines", Blank_Line_Location);
759
         end if;
760
 
761
         --  And reset blank line count
762
 
763
         Blank_Lines := 0;
764
      end if;
765
   end Check_Line_Terminator;
766
 
767
   --------------------------
768
   -- Check_No_Space_After --
769
   --------------------------
770
 
771
   procedure Check_No_Space_After is
772
      S : Source_Ptr;
773
 
774
   begin
775
      if Is_White_Space (Source (Scan_Ptr)) then
776
 
777
         --  Allow one or more spaces if followed by comment
778
 
779
         S := Scan_Ptr + 1;
780
         loop
781
            if Source (S) = '-' and then Source (S + 1) = '-' then
782
               return;
783
 
784
            elsif Is_White_Space (Source (S)) then
785
               S := S + 1;
786
 
787
            else
788
               exit;
789
            end if;
790
         end loop;
791
 
792
         Error_Space_Not_Allowed (Scan_Ptr);
793
      end if;
794
   end Check_No_Space_After;
795
 
796
   ---------------------------
797
   -- Check_No_Space_Before --
798
   ---------------------------
799
 
800
   procedure Check_No_Space_Before is
801
   begin
802
      if Token_Ptr > First_Non_Blank_Location
803
         and then Source (Token_Ptr - 1) <= ' '
804
      then
805
         Error_Space_Not_Allowed (Token_Ptr - 1);
806
      end if;
807
   end Check_No_Space_Before;
808
 
809
   -----------------------
810
   -- Check_Pragma_Name --
811
   -----------------------
812
 
813
   --  In check pragma casing mode (-gnatyp), pragma names must be mixed
814
   --  case, i.e. start with an upper case letter, and otherwise lower case,
815
   --  except after an underline character.
816
 
817
   procedure Check_Pragma_Name is
818
   begin
819
      if Style_Check_Pragma_Casing then
820
         if Determine_Token_Casing /= Mixed_Case then
821
            Error_Msg_SC -- CODEFIX
822
              ("(style) bad capitalization, mixed case required");
823
         end if;
824
      end if;
825
   end Check_Pragma_Name;
826
 
827
   -----------------------
828
   -- Check_Right_Paren --
829
   -----------------------
830
 
831
   --  In check tokens mode (-gnatyt), right paren must not be immediately
832
   --  followed by an identifier character, and must never be preceded by
833
   --  a space unless it is the initial non-blank character on the line.
834
 
835
   procedure Check_Right_Paren is
836
   begin
837
      if Style_Check_Tokens then
838
         if Identifier_Char (Source (Token_Ptr + 1)) then
839
            Error_Space_Required (Token_Ptr + 1);
840
         end if;
841
 
842
         Check_No_Space_Before;
843
      end if;
844
   end Check_Right_Paren;
845
 
846
   ---------------------
847
   -- Check_Semicolon --
848
   ---------------------
849
 
850
   --  In check tokens mode (-gnatyt), semicolon does not permit a preceding
851
   --  space and a following space is required.
852
 
853
   procedure Check_Semicolon is
854
   begin
855
      if Style_Check_Tokens then
856
         Check_No_Space_Before;
857
 
858
         if Source (Scan_Ptr) > ' ' then
859
            Error_Space_Required (Scan_Ptr);
860
         end if;
861
      end if;
862
   end Check_Semicolon;
863
 
864
   -------------------------------
865
   -- Check_Separate_Stmt_Lines --
866
   -------------------------------
867
 
868
   procedure Check_Separate_Stmt_Lines is
869
   begin
870
      if Style_Check_Separate_Stmt_Lines then
871
         Check_Separate_Stmt_Lines_Cont;
872
      end if;
873
   end Check_Separate_Stmt_Lines;
874
 
875
   ------------------------------------
876
   -- Check_Separate_Stmt_Lines_Cont --
877
   ------------------------------------
878
 
879
   procedure Check_Separate_Stmt_Lines_Cont is
880
      S : Source_Ptr;
881
 
882
   begin
883
      --  Skip past white space
884
 
885
      S := Scan_Ptr;
886
      while Is_White_Space (Source (S)) loop
887
         S := S + 1;
888
      end loop;
889
 
890
      --  Line terminator is OK
891
 
892
      if Source (S) in Line_Terminator then
893
         return;
894
 
895
      --  Comment is OK
896
 
897
      elsif Source (S) = '-' and then Source (S + 1) = '-' then
898
         return;
899
 
900
      --  ABORT keyword is OK after THEN (THEN ABORT case)
901
 
902
      elsif Token = Tok_Then
903
        and then (Source (S + 0) = 'a' or else Source (S + 0) = 'A')
904
        and then (Source (S + 1) = 'b' or else Source (S + 1) = 'B')
905
        and then (Source (S + 2) = 'o' or else Source (S + 2) = 'O')
906
        and then (Source (S + 3) = 'r' or else Source (S + 3) = 'R')
907
        and then (Source (S + 4) = 't' or else Source (S + 4) = 'T')
908
        and then (Source (S + 5) in Line_Terminator
909
                   or else Is_White_Space (Source (S + 5)))
910
      then
911
         return;
912
 
913
      --  PRAGMA keyword is OK after ELSE
914
 
915
      elsif Token = Tok_Else
916
        and then (Source (S + 0) = 'p' or else Source (S + 0) = 'P')
917
        and then (Source (S + 1) = 'r' or else Source (S + 1) = 'R')
918
        and then (Source (S + 2) = 'a' or else Source (S + 2) = 'A')
919
        and then (Source (S + 3) = 'g' or else Source (S + 3) = 'G')
920
        and then (Source (S + 4) = 'm' or else Source (S + 4) = 'M')
921
        and then (Source (S + 5) = 'a' or else Source (S + 5) = 'A')
922
        and then (Source (S + 6) in Line_Terminator
923
                   or else Is_White_Space (Source (S + 6)))
924
      then
925
         return;
926
 
927
         --  Otherwise we have the style violation we are looking for
928
 
929
      else
930
         if Token = Tok_Then then
931
            Error_Msg -- CODEFIX
932
              ("(style) no statements may follow THEN on same line", S);
933
         else
934
            Error_Msg
935
              ("(style) no statements may follow ELSE on same line", S);
936
         end if;
937
      end if;
938
   end Check_Separate_Stmt_Lines_Cont;
939
 
940
   ----------------
941
   -- Check_Then --
942
   ----------------
943
 
944
   --  In check if then layout mode (-gnatyi), we expect a THEN keyword
945
   --  to appear either on the same line as the IF, or on a separate line
946
   --  after multiple conditions. In any case, it may not appear on the
947
   --  line immediately following the line with the IF.
948
 
949
   procedure Check_Then (If_Loc : Source_Ptr) is
950
   begin
951
      if Style_Check_If_Then_Layout then
952
         if Get_Physical_Line_Number (Token_Ptr) =
953
            Get_Physical_Line_Number (If_Loc) + 1
954
         then
955
            Error_Msg_SC ("(style) misplaced THEN");
956
         end if;
957
      end if;
958
   end Check_Then;
959
 
960
   -------------------------------
961
   -- Check_Unary_Plus_Or_Minus --
962
   -------------------------------
963
 
964
   --  In check token mode (-gnatyt), unary plus or minus must not be
965
   --  followed by a space.
966
 
967
   procedure Check_Unary_Plus_Or_Minus is
968
   begin
969
      if Style_Check_Tokens then
970
         Check_No_Space_After;
971
      end if;
972
   end Check_Unary_Plus_Or_Minus;
973
 
974
   ------------------------
975
   -- Check_Vertical_Bar --
976
   ------------------------
977
 
978
   --  In check token mode (-gnatyt), vertical bar must be surrounded by spaces
979
 
980
   procedure Check_Vertical_Bar is
981
   begin
982
      if Style_Check_Tokens then
983
         Require_Preceding_Space;
984
         Require_Following_Space;
985
      end if;
986
   end Check_Vertical_Bar;
987
 
988
   -----------------------
989
   -- Check_Xtra_Parens --
990
   -----------------------
991
 
992
   procedure Check_Xtra_Parens (Loc : Source_Ptr) is
993
   begin
994
      if Style_Check_Xtra_Parens then
995
         Error_Msg -- CODEFIX
996
           ("redundant parentheses?", Loc);
997
      end if;
998
   end Check_Xtra_Parens;
999
 
1000
   ----------------------------
1001
   -- Determine_Token_Casing --
1002
   ----------------------------
1003
 
1004
   function Determine_Token_Casing return Casing_Type is
1005
   begin
1006
      return Determine_Casing (Source (Token_Ptr .. Scan_Ptr - 1));
1007
   end Determine_Token_Casing;
1008
 
1009
   -----------------------------
1010
   -- Error_Space_Not_Allowed --
1011
   -----------------------------
1012
 
1013
   procedure Error_Space_Not_Allowed (S : Source_Ptr) is
1014
   begin
1015
      Error_Msg -- CODEFIX
1016
        ("(style) space not allowed", S);
1017
   end Error_Space_Not_Allowed;
1018
 
1019
   --------------------------
1020
   -- Error_Space_Required --
1021
   --------------------------
1022
 
1023
   procedure Error_Space_Required (S : Source_Ptr) is
1024
   begin
1025
      Error_Msg -- CODEFIX
1026
        ("(style) space required", S);
1027
   end Error_Space_Required;
1028
 
1029
   --------------------
1030
   -- Is_White_Space --
1031
   --------------------
1032
 
1033
   function Is_White_Space (C : Character) return Boolean is
1034
   begin
1035
      return C = ' ' or else C = HT;
1036
   end Is_White_Space;
1037
 
1038
   -------------------
1039
   -- Mode_In_Check --
1040
   -------------------
1041
 
1042
   function Mode_In_Check return Boolean is
1043
   begin
1044
      return Style_Check and Style_Check_Mode_In;
1045
   end Mode_In_Check;
1046
 
1047
   -----------------
1048
   -- No_End_Name --
1049
   -----------------
1050
 
1051
   --  In check end/exit labels mode (-gnatye), always require the name of
1052
   --  a subprogram or package to be present on the END, so this is an error.
1053
 
1054
   procedure No_End_Name (Name : Node_Id) is
1055
   begin
1056
      if Style_Check_End_Labels then
1057
         Error_Msg_Node_1 := Name;
1058
         Error_Msg_SP -- CODEFIX
1059
           ("(style) `END &` required");
1060
      end if;
1061
   end No_End_Name;
1062
 
1063
   ------------------
1064
   -- No_Exit_Name --
1065
   ------------------
1066
 
1067
   --  In check end/exit labels mode (-gnatye), always require the name of
1068
   --  the loop to be present on the EXIT when exiting a named loop.
1069
 
1070
   procedure No_Exit_Name (Name : Node_Id) is
1071
   begin
1072
      if Style_Check_End_Labels then
1073
         Error_Msg_Node_1 := Name;
1074
         Error_Msg_SP -- CODEFIX
1075
           ("(style) `EXIT &` required");
1076
      end if;
1077
   end No_Exit_Name;
1078
 
1079
   ----------------------------
1080
   -- Non_Lower_Case_Keyword --
1081
   ----------------------------
1082
 
1083
   --  In check casing mode (-gnatyk), reserved keywords must be spelled
1084
   --  in all lower case (excluding keywords range, access, delta and digits
1085
   --  used as attribute designators).
1086
 
1087
   procedure Non_Lower_Case_Keyword is
1088
   begin
1089
      if Style_Check_Keyword_Casing then
1090
         Error_Msg_SC -- CODEFIX
1091
           ("(style) reserved words must be all lower case");
1092
      end if;
1093
   end Non_Lower_Case_Keyword;
1094
 
1095
   -----------------------------
1096
   -- Require_Following_Space --
1097
   -----------------------------
1098
 
1099
   procedure Require_Following_Space is
1100
   begin
1101
      if Source (Scan_Ptr) > ' ' then
1102
         Error_Space_Required (Scan_Ptr);
1103
      end if;
1104
   end Require_Following_Space;
1105
 
1106
   -----------------------------
1107
   -- Require_Preceding_Space --
1108
   -----------------------------
1109
 
1110
   procedure Require_Preceding_Space is
1111
   begin
1112
      if Token_Ptr > Source_First (Current_Source_File)
1113
        and then Source (Token_Ptr - 1) > ' '
1114
      then
1115
         Error_Space_Required (Token_Ptr);
1116
      end if;
1117
   end Require_Preceding_Space;
1118
 
1119
end Styleg;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.