1 //===-- lib/Semantics/mod-file.h --------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef FORTRAN_SEMANTICS_MOD_FILE_H_
10 #define FORTRAN_SEMANTICS_MOD_FILE_H_
12 #include "flang/Semantics/attr.h"
13 #include "flang/Semantics/symbol.h"
14 #include "llvm/Support/raw_ostream.h"
17 namespace Fortran::parser
{
20 class MessageFixedText
;
21 } // namespace Fortran::parser
27 namespace Fortran::semantics
{
29 using SourceName
= parser::CharBlock
;
32 class SemanticsContext
;
36 explicit ModFileWriter(SemanticsContext
&context
) : context_
{context
} {}
40 SemanticsContext
&context_
;
41 // Buffer to use with raw_string_ostream
43 std::string useExtraAttrsBuf_
;
44 std::string declsBuf_
;
45 std::string containsBuf_
;
46 // Tracks nested DEC structures and fields of that type
47 UnorderedSymbolSet emittedDECStructures_
, emittedDECFields_
;
49 llvm::raw_string_ostream uses_
{usesBuf_
};
50 llvm::raw_string_ostream useExtraAttrs_
{
51 useExtraAttrsBuf_
}; // attrs added to used entity
52 llvm::raw_string_ostream decls_
{declsBuf_
};
53 llvm::raw_string_ostream contains_
{containsBuf_
};
54 bool isSubmodule_
{false};
56 void WriteAll(const Scope
&);
57 void WriteOne(const Scope
&);
58 void Write(const Symbol
&);
59 std::string
GetAsString(const Symbol
&);
60 void PutSymbols(const Scope
&);
61 // Returns true if a derived type with bindings and "contains" was emitted
62 bool PutComponents(const Symbol
&);
63 void PutSymbol(llvm::raw_ostream
&, const Symbol
&);
64 void PutEntity(llvm::raw_ostream
&, const Symbol
&);
66 llvm::raw_ostream
&, const Symbol
&, std::function
<void()>, Attrs
);
67 void PutObjectEntity(llvm::raw_ostream
&, const Symbol
&);
68 void PutProcEntity(llvm::raw_ostream
&, const Symbol
&);
69 void PutDerivedType(const Symbol
&, const Scope
* = nullptr);
70 void PutDECStructure(const Symbol
&, const Scope
* = nullptr);
71 void PutTypeParam(llvm::raw_ostream
&, const Symbol
&);
72 void PutSubprogram(const Symbol
&);
73 void PutGeneric(const Symbol
&);
74 void PutUse(const Symbol
&);
75 void PutUseExtraAttr(Attr
, const Symbol
&, const Symbol
&);
76 llvm::raw_ostream
&PutAttrs(llvm::raw_ostream
&, Attrs
,
77 const std::string
* = nullptr, bool = false, std::string before
= ","s
,
78 std::string after
= ""s
) const;
83 // directories specifies where to search for module files
84 ModFileReader(SemanticsContext
&context
) : context_
{context
} {}
85 // Find and read the module file for a module or submodule.
86 // If ancestor is specified, look for a submodule of that module.
87 // Return the Scope for that module/submodule or nullptr on error.
88 Scope
*Read(const SourceName
&, std::optional
<bool> isIntrinsic
,
89 Scope
*ancestor
, bool silent
= false);
92 SemanticsContext
&context_
;
94 parser::Message
&Say(const SourceName
&, const std::string
&,
95 parser::MessageFixedText
&&, const std::string
&);
98 } // namespace Fortran::semantics