@@ -44,7 +44,8 @@ bool IODEF(OutputNamelist)(Cookie cookie, const NamelistGroup &group) {
4444 if ((connection.NeedAdvance (prefixLen) &&
4545 !(io.AdvanceRecord () && EmitAscii (io, " " , 1 ))) ||
4646 !EmitAscii (io, prefix, prefixLen) ||
47- (connection.NeedAdvance (runtime::strlen (str) + (suffix != ' ' )) &&
47+ (connection.NeedAdvance (
48+ Fortran::runtime::strlen (str) + (suffix != ' ' )) &&
4849 !(io.AdvanceRecord () && EmitAscii (io, " " , 1 )))) {
4950 return false ;
5051 }
@@ -101,8 +102,8 @@ static constexpr RT_API_ATTRS char NormalizeIdChar(char32_t ch) {
101102 return static_cast <char >(ch >= ' A' && ch <= ' Z' ? ch - ' A' + ' a' : ch);
102103}
103104
104- static RT_API_ATTRS bool GetLowerCaseName (IoStatementState &io, char buffer[],
105- std:: size_t maxLength, bool crashIfTooLong = true ) {
105+ static RT_API_ATTRS bool GetLowerCaseName (
106+ IoStatementState &io, char buffer[], std:: size_t maxLength ) {
106107 std::size_t byteLength{0 };
107108 if (auto ch{io.GetNextNonBlank (byteLength)}) {
108109 if (IsLegalIdStart (*ch)) {
@@ -116,10 +117,8 @@ static RT_API_ATTRS bool GetLowerCaseName(IoStatementState &io, char buffer[],
116117 if (j <= maxLength) {
117118 return true ;
118119 }
119- if (crashIfTooLong) {
120- io.GetIoErrorHandler ().SignalError (
121- " Identifier '%s...' in NAMELIST input group is too long" , buffer);
122- }
120+ io.GetIoErrorHandler ().SignalError (
121+ " Identifier '%s...' in NAMELIST input group is too long" , buffer);
123122 }
124123 }
125124 return false ;
@@ -357,8 +356,9 @@ static RT_API_ATTRS bool HandleComponent(IoStatementState &io, Descriptor &desc,
357356 const DescriptorAddendum *addendum{source.Addendum ()};
358357 if (const typeInfo::DerivedType *
359358 type{addendum ? addendum->derivedType () : nullptr }) {
360- if (const typeInfo::Component *comp{
361- type->FindDataComponent (compName, runtime::strlen (compName))}) {
359+ if (const typeInfo::Component *
360+ comp{type->FindDataComponent (
361+ compName, Fortran::runtime::strlen (compName))}) {
362362 bool createdDesc{false };
363363 if (comp->rank () > 0 && source.rank () > 0 ) {
364364 // If base and component are both arrays, the component name
@@ -483,7 +483,7 @@ bool IODEF(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
483483 handler.SignalError (" NAMELIST input group has no name" );
484484 return false ;
485485 }
486- if (runtime::strcmp (group.groupName , name) == 0 ) {
486+ if (Fortran:: runtime::strcmp (group.groupName , name) == 0 ) {
487487 break ; // found it
488488 }
489489 SkipNamelistGroup (io);
@@ -502,7 +502,7 @@ bool IODEF(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
502502 }
503503 std::size_t itemIndex{0 };
504504 for (; itemIndex < group.items ; ++itemIndex) {
505- if (runtime::strcmp (name, group.item [itemIndex].name ) == 0 ) {
505+ if (Fortran:: runtime::strcmp (name, group.item [itemIndex].name ) == 0 ) {
506506 break ;
507507 }
508508 }
@@ -576,14 +576,13 @@ bool IODEF(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
576576 if (const auto *addendum{useDescriptor->Addendum ()};
577577 addendum && addendum->derivedType ()) {
578578 const NonTbpDefinedIoTable *table{group.nonTbpDefinedIo };
579- listInput->ResetForNextNamelistItem (&group );
579+ listInput->ResetForNextNamelistItem (/* inNamelistSequence= */ true );
580580 if (!IONAME (InputDerivedType)(cookie, *useDescriptor, table) &&
581581 handler.InError ()) {
582582 return false ;
583583 }
584584 } else {
585- listInput->ResetForNextNamelistItem (
586- useDescriptor->rank () > 0 ? &group : nullptr );
585+ listInput->ResetForNextNamelistItem (useDescriptor->rank () > 0 );
587586 if (!descr::DescriptorIO<Direction::Input>(io, *useDescriptor) &&
588587 handler.InError ()) {
589588 return false ;
@@ -607,51 +606,27 @@ bool IODEF(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
607606}
608607
609608RT_API_ATTRS bool IsNamelistNameOrSlash (IoStatementState &io) {
610- auto *listInput{io.get_if <ListDirectedStatementState<Direction::Input>>()};
611- if (!listInput || !listInput->namelistGroup ()) {
612- return false ; // not namelist
613- }
614- SavedPosition savedPosition{io};
615- std::size_t byteCount{0 };
616- auto ch{io.GetNextNonBlank (byteCount)};
617- if (!ch) {
618- return false ;
619- } else if (!IsLegalIdStart (*ch)) {
620- return *ch == ' /' || *ch == ' &' || *ch == ' $' ;
621- }
622- char id[nameBufferSize];
623- if (!GetLowerCaseName (io, id, sizeof id, /* crashIfTooLong=*/ false )) {
624- return true ; // long name
625- }
626- // It looks like a name, but might be "inf" or "nan". Check what
627- // follows.
628- ch = io.GetNextNonBlank (byteCount);
629- if (!ch) {
630- return false ;
631- } else if (*ch == ' =' || *ch == ' %' ) {
632- return true ;
633- } else if (*ch != ' (' ) {
634- return false ;
635- } else if (runtime::strcmp (id, " nan" ) != 0 ) {
636- return true ;
637- }
638- // "nan(" ambiguity
639- int depth{1 };
640- while (true ) {
641- io.HandleRelativePosition (byteCount);
642- ch = io.GetNextNonBlank (byteCount);
643- if (depth == 0 ) {
644- // nan(...) followed by '=', '%', or '('?
645- break ;
646- } else if (!ch) {
647- return true ; // not a valid NaN(...)
648- } else if (*ch == ' (' ) {
649- ++depth;
650- } else if (*ch == ' )' ) {
651- --depth;
609+ if (auto *listInput{
610+ io.get_if <ListDirectedStatementState<Direction::Input>>()}) {
611+ if (listInput->inNamelistSequence ()) {
612+ SavedPosition savedPosition{io};
613+ std::size_t byteCount{0 };
614+ if (auto ch{io.GetNextNonBlank (byteCount)}) {
615+ if (IsLegalIdStart (*ch)) {
616+ do {
617+ io.HandleRelativePosition (byteCount);
618+ ch = io.GetCurrentChar (byteCount);
619+ } while (ch && IsLegalIdChar (*ch));
620+ ch = io.GetNextNonBlank (byteCount);
621+ // TODO: how to deal with NaN(...) ambiguity?
622+ return ch && (*ch == ' =' || *ch == ' (' || *ch == ' %' );
623+ } else {
624+ return *ch == ' /' || *ch == ' &' || *ch == ' $' ;
625+ }
626+ }
652627 }
653628 }
654- return ch && (*ch == ' = ' || *ch == ' % ' || *ch == ' ( ' ) ;
629+ return false ;
655630}
656631
657632RT_OFFLOAD_API_GROUP_END
0 commit comments