OSDN Git Service

* gcc.dg/tree-ssa/ssa-dse-10.c: Clean up all dse dump files.
[pf3gnuchains/gcc-fork.git] / gcc / ada / gnat-style.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3
4 @c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
5 @c                                                                            o
6 @c                           GNAT DOCUMENTATION                               o
7 @c                                                                            o
8 @c                     G N A T   C O D I N G   S T Y L E                      o
9 @c                                                                            o
10 @c                     Copyright (C) 1992-2007, AdaCore                       o
11 @c                                                                            o
12 @c  GNAT is free software;  you can  redistribute it  and/or modify it under  o
13 @c  terms of the  GNU General Public License as published  by the Free Soft-  o
14 @c  ware  Foundation;  either version 2,  or (at your option) any later ver-  o
15 @c  sion.  GNAT is distributed in the hope that it will be useful, but WITH-  o
16 @c  OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY  o
17 @c  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  o
18 @c  for  more details.  You should have  received  a copy of the GNU General  o
19 @c  Public License  distributed with GNAT;  see file COPYING.  If not, write  o
20 @c  to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor,  o
21 @c  Boston, MA 02110-1301, USA.                                               o
22 @c                                                                            o
23 @c oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
24
25 @setfilename gnat-style.info
26
27 @settitle GNAT Coding Style
28 @setchapternewpage odd
29
30 @include gcc-common.texi
31
32 @dircategory Software development
33 @direntry
34 * gnat-style: (gnat-style).      GNAT Coding Style
35 @end direntry
36
37 @macro syntax{element}
38 @t{\element\}
39 @end macro
40 @c %**end of header
41
42 @titlepage
43 @titlefont{GNAT Coding Style:}
44 @sp 1
45 @title @hfill A Guide for GNAT Developers
46 @subtitle GNAT, The GNU Ada Compiler
47 @versionsubtitle
48 @author Ada Core Technologies, Inc.
49 @page
50 @vskip 0pt plus 1filll
51
52 Copyright @copyright{} 1995-2007, Free Software Foundation
53
54 Permission is granted to copy, distribute and/or modify this document
55 under the terms of the GNU Free Documentation License, Version 1.1
56 or any later version published by the Free Software Foundation;
57 with the Invariant Sections being ``GNU Free Documentation License'', with the
58 Front-Cover Texts being
59 ``GNAT Coding Style'' and ``A Guide for GNAT Developers'',
60 and with no Back-Cover Texts.
61 A copy of the license is included in the section entitled
62 ``GNU Free Documentation License''.
63 @end titlepage
64
65 @raisesections
66
67 @node    Top,       General,         , (dir)
68 @comment node-name, next,    previous, up
69
70 @ifnottex
71 @noindent
72 GNAT Coding Style@*
73 A Guide for GNAT Developers
74 @sp 2
75 @noindent
76 GNAT, The GNU Ada Compiler@*
77
78 @noindent
79 Permission is granted to copy, distribute and/or modify this document
80 under the terms of the GNU Free Documentation License, Version 1.1
81 or any later version published by the Free Software Foundation;
82 with the Invariant Sections being ``GNU Free Documentation License'', with the
83 Front-Cover Texts being
84 ``GNAT Coding Style'' and ``A Guide for GNAT Developers''
85 and with no Back-Cover Texts.
86 A copy of the license is included in the section entitled
87 ``GNU Free Documentation License''.
88 @end ifnottex
89
90
91 @menu
92 * General::
93 * Lexical Elements::
94 * Declarations and Types::
95 * Expressions and Names::
96 * Statements::
97 * Subprograms::
98 * Packages::
99 * Program Structure::
100 * GNU Free Documentation License::
101 * Index::
102 @end menu
103
104 @c  -------------------------------------------------------------------------
105 @node    General, Lexical Elements, Top, Top
106 @section General
107 @c  -------------------------------------------------------------------------
108
109 @noindent
110 Most of GNAT is written in Ada using a consistent style to ensure
111 readability of the code.  This document has been written to help
112 maintain this consistent style, while having a large group of developers
113 work on the compiler.
114
115 For the coding style in the C parts of the compiler and run time,
116 see the GNU Coding Guidelines.
117
118 This document is structured after the @cite{Ada Reference Manual}.
119 Those familiar with that document should be able to quickly
120 lookup style rules for particular constructs.
121
122
123 @c  -------------------------------------------------------------------------
124 @node    Lexical Elements, Declarations and Types, General, Top
125 @section Lexical Elements
126 @c  -------------------------------------------------------------------------
127 @cindex Lexical elements
128
129 @subsection Character Set and Separators
130 @c  -------------------------------------------------------------------------
131 @cindex Character set
132 @cindex ASCII
133 @cindex Separators
134 @cindex End-of-line
135 @cindex Line length
136 @cindex Indentation
137
138 @itemize @bullet
139 @item
140 The character set used should be plain 7-bit ASCII@.
141 The only separators allowed are space and the end-of-line sequence.
142 No other control character or format effector (such as @code{HT},
143 @code{VT}, @code{FF})
144 should be used.
145 The normal end-of-line sequence is used, which may be
146 @code{LF}, @code{CR/LF} or @code{CR},
147 depending on the host system.  An optional @code{SUB}
148 (@code{16#1A#}) may be present as the
149 last character in the file on hosts using that character as file terminator.
150
151 @item
152 Files that are checked in or distributed should be in host format.
153
154 @item
155 A line should never be longer than 79 characters, not counting the line
156 separator.
157
158 @item
159 Lines must not have trailing blanks.
160
161 @item
162 Indentation is 3 characters per level for @code{if} statements, loops, and
163 @code{case} statements.
164 For exact information on required spacing between lexical
165 elements, see file @file{style.adb}.
166 @cindex @file{style.adb} file
167 @end itemize
168
169
170 @subsection Identifiers
171 @c  -------------------------------------------------------------------------
172 @itemize @bullet
173 @cindex Identifiers
174
175 @item
176 Identifiers will start with an upper case letter, and each letter following
177 an underscore will be upper case.
178 @cindex Casing (for identifiers)
179 Short acronyms may be all upper case.
180 All other letters are lower case.
181 An exception is for identifiers matching a foreign language.  In particular,
182 we use all lower case where appropriate for C@.
183
184 @item
185 Use underscores to separate words in an identifier.
186 @cindex Underscores
187
188 @item Try to limit your use of abbreviations in identifiers.
189 It is ok to make a few abbreviations, explain what they mean, and then
190 use them frequently, but don't use lots of obscure abbreviations.  An
191 example is the @code{ALI} word which stands for Ada Library
192 Information and is by convention always written in upper-case when
193 used in entity names.
194
195 @smallexample @c adanocomment
196        procedure Find_ALI_Files;
197 @end smallexample
198
199 @item
200 Don't use the variable name @code{I}, use @code{J} instead; @code{I} is too
201 easily confused with @code{1} in some fonts.  Similarly don't use the
202 variable @code{O}, which is too easily mistaken for the number @code{0}.
203 @end itemize
204
205 @subsection Numeric Literals
206 @c  -------------------------------------------------------------------------
207 @cindex Numeric literals
208
209 @itemize @bullet
210 @item
211 Numeric literals should include underscores where helpful for
212 readability.
213 @cindex Underscores
214
215 @smallexample
216       1_000_000
217       16#8000_000#
218       3.14159_26535_89793_23846
219 @end smallexample
220 @end itemize
221
222 @subsection Reserved Words
223 @c  -------------------------------------------------------------------------
224 @cindex Reserved words
225
226 @itemize @bullet
227 @item
228 Reserved words use all lower case.
229 @cindex Casing (for reserved words)
230
231 @smallexample @c adanocomment
232        return else
233 @end smallexample
234
235 @item
236 The words @code{Access}, @code{Delta} and @code{Digits} are
237 capitalized when used as @syntax{attribute_designator}.
238 @end itemize
239
240 @subsection Comments
241 @c  -------------------------------------------------------------------------
242 @cindex Comments
243
244 @itemize @bullet
245 @item
246 A comment starts with @code{--} followed by two spaces.
247 The only exception to this rule (i.e.@: one space is tolerated) is when the
248 comment ends with a single space followed by @code{--}.
249 It is also acceptable to have only one space between @code{--} and the start
250 of the comment when the comment is at the end of a line,
251 after some Ada code.
252
253 @item
254 Every sentence in a comment should start with an upper-case letter (including
255 the first letter of the comment).
256 @cindex Casing (in comments)
257
258 @item
259 When declarations are commented with ``hanging'' comments, i.e.@:
260 comments after the declaration, there is no blank line before the
261 comment, and if it is absolutely necessary to have blank lines within
262 the comments, e.g. to make paragraph separations within a single comment,
263 these blank lines @emph{do} have a @code{--} (unlike the
264 normal rule, which is to use entirely blank lines for separating
265 comment paragraphs).  The comment starts at same level of indentation
266 as code it is commenting.
267 @cindex Blank lines (in comments)
268 @cindex Indentation
269
270 @smallexample @c adanocomment
271        z : Integer;
272        --  Integer value for storing value of z
273        --
274        --  The previous line was a blank line.
275 @end smallexample
276
277 @item
278 Comments that are dubious or incomplete, or that comment on possibly
279 wrong or incomplete code, should be preceded or followed by @code{???}@.
280
281 @item
282 Comments in a subprogram body must generally be surrounded by blank lines.
283 An exception is a comment that follows a line containing a single keyword
284 (@code{begin}, @code{else}, @code{loop}):
285
286 @smallexample @c adanocomment
287 @group
288        begin
289           --  Comment for the next statement
290
291           A := 5;
292
293           --  Comment for the B statement
294
295           B := 6;
296        end;
297 @end group
298 @end smallexample
299
300 @item
301 In sequences of statements, comments at the end of the lines should be
302 aligned.
303 @cindex Alignment (in comments)
304
305 @smallexample @c adanocomment
306         My_Identifier := 5;      --  First comment
307         Other_Id := 6;           --  Second comment
308 @end smallexample
309
310 @item
311 Short comments that fit on a single line are @emph{not} ended with a
312 period.  Comments taking more than a line are punctuated in the normal
313 manner.
314
315 @item
316 Comments should focus on @emph{why} instead of @emph{what}.
317 Descriptions of what subprograms do go with the specification.
318
319 @item
320 Comments describing a subprogram spec should specifically mention the
321 formal argument names.  General rule: write a comment that does not
322 depend on the names of things.  The names are supplementary, not
323 sufficient, as comments.
324
325 @item
326 @emph{Do not} put two spaces after periods in comments.
327 @end itemize
328
329 @c  -------------------------------------------------------------------------
330 @node    Declarations and Types, Expressions and Names, Lexical Elements,Top
331 @section Declarations and Types
332 @c  -------------------------------------------------------------------------
333 @cindex Declarations and Types
334
335 @itemize @bullet
336 @item
337 In entity declarations, colons must be surrounded by spaces.  Colons
338 should be aligned.
339 @cindex Alignment (in declarations)
340
341 @smallexample @c adanocomment
342         Entity1   : Integer;
343         My_Entity : Integer;
344 @end smallexample
345
346 @item
347 Declarations should be grouped in a logical order.
348 Related groups of declarations may be preceded by a header comment.
349
350 @item
351 All local subprograms in a subprogram or package body should be declared
352 before the first local subprogram body.
353
354 @item
355 Do not declare local entities that hide global entities.
356 @cindex Hiding of outer entities
357
358 @item
359 Do not declare multiple variables in one declaration that spans lines.
360 Start a new declaration on each line, instead.
361
362 @item
363 The @syntax{defining_identifier}s of global declarations serve as
364 comments of a sort.  So don't choose terse names, but look for names
365 that give useful information instead.
366
367 @item
368 Local names can be shorter, because they are used only within
369 one context, where comments explain their purpose.
370
371 @end itemize
372
373
374 @c  -------------------------------------------------------------------------
375 @node    Expressions and Names, Statements, Declarations and Types, Top
376 @section Expressions and Names
377 @c  -------------------------------------------------------------------------
378 @cindex Expressions and names
379
380 @itemize @bullet
381
382 @item
383 Every operator must be surrounded by spaces. An exception is that
384 this rule does not apply to the exponentiation operator, for which
385 there are no specific layout rules. The reason for this exception
386 is that sometimes it makes clearer reading to leave out the spaces
387 around exponentiation.
388 @cindex Operators
389
390 @smallexample @c adanocomment
391        E := A * B**2 + 3 * (C - D);
392 @end smallexample
393
394 @item
395 Use parentheses where they clarify the intended association of operands
396 with operators:
397 @cindex Parenthesization of expressions
398 @smallexample @c adanocomment
399        (A / B) * C
400 @end smallexample
401 @end itemize
402
403 @c  -------------------------------------------------------------------------
404 @node    Statements, Subprograms, Expressions and Names, Top
405 @section Statements
406 @c  -------------------------------------------------------------------------
407 @cindex Statements
408
409 @subsection Simple and Compound Statements
410 @c  -------------------------------------------------------------------------
411 @cindex Simple and compound statements
412
413 @itemize @bullet
414 @item
415 Use only one statement or label per line.
416 @item
417 A longer @syntax{sequence_of_statements} may be divided in logical
418 groups or separated from surrounding code using a blank line.
419 @end itemize
420
421 @subsection If Statements
422 @c  -------------------------------------------------------------------------
423 @cindex @code{if} statement
424
425 @itemize @bullet
426 @item
427 When the @code{if}, @code{elsif} or @code{else} keywords fit on the
428 same line with the condition and the @code{then} keyword, then the
429 statement is formatted as follows:
430 @cindex Alignment (in an @code{if} statement)
431
432 @smallexample @c adanocomment
433 @group
434         if @var{condition} then
435            ...
436         elsif @var{condition} then
437            ...
438         else
439            ...
440         end if;
441 @end group
442 @end smallexample
443
444 @noindent
445 When the above layout is not possible, @code{then} should be aligned
446 with @code{if}, and conditions should preferably be split before an
447 @code{and} or @code{or} keyword a follows:
448
449 @smallexample @c adanocomment
450 @group
451         if @var{long_condition_that_has_to_be_split}
452           and then @var{continued_on_the_next_line}
453         then
454            ...
455         end if;
456 @end group
457 @end smallexample
458
459 @noindent
460 The @code{elsif}, @code{else} and @code{end if} always line up with
461 the @code{if} keyword.  The preferred location for splitting the line
462 is before @code{and} or @code{or}.  The continuation of a condition is
463 indented with two spaces or as many as needed to make nesting clear.
464 As an exception, if conditions are closely related either of the
465 following is allowed:
466
467 @smallexample
468 @group
469      if x = lakdsjfhlkashfdlkflkdsalkhfsalkdhflkjdsahf
470           or else
471         x = asldkjhalkdsjfhhfd
472           or else
473         x = asdfadsfadsf
474      then
475        ...
476      end if;
477 @end group
478
479 @group
480      if x = lakdsjfhlkashfdlkflkdsalkhfsalkdhflkjdsahf or else
481         x = asldkjhalkdsjfhhfd                         or else
482         x = asdfadsfadsf
483      then
484        ...
485      end if;
486 @end group
487 @end smallexample
488
489 @item
490 Conditions should use short-circuit forms (@code{and then},
491 @code{or else}), except when the operands are boolean variables
492 or boolean constants.
493 @cindex Short-circuit forms
494
495 @item
496 Complex conditions in @code{if} statements are indented two characters:
497 @cindex Indentation (in @code{if} statements)
498
499 @smallexample @c adanocomment
500 @group
501       if @var{this_complex_condition}
502         and then @var{that_other_one}
503         and then @var{one_last_one}
504       then
505          ...
506       end if;
507 @end group
508 @end smallexample
509
510 @noindent
511 There are some cases where complex conditionals can be laid out
512 in manners that do not follow these rules to preserve better
513 parallelism between branches, e.g.
514
515 @smallexample @c adanocomment
516 @group
517       if xyz.abc (gef) = 'c'
518            or else
519          xyz.abc (gef) = 'x'
520       then
521          ...
522       end if;
523 @end group
524 @end smallexample
525
526
527 @item
528 Every @code{if} block is preceded and followed by a blank line, except
529 where it begins or ends a @syntax{sequence_of_statements}.
530 @cindex Blank lines (in an @code{if} statement)
531
532 @smallexample @c adanocomment
533 @group
534         A := 5;
535
536         if A = 5 then
537            null;
538         end if;
539
540         A := 6;
541 @end group
542 @end smallexample
543 @end itemize
544
545 @subsection Case Statements
546 @cindex @code{case} statements
547
548 @itemize @bullet
549 @item
550 Layout is as below.  For long @code{case} statements, the extra indentation
551 can be saved by aligning the @code{when} clauses with the opening @code{case}.
552
553 @smallexample @c adanocomment
554 @group
555        case @var{expression} is
556           when @var{condition} =>
557              ...
558           when @var{condition} =>
559              ...
560        end case;
561 @end group
562 @end smallexample
563 @end itemize
564
565 @subsection Loop Statements
566 @cindex Loop statements
567
568 @itemize @bullet
569 @noindent
570 When possible, have @code{for} or @code{while} on one line with the
571 condition and the @code{loop} keyword.
572
573 @smallexample @c adanocomment
574 @group
575        for J in S'Range loop
576           ...
577        end loop;
578 @end group
579 @end smallexample
580
581 @noindent
582 If the condition is too long, split the condition (see ``If
583 statements'' above) and align @code{loop} with the @code{for} or
584 @code{while} keyword.
585 @cindex Alignment (in a loop statement)
586
587 @smallexample @c adanocomment
588 @group
589       while @var{long_condition_that_has_to_be_split}
590         and then @var{continued_on_the_next_line}
591       loop
592          ...
593       end loop;
594 @end group
595 @end smallexample
596
597 @noindent
598 If the @syntax{loop_statement} has an identifier, it is laid out as follows:
599
600 @smallexample @c adanocomment
601 @group
602       Outer : while not @var{condition} loop
603          ...
604       end Outer;
605 @end group
606 @end smallexample
607 @end itemize
608
609 @subsection Block Statements
610 @cindex Block statement
611
612 @itemize @bullet
613 @item
614 The @code{declare} (optional), @code{begin} and @code{end} words
615 are aligned, except when the @syntax{block_statement} is named.  There
616 is a blank line before the @code{begin} keyword:
617 @cindex Alignment (in a block statement)
618
619 @smallexample @c adanocomment
620 @group
621       Some_Block : declare
622          ...
623
624       begin
625          ...
626       end Some_Block;
627 @end group
628 @end smallexample
629
630 @end itemize
631
632 @c  -------------------------------------------------------------------------
633 @node    Subprograms, Packages, Statements, Top
634 @section Subprograms
635 @c  -------------------------------------------------------------------------
636 @cindex Subprograms
637
638 @subsection Subprogram Declarations
639 @c  -------------------------------------------------------------------------
640 @itemize @bullet
641
642 @item
643 Do not write the @code{in} for parameters.
644
645 @smallexample @c adanocomment
646       function Length (S : String) return Integer;
647 @end smallexample
648
649 @item
650 When the declaration line for a procedure or a function is too long to fit
651 the entire declaration (including the keyword procedure or function) on a
652 single line, then fold it, putting a single parameter on a line, aligning
653 the colons, as in:
654
655 @smallexample @c adanocomment
656 @group
657      procedure Set_Heading
658         (Source : String;
659          Count  : Natural;
660          Pad    : Character := Space;
661          Fill   : Boolean   := True);
662 @end group
663 @end smallexample
664
665 @noindent
666 In the case of a function, if the entire spec does not fit on one line, then
667 the return may appear after the last parameter, as in:
668
669 @smallexample @c adanocomment
670 @group
671       function Head
672         (Source : String;
673          Count  : Natural;
674          Pad    : Character := Space) return String;
675 @end group
676 @end smallexample
677
678 @noindent
679 Or it may appear on its own as a separate line. This form is preferred when
680 putting the return on the same line as the last parameter would result in
681 an overlong line. The return type may optionally be aligned with the types
682 of the parameters (usually we do this aligning if it results only in a small
683 number of extra spaces, and otherwise we don't attempt to align). So two
684 alternative forms for the above spec are:
685
686 @smallexample @c adanocomment
687 @group
688       function Head
689         (Source : String;
690          Count  : Natural;
691          Pad    : Character := Space)
692          return   String;
693
694       function Head
695         (Source : String;
696          Count  : Natural;
697          Pad    : Character := Space)
698          return String;
699 @end group
700 @end smallexample
701
702 @end itemize
703
704 @subsection Subprogram Bodies
705 @c  -------------------------------------------------------------------------
706 @cindex Subprogram bodies
707
708 @itemize @bullet
709 @item
710 Function and procedure bodies should usually be sorted alphabetically. Do
711 not attempt to sort them in some logical order by functionality. For a
712 sequence of subprogram specs, a general alphabetical sorting is also
713 usually appropriate, but occasionally it makes sense to group by major
714 function, with appropriate headers.
715
716 @item
717 All subprograms have a header giving the function name, with the following
718 format:
719
720 @smallexample @c adanocomment
721 @group
722       -----------------
723       -- My_Function --
724       -----------------
725
726       procedure My_Function is
727       begin
728         ...
729       end My_Function;
730 @end group
731 @end smallexample
732
733 @noindent
734 Note that the name in the header is preceded by a single space,
735 not two spaces as for other comments. These headers are used on
736 nested subprograms as well as outer level subprograms. They may
737 also be used as headers for sections of comments, or collections
738 of declarations that are related.
739
740 @item
741 Every subprogram body must have a preceding @syntax{subprogram_declaration}.
742
743 @item
744 @cindex Blank lines (in subprogram bodies)
745 A sequence of declarations may optionally be separated from the following
746 begin by a blank line.  Just as we optionally allow blank lines in general
747 between declarations, this blank line should be present only if it improves
748 readability. Generally we avoid this blank line if the declarative part is
749 small (one or two lines) and the body has no blank lines, and we include it
750 if the declarative part is long or if the body has blank lines.
751
752 @item
753 If the declarations in a subprogram contain at least one nested
754 subprogram body, then just before the @code{begin} of the enclosing
755 subprogram, there is a comment line and a blank line:
756
757 @smallexample @c adanocomment
758 @group
759     --  Start of processing for @var{Enclosing_Subprogram}
760
761     begin
762       ...
763     end @var{Enclosing_Subprogram};
764 @end group
765 @end smallexample
766
767 @item
768 When nested subprograms are present, variables that are referenced by any
769 nested subprogram should precede the nested subprogram specs. For variables
770 that are not referenced by nested procedures, the declarations can either also
771 be before any of the nested subprogram specs (this is the old style, more
772 generally used). Or then can come just before the begin, with a header. The
773 following example shows the two possible styles:
774
775 @smallexample @c adanocomment
776 @group
777     procedure Style1 is
778        Var_Referenced_In_Nested      : Integer;
779        Var_Referenced_Only_In_Style1 : Integer;
780
781        proc Nested;
782        --  Comments ...
783
784
785        ------------
786        -- Nested --
787        ------------
788
789        procedure Nested is
790        begin
791           ...
792        end Nested;
793
794     --  Start of processing for Style1
795
796     begin
797        ...
798     end Style1;
799
800 @end group
801
802 @group
803     procedure Style2 is
804        Var_Referenced_In_Nested : Integer;
805
806        proc Nested;
807        --  Comments ...
808
809        ------------
810        -- Nested --
811        ------------
812
813        procedure Nested is
814        begin
815           ...
816        end Nested;
817
818        --  Local variables
819
820        Var_Referenced_Only_In_Style2 : Integer;
821
822     --  Start of processing for Style2
823
824     begin
825        ...
826     end Style2;
827
828 @end group
829 @end smallexample
830
831 @noindent
832 For new code, we generally prefer Style2, but we do not insist on
833 modifying all legacy occurrences of Style1, which is still much
834 more common in the sources.
835
836 @end itemize
837
838
839 @c  -------------------------------------------------------------------------
840 @node    Packages, Program Structure, Subprograms, Top
841 @section Packages and Visibility Rules
842 @c  -------------------------------------------------------------------------
843 @cindex Packages
844
845 @itemize @bullet
846 @item
847 All program units and subprograms have their name at the end:
848
849 @smallexample @c adanocomment
850 @group
851       package P is
852          ...
853       end P;
854 @end group
855 @end smallexample
856
857 @item
858 We will use the style of @code{use}-ing @code{with}-ed packages, with
859 the context clauses looking like:
860 @cindex @code{use} clauses
861
862 @smallexample @c adanocomment
863 @group
864       with A; use A;
865       with B; use B;
866 @end group
867 @end smallexample
868
869 @item
870 Names declared in the visible part of packages should be
871 unique, to prevent name clashes when the packages are @code{use}d.
872 @cindex Name clash avoidance
873
874 @smallexample @c adanocomment
875 @group
876       package Entity is
877          type Entity_Kind is ...;
878          ...
879       end Entity;
880 @end group
881 @end smallexample
882
883 @item
884 After the file header comment, the context clause and unit specification
885 should be the first thing in a @syntax{program_unit}.
886
887 @item
888 Preelaborate, Pure and Elaborate_Body pragmas should be added right after the
889 package name, indented an extra level and using the parameterless form:
890
891 @smallexample @c adanocomment
892 @group
893       package Preelaborate_Package is
894          pragma Preelaborate;
895          ...
896       end Preelaborate_Package;
897 @end group
898 @end smallexample
899
900 @end itemize
901
902 @c  -------------------------------------------------------------------------
903 @node    Program Structure, GNU Free Documentation License, Packages, Top
904 @section Program Structure and Compilation Issues
905 @c  -------------------------------------------------------------------------
906 @cindex Program structure
907
908 @itemize @bullet
909 @item
910 Every GNAT source file must be compiled with the @option{-gnatg}
911 switch to check the coding style.
912 (Note that you should look at
913 @file{style.adb} to see the lexical rules enforced by
914 @option{-gnatg}).
915 @cindex @option{-gnatg} option (to gcc)
916 @cindex @file{style.adb} file
917
918 @item
919 Each source file should contain only one compilation unit.
920
921 @item
922 Filenames should be 8 or fewer characters, followed by the @code{.adb}
923 extension for a body or @code{.ads} for a spec.
924 @cindex File name length
925
926 @item
927 Unit names should be distinct when ``krunch''ed to 8 characters
928 (see @file{krunch.ads}) and the filenames should match the unit name,
929 except that they are all lower case.
930 @cindex @file{krunch.ads} file
931 @end itemize
932
933
934 @c **********************************
935 @c * GNU Free Documentation License *
936 @c **********************************
937 @include fdl.texi
938 @c GNU Free Documentation License
939 @cindex GNU Free Documentation License
940
941 @node Index,,GNU Free Documentation License, Top
942 @unnumberedsec Index
943
944 @printindex cp
945
946 @contents
947
948 @bye