From 4130b8a588ae65ac3b29996fb1c43c0541d6f7e1 Mon Sep 17 00:00:00 2001 From: Gary Klimowicz Date: Sun, 4 May 2025 19:51:52 -0700 Subject: [PATCH 1/5] Rough draft of conditional directives --- drafts/25-xxx-specifications.txt | 118 ++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/drafts/25-xxx-specifications.txt b/drafts/25-xxx-specifications.txt index 845ce75..4d61079 100644 --- a/drafts/25-xxx-specifications.txt +++ b/drafts/25-xxx-specifications.txt @@ -413,22 +413,134 @@ in28. Unlike INCLUDE lines (see the section on "INCLUDE lines"), the #include directive is not prohibited from including the same source file at a deeper level of nesting. + 3.5 The '#if', '#ifdef', '#ifndef', '#elif', '#elifdef', - '#elifndef', '#else', '#endif' directives + '#elifndef', '#else', '#endif' conditional directives --------------------------------------------------------- -Example syntax: +Example syntax (extra spacing for illustration purposes only): + General form: + #endif EOL + #endif EOL + #endif EOL + + Where: + is one of: + #if token-list EOL + #ifdef ID EOL + #ifndef ID EOL + + is zero or more of: + #elif token-list EOL + #elifdef ID EOL + #elifndef ID EOL + is zero or one of: + #else EOL + + are zero or more of: + directive lines + Fortran comment lines + Fortran source lines 3.5.1 Static semantics specifications --------------------------------------- +------------------------------------- + +if05. A #if, ##ifdef, or #ifndef directive signals the start + of a list of conditional directives. + +if10: Whitespace must immediately follow the directives tokens + 'ifdef', 'ifndef', 'elifdef', and 'elifndef' to separate + them from the ID tokens. + +if15. The list of #elif, #elifdef, and #elifndef directives, and + the #else directive (if present) are part of the same list + of directives introduced by the #if directive. + +if20. The chain of conditional directives ends with the #endif + directive. + +if25. Within a conditional directive list, a #if, #ifdef, or + #endif directive introduces a new list of conditional + directives, at a new nesting level, within the enclosing + conditional directive list. + +if30. The conditional directive lists must properly nest. + +if35. As shown in the illustrative syntax, there should be + no unmatched #endif directives. + +if40. As shown in the illustrative syntax, there should be + no more than one #else directive in a list of conditional + directives at any nesting level. 3.5.2 Evaluation semantics specifications ----------------------------------------- +ix05. The #ifdef and #ifndef macros are evaluated as if + they had been written "#if defined(ID)" and + "#if !defined(ID)" respectively. + +ix10. The #elifdef and #elifndef macros are evaluated as if + they had been written "#elif defined(ID)" and "#elif !defined(ID)" + respectively. + +ix15. The token-lists in #if and #elif are processed as described + in the section "Macro recognition and expansion". + +ix20. After expansion, the resulting token list in #if and #elif + directives must represent a valid integer expression as + described in the section "Expressions allowed in #if and + #elif directives". + +ix25. The resulting token list is parsed and evaluated according + to the semantic rules described in section "Expressions allowed + in #if and #elif directives". + +ix30. If the expression in a #if evaluates to a C true value, the + immediately following the #if participate in preprocessing. + They are subject to preprocessing expansion, substitution, and + evaluation of processing directives in the . + +ix40. Further preprocessing when #if evaluates to C true proceeds. + Subsequent #elif and #else directives at the same level of + nesting are skipped, and do not participate in preprocessing + except to be examined for proper nesting of conditional directives. + +ix45. If the expression in a #if evaluates to a C false value (zero), + the lines immediately following the #if directive are skipped, and + examined only to determine nesting of conditionals. No token + expansion occurs. No Fortran comment lines or source lines are + made available to the processor. Processing continues with + processing any #elif directives at the same level of nesting, as + described below. + +ix50. When the #if expression evaluates to C false, the #elif directives + at the same nesting level are evaluated in the order they appear + in the source. Those whose expression evaluate to false are + skipped in the same manner as when a #if clause evaluates to false. + +ix55. When a #elif expression evaluates to C true, the + immediately following the #elif participate in preprocessing + just as they do when the expression in a #if evaluates to C true. + Subsequent #elif and #else directives at the same nesting + level are skipped, as described for #if. + +ix60. When no #if expression or #elif expression evaluates to C true + and a #else directive is present at the same nesting level, + the between the #else directive and the matching #endif + directive are subject to preprocessing, expansion and substitution + as they would be in #if true processing. + +ix65. When no #if expression or #elif expression evaluates to C true + and no #else directive is present at the same nesting level, + there are no in the list of conditional directives + subject to preprocessing. + + 3.6 The '#error' and '#warning' directives ------------------------------------------ From 286520f85720fadc7bd8f50184e3c93858e8fdad Mon Sep 17 00:00:00 2001 From: Gary Klimowicz Date: Sun, 4 May 2025 20:18:50 -0700 Subject: [PATCH 2/5] squash! Rough draft of conditional directives --- drafts/25-xxx-specifications.txt | 145 ++++++++++++++++--------------- 1 file changed, 76 insertions(+), 69 deletions(-) diff --git a/drafts/25-xxx-specifications.txt b/drafts/25-xxx-specifications.txt index 4d61079..c622ed9 100644 --- a/drafts/25-xxx-specifications.txt +++ b/drafts/25-xxx-specifications.txt @@ -447,98 +447,105 @@ Example syntax (extra spacing for illustration purposes only): 3.5.1 Static semantics specifications ------------------------------------- -if05. A #if, ##ifdef, or #ifndef directive signals the start - of a list of conditional directives. +if05. A #if, ##ifdef, or #ifndef directive signals the start of a list + of conditional directives. if10: Whitespace must immediately follow the directives tokens - 'ifdef', 'ifndef', 'elifdef', and 'elifndef' to separate - them from the ID tokens. + 'ifdef', 'ifndef', 'elifdef', and 'elifndef' to separate them + from the ID tokens. -if15. The list of #elif, #elifdef, and #elifndef directives, and - the #else directive (if present) are part of the same list - of directives introduced by the #if directive. +if15. The list of #elif, #elifdef, and #elifndef directives, and the + #else directive (if present) are part of the same list of + directives introduced by the #if directive. if20. The chain of conditional directives ends with the #endif directive. -if25. Within a conditional directive list, a #if, #ifdef, or - #endif directive introduces a new list of conditional - directives, at a new nesting level, within the enclosing - conditional directive list. +if25. Within a conditional directive list, a #if, #ifdef, or #endif + directive introduces a new list of conditional directives, at a new + nesting level, within the enclosing conditional directive list. if30. The conditional directive lists must properly nest. -if35. As shown in the illustrative syntax, there should be - no unmatched #endif directives. +if35. As shown in the illustrative syntax, there should be no + unmatched #endif directives. -if40. As shown in the illustrative syntax, there should be - no more than one #else directive in a list of conditional - directives at any nesting level. +if40. As shown in the illustrative syntax, there should be no more + than one #else directive in a list of conditional directives at + any nesting level. 3.5.2 Evaluation semantics specifications ----------------------------------------- -ix05. The #ifdef and #ifndef macros are evaluated as if - they had been written "#if defined(ID)" and - "#if !defined(ID)" respectively. +ix05. The #ifdef and #ifndef macros are evaluated as if they had been + written "#if defined(ID)" and "#if !defined(ID)" respectively. + (For brevity, the descriptions of #ifdef and #ifndef directives + below are omitted, and assume this transformation.) -ix10. The #elifdef and #elifndef macros are evaluated as if - they had been written "#elif defined(ID)" and "#elif !defined(ID)" +ix10. The #elifdef and #elifndef macros are evaluated as if they had + been written "#elif defined(ID)" and "#elif !defined(ID)" respectively. -ix15. The token-lists in #if and #elif are processed as described - in the section "Macro recognition and expansion". +ix15. The token-lists in #if and #elif are processed as described in + the section "Macro recognition and expansion". ix20. After expansion, the resulting token list in #if and #elif directives must represent a valid integer expression as - described in the section "Expressions allowed in #if and - #elif directives". - -ix25. The resulting token list is parsed and evaluated according - to the semantic rules described in section "Expressions allowed - in #if and #elif directives". - -ix30. If the expression in a #if evaluates to a C true value, the - immediately following the #if participate in preprocessing. - They are subject to preprocessing expansion, substitution, and - evaluation of processing directives in the . - -ix40. Further preprocessing when #if evaluates to C true proceeds. - Subsequent #elif and #else directives at the same level of - nesting are skipped, and do not participate in preprocessing - except to be examined for proper nesting of conditional directives. - -ix45. If the expression in a #if evaluates to a C false value (zero), - the lines immediately following the #if directive are skipped, and - examined only to determine nesting of conditionals. No token - expansion occurs. No Fortran comment lines or source lines are - made available to the processor. Processing continues with - processing any #elif directives at the same level of nesting, as - described below. - -ix50. When the #if expression evaluates to C false, the #elif directives - at the same nesting level are evaluated in the order they appear - in the source. Those whose expression evaluate to false are - skipped in the same manner as when a #if clause evaluates to false. - -ix55. When a #elif expression evaluates to C true, the - immediately following the #elif participate in preprocessing - just as they do when the expression in a #if evaluates to C true. - Subsequent #elif and #else directives at the same nesting - level are skipped, as described for #if. - -ix60. When no #if expression or #elif expression evaluates to C true - and a #else directive is present at the same nesting level, - the between the #else directive and the matching #endif - directive are subject to preprocessing, expansion and substitution - as they would be in #if true processing. - -ix65. When no #if expression or #elif expression evaluates to C true - and no #else directive is present at the same nesting level, - there are no in the list of conditional directives - subject to preprocessing. + described in the section "Expressions allowed in #if and #elif + directives". This expression is called the "controlling + expression" for the directive. + +ix25. Controlling expressions in #if and #elif directives are parsed + and evaluated according to the semantic rules described in + section "Expressions allowed in #if and #elif directives". + +ix30. If the controlling expression in a #if evaluates to a nonzero + value, the immediately following the #if participate in + preprocessing. They are subject to preprocessing expansion, + substitution, and evaluation of processing directives in the + . + +ix40. Further preprocessing when #if controlling expression evaluates + to a nonzero value proceeds. Subsequent #elif and #else + directives at the same level of nesting are skipped, and do not + participate in preprocessing except to be examined for proper + nesting of conditional directives. + +ix45. If the controlling expression in a #if evaluates to a zero + value, the lines immediately following the #if directive are + skipped, and examined only to determine nesting of conditionals. + Within these lines, no token expansion occurs, and no Fortran + comment lines nor source lines are made available for subsequent + processing by the processor. Preprocessing continues with any + #elif directives at the same level of nesting, as described + below. + +ix50. When the #if controlling expression evaluates to zero, the + controlling expressions in each of the #elif directives at the + same nesting level are evaluated in turn. Those whose expression + evaluate to false are skipped in the same manner as when a #if + clause evaluates to false. + +ix55. When a #elif controlling expression evaluates to a nonzero + value, the immediately following the #elif participate + in preprocessing just as they do when the controlling expression + in a #if evaluates to a nonzero value. Subsequent #elif and + #else directives at the same nesting level are skipped, as + described for #if. + +ix60. When all controlling expression in #if or #elif directives + evaluates to a zero value and a #else directive is present at + the same nesting level, the between the #else directive + and the matching #endif directive are subject to preprocessing, + expansion and substitution as they would be in #if true + processing. + +ix65. When all controlling expression in #if or #elif directives + evaluates to a zero value and no #else directive is present at + the same nesting level, there are no in the list of + conditional directives subject to preprocessing. 3.6 The '#error' and '#warning' directives From 4447b62760607a95d12524a29ed49ffef2eb9ec7 Mon Sep 17 00:00:00 2001 From: Gary Klimowicz Date: Mon, 5 May 2025 11:57:38 -0700 Subject: [PATCH 3/5] Remove redundant `` in illustrative conditional directives. Co-authored-by: Dan Bonachea --- drafts/25-xxx-specifications.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drafts/25-xxx-specifications.txt b/drafts/25-xxx-specifications.txt index c622ed9..bace227 100644 --- a/drafts/25-xxx-specifications.txt +++ b/drafts/25-xxx-specifications.txt @@ -420,9 +420,9 @@ in28. Unlike INCLUDE lines (see the section on "INCLUDE lines"), Example syntax (extra spacing for illustration purposes only): General form: - #endif EOL - #endif EOL - #endif EOL + #endif EOL + #endif EOL + #endif EOL Where: is one of: From 940dc2239050081eb6ea040f8ed81d2528f46f5e Mon Sep 17 00:00:00 2001 From: Gary Klimowicz Date: Mon, 5 May 2025 11:58:07 -0700 Subject: [PATCH 4/5] Replace typo `##` with `#` Co-authored-by: Dan Bonachea --- drafts/25-xxx-specifications.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drafts/25-xxx-specifications.txt b/drafts/25-xxx-specifications.txt index bace227..afec4f9 100644 --- a/drafts/25-xxx-specifications.txt +++ b/drafts/25-xxx-specifications.txt @@ -447,7 +447,7 @@ Example syntax (extra spacing for illustration purposes only): 3.5.1 Static semantics specifications ------------------------------------- -if05. A #if, ##ifdef, or #ifndef directive signals the start of a list +if05. A #if, #ifdef, or #ifndef directive signals the start of a list of conditional directives. if10: Whitespace must immediately follow the directives tokens From a77c93f22e64d3b316530682977463d5da3be41d Mon Sep 17 00:00:00 2001 From: Gary Klimowicz Date: Mon, 5 May 2025 11:59:05 -0700 Subject: [PATCH 5/5] Replace incorrect use of `macros` with `directives` Co-authored-by: Dan Bonachea --- drafts/25-xxx-specifications.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drafts/25-xxx-specifications.txt b/drafts/25-xxx-specifications.txt index afec4f9..945cd9f 100644 --- a/drafts/25-xxx-specifications.txt +++ b/drafts/25-xxx-specifications.txt @@ -479,7 +479,7 @@ if40. As shown in the illustrative syntax, there should be no more ----------------------------------------- -ix05. The #ifdef and #ifndef macros are evaluated as if they had been +ix05. The #ifdef and #ifndef directives are evaluated as if they had been written "#if defined(ID)" and "#if !defined(ID)" respectively. (For brevity, the descriptions of #ifdef and #ifndef directives below are omitted, and assume this transformation.)