FLANG

mod-file.h
1 //===-- lib/Semantics/mod-file.h --------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef FORTRAN_SEMANTICS_MOD_FILE_H_
10 #define FORTRAN_SEMANTICS_MOD_FILE_H_
11
12 #include "flang/Semantics/attr.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include <string>
15
16 namespace Fortran::parser {
17 class CharBlock;
18 class Message;
19 class MessageFixedText;
20 } // namespace Fortran::parser
21
22 namespace llvm {
23 class raw_ostream;
24 }
25
26 namespace Fortran::semantics {
27
28 using SourceName = parser::CharBlock;
29 class Symbol;
30 class Scope;
31 class SemanticsContext;
32
33 class ModFileWriter {
34 public:
35 explicit ModFileWriter(SemanticsContext &context) : context_{context} {}
36 bool WriteAll();
37
38 private:
39 SemanticsContext &context_;
40 // Buffer to use with raw_string_ostream
41 std::string usesBuf_;
42 std::string useExtraAttrsBuf_;
43 std::string declsBuf_;
44 std::string containsBuf_;
45
46 llvm::raw_string_ostream uses_{usesBuf_};
47 llvm::raw_string_ostream useExtraAttrs_{
48 useExtraAttrsBuf_}; // attrs added to used entity
49 llvm::raw_string_ostream decls_{declsBuf_};
50 llvm::raw_string_ostream contains_{containsBuf_};
51
52 void WriteAll(const Scope &);
53 void WriteOne(const Scope &);
54 void Write(const Symbol &);
55 std::string GetAsString(const Symbol &);
56 void PutSymbols(const Scope &);
57 void PutSymbol(llvm::raw_ostream &, const Symbol &);
58 void PutDerivedType(const Symbol &);
59 void PutSubprogram(const Symbol &);
60 void PutGeneric(const Symbol &);
61 void PutUse(const Symbol &);
62 void PutUseExtraAttr(Attr, const Symbol &, const Symbol &);
63 };
64
65 class ModFileReader {
66 public:
67 // directories specifies where to search for module files
68 ModFileReader(SemanticsContext &context) : context_{context} {}
69 // Find and read the module file for a module or submodule.
70 // If ancestor is specified, look for a submodule of that module.
71 // Return the Scope for that module/submodule or nullptr on error.
72 Scope *Read(const SourceName &, Scope *ancestor = nullptr);
73
74 private:
75 SemanticsContext &context_;
76
77 parser::Message &Say(const SourceName &, const std::string &,
78 parser::MessageFixedText &&, const std::string &);
79 };
80
81 } // namespace Fortran::semantics
82 #endif
Fortran::semantics::SemanticsContext
Definition: semantics.h:60
Fortran::semantics::Symbol
Definition: symbol.h:479
Fortran::parser::Message
Definition: message.h:141
Fortran::semantics::ModFileWriter
Definition: mod-file.h:33
Fortran::parser::MessageFixedText
Definition: message.h:33
Fortran::parser::CharBlock
Definition: char-block.h:28
Fortran::semantics::Scope
Definition: scope.h:56
Fortran::parser
Definition: check-expression.h:19
Fortran::semantics::ModFileReader
Definition: mod-file.h:65