2018-03-01 01:56:10 +01:00
|
|
|
#ifndef FORTRAN_PARSER_PARSING_H_
|
|
|
|
#define FORTRAN_PARSER_PARSING_H_
|
|
|
|
|
|
|
|
#include "characters.h"
|
2018-04-19 22:03:23 +02:00
|
|
|
#include "instrumented-parser.h"
|
2018-03-01 01:56:10 +01:00
|
|
|
#include "message.h"
|
|
|
|
#include "parse-tree.h"
|
|
|
|
#include "provenance.h"
|
2018-03-17 00:13:49 +01:00
|
|
|
#include <optional>
|
2018-03-01 01:56:10 +01:00
|
|
|
#include <ostream>
|
2018-03-17 00:13:49 +01:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2018-03-01 01:56:10 +01:00
|
|
|
|
|
|
|
namespace Fortran {
|
|
|
|
namespace parser {
|
|
|
|
|
|
|
|
struct Options {
|
|
|
|
Options() {}
|
|
|
|
|
2018-03-17 00:13:49 +01:00
|
|
|
using Predefinition = std::pair<std::string, std::optional<std::string>>;
|
|
|
|
|
2018-03-01 01:56:10 +01:00
|
|
|
bool isFixedForm{false};
|
|
|
|
int fixedFormColumns{72};
|
|
|
|
bool enableBackslashEscapes{true};
|
|
|
|
bool enableOldDebugLines{false};
|
|
|
|
bool isStrictlyStandard{false};
|
|
|
|
Encoding encoding{Encoding::UTF8};
|
2018-03-17 00:13:49 +01:00
|
|
|
std::vector<std::string> searchDirectories;
|
|
|
|
std::vector<Predefinition> predefinitions;
|
2018-04-19 22:03:23 +02:00
|
|
|
bool instrumentedParse{false};
|
2018-03-01 01:56:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Parsing {
|
|
|
|
public:
|
|
|
|
Parsing() {}
|
|
|
|
|
|
|
|
bool consumedWholeFile() const { return consumedWholeFile_; }
|
2018-03-29 02:15:00 +02:00
|
|
|
const char *finalRestingPlace() const { return finalRestingPlace_; }
|
2018-04-20 00:46:02 +02:00
|
|
|
CookedSource &cooked() { return cooked_; }
|
2018-03-01 01:56:10 +01:00
|
|
|
Messages &messages() { return messages_; }
|
2018-04-03 00:51:04 +02:00
|
|
|
std::optional<Program> &parseTree() { return parseTree_; }
|
2018-03-01 01:56:10 +01:00
|
|
|
|
2018-04-03 00:51:04 +02:00
|
|
|
void Prescan(const std::string &path, Options);
|
2018-03-01 01:56:10 +01:00
|
|
|
void DumpCookedChars(std::ostream &) const;
|
|
|
|
void DumpProvenance(std::ostream &) const;
|
2018-04-19 22:03:23 +02:00
|
|
|
void DumpParsingLog(std::ostream &) const;
|
2018-04-21 01:14:57 +02:00
|
|
|
void Parse(std::ostream *debugOutput = nullptr);
|
2018-04-20 02:02:12 +02:00
|
|
|
void ClearLog();
|
2018-03-01 01:56:10 +01:00
|
|
|
|
2018-03-29 02:15:00 +02:00
|
|
|
void Identify(std::ostream &o, const char *at, const std::string &prefix,
|
2018-03-01 01:56:10 +01:00
|
|
|
bool echoSourceLine = false) const {
|
2018-03-29 21:16:10 +02:00
|
|
|
allSources_.Identify(
|
|
|
|
o, cooked_.GetProvenance(at).start(), prefix, echoSourceLine);
|
2018-03-01 01:56:10 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 01:06:18 +02:00
|
|
|
bool ForTesting(std::string path, std::ostream &);
|
2018-04-03 00:51:04 +02:00
|
|
|
|
2018-03-01 01:56:10 +01:00
|
|
|
private:
|
|
|
|
Options options_;
|
|
|
|
AllSources allSources_;
|
2018-03-23 23:14:52 +01:00
|
|
|
CookedSource cooked_{allSources_};
|
2018-04-20 00:46:02 +02:00
|
|
|
Messages messages_;
|
2018-03-01 01:56:10 +01:00
|
|
|
bool consumedWholeFile_{false};
|
2018-03-29 02:15:00 +02:00
|
|
|
const char *finalRestingPlace_{nullptr};
|
2018-03-01 01:56:10 +01:00
|
|
|
std::optional<Program> parseTree_;
|
2018-04-19 22:03:23 +02:00
|
|
|
ParsingLog log_;
|
2018-03-01 01:56:10 +01:00
|
|
|
};
|
|
|
|
} // namespace parser
|
|
|
|
} // namespace Fortran
|
|
|
|
#endif // FORTRAN_PARSER_PARSING_H_
|