10-126
To: J3
From: Malcolm Cohen
Subject: Scoping unit fixes for BLOCK construct.
Date: 2010 February 15
References: 09-303r2, 10-124.
1. Introduction
The standard often uses "scoping unit" in contexts where we need to
consider BLOCK constructs. This paper attempts to fix these by making
BLOCK constructs into a special kind of scoping unit.
This includes all appropriate edits from 09-303r2 and 10-124.
2. Edits to 09-007r3
[11:42-45] Delete 1.3.82 interface body.
{This is just a prose name for a syntax term.
We don't do definitions of those normally, I see no reason to do so here.}
[throughout] Fix hyperlink references to "interface body" to land on the
syntax term, and index that as a definition.
[15:34+] Insert new bullet item
"- a BLOCK construct, excluding any scoping units in it,"
[15:36+] Insert new definitions
"1.3.115.1
<>
scoping unit that is a BLOCK construct
1.3.115.2
<>
scoping unit plus every block scoping unit whose host is that scoping
unit or that is nested within such a block scoping unit
Note 1.4a
That is, inclusive scope is the scope as if BLOCK constructs were not
scoping units.".
[20:18-19] 1.3.143.1 local variable,
Delete "or BLOCK construct",
Delete "or construct".
{No longer needed.}
[44:20] 3.2.5 Statement labels, p2, 2nd sentence,
"in a scoping unit" -> "in its scope".
{Better wording, safe against all scoping unit definition changes.}
[101:12] 5.3.16 SAVE attribute, p4, last sentence,
Before "a main program" insert "of" .
{A main program/module/submodule is not necessarily the same as its scoping
unit.}
[109:28] 5.5 IMPLICIT statement, p4, penultimate sentence,
Change "outermost scoping unit in which it appears"
to "outermost inclusive scope in which it appears"
{A bit ugly, but works because "inclusive scope" is just what "scoping
unit" used to be.}
[110:end-of-page+] end of subclause 5.5, insert new note
"Note 5.38a
Implicit typing is not affected by BLOCK constructs. For example, in
SUBROUTINE S(N)
...
IF (N>0) THEN
BLOCK
NSQP = CEILING(SQRT(DBLE(N)))
END BLOCK
END IF
...
IF (N>0) THEN
BLOCK
PRINT *,NSQP
END BLOCK
END IF
END SUBROUTINE
even if the only two appearances of NSQP are within the BLOCK
constructs, the scope of NSQP is the whole subroutine S."
[131:4,6] 6.7.3.2 Deallocation of allocatable variables, p5,
Delete "or BLOCK construct" and delete "or block".
[172:9+] 8.1.4 BLOCK construct, end of subclause,
"Note 8.4a
The following is an example of a BLOCK construct.
IF (swapxy) THEN
BLOCK
REAL(KIND(x)) tmp
tmp = x
x = y
y = tmp
END BLOCK
END IF
Actions on a variable local to a BLOCK construct do not affect any
variable of the same name outside the construct. For example,
F = 254E-2
BLOCK
REAL F
F = 39.37
END BLOCK
! F is still equal to 254E-2.
A SAVE statement outside a BLOCK construct does not affect variables
local to the BLOCK construct, because a SAVE statement affects
variables in its scoping unit rather than in its inclusive scope.
For example,
SUBROUTINE S
...
SAVE
...
BLOCK
REAL X ! Not saved.
REAL,SAVE :: Y(100) ! SAVE attribute is allowed.
Z = 3 ! Implicitly declared in S, thus saved.
...
END BLOCK
...
END SUBROUTINE"
[186:15] 8.2.1 Branch concepts, p1,
Delete "in a scoping unit",
and change "same scoping unit" to "same inclusive scope".
{First "in a scoping unit" is unnecessary and confusing.}
[186:26,30-31,37] 8.2.2 GO TO statement, C846,
and 8.2.3 Computed GO TO statement, C847,
and 8.2.4 Arithmetic IF statement, C848,
Change "scoping unit" to "inclusive scope", thrice.
[207:26] 9.5.6.2 Syntax, C905, "scoping unit" -> "inclusive scope".
[211:15] 9.5.7.2 Syntax, C909, "scoping unit" -> "inclusive scope".
[212:35] 9.6.2.1 Syntax, C914, "scoping unit" -> "inclusive scope".
[214:7] 9.6.2.2 Format specification in a data transfer statement, C931,
Change "scoping unit" to "inclusive scope".
[231:4] 9.7.2 WAIT statement, C940,
Change "scoping unit" to "inclusive scope".
[231:33] 9.8.1 Syntax, C943, "scoping unit" -> "inclusive scope".
[233:12] 9.9 FLUSH statement, C946, "scoping unit" -> "inclusive scope".
[235:15] 9.10.2.1 Syntax, "scoping unit" -> "inclusive scope".
[272:24,26] 11.2.2 The USE statement and use association, p2,
Delete "or BLOCK construct", twice.
[273:1] Same paragraph, delete "or BLOCK construct" again.
[290:22] 12.5.1 Syntax of a procedure reference, C1253,
Change "scoping unit" to "inclusive scope".
[307:28,30] C1253 and 12.6.2.2p4,
"scoping unit" -> "scope of the function name", twice.
[441:2] 16.1 Identifiers and entities,
Change title to "Scopes, identifiers, and entities".
{Because *here* is where we say what the scopes actually are.}
[441:3] p1,
"Entities are identified by identifiers within a scope that is a program,
a scoping unit, a construct, a single statement, or part of a
statement."
->
"An entity is identified by an identifier.
{We are about to list the scopes, don't repeat ourselves.}
[441:5-8] Replace with
"The scope of
- a global identifier is a program (2.2.2),
- a local identifier is an inclusive scope,
- an identifier of a construct entity is that construct (7.2.4, 8.1),
and
- an identifier of a statement entity is that statement or part of that
statement (3.3),
excluding any nested scope where the identifier is treated as the
identifier of a different entity (16.3, 16.4)."
{Describe the scope correctly, if a bit vaguely.}
[441:20] 16.2 Scope of global identifiers,
Change title to "Global identifiers".
{Nothing here about scopes, they were done in 16.1.}
[442:1] 16.3 Scope of local identifiers,
Change title to "Local identifiers".
{Nothing here about scopes, they were done in 16.1.}
[442:3] 16.3.1 Classes of local identifiers, p1,
"Within a scoping unit, identifiers of entities in the classes"
-> "Identifiers of entities in the following classes:"
[442:11]
Delete "in that scoping unit".
{Scope is already established in 16.1p1.}
[442:12] "Within a scoping unit" -> "Within its scope",
[442:13] "that scoping unit" -> "that scope".
[442:18] "Within a scoping unit" -> "Within its scope".
[443:1-2] p4,
Replace "scoping unit" with "scope", twice.
{We have already defined "scope" correctly, we only need use it here.}
[443:32] "scoping units" ->"the scope".
{Should have been singular before anyway.}
[444:17-19] 16.4 Statement and construct entities, p2,
Delete whole paragraph which is now unnecessary after fixing the scope
of global and local entities.
{Previously wrong for nested constructs, also contradicted by p4
re statement entities.}
[444:20-27] p3 and p4, Replace both paragraphs with
"Even if the name of a statement entity is the same as another identifier
and the statement is in the scope of that identifier, within the scope
of the statement entity the name is interpreted as that of the
statement entity."
{Previously wrong when a construct entity also existed, also wrong for
multiple statement entities in separate statements with the same name, and
also for construct entities elsewhere.}
[444:28-29] p4, Replace first sentence with
"The name of a statement entity shall not be the same as an accessible
global identifier or local identifier of class (1) (16.3.1), except
for a common block name or a scalar variable name.".
{Previously confusing and ambiguous re global identifiers.}
[445:1-3] p9, Replace first sentence "Except ... s." with
"If a FORALL statement, FORALL construct, or DO CONCURRENT construct does
not have a , an shall not be the same as an
accessible global identifier, local identifier, or identifier of an
outer construct entity, except for a common block name or a scalar
variable name.".
{Broken for ASSOCIATE, BLOCK and SELECT TYPE.}
[445:15] 16.5.1.1p1 Forms of name association,
"scoping unit"->"scope", twice.
[445:28] 16.5.1.3 Use association,
After "Use" insert "association",
Change "scoping units" to "scopes".
[445:30] "scoping unit"->"scope", twice.
3. Non-edits
The following possibly-problematic places seem, on closer examination,
to be ok.
[58:18] This is very poorly worded and could do with rewriting.
[97:3-5] Looks ok - this is not exhaustive.
[105:9] Looks ok.
[105:18] Looks ok.
[151:4] Looks ok.
[404:1-4] Ok, except that it is self-contradictory and incomplete.
And the last part belongs in 14.3.
[443:13,14] Probably ok.
[443:30] Probably ok.
[444:31-43] Broken already in F2003, fix this later.
===END===