Lines Matching full:symbol

18 #include "flang/Semantics/symbol.h"
52 static void PutInit(llvm::raw_ostream &, const Symbol &, const MaybeExpr &,
73 SubprogramSymbolCollector(const Symbol &symbol, const Scope &scope)
74 : symbol_{symbol}, scope_{scope} {}
80 const Symbol &symbol_;
88 void DoSymbol(const Symbol &);
89 void DoSymbol(const SourceName &, const Symbol &);
93 bool NeedImport(const SourceName &, const Symbol &);
96 for (const Symbol &symbol : evaluate::CollectSymbols(expr)) {
97 DoSymbol(symbol);
118 auto *symbol{scope.symbol()};
119 if (!symbol->test(Symbol::Flag::ModFile)) {
120 Write(*symbol);
133 // Write the module file for symbol, which must be a module or submodule.
134 void ModFileWriter::Write(const Symbol &symbol) {
135 const auto &module{symbol.get<ModuleDetails>()};
143 ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())};
146 hermeticModules.insert(symbol);
148 PutSymbols(DEREF(symbol.scope()),
150 auto asStr{GetAsString(symbol)};
165 symbol.name(), "Error writing %s: %s"_err_en_US, path, error.message());
170 void ModFileWriter::WriteClosure(llvm::raw_ostream &out, const Symbol &symbol,
172 if (!symbol.has<ModuleDetails>() || symbol.owner().IsIntrinsicModules() ||
173 !nonIntrinsicModulesWritten.insert(symbol).second) {
176 PutSymbols(DEREF(symbol.scope()), /*hermeticModules=*/nullptr);
178 auto str{GetAsString(symbol)};
187 std::string ModFileWriter::GetAsString(const Symbol &symbol) {
192 auto &details{symbol.get<ModuleDetails>()};
194 all << "module " << symbol.name();
196 auto *parent{details.parent()->symbol()};
197 auto *ancestor{details.ancestor()->symbol()};
202 all << ") " << symbol.name();
225 SourceOrderedSymbolSet &set, const Symbol &symbol, const Scope &scope) {
243 if (symbol.has<DerivedTypeDetails>()) {
244 if (symbol.scope()) {
245 HarvestSymbolsNeededFromOtherModules(set, *symbol.scope());
247 } else if (const auto &generic{symbol.detailsIf<GenericDetails>()};
249 const Symbol &dtSym{*generic->derivedType()};
257 } else if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
260 if (IsNamedConstant(symbol) || scope.IsDerivedType()) {
267 } else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}) {
271 } else if (const auto *subp{symbol.detailsIf<SubprogramDetails>()}) {
272 for (const Symbol *dummy : subp->dummyArgs()) {
285 for (const auto &[_, symbol] : scope) {
286 HarvestSymbolsNeededFromOtherModules(set, *symbol, scope);
292 std::map<const Symbol *, const Symbol *> useMap;
294 const Symbol *symbol{&*symbolRef};
295 while (const auto *hostAssoc{symbol->detailsIf<HostAssocDetails>()}) {
296 symbol = &hostAssoc->symbol();
298 if (const auto *use{symbol->detailsIf<UseDetails>()}) {
299 useMap.emplace(&use->symbol(), symbol);
321 if (const Symbol * found{scope.FindSymbol(s->name())}) {
334 if (&s->owner() != &found->owner()) { // Symbol needs renaming
336 DEREF(sMod->symbol()).name().ToString() + "$" +
340 // Symbol is used in this scope but not visible under its name
346 uses_ << DEREF(sMod->symbol()).name() << ",only:";
382 for (const Symbol &symbol : sorted) {
383 if (!symbol.test(Symbol::Flag::CompilerCreated)) {
384 PutSymbol(typeBindings, symbol);
387 for (const Symbol &symbol : uses) {
388 PutUse(symbol);
392 !set.front().symbol.test(Symbol::Flag::CompilerCreated)) {
407 bool ModFileWriter::PutComponents(const Symbol &typeSymbol) {
415 for (const Symbol &symbol : details.paramDeclOrder()) {
416 CHECK(symbol.has<TypeParamDetails>());
417 PutSymbol(typeBindings, symbol);
418 emitted.emplace(symbol);
424 const Symbol &component{*iter->second};
425 if (!component.test(Symbol::Flag::ParentComp)) {
432 for (const Symbol &symbol : symbols) {
433 if (emitted.find(symbol) == emitted.end()) {
434 PutSymbol(typeBindings, symbol);
446 // Return the symbol's attributes that should be written
448 static Attrs getSymbolAttrsToWrite(const Symbol &symbol) {
451 return symbol.attrs() & ~(symbol.implicitAttrs() & Attrs{Attr::SAVE});
455 llvm::raw_ostream &os, const Symbol &symbol) {
456 if (IsGenericDefinedOp(symbol)) {
457 return os << "operator(" << symbol.name() << ')';
459 return os << symbol.name();
463 // Emit a symbol to decls_, except for bindings in a derived type (type-bound
466 llvm::raw_ostream &typeBindings, const Symbol &symbol) {
470 [&](const DerivedTypeDetails &) { PutDerivedType(symbol); },
471 [&](const SubprogramDetails &) { PutSubprogram(symbol); },
473 if (symbol.owner().IsDerivedType()) {
475 for (const Symbol &proc : x.specificProcs()) {
476 PutGenericName(typeBindings << "generic::", symbol)
480 PutGeneric(symbol);
483 [&](const UseDetails &) { PutUse(symbol); },
486 bool deferred{symbol.attrs().test(Attr::DEFERRED)};
489 typeBindings << '(' << x.symbol().name() << ')';
492 auto attrs{symbol.attrs()};
497 typeBindings << "::" << symbol.name();
498 if (!deferred && x.symbol().name() != symbol.name()) {
499 typeBindings << "=>" << x.symbol().name();
504 decls_ << "namelist/" << symbol.name();
506 for (const Symbol &object : x.objects()) {
511 if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
512 decls_ << "private::" << symbol.name() << '\n';
516 decls_ << "common/" << symbol.name();
523 if (symbol.attrs().test(Attr::BIND_C)) {
524 PutAttrs(decls_, getSymbolAttrsToWrite(symbol), x.bindName(),
526 decls_ << "::/" << symbol.name() << "/\n";
532 PutEntity(decls_, symbol);
533 PutDirective(decls_, symbol);
536 symbol.details());
540 const Symbol &typeSymbol, const Scope *scope) {
578 const Symbol &typeSymbol, const Scope *scope) {
671 void ModFileWriter::PutSubprogram(const Symbol &symbol) {
672 auto &details{symbol.get<SubprogramDetails>()};
673 if (const Symbol * interface{details.moduleInterface()}) {
675 if (module && module != &symbol.owner()) {
681 auto attrs{symbol.attrs()};
699 decls_ << ss.str().substr(1) << "::" << symbol.name() << '\n';
733 os << symbol.name() << '(';
749 const Symbol &result{details.result()};
750 if (result.name() != symbol.name()) {
757 details.entryScope() ? *details.entryScope() : DEREF(symbol.scope())};
758 SubprogramSymbolCollector collector{symbol, scope};
763 for (const Symbol &need : collector.symbols()) {
779 static bool IsIntrinsicOp(const Symbol &symbol) {
780 if (const auto *details{symbol.GetUltimate().detailsIf<GenericDetails>()}) {
787 void ModFileWriter::PutGeneric(const Symbol &symbol) {
788 const auto &genericOwner{symbol.owner()};
789 auto &details{symbol.get<GenericDetails>()};
790 PutGenericName(decls_ << "interface ", symbol) << '\n';
791 for (const Symbol &specific : details.specificProcs()) {
797 if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
798 PutGenericName(decls_ << "private::", symbol) << '\n';
802 void ModFileWriter::PutUse(const Symbol &symbol) {
803 auto &details{symbol.get<UseDetails>()};
804 auto &use{details.symbol()};
805 const Symbol &module{GetUsedModule(details)};
813 PutGenericName(uses_, symbol);
816 if (!IsIntrinsicOp(symbol) && use.name() != symbol.name()) {
820 PutUseExtraAttr(Attr::VOLATILE, symbol, use);
821 PutUseExtraAttr(Attr::ASYNCHRONOUS, symbol, use);
822 if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
823 PutGenericName(useExtraAttrs_ << "private::", symbol) << '\n';
830 Attr attr, const Symbol &local, const Symbol &use) {
837 static inline SourceName NameInModuleFile(const Symbol &symbol) {
838 if (const auto *use{symbol.detailsIf<UseDetails>()}) {
839 if (use->symbol().attrs().test(Attr::PRIVATE)) {
843 return use->symbol().name();
846 return symbol.name();
857 for (SymbolRef symbol : symbols) {
858 const auto *generic{symbol->detailsIf<GenericDetails>()};
864 } else if (const auto *use{symbol->detailsIf<UseDetails>()}) {
867 if (symbol->test(Symbol::Flag::ParentComp)) {
868 } else if (symbol->has<NamelistDetails>()) {
869 namelist.push_back(symbol);
872 &generic->specific()->owner() == &symbol->owner()) {
875 &generic->derivedType()->owner() == &symbol->owner()) {
878 generics.push_back(symbol);
880 sorted.push_back(symbol);
883 // Sort most symbols by name: use of Symbol::ReplaceName ensures the source
884 // location of a symbol's name is the first "real" use.
899 void ModFileWriter::PutEntity(llvm::raw_ostream &os, const Symbol &symbol) {
902 [&](const ObjectEntityDetails &) { PutObjectEntity(os, symbol); },
903 [&](const ProcEntityDetails &) { PutProcEntity(os, symbol); },
904 [&](const TypeParamDetails &) { PutTypeParam(os, symbol); },
907 DetailsToString(symbol.details()).c_str());
910 symbol.details());
945 llvm::raw_ostream &os, const Symbol &symbol) {
946 auto &details{symbol.get<ObjectEntityDetails>()};
949 const Symbol &typeSymbol{details.type()->derivedTypeSpec().typeSymbol()};
951 PutDerivedType(typeSymbol, &symbol.owner());
952 if (emittedDECFields_.find(symbol) != emittedDECFields_.end()) {
953 return; // symbol was emitted on STRUCTURE statement
958 os, symbol, [&]() { PutType(os, DEREF(symbol.GetType())); },
959 getSymbolAttrsToWrite(symbol));
962 PutInit(os, symbol, details.init(), details.unanalyzedPDTComponentInit());
964 if (auto tkr{GetIgnoreTKR(symbol)}; !tkr.empty()) {
989 os << ") " << symbol.name() << '\n';
993 << ") " << symbol.name() << '\n';
995 if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointer)) {
996 if (!symbol.owner().crayPointers().empty()) {
997 for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
998 if (pointer == symbol) {
999 os << "pointer(" << symbol.name() << "," << pointee << ")\n";
1006 void ModFileWriter::PutProcEntity(llvm::raw_ostream &os, const Symbol &symbol) {
1007 if (symbol.attrs().test(Attr::INTRINSIC)) {
1008 os << "intrinsic::" << symbol.name() << '\n';
1009 if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
1010 os << "private::" << symbol.name() << '\n';
1014 const auto &details{symbol.get<ProcEntityDetails>()};
1015 Attrs attrs{symbol.attrs()};
1020 os, symbol,
1042 void ModFileWriter::PutTypeParam(llvm::raw_ostream &os, const Symbol &symbol) {
1043 auto &details{symbol.get<TypeParamDetails>()};
1045 os, symbol,
1047 PutType(os, DEREF(symbol.GetType()));
1050 symbol.attrs());
1055 void PutInit(llvm::raw_ostream &os, const Symbol &symbol, const MaybeExpr &init,
1057 if (IsNamedConstant(symbol) || symbol.owner().IsDerivedType()) {
1058 const char *assign{symbol.attrs().test(Attr::POINTER) ? "=>" : "="};
1085 void ModFileWriter::PutEntity(llvm::raw_ostream &os, const Symbol &symbol,
1088 PutAttrs(os, attrs, symbol.GetBindName(), symbol.GetIsExplicitBindName());
1089 if (symbol.owner().kind() == Scope::Kind::DerivedType &&
1090 context_.IsTempName(symbol.name().ToString())) {
1093 os << "::" << symbol.name();
1139 void PutOpenACCDirective(llvm::raw_ostream &os, const Symbol &symbol) {
1140 if (symbol.test(Symbol::Flag::AccDeclare)) {
1142 if (symbol.test(Symbol::Flag::AccCopy)) {
1144 } else if (symbol.test(Symbol::Flag::AccCopyIn) ||
1145 symbol.test(Symbol::Flag::AccCopyInReadOnly)) {
1147 } else if (symbol.test(Symbol::Flag::AccCopyOut)) {
1149 } else if (symbol.test(Symbol::Flag::AccCreate)) {
1151 } else if (symbol.test(Symbol::Flag::AccPresent)) {
1153 } else if (symbol.test(Symbol::Flag::AccDevicePtr)) {
1155 } else if (symbol.test(Symbol::Flag::AccDeviceResident)) {
1157 } else if (symbol.test(Symbol::Flag::AccLink)) {
1161 if (symbol.test(Symbol::Flag::AccCopyInReadOnly)) {
1164 os << symbol.name() << ")\n";
1168 void PutOpenMPDirective(llvm::raw_ostream &os, const Symbol &symbol) {
1169 if (symbol.test(Symbol::Flag::OmpThreadprivate)) {
1170 os << "!$omp threadprivate(" << symbol.name() << ")\n";
1174 void ModFileWriter::PutDirective(llvm::raw_ostream &os, const Symbol &symbol) {
1175 PutOpenACCDirective(os, symbol);
1176 PutOpenMPDirective(os, symbol);
1357 const Symbol *notAModule{nullptr};
1368 // Already present in the symbol table as a usable non-intrinsic module?
1379 for (const Symbol *found{scope->symbol()}; found;) {
1393 notAModule = scope->symbol();
1433 // path; see whether it's already in the symbol table as an intrinsic
1440 // We don't have this module in the symbol table yet.
1472 // symbol of the same name that is not a module.
1521 Symbol *moduleSymbol{nullptr};
1522 const Symbol *previousModuleSymbol{nullptr};
1527 // There is already a global symbol or intrinsic module of the same name.
1542 moduleSymbol->set(Symbol::Flag::ModFile);
1575 moduleSymbol = submoduleScope->symbol();
1577 moduleSymbol->set(Symbol::Flag::ModFile);
1582 CHECK(moduleSymbol->test(Symbol::Flag::ModFile));
1627 for (const Symbol *dummyArg : details.dummyArgs()) {
1636 const Symbol &symbol{*pair.second};
1637 if (const auto *useDetails{symbol.detailsIf<UseDetails>()}) {
1638 const Symbol &ultimate{useDetails->symbol().GetUltimate()};
1643 const Symbol *spec{generic->specific()};
1644 const Symbol *dt{generic->derivedType()};
1648 const Symbol *interface { subp->moduleInterface() };
1652 need_.push_back(symbol);
1654 } else if (symbol.has<SubprogramDetails>()) {
1658 const auto hasInterface{[&symbol](const Symbol *s) -> bool {
1659 // Is 's' a procedure with interface 'symbol'?
1662 if (sDetails->procInterface() == &symbol) {
1669 for (const Symbol *dummyArg : details.dummyArgs()) {
1674 if (needed && needSet_.insert(symbol).second) {
1675 need_.push_back(symbol);
1681 void SubprogramSymbolCollector::DoSymbol(const Symbol &symbol) {
1682 DoSymbol(symbol.name(), symbol);
1687 const SourceName &name, const Symbol &symbol) {
1688 const auto &scope{symbol.owner()};
1691 useSet_.insert(symbol);
1693 if (NeedImport(name, symbol)) {
1698 if (!needSet_.insert(symbol).second) {
1711 if (const Symbol * commonBlock{details.commonBlock()}) {
1728 DoSymbol(details.symbol());
1732 symbol.details());
1733 if (!symbol.has<UseDetails>()) {
1734 DoType(symbol.GetType());
1737 need_.push_back(symbol);
1759 // any) matter to IMPORT symbol collection only for derived types
1785 // Do we need a IMPORT of this symbol into an interface block?
1787 const SourceName &name, const Symbol &symbol) {
1793 } else if (&symbol == scope_.symbol()) {
1795 } else if (symbol.owner().Contains(scope_)) {
1797 } else if (const Symbol *found{scope_.FindSymbol(name)}) {
1798 // detect import from ancestor of use-associated symbol