@@ -247,6 +247,28 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
247
247
return false ;
248
248
}
249
249
250
+ static void StorageSequenceExtension (
251
+ Descriptor &desc, const Descriptor &source) {
252
+ // Support the near-universal extension of NAMELIST input into a
253
+ // designatable storage sequence identified by its initial scalar array
254
+ // element. For example, treat "A(1) = 1. 2. 3." as if it had been
255
+ // "A(1:) = 1. 2. 3.".
256
+ if (desc.rank () == 0 && (source.rank () == 1 || source.IsContiguous ())) {
257
+ if (auto stride{source.rank () == 1
258
+ ? source.GetDimension (0 ).ByteStride ()
259
+ : static_cast <SubscriptValue>(source.ElementBytes ())};
260
+ stride != 0 ) {
261
+ desc.raw ().attribute = CFI_attribute_pointer;
262
+ desc.raw ().rank = 1 ;
263
+ desc.GetDimension (0 )
264
+ .SetBounds (1 ,
265
+ source.Elements () -
266
+ ((source.OffsetElement () - desc.OffsetElement ()) / stride))
267
+ .SetByteStride (stride);
268
+ }
269
+ }
270
+ }
271
+
250
272
static bool HandleSubstring (
251
273
IoStatementState &io, Descriptor &desc, const char *name) {
252
274
IoErrorHandler &handler{io.GetIoErrorHandler ()};
@@ -480,10 +502,14 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
480
502
bool hadSubscripts{false };
481
503
bool hadSubstring{false };
482
504
if (next && (*next == ' (' || *next == ' %' )) {
505
+ const Descriptor *lastSubscriptBase{nullptr };
506
+ Descriptor *lastSubscriptDescriptor{nullptr };
483
507
do {
484
508
Descriptor &mutableDescriptor{staticDesc[whichStaticDesc].descriptor ()};
485
509
whichStaticDesc ^= 1 ;
486
510
io.HandleRelativePosition (byteCount); // skip over '(' or '%'
511
+ lastSubscriptDescriptor = nullptr ;
512
+ lastSubscriptBase = nullptr ;
487
513
if (*next == ' (' ) {
488
514
if (!hadSubstring && (hadSubscripts || useDescriptor->rank () == 0 )) {
489
515
mutableDescriptor = *useDescriptor;
@@ -497,11 +523,12 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
497
523
" NAMELIST group '%s'" ,
498
524
name, group.groupName );
499
525
return false ;
526
+ } else if (HandleSubscripts (
527
+ io, mutableDescriptor, *useDescriptor, name)) {
528
+ lastSubscriptBase = useDescriptor;
529
+ lastSubscriptDescriptor = &mutableDescriptor;
500
530
} else {
501
- if (!HandleSubscripts (
502
- io, mutableDescriptor, *useDescriptor, name)) {
503
- return false ;
504
- }
531
+ return false ;
505
532
}
506
533
hadSubscripts = true ;
507
534
} else {
@@ -514,6 +541,9 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
514
541
useDescriptor = &mutableDescriptor;
515
542
next = io.GetCurrentChar (byteCount);
516
543
} while (next && (*next == ' (' || *next == ' %' ));
544
+ if (lastSubscriptDescriptor) {
545
+ StorageSequenceExtension (*lastSubscriptDescriptor, *lastSubscriptBase);
546
+ }
517
547
}
518
548
// Skip the '='
519
549
next = io.GetNextNonBlank (byteCount);
0 commit comments