Lines Matching defs:symbol

38 #include "flang/Semantics/symbol.h"
182 // Make a placeholder symbol for a Name that otherwise wouldn't have one.
196 const Symbol &symbol, const T &expr, parser::CharBlock source) {
197 if (!context().HasError(symbol)) {
201 symbol, std::move(*maybeExpr), GetFoldingContext());
485 // Result symbol
492 // Completes the definition of a symbol if it is the top function's result.
522 void PushScope(Scope::Kind kind, Symbol *symbol);
536 // Special messages: already declared; referencing symbol's declaration;
556 // Search for symbol by name in current, parent derived type, and
572 void EraseSymbol(const Symbol &symbol) { currScope().erase(symbol.name()); }
573 // Make a new symbol with the name and attrs of an existing one
599 auto *symbol{FindInScope(name)};
600 if (!symbol) {
601 symbol = &MakeSymbol(name, attrs);
602 symbol->set_details(std::move(details));
603 return *symbol;
606 if (auto *d{symbol->detailsIf<GenericDetails>()}) {
616 CheckDuplicatedAttrs(name, *symbol, attrs);
626 if (auto *d{symbol->detailsIf<GenericDetails>()}) {
640 if (symbol->CanReplaceDetails(details)) {
641 // update the existing symbol
642 CheckDuplicatedAttrs(name, *symbol, attrs);
643 SetExplicitAttrs(*symbol, attrs);
646 details.set_isDummy(IsDummy(*symbol));
648 symbol->set_details(std::move(details));
649 return *symbol;
651 CheckDuplicatedAttrs(name, *symbol, attrs);
652 SetExplicitAttrs(*symbol, attrs);
653 return *symbol;
655 if (!CheckPossibleBadForwardRef(*symbol)) {
656 if (name.empty() && symbol->name().empty()) {
658 return *symbol;
660 Symbol &errSym{*symbol};
661 if (auto *d{symbol->detailsIf<GenericDetails>()}) {
670 // replace the old symbol with a new one with correct details
671 EraseSymbol(*symbol);
684 void SetExplicitAttr(Symbol &symbol, Attr attr) const {
685 symbol.attrs().set(attr);
686 symbol.implicitAttrs().reset(attr);
688 void SetExplicitAttrs(Symbol &symbol, Attrs attrs) const {
689 symbol.attrs() |= attrs;
690 symbol.implicitAttrs() &= ~attrs;
692 void SetImplicitAttr(Symbol &symbol, Attr attr) const {
693 symbol.attrs().set(attr);
694 symbol.implicitAttrs().set(attr);
702 // Apply the implicit type rules to this symbol.
828 return useModuleScope_ && useModuleScope_->symbol() &&
829 useRenames_.find({name, useModuleScope_->symbol()->name()}) !=
874 Symbol &GetGenericSymbol() { return DEREF(genericInfo_.top().symbol); }
875 // Add to generic the symbol for the subprogram with the same name
885 Symbol *symbol{nullptr}; // the generic symbol being defined
889 void SetGenericSymbol(Symbol &symbol) { genericInfo_.top().symbol = &symbol; }
927 // Edits an existing symbol created for earlier calls to a subprogram or ENTRY
931 // Create a subprogram symbol in the current scope and push a new scope.
1078 // type specified, implicit rules apply. Return pointer to the new symbol,
1093 // Each of these returns a pointer to a resolved Name (i.e. with symbol)
1099 bool PassesSharedLocalityChecks(const parser::Name &name, Symbol &symbol);
1112 void NoteScalarSpecificationArgument(const Symbol &symbol) {
1113 mustBeScalar_.emplace(symbol);
1119 Symbol &symbol{MakeSymbol(name, attrs)};
1120 if (context().HasError(symbol) || symbol.has<T>()) {
1121 return symbol; // OK or error already reported
1122 } else if (symbol.has<UnknownDetails>()) {
1123 symbol.set_details(T{});
1124 return symbol;
1125 } else if (auto *details{symbol.detailsIf<EntityDetails>()}) {
1126 symbol.set_details(T{std::move(*details)});
1127 return symbol;
1129 (symbol.has<ObjectEntityDetails>() ||
1130 symbol.has<ProcEntityDetails>())) {
1131 return symbol; // OK
1132 } else if (auto *details{symbol.detailsIf<UseDetails>()}) {
1136 } else if (auto *details{symbol.detailsIf<SubprogramNameDetails>()}) {
1140 symbol, "Module procedure definition"_en_US);
1144 symbol, "Internal procedure definition"_en_US);
1149 symbol.has<ProcEntityDetails>()) {
1151 name, symbol, "'%s' is already declared as a procedure"_err_en_US);
1153 symbol.has<ObjectEntityDetails>()) {
1154 if (FindCommonBlockContaining(symbol)) {
1155 SayWithDecl(name, symbol,
1159 name, symbol, "'%s' is already declared as an object"_err_en_US);
1161 } else if (!CheckPossibleBadForwardRef(symbol)) {
1162 SayAlreadyDeclared(name, symbol);
1164 context().SetError(symbol);
1165 return symbol;
1230 const parser::Name &name, Symbol &symbol, Symbol::Flag flag);
1233 bool MustBeScalar(const Symbol &symbol) const {
1234 return mustBeScalar_.find(symbol) != mustBeScalar_.end();
1271 // Creates Block scopes with neither symbol name nor symbol details.
1670 mapperName->symbol = mapperSym;
1692 if (auto *symbol{FindSymbol(currScope(), mapper->v)}) {
1696 auto *misc{symbol->detailsIf<MiscDetails>()};
1701 mapper->v.symbol = symbol;
1703 mapper->v.symbol =
1706 // the symbol is not declared, but right now, testing that the TODO for
1933 if (!name.symbol) {
1934 name.symbol = &context_->globalScope().MakeSymbol(
1960 bool AttrsVisitor::SetPassNameOn(Symbol &symbol) {
1969 symbol.details());
1973 void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
1975 !symbol.attrs().test(Attr::BIND_C)) {
1978 symbol.SetIsCDefined(isCDefined_);
1983 symbol.SetIsExplicitBindName(true);
1991 } else if (symbol.GetIsExplicitBindName()) {
1994 } else if (ClassifyProcedure(symbol) == ProcedureDefinitionClass::Internal) {
1998 label = symbol.name().ToString();
2000 // Checks whether a symbol has two Bind names.
2002 if (const auto *bindName{symbol.GetBindName()}) {
2005 symbol.SetBindName(std::move(*label));
2007 if (const std::string * newBindName{symbol.GetBindName()}) {
2009 Say(symbol.name(),
2011 symbol.name(), oldBindName, *newBindName);
2390 Symbol &symbol{*info->resultSymbol};
2391 if (!scopeHandler_.context().HasError(symbol)) {
2392 if (symbol.GetType()) {
2393 scopeHandler_.Say(symbol.name(),
2395 scopeHandler_.context().SetError(symbol);
2397 symbol.SetType(*type);
2408 void FuncResultStack::CompleteTypeIfFunctionResult(Symbol &symbol) {
2410 if (info->resultSymbol == &symbol) {
2435 details->symbol().name(), GetUsedModule(*details).name());
2452 void ScopeHandler::SayWithReason(const parser::Name &name, Symbol &symbol,
2455 Say(name, std::move(msg1), symbol.name()).Attach(std::move(msg2));
2456 context().SetError(symbol, isFatal);
2460 Message &ScopeHandler::SayWithDecl(const parser::Name &name, Symbol &symbol,
2463 Say(name.source, std::move(msg), symbol.name(), std::forward<A>(args)...)
2464 .Attach(symbol.name(),
2465 symbol.test(Symbol::Flag::Implicit)
2469 if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}) {
2471 if (usedAsProc->begin() != symbol.name().begin()) {
2480 const parser::Name &name, Symbol &symbol) {
2481 SayWithDecl(name, symbol,
2498 Symbol &symbol, MessageFixedText &&msg2) {
2500 Message &result{Say2(name, std::move(msg1), symbol.name(), std::move(msg2))};
2501 context().SetError(symbol, isFatal);
2505 Symbol &symbol, MessageFixedText &&msg2) {
2508 Say2(name.source, std::move(msg1), symbol.name(), std::move(msg2))};
2509 context().SetError(symbol, isFatal);
2551 void ScopeHandler::PushScope(Scope::Kind kind, Symbol *symbol) {
2552 PushScope(currScope().MakeScope(kind, symbol));
2567 if (auto *symbol{scope.symbol()}) {
2568 // Create a dummy symbol so we can't create another one with the same
2570 SourceName name{symbol->name()};
2574 // Allow for recursive references. If this symbol is a function
2575 // without an explicit RESULT(), this new symbol will be discarded
2577 newSymbol.set_details(HostAssocDetails{*symbol});
2610 if (Symbol * symbol{scope.FindComponent(name.source)}) {
2611 if (symbol->has<TypeParamDetails>()) {
2612 return Resolve(name, symbol);
2627 if (Symbol * symbol{FindInScope(scope, name)}) {
2628 CheckDuplicatedAttrs(name, *symbol, attrs);
2629 SetExplicitAttrs(*symbol, attrs);
2630 return *symbol;
2645 Symbol &symbol{*NonDerivedTypeScope()
2648 name.symbol = &symbol;
2649 symbol.attrs() = hostSymbol.attrs(); // TODO: except PRIVATE, PUBLIC?
2652 symbol.implicitAttrs() =
2653 symbol.attrs() & Attrs{Attr::ASYNCHRONOUS, Attr::VOLATILE};
2654 // SAVE statement in the inner scope will create a new symbol.
2659 symbol.implicitAttrs() |= hostSymbol.implicitAttrs() & Attrs{Attr::SAVE};
2660 symbol.flags() = hostSymbol.flags();
2661 return symbol;
2663 Symbol &ScopeHandler::CopySymbol(const SourceName &name, const Symbol &symbol) {
2665 return MakeSymbol(currScope(), name, symbol.attrs());
2695 if (Symbol * symbol{FindInScope(scope, name)}) {
2696 return symbol;
2700 if (Symbol * symbol{FindInScopeOrBlockConstructs(child, name)}) {
2701 return symbol;
2710 name.symbol = nullptr;
2713 static bool NeedsType(const Symbol &symbol) {
2714 return !symbol.GetType() &&
2720 return symbol.test(Symbol::Flag::Function) &&
2721 !symbol.attrs().test(Attr::INTRINSIC) &&
2726 symbol.details());
2730 Symbol &symbol, bool allowForwardReference) {
2731 funcResultStack_.CompleteTypeIfFunctionResult(symbol);
2732 if (context().HasError(symbol) || !NeedsType(symbol)) {
2735 if (const DeclTypeSpec * type{GetImplicitType(symbol)}) {
2737 symbol.set(Symbol::Flag::Implicit);
2738 symbol.SetType(*type);
2742 if (symbol.has<ProcEntityDetails>() && !symbol.attrs().test(Attr::EXTERNAL)) {
2744 if (symbol.test(Symbol::Flag::Function)) {
2746 } else if (symbol.test(Symbol::Flag::Subroutine)) {
2749 if (IsIntrinsic(symbol.name(), functionOrSubroutineFlag)) {
2751 AcquireIntrinsicProcedureFlags(symbol);
2755 if (allowForwardReference && ImplicitlyTypeForwardRef(symbol)) {
2758 if (const auto *entity{symbol.detailsIf<EntityDetails>()};
2768 if (!context().HasError(symbol)) {
2769 Say(symbol.name(), "No explicit type declared for '%s'"_err_en_US);
2770 context().SetError(symbol);
2778 bool ScopeHandler::ImplicitlyTypeForwardRef(Symbol &symbol) {
2779 if (!inSpecificationPart_ || context().HasError(symbol) ||
2780 !(IsDummy(symbol) || FindCommonBlockContaining(symbol)) ||
2781 symbol.Rank() != 0 ||
2787 GetImplicitType(symbol, false /*ignore IMPLICIT NONE*/)};
2795 if (!ConvertToObjectEntity(symbol)) {
2799 context().Warn(common::LanguageFeature::ForwardRefImplicitNone, symbol.name(),
2801 symbol.name());
2802 symbol.set(Symbol::Flag::Implicit);
2803 symbol.SetType(*type);
2807 // Ensure that the symbol for an intrinsic procedure is marked with
2810 void ScopeHandler::AcquireIntrinsicProcedureFlags(Symbol &symbol) {
2811 SetImplicitAttr(symbol, Attr::INTRINSIC);
2812 switch (context().intrinsics().GetIntrinsicClass(symbol.name().ToString())) {
2815 SetExplicitAttr(symbol, Attr::ELEMENTAL);
2816 SetExplicitAttr(symbol, Attr::PURE);
2821 SetExplicitAttr(symbol, Attr::PURE);
2826 Symbol &symbol, bool respectImplicitNoneType) {
2827 const Scope *scope{&symbol.owner()};
2833 symbol.name(), respectImplicitNoneType)};
2844 void ScopeHandler::CheckEntryDummyUse(SourceName source, Symbol *symbol) {
2845 if (!inSpecificationPart_ && symbol &&
2846 symbol->test(Symbol::Flag::EntryDummyArgument)) {
2849 symbol->name());
2850 symbol->set(Symbol::Flag::EntryDummyArgument, false);
2854 // Convert symbol to be a ObjectEntity or return false if it can't be.
2855 bool ScopeHandler::ConvertToObjectEntity(Symbol &symbol) {
2856 if (symbol.has<ObjectEntityDetails>()) {
2858 } else if (symbol.has<UnknownDetails>()) {
2861 if (symbol.attrs().HasAny({Attr::EXTERNAL, Attr::INTRINSIC})) {
2864 symbol.set_details(ObjectEntityDetails{});
2865 } else if (auto *details{symbol.detailsIf<EntityDetails>()}) {
2866 if (symbol.attrs().HasAny({Attr::EXTERNAL, Attr::INTRINSIC})) {
2869 funcResultStack_.CompleteTypeIfFunctionResult(symbol);
2870 symbol.set_details(ObjectEntityDetails{std::move(*details)});
2871 } else if (auto *useDetails{symbol.detailsIf<UseDetails>()}) {
2872 return useDetails->symbol().has<ObjectEntityDetails>();
2873 } else if (auto *hostDetails{symbol.detailsIf<HostAssocDetails>()}) {
2874 return hostDetails->symbol().has<ObjectEntityDetails>();
2880 // Convert symbol to be a ProcEntity or return false if it can't be.
2882 Symbol &symbol, std::optional<SourceName> usedHere) {
2883 if (symbol.has<ProcEntityDetails>()) {
2884 } else if (symbol.has<UnknownDetails>()) {
2885 symbol.set_details(ProcEntityDetails{});
2886 } else if (auto *details{symbol.detailsIf<EntityDetails>()}) {
2887 if (IsFunctionResult(symbol) &&
2888 !(IsPointer(symbol) && symbol.attrs().test(Attr::EXTERNAL))) {
2893 funcResultStack_.CompleteTypeIfFunctionResult(symbol);
2894 symbol.set_details(ProcEntityDetails{std::move(*details)});
2895 if (symbol.GetType() && !symbol.test(Symbol::Flag::Implicit)) {
2896 CHECK(!symbol.test(Symbol::Flag::Subroutine));
2897 symbol.set(Symbol::Flag::Function);
2899 } else if (auto *useDetails{symbol.detailsIf<UseDetails>()}) {
2900 return useDetails->symbol().has<ProcEntityDetails>();
2901 } else if (auto *hostDetails{symbol.detailsIf<HostAssocDetails>()}) {
2902 return hostDetails->symbol().has<ProcEntityDetails>();
2906 auto &proc{symbol.get<ProcEntityDetails>()};
2943 if (inSpecificationPart_ && !deferImplicitTyping_ && name.symbol) {
2947 bool isHostAssociated{&name.symbol->owner() == &currScope()
2948 ? name.symbol->has<HostAssocDetails>()
2949 : name.symbol->owner().Contains(currScope())};
2958 const Symbol &symbol) const {
2959 auto iter{specPartState_.forwardRefs.find(symbol.name())};
2966 bool ScopeHandler::CheckPossibleBadForwardRef(const Symbol &symbol) {
2967 if (!context().HasError(symbol)) {
2968 if (auto fwdRef{HadForwardRef(symbol)}) {
2969 const Symbol *outer{symbol.owner().FindSymbol(symbol.name())};
2970 if (outer && symbol.has<UseDetails>() &&
2971 &symbol.GetUltimate() == &outer->GetUltimate()) {
2978 .Attach(symbol.name(), "Later declaration of '%s'"_en_US, *fwdRef);
2979 context().SetError(symbol);
2982 if ((IsDummy(symbol) || FindCommonBlockContaining(symbol)) &&
2983 isImplicitNoneType() && symbol.test(Symbol::Flag::Implicit) &&
2984 !context().HasError(symbol)) {
2988 Say(symbol.name(), "No explicit type declared for '%s'"_err_en_US);
2989 context().SetError(symbol);
2996 void ScopeHandler::MakeExternal(Symbol &symbol) {
2997 if (!symbol.attrs().test(Attr::EXTERNAL)) {
2998 SetImplicitAttr(symbol, Attr::EXTERNAL);
2999 if (symbol.attrs().test(Attr::INTRINSIC)) { // C840
3000 Say(symbol.name(),
3002 symbol.name());
3008 SourceName name, Symbol &symbol, Attr attr) {
3011 } else if (symbol.attrs().test(attr)) { // C815
3012 if (symbol.implicitAttrs().test(attr)) {
3014 symbol.implicitAttrs().reset(attr);
3025 SourceName name, Symbol &symbol, Attrs attrs) {
3028 [&](Attr x) { ok &= CheckDuplicatedAttr(name, symbol, x); });
3032 void ScopeHandler::SetCUDADataAttr(SourceName source, Symbol &symbol,
3035 ConvertToObjectEntity(symbol);
3036 if (auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
3040 symbol.name(),
3048 symbol.name());
3128 } else if (currScope().IsModule() && currScope().symbol() &&
3129 currScope().symbol()->attrs().test(Attr::INTRINSIC)) {
3140 useModuleScope_->symbol()->ReplaceName(x.moduleName.source);
3160 for (const auto &[name, symbol] : *useModuleScope_) {
3161 if (symbol->attrs().test(Attr::PUBLIC) && !IsUseRenamed(symbol->name()) &&
3162 (!symbol->implicitAttrs().test(Attr::INTRINSIC) ||
3163 symbol->has<UseDetails>()) &&
3164 !symbol->has<MiscDetails>() && useNames.count(name) == 0) {
3167 DoAddUse(location, localSymbol->name(), *localSymbol, *symbol);
3169 DoAddUse(location, location, CopySymbol(name, *symbol), *symbol);
3206 // symbol must be either a Use or a Generic formed by merging two uses.
3209 Symbol &symbol, const SourceName &location, const Symbol &used) {
3210 if (auto *ued{symbol.detailsIf<UseErrorDetails>()}) {
3214 const auto *useDetails{symbol.detailsIf<UseDetails>()};
3216 if (auto *genericDetails{symbol.detailsIf<GenericDetails>()}) {
3223 symbol.set_details(
3335 // use a UseDetails symbol for proper data addressing, and a derived
3354 // use-associating the same symbol again -- ok
3366 // Convert the local symbol to a UseErrorDetails, if possible;
3392 // There are many possible combinations of symbol types that could arrive
3446 // Creates a UseErrorDetails symbol in the current scope for a
3447 // current UseDetails symbol, but leaves the UseDetails in the
3687 // Create a UseDetails symbol for this USE and add it to generic
3756 Symbol &symbol{isSubmodule ? Resolve(name,
3760 auto &details{symbol.get<ModuleDetails>()};
3761 PushScope(Scope::Kind::Module, &symbol);
3790 Resolve(name, scope->symbol());
3797 DEREF(currScope().symbol()).detailsIf<ModuleDetails>()};
3802 Symbol &symbol{*pair.second};
3803 if (!symbol.attrs().HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
3805 if (auto *generic{symbol.detailsIf<GenericDetails>()}) {
3817 SetImplicitAttr(symbol, attr);
3837 // Create a symbol in genericSymbol_ for this GenericSpec.
3839 if (auto *symbol{FindInScope(GenericSpecInfo{x}.symbolName())}) {
3840 SetGenericSymbol(*symbol);
3862 if (Symbol * symbol{GetGenericInfo().symbol}) {
3863 SetExplicitAttrs(*symbol, attrs);
3875 return !genericInfo_.empty() && GetGenericInfo().symbol;
3883 if (Symbol * symbol{GetGenericInfo().symbol};
3884 symbol && symbol->has<GenericDetails>()) {
3886 specificsForGenericProcs_.emplace(symbol, std::make_pair(&name, kind));
3887 genericsForSpecificProcs_.emplace(name.source, symbol);
3898 for (const Symbol &symbol : details.specificProcs()) {
3899 symbolsSeen.insert(symbol.GetUltimate());
3906 const Symbol *symbol{isEndOfSpecificationPart
3910 const Symbol *specific{symbol};
3912 if (symbol) {
3913 // Subtlety: when *symbol is a use- or host-association, the specific
3914 // procedure that is recorded in the GenericDetails below must be *symbol,
3916 // procedure may be a symbol from another module and its name unavailable
3918 const Symbol &bypassed{BypassGeneric(*symbol)};
3919 if (symbol == &symbol->GetUltimate()) {
3957 // is saved in the generic's specifics, not its ultimate symbol,
3983 if (Symbol * generic{genericInfo_.top().symbol};
4052 if (auto *symbol{FindSymbol(name)}) {
4053 Symbol &ultimate{symbol->GetUltimate()};
4057 (&symbol->owner() == &currScope() && IsFunctionResult(*symbol))) {
4061 if (IsHostAssociated(*symbol, currScope())) {
4080 auto &symbol{PushSubprogramScope(name, Symbol::Flag::Function)};
4081 symbol.set(Symbol::Flag::StmtFunction);
4082 EraseSymbol(symbol); // removes symbol added by PushSubprogramScope
4083 auto &details{symbol.get<SubprogramDetails>()};
4124 if (const Symbol * subprogram{InclusiveScope().symbol()}) {
4158 if (auto *subp{currScope().symbol()
4159 ? currScope().symbol()->detailsIf<SubprogramDetails>()
4227 } else if (auto *subp{currScope().symbol()
4228 ? currScope().symbol()->detailsIf<SubprogramDetails>()
4252 } else if (auto *subp{currScope().symbol()
4253 ? currScope().symbol()->detailsIf<SubprogramDetails>()
4305 Symbol &symbol{PostSubprogramStmt()};
4306 SubprogramDetails &details{symbol.get<SubprogramDetails>()};
4329 Symbol &symbol{PostSubprogramStmt()};
4330 SubprogramDetails &details{symbol.get<SubprogramDetails>()};
4342 // The symbol created by PushScope() is retained as a place-holder
4350 CHECK(context().HasError(currScope().symbol()));
4385 // resolved to the created function result symbol because every parser::Name
4389 name.symbol = &symbol; // must not be function result symbol
4396 Symbol &symbol{*currScope().symbol()};
4397 SetExplicitAttrs(symbol, EndAttrs());
4398 if (symbol.attrs().test(Attr::MODULE)) {
4399 symbol.attrs().set(Attr::EXTERNAL, false);
4400 symbol.implicitAttrs().set(Attr::EXTERNAL, false);
4402 return symbol;
4475 // Hide the entry's symbol in a new anonymous global scope so
4477 Symbol &symbol{MakeSymbol(outer, context().GetTempName(outer), Attrs{})};
4478 symbol.set_details(MiscDetails{MiscDetails::Kind::ScopeName});
4479 Scope &hidden{outer.MakeScope(Scope::Kind::Global, &symbol)};
4574 // The entry symbol should have already been created and resolved
4578 if (!name.symbol) {
4583 } else if (FindSeparateModuleSubprogramInterface(inclusiveScope.symbol())) {
4593 Symbol &entrySymbol{*name.symbol};
4627 auto *symbol{FindSymbol(name)};
4628 if (symbol && symbol->has<SubprogramNameDetails>()) {
4631 parent = currScope().symbol()->get<ModuleDetails>().parent();
4633 symbol = parent ? FindSymbol(*parent, name) : nullptr;
4635 if (symbol) {
4636 if (auto *generic{symbol->detailsIf<GenericDetails>()}) {
4637 symbol = generic->specific();
4640 if (const Symbol * defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
4642 symbol = const_cast<Symbol *>(defnIface);
4644 if (!IsSeparateModuleProcedureInterface(symbol)) {
4646 symbol = nullptr;
4648 return symbol;
4653 Symbol *symbol{FindSeparateModuleProcedureInterface(name)};
4654 if (!symbol) {
4657 if (symbol->owner() == currScope() && symbol->scope()) {
4660 SetScope(DEREF(symbol->scope()));
4661 symbol->get<SubprogramDetails>().set_isInterface(false);
4662 name.symbol = symbol;
4669 newSubprogram.set_moduleInterface(*symbol);
4670 auto &subprogram{symbol->get<SubprogramDetails>()};
4674 newSymbol.attrs() |= symbol->attrs();
4675 newSymbol.set(symbol->test(Symbol::Flag::Subroutine)
4678 MapSubprogramToNewSymbols(*symbol, newSymbol, currScope());
4707 name.symbol = nullptr;
4731 void SubprogramVisitor::HandleLanguageBinding(Symbol *symbol,
4734 if (binding && *binding && symbol) {
4742 SetBindNameOn(*symbol);
4743 symbol->attrs() |= EndAttrs();
4752 HandleLanguageBinding(currScope().symbol(), stmtSource, binding);
4759 HandleLanguageBinding(name.symbol, name.source, &suffix->binding);
4763 if (inInterfaceBlock() && currScope().symbol()) {
4764 DeclaredPossibleSpecificProc(*currScope().symbol());
4770 const parser::Name &name, Symbol &symbol, Symbol::Flag subpFlag) {
4771 // If the extant symbol is a generic, check its homonymous specific
4773 if (auto *generic{symbol.detailsIf<GenericDetails>()}) {
4776 } else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
4778 !symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
4779 // There's a symbol created for previous calls to this subprogram or
4780 // ENTRY's name. We have to replace that symbol in situ to avoid the
4781 // obligation to rewrite symbol pointers in the parse tree.
4782 if (!symbol.test(subpFlag)) {
4787 if (symbol.attrs().test(Attr::EXTERNAL) &&
4788 !symbol.implicitAttrs().test(Attr::EXTERNAL)) {
4793 } else if (symbol.test(other)) {
4798 symbol, "Previous call of '%s'"_en_US);
4800 symbol.set(subpFlag);
4807 symbol.details() = std::move(entity);
4810 return symbol.has<UnknownDetails>() || symbol.has<SubprogramNameDetails>();
4833 Symbol *symbol{GetSpecificFromGeneric(name)};
4834 if (!symbol) {
4840 // in a new global scope, so that its symbol's name won't clash
4841 // with another symbol that has a distinct binding label.
4847 symbol = &MakeSymbol(name, SubprogramDetails{});
4849 symbol->ReplaceName(name.source);
4850 symbol->set(subpFlag);
4851 PushScope(Scope::Kind::Subprogram, symbol);
4856 auto &details{symbol->get<SubprogramDetails>()};
4859 SetExplicitAttr(*symbol, Attr::ABSTRACT);
4861 SetExplicitAttr(*symbol, Attr::MODULE);
4863 MakeExternal(*symbol);
4868 details->AddSpecificProc(*symbol, name.source);
4877 found->set(subpFlag); // PushScope() created symbol
4879 return *symbol;
4904 if (auto *symbol{currScope().FindSymbol(name.source)}) {
4905 if (symbol->has<SubprogramNameDetails>()) {
4908 // symbol doesn't inherit it and ruin the ability to check it.
4909 symbol->attrs().reset(Attr::MODULE);
4911 } else if (auto *details{symbol->detailsIf<GenericDetails>()}) {
4924 // Define its interface now as a new symbol.
4927 } else if (&specific->owner() != &symbol->owner()) {
4936 if (&dType->owner() != &symbol->owner()) {
4978 return HadUseError(context(), name.source, name.symbol);
4981 // Report error if accessibility of symbol doesn't match isPrivate.
4983 const SourceName &name, bool isPrivate, Symbol &symbol) {
4984 if (symbol.attrs().test(Attr::PRIVATE) != isPrivate) {
4987 symbol, "Previous declaration of '%s'"_en_US);
5018 // symbol being initialized will be available within the initialization
5027 Symbol &symbol{DeclareUnknownEntity(name, attrs)};
5028 symbol.ReplaceName(name.source);
5029 SetCUDADataAttr(name.source, symbol, cudaDataAttr());
5031 ConvertToObjectEntity(symbol) || ConvertToProcEntity(symbol);
5032 symbol.set(
5038 if (auto *scopeSymbol{currScope().symbol()}) {
5041 details->add_component(symbol);
5054 Symbol &symbol{DeclareObjectEntity(name, Attrs{Attr::POINTER})};
5055 symbol.ReplaceName(name.source);
5058 if (const auto *symbol{FindInScope(name)}) {
5059 const auto *subp{symbol->detailsIf<SubprogramDetails>()};
5060 if (!symbol->has<UseDetails>() && // error caught elsewhere
5061 !symbol->has<ObjectEntityDetails>() &&
5062 !symbol->has<ProcEntityDetails>() &&
5063 !symbol->CanReplaceDetails(ObjectEntityDetails{}) &&
5064 !symbol->CanReplaceDetails(ProcEntityDetails{}) &&
5076 Symbol *symbol;
5078 symbol = &HandleAttributeStmt(Attr::BIND_C, name);
5080 symbol = &MakeCommonBlockSymbol(name);
5081 SetExplicitAttr(*symbol, Attr::BIND_C);
5087 if (symbol->has<CommonBlockDetails>() || symbol->has<ObjectEntityDetails>() ||
5088 symbol->has<EntityDetails>()) {
5089 SetBindNameOn(*symbol);
5104 auto &symbol{HandleAttributeStmt(Attr::PARAMETER, name)};
5105 ConvertToObjectEntity(symbol);
5106 auto *details{symbol.detailsIf<ObjectEntityDetails>()};
5107 if (!details || symbol.test(Symbol::Flag::CrayPointer) ||
5108 symbol.test(Symbol::Flag::CrayPointee)) {
5110 name, symbol, "PARAMETER attribute not allowed on '%s'"_err_en_US);
5114 if (details->init() || symbol.test(Symbol::Flag::InDataStmt)) {
5122 SayWithDecl(name, symbol,
5148 ApplyImplicitRules(symbol);
5151 symbol, expr, expr.thing.value().source)}) {
5169 Symbol *symbol{FindInScope(name)};
5170 if (symbol && !symbol->has<UnknownDetails>()) {
5178 SayAlreadyDeclared(name, *symbol);
5179 symbol = nullptr;
5182 symbol = &MakeSymbol(name, Attrs{Attr::PARAMETER}, ObjectEntityDetails{});
5183 symbol->SetType(context().MakeNumericType(
5203 if (symbol) {
5205 symbol->get<ObjectEntityDetails>().set_init(SomeExpr{
5208 context().SetError(*symbol);
5242 auto *symbol{FindSymbol(name)};
5243 if (!ConvertToProcEntity(DEREF(symbol), name.source)) {
5244 // Check if previous symbol is an interface.
5245 if (auto *details{symbol->detailsIf<SubprogramDetails>()}) {
5255 name, *symbol, "EXTERNAL attribute not allowed on '%s'"_err_en_US);
5257 } else if (symbol->attrs().test(Attr::INTRINSIC)) { // C840
5258 Say(symbol->name(),
5260 symbol->name());
5282 auto &symbol{DEREF(FindSymbol(name))};
5283 if (symbol.has<GenericDetails>()) {
5285 } else if (!ConvertToProcEntity(symbol, name.source)) {
5287 name, symbol, "INTRINSIC attribute not allowed on '%s'"_err_en_US);
5288 } else if (symbol.attrs().test(Attr::EXTERNAL)) { // C840
5289 Say(symbol.name(),
5291 symbol.name());
5293 if (symbol.GetType()) {
5297 common::UsageWarning::IgnoredIntrinsicFunctionType, symbol.name(),
5299 symbol.name())}) {
5304 if (!symbol.test(Symbol::Flag::Function) &&
5305 !symbol.test(Symbol::Flag::Subroutine)) {
5307 symbol.set(Symbol::Flag::Function);
5310 symbol.set(Symbol::Flag::Subroutine);
5332 auto *symbol{FindInScope(name)};
5333 if (symbol && symbol->has<UseDetails>()) {
5338 if (!symbol) {
5339 symbol = &MakeSymbol(name, ObjectEntityDetails{});
5341 SetCUDADataAttr(name.source, *symbol, attr);
5356 auto *symbol{FindInScope(name)};
5358 // these can be set on a symbol that is host-assoc or use-assoc
5359 if (!symbol &&
5363 symbol = &MakeHostAssocSymbol(name, *hostSymbol);
5366 } else if (symbol && symbol->has<UseDetails>()) {
5367 if (symbol->GetUltimate().attrs().test(attr)) {
5377 return *symbol;
5379 if (!symbol) {
5380 symbol = &MakeSymbol(name, EntityDetails{});
5382 if (CheckDuplicatedAttr(name.source, *symbol, attr)) {
5384 SetExplicitAttr(*symbol, attr);
5386 return *symbol;
5411 Symbol &symbol{DeclareEntity<EntityDetails>(name, attrs)};
5416 if (symbol.attrs().test(Attr::EXTERNAL)) {
5417 ConvertToProcEntity(symbol);
5418 } else if (symbol.attrs().HasAny(Attrs{Attr::ALLOCATABLE,
5421 ConvertToObjectEntity(symbol);
5424 SetBindNameOn(symbol);
5426 return symbol;
5463 // Create the ProcEntityDetails symbol in the scope as the "specific()"
5464 // symbol behind an existing GenericDetails symbol of the same name.
5471 Symbol &symbol{proc ? *proc : DeclareEntity<ProcEntityDetails>(name, attrs)};
5472 if (auto *details{symbol.detailsIf<ProcEntityDetails>()}) {
5473 if (context().HasError(symbol)) {
5474 } else if (HasCycle(symbol, interface)) {
5475 return symbol;
5477 SayWithDecl(name, symbol,
5479 context().SetError(symbol);
5484 symbol.set(Symbol::Flag::Function);
5486 symbol.set(Symbol::Flag::Subroutine);
5490 symbol.set(Symbol::Flag::Function);
5492 SetBindNameOn(symbol);
5493 SetPassNameOn(symbol);
5495 return symbol;
5500 Symbol &symbol{DeclareEntity<ObjectEntityDetails>(name, attrs)};
5501 if (auto *details{symbol.detailsIf<ObjectEntityDetails>()}) {
5507 if (!context().HasError(symbol)) {
5510 context().SetError(symbol);
5512 } else if (MustBeScalar(symbol)) {
5516 } else if (details->init() || symbol.test(Symbol::Flag::InDataStmt)) {
5524 if (!context().HasError(symbol)) {
5527 context().SetError(symbol);
5533 SetBindNameOn(symbol);
5538 return symbol;
5741 if (const Symbol * derivedSymbol{derivedName.symbol}) {
5756 SayWithDecl(typeName, *typeName.symbol,
5861 CHECK(scope.symbol());
5862 CHECK(scope.symbol()->scope() == &scope);
5863 auto &details{scope.symbol()->get<DerivedTypeDetails>()};
5865 if (auto *symbol{FindInScope(scope, paramName)}) {
5866 if (auto *details{symbol->detailsIf<TypeParamDetails>()}) {
5908 // type's symbol to foil attempts to recursively extend a type.
5915 auto &symbol{MakeSymbol(name, GetAttrs(), std::move(derivedTypeDetails))};
5916 symbol.ReplaceName(name.source);
5917 derivedTypeInfo_.type = &symbol;
5918 PushScope(Scope::Kind::DerivedType, &symbol);
5921 // Any symbol stored in the EXTENDS() clause is temporarily
5922 // hidden so that a new symbol can be created for the parent
5926 auto restorer{common::ScopedSet(extendsName->symbol, nullptr)};
5938 DerivedTypeDetails &details{symbol.get<DerivedTypeDetails>()};
5944 if (auto *details{symbol.detailsIf<DerivedTypeDetails>()}) {
5946 if (Symbol * symbol{MakeTypeSymbol(name, TypeParamDetails{})}) {
5947 details->add_paramNameOrder(*symbol);
5957 if (Symbol * dtSym{currScope().symbol()}) {
5963 if (Symbol * symbol{FindInScope(currScope(), name)}) {
5964 if (auto *paramDetails{symbol->detailsIf<TypeParamDetails>()}) {
5977 derivedDetails->add_paramDeclOrder(*symbol);
6066 auto &symbol{DeclareObjectEntity(name, attrs)};
6067 SetCUDADataAttr(name.source, symbol, cudaDataAttr());
6068 if (symbol.has<ObjectEntityDetails>()) {
6073 currScope().symbol()->get<DerivedTypeDetails>().add_component(symbol);
6083 auto &symbol{DeclareObjectEntity(name, GetAttrs())};
6084 currScope().symbol()->get<DerivedTypeDetails>().add_component(symbol);
6165 // Don't use BypassGeneric or GetUltimate on this symbol, they can
6168 interfaceName_ ? interfaceName_->symbol : nullptr};
6171 if (Symbol * symbol{currScope().symbol()}) {
6172 dtDetails = symbol->detailsIf<DerivedTypeDetails>();
6177 Symbol &symbol{DeclareProcEntity(name, attrs, procInterface)};
6178 SetCUDADataAttr(name.source, symbol, cudaDataAttr()); // for error
6179 symbol.ReplaceName(name.source);
6181 dtDetails->add_component(symbol);
6183 DeclaredPossibleSpecificProc(symbol);
6209 auto *symbol{FindInTypeOrParents(*bindingName)};
6210 if (!symbol) {
6213 } else if (!symbol->has<ProcBindingDetails>()) {
6214 SayWithDecl(*bindingName, *symbol, // C772
6218 *symbol, bindingName->source);
6262 const Symbol &ultimate{details->symbol().GetUltimate()};
6268 if (details->symbol().name() != binding->name()) {
6273 binding->name(), details->symbol().name());
6306 if (currScope().IsDerivedType() && currScope().symbol()) {
6307 if (auto *details{currScope().symbol()->detailsIf<DerivedTypeDetails>()}) {
6309 Symbol *symbol{FindSymbol(subrName)};
6310 if (!symbol) {
6312 symbol = &MakeSymbol(
6314 Resolve(subrName, symbol);
6315 symbol->set_details(ProcEntityDetails{});
6316 symbol->set(Symbol::Flag::Subroutine);
6318 if (auto pair{details->finals().emplace(subrName.source, *symbol)};
6353 "Type bound generic procedure '%s' may not have the same name as a non-generic symbol inherited from an ancestor type"_err_en_US)
6354 .Attach(inherited->name(), "Inherited symbol"_en_US);
6399 auto &symbol{MakeSymbol(*name, DerivedTypeDetails{})};
6400 symbol.ReplaceName(name->source);
6401 symbol.get<DerivedTypeDetails>().set_sequence(true);
6402 symbol.get<DerivedTypeDetails>().set_isDECStructure(true);
6403 derivedTypeInfo_.type = &symbol;
6404 PushScope(Scope::Kind::DerivedType, &symbol);
6409 DerivedTypeSpec derivedTypeSpec{symbol.name(), symbol};
6410 derivedTypeSpec.set_scope(DEREF(symbol.scope()));
6480 // we need to resolve its symbol in the scope of the derived type.
6523 if (Symbol * pointee{pointeeName.symbol}) {
6576 auto *symbol{FindSymbol(name)};
6577 if (!symbol) {
6578 symbol = &MakeSymbol(name, ObjectEntityDetails{});
6579 ApplyImplicitRules(*symbol);
6580 } else if (!ConvertToObjectEntity(symbol->GetUltimate())) {
6581 SayWithDecl(name, *symbol, "'%s' is not a variable"_err_en_US);
6584 symbol->GetUltimate().set(Symbol::Flag::InNamelist);
6585 details->add_object(*symbol);
6596 auto *symbol{FindSymbol(*name)};
6597 if (!symbol) {
6599 } else if (!symbol->GetUltimate().has<NamelistDetails>()) {
6601 *name, *symbol, "'%s' is not the name of a namelist group"_err_en_US);
6687 auto *symbol{FindInScope(name)};
6688 if (!symbol) {
6698 } else if (!IsSaved(*symbol)) {
6699 SetExplicitAttr(*symbol, Attr::SAVE);
6703 if (auto *symbol{currScope().FindCommonBlock(name)}) {
6704 auto &objects{symbol->get<CommonBlockDetails>().objects()};
6716 for (auto &object : symbol->get<CommonBlockDetails>().objects()) {
6751 const auto &symbol{*pair.second};
6752 if (symbol.get<CommonBlockDetails>().objects().empty() &&
6753 symbol.attrs().test(Attr::BIND_C)) {
6754 Say(symbol.name(),
6761 const auto *symbol{currScope().FindSymbol(name)};
6762 if (!symbol) {
6765 const auto &attrs{symbol->attrs()};
6772 } else if (IsNamedConstant(*symbol)) {
6775 } else if (IsDummy(*symbol)) {
6778 } else if (symbol->IsFuncResult()) {
6781 } else if (const DeclTypeSpec * type{symbol->GetType()}) {
6858 // INTRINSIC flag will cause this symbol to have a complete interface
6862 Symbol &symbol{MakeSymbol(InclusiveScope(), name.source, Attrs{})};
6863 SetImplicitAttr(symbol, Attr::INTRINSIC);
6872 symbol.set_details(std::move(details));
6873 symbol.set(Symbol::Flag::Function);
6875 SetExplicitAttr(symbol, Attr::ELEMENTAL);
6878 SetExplicitAttr(symbol, Attr::PURE);
6880 Resolve(name, symbol);
6889 const parser::Name &name, Symbol &symbol) {
6890 if (!IsVariableName(symbol)) {
6891 SayLocalMustBeVariable(name, symbol); // C1124
6894 if (symbol.owner() == currScope()) { // C1125 and C1126
6895 SayAlreadyDeclared(name, symbol);
6903 const parser::Name &name, Symbol &symbol, Symbol::Flag flag) {
6907 if (IsAllocatable(symbol) && !isReduce) { // F'2023 C1130
6908 SayWithDecl(name, symbol,
6913 if (IsOptional(symbol)) { // F'2023 C1130-C1131
6914 SayWithDecl(name, symbol,
6918 if (IsIntentIn(symbol)) { // F'2023 C1130-C1131
6919 SayWithDecl(name, symbol,
6923 if (IsFinalizable(symbol) && !isReduce) { // F'2023 C1130
6924 SayWithDecl(name, symbol,
6929 if (evaluate::IsCoarray(symbol) && !isReduce) { // F'2023 C1130
6930 SayWithDecl(name, symbol,
6934 if (const DeclTypeSpec * type{symbol.GetType()}) {
6935 if (type->IsPolymorphic() && IsDummy(symbol) && !IsPointer(symbol) &&
6937 SayWithDecl(name, symbol,
6943 if (symbol.attrs().test(Attr::ASYNCHRONOUS) && isReduce) { // F'2023 C1131
6944 SayWithDecl(name, symbol,
6948 if (symbol.attrs().test(Attr::VOLATILE) && isReduce) { // F'2023 C1131
6949 SayWithDecl(name, symbol,
6953 if (IsAssumedSizeArray(symbol)) { // F'2023 C1130-C1131
6954 SayWithDecl(name, symbol,
6959 name.source, currScope(), DefinabilityFlags{}, symbol)}) {
6960 SayWithReason(name, symbol,
6965 return PassesSharedLocalityChecks(name, symbol);
6985 if (auto *symbol{&MakeHostAssocSymbol(name, prev)}) {
6986 symbol->set(flag);
7001 name.symbol = nullptr;
7005 Symbol &symbol{DeclareEntity<ObjectEntityDetails>(name, {})};
7006 if (!symbol.has<ObjectEntityDetails>()) {
7019 ApplyImplicitRules(symbol);
7021 return Resolve(name, &symbol);
7027 CHECK(name.symbol);
7028 auto &symbol{*name.symbol};
7043 if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}) {
7047 context().SetError(symbol);
7051 auto *prevType{symbol.GetType()};
7053 if (symbol.test(Symbol::Flag::InDataStmt) && isImplicitNoneType()) {
7059 symbol.SetType(type);
7060 } else if (symbol.has<UseDetails>()) {
7062 } else if (HadForwardRef(symbol)) {
7064 } else if (!symbol.test(Symbol::Flag::Implicit)) {
7066 name, symbol, "The type of '%s' has already been declared"_err_en_US);
7067 context().SetError(symbol);
7069 SayWithDecl(name, symbol,
7071 context().SetError(symbol);
7073 symbol.set(Symbol::Flag::Implicit, false);
7080 Symbol *symbol{FindSymbol(outer, name)};
7081 Symbol *ultimate{symbol ? &symbol->GetUltimate() : nullptr};
7085 symbol = genDT;
7089 if (!symbol || symbol->has<UnknownDetails>() ||
7092 if (!symbol) {
7093 symbol = &MakeSymbol(outer, name.source, Attrs{});
7094 Resolve(name, *symbol);
7097 symbol = &outer.MakeSymbol(name.source, Attrs{}, UnknownDetails{});
7098 generic->set_derivedType(*symbol);
7099 name.symbol = symbol;
7103 symbol->set_details(std::move(details));
7108 } else if (&DEREF(symbol).owner() != &outer &&
7116 } else if (symbol->GetUltimate().has<DerivedTypeDetails>()) {
7117 return DerivedTypeSpec{name.source, *symbol};
7143 // The symbol is checked later by CheckExplicitInterface() and
7146 Symbol &symbol{MakeSymbol(InclusiveScope(), name.source, Attrs{})};
7147 Resolve(name, symbol);
7149 return name.symbol;
7153 if (const Symbol * symbol{name.symbol}) {
7154 const Symbol &ultimate{symbol->GetUltimate()};
7155 if (!context().HasError(*symbol) && !context().HasError(ultimate) &&
7159 symbol->name());
7164 // Create a symbol for a type parameter, component, or procedure binding in
7174 if (auto *symbol{FindInScope(derivedType, name)}) { // C742
7178 *symbol, "Previous definition of '%s'"_en_US);
7280 name.symbol = nullptr;
7282 auto &symbol{DeclareObjectEntity(name)};
7283 if (symbol.GetType()) {
7286 ApplyImplicitRules(symbol);
7291 symbol.SetType(*type);
7293 ApplyImplicitRules(symbol);
7424 // during semantic analysis before the symbol's initializer is constructed.
7431 if (first.symbol) {
7432 first.symbol->set(Symbol::Flag::InDataStmt);
7454 if (first.symbol) {
7455 first.symbol->set(Symbol::Flag::InDataStmt);
7473 if (const Symbol * symbol{FindSymbol(*name)};
7474 symbol && symbol->GetUltimate().has<DerivedTypeDetails>()) {
7476 DerivedTypeSpec{name->source, *symbol});
7533 if (auto *symbol{MakeAssocEntity()}) {
7541 SetTypeFromAssociation(*symbol);
7542 SetAttrsFromAssociation(*symbol);
7570 if (auto *symbol{FindInScope(name)}) {
7578 if (!symbol->GetType()) {
7579 symbol->SetType(ToDeclTypeSpec(std::move(*dynType)));
7676 if (auto *symbol{MakeAssocEntity()}) {
7678 SetTypeFromAssociation(*symbol);
7680 symbol->SetType(*type);
7682 SetAttrsFromAssociation(*symbol);
7687 if (auto *symbol{MakeAssocEntity()}) {
7688 SetTypeFromAssociation(*symbol);
7689 auto &details{symbol->get<AssocEntityDetails>()};
7714 symbol->attrs() |= selectorAttrs & attrsToKeep;
7728 if (x && !x->symbol) {
7755 // Make a symbol for the associating entity of the current association.
7757 Symbol *symbol{nullptr};
7760 symbol = &MakeSymbol(*association.name, UnknownDetails{});
7761 if (symbol->has<AssocEntityDetails>() && symbol->owner() == currScope()) {
7768 symbol = &MakeSymbol(whole->name());
7773 symbol->set_details(AssocEntityDetails{common::Clone(*expr)});
7775 symbol->set_details(AssocEntityDetails{});
7777 return symbol;
7780 // Set the type of symbol based on the current association selector.
7781 void ConstructVisitor::SetTypeFromAssociation(Symbol &symbol) {
7782 auto &details{symbol.get<AssocEntityDetails>()};
7793 symbol.SetType(ToDeclTypeSpec(std::move(*type),
7798 symbol.SetType(ToDeclTypeSpec(std::move(*type)));
7802 Say(symbol.name(), "Associate name '%s' must have a type"_err_en_US);
7807 // If current selector is a variable, set some of its attributes on symbol.
7809 void ConstructVisitor::SetAttrsFromAssociation(Symbol &symbol) {
7811 symbol.attrs() |=
7814 SetImplicitAttr(symbol, Attr::TARGET);
8162 if (Symbol * symbol{currScope().FindSymbol(name)}) {
8163 if (!symbol->attrs().test(Attr::ASYNCHRONOUS)) {
8164 if (&symbol->owner() != &currScope()) {
8165 symbol = &*currScope()
8166 .try_emplace(name, HostAssocDetails{*symbol})
8169 if (symbol->has<AssocEntityDetails>()) {
8170 symbol = const_cast<Symbol *>(&GetAssociationRoot(*symbol));
8172 SetImplicitAttr(*symbol, Attr::ASYNCHRONOUS);
8223 if (Symbol * symbol{FindInScope(name)}) {
8224 if (outer->GetUltimate() == symbol->GetUltimate()) {
8231 .Attach(symbol->name(), "Previous declaration of '%s'"_en_US)
8272 if (name && name->symbol) {
8273 if (!IsProcedure(*name->symbol)) {
8274 ConvertToObjectEntity(*name->symbol);
8275 } else if (!context().HasError(*name->symbol)) {
8276 SayWithDecl(*name, *name->symbol,
8278 context().SetError(*name->symbol);
8291 // If implicit types are allowed, ensure name is in the symbol table.
8304 if (Symbol * symbol{name.symbol}) {
8309 symbol->set(Symbol::Flag::ImplicitOrError, false);
8310 if (IsUplevelReference(*symbol)) {
8311 MakeHostAssocSymbol(name, *symbol);
8312 } else if (IsDummy(*symbol) ||
8313 (!symbol->GetType() && FindCommonBlockContaining(*symbol))) {
8314 CheckEntryDummyUse(name.source, symbol);
8315 ConvertToObjectEntity(*symbol);
8316 ApplyImplicitRules(*symbol);
8317 } else if (const auto *tpd{symbol->detailsIf<TypeParamDetails>()};
8322 context().SetError(*symbol);
8336 // Create the symbol, then ensure that it is accessible
8343 auto *symbol{FindSymbol(name)};
8344 if (!symbol) {
8349 ConvertToObjectEntity(*symbol);
8350 ApplyImplicitRules(*symbol);
8355 // A specification expression may refer to a symbol in the host procedure that
8357 // execution parts, this may be the first time we see the symbol. It can't be a
8360 // We create a symbol in the host assuming it is the former; if that proves to
8367 if (name.symbol) {
8368 ApplyImplicitRules(*name.symbol, true);
8372 if (!name.symbol) {
8379 } else if (name.symbol->test(Symbol::Flag::ImplicitOrError)) {
8380 hostSymbol = name.symbol;
8383 Symbol &symbol{MakeHostAssocSymbol(name, *hostSymbol)};
8384 if (auto *assoc{symbol.detailsIf<HostAssocDetails>()}) {
8397 bool DeclarationVisitor::IsUplevelReference(const Symbol &symbol) {
8398 if (symbol.owner().IsTopLevel()) {
8401 const Scope &symbolUnit{GetProgramUnitContaining(symbol)};
8415 if (!base || !base->symbol) {
8418 if (auto *misc{base->symbol->detailsIf<MiscDetails>()}) {
8430 CheckEntryDummyUse(base->source, base->symbol);
8431 auto &symbol{base->symbol->GetUltimate()};
8432 if (!symbol.has<AssocEntityDetails>() && !ConvertToObjectEntity(symbol)) {
8433 SayWithDecl(*base, symbol,
8437 auto *type{symbol.GetType()};
8465 if (auto msg{CheckAccessibleSymbol(currScope(), *component.symbol)}) {
8476 if (symbol.test(Symbol::Flag::Implicit)) {
8481 *base, symbol, "'%s' is not an object of derived type"_err_en_US);
8491 // Search preceding scopes until we find a matching symbol or run out
8495 if (Symbol * symbol{scope->FindSymbol(name.source)}) {
8496 if (symbol->test(Symbol::Flag::Subroutine) ||
8497 symbol->test(Symbol::Flag::Function)) {
8499 symbol->name(), Attrs{}, HostAssocDetails{*symbol})};
8502 "subroutine/function symbol");
8503 name.symbol = &*sym->second;
8504 symbol->test(Symbol::Flag::Subroutine)
8505 ? name.symbol->set(Symbol::Flag::Subroutine)
8506 : name.symbol->set(Symbol::Flag::Function);
8509 // if we find a symbol that is not a function or subroutine, we
8530 // symbol being declared can be available for use in the expression, e.g.:
8532 if (!name.symbol) {
8535 Symbol &ultimate{name.symbol->GetUltimate()};
8591 if (name.symbol) {
8592 Symbol &ultimate{name.symbol->GetUltimate()};
8628 if (name.symbol) {
8629 Symbol &ultimate{name.symbol->GetUltimate()};
8639 if (!CheckUseError(*targetName) && targetName->symbol) {
8641 details.set_init(*targetName->symbol);
8657 if (!context().HasError(name.symbol)) {
8658 Symbol &ultimate{name.symbol->GetUltimate()};
8665 SayWithDecl(name, *name.symbol,
8692 if (Symbol * symbol{name.symbol}) {
8693 if (IsProcedure(*symbol)) {
8694 SetProcFlag(name, *symbol, procFlag);
8717 name && name->symbol) {
8718 const Symbol &symbol{*name->symbol};
8719 const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
8720 if (symbol.has<EntityDetails>() ||
8722 NoteScalarSpecificationArgument(symbol);
8735 auto *symbol{FindSymbol(NonDerivedTypeScope(), name)};
8736 if (!symbol) {
8738 symbol = &MakeSymbol(InclusiveScope(), name.source, Attrs{});
8739 SetImplicitAttr(*symbol, Attr::INTRINSIC);
8743 symbol = FindSymbol(*ppcBuiltinScope, name);
8744 if (!symbol) {
8745 symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
8748 symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
8750 Resolve(name, *symbol);
8751 ConvertToProcEntity(*symbol, name.source);
8752 if (!symbol->attrs().test(Attr::INTRINSIC)) {
8753 if (CheckImplicitNoneExternal(name.source, *symbol)) {
8754 MakeExternal(*symbol);
8755 // Create a place-holder HostAssocDetails symbol to preclude later
8756 // use of this name as a local symbol; but don't actually use this new
8757 // HostAssocDetails symbol in expressions.
8758 MakeHostAssocSymbol(name, *symbol);
8759 name.symbol = symbol;
8762 CheckEntryDummyUse(name.source, symbol);
8763 SetProcFlag(name, *symbol, flag);
8767 symbol = &symbol->GetUltimate();
8768 if (!name.symbol ||
8769 (name.symbol->has<HostAssocDetails>() && symbol->owner().IsGlobal() &&
8770 (symbol->has<ProcEntityDetails>() ||
8771 (symbol->has<SubprogramDetails>() &&
8772 symbol->scope() /*not ENTRY*/)))) {
8773 name.symbol = symbol;
8775 CheckEntryDummyUse(name.source, symbol);
8776 bool convertedToProcEntity{ConvertToProcEntity(*symbol, name.source)};
8777 if (convertedToProcEntity && !symbol->attrs().test(Attr::EXTERNAL) &&
8778 IsIntrinsic(symbol->name(), flag) && !IsDummy(*symbol)) {
8779 AcquireIntrinsicProcedureFlags(*symbol);
8781 if (!SetProcFlag(name, *symbol, flag)) {
8784 CheckImplicitNoneExternal(name.source, *symbol);
8785 if (IsProcedure(*symbol) || symbol->has<DerivedTypeDetails>() ||
8786 symbol->has<AssocEntityDetails>()) {
8791 } else if (symbol->has<ObjectEntityDetails>()) {
8794 // this is a symbol from a host procedure, a symbol with HostAssocDetails
8796 // Operate on non ultimate symbol so that HostAssocDetails are also
8799 } else if (symbol->test(Symbol::Flag::Implicit)) {
8803 SayWithDecl(name, *symbol,
8810 const SourceName &name, const Symbol &symbol) {
8811 if (symbol.has<ProcEntityDetails>() && isImplicitNoneExternal() &&
8812 !symbol.attrs().test(Attr::EXTERNAL) &&
8813 !symbol.attrs().test(Attr::INTRINSIC) && !symbol.HasExplicitInterface()) {
8827 // Subtlety: The symbol pointers in the parse tree are not set, because
8830 if (Symbol * symbol{currScope().FindSymbol(name)}) {
8834 if (!symbol->test(other)) {
8835 ConvertToProcEntity(*symbol, name);
8836 if (auto *details{symbol->detailsIf<ProcEntityDetails>()}) {
8837 symbol->set(flag);
8838 if (IsDummy(*symbol)) {
8839 SetImplicitAttr(*symbol, Attr::EXTERNAL);
8841 ApplyImplicitRules(*symbol);
8851 const Symbol &symbol, const parser::Name &localName) {
8852 if (symbol.owner().IsGlobal()) {
8853 const auto *subp{symbol.detailsIf<SubprogramDetails>()};
8855 subp && subp->entryScope() ? subp->entryScope() : symbol.scope()};
8866 // Check and set the Function or Subroutine flag on symbol; false on error.
8868 const parser::Name &name, Symbol &symbol, Symbol::Flag flag) {
8869 if (symbol.test(Symbol::Flag::Function) && flag == Symbol::Flag::Subroutine) {
8871 name, symbol, "Cannot call function '%s' like a subroutine"_err_en_US);
8872 context().SetError(symbol);
8874 } else if (symbol.test(Symbol::Flag::Subroutine) &&
8877 name, symbol, "Cannot call subroutine '%s' like a function"_err_en_US);
8878 context().SetError(symbol);
8881 IsLocallyImplicitGlobalSymbol(symbol, name) &&
8882 TypesMismatchIfNonNull(symbol.GetType(), GetImplicitType(symbol))) {
8883 SayWithDecl(name, symbol,
8886 } else if (symbol.has<ProcEntityDetails>()) {
8887 symbol.set(flag); // in case it hasn't been set yet
8889 ApplyImplicitRules(symbol);
8891 if (symbol.attrs().test(Attr::INTRINSIC)) {
8892 AcquireIntrinsicProcedureFlags(symbol);
8894 } else if (symbol.GetType() && flag == Symbol::Flag::Subroutine) {
8896 name, symbol, "Cannot call function '%s' like a subroutine"_err_en_US);
8897 context().SetError(symbol);
8898 } else if (symbol.attrs().test(Attr::INTRINSIC)) {
8899 AcquireIntrinsicProcedureFlags(symbol);
8919 auto *moduleDetails{DEREF(currScope().symbol()).detailsIf<ModuleDetails>()};
8924 auto *symbol{FindInScope(info.symbolName())};
8925 if (!symbol && !info.kind().IsName()) {
8926 symbol = &MakeSymbol(info.symbolName(), Attrs{}, GenericDetails{});
8928 info.Resolve(&SetAccess(info.symbolName(), accessAttr, symbol));
8934 // Set the access specification for this symbol.
8936 const SourceName &name, Attr attr, Symbol *symbol) {
8937 if (!symbol) {
8938 symbol = &MakeSymbol(name);
8940 Attrs &attrs{symbol->attrs()};
8956 return *symbol;
8959 static bool NeedsExplicitType(const Symbol &symbol) {
8960 if (symbol.has<UnknownDetails>()) {
8962 } else if (const auto *details{symbol.detailsIf<EntityDetails>()}) {
8964 } else if (const auto *details{symbol.detailsIf<ObjectEntityDetails>()}) {
8966 } else if (const auto *details{symbol.detailsIf<ProcEntityDetails>()}) {
9067 for (const auto &[name, symbol] : context().GetCUDABuiltinsScope()) {
9070 localSymbol.set_details(UseDetails{name, *symbol});
9071 localSymbol.flags() = symbol->flags();
9163 genericDetails, existing->name(), existingUse->symbol());
9202 auto &symbol{*pair.second};
9204 ConvertToObjectEntity(symbol);
9206 if (NeedsExplicitType(symbol)) {
9207 ApplyImplicitRules(symbol);
9209 if (IsDummy(symbol) && isImplicitNoneType() &&
9210 symbol.test(Symbol::Flag::Implicit) && !context().HasError(symbol)) {
9211 Say(symbol.name(),
9213 context().SetError(symbol);
9215 if (symbol.has<GenericDetails>()) {
9216 CheckGenericProcedures(symbol);
9218 if (!symbol.has<HostAssocDetails>()) {
9219 CheckPossibleBadForwardRef(symbol);
9226 if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
9227 !proc->isDummy() && !IsPointer(symbol) &&
9228 !symbol.attrs().test(Attr::BIND_C)) {
9231 SetImplicitAttr(symbol, Attr::BIND_C);
9232 SetBindNameOn(symbol);
9262 Symbol *symbol{name.symbol};
9263 auto *details{symbol ? symbol->detailsIf<SubprogramDetails>() : nullptr};
9264 if (!details || !symbol->scope() ||
9265 &symbol->scope()->parent() != &currScope() || details->isInterface() ||
9267 details->moduleInterface() || symbol->test(Symbol::Flag::Subroutine)) {
9271 PushScope(*symbol->scope());
9276 if (auto type{evaluate::DynamicType::From(*symbol)}) {
9289 context().SetError(*symbol);
9320 if (auto *symbol{FindInScope(name)}) {
9321 const Symbol &ultimate{symbol->GetUltimate()};
9324 .Attach(symbol->name(), "'%s' is hidden by this entity"_because_en_US,
9325 symbol->name());
9359 Symbol *ptrSymbol{parser::GetLastName(dataRef).symbol};
9364 if (Symbol * symbol{name->symbol}) {
9368 if (symbol->test(Symbol::Flag::Function)) {
9373 // procedure, create a host associated symbol.
9374 if (symbol->GetUltimate().has<ObjectEntityDetails>() &&
9375 IsUplevelReference(*symbol)) {
9376 MakeHostAssocSymbol(*name, *symbol);
9390 if (IsProcedurePointer(parser::GetLastName(dataRef).symbol) &&
9393 Symbol &symbol{MakeSymbol(
9395 symbol.implicitAttrs().set(Attr::EXTERNAL);
9396 Resolve(*name, symbol);
9397 ConvertToProcEntity(symbol, name->source);
9449 CheckEntryDummyUse(name->source, name->symbol);
9450 ConvertToObjectEntity(DEREF(name->symbol));
9455 CheckEntryDummyUse(name->source, name->symbol);
9456 ConvertToObjectEntity(DEREF(name->symbol));
9480 Symbol *symbol{currScope().symbol()};
9482 subp{symbol ? symbol->detailsIf<SubprogramDetails>() : nullptr}) {
9532 Symbol *symbol{FindSymbol(name)};
9533 if (!symbol) {
9534 symbol = &MakeSymbol(name, Attrs{}, ObjectEntityDetails{});
9536 if (symbol->owner() != currScope()) {
9538 name, *symbol, "'%s' must be local to this subprogram"_err_en_US);
9540 ConvertToObjectEntity(*symbol);
9541 if (auto *object{symbol->detailsIf<ObjectEntityDetails>()}) {
9544 SayWithDecl(name, *symbol, "'%s' must be an object"_err_en_US);
9742 // result from being converted later to a function symbol if it is called
9745 // convert the result to an object, and calling the symbol inside the function
9749 if (Symbol * symbol{scope.symbol()}) {
9750 if (auto *details{symbol->detailsIf<SubprogramDetails>()}) {
9780 Symbol &symbol{*pair.second};
9781 if (inModule && symbol.attrs().test(Attr::EXTERNAL) && !IsPointer(symbol) &&
9782 !symbol.test(Symbol::Flag::Function) &&
9783 !symbol.test(Symbol::Flag::Subroutine)) {
9785 symbol.set(
9786 symbol.GetType() ? Symbol::Flag::Function : Symbol::Flag::Subroutine);
9788 ApplyImplicitRules(symbol);
9790 if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
9791 auto *object{symbol.detailsIf<ObjectEntityDetails>()};
9792 if (!object->cudaDataAttr() && !IsValue(symbol) &&
9793 (IsDummy(symbol) || object->IsArray())) {
9807 auto &symbol{MakeSymbol(child.name(), SubprogramNameDetails{kind, child})};
9809 SetExplicitAttr(symbol, Attr::MODULE);
9812 SetExplicitAttr(symbol, Attr::BIND_C);
9816 symbol.set(Symbol::Flag::Function);
9818 symbol.set(Symbol::Flag::Subroutine);
9824 auto &symbol{
9826 symbol.set(child.GetSubpFlag());
9828 SetExplicitAttr(symbol, Attr::MODULE);
9831 SetExplicitAttr(symbol, Attr::BIND_C);
9839 // subprogram with the same name, create the generic's symbol
9920 if (Symbol * symbol{name.symbol}) {
9921 if (Scope * scope{symbol->scope()}) {
9987 if (name.symbol) {
9988 if (const auto *object{name.symbol->detailsIf<ObjectEntityDetails>()};
10044 CHECK(scope.IsDerivedType() && !scope.symbol());
10050 origTypeScope->symbol() == &origTypeSymbol);