2020-02-25 23:11:52 +08:00
|
|
|
//===-- lib/Semantics/mod-file.h --------------------------------*- C++ -*-===//
|
2018-07-17 07:23:18 +08:00
|
|
|
//
|
2019-12-21 04:52:07 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-07-17 07:23:18 +08:00
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-07-17 07:23:18 +08:00
|
|
|
|
|
|
|
#ifndef FORTRAN_SEMANTICS_MOD_FILE_H_
|
|
|
|
#define FORTRAN_SEMANTICS_MOD_FILE_H_
|
|
|
|
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Semantics/attr.h"
|
2020-07-03 00:52:48 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-07-25 21:55:11 +08:00
|
|
|
#include <string>
|
2018-07-26 08:07:38 +08:00
|
|
|
|
|
|
|
namespace Fortran::parser {
|
|
|
|
class CharBlock;
|
2019-09-24 08:10:58 +08:00
|
|
|
class Message;
|
|
|
|
class MessageFixedText;
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::parser
|
2018-07-25 21:55:11 +08:00
|
|
|
|
2020-02-28 23:11:03 +08:00
|
|
|
namespace llvm {
|
|
|
|
class raw_ostream;
|
|
|
|
}
|
|
|
|
|
2018-07-17 07:23:18 +08:00
|
|
|
namespace Fortran::semantics {
|
|
|
|
|
2018-07-25 21:55:11 +08:00
|
|
|
using SourceName = parser::CharBlock;
|
2018-07-26 08:07:38 +08:00
|
|
|
class Symbol;
|
|
|
|
class Scope;
|
2018-10-22 22:37:38 +08:00
|
|
|
class SemanticsContext;
|
2018-07-26 08:07:38 +08:00
|
|
|
|
|
|
|
class ModFileWriter {
|
|
|
|
public:
|
2020-07-14 03:19:17 +08:00
|
|
|
explicit ModFileWriter(SemanticsContext &context) : context_{context} {}
|
2019-03-07 09:07:25 +08:00
|
|
|
bool WriteAll();
|
2018-07-25 21:55:11 +08:00
|
|
|
|
2018-07-26 08:07:38 +08:00
|
|
|
private:
|
2018-10-22 22:37:38 +08:00
|
|
|
SemanticsContext &context_;
|
2020-02-28 23:11:03 +08:00
|
|
|
// Buffer to use with raw_string_ostream
|
|
|
|
std::string usesBuf_;
|
|
|
|
std::string useExtraAttrsBuf_;
|
|
|
|
std::string declsBuf_;
|
|
|
|
std::string containsBuf_;
|
|
|
|
|
|
|
|
llvm::raw_string_ostream uses_{usesBuf_};
|
2020-03-29 12:00:16 +08:00
|
|
|
llvm::raw_string_ostream useExtraAttrs_{
|
|
|
|
useExtraAttrsBuf_}; // attrs added to used entity
|
2020-02-28 23:11:03 +08:00
|
|
|
llvm::raw_string_ostream decls_{declsBuf_};
|
|
|
|
llvm::raw_string_ostream contains_{containsBuf_};
|
2018-07-26 08:07:38 +08:00
|
|
|
|
2018-10-22 22:37:38 +08:00
|
|
|
void WriteAll(const Scope &);
|
2018-08-03 07:21:27 +08:00
|
|
|
void WriteOne(const Scope &);
|
2018-08-04 02:32:21 +08:00
|
|
|
void Write(const Symbol &);
|
2018-08-03 07:21:27 +08:00
|
|
|
std::string GetAsString(const Symbol &);
|
2020-10-01 04:34:23 +08:00
|
|
|
// Returns true if a derived type with bindings and "contains" was emitted
|
|
|
|
bool PutSymbols(const Scope &);
|
2020-02-28 23:11:03 +08:00
|
|
|
void PutSymbol(llvm::raw_ostream &, const Symbol &);
|
2018-07-26 08:07:38 +08:00
|
|
|
void PutDerivedType(const Symbol &);
|
|
|
|
void PutSubprogram(const Symbol &);
|
|
|
|
void PutGeneric(const Symbol &);
|
|
|
|
void PutUse(const Symbol &);
|
|
|
|
void PutUseExtraAttr(Attr, const Symbol &, const Symbol &);
|
|
|
|
};
|
2018-07-17 07:23:18 +08:00
|
|
|
|
2018-07-25 21:55:11 +08:00
|
|
|
class ModFileReader {
|
|
|
|
public:
|
|
|
|
// directories specifies where to search for module files
|
2018-10-22 22:37:38 +08:00
|
|
|
ModFileReader(SemanticsContext &context) : context_{context} {}
|
2018-08-03 07:21:27 +08:00
|
|
|
// Find and read the module file for a module or submodule.
|
|
|
|
// If ancestor is specified, look for a submodule of that module.
|
|
|
|
// Return the Scope for that module/submodule or nullptr on error.
|
2018-10-22 22:37:38 +08:00
|
|
|
Scope *Read(const SourceName &, Scope *ancestor = nullptr);
|
2018-07-25 21:55:11 +08:00
|
|
|
|
|
|
|
private:
|
2018-10-22 22:37:38 +08:00
|
|
|
SemanticsContext &context_;
|
2018-07-25 21:55:11 +08:00
|
|
|
|
2019-09-24 08:10:58 +08:00
|
|
|
parser::Message &Say(const SourceName &, const std::string &,
|
|
|
|
parser::MessageFixedText &&, const std::string &);
|
2018-07-25 21:55:11 +08:00
|
|
|
};
|
2018-07-17 07:23:18 +08:00
|
|
|
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::semantics
|
2018-07-17 07:23:18 +08:00
|
|
|
#endif
|