|
11 | 11 | \pnum
|
12 | 12 | A \defn{preprocessing directive} consists of a sequence of preprocessing tokens
|
13 | 13 | that satisfies the following constraints:
|
14 |
| -The first token in the sequence is a |
15 |
| -\tcode{\#} |
16 |
| -preprocessing token that (at the start of translation phase 4) |
17 |
| -either is the first character in the source file |
| 14 | +The first token in the sequence, |
| 15 | +referred to as a \defnadj{directive-introducing}{token}, |
| 16 | +is a \tcode{\#} preprocessing token, |
| 17 | +an \tcode{import} preprocessing token, or |
| 18 | +an \tcode{export} preprocessing token |
| 19 | +immediately followed by an \tcode{import} preprocessing token, |
| 20 | +that (at the start of translation phase 4) |
| 21 | +either begins with the first character in the source file |
18 | 22 | (optionally after white space containing no new-line characters)
|
19 | 23 | or follows white space containing at least one new-line character.
|
20 | 24 | The last token in the sequence is the first new-line character
|
|
50 | 54 | \begin{bnf}\obeyspaces
|
51 | 55 | \nontermdef{control-line}\br
|
52 | 56 | \terminal{\# include} pp-tokens new-line\br
|
| 57 | + \opt{\terminal{export}} \terminal{import} pp-tokens new-line\br |
53 | 58 | \terminal{\# define } identifier replacement-list new-line\br
|
54 | 59 | \terminal{\# define } identifier lparen \opt{identifier-list} \terminal{)} replacement-list new-line\br
|
55 | 60 | \terminal{\# define } identifier lparen \terminal{... )} replacement-list new-line\br
|
|
149 | 154 | The only white-space characters that shall appear
|
150 | 155 | between preprocessing tokens
|
151 | 156 | within a preprocessing directive
|
152 |
| -(from just after the introducing |
153 |
| -\tcode{\#} |
154 |
| -preprocessing token through just before the terminating new-line character) |
| 157 | +(from just after the directive-introducing token |
| 158 | +through just before the terminating new-line character) |
155 | 159 | are space and horizontal-tab
|
156 | 160 | (including spaces that have replaced comments
|
157 | 161 | or possibly other white-space characters
|
|
243 | 247 | if the identifier is currently defined
|
244 | 248 | as a macro name
|
245 | 249 | (that is, if it is predefined
|
246 |
| -or if it has one or more active macro definitions\iref{cpp.module}, |
| 250 | +or if it has one or more active macro definitions\iref{cpp.import}, |
247 | 251 | for example because
|
248 | 252 | it has been the subject of a
|
249 | 253 | \tcode{\#define}
|
|
623 | 627 | denotes an importable header\iref{module.import},
|
624 | 628 | it is
|
625 | 629 | \impldef{whether source file inclusion of importable header
|
626 |
| -is replaced with \tcode{import}} |
627 |
| -whether the preprocessing directive |
628 |
| -is instead replaced by the \grammarterm{preprocessing-token}{s} |
| 630 | +is replaced with \tcode{import} directive} |
| 631 | +whether the \tcode{\#include} preprocessing directive |
| 632 | +is instead replaced by an \tcode{import} directive\iref{cpp.import} of the form |
629 | 633 | \begin{ncbnf}
|
630 |
| -\terminal{import} header-name \terminal{;} |
| 634 | +\terminal{import} header-name \terminal{;} new-line |
631 | 635 | \end{ncbnf}
|
632 | 636 |
|
633 | 637 | \pnum
|
|
665 | 669 | \end{codeblock}
|
666 | 670 | \end{example}
|
667 | 671 |
|
668 |
| -\rSec1[cpp.glob.frag]{Global module fragment} |
669 |
| - |
670 |
| -\begin{bnf} |
671 |
| -\nontermdef{pp-global-module-fragment}\br |
672 |
| - \terminal{module} \terminal{;} pp-balanced-token-seq \terminal{module} |
673 |
| -\end{bnf} |
674 |
| - |
675 |
| -\pnum |
676 |
| -If the first two preprocessing tokens at the start of phase 4 of translation |
677 |
| -are \tcode{module} \tcode{;}, |
678 |
| -the result of preprocessing shall begin with |
679 |
| -a \grammarterm{pp-global-module-fragment} |
680 |
| -for which all \grammarterm{preprocessing-token}{s} |
681 |
| -in the \grammarterm{pp-balanced-token-seq} |
682 |
| -were produced directly or indirectly by source file inclusion\iref{cpp.include}, |
683 |
| -and for which the second \tcode{module} \grammarterm{preprocessing-token} |
684 |
| -was not produced by source file inclusion or |
685 |
| -macro replacement\iref{cpp.replace}. |
686 |
| -Otherwise, |
687 |
| -the first two preprocessing tokens at the end of phase 4 of translation |
688 |
| -shall not be \tcode{module} \tcode{;}. |
689 |
| - |
690 |
| -\rSec1[cpp.module]{Header units} |
| 672 | +\rSec1[cpp.import]{Header unit importation} |
691 | 673 | \indextext{header unit!preprocessing}%
|
692 | 674 | \indextext{macro import|(}%
|
693 | 675 |
|
694 |
| -\begin{bnf} |
695 |
| -\nontermdef{import-seq}\br |
696 |
| - \opt{top-level-token-seq} \opt{\terminal{export}} \terminal{import} |
697 |
| -\end{bnf} |
698 |
| - |
699 |
| -\begin{bnf} |
700 |
| -\nontermdef{top-level-token-seq}\br |
701 |
| - \descr{any \grammarterm{pp-balanced-token-seq} ending in \terminal{;} or \terminal{\}}} |
702 |
| -\end{bnf} |
703 |
| - |
704 | 676 | \begin{bnf}
|
705 | 677 | \nontermdef{pp-import}\br
|
706 |
| - \terminal{import} header-name \opt{pp-import-suffix} \terminal{;}\br |
707 |
| - \terminal{import} header-name-tokens \opt{pp-import-suffix} \terminal{;} |
708 |
| -\end{bnf} |
709 |
| - |
710 |
| -\begin{bnf} |
711 |
| -\nontermdef{pp-import-suffix}\br |
712 |
| - pp-import-suffix-token\br |
713 |
| - pp-import-suffix pp-import-suffix-token |
714 |
| -\end{bnf} |
715 |
| - |
716 |
| -\begin{bnf} |
717 |
| -\nontermdef{pp-import-suffix-token}\br |
718 |
| - \descr{any \grammarterm{pp-balanced-token} other than \terminal{;}} |
719 |
| -\end{bnf} |
720 |
| - |
721 |
| -\begin{bnf} |
722 |
| -\nontermdef{pp-balanced-token-seq}\br |
723 |
| - pp-balanced-token\br |
724 |
| - pp-balanced-token-seq pp-balanced-token |
725 |
| -\end{bnf} |
726 |
| - |
727 |
| -\begin{bnf} |
728 |
| -\nontermdef{pp-balanced-token}\br |
729 |
| - pp-ldelim \opt{pp-balanced-token-seq} pp-rdelim\br |
730 |
| - \descr{any \grammarterm{preprocessing-token} other than a \grammarterm{pp-ldelim} or \grammarterm{pp-rdelim}} |
731 |
| -\end{bnf} |
732 |
| - |
733 |
| -\begin{bnf} |
734 |
| -\nontermdef{pp-ldelim} \descr{one of}\br |
735 |
| - \terminal{( [ \{ <: <\%} |
736 |
| -\end{bnf} |
737 |
| - |
738 |
| -\begin{bnf} |
739 |
| -\nontermdef{pp-rdelim} \descr{one of}\br |
740 |
| - \terminal{) ] \} :> \%>} |
| 678 | + \opt{\terminal{export}} \terminal{import} header-name \opt{pp-tokens} \terminal{;} new-line\br |
| 679 | + \opt{\terminal{export}} \terminal{import} header-name-tokens \opt{pp-tokens} \terminal{;} new-line\br |
| 680 | + \opt{\terminal{export}} \terminal{import} pp-tokens \terminal{;} new-line |
741 | 681 | \end{bnf}
|
742 | 682 |
|
743 | 683 | \pnum
|
744 |
| -A sequence of \grammarterm{preprocessing-token}{s} |
745 |
| -matching the form of a \grammarterm{pp-import} |
| 684 | +The preprocessing tokens after the \tcode{import} preprocessing token |
| 685 | +in the \tcode{import} \grammarterm{control-line} |
| 686 | +are processed just as in normal text |
| 687 | +(i.e., each identifier currently defined as a macro name |
| 688 | +is replaced by its replacement list of preprocessing tokens). |
| 689 | +An \tcode{import} directive |
| 690 | +matching the first two forms of a \grammarterm{pp-import} |
746 | 691 | instructs the preprocessor to import macros
|
747 | 692 | from the header unit\iref{module.import}
|
748 | 693 | denoted by the \grammarterm{header-name}.
|
749 |
| -A \grammarterm{pp-import} is only recognized |
750 |
| -when the sequence of tokens |
751 |
| -produced by phase 4 of translation |
752 |
| -up to the \tcode{import} token |
753 |
| -forms an \grammarterm{import-seq}, |
754 |
| -and the \tcode{import} token is not within |
755 |
| -the \grammarterm{header-name-tokens} or \grammarterm{pp-import-suffix} |
756 |
| -of another \grammarterm{pp-import}. |
757 |
| -The \tcode{;} \grammarterm{preprocessing-token} |
758 |
| -terminating a \grammarterm{pp-import} |
759 |
| -shall not have been produced by |
760 |
| -macro replacement\iref{cpp.replace}. |
761 |
| -The \defnadj{point of}{macro import} for a \grammarterm{pp-import} is |
762 |
| -immediately after the \tcode{;} terminating the \grammarterm{pp-import}. |
| 694 | +The \defnadj{point of}{macro import} for the |
| 695 | +first two forms of \grammarterm{pp-import} is |
| 696 | +immediately after the \grammarterm{new-line} terminating |
| 697 | +the \grammarterm{pp-import}. |
| 698 | +The last form of \grammarterm{pp-import} is only considered |
| 699 | +if the first two forms did not match. |
763 | 700 |
|
764 | 701 | \pnum
|
765 |
| -In the second form of \grammarterm{pp-import}, |
| 702 | +In all three forms of \grammarterm{pp-import}, |
| 703 | +the \tcode{import} token is replaced by the \grammarterm{import-keyword} token. |
| 704 | +Additionally, in the second form of \grammarterm{pp-import}, |
766 | 705 | a \grammarterm{header-name} token is formed as if
|
767 | 706 | the \grammarterm{header-name-tokens}
|
768 | 707 | were the \grammarterm{pp-tokens} of a \tcode{\#include} directive.
|
|
847 | 786 |
|
848 | 787 | \indextext{macro import|)}%
|
849 | 788 |
|
| 789 | +\rSec1[cpp.glob.frag]{Global module fragment} |
| 790 | + |
| 791 | +\begin{bnf} |
| 792 | +\nontermdef{pp-global-module-fragment}\br |
| 793 | + \terminal{module} \terminal{;} pp-balanced-token-seq \terminal{module} |
| 794 | +\end{bnf} |
| 795 | +\begin{bnf} |
| 796 | + |
| 797 | +\nontermdef{pp-balanced-token-seq}\br |
| 798 | + pp-balanced-token\br |
| 799 | + pp-balanced-token-seq pp-balanced-token |
| 800 | +\end{bnf} |
| 801 | + |
| 802 | +\begin{bnf} |
| 803 | +\nontermdef{pp-balanced-token}\br |
| 804 | + pp-ldelim \opt{pp-balanced-token-seq} pp-rdelim\br |
| 805 | + \descr{any \grammarterm{preprocessing-token} other than a \grammarterm{pp-ldelim} or \grammarterm{pp-rdelim}} |
| 806 | +\end{bnf} |
| 807 | + |
| 808 | +\begin{bnf} |
| 809 | +\nontermdef{pp-ldelim} \descr{one of}\br |
| 810 | + \terminal{( [ \{ <: <\%} |
| 811 | +\end{bnf} |
| 812 | + |
| 813 | +\begin{bnf} |
| 814 | +\nontermdef{pp-rdelim} \descr{one of}\br |
| 815 | + \terminal{) ] \} :> \%>} |
| 816 | +\end{bnf} |
| 817 | + |
| 818 | +\pnum |
| 819 | +If the first two preprocessing tokens at the start of phase 4 of translation |
| 820 | +are \tcode{module} \tcode{;}, |
| 821 | +the result of preprocessing shall begin with |
| 822 | +a \grammarterm{pp-global-module-fragment} |
| 823 | +for which all \grammarterm{preprocessing-token}{s} |
| 824 | +in the \grammarterm{pp-balanced-token-seq} |
| 825 | +were produced directly or indirectly by source file inclusion\iref{cpp.include}, |
| 826 | +and for which the second \tcode{module} \grammarterm{preprocessing-token} |
| 827 | +was not produced by source file inclusion or |
| 828 | +macro replacement\iref{cpp.replace}. |
| 829 | +Otherwise, |
| 830 | +the first two preprocessing tokens at the end of phase 4 of translation |
| 831 | +shall not be \tcode{module} \tcode{;}. |
| 832 | + |
850 | 833 | \rSec1[cpp.replace]{Macro replacement}%
|
851 | 834 | \indextext{macro!replacement|(}%
|
852 | 835 | \indextext{replacement!macro|see{macro, replacement}}%
|
|
0 commit comments